Label and constant cleanup (#528)

* Label cleanup, add some constants instead of raw numbers

* Rename load/save game functions to be more explicit
This commit is contained in:
Narishma-gb
2025-09-03 17:56:09 +02:00
committed by GitHub
parent d98b5e6f02
commit 4d2594cb24
30 changed files with 236 additions and 229 deletions

View File

@@ -49,6 +49,7 @@ DEF BIT_NO_PREVIOUS_MAP EQU 7
; wCurrentBoxNum
DEF BIT_HAS_CHANGED_BOXES EQU 7
DEF BOX_NUM_MASK EQU %01111111
; wObtainedBadges, wBeatGymFlags
const_def
@@ -153,3 +154,6 @@ DEF NUM_BADGES EQU const_value
const_def
const BIT_PLAYER_LOWER_Y ; 0
const BIT_PLAYER_LOWER_X ; 1
; rLCDC
DEF LCDC_DEFAULT EQU LCDC_ON | LCDC_WIN_9C00 | LCDC_WIN_ON | LCDC_BLOCK21 | LCDC_BG_9800 | LCDC_OBJ_8 | LCDC_OBJ_ON | LCDC_BG_ON

View File

@@ -1,6 +1,6 @@
object_const_def
const_export ROUTE2_OAKS_AIDE
const_export ROUTE2_YOUNGSTER
const_export ROUTE2GATE_OAKS_AIDE
const_export ROUTE2GATE_YOUNGSTER
Route2Gate_Object:
db $a ; border block

View File

@@ -53,7 +53,7 @@ PredefPointers::
add_predef DoubleOrHalveSelectedStats
add_predef ShowPokedexMenu
add_predef EvolutionAfterBattle
add_predef SaveSAVtoSRAM0
add_predef SaveMainData
add_predef InitOpponent
add_predef CableClub_Run
add_predef DrawBadges
@@ -73,7 +73,7 @@ PredefPointers::
add_predef UsedCut
add_predef ShowPokedexData
add_predef WriteMonMoves
add_predef SaveSAV
add_predef SaveMenu
add_predef LoadSGB
add_predef MarkTownVisitedAndLoadMissableObjects
add_predef SetPartyMonTypes
@@ -90,10 +90,10 @@ PredefPointers::
add_predef EmptyFunc ; return immediately
add_predef AskName
add_predef PewterGuys
add_predef SaveSAVtoSRAM2
add_predef LoadSAV2
add_predef LoadSAV
add_predef SaveSAVtoSRAM1
add_predef SavePartyAndDexData
add_predef LoadPartyAndDexData
add_predef TryLoadSaveFile
add_predef SaveCurrentBoxData
add_predef DoInGameTradeDialogue
add_predef HallOfFamePC
add_predef DisplayDexRating

View File

@@ -3137,30 +3137,30 @@ PlayerCalcMoveDamage:
jp c, .moveHitTest ; SetDamageEffects moves (e.g. Seismic Toss and Super Fang) skip damage calculation
call CriticalHitTest
call HandleCounterMove
jr z, handleIfPlayerMoveMissed
jr z, HandleIfPlayerMoveMissed
call GetDamageVarsForPlayerAttack
call CalculateDamage
jp z, playerCheckIfFlyOrChargeEffect ; for moves with 0 BP, skip any further damage calculation and, for now, skip MoveHitTest
jp z, PlayerCheckIfFlyOrChargeEffect ; for moves with 0 BP, skip any further damage calculation and, for now, skip MoveHitTest
; for these moves, accuracy tests will only occur if they are called as part of the effect itself
call AdjustDamageForMoveType
call RandomizeDamage
.moveHitTest
call MoveHitTest
handleIfPlayerMoveMissed:
HandleIfPlayerMoveMissed:
ld a, [wMoveMissed]
and a
jr z, getPlayerAnimationType
jr z, GetPlayerAnimationType
ld a, [wPlayerMoveEffect]
sub EXPLODE_EFFECT
jr z, playPlayerMoveAnimation ; don't play any animation if the move missed, unless it was EXPLODE_EFFECT
jr playerCheckIfFlyOrChargeEffect
getPlayerAnimationType:
jr z, PlayPlayerMoveAnimation ; don't play any animation if the move missed, unless it was EXPLODE_EFFECT
jr PlayerCheckIfFlyOrChargeEffect
GetPlayerAnimationType:
ld a, [wPlayerMoveEffect]
and a
ld a, ANIMATIONTYPE_BLINK_ENEMY_MON_SPRITE ; move has no effect other than dealing damage
jr z, playPlayerMoveAnimation
jr z, PlayPlayerMoveAnimation
ld a, ANIMATIONTYPE_SHAKE_SCREEN_HORIZONTALLY_LIGHT ; move has effect
playPlayerMoveAnimation:
PlayPlayerMoveAnimation:
push af
ld a, [wPlayerBattleStatus2]
bit HAS_SUBSTITUTE_UP, a
@@ -3179,7 +3179,7 @@ playPlayerMoveAnimation:
ld b, BANK(ReshowSubstituteAnim)
call nz, Bankswitch
jr MirrorMoveCheck
playerCheckIfFlyOrChargeEffect:
PlayerCheckIfFlyOrChargeEffect:
ld c, 30
call DelayFrames
ld a, [wPlayerMoveEffect]
@@ -3246,7 +3246,7 @@ MirrorMoveCheck:
ld a, [wPlayerNumAttacksLeft]
dec a
ld [wPlayerNumAttacksLeft], a
jp nz, getPlayerAnimationType ; for multi-hit moves, apply attack until PlayerNumAttacksLeft hits 0 or the enemy faints.
jp nz, GetPlayerAnimationType ; for multi-hit moves, apply attack until PlayerNumAttacksLeft hits 0 or the enemy faints.
; damage calculation and accuracy tests only happen for the first hit
res ATTACKING_MULTIPLE_TIMES, [hl] ; clear attacking multiple times status when all attacks are over
ld hl, MultiHitText
@@ -3523,7 +3523,7 @@ CheckPlayerStatusConditions:
ld [hl], a
ld a, BIDE
ld [wPlayerMoveNum], a
ld hl, handleIfPlayerMoveMissed ; skip damage calculation, DecrementPP and MoveHitTest
ld hl, HandleIfPlayerMoveMissed ; skip damage calculation, DecrementPP and MoveHitTest
jp .returnToHL
.ThrashingAboutCheck
@@ -3557,7 +3557,7 @@ CheckPlayerStatusConditions:
ld a, [wPlayerNumAttacksLeft]
dec a ; did multi-turn move end?
ld [wPlayerNumAttacksLeft], a
ld hl, getPlayerAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit),
ld hl, GetPlayerAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit),
; DecrementPP and MoveHitTest
jp nz, .returnToHL
jp .returnToHL
@@ -5567,7 +5567,7 @@ RandomizeDamage:
.loop
call BattleRandom
rrca
cp 217
cp 85 percent + 1
jr c, .loop
ldh [hMultiplier], a
call Multiply ; multiply damage by the random number, which is in the range [217, 255]
@@ -5660,7 +5660,7 @@ EnemyCalcMoveDamage:
jp c, EnemyMoveHitTest
call CriticalHitTest
call HandleCounterMove
jr z, handleIfEnemyMoveMissed
jr z, HandleIfEnemyMoveMissed
call SwapPlayerAndEnemyLevels
call GetDamageVarsForEnemyAttack
call SwapPlayerAndEnemyLevels
@@ -5671,13 +5671,13 @@ EnemyCalcMoveDamage:
EnemyMoveHitTest:
call MoveHitTest
handleIfEnemyMoveMissed:
HandleIfEnemyMoveMissed:
ld a, [wMoveMissed]
and a
jr z, .moveDidNotMiss
ld a, [wEnemyMoveEffect]
cp EXPLODE_EFFECT
jr z, handleExplosionMiss
jr z, HandleExplosionMiss
jr EnemyCheckIfFlyOrChargeEffect
.moveDidNotMiss
call SwapPlayerAndEnemyLevels
@@ -5686,13 +5686,13 @@ GetEnemyAnimationType:
ld a, [wEnemyMoveEffect]
and a
ld a, ANIMATIONTYPE_SHAKE_SCREEN_VERTICALLY
jr z, playEnemyMoveAnimation
jr z, PlayEnemyMoveAnimation
ld a, ANIMATIONTYPE_SHAKE_SCREEN_HORIZONTALLY_HEAVY
jr playEnemyMoveAnimation
handleExplosionMiss:
jr PlayEnemyMoveAnimation
HandleExplosionMiss:
call SwapPlayerAndEnemyLevels
xor a
playEnemyMoveAnimation:
PlayEnemyMoveAnimation:
push af
ld a, [wEnemyBattleStatus2]
bit HAS_SUBSTITUTE_UP, a ; does mon have a substitute?
@@ -6031,7 +6031,7 @@ CheckEnemyStatusConditions:
ld a, BIDE
ld [wEnemyMoveNum], a
call SwapPlayerAndEnemyLevels
ld hl, handleIfEnemyMoveMissed ; skip damage calculation, DecrementPP and MoveHitTest
ld hl, HandleIfEnemyMoveMissed ; skip damage calculation, DecrementPP and MoveHitTest
jp .enemyReturnToHL
.checkIfThrashingAbout
bit THRASHING_ABOUT, [hl] ; is mon using thrash or petal dance?
@@ -6881,12 +6881,12 @@ _InitBattleCommon:
call PrintText
call SaveScreenTilesToBuffer1
call ClearScreen
ld a, $98
ld a, HIGH(vBGMap0)
ldh [hAutoBGTransferDest + 1], a
ld a, $1
ldh [hAutoBGTransferEnabled], a
call Delay3
ld a, $9c
ld a, HIGH(vBGMap1)
ldh [hAutoBGTransferDest + 1], a
call LoadScreenTilesFromBuffer1
hlcoord 9, 7

