; *************************************************************************** ; *************************************************************************** ; ; core-kernel.asm ; ; The "CORE(not TM)" PC Engine library kernel code that runs after startup. ; ; Copyright John Brandwood 2021-2024. ; ; Distributed under the Boost Software License, Version 1.0. ; (See accompanying file LICENSE_1_0.txt or copy at ; http://www.boost.org/LICENSE_1_0.txt) ; ; *************************************************************************** ; *************************************************************************** ; ; This code is permanently located in either MPR7 (HuCARD), or MPR1 (CD-ROM), ; and it provides a consistant method of interrupt-handling on both systems ; that is designed to be compatible with the System Card. ; ; The library uses the "irq1_hook" for its own VDC interrupt handler, and PCE ; developers are expected to use "vsync_hook" and "hsync_hook" for their VDC ; interrupt functions. Plenty of memory is available in the 1st bank for the ; developer to put those functions. ; ; The reason for using "irq1_hook", is so that the library can work properly ; if either the current overlay program, or the System Card, are mapped into ; MPR7 whenever an interrupt occurs. ; ; The VDC interupt handler itself is changed from the System Card's handler, ; and it is designed to provide faster response to vsync_hook, and to enable ; interrupts during the slow(ish) joypad and sound driver code, so that both ; raster and timer interrupts are not delayed. ; ; Developers are free to enable interrupts during their own vsync_hook code, ; if they wish to do so. ; ; On CD-ROM systems, this library kernel also provides a function to load and ; run a new overlay program, without relying upon any of the code/data within ; the current overlay program's memory (unlike HuC v3). ; ; *************************************************************************** ; *************************************************************************** ; *************************************************************************** ; *************************************************************************** ; ; core_kernel - Start of kernel code. ; core_kernel = * ; *************************************************************************** ; *************************************************************************** ; ; Useful constants, needed by joypad library code, and used by many others. ; ; The kernel starts with a non-zero byte so that core-startup.asm can check ; whether it has already been loaded into RAM. ; const_FFFF: dw $FFFF ; Useful constant for TAI. const_0000: dw $0000 ; Useful constant for TAI. bit_mask: db $01,$02,$04,$08,$10,$20,$40,$80 ; *************************************************************************** ; *************************************************************************** ; ; core_irq2 - Minimal interrupt handler compatible with System Card. ; core_irq1 - Minimal interrupt handler compatible with System Card. ; core_timer - Minimal interrupt handler compatible with System Card. ; core_rti - Minimal interrupt handler compatible with System Card. ; ; Note that it takes 8 cycles to respond to an IRQ. ; ; These routines are copied to a location in RAM that does not vary when ; a different overlay program is loaded. ; ; All overlay programs are set up to vector interrupts to these routines, ; which is designed to avoid interrupt-related crashes when loading a new ; overlay on top of an old overlay in memory. ; ; All of the game's actual interrupt handling itself is done in the "hook" ; functions so that everything works the same if the System Card is banked ; into MPR7 when an interrupt occurs. ; ; *************************************************************************** ; *************************************************************************** ; ; Bit settings for irq_vec ... ; ; 7 : 1 to skip BIOS hsync processsing ; 6 : 1 to call [hsync_hook] ; 5 : 1 to skip BIOS vsync processsing ; 4 : 1 to call [vsync_hook] ; ; 3 : 1 to jump [nmi_hook] ; 2 : 1 to jump [timer_hook] ; 1 : 1 to jump [irq1_hook] ; 0 : 1 to jump [irq2_hook] ; ; *************************************************************************** ; *************************************************************************** core_irq2: bbs0 core_sw_reset sta.h reset_hook lda #irq1_handler sta.h irq1_hook lda #tirq_handler sta.h timer_hook lda #%00000110 ; Replace the System Card's sta = $4000) ; If not running in RAM, then .bss ; put these variables in RAM. .endif sound_mutex: ds 1 ; NZ when controller port busy. .if SUPPORT_SGX sgx_detected: ds 1 ; NZ if SuperGrafx detected. hsync_hook_sgx: ds 2 ; SGX version of hsync_hook. .endif .if SUPPORT_ACD acd_detected: ds 1 ; NZ if ArcadeCard detected. .endif .if (core_kernel >= $4000) .code .endif