diff options
Diffstat (limited to 'engine')
| -rw-r--r-- | engine/battle/core.asm | 47 | ||||
| -rw-r--r-- | engine/battle/effects.asm | 12 | ||||
| -rw-r--r-- | engine/battle/init_battle.asm | 4 | ||||
| -rw-r--r-- | engine/battle/read_trainer_party.asm | 8 | ||||
| -rw-r--r-- | engine/battle/trainer_ai.asm | 8 | ||||
| -rw-r--r-- | engine/debug/debug_menu.asm | 2 | ||||
| -rw-r--r-- | engine/events/give_pokemon.asm | 2 | ||||
| -rw-r--r-- | engine/events/hidden_objects/bench_guys.asm | 9 | ||||
| -rw-r--r-- | engine/events/in_game_trades.asm | 2 | ||||
| -rw-r--r-- | engine/events/prize_menu.asm | 12 | ||||
| -rw-r--r-- | engine/gfx/palettes.asm | 46 | ||||
| -rw-r--r-- | engine/link/cable_club.asm | 2 | ||||
| -rw-r--r-- | engine/link/cable_club_npc.asm | 2 | ||||
| -rw-r--r-- | engine/menus/display_text_id_init.asm | 2 | ||||
| -rw-r--r-- | engine/menus/main_menu.asm | 4 | ||||
| -rw-r--r-- | engine/menus/save.asm | 148 | ||||
| -rw-r--r-- | engine/menus/start_sub_menus.asm | 36 | ||||
| -rw-r--r-- | engine/movie/hall_of_fame.asm | 2 | ||||
| -rw-r--r-- | engine/movie/oak_speech/clear_save.asm | 2 | ||||
| -rw-r--r-- | engine/movie/title.asm | 2 | ||||
| -rw-r--r-- | engine/movie/trade.asm | 12 | ||||
| -rw-r--r-- | engine/pokemon/bills_pc.asm | 5 | ||||
| -rw-r--r-- | engine/pokemon/status_screen.asm | 2 |
23 files changed, 195 insertions, 176 deletions
diff --git a/engine/battle/core.asm b/engine/battle/core.asm index 8024fb9e..ca5dcec9 100644 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -1869,7 +1869,8 @@ AnimateRetreatingPlayerMon: call ClearScreenArea ret -; reads player's current mon's HP into wBattleMonHP +; Copies player's current pokemon's current HP and status into the party +; struct data so it stays after battle or switching ReadPlayerMonCurHPAndStatus: ld a, [wPlayerMonNumber] ld hl, wPartyMon1HP @@ -3308,30 +3309,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 @@ -3350,7 +3351,7 @@ playPlayerMoveAnimation: ld b, BANK(ReshowSubstituteAnim) call nz, Bankswitch jr MirrorMoveCheck -playerCheckIfFlyOrChargeEffect: +PlayerCheckIfFlyOrChargeEffect: ld c, 30 call DelayFrames ld a, [wPlayerMoveEffect] @@ -3417,7 +3418,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 @@ -3694,7 +3695,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 @@ -3728,7 +3729,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 @@ -5749,7 +5750,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] @@ -5842,7 +5843,7 @@ EnemyCalcMoveDamage: jp c, EnemyMoveHitTest call CriticalHitTest call HandleCounterMove - jr z, handleIfEnemyMoveMissed + jr z, HandleIfEnemyMoveMissed call SwapPlayerAndEnemyLevels call GetDamageVarsForEnemyAttack call SwapPlayerAndEnemyLevels @@ -5853,13 +5854,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 @@ -5868,13 +5869,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? @@ -6213,7 +6214,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? diff --git a/engine/battle/effects.asm b/engine/battle/effects.asm index b2976a64..6a674ec5 100644 --- a/engine/battle/effects.asm +++ b/engine/battle/effects.asm @@ -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 @@ -716,14 +716,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 @@ -1494,9 +1494,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 diff --git a/engine/battle/init_battle.asm b/engine/battle/init_battle.asm index fabff3e3..629ae7b0 100644 --- a/engine/battle/init_battle.asm +++ b/engine/battle/init_battle.asm @@ -117,12 +117,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 diff --git a/engine/battle/read_trainer_party.asm b/engine/battle/read_trainer_party.asm index 6a46759e..c8ee8fda 100644 --- a/engine/battle/read_trainer_party.asm +++ b/engine/battle/read_trainer_party.asm @@ -31,14 +31,14 @@ ReadTrainer: ; and hl points to the trainer class. ; Our next task is to iterate through the trainers, ; decrementing b each time, until we get to the right one. -.outer +.CheckNextTrainer dec b jr z, .IterateTrainer -.inner +.SkipTrainer ld a, [hli] and a - jr nz, .inner - jr .outer + jr nz, .SkipTrainer + jr .CheckNextTrainer ; if the first byte of trainer data is FF, ; - each pokemon has a specific level diff --git a/engine/battle/trainer_ai.asm b/engine/battle/trainer_ai.asm index 7843b1e2..7081fdfd 100644 --- a/engine/battle/trainer_ai.asm +++ b/engine/battle/trainer_ai.asm @@ -692,22 +692,22 @@ AICheckIfHPBelowFraction: ret AIUseXAttack: - ld b, $A + ld b, ATTACK_UP1_EFFECT ld a, X_ATTACK jr AIIncreaseStat AIUseXDefend: - ld b, $B + ld b, DEFENSE_UP1_EFFECT ld a, X_DEFEND jr AIIncreaseStat AIUseXSpeed: - ld b, $C + ld b, SPEED_UP1_EFFECT ld a, X_SPEED jr AIIncreaseStat AIUseXSpecial: - ld b, $D + ld b, SPECIAL_UP1_EFFECT ld a, X_SPECIAL ; fallthrough diff --git a/engine/debug/debug_menu.asm b/engine/debug/debug_menu.asm index 5cd07d53..a8f147a6 100644 --- a/engine/debug/debug_menu.asm +++ b/engine/debug/debug_menu.asm @@ -1568,7 +1568,7 @@ Func_ff295: push af ld a, 1 << BIT_FAST_TEXT_DELAY ld [wLetterPrintingDelayFlags], a - callfar SaveSAVtoSRAM + callfar SaveGameData pop af ld [wLetterPrintingDelayFlags], a pop de diff --git a/engine/events/give_pokemon.asm b/engine/events/give_pokemon.asm index e33d5165..5d7d0661 100644 --- a/engine/events/give_pokemon.asm +++ b/engine/events/give_pokemon.asm @@ -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 diff --git a/engine/events/hidden_objects/bench_guys.asm b/engine/events/hidden_objects/bench_guys.asm index 55090c01..e5a2a724 100644 --- a/engine/events/hidden_objects/bench_guys.asm +++ b/engine/events/hidden_objects/bench_guys.asm @@ -17,6 +17,15 @@ PrintBenchGuyText: ld b, a ld a, [wSpritePlayerStateData1FacingDirection] cp b + + ; bug: an 'inc hl' instruction is needed before looping back. When trying to + ; talk to a bench guy from above, this Sprite Facing test will fail, and the + ; next loop iteration will be misaligned within BenchGuyTextPointers table. + ; As a result, the routine will miss the terminator byte, and continue to + ; process data beyond the table boundary. + ; It seems that it will only return after starting to read data from VRAM + ; (According to Pan Docs, during PPU mode 3, reads return garbage value, + ; usually $FF). jr nz, .loop ; player isn't facing the bench guy ld a, [hl] jp PrintPredefTextID diff --git a/engine/events/in_game_trades.asm b/engine/events/in_game_trades.asm index 3671dba8..8c5f4e5c 100644 --- a/engine/events/in_game_trades.asm +++ b/engine/events/in_game_trades.asm @@ -259,7 +259,7 @@ InGameTrade_CheckForTradeEvo: jp PlayDefaultMusic InGameTrade_TrainerString: - db "<TRAINER>@@@@@@@@@@" + dname "<TRAINER>", NAME_LENGTH InGameTradeTextPointers: ; entries correspond to TRADE_DIALOGSET_* constants diff --git a/engine/events/prize_menu.asm b/engine/events/prize_menu.asm index 4285b7d6..16ada216 100644 --- a/engine/events/prize_menu.asm +++ b/engine/events/prize_menu.asm @@ -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 @@ -27,7 +27,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 @@ -41,16 +41,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 diff --git a/engine/gfx/palettes.asm b/engine/gfx/palettes.asm index e2924c91..e46c6715 100644 --- a/engine/gfx/palettes.asm +++ b/engine/gfx/palettes.asm @@ -491,30 +491,30 @@ _SendSGBPacket: ; save B for later use push bc ; send RESET signal (P14=LOW, P15=LOW) - xor a + xor a ; JOYP_SGB_START ldh [rJOYP], a ; set P14=HIGH, P15=HIGH - ld a, $30 + ld a, JOYP_SGB_FINISH ldh [rJOYP], a ;load length of packets (16 bytes) - ld b, $10 + ld b, 16 .nextByte ;set bit counter (8 bits per byte) - ld e, $08 + ld e, 8 ; get next byte in the packet ld a, [hli] ld d, a .nextBit0 bit 0, d ; if 0th bit is not zero set P14=HIGH, P15=LOW (send bit 1) - ld a, $10 + ld a, JOYP_SGB_ONE jr nz, .next0 ; else (if 0th bit is zero) set P14=LOW, P15=HIGH (send bit 0) - ld a, $20 + ld a, JOYP_SGB_ZERO .next0 ldh [rJOYP], a ; must set P14=HIGH,P15=HIGH between each "pulse" - ld a, $30 + ld a, JOYP_SGB_FINISH ldh [rJOYP], a ; rotation will put next bit in 0th position (so we can always use command ; "bit 0, d" to fetch the bit that has to be sent) @@ -524,11 +524,11 @@ _SendSGBPacket: jr nz, .nextBit0 dec b jr nz, .nextByte -; send bit 1 as a "stop bit" (end of parameter data) - ld a, $20 +; send bit 0 as a "stop bit" (end of parameter data) + ld a, JOYP_SGB_ZERO ldh [rJOYP], a ; set P14=HIGH,P15=HIGH - ld a, $30 + ld a, JOYP_SGB_FINISH ldh [rJOYP], a ; wait for about 70000 cycles call Wait7000 @@ -612,20 +612,20 @@ CheckSGB: call SendSGBPacket call Wait7000 ldh a, [rJOYP] - and $3 - cp $3 + and JOYP_SGB_MLT_REQ + cp JOYP_SGB_MLT_REQ jr nz, .isSGB - ld a, $20 + ld a, JOYP_SGB_ZERO ldh [rJOYP], a ldh a, [rJOYP] ldh a, [rJOYP] call Wait7000 call Wait7000 - ld a, $30 + ld a, JOYP_SGB_FINISH ldh [rJOYP], a call Wait7000 call Wait7000 - ld a, $10 + ld a, JOYP_SGB_ONE ldh [rJOYP], a ldh a, [rJOYP] ldh a, [rJOYP] @@ -635,7 +635,7 @@ CheckSGB: ldh a, [rJOYP] call Wait7000 call Wait7000 - ld a, $30 + ld a, JOYP_SGB_FINISH ldh [rJOYP], a ldh a, [rJOYP] ldh a, [rJOYP] @@ -643,8 +643,8 @@ CheckSGB: call Wait7000 call Wait7000 ldh a, [rJOYP] - and $3 - cp $3 + and JOYP_SGB_MLT_REQ + cp JOYP_SGB_MLT_REQ jr nz, .isSGB call SendMltReq1Packet and a @@ -674,15 +674,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 @@ -691,7 +691,7 @@ CopyGfxToSuperNintendoVRAM: add hl, de dec c jr nz, .loop - ld a, $e3 + ld a, LCDC_DEFAULT ldh [rLCDC], a pop hl call SendSGBPacket diff --git a/engine/link/cable_club.asm b/engine/link/cable_club.asm index ce6c582b..f7539bdb 100644 --- a/engine/link/cable_club.asm +++ b/engine/link/cable_club.asm @@ -867,7 +867,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 diff --git a/engine/link/cable_club_npc.asm b/engine/link/cable_club_npc.asm index ba29ca06..fda27dd9 100644 --- a/engine/link/cable_club_npc.asm +++ b/engine/link/cable_club_npc.asm @@ -67,7 +67,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 diff --git a/engine/menus/display_text_id_init.asm b/engine/menus/display_text_id_init.asm index 74fb5800..ca828006 100644 --- a/engine/menus/display_text_id_init.asm +++ b/engine/menus/display_text_id_init.asm @@ -66,7 +66,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 diff --git a/engine/menus/main_menu.asm b/engine/menus/main_menu.asm index d739e560..262250a3 100644 --- a/engine/menus/main_menu.asm +++ b/engine/menus/main_menu.asm @@ -8,7 +8,7 @@ MainMenu: call CheckForPlayerNameInSRAM jr nc, .mainMenuLoop - predef LoadSAV + predef TryLoadSaveFile .mainMenuLoop ld c, 20 @@ -278,7 +278,7 @@ CheckForPlayerNameInSRAM: ld [rRAMG], a ld a, BMODE_ADVANCED ld [rBMODE], a - ASSERT BMODE_ADVANCED == BANK("Save Data") + ASSERT BANK(sPlayerName) == BMODE_ADVANCED ld [rRAMB], a ld b, NAME_LENGTH ld hl, sPlayerName diff --git a/engine/menus/save.asm b/engine/menus/save.asm index 51c6197a..0ad7eeac 100644 --- a/engine/menus/save.asm +++ b/engine/menus/save.asm @@ -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,7 +29,7 @@ FileDataDestroyedText: text_far _FileDataDestroyedText text_end -LoadSAV0: +LoadMainData: call EnableSRAM ld a, BANK("Save Data") ld [rRAMB], a @@ -39,22 +38,22 @@ LoadSAV0: 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 @@ -71,42 +70,45 @@ 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 SAVGoodChecksum + jp GoodCheckSum -LoadSAV1: +LoadCurrentBoxData: call EnableSRAM ld a, BANK("Save Data") 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 + jr nz, CheckSumFailed ld hl, sCurBoxData ld de, wBoxDataStart ld bc, wBoxDataEnd - wBoxDataStart call CopyData and a - jp SAVGoodChecksum + jp GoodCheckSum -LoadSAV2: +LoadPartyAndDexData: call EnableSRAM ld a, BANK("Save Data") ld [rRAMB], a 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 ld hl, sPartyData ld de, wPartyDataStart ld bc, wPartyDataEnd - wPartyDataStart @@ -116,27 +118,29 @@ LoadSAV2: ld bc, wPokedexSeenEnd - wPokedexOwned call CopyData and a - jp SAVGoodChecksum + jp GoodCheckSum -SAVBadCheckSum: +CheckSumFailed: scf + ; fallthrough -SAVGoodChecksum: +GoodCheckSum: call DisableSRAM 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 c, 10 call DelayFrames ld hl, WouldYouLikeToSaveText - call SaveSAVConfirm + call SaveTheGame_YesOrNo and a ;|0 = Yes|1 = No| ret nz ld c, 10 @@ -144,14 +148,14 @@ SaveSAV: ld a, [wSaveFileStatus] cp $1 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 ld hl, SavingText call PrintText ld c, 128 @@ -167,13 +171,13 @@ SaveSAV: call DelayFrames ret -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 @@ -193,10 +197,11 @@ OlderFileWillBeErasedText: text_far _OlderFileWillBeErasedText text_end -SaveSAVtoSRAM0: +SaveMainData: call EnableSRAM ld a, BANK("Save Data") ld [rRAMB], a + ld hl, wPlayerName ld de, sPlayerName ld bc, NAME_LENGTH @@ -210,20 +215,22 @@ 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 call DisableSRAM ret -SaveSAVtoSRAM1: -; stored pokémon +SaveCurrentBoxData: call EnableSRAM ld a, BANK("Save Data") ld [rRAMB], a @@ -233,12 +240,12 @@ SaveSAVtoSRAM1: call CopyData ld hl, sGameData ld bc, sGameDataEnd - sGameData - call SAVCheckSum + call CalcCheckSum ld [sMainDataCheckSum], a call DisableSRAM ret -SaveSAVtoSRAM2: +SavePartyAndDexData: call EnableSRAM ld a, BANK("Save Data") ld [rRAMB], a @@ -259,19 +266,19 @@ SaveSAVtoSRAM2: ld [de], a ld hl, sGameData ld bc, sGameDataEnd - sGameData - call SAVCheckSum + call CalcCheckSum ld [sMainDataCheckSum], a call DisableSRAM 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 @@ -294,7 +301,7 @@ CalcIndividualBoxCheckSums: push bc push de ld bc, wBoxDataEnd - wBoxDataStart - call SAVCheckSum + call CalcCheckSum pop de ld [de], a inc de @@ -308,7 +315,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 @@ -373,7 +380,7 @@ ChangeBox:: ld a, [hl] ld [de], a call RestoreMapTextPointer - call SaveSAVtoSRAM + call SaveGameData ld hl, wChangeBoxSavedMapTextPointer call SetMapTextPointer ret @@ -392,7 +399,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 @@ -400,7 +407,7 @@ CopyBoxToOrFromSRAM: ld hl, sBox1 ; sBox7 ld bc, sBank2AllBoxesChecksum - sBox1 - call SAVCheckSum + call CalcCheckSum ld [sBank2AllBoxesChecksum], a ; sBank3AllBoxesChecksum call CalcIndividualBoxCheckSums call DisableSRAM @@ -420,7 +427,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 @@ -439,7 +446,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 @@ -458,7 +465,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] @@ -525,7 +532,7 @@ EmptySRAMBoxesInBank: call EmptySRAMBox ld hl, sBox1 ; sBox7 ld bc, sBank2AllBoxesChecksum - sBox1 - call SAVCheckSum + call CalcCheckSum ld [sBank2AllBoxesChecksum], a ; sBank3AllBoxesChecksum call CalcIndividualBoxCheckSums ret @@ -552,7 +559,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 @@ -576,10 +583,10 @@ 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 +; 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: call EnableSRAM ld a, BANK("Save Data") ld [rRAMB], a @@ -588,11 +595,11 @@ SAVCheckRandomID: 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] @@ -603,8 +610,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 @@ -651,19 +659,20 @@ HallOfFame_Copy: call DisableSRAM ret -ClearSAV: +; Fill SRAM with $ff, erasing save data. Used by DoClearSaveDialogue +ClearAllSRAMBanks: call EnableSRAM ld a, $4 .loop dec a push af - call PadSRAM_FF + call .PadSRAM_FF pop af jr nz, .loop call DisableSRAM ret -PadSRAM_FF: +.PadSRAM_FF ld [rRAMB], a ld hl, STARTOF(SRAM) ld bc, SIZEOF(SRAM) @@ -678,7 +687,8 @@ EnableSRAM: ret DisableSRAM: - ld a, 0 + ld a, BMODE_SIMPLE ; preserve flags ld [rBMODE], a + ASSERT RAMG_SRAM_DISABLE == BMODE_SIMPLE ld [rRAMG], a ret diff --git a/engine/menus/start_sub_menus.asm b/engine/menus/start_sub_menus.asm index 9e8a181b..32258437 100644 --- a/engine/menus/start_sub_menus.asm +++ b/engine/menus/start_sub_menus.asm @@ -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 @@ -303,7 +303,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], " " @@ -313,7 +313,7 @@ ErasePartyMenuCursors:: ret ItemMenuLoop: - call LoadScreenTilesFromBuffer2DisableBGTransfer ; restore saved screen + call LoadScreenTilesFromBuffer2DisableBGTransfer call RunDefaultPaletteCommand StartMenu_Item:: @@ -340,7 +340,7 @@ StartMenu_Item:: ld [wBagSavedMenuItem], a jr nc, .choseItem .exitMenu - call LoadScreenTilesFromBuffer2 ; restore saved screen + call LoadScreenTilesFromBuffer2 call LoadTextBoxTilePatterns call UpdateSprites jp RedisplayStartMenu @@ -380,7 +380,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 @@ -476,14 +476,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 farcall DrawStartMenu ; XXX what difference does this make? @@ -507,7 +507,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 @@ -517,10 +517,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) @@ -573,12 +573,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 @@ -660,8 +660,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:: @@ -670,7 +670,7 @@ StartMenu_Option:: call ClearScreen call UpdateSprites callfar DisplayOptionMenu - call LoadScreenTilesFromBuffer2 ; restore saved screen + call LoadScreenTilesFromBuffer2 call LoadTextBoxTilePatterns call UpdateSprites jp RedisplayStartMenu diff --git a/engine/movie/hall_of_fame.asm b/engine/movie/hall_of_fame.asm index 025d6a03..38d937f6 100644 --- a/engine/movie/hall_of_fame.asm +++ b/engine/movie/hall_of_fame.asm @@ -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 diff --git a/engine/movie/oak_speech/clear_save.asm b/engine/movie/oak_speech/clear_save.asm index 4df2faa4..f44a12b9 100644 --- a/engine/movie/oak_speech/clear_save.asm +++ b/engine/movie/oak_speech/clear_save.asm @@ -19,7 +19,7 @@ DoClearSaveDialogue: ld a, [wCurrentMenuItem] and a jp z, Init - farcall ClearSAV + farcall ClearAllSRAMBanks jp Init ClearSaveDataText: diff --git a/engine/movie/title.asm b/engine/movie/title.asm index 7a4637ec..495c8cfe 100644 --- a/engine/movie/title.asm +++ b/engine/movie/title.asm @@ -240,7 +240,6 @@ ENDC .doClearSaveDialogue farjp DoClearSaveDialogue - TitleScreenCopyTileMapToVRAM: ldh [hAutoBGTransferDest + 1], a jp Delay3 @@ -283,7 +282,6 @@ DoTitleScreenFunction: ld l, a jp hl - .Jumptable: dw .Nop dw .BlinkHalf diff --git a/engine/movie/trade.asm b/engine/movie/trade.asm index 2cb51d98..852af717 100644 --- a/engine/movie/trade.asm +++ b/engine/movie/trade.asm @@ -168,7 +168,7 @@ LoadTradingGFXAndMonNames: ld a, BANK(TradingAnimationGraphics2) call FarCopyData ld hl, vBGMap0 - ld bc, $800 + ld bc, 2 * TILEMAP_AREA ld a, " " call FillMemory call ClearSprites @@ -226,7 +226,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 @@ -281,7 +281,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 @@ -341,7 +341,7 @@ Trade_AnimateBallEnteringLinkCable: ld a, $1 ldh [hAutoBGTransferEnabled], a call ClearScreen - ld b, $98 + ld b, HIGH(vBGMap0) call CopyScreenTileBufferToVRAM call Delay3 xor a @@ -457,7 +457,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 @@ -761,7 +761,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 diff --git a/engine/pokemon/bills_pc.asm b/engine/pokemon/bills_pc.asm index 09c04293..e5c0211d 100644 --- a/engine/pokemon/bills_pc.asm +++ b/engine/pokemon/bills_pc.asm @@ -148,7 +148,7 @@ BillsPCMenu: lb bc, 2, 9 call TextBoxBorder ld a, [wCurrentBoxNum] - and $7f + and BOX_NUM_MASK cp 9 jr c, .singleDigitBoxNum ; two digit box num @@ -254,7 +254,7 @@ BillsPCDeposit: call WaitForSoundToFinish ld hl, wBoxNumString ld a, [wCurrentBoxNum] - and $7f + and BOX_NUM_MASK cp 9 jr c, .singleDigitBoxNum sub 9 @@ -582,6 +582,7 @@ JustAMomentText:: text_far _JustAMomentText text_end +UnusedOpenBillsPC: ; unreferenced ld a, [wSpritePlayerStateData1FacingDirection] cp SPRITE_FACING_UP ret nz diff --git a/engine/pokemon/status_screen.asm b/engine/pokemon/status_screen.asm index d0952cb9..ec8cf1ee 100644 --- a/engine/pokemon/status_screen.asm +++ b/engine/pokemon/status_screen.asm @@ -441,7 +441,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 |