View File

@@ -7,9 +7,9 @@ _JumpMoveEffect:
ldh a, [hWhoseTurn]
and a
ld a, [wPlayerMoveEffect]
jr z, .next1
jr z, .next
ld a, [wEnemyMoveEffect]
.next1
.next
dec a ; subtract 1, there is no special effect for 00
add a ; x2, 16bit pointers
ld hl, MoveEffectPointerTable
@@ -680,14 +680,14 @@ UpdateLoweredStatDone:
call PrintStatText
pop de
ld a, [de]
cp $44
cp ATTACK_DOWN_SIDE_EFFECT ; for all side effects, move animation has already played, skip it
jr nc, .ApplyBadgeBoostsAndStatusPenalties
call PlayCurrentMoveAnimation2
.ApplyBadgeBoostsAndStatusPenalties
ldh a, [hWhoseTurn]
and a
call nz, ApplyBadgeStatBoosts ; whenever the player uses a stat-down move, badge boosts get reapplied again to every stat,
; even to those not affected by the stat-up move (will be boosted further)
; even to those not affected by the stat-down move (will be boosted further)
ld hl, MonsStatsFellText
call PrintText
@@ -1438,9 +1438,9 @@ CheckTargetSubstitute:
ld hl, wEnemyBattleStatus2
ldh a, [hWhoseTurn]
and a
jr z, .next1
jr z, .next
ld hl, wPlayerBattleStatus2
.next1
.next
bit HAS_SUBSTITUTE_UP, [hl]
pop hl
ret

View File

@@ -20,7 +20,7 @@ _GivePokemon::
callfar SendNewMonToBox
ld hl, wStringBuffer
ld a, [wCurrentBoxNum]
and $7f
and BOX_NUM_MASK
cp 9
jr c, .singleDigitBoxNum
sub 9

View File

