Add banking helpers.

This commit is contained in:
Randy Thiemann 2023-10-25 07:21:48 +02:00
parent b384673e30
commit fd40ba2ecc
5 changed files with 61 additions and 11 deletions

Binary file not shown.

View File

@ -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

46
src/banking.asm Normal file
View File

@ -0,0 +1,46 @@
; DMGTRIS
; Copyright (C) 2023 - Randy Thiemann <randy.thiemann@gmail.com>
; 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 <https://www.gnu.org/licenses/>.
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

View File

@ -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

View File

@ -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