ref: 94f32db7bc4a5e4e4d8837d3110d0876146783af
parent: d6f20ae74619fa4b3071867016fa7ae7253df98f
author: Adelaide Walter <[email protected]>
date: Mon Jan 8 17:48:58 EST 2018
Document hardcoded SRAM addresses.
--- a/engine/battle/checkbattlescene.asm
+++ b/engine/battle/checkbattlescene.asm
@@ -21,7 +21,7 @@
ld a, 4 ; MBC30 bank used by JP Crystal; inaccessible by MBC3
call GetSRAMBank
- ld a, [$a60c]
+ ld a, [$a60c] ; address of MBC30 bank
ld c, a
call CloseSRAM
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -234,7 +234,7 @@
MobileFn_3c1bf: mobile
ld a, 5 ; MBC30 bank used by JP Crystal; inaccessible by MBC3
call GetSRAMBank
- ld hl, $a89b ; s5_a89b
+ ld hl, $a89b ; address of MBC30 bank
inc [hl]
jr nz, .finish
dec hl
--- a/engine/mystery_gift.asm
+++ b/engine/mystery_gift.asm
@@ -1563,10 +1563,10 @@
inc de
ld a, 4 ; MBC30 bank used by JP Crystal; inaccessible by MBC3
call GetSRAMBank
- ld hl, $a603
+ ld hl, $a603 ; address of MBC30 bank
ld bc, $8
call CopyBytes
- ld hl, $a007
+ ld hl, $a007 ; address of MBC30 bank
ld bc, $c
call CopyBytes
call CloseSRAM
--- a/engine/rtc.asm
+++ b/engine/rtc.asm
@@ -148,12 +148,12 @@
; mobile
ld a, 5 ; MBC30 bank used by JP Crystal; inaccessible by MBC3
call GetSRAMBank
- ld a, [$aa8c]
+ ld a, [$aa8c] ; address of MBC30 bank
inc a
- ld [$aa8c], a
- ld a, [$b2fa]
+ ld [$aa8c], a ; address of MBC30 bank
+ ld a, [$b2fa] ; address of MBC30 bank
inc a
- ld [$b2fa], a
+ ld [$b2fa], a ; address of MBC30 bank
call CloseSRAM
ret
--- a/engine/save.asm
+++ b/engine/save.asm
@@ -421,7 +421,7 @@
ld a, 4 ; MBC30 bank used by JP Crystal; inaccessible by MBC3
call GetSRAMBank
ld hl, .Data
- ld de, $a007
+ ld de, $a007 ; address of MBC30 bank
ld bc, .DataEnd - .Data
call CopyBytes
jp CloseSRAM
@@ -456,7 +456,7 @@
; XXX
ld a, 4 ; MBC30 bank used by JP Crystal; inaccessible by MBC3
call GetSRAMBank
- ld a, [$a60b]
+ ld a, [$a60b] ; address of MBC30 bank
ld b, $0
and a
jr z, .ok
@@ -464,7 +464,7 @@
.ok
ld a, b
- ld [$a60b], a
+ ld [$a60b], a ; address of MBC30 bank
call CloseSRAM
ret
; 14d83
@@ -474,8 +474,8 @@
ld a, 4 ; MBC30 bank used by JP Crystal; inaccessible by MBC3
call GetSRAMBank
xor a
- ld [$a60c], a
- ld [$a60d], a
+ ld [$a60c], a ; address of MBC30 bank
+ ld [$a60d], a ; address of MBC30 bank
call CloseSRAM
ret
; 14d93
@@ -485,7 +485,7 @@
ld a, 7 ; MBC30 bank used by JP Crystal; inaccessible by MBC3
call GetSRAMBank
xor a
- ld [$a000], a
+ ld [$a000], a ; address of MBC30 bank
call CloseSRAM
ret
; 14da0
@@ -873,6 +873,11 @@
_SaveData: ; 1509a
+ ; This is called within two scenarios:
+ ; a) ErasePreviousSave (the process of erasing the save from a previous game file)
+ ; b) unused mobile functionality
+ ; It is not part of a regular save.
+
ld a, BANK(sCrystalData)
call GetSRAMBank
ld hl, wCrystalData
@@ -880,7 +885,11 @@
ld bc, wCrystalDataEnd - wCrystalData
call CopyBytes
- ; XXX SRAM bank 7
+ ; This block originally had some mobile functionality, but since we're still in
+ ; BANK(sCrystalData), it instead overwrites the sixteen EventFlags starting at 1:a603 with
+ ; garbage from wd479. This isn't an issue, since ErasePreviousSave is followed by a regular
+ ; save that unwrites the garbage.
+
ld hl, wd479
ld a, [hli]
ld [$a60e + 0], a
@@ -897,8 +906,10 @@
ld de, wCrystalData
ld bc, wCrystalDataEnd - wCrystalData
call CopyBytes
-
- ; XXX SRAM bank 7
+
+ ; This block originally had some mobile functionality to mirror _SaveData above, but instead it
+ ; (harmlessly) writes the aforementioned EventFlags to the unused wd479.
+
ld hl, wd479
ld a, [$a60e + 0]
ld [hli], a