@@ -2,12 +2,12 @@ CeladonPrizeMenu::
ld b, COIN_CASE
call IsItemInBag
jr nz, .havingCoinCase
ld hl, RequireCoinCaseTextPtr
ld hl, RequireCoinCaseText
jp PrintText
.havingCoinCase
ld hl, wStatusFlags5
set BIT_NO_TEXT_DELAY, [hl]
ld hl, ExchangeCoinsForPrizesTextPtr
ld hl, ExchangeCoinsForPrizesText
call PrintText
; the following are the menu settings
xor a
@@ -28,7 +28,7 @@ CeladonPrizeMenu::
call TextBoxBorder
call GetPrizeMenuId
call UpdateSprites
ld hl, WhichPrizeTextPtr
ld hl, WhichPrizeText
call PrintText
call HandleMenuInput ; menu choice handler
bit B_PAD_B, a
@@ -42,16 +42,16 @@ CeladonPrizeMenu::
res BIT_NO_TEXT_DELAY, [hl]
ret
RequireCoinCaseTextPtr:
RequireCoinCaseText:
text_far _RequireCoinCaseText
text_waitbutton
text_end
ExchangeCoinsForPrizesTextPtr:
ExchangeCoinsForPrizesText:
text_far _ExchangeCoinsForPrizesText
text_end
WhichPrizeTextPtr:
WhichPrizeText:
text_far _WhichPrizeText
text_end

View File

@@ -523,15 +523,15 @@ CopyGfxToSuperNintendoVRAM:
call CopySGBBorderTiles
jr .next
.notCopyingTileData
ld bc, $1000
ld bc, 256 tiles
call CopyData
.next
ld hl, vBGMap0
ld de, $c
ld de, TILEMAP_WIDTH - SCREEN_WIDTH
ld a, $80
ld c, $d
ld c, (256 + SCREEN_WIDTH - 1) / SCREEN_WIDTH ; enough rows to fit 256 tiles
.loop
ld b, $14
ld b, SCREEN_WIDTH
.innerLoop
ld [hli], a
inc a
@@ -540,7 +540,7 @@ CopyGfxToSuperNintendoVRAM:
add hl, de
dec c
jr nz, .loop
ld a, $e3
ld a, LCDC_DEFAULT
ldh [rLCDC], a
pop hl
call SendSGBPacket

View File

@@ -861,7 +861,7 @@ TradeCenter_Trade:
hlcoord 1, 14
ld de, TradeCompleted
call PlaceString
predef SaveSAVtoSRAM2
predef SavePartyAndDexData ; this allows reset into Pokecenter
vc_hook Trade_save_game_end
ld c, 50
call DelayFrames

View File

@@ -64,7 +64,7 @@ CableClubNPC::
and a
jr nz, .choseNo
vc_hook Wireless_TryQuickSave_block_input
callfar SaveSAVtoSRAM
callfar SaveGameData
call WaitForSoundToFinish
ld a, SFX_SAVE
call PlaySoundWaitForCurrent

View File

@@ -69,7 +69,7 @@ DisplayTextIDInit::
add hl, de
dec c
jr nz, .spriteStandStillLoop
ld b, $9c ; window background address
ld b, HIGH(vBGMap1)
call CopyScreenTileBufferToVRAM ; transfer background in WRAM to VRAM
xor a
ldh [hWY], a ; put the window on the screen

View File

@@ -8,7 +8,7 @@ MainMenu:
call CheckForPlayerNameInSRAM
jr nc, .mainMenuLoop
predef LoadSAV
predef TryLoadSaveFile
.mainMenuLoop
ld c, 20
@@ -701,8 +701,9 @@ CheckForPlayerNameInSRAM:
; in carry.
ld a, RAMG_SRAM_ENABLE
ld [rRAMG], a
ld a, $1
ld a, BMODE_ADVANCED
ld [rBMODE], a
ASSERT BANK(sPlayerName) == BMODE_ADVANCED
ld [rRAMB], a
ld b, NAME_LENGTH
ld hl, sPlayerName

View File

