diff --git a/bin/DMGTRIS.GBC b/bin/DMGTRIS.GBC index 309339f..10e073a 100644 Binary files a/bin/DMGTRIS.GBC and b/bin/DMGTRIS.GBC differ diff --git a/src/bankid.asm b/src/bankid.asm index 71ba494..36a9c05 100644 --- a/src/bankid.asm +++ b/src/bankid.asm @@ -20,12 +20,21 @@ DEF BANKID_ASM EQU 1 SECTION "Bank ID 0", ROM0[$0] + REPT 7 + rst $00 + ENDR db $00 SECTION "Bank ID 1", ROMX[$4000], BANK[1] + REPT 7 + rst $00 + ENDR db $01 SECTION "Bank ID 2", ROMX[$4000], BANK[2] + REPT 7 + rst $00 + ENDR db $02 diff --git a/src/banking.asm b/src/banking.asm new file mode 100644 index 0000000..a0ee652 --- /dev/null +++ b/src/banking.asm @@ -0,0 +1,46 @@ +; DMGTRIS +; Copyright (C) 2023 - Randy Thiemann + +; This program is free software: you can redistribute it and/or modify +; it under the terms of the GNU General Public License as published by +; the Free Software Foundation, either version 3 of the License, or +; (at your option) any later version. + +; This program is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU General Public License for more details. + +; You should have received a copy of the GNU General Public License +; along with this program. If not, see . + + +IF !DEF(BANKING_ASM) +DEF BANKING_ASM EQU 1 + + +INCLUDE "globals.asm" + + +SECTION "High Banking Variables", HRAM +hBankBackup: ds 1 + +; 0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30, and 0x38 +SECTION "Switch Bank", ROM0[$08] + ; Saves the current bank and switches to the bank in b. +RSTSwitchBank:: + ld a, [rBANKID] + ldh [hBankBackup], a + ld a, b + ld [rROMB0], a + ret + +SECTION "Restore Bank", ROM0[$18] + ; Restore the bank previously saved. The current one is not saved. +RSTRestoreBank:: + ld a, [hBankBackup] + ld [rROMB0], a + ret + + +ENDC diff --git a/src/include/globals.asm b/src/include/globals.asm index c4f0e80..b8b270e 100644 --- a/src/include/globals.asm +++ b/src/include/globals.asm @@ -215,7 +215,7 @@ DEF FIELD_TOP_LEFT EQU $9800+1 DEF EASTER_0 EQU $9845 DEF EASTER_1 EQU $9865 -DEF rBANKID EQU $4000 +DEF rBANKID EQU $4007 ENDC diff --git a/src/sfx.asm b/src/sfx.asm index 4da20dd..2adc669 100644 --- a/src/sfx.asm +++ b/src/sfx.asm @@ -2432,10 +2432,8 @@ SFXKill:: ; This play routine must be called every frame. SFXPlay:: ; Bank to SFX bank. - ld a, [rBANKID] - ld e, a - ld a, BANK("SFX Data") - ld [rROMB0], a + ld b, BANK("SFX Data") + rst RSTSwitchBank ; Load the playhead position into HL. ldh a, [hPlayhead] @@ -2446,8 +2444,7 @@ SFXPlay:: ; Nothing to do if it's a null ptr. or a, l jr nz, .getRegister - ld a, e - ld [rROMB0], a + rst RSTRestoreBank ret ; Otherwise, get the register to write to. @@ -2458,8 +2455,7 @@ SFXPlay:: ; If it's $FE, then we're done. Check if there's more for us in the queue. cp a, $FE jr nz, :+ - ld a, e - ld [rROMB0], a + rst RSTRestoreBank call SFXProcessQueue ret @@ -2484,8 +2480,7 @@ SFXPlay:: ldh [hPlayhead], a ld a, h ldh [hPlayhead+1], a - ld a, e - ld [rROMB0], a + rst RSTRestoreBank ret