; SPDX-License-Identifier: MIT ; Bank-switch stubs, identical in all four banks at $xFC0. A store to a hotspot ; switches the bank, and the next instruction is fetched from the new bank at the ; same offset, so each jump below is only ever executed in the bank it names. ; F6 hotspots: $1FF6 bank 0, $1FF7 bank 1, $1FF8 bank 2, $1FF9 bank 3 ; (DOC: Kevin Horton's 2600 bankswitching document, prose description of F6). .macro STUBS Start_: sta $1FF6 ; $FC0 reset in any bank: go to bank 0 jmp Init ; $FC3 (runs in bank 0) ToTop_: sta $1FF7 ; $FC6 called from bank 0 jmp KernelTop ; $FC9 (runs in bank 1) ToTitle_: sta $1FF8 ; $FCC called from bank 0 jmp TitleKernel ; $FCF (runs in bank 2) ToLow_: sta $1FF9 ; $FD2 called from bank 0 jmp KernelLow ; $FD5 (runs in bank 3) ToLogic_: sta $1FF6 ; $FD8 jumped to from banks 1-3 rts ; $FDB (runs in bank 0) .res $FF6-$FDC, $00 .byte 0,0,0,0 ; $FF6-$FF9 hotspots .word $FFC0 ; NMI .word $FFC0 ; RESET .word $FFC0 ; IRQ/BRK .endmacro .segment "STUB0" .org $DFC0 .scope s0 STUBS .endscope .segment "STUB1" .org $FFC0 .scope s1 STUBS .endscope .segment "STUB2" .org $BFC0 .scope s2 STUBS .endscope .segment "STUB3" .org $9FC0 .scope s3 STUBS .endscope ; The callers use these fixed offsets (the same in every bank, linked per bank). ToTop = $DFC6 ; jsr from bank 0 ToTitle = $DFCC ToLow = $DFD2 ToLogic1 = $FFD8 ; jmp from bank 1 ToLogic2 = $BFD8 ; jmp from bank 2 ToLogic3 = $9FD8 ; jmp from bank 3 .assert s0::ToTop_ = ToTop, error, "stub layout" .assert s0::ToTitle_ = ToTitle, error, "stub layout" .assert s0::ToLow_ = ToLow, error, "stub layout" .assert s1::ToLogic_ = ToLogic1, error, "stub layout" .assert s2::ToLogic_ = ToLogic2, error, "stub layout" .assert s3::ToLogic_ = ToLogic3, error, "stub layout"