@@ -1,16 +1,15 @@
LoadSAV:
; if carry, write "the file data is destroyed"
TryLoadSaveFile:
call ClearScreen
call LoadFontTilePatterns
call LoadTextBoxTilePatterns
call LoadSAV0
call LoadMainData
jr c, .badsum
call LoadSAV1
call LoadCurrentBoxData
jr c, .badsum
call LoadSAV2
call LoadPartyAndDexData
jr c, .badsum
ld a, $2 ; good checksum
jr .goodsum
jr .done
.badsum
ld hl, wStatusFlags5
push hl
@@ -22,7 +21,7 @@ LoadSAV:
pop hl
res BIT_NO_TEXT_DELAY, [hl]
ld a, $1 ; bad checksum
.goodsum
.done
ld [wSaveFileStatus], a
ret
@@ -30,33 +29,34 @@ FileDataDestroyedText:
text_far _FileDataDestroyedText
text_end
LoadSAV0:
LoadMainData:
ld a, RAMG_SRAM_ENABLE
ld [rRAMG], a
ld a, $1
ld a, BMODE_ADVANCED
ld [rBMODE], a
ASSERT BANK("Save Data") == BMODE_ADVANCED
ld [rRAMB], a
; This vc_hook does not have to be in any particular location.
; It is defined here because it refers to the same labels as the two lines below.
vc_hook Unknown_save_limit
ld hl, sGameData
ld bc, sGameDataEnd - sGameData
call SAVCheckSum
call CalcCheckSum
ld c, a
ld a, [sMainDataCheckSum]
cp c
jp z, .checkSumsMatched
jp z, .checkSumMatched
; If the computed checksum didn't match the saved on, try again.
ld hl, sGameData
ld bc, sGameDataEnd - sGameData
call SAVCheckSum
call CalcCheckSum
ld c, a
ld a, [sMainDataCheckSum]
cp c
jp nz, SAVBadCheckSum
jp nz, CheckSumFailed
.checkSumsMatched
.checkSumMatched
ld hl, sPlayerName
ld de, wPlayerName
ld bc, NAME_LENGTH
@@ -73,46 +73,51 @@ LoadSAV0:
call CopyData
ld a, [sTileAnimations]
ldh [hTileAnimations], a
; this part is redundant, LoadCurrentBoxData is always called next
ld hl, sCurBoxData
ld de, wBoxDataStart
ld bc, wBoxDataEnd - wBoxDataStart
call CopyData
and a
jp GoodCheckSum
LoadCurrentBoxData:
ld a, RAMG_SRAM_ENABLE
ld [rRAMG], a
ld a, BMODE_ADVANCED
ld [rBMODE], a
ASSERT BANK("Save Data") == BMODE_ADVANCED
ld [rRAMB], a
ld hl, sGameData
ld bc, sGameDataEnd - sGameData
call CalcCheckSum
ld c, a
ld a, [sMainDataCheckSum]
cp c
jr nz, CheckSumFailed
ld hl, sCurBoxData
ld de, wBoxDataStart
ld bc, wBoxDataEnd - wBoxDataStart
call CopyData
and a
jp SAVGoodChecksum
jp GoodCheckSum
LoadSAV1:
LoadPartyAndDexData:
ld a, RAMG_SRAM_ENABLE
ld [rRAMG], a
ld a, $1
ld a, BMODE_ADVANCED
ld [rBMODE], a
ASSERT BANK("Save Data") == BMODE_ADVANCED
ld [rRAMB], a
ld hl, sGameData
ld bc, sGameDataEnd - sGameData
call SAVCheckSum
call CalcCheckSum
ld c, a
ld a, [sMainDataCheckSum]
cp c
jr nz, SAVBadCheckSum
ld hl, sCurBoxData
ld de, wBoxDataStart
ld bc, wBoxDataEnd - wBoxDataStart
call CopyData
and a
jp SAVGoodChecksum
LoadSAV2:
ld a, RAMG_SRAM_ENABLE
ld [rRAMG], a
ld a, $1
ld [rBMODE], a
ld [rRAMB], a
ld hl, sGameData
ld bc, sGameDataEnd - sGameData
call SAVCheckSum
ld c, a
ld a, [sMainDataCheckSum]
cp c
jp nz, SAVBadCheckSum
jp nz, CheckSumFailed
ld hl, sPartyData
ld de, wPartyDataStart
ld bc, wPartyDataEnd - wPartyDataStart
@@ -122,40 +127,43 @@ LoadSAV2:
ld bc, wPokedexSeenEnd - wPokedexOwned
call CopyData
and a
jp SAVGoodChecksum
jp GoodCheckSum
SAVBadCheckSum:
CheckSumFailed:
scf
; fallthrough
SAVGoodChecksum:
ld a, $0
GoodCheckSum:
ld a, BMODE_SIMPLE ; preserve flags
ld [rBMODE], a
ASSERT RAMG_SRAM_DISABLE == BMODE_SIMPLE
ld [rRAMG], a
ret
LoadSAVIgnoreBadCheckSum:
; unused function that loads save data and ignores bad checksums
call LoadSAV0
call LoadSAV1
jp LoadSAV2
TryLoadSaveFileIgnoreChecksum: ; unreferenced
; don't update wSaveFileStatus upon success or failure
; don't display warning in case of failed checksum
call LoadMainData
call LoadCurrentBoxData
jp LoadPartyAndDexData
SaveSAV:
SaveMenu:
farcall PrintSaveScreenText
ld hl, WouldYouLikeToSaveText
call SaveSAVConfirm
call SaveTheGame_YesOrNo
and a ;|0 = Yes|1 = No|
ret nz
ld a, [wSaveFileStatus]
dec a
jr z, .save
call SAVCheckRandomID
call CheckPreviousSaveFile
jr z, .save
ld hl, OlderFileWillBeErasedText
call SaveSAVConfirm
call SaveTheGame_YesOrNo
and a
ret nz
.save
call SaveSAVtoSRAM
call SaveGameData
hlcoord 1, 13
lb bc, 4, 18
call ClearScreenArea
@@ -175,13 +183,13 @@ SaveSAV:
NowSavingString:
db "Now saving...@"
SaveSAVConfirm:
SaveTheGame_YesOrNo:
call PrintText
hlcoord 0, 7
lb bc, 8, 1
ld a, TWO_OPTION_MENU
ld [wTextBoxID], a
call DisplayTextBoxID ; yes/no menu
call DisplayTextBoxID
ld a, [wCurrentMenuItem]
ret
@@ -197,12 +205,14 @@ OlderFileWillBeErasedText:
text_far _OlderFileWillBeErasedText
text_end
SaveSAVtoSRAM0:
SaveMainData:
ld a, RAMG_SRAM_ENABLE
ld [rRAMG], a
ld a, $1
ld a, BMODE_ADVANCED
ld [rBMODE], a
ASSERT BANK("Save Data") == BMODE_ADVANCED
ld [rRAMB], a
ld hl, wPlayerName
ld de, sPlayerName
ld bc, NAME_LENGTH
@@ -216,26 +226,29 @@ SaveSAVtoSRAM0:
ld bc, wSpriteDataEnd - wSpriteDataStart
call CopyData
ld hl, wBoxDataStart
; this part is redundant, SaveCurrentBoxData is always called next
ld de, sCurBoxData
ld bc, wBoxDataEnd - wBoxDataStart
call CopyData
ldh a, [hTileAnimations]
ld [sTileAnimations], a
ld hl, sGameData
ld bc, sGameDataEnd - sGameData
call SAVCheckSum
call CalcCheckSum
ld [sMainDataCheckSum], a
xor a
ld [rBMODE], a
ld [rRAMG], a
ret
SaveSAVtoSRAM1:
; stored pokémon
SaveCurrentBoxData:
ld a, RAMG_SRAM_ENABLE
ld [rRAMG], a
ld a, $1
ld a, BMODE_ADVANCED
ld [rBMODE], a
ASSERT BANK("Save Data") == BMODE_ADVANCED
ld [rRAMB], a
ld hl, wBoxDataStart
ld de, sCurBoxData
@@ -243,18 +256,19 @@ SaveSAVtoSRAM1:
call CopyData
ld hl, sGameData
ld bc, sGameDataEnd - sGameData
call SAVCheckSum
call CalcCheckSum
ld [sMainDataCheckSum], a
xor a
ld [rBMODE], a
ld [rRAMG], a
ret
SaveSAVtoSRAM2:
SavePartyAndDexData:
ld a, RAMG_SRAM_ENABLE
ld [rRAMG], a
ld a, $1
ld a, BMODE_ADVANCED
ld [rBMODE], a
ASSERT BANK("Save Data") == BMODE_ADVANCED
ld [rRAMB], a
ld hl, wPartyDataStart
ld de, sPartyData
@@ -266,21 +280,21 @@ SaveSAVtoSRAM2:
call CopyData
ld hl, sGameData
ld bc, sGameDataEnd - sGameData
call SAVCheckSum
call CalcCheckSum
ld [sMainDataCheckSum], a
xor a
ld [rBMODE], a
ld [rRAMG], a
ret
SaveSAVtoSRAM::
SaveGameData::
ld a, $2
ld [wSaveFileStatus], a
call SaveSAVtoSRAM0
call SaveSAVtoSRAM1
jp SaveSAVtoSRAM2
call SaveMainData
call SaveCurrentBoxData
jp SavePartyAndDexData
SAVCheckSum:
CalcCheckSum:
;Check Sum (result[1 byte] is complemented)
ld d, 0
.loop
@@ -303,7 +317,7 @@ CalcIndividualBoxCheckSums:
push bc
push de
ld bc, wBoxDataEnd - wBoxDataStart
call SAVCheckSum
call CalcCheckSum
pop de
ld [de], a
inc de
@@ -317,7 +331,7 @@ GetBoxSRAMLocation:
; out: b = box SRAM bank, hl = pointer to start of box
ld hl, BoxSRAMPointerTable
ld a, [wCurrentBoxNum]
and $7f
and BOX_NUM_MASK
cp NUM_BOXES / 2
ld b, 2
jr c, .next
@@ -379,7 +393,7 @@ ChangeBox::
ld a, [hl]
ld [de], a
call RestoreMapTextPointer
call SaveSAVtoSRAM
call SaveGameData
ld hl, wChangeBoxSavedMapTextPointer
call SetMapTextPointer
ld a, SFX_SAVE
@@ -396,7 +410,7 @@ CopyBoxToOrFromSRAM:
push hl
ld a, RAMG_SRAM_ENABLE
ld [rRAMG], a
ld a, $1
ld a, BMODE_ADVANCED
ld [rBMODE], a
ld a, b
ld [rRAMB], a
@@ -404,7 +418,7 @@ CopyBoxToOrFromSRAM:
call CopyData
pop hl
; mark the memory that the box was copied from as am empty box
; mark the source box as an empty box
xor a
ld [hli], a
dec a
@@ -412,7 +426,7 @@ CopyBoxToOrFromSRAM:
ld hl, sBox1 ; sBox7
ld bc, sBank2AllBoxesChecksum - sBox1
call SAVCheckSum
call CalcCheckSum
ld [sBank2AllBoxesChecksum], a ; sBank3AllBoxesChecksum
call CalcIndividualBoxCheckSums
xor a
@@ -434,7 +448,7 @@ DisplayChangeBoxMenu:
xor a
ld [wMenuWatchMovingOutOfBounds], a
ld a, [wCurrentBoxNum]
and $7f
and BOX_NUM_MASK
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
hlcoord 0, 0
@@ -455,7 +469,7 @@ DisplayChangeBoxMenu:
ld hl, hUILayoutFlags
res BIT_SINGLE_SPACED_LINES, [hl]
ld a, [wCurrentBoxNum]
and $7f
and BOX_NUM_MASK
cp 9
jr c, .singleDigitBoxNum
sub 9
@@ -474,7 +488,7 @@ DisplayChangeBoxMenu:
hlcoord 18, 1
ld de, wBoxMonCounts
ld bc, SCREEN_WIDTH
ld a, $c
ld a, NUM_BOXES
.loop
push af
ld a, [de]
@@ -517,12 +531,12 @@ EmptyAllSRAMBoxes:
; player changes the box)
ld a, RAMG_SRAM_ENABLE
ld [rRAMG], a
ld a, $1
ld a, BMODE_ADVANCED
ld [rBMODE], a
ld a, 2
ld a, BANK("Saved Boxes 1")
ld [rRAMB], a
call EmptySRAMBoxesInBank
ld a, 3
ld a, BANK("Saved Boxes 2")
ld [rRAMB], a
call EmptySRAMBoxesInBank
xor a
@@ -546,7 +560,7 @@ EmptySRAMBoxesInBank:
call EmptySRAMBox
ld hl, sBox1 ; sBox7
ld bc, sBank2AllBoxesChecksum - sBox1
call SAVCheckSum
call CalcCheckSum
ld [sBank2AllBoxesChecksum], a ; sBank3AllBoxesChecksum
call CalcIndividualBoxCheckSums
ret
@@ -563,12 +577,12 @@ GetMonCountsForAllBoxes:
push hl
ld a, RAMG_SRAM_ENABLE
ld [rRAMG], a
ld a, $1
ld a, BMODE_ADVANCED
ld [rBMODE], a
ld a, $2
ld a, BANK("Saved Boxes 1")
ld [rRAMB], a
call GetMonCountsForBoxesInBank
ld a, $3
ld a, BANK("Saved Boxes 2")
ld [rRAMB], a
call GetMonCountsForBoxesInBank
xor a
@@ -578,7 +592,7 @@ GetMonCountsForAllBoxes:
; copy the count for the current box from WRAM
ld a, [wCurrentBoxNum]
and $7f
and BOX_NUM_MASK
ld c, a
ld b, 0
add hl, bc
@@ -602,25 +616,26 @@ GetMonCountsForBoxesInBank:
ld [hli], a
ret
SAVCheckRandomID:
; checks if Sav file is the same by checking player's name 1st letter
; and the two random numbers generated at game beginning
; (which are stored at wPlayerID)s
ld a, $0a
; check if we're trying to save over a different playthrough
; return result in zero flag
; z set: a valid save file was found, and saved PlayerID is different from wPlayerID
CheckPreviousSaveFile:
ld a, RAMG_SRAM_ENABLE
ld [rRAMG], a
ld a, $01
ld a, BMODE_ADVANCED
ld [rBMODE], a
ASSERT BANK("Save Data") == BMODE_ADVANCED
ld [rRAMB], a
ld a, [sPlayerName]
and a
jr z, .next
ld hl, sGameData
ld bc, sGameDataEnd - sGameData
call SAVCheckSum
call CalcCheckSum
ld c, a
ld a, [sMainDataCheckSum]
cp c
jr nz, .next
jr nz, .next ; return z set if save data is corrupted
ld hl, sMainData + (wPlayerID - wMainDataStart) ; player ID
ld a, [hli]
ld h, [hl]
@@ -631,8 +646,9 @@ SAVCheckRandomID:
ld a, [wPlayerID + 1]
cp h
.next
ld a, $00
ld a, BMODE_SIMPLE
ld [rBMODE], a
ASSERT RAMG_SRAM_DISABLE == BMODE_SIMPLE
ld [rRAMG], a
ret
@@ -674,7 +690,7 @@ LoadHallOfFameTeams:
HallOfFame_Copy:
ld a, RAMG_SRAM_ENABLE
ld [rRAMG], a
ld a, $1
ld a, BMODE_ADVANCED
ld [rBMODE], a
xor a
ld [rRAMB], a
@@ -684,25 +700,26 @@ HallOfFame_Copy:
ld [rRAMG], a
ret
ClearSAV:
; Fill SRAM with $ff, erasing save data. Used by DoClearSaveDialogue
ClearAllSRAMBanks:
ld a, RAMG_SRAM_ENABLE
ld [rRAMG], a
ld a, $1
ld a, BMODE_ADVANCED
ld [rBMODE], a
xor a
call PadSRAM_FF
ld a, $1
call PadSRAM_FF
ld a, $2
call PadSRAM_FF
ld a, $3
call PadSRAM_FF
call .PadSRAM_FF
ld a, 1
call .PadSRAM_FF
ld a, 2
call .PadSRAM_FF
ld a, 3
call .PadSRAM_FF
xor a
ld [rBMODE], a
ld [rRAMG], a
ret
PadSRAM_FF:
.PadSRAM_FF
ld [rRAMB], a
ld hl, STARTOF(SRAM)
ld bc, SIZEOF(SRAM)

