Skip to content

Commit

Permalink
Document hardcoded SRAM addresses.
Browse files Browse the repository at this point in the history
  • Loading branch information
CuriouserThing committed Jan 9, 2018
1 parent d6f20ae commit 94f32db
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion engine/battle/checkbattlescene.asm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CheckBattleScene: ; 4ea44

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

Expand Down
2 changes: 1 addition & 1 deletion engine/battle/core.asm
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ BattleTurn: ; 3c12f
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
Expand Down
4 changes: 2 additions & 2 deletions engine/mystery_gift.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1563,10 +1563,10 @@ Function10578c: ; 10578c (41:578c)
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
Expand Down
8 changes: 4 additions & 4 deletions engine/rtc.asm
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ Function140ae: ; 140ae
; 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

Expand Down
29 changes: 20 additions & 9 deletions engine/save.asm
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ Function14d18: ; 14d18
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
Expand Down Expand Up @@ -456,15 +456,15 @@ Function14d6c: ; 14d6c
; 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
ld b, $2

.ok
ld a, b
ld [$a60b], a
ld [$a60b], a ; address of MBC30 bank
call CloseSRAM
ret
; 14d83
Expand All @@ -474,8 +474,8 @@ Function14d83: ; 14d83
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
Expand All @@ -485,7 +485,7 @@ Function14d93: ; 14d93
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
Expand Down Expand Up @@ -873,14 +873,23 @@ VerifyBackupChecksum: ; 1507c (5:507c)


_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
ld de, sCrystalData
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
Expand All @@ -897,8 +906,10 @@ _LoadData: ; 150b9
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
Expand Down

0 comments on commit 94f32db

Please sign in to comment.