Add comments to bank switching

refactor
Christophe Parent 2023-12-26 19:03:13 -08:00
parent 3df5a940a4
commit 23ac63a261
1 changed files with 23 additions and 11 deletions

View File

@ -24,7 +24,7 @@ JOYPAD_PORT = $4016
JOYPAD_PORT1 = $4016 JOYPAD_PORT1 = $4016
JOYPAD_PORT2 = $4017 JOYPAD_PORT2 = $4017
; GAME SPECIFIC DEFINES ; game specific defines
ObjectOffset = $08 ObjectOffset = $08
@ -530,6 +530,8 @@ PauseModeFlag = $07c6
GroundMusicHeaderOfs = $07c7 GroundMusicHeaderOfs = $07c7
AltRegContentFlag = $07ca AltRegContentFlag = $07ca
; mapper specific defines
CurrentBank = $15 ; The mapper is read-only; need to track its state separately 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
@ -652,6 +654,7 @@ VictoryModeValue = 2
GameOverModeValue = 3 GameOverModeValue = 3
;------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------
; HEADER DEFINITION
.segment "HEADER" .segment "HEADER"
@ -4804,10 +4807,10 @@ AreaDataAddrHigh:
.byte >L_GroundArea22, >L_UndergroundArea1, >L_UndergroundArea2, >L_UndergroundArea3, >L_CastleArea1 .byte >L_GroundArea22, >L_UndergroundArea1, >L_UndergroundArea2, >L_UndergroundArea3, >L_CastleArea1
.byte >L_CastleArea2, >L_CastleArea3, >L_CastleArea4, >L_CastleArea5, >L_CastleArea6 .byte >L_CastleArea2, >L_CastleArea3, >L_CastleArea4, >L_CastleArea5, >L_CastleArea6
.segment "ENEMYDATA"
; ENEMY OBJECT DATA ; ENEMY OBJECT DATA
.segment "ENEMYDATA"
; level 1-4/6-4 ; level 1-4/6-4
E_CastleArea1: E_CastleArea1:
.byte $76, $dd, $bb, $4c, $ea, $1d, $1b, $cc, $56, $5d .byte $76, $dd, $bb, $4c, $ea, $1d, $1b, $cc, $56, $5d
@ -5055,10 +5058,10 @@ E_WaterArea3:
.byte $56, $07, $88, $1b, $07, $9d, $2e, $65, $f0 .byte $56, $07, $88, $1b, $07, $9d, $2e, $65, $f0
.byte $ff .byte $ff
.segment "AREADATA"
; AREA OBJECT DATA ; AREA OBJECT DATA
.segment "AREADATA"
; level 1-4/6-4 ; level 1-4/6-4
L_CastleArea1: L_CastleArea1:
.byte $9b, $07 .byte $9b, $07
@ -17296,14 +17299,17 @@ BrickShatterEnvData:
.byte $1a, $1a, $1c, $1d, $1d, $1e, $1e, $1f .byte $1a, $1a, $1c, $1d, $1d, $1e, $1e, $1f
;------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------
; BANK SWITCHING
.segment "BANKSWITCH" .segment "BANKSWITCH"
; We make sure to have Bank 0 loaded on startup, as the startup code is located there
StartBankSwitch: StartBankSwitch:
ldx #$00 ldx #$00
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
NonMaskableInterruptBankSwitch: NonMaskableInterruptBankSwitch:
ldx #$00 ldx #$00
jsr BankSwitchNoSave jsr BankSwitchNoSave
@ -17312,30 +17318,33 @@ NonMaskableInterruptBankSwitch:
jsr BankSwitchNoSave jsr BankSwitchNoSave
rti rti
; Area data is located in Bank 1; we switch back to Bank 0 when we are done
AreaDataBankSwitch: AreaDataBankSwitch:
stx XStore stx XStore ; We need to save the value of X because X is used for bank switching
ldx #$01 ldx #$01
jsr BankSwitchNoSave jsr BankSwitchNoSave
lda (AreaData),y lda (AreaData),y
pha pha ; We need to save the byte because A is used for bank switching
ldx #$00 ldx #$00
jsr BankSwitchNoSave jsr BankSwitchNoSave
pla pla
ldx XStore ldx XStore
rts rts
; Enemy data is located in Bank 1; we switch back to Bank 0 when we are done
EnemyDataBankSwitch: EnemyDataBankSwitch:
stx XStore stx XStore ; We need to save the value of X because X is used for bank switching
ldx #$01 ldx #$01
jsr BankSwitchNoSave jsr BankSwitchNoSave
lda (EnemyData),y lda (EnemyData),y
pha pha ; We need to save the byte because A is used for bank switching
ldx #$00 ldx #$00
jsr BankSwitchNoSave jsr BankSwitchNoSave
pla pla
ldx XStore ldx XStore
rts rts
; Graphic tiles and the graphics init copy routine are located in Bank 2; we switch back to Bank 0 when we are done
CopyCharsBankSwitch: CopyCharsBankSwitch:
ldx #$02 ldx #$02
jsr BankSwitch jsr BankSwitch
@ -17344,6 +17353,7 @@ CopyCharsBankSwitch:
jsr BankSwitch jsr BankSwitch
rts rts
; 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 BankSwitchNoSave
@ -17361,18 +17371,19 @@ BankSwitchNoSave:
rts rts
BankTable: BankTable:
.byte $00, $01, $02 .byte $00, $01, $02 ; No need for Bank 3 here
;------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------
; INTERRUPT VECTORS
.segment "VECTORS" .segment "VECTORS"
; INTERRUPT VECTORS
.addr NonMaskableInterruptBankSwitch .addr NonMaskableInterruptBankSwitch
.addr StartBankSwitch .addr StartBankSwitch
.addr $fff0 ; unused .addr $fff0 ; unused
;------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------
; INSERTION OF GRAPHIC TILES
.segment "CHARS" .segment "CHARS"
@ -17380,6 +17391,7 @@ Chars:
.incbin "chars.bin" .incbin "chars.bin"
;------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------
; GRAPHICS INIT LOADING
.segment "COPYCHARS" .segment "COPYCHARS"