View File

@@ -1,6 +1,6 @@
StartMenu_Pokedex::
predef ShowPokedexMenu
call LoadScreenTilesFromBuffer2 ; restore saved screen
call LoadScreenTilesFromBuffer2
call Delay3
call LoadGBPal
call UpdateSprites
@@ -63,7 +63,7 @@ StartMenu_Pokemon::
ld [hl], a
call HandleMenuInput
push af
call LoadScreenTilesFromBuffer1 ; restore saved screen
call LoadScreenTilesFromBuffer1
pop af
bit B_PAD_B, a
jp nz, .loop
@@ -117,7 +117,7 @@ StartMenu_Pokemon::
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wObtainedBadges] ; badges obtained
ld a, [wObtainedBadges]
jp hl
.outOfBattleMovePointers
dw .cut
@@ -286,7 +286,7 @@ StartMenu_Pokemon::
; writes a blank tile to all possible menu cursor positions on the party menu
ErasePartyMenuCursors::
hlcoord 0, 1
ld bc, 2 * 20 ; menu cursor positions are 2 rows apart
ld bc, 2 * SCREEN_WIDTH ; menu cursor positions are 2 rows apart
ld a, 6 ; 6 menu cursor positions
.loop
ld [hl], " "
@@ -296,7 +296,7 @@ ErasePartyMenuCursors::
ret
ItemMenuLoop:
call LoadScreenTilesFromBuffer2DisableBGTransfer ; restore saved screen
call LoadScreenTilesFromBuffer2DisableBGTransfer
call RunDefaultPaletteCommand
StartMenu_Item::
@@ -323,7 +323,7 @@ StartMenu_Item::
ld [wBagSavedMenuItem], a
jr nc, .choseItem
.exitMenu
call LoadScreenTilesFromBuffer2 ; restore saved screen
call LoadScreenTilesFromBuffer2
call LoadTextBoxTilePatterns
call UpdateSprites
jp RedisplayStartMenu
@@ -363,7 +363,7 @@ StartMenu_Item::
bit B_PAD_B, a
jr z, .useOrTossItem
jp ItemMenuLoop
.useOrTossItem ; if the player made the choice to use or toss the item
.useOrTossItem
ld a, [wCurItem]
ld [wNamedObjectIndex], a
call GetItemName
@@ -459,14 +459,14 @@ StartMenu_TrainerInfo::
xor a
ldh [hTileAnimations], a
call DrawTrainerInfo
predef DrawBadges ; draw badges
predef DrawBadges
ld b, SET_PAL_TRAINER_CARD
call RunPaletteCommand
call GBPalNormal
call WaitForTextScrollButtonPress ; wait for button press
call WaitForTextScrollButtonPress
call GBPalWhiteOut
call LoadFontTilePatterns
call LoadScreenTilesFromBuffer2 ; restore saved screen
call LoadScreenTilesFromBuffer2
call RunDefaultPaletteCommand
call ReloadMapData
call LoadGBPal
@@ -489,7 +489,7 @@ DrawTrainerInfo:
ld de, vChars2 tile $00
ld bc, $1c tiles
call CopyData
ld hl, TrainerInfoTextBoxTileGraphics ; trainer info text box tile patterns
ld hl, TrainerInfoTextBoxTileGraphics
ld de, vChars2 tile $77
ld bc, 8 tiles
push bc
@@ -499,10 +499,10 @@ DrawTrainerInfo:
ld bc, $17 tiles
call TrainerInfo_FarCopyData
pop bc
ld hl, BadgeNumbersTileGraphics ; badge number tile patterns
ld hl, BadgeNumbersTileGraphics
ld de, vChars1 tile $58
call TrainerInfo_FarCopyData
ld hl, GymLeaderFaceAndBadgeTileGraphics ; gym leader face and badge tile patterns
ld hl, GymLeaderFaceAndBadgeTileGraphics
ld de, vChars2 tile $20
ld bc, 8 * 8 tiles
ld a, BANK(GymLeaderFaceAndBadgeTileGraphics)
@@ -555,12 +555,12 @@ DrawTrainerInfo:
ld c, 3 | LEADING_ZEROES | LEFT_ALIGN | MONEY_SIGN
call PrintBCDNumber
hlcoord 9, 6
ld de, wPlayTimeHours ; hours
ld de, wPlayTimeHours
lb bc, LEFT_ALIGN | 1, 3
call PrintNumber
ld [hl], $d6 ; colon tile ID
inc hl
ld de, wPlayTimeMinutes ; minutes
ld de, wPlayTimeMinutes
lb bc, LEADING_ZEROES | 1, 2
jp PrintNumber
@@ -642,8 +642,8 @@ StartMenu_SaveReset::
ld a, [wStatusFlags4]
bit BIT_LINK_CONNECTED, a
jp nz, Init
predef SaveSAV ; save the game
call LoadScreenTilesFromBuffer2 ; restore saved screen
predef SaveMenu
call LoadScreenTilesFromBuffer2
jp HoldTextDisplayOpen
StartMenu_Option::
@@ -652,7 +652,7 @@ StartMenu_Option::
call ClearScreen
call UpdateSprites
callfar DisplayOptionMenu
call LoadScreenTilesFromBuffer2 ; restore saved screen
call LoadScreenTilesFromBuffer2
call LoadTextBoxTilePatterns
call UpdateSprites
jp RedisplayStartMenu

