2020-06-17 14:03:38 -07:00
|
|
|
OpenSRAM::
|
2013-09-07 23:50:06 -07:00
|
|
|
; if invalid bank, sram is disabled
|
|
|
|
cp NUM_SRAM_BANKS
|
2020-06-17 14:03:38 -07:00
|
|
|
jr c, .valid
|
2020-07-13 10:05:05 -07:00
|
|
|
if DEF(_DEBUG)
|
|
|
|
push af
|
|
|
|
push bc
|
|
|
|
ld b, 1
|
|
|
|
.loop
|
|
|
|
sla b
|
|
|
|
dec a
|
|
|
|
jr nz, .loop
|
|
|
|
ld a, BANK(sOpenedInvalidSRAM)
|
|
|
|
call OpenSRAM
|
|
|
|
ld a, [sOpenedInvalidSRAM]
|
|
|
|
or b
|
|
|
|
ld [sOpenedInvalidSRAM], a
|
|
|
|
pop bc
|
|
|
|
pop af
|
|
|
|
endc
|
2013-09-07 23:50:06 -07:00
|
|
|
jr CloseSRAM
|
|
|
|
|
2020-06-17 14:03:38 -07:00
|
|
|
.valid:
|
2013-09-07 23:50:06 -07:00
|
|
|
; switch to sram bank a
|
|
|
|
push af
|
2023-07-27 15:07:07 -07:00
|
|
|
; enable sram write
|
2013-09-07 23:50:06 -07:00
|
|
|
ld a, SRAM_ENABLE
|
2023-07-31 09:52:47 -07:00
|
|
|
ld [MBC5SRamEnable], a
|
2013-09-07 23:50:06 -07:00
|
|
|
; select sram bank
|
|
|
|
pop af
|
2023-07-31 09:52:47 -07:00
|
|
|
ld [MBC5SRamBank], a
|
2013-09-07 23:50:06 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CloseSRAM::
|
2013-09-07 23:50:06 -07:00
|
|
|
push af
|
|
|
|
ld a, SRAM_DISABLE
|
2023-07-27 15:07:07 -07:00
|
|
|
; disable sram write
|
2023-07-31 09:52:47 -07:00
|
|
|
ld [MBC5SRamEnable], a
|
2013-09-07 23:50:06 -07:00
|
|
|
pop af
|
|
|
|
ret
|