Remove CurrentBank as game runs in NMI handler only

refactor
Christophe Parent 2023-12-28 00:36:20 -08:00
parent 23ac63a261
commit 9711b4ecc1
1 changed files with 10 additions and 17 deletions

View File

@ -532,7 +532,6 @@ AltRegContentFlag = $07ca
; mapper specific defines ; mapper specific defines
CurrentBank = $15 ; The mapper is read-only; need to track its state separately
CharsCopy = $41 ; Reserving $41 and $42 CharsCopy = $41 ; Reserving $41 and $42
XStore = $43 ; To store the X register XStore = $43 ; To store the X register
@ -868,7 +867,7 @@ SkipMainOper:
pla pla
ora #%10000000 ; reactivate NMIs ora #%10000000 ; reactivate NMIs
sta PPU_CTRL_REG1 sta PPU_CTRL_REG1
rts ; we are done until the next frame! rti ; we are done until the next frame!
;------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------
@ -17309,24 +17308,21 @@ StartBankSwitch:
jsr BankSwitch jsr BankSwitch
jmp Start jmp Start
; We make sure to have Bank 0 loaded at NMI, as the NMI code is located there; we switch back to the saved bank when we are done ; We make sure to have Bank 0 loaded at NMI, as the NMI code is located there
NonMaskableInterruptBankSwitch: NonMaskableInterruptBankSwitch:
ldx #$00 ldx #$00
jsr BankSwitchNoSave jsr BankSwitch
jsr NonMaskableInterrupt jmp NonMaskableInterrupt
ldx CurrentBank
jsr BankSwitchNoSave
rti
; Area data is located in Bank 1; we switch back to Bank 0 when we are done ; Area data is located in Bank 1; we switch back to Bank 0 when we are done
AreaDataBankSwitch: AreaDataBankSwitch:
stx XStore ; We need to save the value of X because X is used for bank switching stx XStore ; We need to save the value of X because X is used for bank switching
ldx #$01 ldx #$01
jsr BankSwitchNoSave jsr BankSwitch
lda (AreaData),y lda (AreaData),y
pha ; We need to save the byte because A is used for bank switching pha ; We need to save the byte because A is used for bank switching
ldx #$00 ldx #$00
jsr BankSwitchNoSave jsr BankSwitch
pla pla
ldx XStore ldx XStore
rts rts
@ -17335,11 +17331,11 @@ AreaDataBankSwitch:
EnemyDataBankSwitch: EnemyDataBankSwitch:
stx XStore ; We need to save the value of X because X is used for bank switching stx XStore ; We need to save the value of X because X is used for bank switching
ldx #$01 ldx #$01
jsr BankSwitchNoSave jsr BankSwitch
lda (EnemyData),y lda (EnemyData),y
pha ; We need to save the byte because A is used for bank switching pha ; We need to save the byte because A is used for bank switching
ldx #$00 ldx #$00
jsr BankSwitchNoSave jsr BankSwitch
pla pla
ldx XStore ldx XStore
rts rts
@ -17356,16 +17352,13 @@ CopyCharsBankSwitch:
; The sound engine is located in Bank 2; we switch back to Bank 0 when we are done ; The sound engine is located in Bank 2; we switch back to Bank 0 when we are done
SoundEngineBankSwitch: SoundEngineBankSwitch:
ldx #$02 ldx #$02
jsr BankSwitchNoSave jsr BankSwitch
jsr SoundEngine jsr SoundEngine
ldx #$00 ldx #$00
jsr BankSwitchNoSave jsr BankSwitch
rts rts
BankSwitch: BankSwitch:
stx CurrentBank ; save the current bank in RAM so the NMI handler can restore it
BankSwitchNoSave:
lda BankTable,x ; remap from the convenient banks numbered 0 through 2 to the value needed by the hardware lda BankTable,x ; remap from the convenient banks numbered 0 through 2 to the value needed by the hardware
sta BankTable,x ; and write it to the corresponding entry, switching banks sta BankTable,x ; and write it to the corresponding entry, switching banks
rts rts