View File

@@ -7,7 +7,7 @@ AnimateHallOfFame:
call LoadTextBoxTilePatterns
call DisableLCD
ld hl, vBGMap0
ld bc, $800
ld bc, 2 * TILEMAP_AREA
ld a, " "
call FillMemory
call EnableLCD

View File

@@ -15,7 +15,7 @@ DoClearSaveDialogue:
ld a, [wCurrentMenuItem]
and a
jp z, Init
farcall ClearSAV
farcall ClearAllSRAMBanks
jp Init
ClearSaveDataText:

View File

@@ -356,7 +356,7 @@ DrawPlayerCharacter:
ClearBothBGMaps:
ld hl, vBGMap0
ld bc, $400 * 2
ld bc, 2 * TILEMAP_AREA
ld a, " "
jp FillMemory

View File

@@ -167,7 +167,7 @@ LoadTradingGFXAndMonNames:
ld a, BANK(TradingAnimationGraphics2)
call FarCopyData2
ld hl, vBGMap0
ld bc, $800
ld bc, 2 * TILEMAP_AREA
ld a, " "
call FillMemory
call ClearSprites
@@ -223,7 +223,7 @@ Trade_Cleanup:
ret
Trade_ShowPlayerMon:
ld a, %10101011
ld a, LCDC_ON | LCDC_WIN_9800 | LCDC_WIN_ON | LCDC_BLOCK21 | LCDC_BG_9C00 | LCDC_OBJ_8 | LCDC_OBJ_ON | LCDC_BG_ON
ldh [rLCDC], a
ld a, $50
ldh [hWY], a
@@ -279,7 +279,7 @@ Trade_DrawOpenEndOfLinkCable:
ld a, $a0
ldh [hSCX], a
call DelayFrame
ld a, %10001011
ld a, LCDC_ON | LCDC_WIN_9800 | LCDC_WIN_OFF | LCDC_BLOCK21 | LCDC_BG_9C00 | LCDC_OBJ_8 | LCDC_OBJ_ON | LCDC_BG_ON
ldh [rLCDC], a
hlcoord 6, 2
ld b, TILEMAP_LINK_CABLE
@@ -338,7 +338,7 @@ Trade_AnimateBallEnteringLinkCable:
ld a, $1
ldh [hAutoBGTransferEnabled], a
call ClearScreen
ld b, $98
ld b, HIGH(vBGMap0)
call CopyScreenTileBufferToVRAM
call Delay3
xor a
@@ -452,7 +452,7 @@ Trade_InitGameboyTransferGfx:
ldh [hAutoBGTransferEnabled], a
call Trade_LoadMonPartySpriteGfx
call DelayFrame
ld a, %10101011
ld a, LCDC_ON | LCDC_WIN_9800 | LCDC_WIN_ON | LCDC_BLOCK21 | LCDC_BG_9C00 | LCDC_OBJ_8 | LCDC_OBJ_ON | LCDC_BG_ON
ldh [rLCDC], a
xor a
ldh [hSCX], a
@@ -757,7 +757,7 @@ Trade_ShowClearedWindow:
ld a, $1
ldh [hAutoBGTransferEnabled], a
call ClearScreen
ld a, %11100011
ld a, LCDC_DEFAULT
ldh [rLCDC], a
ld a, $7
ldh [rWX], a

View File

@@ -15,9 +15,6 @@ MarkTownVisitedAndLoadMissableObjects::
add hl, bc
ld a, [hli] ; load missable objects pointer in hl
ld h, [hl]
; fall through
LoadMissableObjects:
ld l, a
push hl
ld de, MissableObjects ; calculate difference between out pointer and the base pointer

View File

@@ -151,7 +151,7 @@ BillsPCMenu:
ld c, 9
call TextBoxBorder
ld a, [wCurrentBoxNum]
and $7f
and BOX_NUM_MASK
cp 9
jr c, .singleDigitBoxNum
; two digit box num
@@ -236,7 +236,7 @@ BillsPCDeposit:
call WaitForSoundToFinish
ld hl, wBoxNumString
ld a, [wCurrentBoxNum]
and $7f
and BOX_NUM_MASK
cp 9
jr c, .singleDigitBoxNum
sub 9
@@ -538,6 +538,7 @@ JustAMomentText::
text_far _JustAMomentText
text_end
UnusedOpenBillsPC: ; unreferenced
ld a, [wSpritePlayerStateData1FacingDirection]
cp SPRITE_FACING_UP
ret nz

View File

@@ -427,7 +427,7 @@ StatusScreen2:
ld a, $1
ldh [hAutoBGTransferEnabled], a
call Delay3
call WaitForTextScrollButtonPress ; wait for button
call WaitForTextScrollButtonPress
pop af
ldh [hTileAnimations], a
ld hl, wStatusFlags2

View File

@@ -7,17 +7,6 @@ SoftReset::
Init::
; Program init.
; * LCD enabled
; * Window tile map at $9C00
; * Window display enabled
; * BG and window tile data at $8800
; * BG tile map at $9800
; * 8x8 OBJ size
; * OBJ display enabled
; * BG display enabled
DEF LCDC_DEFAULT EQU LCDC_ON | LCDC_WIN_9C00 | LCDC_WIN_ON | LCDC_BLOCK21 | LCDC_BG_9800 | LCDC_OBJ_8 | LCDC_OBJ_ON | LCDC_BG_ON
di
xor a
@@ -100,7 +89,7 @@ DEF LCDC_DEFAULT EQU LCDC_ON | LCDC_WIN_9C00 | LCDC_WIN_ON | LCDC_BLOCK21 | LCDC
ld a, BANK(SFX_Shooting_Star)
ld [wAudioROMBank], a
ld [wAudioSavedROMBank], a
ld a, $9c
ld a, HIGH(vBGMap1)
ldh [hAutoBGTransferDest + 1], a
xor a
ldh [hAutoBGTransferDest], a

View File

@@ -30,27 +30,25 @@ TextScript_ItemStoragePC::
call SaveScreenTilesToBuffer2
ld b, BANK(PlayerPC)
ld hl, PlayerPC
jr bankswitchAndContinue
jr BankswitchAndContinue
TextScript_BillsPC::
call SaveScreenTilesToBuffer2
ld b, BANK(BillsPC_)
ld hl, BillsPC_
jr bankswitchAndContinue
jr BankswitchAndContinue
TextScript_GameCornerPrizeMenu::
; XXX find a better name for this function
; special_F7
ld b, BANK(CeladonPrizeMenu)
ld hl, CeladonPrizeMenu
bankswitchAndContinue::
BankswitchAndContinue::
call Bankswitch
jp HoldTextDisplayOpen ; continue to main text-engine function
TextScript_PokemonCenterPC::
ld b, BANK(ActivatePC)
ld hl, ActivatePC
jr bankswitchAndContinue
jr BankswitchAndContinue
StartSimulatingJoypadStates::
xor a

View File

@@ -114,7 +114,7 @@ OverworldLoopLessDelay::
ld [wEnteringCableClub], a
jr z, .changeMap
; XXX can this code be reached?
predef LoadSAV
predef TryLoadSaveFile
ld a, [wCurMap]
ld [wDestinationMap], a
call PrepareForSpecialWarp

View File

@@ -84,7 +84,7 @@ ENDM
dict TX_SCRIPT_PRIZE_VENDOR, TextScript_GameCornerPrizeMenu
dict2 TX_SCRIPT_CABLE_CLUB_RECEPTIONIST, callfar CableClubNPC
call PrintText_NoCreatingTextBox ; display the text
call PrintText_NoCreatingTextBox
ld a, [wDoNotWaitForButtonPressAfterDisplayingText]
and a
jr nz, HoldTextDisplayOpen
@@ -93,7 +93,7 @@ AfterDisplayingTextID::
ld a, [wEnteringCableClub]
and a
jr nz, HoldTextDisplayOpen
call WaitForTextScrollButtonPress ; wait for a button press after displaying all the text
call WaitForTextScrollButtonPress
; loop to hold the dialogue box open as long as the player keeps holding down the A button
HoldTextDisplayOpen::

View File

@@ -140,7 +140,7 @@ AutoBgMapTransfer::
ld h, a
ldh a, [hAutoBGTransferDest]
ld l, a
ld de, 12 * 32
ld de, 12 * TILEMAP_WIDTH
add hl, de
xor a ; TRANSFERTOP
jr .doTransfer
@@ -160,7 +160,7 @@ AutoBgMapTransfer::
ld h, a
ldh a, [hAutoBGTransferDest]
ld l, a
ld de, 6 * 32
ld de, 6 * TILEMAP_WIDTH
add hl, de
ld a, TRANSFERBOTTOM
.doTransfer

View File

@@ -47,7 +47,7 @@ HallOfFameResetEventsAndSaveScript:
ld [wHallOfFameCurScript], a
ld a, PALLET_TOWN
ld [wLastBlackoutMap], a
farcall SaveSAVtoSRAM
farcall SaveGameData
ld b, 5
.delayLoop
ld c, 600 / 5

View File

@@ -16,30 +16,30 @@ MansionB1FCheckReplaceSwitchDoorBlocks:
CheckEvent EVENT_MANSION_SWITCH_ON
jr nz, .switchTurnedOn
ld a, $e
ld bc, $80d
lb bc, 8, 13
call Mansion2ReplaceBlock
ld a, $e
ld bc, $b06
lb bc, 11, 6
call Mansion2ReplaceBlock
ld a, $5f
ld bc, $304
lb bc, 3, 4
call Mansion2ReplaceBlock
ld a, $54
ld bc, $808
lb bc, 8, 8
call Mansion2ReplaceBlock
ret
.switchTurnedOn
ld a, $2d
ld bc, $80d
lb bc, 8, 13
call Mansion2ReplaceBlock
ld a, $5f
ld bc, $b06
lb bc, 11, 6
call Mansion2ReplaceBlock
ld a, $e
ld bc, $304
lb bc, 3, 4
call Mansion2ReplaceBlock
ld a, $e
ld bc, $808
lb bc, 8, 8
call Mansion2ReplaceBlock
ret

View File

@@ -37,7 +37,7 @@ SeafoamIslandsB4FDefaultScript:
ld a, [wCoordIndex]
cp $3
jr nc, .only1UpInputNeeded
ld a, NPC_MOVEMENT_UP
ld a, PAD_UP
ld [wSimulatedJoypadStatesEnd + 1], a
ld a, 2
jr .forcePlayerUpFromSurfExit

View File

@@ -50,7 +50,7 @@ VermilionDockSSAnneLeavesScript:
ld [wSpritePlayerStateData1ImageIndex], a
ld c, 120
call DelayFrames
ld b, $9c
ld b, HIGH(vBGMap1)
call CopyScreenTileBufferToVRAM
hlcoord 0, 10
ld bc, SCREEN_WIDTH * 6