diff options
author | Rangi <35663410+Rangi42@users.noreply.github.com> | 2020-10-30 12:26:03 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-30 12:26:03 -0400 |
commit | 7a42f1790ae1e9e357593879bd38c6596dcb03da (patch) | |
tree | dbf4ee19995364f15a3b3f98925f606c50598334 /engine | |
parent | a2b6befd7d12b2ad8bb97979a10519500dcdd870 (diff) | |
parent | 1092983bde65bbf1a27eeabbfbceec1f278a4831 (diff) |
Merge pull request #776 from Rangi42/unreferenced
Comment, remove, or revise many unreferenced labels
Diffstat (limited to 'engine')
94 files changed, 1439 insertions, 1220 deletions
diff --git a/engine/battle/ai/items.asm b/engine/battle/ai/items.asm index 4de82d153..62adaca77 100644 --- a/engine/battle/ai/items.asm +++ b/engine/battle/ai/items.asm @@ -20,8 +20,9 @@ AI_SwitchOrTryItem: and a jr nz, DontSwitch + ; always load the first trainer class in wTrainerClass for Battle Tower trainers ld hl, TrainerClassAttributes + TRNATTR_AI_ITEM_SWITCH - ld a, [wInBattleTowerBattle] ; always load the first trainer class in wTrainerClass for BattleTower-Trainers + ld a, [wInBattleTowerBattle] and a jr nz, .ok @@ -29,6 +30,7 @@ AI_SwitchOrTryItem: dec a ld bc, NUM_TRAINER_ATTRIBUTES call AddNTimes + .ok bit SWITCH_OFTEN_F, [hl] jp nz, SwitchOften @@ -145,13 +147,13 @@ SwitchSometimes: ld [wEnemySwitchMonIndex], a jp AI_TrySwitch -CheckSubstatusCantRun: +CheckSubstatusCantRun: ; unreferenced ld a, [wEnemySubStatus5] bit SUBSTATUS_CANT_RUN, a ret AI_TryItem: - ; items are not allowed in the BattleTower + ; items are not allowed in the Battle Tower ld a, [wInBattleTowerBattle] and a ret nz @@ -213,7 +215,7 @@ AI_TryItem: inc hl jr c, .loop -.used_item +; used item xor a ld [de], a inc a @@ -259,7 +261,7 @@ AI_TryItem: cp e jr nc, .yes -.no +.no ; unreferenced and a ret diff --git a/engine/battle/battle_transition.asm b/engine/battle/battle_transition.asm index a1cdd239d..12932ede5 100644 --- a/engine/battle/battle_transition.asm +++ b/engine/battle/battle_transition.asm @@ -258,7 +258,7 @@ StartTrainerBattle_NextScene: StartTrainerBattle_SetUpBGMap: call StartTrainerBattle_NextScene xor a - ld [wcf64], a + ld [wBattleTransitionCounter], a ldh [hBGMapMode], a ret @@ -272,7 +272,7 @@ StartTrainerBattle_Flash: ld a, [wTimeOfDayPalset] cp DARKNESS_PALSET jr z, .done - ld hl, wcf64 + ld hl, wBattleTransitionCounter ld a, [hl] inc [hl] srl a @@ -290,7 +290,7 @@ StartTrainerBattle_Flash: .done xor a - ld [wcf64], a + ld [wBattleTransitionCounter], a scf ret @@ -322,12 +322,12 @@ StartTrainerBattle_SetUpForWavyOutro: ld a, $90 ldh [hLYOverrideEnd], a xor a - ld [wcf64], a - ld [wcf65], a + ld [wBattleTransitionCounter], a + ld [wBattleTransitionSineWaveOffset], a ret StartTrainerBattle_SineWave: - ld a, [wcf64] + ld a, [wBattleTransitionCounter] cp $60 jr nc, .end call .DoSineWave @@ -339,10 +339,10 @@ StartTrainerBattle_SineWave: ret .DoSineWave: - ld hl, wcf65 + ld hl, wBattleTransitionSineWaveOffset ld a, [hl] inc [hl] - ld hl, wcf64 + ld hl, wBattleTransitionCounter ld d, [hl] add [hl] ld [hl], a @@ -372,13 +372,13 @@ StartTrainerBattle_SetUpForSpinOutro: ldh [rSVBK], a call StartTrainerBattle_NextScene xor a - ld [wcf64], a + ld [wBattleTransitionCounter], a ret StartTrainerBattle_SpinToBlack: xor a ldh [hBGMapMode], a - ld a, [wcf64] + ld a, [wBattleTransitionCounter] ld e, a ld d, 0 ld hl, .spin_quadrants @@ -388,13 +388,13 @@ endr ld a, [hli] cp -1 jr z, .end - ld [wcf65], a + ld [wBattleTransitionSineWaveOffset], a call .load ld a, 1 ldh [hBGMapMode], a call DelayFrame call DelayFrame - ld hl, wcf64 + ld hl, wBattleTransitionCounter inc [hl] ret @@ -449,7 +449,7 @@ ENDM spin_quadrant LOWER_LEFT, .wedge1, 1, 11 db -1 -.load +.load: ld a, [hli] ld e, a ld a, [hli] @@ -464,7 +464,7 @@ ENDM inc de .loop1 ld [hl], BATTLETRANSITION_BLACK - ld a, [wcf65] + ld a, [wBattleTransitionSineWaveOffset] bit RIGHT_QUADRANT_F, a jr z, .leftside inc hl @@ -475,7 +475,7 @@ ENDM dec c jr nz, .loop1 pop hl - ld a, [wcf65] + ld a, [wBattleTransitionSineWaveOffset] bit LOWER_QUADRANT_F, a ld bc, SCREEN_WIDTH jr z, .upper @@ -490,7 +490,7 @@ ENDM jr z, .loop ld c, a .loop2 - ld a, [wcf65] + ld a, [wBattleTransitionSineWaveOffset] bit RIGHT_QUADRANT_F, a jr z, .leftside2 dec hl @@ -514,13 +514,13 @@ StartTrainerBattle_SetUpForRandomScatterOutro: ldh [rSVBK], a call StartTrainerBattle_NextScene ld a, $10 - ld [wcf64], a + ld [wBattleTransitionCounter], a ld a, 1 ldh [hBGMapMode], a ret StartTrainerBattle_SpeckleToBlack: - ld hl, wcf64 + ld hl, wBattleTransitionCounter ld a, [hl] and a jr z, .done diff --git a/engine/battle/core.asm b/engine/battle/core.asm index 85cba5f85..f84864a95 100644 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -1697,7 +1697,7 @@ HandleWeather: cp USING_EXTERNAL_CLOCK jr z, .enemy_first -.player_first +; player first call SetPlayerTurn call .SandstormDamage call SetEnemyTurn @@ -2711,7 +2711,7 @@ AskUseNextPokemon: ForcePlayerMonChoice: call EmptyBattleTextbox call LoadStandardMenuHeader - call SetUpBattlePartyMenu_NoLoop + call SetUpBattlePartyMenu call ForcePickPartyMonInBattle ld a, [wLinkMode] and a @@ -2810,9 +2810,9 @@ IsMobileBattle: cp LINK_MOBILE ret -SetUpBattlePartyMenu_NoLoop: +SetUpBattlePartyMenu: call ClearBGPalettes -SetUpBattlePartyMenu: ; switch to fullscreen menu? +SetUpBattlePartyMenu_Loop: ; switch to fullscreen menu? farcall LoadPartyMenuGFX farcall InitPartyMenuWithCancel farcall InitPartyMenuBGPal7 @@ -3006,10 +3006,11 @@ PlayerMonFaintedAnimation: jp MonFaintedAnimation MonFaintedAnimation: - ld a, [wcfbe] + ld a, [wJoypadDisable] push af - set 6, a - ld [wcfbe], a + set JOYPAD_DISABLE_MON_FAINT_F, a + ld [wJoypadDisable], a + ld b, 7 .OuterLoop: @@ -3052,7 +3053,7 @@ MonFaintedAnimation: jr nz, .OuterLoop pop af - ld [wcfbe], a + ld [wJoypadDisable], a ret .Spaces: @@ -3486,7 +3487,7 @@ OfferSwitch: ld a, [wMenuCursorY] dec a jr nz, .said_no - call SetUpBattlePartyMenu_NoLoop + call SetUpBattlePartyMenu call PickSwitchMonInBattle jr c, .canceled_switch ld a, [wCurBattleMon] @@ -4639,7 +4640,7 @@ CheckDanger: PrintPlayerHUD: ld de, wBattleMonNick hlcoord 10, 7 - call ret_3e138 + call Battle_DummyFunction call PlaceString push bc @@ -4725,7 +4726,7 @@ DrawEnemyHUD: call GetBaseData ld de, wEnemyMonNick hlcoord 1, 0 - call ret_3e138 + call Battle_DummyFunction call PlaceString ld h, b ld l, c @@ -4854,7 +4855,8 @@ UpdateHPPal: ret z jp FinishBattleAnim -ret_3e138: +Battle_DummyFunction: +; called before placing either battler's nickname in the HUD ret BattleMenu: @@ -5043,7 +5045,7 @@ BattleMenuPKMN_ReturnFromStats: call LoadStandardMenuHeader call ClearBGPalettes BattleMenuPKMN_Loop: - call SetUpBattlePartyMenu + call SetUpBattlePartyMenu_Loop xor a ld [wPartyMenuActionText], a call JumpToPartyMenuAndPrintText @@ -7436,13 +7438,13 @@ AnimateExpBar: jp nc, .finish ldh a, [hProduct + 3] - ld [wd004], a + ld [wExperienceGained + 2], a push af ldh a, [hProduct + 2] - ld [wd003], a + ld [wExperienceGained + 1], a push af xor a - ld [wd002], a + ld [wExperienceGained], a xor a ; PARTYMON ld [wMonType], a predef CopyMonToTempMon @@ -7454,10 +7456,10 @@ AnimateExpBar: call CalcExpBar push bc ld hl, wTempMonExp + 2 - ld a, [wd004] + ld a, [wExperienceGained + 2] add [hl] ld [hld], a - ld a, [wd003] + ld a, [wExperienceGained + 1] adc [hl] ld [hld], a jr nc, .NoOverflow @@ -7781,7 +7783,8 @@ HandleSafariAngerEatingStatus: ; unreferenced jr .finish .angry - dec hl ; wSafariMonAngerCount + dec hl + assert wSafariMonEating - 1 == wSafariMonAngerCount ld a, [hl] and a ret z @@ -8785,7 +8788,7 @@ AddLastLinkBattleToLinkRecord: .FindOpponentAndAppendRecord: ld b, NUM_LINK_BATTLE_RECORDS ld hl, sLinkBattleRecord1End - 1 - ld de, wd002 + ld de, wLinkBattleRecordBuffer .loop3 push bc push de @@ -8814,16 +8817,16 @@ AddLastLinkBattleToLinkRecord: add b add b ld e, a - ld d, $0 - ld hl, wd002 + ld d, 0 + ld hl, wLinkBattleRecordBuffer add hl, de push hl ld a, c add c add c ld e, a - ld d, $0 - ld hl, wd002 + ld d, 0 + ld hl, wLinkBattleRecordBuffer add hl, de ld d, h ld e, l @@ -8855,7 +8858,7 @@ AddLastLinkBattleToLinkRecord: ld hl, sLinkBattleRecord call AddNTimes push hl - ld de, wd002 + ld de, wLinkBattleRecordBuffer ld bc, LINK_BATTLE_RECORD_LENGTH call CopyBytes pop hl @@ -8869,7 +8872,7 @@ AddLastLinkBattleToLinkRecord: push hl ld bc, LINK_BATTLE_RECORD_LENGTH call CopyBytes - ld hl, wd002 + ld hl, wLinkBattleRecordBuffer ld bc, LINK_BATTLE_RECORD_LENGTH pop de call CopyBytes @@ -8952,13 +8955,13 @@ InitBattleDisplay: ldh [rSVBK], a ld hl, wDecompressScratch - ld bc, wScratchAttrmap - wDecompressScratch + ld bc, BG_MAP_WIDTH * BG_MAP_HEIGHT ld a, " " call ByteFill ld de, wDecompressScratch hlbgcoord 0, 0 - lb bc, BANK(.BlankBGMap), $40 + lb bc, BANK(@), (BG_MAP_WIDTH * BG_MAP_HEIGHT) / LEN_2BPP_TILE call Request2bpp pop af diff --git a/engine/battle/effect_commands.asm b/engine/battle/effect_commands.asm index 4d670b4b1..14f1afd82 100644 --- a/engine/battle/effect_commands.asm +++ b/engine/battle/effect_commands.asm @@ -134,7 +134,7 @@ BattleCommand_CheckTurn: and a jp nz, CheckEnemyTurn -CheckPlayerTurn: +; check player turn ld hl, wPlayerSubStatus4 bit SUBSTATUS_RECHARGE, [hl] jr z, .no_recharge @@ -2586,7 +2586,7 @@ PlayerAttackDamage: cp SPECIAL jr nc, .special -.physical +; physical ld hl, wEnemyMonDefense ld a, [hli] ld b, a @@ -2826,9 +2826,9 @@ EnemyAttackDamage: ld a, [hl] cp SPECIAL - jr nc, .Special + jr nc, .special -.physical +; physical ld hl, wBattleMonDefense ld a, [hli] ld b, a @@ -2852,7 +2852,7 @@ EnemyAttackDamage: ld hl, wEnemyAttack jr .thickclub -.Special: +.special ld hl, wBattleMonSpclDef ld a, [hli] ld b, a @@ -5714,8 +5714,7 @@ BattleCommand_Charge: text_far _BattleDugText text_end -BattleCommand3c: -; unused +BattleCommand_Unused3C: ; unreferenced ret BattleCommand_TrapTarget: @@ -6124,7 +6123,7 @@ INCLUDE "engine/battle/move_effects/conversion.asm" BattleCommand_ResetStats: ; resetstats - ld a, 7 ; neutral + ld a, BASE_STAT_LEVEL ld hl, wPlayerStatLevels call .Fill ld hl, wEnemyStatLevels @@ -6147,7 +6146,7 @@ BattleCommand_ResetStats: jp StdBattleTextbox .Fill: - ld b, wPlayerStatLevelsEnd - wPlayerStatLevels + ld b, NUM_LEVEL_STATS .next ld [hli], a dec b @@ -6489,8 +6488,7 @@ INCLUDE "engine/battle/move_effects/sandstorm.asm" INCLUDE "engine/battle/move_effects/rollout.asm" -BattleCommand5d: -; unused +BattleCommand_Unused5D: ; unreferenced ret INCLUDE "engine/battle/move_effects/fury_cutter.asm" diff --git a/engine/battle/menu.asm b/engine/battle/menu.asm index a4955ec6a..e29bff48b 100644 --- a/engine/battle/menu.asm +++ b/engine/battle/menu.asm @@ -9,8 +9,7 @@ LoadBattleMenu: call ExitMenu ret -SafariBattleMenu: -; untranslated +SafariBattleMenu: ; unreferenced ld hl, SafariBattleMenuHeader call LoadMenuHeader jr CommonBattleMenu @@ -18,7 +17,8 @@ SafariBattleMenu: ContestBattleMenu: ld hl, ContestBattleMenuHeader call LoadMenuHeader -; fallthrough + ; fallthrough + CommonBattleMenu: ld a, [wBattleMenuCursorBuffer] ld [wMenuCursorBuffer], a diff --git a/engine/battle/move_effects/baton_pass.asm b/engine/battle/move_effects/baton_pass.asm index 46baeb75f..bafe33866 100644 --- a/engine/battle/move_effects/baton_pass.asm +++ b/engine/battle/move_effects/baton_pass.asm @@ -17,7 +17,7 @@ BattleCommand_BatonPass: ; Transition into switchmon menu call LoadStandardMenuHeader - farcall SetUpBattlePartyMenu_NoLoop + farcall SetUpBattlePartyMenu farcall ForcePickSwitchMonInBattle diff --git a/engine/battle/move_effects/beat_up.asm b/engine/battle/move_effects/beat_up.asm index 73bbb2e42..f1cc7a5c2 100644 --- a/engine/battle/move_effects/beat_up.asm +++ b/engine/battle/move_effects/beat_up.asm @@ -14,7 +14,7 @@ BattleCommand_BeatUp: call DelayFrames xor a ld [wPlayerRolloutCount], a - ld [wd002], a + ld [wCurBeatUpPartyMon], a ld [wBeatUpHitAtLeastOnce], a jr .got_mon @@ -23,10 +23,10 @@ BattleCommand_BeatUp: ld b, a ld a, [wPartyCount] sub b - ld [wd002], a + ld [wCurBeatUpPartyMon], a .got_mon - ld a, [wd002] + ld a, [wCurBeatUpPartyMon] ld hl, wPartyMonNicknames call GetNick ld a, MON_HP @@ -34,7 +34,7 @@ BattleCommand_BeatUp: ld a, [hli] or [hl] jp z, .beatup_fail ; fainted - ld a, [wd002] + ld a, [wCurBeatUpPartyMon] ld c, a ld a, [wCurBattleMon] ; BUG: this can desynchronize link battles @@ -88,7 +88,7 @@ BattleCommand_BeatUp: xor a ld [wEnemyRolloutCount], a - ld [wd002], a + ld [wCurBeatUpPartyMon], a ld [wBeatUpHitAtLeastOnce], a jr .enemy_got_mon @@ -97,7 +97,7 @@ BattleCommand_BeatUp: ld b, a ld a, [wOTPartyCount] sub b - ld [wd002], a + ld [wCurBeatUpPartyMon], a .enemy_got_mon ld a, [wBattleMode] @@ -112,7 +112,7 @@ BattleCommand_BeatUp: and a jr nz, .link_or_tower - ld a, [wd002] + ld a, [wCurBeatUpPartyMon] ld c, a ld b, 0 ld hl, wOTPartySpecies @@ -123,7 +123,7 @@ BattleCommand_BeatUp: jr .got_enemy_nick .link_or_tower - ld a, [wd002] + ld a, [wCurBeatUpPartyMon] ld hl, wOTPartyMonNicknames ld bc, NAME_LENGTH call AddNTimes @@ -137,7 +137,7 @@ BattleCommand_BeatUp: or [hl] jp z, .beatup_fail - ld a, [wd002] + ld a, [wCurBeatUpPartyMon] ld b, a ld a, [wCurOTMon] cp b @@ -217,7 +217,7 @@ GetBeatupMonLocation: ld hl, wOTPartyMon1Species .got_species - ld a, [wd002] + ld a, [wCurBeatUpPartyMon] add hl, bc call GetPartyLocation pop bc diff --git a/engine/battle/move_effects/present.asm b/engine/battle/move_effects/present.asm index 8d7461fa1..6aa35acbf 100644 --- a/engine/battle/move_effects/present.asm +++ b/engine/battle/move_effects/present.asm @@ -80,7 +80,7 @@ BattleCommand_Present: call _CheckBattleScene jr nc, .do_animation call AnimateFailedMove - ld hl, RefusedGiftText + ld hl, PresentFailedText call StdBattleTextbox .do_animation jp EndMoveEffect diff --git a/engine/battle_anims/anim_commands.asm b/engine/battle_anims/anim_commands.asm index fd2457bb3..34ef87f61 100644 --- a/engine/battle_anims/anim_commands.asm +++ b/engine/battle_anims/anim_commands.asm @@ -245,7 +245,8 @@ BattleAnim_ClearOAM: ld c, NUM_SPRITE_OAM_STRUCTS .loop ld a, [hl] - and $ff ^ (PALETTE_MASK | VRAM_BANK_1) ; PAL_BATTLE_OB_ENEMY (0) + and $ff ^ (PALETTE_MASK | VRAM_BANK_1) ; zeros out the palette bits + assert PAL_BATTLE_OB_ENEMY == 0 ld [hli], a rept SPRITEOAMSTRUCT_LENGTH - 1 inc hl @@ -1050,7 +1051,7 @@ GetMinimizePic: and a jr z, .player - ld de, sScratch + $1a tiles + ld de, sScratch + (3 * 7 + 5) tiles call CopyMinimizePic ld hl, vTiles2 tile $00 ld de, sScratch @@ -1058,7 +1059,7 @@ GetMinimizePic: ret .player - ld de, sScratch + $160 + ld de, sScratch + (3 * 6 + 4) tiles call CopyMinimizePic ld hl, vTiles2 tile $31 ld de, sScratch diff --git a/engine/battle_anims/core.asm b/engine/battle_anims/core.asm index adba64e0d..d756a447a 100644 --- a/engine/battle_anims/core.asm +++ b/engine/battle_anims/core.asm @@ -263,14 +263,12 @@ InitBattleAnimBuffer: jr nz, .no_sub ld a, [wFXAnimID] cp KINESIS - jr z, .kinesis + jr z, .do_sub cp SOFTBOILED - jr z, .softboiled + jr z, .do_sub cp MILK_DRINK jr nz, .no_sub -.kinesis -.softboiled -.milk_drink +.do_sub pop af sub 1 * 8 jr .done diff --git a/engine/battle_anims/functions.asm b/engine/battle_anims/functions.asm index 271c39252..5a04a5b65 100644 --- a/engine/battle_anims/functions.asm +++ b/engine/battle_anims/functions.asm @@ -4299,14 +4299,14 @@ BattleAnim_Cosine_e: ld e, a ret -BattleAnim_AbsSinePrecise: +BattleAnim_AbsSinePrecise: ; unreferenced ld a, e call BattleAnim_Sine ld e, l ld d, h ret -BattleAnim_AbsCosinePrecise: +BattleAnim_AbsCosinePrecise: ; unreferenced ld a, e call BattleAnim_Cosine ld e, l diff --git a/engine/debug/color_picker.asm b/engine/debug/color_picker.asm index ee9a9f6a6..40261a391 100644 --- a/engine/debug/color_picker.asm +++ b/engine/debug/color_picker.asm @@ -32,7 +32,7 @@ const DEBUGCOLORMAIN_INITTMHM ; 4 const DEBUGCOLORMAIN_TMHMJOYPAD ; 5 -DebugColorPicker: +DebugColorPicker: ; unreferenced ; A debug menu to test monster and trainer palettes at runtime. ldh a, [hCGB] and a @@ -929,13 +929,13 @@ DebugColor_FillBoxWithByte: ret DebugColor_PushSGBPals: - ld a, [wcfbe] + ld a, [wJoypadDisable] push af - set 7, a - ld [wcfbe], a + set JOYPAD_DISABLE_SGB_TRANSFER_F, a + ld [wJoypadDisable], a call _DebugColor_PushSGBPals pop af - ld [wcfbe], a + ld [wJoypadDisable], a ret _DebugColor_PushSGBPals: @@ -1069,7 +1069,7 @@ INCBIN "gfx/debug/up_arrow.2bpp" DebugColor_GFX: INCBIN "gfx/debug/color_test.2bpp" -TilesetColorPicker: +TilesetColorPicker: ; unreferenced ; A debug menu to test tileset palettes at runtime. ; dummied out ret @@ -1437,8 +1437,8 @@ DebugTileset_CalculatePalette: ld [hl], d ret -; unused +.dummy1: ; unreferenced ret -; unused +.dummy2: ; unreferenced ret diff --git a/engine/debug/debug_room.asm b/engine/debug/debug_room.asm index 95692c8d3..895de62d5 100644 --- a/engine/debug/debug_room.asm +++ b/engine/debug/debug_room.asm @@ -1328,9 +1328,9 @@ DebugRoom_BoxStructStrings: .Move4: db "MOVE 4@" .ID0: db "ID[0]@" .ID1: db "ID[1]@" -.BaseExp0: db "BASE EXP[0]@" -.BaseExp1: db "BASE EXP[1]@" -.BaseExp2: db "BASE EXP[2]@" +.BaseExp0: db "BASE EXP[0]@" ; unreferenced +.BaseExp1: db "BASE EXP[1]@" ; unreferenced +.BaseExp2: db "BASE EXP[2]@" ; unreferenced .HPExp0: db "HP EXP[0]@" .HPExp1: db "HP EXP[1]@" .AttkExp0: db "ATTK EXP[0]@" diff --git a/engine/events/battle_tower/battle_tower.asm b/engine/events/battle_tower/battle_tower.asm index f335a83c9..0164ede48 100644 --- a/engine/events/battle_tower/battle_tower.asm +++ b/engine/events/battle_tower/battle_tower.asm @@ -67,7 +67,7 @@ Function170114: call Function170c8b ret -Function170139: +Function170139: ; unreferenced ; Convert the 4-digit decimal number at s5_aa41 into binary ld a, BANK(s5_aa41) call OpenSRAM @@ -183,7 +183,7 @@ BattleTowerBattle: call _BattleTowerBattle ret -DummySpecial_17021d: +UnusedBattleTowerDummySpecial1: ret InitBattleTowerChallengeRAM: @@ -374,7 +374,7 @@ ReadBTTrainerParty: ld [bc], a ret -ValidateBTParty: +ValidateBTParty: ; unreferenced ; Check for and fix errors in party data ld hl, wBT_OTTempMon1Species ld d, BATTLETOWER_PARTY_LENGTH @@ -386,7 +386,7 @@ ValidateBTParty: ld a, [hl] and a x = $ff -rept ($ff - NUM_POKEMON) +rept $ff - NUM_POKEMON jr z, .invalid cp x x = x - 1 @@ -1008,11 +1008,11 @@ BattleTowerAction_SetExplanationRead: BattleTowerAction_SetByteToQuickSaveChallenge: ld c, BATTLETOWER_SAVED_AND_LEFT - jr asm_17079f + jr SetBattleTowerChallengeState BattleTowerAction_SetByteToCancelChallenge: ld c, BATTLETOWER_NO_CHALLENGE -asm_17079f: +SetBattleTowerChallengeState: ld a, BANK(sBattleTowerChallengeState) call OpenSRAM ld a, c @@ -1447,11 +1447,11 @@ Function1709bb: ; BattleTowerAction $10 Function170a9c: ld c, FALSE - jr asm_170aa2 + jr Set_s5_aa8d Function170aa0: ld c, TRUE -asm_170aa2: +Set_s5_aa8d: ld a, BANK(s5_aa8d) call OpenSRAM ld a, c @@ -1576,7 +1576,7 @@ LoadOpponentTrainerAndPokemonWithOTSprite: INCLUDE "data/trainers/sprites.asm" -DummySpecial_170bd2: +UnusedBattleTowerDummySpecial2: ret CheckForBattleTowerRules: diff --git a/engine/events/battle_tower/load_trainer.asm b/engine/events/battle_tower/load_trainer.asm index 8ed401afe..165efb8dd 100644 --- a/engine/events/battle_tower/load_trainer.asm +++ b/engine/events/battle_tower/load_trainer.asm @@ -95,7 +95,7 @@ Function_LoadRandomBattleTowerMon: ld c, BATTLETOWER_PARTY_LENGTH .loop push bc - ld a, BANK(sBTMonPrevTrainer1) + ld a, BANK(sBTMonOfTrainers) call OpenSRAM .FindARandomBattleTowerMon: diff --git a/engine/events/buena.asm b/engine/events/buena.asm index 452f5d62a..dca125ece 100644 --- a/engine/events/buena.asm +++ b/engine/events/buena.asm @@ -85,7 +85,7 @@ BuenaPrize: call Buena_PrizeMenu jr z, .done ld [wMenuSelectionQuantity], a - call Buena_getprize + call Buena_GetPrize ld a, [hl] ld [wNamedObjectIndexBuffer], a call GetItemName @@ -95,7 +95,7 @@ BuenaPrize: jr c, .loop ld a, [wMenuSelectionQuantity] - call Buena_getprize + call Buena_GetPrize inc hl ld a, [hld] ld c, a @@ -258,11 +258,11 @@ Buena_PrizeMenu: db SCROLLINGMENU_DISPLAY_ARROWS ; flags db 4, 13 ; rows, columns db SCROLLINGMENU_ITEMS_NORMAL ; item format - dba .indices - dba .prizeitem - dba .prizepoints + dba .Prizes + dba .PrintPrizeItem + dba .PrintPrizePoints -.indices: +.Prizes: db NUM_BUENA_PRIZES x = 1 rept NUM_BUENA_PRIZES @@ -271,9 +271,9 @@ x = x + 1 endr db -1 -.prizeitem: +.PrintPrizeItem: ld a, [wMenuSelection] - call Buena_getprize + call Buena_GetPrize ld a, [hl] push de ld [wNamedObjectIndexBuffer], a @@ -282,9 +282,9 @@ endr call PlaceString ret -.prizepoints: +.PrintPrizePoints: ld a, [wMenuSelection] - call Buena_getprize + call Buena_GetPrize inc hl ld a, [hl] ld c, "0" @@ -292,7 +292,7 @@ endr ld [de], a ret -Buena_getprize: +Buena_GetPrize: dec a ld hl, BuenaPrizeItems ld b, 0 diff --git a/engine/events/bug_contest/judging.asm b/engine/events/bug_contest/judging.asm index 361aef81a..abb9d60da 100644 --- a/engine/events/bug_contest/judging.asm +++ b/engine/events/bug_contest/judging.asm @@ -68,7 +68,8 @@ ContestJudging_ThirdPlaceScoreText: LoadContestantName: ; If a = 1, get your name. - dec a ; BUG_CONTEST_PLAYER + assert BUG_CONTEST_PLAYER == 1 + dec a jr z, .player ; Find the pointer for the trainer class of the Bug Catching Contestant whose ID is in a. ld c, a diff --git a/engine/events/celebi.asm b/engine/events/celebi.asm index 028f2e350..6a2d16dfc 100644 --- a/engine/events/celebi.asm +++ b/engine/events/celebi.asm @@ -1,6 +1,6 @@ SPECIALCELEBIEVENT_CELEBI EQU $84 -UnusedForestTreeFrames: +UnusedForestTreeFrames: ; unreferenced INCBIN "gfx/tilesets/forest-tree/1.2bpp" INCBIN "gfx/tilesets/forest-tree/2.2bpp" INCBIN "gfx/tilesets/forest-tree/3.2bpp" @@ -99,9 +99,8 @@ CelebiEvent_CountDown: set 7, [hl] ret -CelebiEvent_SpawnLeaf: -; unused - ld hl, wcf65 +CelebiEvent_SpawnLeaf: ; unreferenced + ld hl, wFrameCounter2 ld a, [hl] inc [hl] and $7 diff --git a/engine/events/daycare.asm b/engine/events/daycare.asm index 1c08ca1b8..9393ebc93 100644 --- a/engine/events/daycare.asm +++ b/engine/events/daycare.asm @@ -1,9 +1,9 @@ ; PrintDayCareText.TextTable indexes const_def const DAYCARETEXT_MAN_INTRO - const DAYCARETEXT_MAN_ODD_EGG + const DAYCARETEXT_MAN_INTRO_EGG const DAYCARETEXT_LADY_INTRO - const DAYCARETEXT_LADY_ODD_EGG + const DAYCARETEXT_LADY_INTRO_EGG const DAYCARETEXT_WHICH_ONE const DAYCARETEXT_DEPOSIT const DAYCARETEXT_CANT_BREED_EGG @@ -166,7 +166,7 @@ DayCareAskDepositPokemon: scf ret -.DaycareDummyText: +.DaycareDummyText: ; unreferenced text_far _DaycareDummyText text_end @@ -274,9 +274,9 @@ PrintDayCareText: .TextTable: ; entries correspond to DAYCARETEXT_* constants dw .DayCareManIntroText ; 00 - dw .DayCareManOddEggText ; 01 + dw .DayCareManIntroEggText ; 01 dw .DayCareLadyIntroText ; 02 - dw .DayCareLadyOddEggText ; 03 + dw .DayCareLadyIntroEggText ; 03 dw .WhatShouldIRaiseText ; 04 dw .IllRaiseYourMonText ; 05 dw .CantAcceptEggText ; 06 @@ -298,16 +298,16 @@ PrintDayCareText: text_far _DayCareManIntroText text_end -.DayCareManOddEggText: - text_far _DayCareManOddEggText +.DayCareManIntroEggText: + text_far _DayCareManIntroEggText text_end .DayCareLadyIntroText: text_far _DayCareLadyIntroText text_end -.DayCareLadyOddEggText: - text_far _DayCareLadyOddEggText +.DayCareLadyIntroEggText: + text_far _DayCareLadyIntroEggText text_end .WhatShouldIRaiseText: diff --git a/engine/events/diploma.asm b/engine/events/diploma.asm index f0008b7fd..814c9644c 100644 --- a/engine/events/diploma.asm +++ b/engine/events/diploma.asm @@ -87,4 +87,5 @@ INCBIN "gfx/diploma/page1.tilemap" DiplomaPage2Tilemap: INCBIN "gfx/diploma/page2.tilemap" - ret ; unused +Diploma_DummyFunction: ; unreferenced + ret diff --git a/engine/events/engine_flags.asm b/engine/events/engine_flags.asm index aebbacdc1..13f9a9a81 100644 --- a/engine/events/engine_flags.asm +++ b/engine/events/engine_flags.asm @@ -57,7 +57,7 @@ EngineFlagAction:: jr z, .set ; b = 1 ; Return the given flag in c. -.check +; check ld a, [de] and c ld c, a diff --git a/engine/events/field_moves.asm b/engine/events/field_moves.asm index 6bbb7cbec..130ec411d 100644 --- a/engine/events/field_moves.asm +++ b/engine/events/field_moves.asm @@ -426,7 +426,7 @@ FlyFunction_FrameTimer: ret .SpawnLeaf: - ld hl, wcf65 + ld hl, wFrameCounter2 ld a, [hl] inc [hl] and $7 diff --git a/engine/events/heal_machine_anim.asm b/engine/events/heal_machine_anim.asm index 38ccbf12c..166b42b67 100644 --- a/engine/events/heal_machine_anim.asm +++ b/engine/events/heal_machine_anim.asm @@ -56,7 +56,7 @@ HealMachineAnim: .Pointers: ; entries correspond to HEALMACHINE_* constants dw .Pokecenter - dw .ElmLab + dw .ElmsLab dw .HallOfFame healmachineanimseq: MACRO @@ -68,7 +68,7 @@ ENDM .Pokecenter: healmachineanimseq LOADGFX, PCLOADBALLS, PLAYMUSIC, FINISH -.ElmLab: +.ElmsLab: healmachineanimseq LOADGFX, PCLOADBALLS, PLAYMUSIC, FINISH .HallOfFame: healmachineanimseq LOADGFX, HOFLOADBALLS, HOFPLAYSFX, FINISH diff --git a/engine/events/magnet_train.asm b/engine/events/magnet_train.asm index 14ccb02ba..43b1d716d 100644 --- a/engine/events/magnet_train.asm +++ b/engine/events/magnet_train.asm @@ -69,7 +69,7 @@ MagnetTrain: ld [wRequested2bppSource + 1], a ld [wRequested2bppDest], a ld [wRequested2bppDest + 1], a - ld [wRequested2bpp], a + ld [wRequested2bppSize], a call ClearTilemap pop af diff --git a/engine/events/mom_phone.asm b/engine/events/mom_phone.asm index f18685df8..3ff5f2b3e 100644 --- a/engine/events/mom_phone.asm +++ b/engine/events/mom_phone.asm @@ -228,9 +228,12 @@ MomItsInYourRoomText: text_far _MomItsInYourRoomText text_end - db 0 ; unused + +DummyPredef3A_DummyData: ; unreferenced + db 0 DummyPredef3A: ret - ret ; unused +DummyPredef3A_DummyFunction: ; unreferenced + ret diff --git a/engine/events/npc_trade.asm b/engine/events/npc_trade.asm index 94aaace72..6b32aff56 100644 --- a/engine/events/npc_trade.asm +++ b/engine/events/npc_trade.asm @@ -56,11 +56,12 @@ NPCTrade:: call DisableSpriteUpdates ld a, [wJumptableIndex] push af - ld a, [wcf64] + ; wTradeDialog aliases wFrameCounter, which TradeAnimation uses + ld a, [wTradeDialog] push af predef TradeAnimation pop af - ld [wcf64], a + ld [wTradeDialog], a pop af ld [wJumptableIndex], a call ReturnToMapWithSpeechTextbox @@ -107,7 +108,7 @@ Trade_GetDialog: ld e, NPCTRADE_DIALOG call GetTradeAttribute ld a, [hl] - ld [wcf64], a + ld [wTradeDialog], a ret DoNPCTrade: @@ -392,7 +393,7 @@ PrintTradeText: ld bc, 2 * 4 ld hl, TradeTexts call AddNTimes - ld a, [wcf64] + ld a, [wTradeDialog] ld c, a add hl, bc add hl, bc diff --git a/engine/events/overworld.asm b/engine/events/overworld.asm index 9c956e83b..0ca448930 100644 --- a/engine/events/overworld.asm +++ b/engine/events/overworld.asm @@ -271,7 +271,7 @@ CheckOverworldTileArrays: xor a ret -INCLUDE "data/events/field_move_blocks.asm" +INCLUDE "data/collision/field_move_blocks.asm" FlashFunction: call .CheckUseFlash @@ -1414,7 +1414,7 @@ HasRockSmash: ld d, ROCK_SMASH call CheckPartyMove jr nc, .yes -.no +; no ld a, 1 jr .done .yes @@ -1616,7 +1616,7 @@ RodNothingText: text_far _RodNothingText text_end -UnusedNothingHereText: ; unused +UnusedNothingHereText: ; unreferenced text_far _UnusedNothingHereText text_end @@ -1722,7 +1722,7 @@ Script_GetOnBike_Register: special UpdatePlayerSprite end -; unused +Overworld_DummyFunction: ; unreferenced nop ret diff --git a/engine/events/poisonstep.asm b/engine/events/poisonstep.asm index e6de6f19f..827f69411 100644 --- a/engine/events/poisonstep.asm +++ b/engine/events/poisonstep.asm @@ -149,6 +149,6 @@ DoPoisonStep:: text_far _PoisonFaintText text_end -.PoisonWhiteoutText: +.PoisonWhiteoutText: ; unreferenced text_far _PoisonWhiteoutText text_end diff --git a/engine/events/print_unown_2.asm b/engine/events/print_unown_2.asm index 0badae200..4926bf532 100644 --- a/engine/events/print_unown_2.asm +++ b/engine/events/print_unown_2.asm @@ -9,7 +9,7 @@ RotateUnownFrontpic: push bc push hl push bc - ld de, wd002 + ld de, wPrintedUnownTileSource call .Copy call .Rotate ld hl, UnownPrinter_GBPrinterRectangle @@ -19,10 +19,10 @@ RotateUnownFrontpic: ld a, [hli] ld e, a ld d, [hl] - ld hl, wd012 + ld hl, wPrintedUnownTileDest call .Copy pop hl - ld bc, $10 + ld bc, LEN_2BPP_TILE add hl, bc pop bc inc c @@ -30,7 +30,7 @@ RotateUnownFrontpic: cp 7 * 7 jr c, .loop - ld hl, wGameboyPrinterRAM + ld hl, wGameboyPrinter2bppSource ld de, sScratch ld bc, 7 * 7 tiles call CopyBytes @@ -44,7 +44,7 @@ RotateUnownFrontpic: ret .Copy: - ld c, $10 + ld c, LEN_2BPP_TILE .loop_copy ld a, [hli] ld [de], a @@ -54,18 +54,18 @@ RotateUnownFrontpic: ret .Rotate: - ld hl, wd012 + ld hl, wPrintedUnownTileDest ld e, %10000000 ld d, 8 .loop_decompress push hl - ld hl, wd002 + ld hl, wPrintedUnownTileSource call .CountSetBit pop hl ld a, b ld [hli], a push hl - ld hl, wd003 + ld hl, wPrintedUnownTileSource + 1 call .CountSetBit pop hl ld a, b @@ -100,7 +100,7 @@ y = 0 rept \1 x = \1 * (\2 - 1) + y rept \2 - dw wGameboyPrinterRAM tile x + dw wGameboyPrinter2bppSource tile x x = x - \2 endr y = y + 1 diff --git a/engine/events/prof_oaks_pc.asm b/engine/events/prof_oaks_pc.asm index 1be775a4c..b272e3fb5 100644 --- a/engine/events/prof_oaks_pc.asm +++ b/engine/events/prof_oaks_pc.asm @@ -36,18 +36,18 @@ Rate: ld hl, wPokedexSeen ld b, wEndPokedexSeen - wPokedexSeen call CountSetBits - ld [wd002], a + ld [wTempPokedexSeenCount], a ld hl, wPokedexCaught ld b, wEndPokedexCaught - wPokedexCaught call CountSetBits - ld [wd003], a + ld [wTempPokedexCaughtCount], a ; print appropriate rating call .UpdateRatingBuffers ld hl, OakPCText3 call PrintText call JoyWaitAorB - ld a, [wd003] + ld a, [wTempPokedexCaughtCount] ld hl, OakRatings call FindOakRating push de @@ -57,10 +57,10 @@ Rate: .UpdateRatingBuffers: ld hl, wStringBuffer3 - ld de, wd002 + ld de, wTempPokedexSeenCount call .UpdateRatingBuffer ld hl, wStringBuffer4 - ld de, wd003 + ld de, wTempPokedexCaughtCount call .UpdateRatingBuffer ret diff --git a/engine/events/specials.asm b/engine/events/specials.asm index 28cf2dd13..1333f27ce 100644 --- a/engine/events/specials.asm +++ b/engine/events/specials.asm @@ -15,7 +15,7 @@ Special:: INCLUDE "data/events/special_pointers.asm" -DummySpecial_c224: +UnusedDummySpecial: ret SetPlayerPalette: @@ -207,7 +207,7 @@ CardFlip: call StartGameCornerGame ret -DummyNonfunctionalGameCornerGame: +UnusedDummyGame: call CheckCoinsAndCoinCase ret c ld a, BANK(_DummyGame) @@ -380,17 +380,17 @@ GameboyCheck: ldh a, [hCGB] and a jr nz, .cgb - ldh a, [hSGB] and a jr nz, .sgb - -.gb +; gb xor a ; GBCHECK_GB jr .done + .sgb ld a, GBCHECK_SGB jr .done + .cgb ld a, GBCHECK_CGB .done diff --git a/engine/events/std_collision.asm b/engine/events/std_collision.asm index 8c54c0414..5ab112680 100644 --- a/engine/events/std_collision.asm +++ b/engine/events/std_collision.asm @@ -23,7 +23,7 @@ CheckFacingTileForStdScript:: xor a ret -INCLUDE "data/events/collision_stdscripts.asm" +INCLUDE "data/collision/collision_stdscripts.asm" Script_JumpStdFromRAM: sjump wJumpStdScriptBuffer diff --git a/engine/events/treemons.asm b/engine/events/treemons.asm index 680a9d7f5..9adcdbdc2 100644 --- a/engine/events/treemons.asm +++ b/engine/events/treemons.asm @@ -210,7 +210,7 @@ GetTreeScore: cp 5 jr c, .good -.bad +; bad xor a ; TREEMON_SCORE_BAD ret diff --git a/engine/games/card_flip.asm b/engine/games/card_flip.asm index 1244ca081..bee7aee11 100644 --- a/engine/games/card_flip.asm +++ b/engine/games/card_flip.asm @@ -1,7 +1,8 @@ CARDFLIP_LIGHT_OFF EQU "♂" ; $ef CARDFLIP_LIGHT_ON EQU "♀" ; $f5 -CARDFLIP_DECK_SIZE EQU 4 * 6 +CARDFLIP_DECK_SIZE EQUS "(wDeckEnd - wDeck)" + assert wDiscardPileEnd - wDiscardPile == wDeckEnd - wDeck DummyGameGFX: ; Graphics for an unused Game Corner diff --git a/engine/games/dummy_game.asm b/engine/games/dummy_game.asm index e4bb2d060..648346fc3 100644 --- a/engine/games/dummy_game.asm +++ b/engine/games/dummy_game.asm @@ -20,7 +20,7 @@ _DummyGame: ld a, BANK(DummyGameGFX) call FarCopyBytes ld a, $8 - ld hl, wc300 + ld hl, wSpriteAnimDict ld [hli], a ld [hl], $0 hlcoord 0, 0 @@ -133,11 +133,11 @@ endr .next_try dec [hl] xor a - ld [wcf64], a + ld [wDummyGameCardChoice], a ld hl, wJumptableIndex inc [hl] .PickCard1: - ld a, [wcf64] + ld a, [wDummyGameCardChoice] and a ret z dec a @@ -155,13 +155,13 @@ endr call DummyGame_Card2Coord call DummyGame_PlaceCard xor a - ld [wcf64], a + ld [wDummyGameCardChoice], a ld hl, wJumptableIndex inc [hl] ret .PickCard2: - ld a, [wcf64] + ld a, [wDummyGameCardChoice] and a ret z dec a @@ -527,7 +527,7 @@ DummyGame_InterpretJoypad_AnimateCursor: add hl, bc ld a, [hl] inc a - ld [wcf64], a + ld [wDummyGameCardChoice], a ret .pressed_left diff --git a/engine/games/slot_machine.asm b/engine/games/slot_machine.asm index 84f50e69d..0b2a08fac 100644 --- a/engine/games/slot_machine.asm +++ b/engine/games/slot_machine.asm @@ -249,7 +249,7 @@ DebugPrintSlotBias: ; unreferenced AnimateSlotReelIcons: ; unreferenced ; This animation was present in pokegold-spaceworld. - ld hl, wcf66 + ld hl, wUnusedSlotReelIconDelay ld a, [hl] inc [hl] and $7 diff --git a/engine/games/unown_puzzle.asm b/engine/games/unown_puzzle.asm index 871cb4541..48e36b899 100644 --- a/engine/games/unown_puzzle.asm +++ b/engine/games/unown_puzzle.asm @@ -504,13 +504,13 @@ CheckSolvedUnownPuzzle: RedrawUnownPuzzlePieces: call GetCurrentPuzzlePieceVTileCorner - ld [wd002], a + ld [wUnownPuzzleCornerTile], a xor a call GetUnownPuzzleCoordData ; get pixel positions ld a, [hli] ld b, [hl] ld c, a - ld a, [wd002] + ld a, [wUnownPuzzleCornerTile] cp $e0 jr z, .NoPiece ld hl, .OAM_HoldingPiece @@ -532,7 +532,7 @@ RedrawUnownPuzzlePieces: add c ld [de], a ; x inc de - ld a, [wd002] + ld a, [wUnownPuzzleCornerTile] add [hl] ld [de], a ; tile id inc hl diff --git a/engine/gfx/cgb_layouts.asm b/engine/gfx/cgb_layouts.asm index cd6f16cdb..66aeca079 100644 --- a/engine/gfx/cgb_layouts.asm +++ b/engine/gfx/cgb_layouts.asm @@ -17,19 +17,18 @@ LoadSGBLayoutCGB: ld l, a ld h, 0 add hl, hl - ld de, .dw + ld de, .Jumptable add hl, de ld a, [hli] ld h, [hl] ld l, a - ld de, .ReturnFromJumpTable + ld de, .done push de jp hl - -.ReturnFromJumpTable: +.done: ret -.dw +.Jumptable: dw _CGB_BattleGrayscale dw _CGB_BattleColors dw _CGB_PokegearPals @@ -43,7 +42,7 @@ LoadSGBLayoutCGB: dw _CGB_PartyMenu dw _CGB_Evolution dw _CGB_GSTitleScreen - dw _CGB0d + dw _CGB_Unused0D dw _CGB_MoveList dw _CGB_BetaPikachuMinigame dw _CGB_PokedexSearchOption @@ -60,7 +59,7 @@ LoadSGBLayoutCGB: dw _CGB_TradeTube dw _CGB_TrainerOrMonFrontpicPals dw _CGB_MysteryGift - dw _CGB1e + dw _CGB_Unused1E _CGB_BattleGrayscale: ld hl, PalPacket_BattleGrayscale + 1 @@ -321,12 +320,12 @@ _CGB_BillsPC: ldh [hCGBPalUpdate], a ret -Function9009: ; unreferenced +_CGB_Unknown: ; unreferenced ld hl, BillsPCOrangePalette call LoadHLPaletteIntoDE jr .GotPalette -.GetMonPalette: +.GetMonPalette: ; unreferenced ld bc, wTempMonDVs call GetPlayerOrMonPalettePointer call LoadPalette_White_Col1_Col2_Black @@ -595,7 +594,7 @@ _CGB_GSTitleScreen: ldh [hCGBPalUpdate], a ret -_CGB0d: +_CGB_Unused0D: ld hl, PalPacket_Diploma + 1 call CopyFourPalettes call WipeAttrmap @@ -911,7 +910,7 @@ _CGB_PlayerOrMonFrontpicPals: call ApplyPals ret -_CGB1e: +_CGB_Unused1E: ld de, wBGPals1 ld a, [wCurPartySpecies] call GetMonPalettePointer diff --git a/engine/gfx/color.asm b/engine/gfx/color.asm index 76c2dc504..9f42d24f6 100644 --- a/engine/gfx/color.asm +++ b/engine/gfx/color.asm @@ -15,31 +15,31 @@ CheckShininess: ; Attack ld a, [hl] and 1 << SHINY_ATK_BIT - jr z, .NotShiny + jr z, .not_shiny ; Defense ld a, [hli] and $f cp SHINY_DEF_VAL - jr nz, .NotShiny + jr nz, .not_shiny ; Speed ld a, [hl] and $f0 cp SHINY_SPD_VAL << 4 - jr nz, .NotShiny + jr nz, .not_shiny ; Special ld a, [hl] and $f cp SHINY_SPC_VAL - jr nz, .NotShiny + jr nz, .not_shiny -.Shiny: +; shiny scf ret -.NotShiny: +.not_shiny and a ret @@ -49,30 +49,30 @@ Unused_CheckShininess: ; Attack ld a, [hl] cp 10 << 4 - jr c, .NotShiny + jr c, .not_shiny ; Defense ld a, [hli] and $f cp 10 - jr c, .NotShiny + jr c, .not_shiny ; Speed ld a, [hl] cp 10 << 4 - jr c, .NotShiny + jr c, .not_shiny ; Special ld a, [hl] and $f cp 10 - jr c, .NotShiny + jr c, .not_shiny -.Shiny: +; shiny scf ret -.NotShiny: +.not_shiny and a ret @@ -136,6 +136,7 @@ SGB_ApplyPartyMenuHPPals: Intro_LoadMagikarpPalettes: ; unreferenced call CheckCGB ret z + ; CGB only ld hl, .BGPal ld de, wBGPals1 @@ -789,13 +790,13 @@ endr ret PushSGBPals: - ld a, [wcfbe] + ld a, [wJoypadDisable] push af - set 7, a - ld [wcfbe], a + set JOYPAD_DISABLE_SGB_TRANSFER_F, a + ld [wJoypadDisable], a call _PushSGBPals pop af - ld [wcfbe], a + ld [wJoypadDisable], a ret _PushSGBPals: @@ -841,12 +842,14 @@ _PushSGBPals: InitSGBBorder: call CheckCGB ret nz + ; SGB/DMG only di - ld a, [wcfbe] + ld a, [wJoypadDisable] push af - set 7, a - ld [wcfbe], a + set JOYPAD_DISABLE_SGB_TRANSFER_F, a + ld [wJoypadDisable], a + xor a ldh [rJOYP], a ldh [hSGB], a @@ -866,13 +869,14 @@ InitSGBBorder: .skip pop af - ld [wcfbe], a + ld [wJoypadDisable], a ei ret InitCGBPals:: call CheckCGB ret z + ; CGB only ld a, BANK(vTiles3) ldh [rVBK], a @@ -977,7 +981,7 @@ PushSGBBorder: .LoadSGBBorderPointers: ld hl, SGBBorderGFX - ld de, SGBBorderMap + ld de, SGBBorderMapAndPalettes ret SGB_ClearVRAM: @@ -1174,12 +1178,10 @@ INCLUDE "data/sgb_ctrl_packets.asm" PredefPals: INCLUDE "gfx/sgb/predef.pal" -SGBBorderMap: +SGBBorderMapAndPalettes: ; interleaved tile ids and palette ids, without the center 20x18 screen area INCBIN "gfx/sgb/sgb_border.sgb.tilemap" - -SGBBorderPalettes: -; assumed to come after SGBBorderMap +; four SGB palettes of 16 colors each; only the first 4 colors are used INCLUDE "gfx/sgb/sgb_border.pal" SGBBorderGFX: @@ -1317,7 +1319,7 @@ INCLUDE "gfx/diploma/diploma.pal" PartyMenuOBPals: INCLUDE "gfx/stats/party_menu_ob.pal" -UnusedBattleObjectPals: +UnusedBattleObjectPals: ; unreferenced INCLUDE "gfx/battle_anims/unused_battle_anims.pal" UnusedGSTitleBGPals: diff --git a/engine/gfx/crystal_layouts.asm b/engine/gfx/crystal_layouts.asm index 9c47797d1..1d3cca3ed 100644 --- a/engine/gfx/crystal_layouts.asm +++ b/engine/gfx/crystal_layouts.asm @@ -1,16 +1,16 @@ -GetMysteryGift_MobileAdapterLayout: +GetCrystalCGBLayout: ld a, b cp SCGB_DEFAULT - jr nz, .not_ram + jr nz, .not_default ld a, [wDefaultSGBLayout] -.not_ram +.not_default push af farcall ResetBGPals pop af ld l, a ld h, 0 add hl, hl - ld de, .dw + ld de, .Jumptable add hl, de ld a, [hli] ld h, [hl] @@ -18,15 +18,16 @@ GetMysteryGift_MobileAdapterLayout: ld de, .done push de jp hl -.done +.done: ret -.dw - dw MG_Mobile_Layout00 - dw MG_Mobile_Layout01 - dw MG_Mobile_Layout02 +.Jumptable: + dw _CrystalCGB_MobileLayout0 + dw _CrystalCGB_MobileLayout1 + dw _CrystalCGB_NameCard -MG_Mobile_Layout_FillBox: +Crystal_FillBoxCGB: +; This is a copy of FillBoxCGB. .row push bc push hl @@ -42,7 +43,8 @@ MG_Mobile_Layout_FillBox: jr nz, .row ret -MG_Mobile_Layout_WipeAttrmap: +Crystal_WipeAttrmap: +; This is a copy of WipeAttrmap. hlcoord 0, 0, wAttrmap ld bc, SCREEN_HEIGHT * SCREEN_WIDTH xor a @@ -62,9 +64,9 @@ MG_Mobile_Layout_LoadPals: call FarCopyWRAM ret -MG_Mobile_Layout00: +_CrystalCGB_MobileLayout0: call MG_Mobile_Layout_LoadPals - call MG_Mobile_Layout_WipeAttrmap + call Crystal_WipeAttrmap call MG_Mobile_Layout_CreatePalBoxes farcall ApplyAttrmap farcall ApplyPals @@ -74,33 +76,33 @@ MG_Mobile_Layout_CreatePalBoxes: hlcoord 0, 0, wAttrmap lb bc, 4, 1 ld a, $1 - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB lb bc, 2, 1 ld a, $2 - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB lb bc, 6, 1 ld a, $3 - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB hlcoord 1, 0, wAttrmap ld a, $1 lb bc, 3, 18 - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB lb bc, 2, 18 ld a, $2 - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB lb bc, 12, 18 ld a, $3 - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB hlcoord 19, 0, wAttrmap lb bc, 4, 1 ld a, $1 - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB lb bc, 2, 1 ld a, $2 - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB lb bc, 6, 1 ld a, $3 - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB hlcoord 0, 12, wAttrmap ld bc, 6 * SCREEN_WIDTH ld a, $7 @@ -129,14 +131,14 @@ Function49420:: call FarCopyWRAM ret -MG_Mobile_Layout01: +_CrystalCGB_MobileLayout1: call MG_Mobile_Layout_LoadPals ld de, wBGPals1 palette PAL_BG_TEXT - ld hl, .Palette_49478 + ld hl, .TextPalette ld bc, 1 palettes ld a, BANK(wBGPals1) call FarCopyWRAM - call MG_Mobile_Layout_WipeAttrmap + call Crystal_WipeAttrmap hlcoord 0, 0, wAttrmap ld bc, SCREEN_WIDTH * SCREEN_HEIGHT xor a @@ -149,19 +151,18 @@ MG_Mobile_Layout01: bit 6, a jr z, .asm_49464 call Function49480 - jr .asm_49467 + jr .done .asm_49464 call Function49496 - -.asm_49467 +.done farcall ApplyAttrmap farcall ApplyPals ld a, TRUE ldh [hCGBPalUpdate], a ret -.Palette_49478: +.TextPalette: RGB 31, 31, 31 RGB 26, 31, 00 RGB 20, 16, 03 @@ -171,7 +172,7 @@ Function49480: hlcoord 0, 0, wAttrmap lb bc, 4, SCREEN_WIDTH ld a, $7 - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB hlcoord 0, 2, wAttrmap ld a, $4 ld [hl], a @@ -183,7 +184,7 @@ Function49496: hlcoord 0, 0, wAttrmap lb bc, 2, SCREEN_WIDTH ld a, $7 - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB hlcoord 0, 1, wAttrmap ld a, $4 ld [hl], a @@ -193,29 +194,29 @@ Function49496: INCLUDE "engine/tilesets/tileset_palettes.asm" -MG_Mobile_Layout02: - ld hl, .Palette_49732 +_CrystalCGB_NameCard: + ld hl, .BGPalette ld de, wBGPals1 ld bc, 1 palettes ld a, BANK(wBGPals1) call FarCopyWRAM farcall ApplyPals - call MG_Mobile_Layout_WipeAttrmap + call Crystal_WipeAttrmap farcall ApplyAttrmap - ld hl, .Palette_4973a + ld hl, .OBPalette ld de, wOBPals1 ld bc, 1 palettes ld a, BANK(wOBPals1) call FarCopyWRAM ret -.Palette_49732: +.BGPalette: RGB 31, 31, 31 RGB 23, 16, 07 RGB 23, 07, 07 RGB 03, 07, 20 -.Palette_4973a: +.OBPalette: RGB 00, 00, 00 RGB 07, 05, 31 RGB 14, 18, 31 @@ -237,38 +238,38 @@ _InitMG_Mobile_LinkTradePalMap: hlcoord 0, 0, wAttrmap lb bc, 16, 2 ld a, $4 - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB ld a, $3 ldcoord_a 0, 1, wAttrmap ldcoord_a 0, 14, wAttrmap hlcoord 2, 0, wAttrmap lb bc, 8, 18 ld a, $5 - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB hlcoord 2, 8, wAttrmap lb bc, 8, 18 ld a, $6 - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB hlcoord 0, 16, wAttrmap lb bc, 2, SCREEN_WIDTH ld a, $4 - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB ld a, $3 lb bc, 6, 1 hlcoord 6, 1, wAttrmap - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB ld a, $3 lb bc, 6, 1 hlcoord 17, 1, wAttrmap - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB ld a, $3 lb bc, 6, 1 hlcoord 6, 9, wAttrmap - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB ld a, $3 lb bc, 6, 1 hlcoord 17, 9, wAttrmap - call MG_Mobile_Layout_FillBox + call Crystal_FillBoxCGB ld a, $2 hlcoord 2, 16, wAttrmap ld [hli], a diff --git a/engine/gfx/load_pics.asm b/engine/gfx/load_pics.asm index a8dc82892..98dbdc17b 100644 --- a/engine/gfx/load_pics.asm +++ b/engine/gfx/load_pics.asm @@ -208,7 +208,8 @@ GetMonBackpic: push de ; These are assumed to be at the same address in their respective banks. - ld hl, PokemonPicPointers ; UnownPicPointers + assert PokemonPicPointers == UnownPicPointers + ld hl, PokemonPicPointers ld a, b ld d, BANK(PokemonPicPointers) cp UNOWN diff --git a/engine/gfx/pic_animation.asm b/engine/gfx/pic_animation.asm index f2a59b75a..90bb06620 100644 --- a/engine/gfx/pic_animation.asm +++ b/engine/gfx/pic_animation.asm @@ -648,7 +648,7 @@ PokeAnim_ConvertAndApplyBitmask: .skip2 ret -; unused +.UnusedSizeData: ; unreferenced db 6, 5, 4 .GetTilemap: diff --git a/engine/gfx/player_gfx.asm b/engine/gfx/player_gfx.asm index 9a395e048..149c0ef4a 100644 --- a/engine/gfx/player_gfx.asm +++ b/engine/gfx/player_gfx.asm @@ -113,10 +113,10 @@ GetCardPic: ld bc, $23 tiles ld a, BANK(ChrisCardPic) ; aka BANK(KrisCardPic) call FarCopyBytes - ld hl, CardGFX + ld hl, TrainerCardGFX ld de, vTiles2 tile $23 ld bc, 6 tiles - ld a, BANK(CardGFX) + ld a, BANK(TrainerCardGFX) call FarCopyBytes ret @@ -126,7 +126,7 @@ INCBIN "gfx/trainer_card/chris_card.2bpp" KrisCardPic: INCBIN "gfx/trainer_card/kris_card.2bpp" -CardGFX: +TrainerCardGFX: INCBIN "gfx/trainer_card/trainer_card.2bpp" GetPlayerBackpic: diff --git a/engine/gfx/sgb_layouts.asm b/engine/gfx/sgb_layouts.asm index bfdaeb098..1e5055f26 100644 --- a/engine/gfx/sgb_layouts.asm +++ b/engine/gfx/sgb_layouts.asm @@ -35,7 +35,7 @@ LoadSGBLayout: dw .SGB_PartyMenu dw .SGB_Evolution dw .SGB_GSTitleScreen - dw .SGB0d + dw .SGB_Unused0D dw .SGB_MoveList dw .SGB_BetaPikachuMinigame dw .SGB_PokedexSearchOption @@ -52,7 +52,7 @@ LoadSGBLayout: dw .SGB_TradeTube dw .SGB_TrainerOrMonFrontpicPals dw .SGB_MysteryGift - dw .SGB1e + dw .SGB_Unused1E .SGB_BattleGrayscale: ld hl, PalPacket_BattleGrayscale @@ -397,7 +397,7 @@ endr ld de, BlkPacket_AllPal0 ret -.SGB0d: +.SGB_Unused0D: .SGB_TrainerCard: ld hl, PalPacket_Diploma ld de, BlkPacket_AllPal0 @@ -437,7 +437,7 @@ endr ld de, wSGBPals + PALPACKET_LENGTH ret -.SGB1e: +.SGB_Unused1E: ld hl, PalPacket_Pal01 ld de, wSGBPals ld bc, PALPACKET_LENGTH @@ -450,7 +450,7 @@ endr add hl, hl ld de, PokemonPalettes add hl, de - ld a, [wcf65] + ld a, [wUnusedSGB1eColorOffset] and 3 sla a sla a diff --git a/engine/gfx/sprite_anims.asm b/engine/gfx/sprite_anims.asm index 53fe6b882..0c2c42bcb 100644 --- a/engine/gfx/sprite_anims.asm +++ b/engine/gfx/sprite_anims.asm @@ -357,7 +357,7 @@ AnimSeq_SlotsGolem: AnimSeq_SlotsChansey: callfar Slots_AnimateChansey - ld hl, wcf64 + ld hl, wSlotsDelay ld a, [hl] cp $2 ret nz @@ -382,7 +382,7 @@ AnimSeq_SlotsChanseyEgg: jr c, .move_right call DeinitializeSprite ld a, $4 - ld [wcf64], a + ld [wSlotsDelay], a ld de, SFX_PLACE_PUZZLE_PIECE_DOWN call PlaySFX ret @@ -819,7 +819,7 @@ AnimSeq_IntroUnown: ret AnimSeq_IntroUnownF: - ld a, [wcf64] + ld a, [wSlotsDelay] cp $40 ret nz ld a, SPRITE_ANIM_FRAMESET_INTRO_UNOWN_F_2 diff --git a/engine/items/item_effects.asm b/engine/items/item_effects.asm index bc185500e..f91332761 100644 --- a/engine/items/item_effects.asm +++ b/engine/items/item_effects.asm @@ -1062,14 +1062,13 @@ LevelBallMultiplier: ld b, $ff ret -; These two texts were carried over from gen 1. -; They are not used in gen 2, and are dummied out. +; BallDodgedText and BallMissedText were used in Gen 1. -BallDodgedText: +BallDodgedText: ; unreferenced text_far _BallDodgedText text_end -BallMissedText: +BallMissedText: ; unreferenced text_far _BallMissedText text_end @@ -1896,14 +1895,14 @@ LoadCurHPIntoBuffer5: ld [wBuffer5], a ret -LoadHPIntoBuffer5: +LoadHPIntoBuffer5: ; unreferenced ld a, d ld [wBuffer6], a ld a, e ld [wBuffer5], a ret -LoadHPFromBuffer5: +LoadHPFromBuffer5: ; unreferenced ld a, [wBuffer6] ld d, a ld a, [wBuffer5] @@ -2167,11 +2166,12 @@ INCLUDE "data/items/x_stats.asm" PokeFluteEffect: ld a, [wBattleMode] and a - jr nz, .dummy -.dummy + jr nz, .in_battle + ; overworld flute code was dummied out here +.in_battle xor a - ld [wd002], a + ld [wPokeFluteCuredSleep], a ld b, $ff ^ SLP @@ -2194,7 +2194,7 @@ PokeFluteEffect: and b ld [hl], a - ld a, [wd002] + ld a, [wPokeFluteCuredSleep] and a ld hl, .PlayedFluteText jp z, PrintText @@ -2203,22 +2203,22 @@ PokeFluteEffect: ld a, [wLowHealthAlarm] and 1 << DANGER_ON_F - jr nz, .dummy2 -.dummy2 + jr nz, .dummy + ; more code was dummied out here +.dummy ld hl, .FluteWakeUpText jp PrintText .CureSleep: ld de, PARTYMON_STRUCT_LENGTH ld c, PARTY_LENGTH - .loop ld a, [hl] push af and SLP jr z, .not_asleep - ld a, 1 - ld [wd002], a + ld a, TRUE + ld [wPokeFluteCuredSleep], a .not_asleep pop af and b @@ -2291,7 +2291,7 @@ ItemfinderEffect: RestorePPEffect: ld a, [wCurItem] - ld [wd002], a + ld [wTempRestorePPItem], a .loop ; Party Screen opens to choose on which mon to use the Item @@ -2300,14 +2300,14 @@ RestorePPEffect: jp c, PPRestoreItem_Cancel .loop2 - ld a, [wd002] + ld a, [wTempRestorePPItem] cp MAX_ELIXER jp z, Elixer_RestorePPofAllMoves cp ELIXER jp z, Elixer_RestorePPofAllMoves ld hl, RaiseThePPOfWhichMoveText - ld a, [wd002] + ld a, [wTempRestorePPItem] cp PP_UP jr z, .ppup ld hl, RestoreThePPOfWhichMoveText @@ -2338,7 +2338,7 @@ RestorePPEffect: call CopyName1 pop hl - ld a, [wd002] + ld a, [wTempRestorePPItem] cp PP_UP jp nz, Not_PP_Up @@ -2353,7 +2353,6 @@ RestorePPEffect: jr c, .do_ppup .CantUsePPUpOnSketch: -.pp_is_maxed_out ld hl, PPIsMaxedOutText call PrintText jr .loop2 @@ -2488,7 +2487,7 @@ RestorePP: cp b jr nc, .dont_restore - ld a, [wd002] + ld a, [wTempRestorePPItem] cp MAX_ELIXER jr z, .restore_all cp MAX_ETHER @@ -2650,16 +2649,17 @@ WontHaveAnyEffectMessage: ld hl, ItemWontHaveEffectText jr CantUseItemMessage -BelongsToSomeoneElseMessage: +BelongsToSomeoneElseMessage: ; unreferenced ld hl, ItemBelongsToSomeoneElseText jr CantUseItemMessage -CyclingIsntAllowedMessage: +CyclingIsntAllowedMessage: ; unreferenced ld hl, NoCyclingText jr CantUseItemMessage -CantGetOnYourBikeMessage: +CantGetOnYourBikeMessage: ; unreferenced ld hl, ItemCantGetOnText + ; fallthrough CantUseItemMessage: ; Item couldn't be used. @@ -2711,11 +2711,11 @@ ItemUsedText: text_far _ItemUsedText text_end -ItemGotOnText: +ItemGotOnText: ; unreferenced text_far _ItemGotOnText text_end -ItemGotOffText: +ItemGotOffText: ; unreferenced text_far _ItemGotOffText text_end diff --git a/engine/items/items.asm b/engine/items/items.asm index 78b0e2cd9..42381b411 100644 --- a/engine/items/items.asm +++ b/engine/items/items.asm @@ -481,7 +481,7 @@ GetNumberedTMHM: jr c, .done cp ITEM_DC - (TM01 - 1) - 1 jr c, .skip_one -.skip_two +; skip two inc a .skip_one inc a diff --git a/engine/items/pack.asm b/engine/items/pack.asm index 4f8e7617f..17662cf60 100644 --- a/engine/items/pack.asm +++ b/engine/items/pack.asm @@ -1531,7 +1531,7 @@ PC_Mart_BallsPocketMenuHeader: dba PlaceMenuItemQuantity dba UpdateItemDescription -PackNoItemText: +PackNoItemText: ; unreferenced text_far _PackNoItemText text_end @@ -1571,7 +1571,7 @@ PackEmptyText: text_far _PackEmptyText text_end -YouCantUseItInABattleText: +YouCantUseItInABattleText: ; unreferenced text_far _YouCantUseItInABattleText text_end diff --git a/engine/items/tmhm.asm b/engine/items/tmhm.asm index fd8293603..ea990d849 100644 --- a/engine/items/tmhm.asm +++ b/engine/items/tmhm.asm @@ -159,7 +159,7 @@ TeachTMHM: and a ret -.unused +.didnt_use ; unreferenced ld a, 2 ld [wItemEffectSucceeded], a .learned_move diff --git a/engine/link/init_list.asm b/engine/link/init_list.asm index 470280c4b..3e16d3494 100644 --- a/engine/link/init_list.asm +++ b/engine/link/init_list.asm @@ -44,9 +44,9 @@ InitList: ld a, h ld [wListPointer + 1], a ld a, e - ld [wUnusedD102], a + ld [wUnusedNamesPointer], a ld a, d - ld [wUnusedD102 + 1], a + ld [wUnusedNamesPointer + 1], a ld bc, ItemAttributes ld a, c ld [wItemAttributesPtr], a diff --git a/engine/link/link.asm b/engine/link/link.asm index 3d6d5cf24..3fa34df03 100644 --- a/engine/link/link.asm +++ b/engine/link/link.asm @@ -27,10 +27,11 @@ LinkCommunications: call PlaceString call SetTradeRoomBGPals call WaitBGMap2 - ld hl, wcf5d - xor a ; LOW($5000) + ld hl, wLinkByteTimeout + assert LOW(SERIAL_LINK_BYTE_TIMEOUT) == 0 + xor a ; LOW(SERIAL_LINK_BYTE_TIMEOUT) ld [hli], a - ld [hl], HIGH($5000) + ld [hl], HIGH(SERIAL_LINK_BYTE_TIMEOUT) ld a, [wLinkMode] cp LINK_TIMECAPSULE jp nz, Gen2ToGen2LinkComms @@ -101,14 +102,14 @@ Gen2ToGen1LinkComms: ld a, [hl] pop hl and a - jp z, Function28b22 + jp z, ExitLinkCommunications cp $7 - jp nc, Function28b22 + jp nc, ExitLinkCommunications ld de, wLinkData ld bc, $1a2 call Link_CopyOTData - ld de, wPlayerTrademonSpecies - ld hl, wTimeCapsulePartyMon1Species + ld de, wPlayerTrademon + ld hl, wTimeCapsulePlayerData ld c, 2 .loop ld a, [de] @@ -162,12 +163,12 @@ Gen2ToGen1LinkComms: .done_party ld [de], a - ld hl, wTimeCapsulePartyMon1Species - call Function2868a + ld hl, wTimeCapsulePlayerData + call Link_ConvertPartyStruct1to2 ld a, LOW(wOTPartyMonOT) - ld [wUnusedD102], a + ld [wUnusedNamesPointer], a ld a, HIGH(wOTPartyMonOT) - ld [wUnusedD102 + 1], a + ld [wUnusedNamesPointer + 1], a ld de, MUSIC_NONE call PlayMusic ldh a, [hSerialConnectionStatus] @@ -253,8 +254,8 @@ Gen2ToGen2LinkComms: ld de, wLinkData ld bc, $1b9 call Link_CopyOTData - ld de, wPlayerTrademonSpecies - ld hl, wLinkPlayerPartyMon1Species + ld de, wPlayerTrademon + ld hl, wLinkPlayerData ld c, 2 .loop1 ld a, [de] @@ -407,9 +408,9 @@ Gen2ToGen2LinkComms: ld bc, wOTPartyDataEnd - wOTPartyMons call CopyBytes ld a, LOW(wOTPartyMonOT) - ld [wUnusedD102], a + ld [wUnusedNamesPointer], a ld a, HIGH(wOTPartyMonOT) - ld [wUnusedD102 + 1], a + ld [wUnusedNamesPointer + 1], a ld de, MUSIC_NONE call PlayMusic ldh a, [hSerialConnectionStatus] @@ -467,7 +468,7 @@ Gen2ToGen2LinkComms: pop af ld [wOptions], a farcall LoadPokemonData - jp Function28b22 + jp ExitLinkCommunications .ready_to_trade ld de, MUSIC_ROUTE_30 @@ -510,6 +511,8 @@ LinkTimeout: text_end ExchangeBytes: +; This is similar to Serial_ExchangeBytes, +; but without a SERIAL_PREAMBLE_BYTE check. ld a, TRUE ldh [hSerialIgnoringInitialData], a .loop @@ -520,9 +523,9 @@ ExchangeBytes: ld b, a inc hl ld a, 48 -.delay_cycles +.wait dec a - jr nz, .delay_cycles + jr nz, .wait ldh a, [hSerialIgnoringInitialData] and a ld a, b @@ -584,7 +587,7 @@ FixDataForLinkTransfer: ld [hli], a dec b jr nz, .loop3 - ld hl, wTimeCapsulePartyMon1 - 1 + PARTY_LENGTH + ld hl, wTimeCapsulePlayerData - 1 + PARTY_LENGTH ld de, wc612 lb bc, 0, 0 .loop4 @@ -831,7 +834,7 @@ Link_PrepPartyData_Gen2: ; Fill 5 bytes at wc9f4 with $20 ld de, wc9f4 ld a, $20 - call Function28682 + call Link_CopyMailPreamble ; Copy all the mail messages to wc9f9 ld a, BANK(sPartyMail) @@ -932,7 +935,8 @@ Link_PrepPartyData_Gen2: ld [de], a ret -Function28682: +Link_CopyMailPreamble: +; fill 5 bytes with the value of a, starting at de ld c, 5 .loop ld [de], a @@ -941,7 +945,7 @@ Function28682: jr nz, .loop ret -Function2868a: +Link_ConvertPartyStruct1to2: push hl ld d, h ld e, l @@ -1245,7 +1249,7 @@ LinkTradeOTPartymonMenuLoop: .not_d_up bit D_DOWN_F, a jp z, LinkTradePartiesMenuMasterLoop - jp Function28ac9 + jp LinkTradeCheckCancel LinkTrade_PlayerPartyMenu: farcall InitMG_Mobile_LinkTradePalMap @@ -1281,7 +1285,7 @@ LinkTradePartymonMenuLoop: .check_joypad bit A_BUTTON_F, a jr z, .not_a_button - jp Function28926 + jp LinkTrade_TradeStatsMenu .not_a_button bit D_DOWN_F, a @@ -1327,7 +1331,7 @@ LinkTradePartiesMenuMasterLoop: jp z, LinkTradePartymonMenuLoop ; PARTYMON jp LinkTradeOTPartymonMenuLoop ; OTPARTYMON -Function28926: +LinkTrade_TradeStatsMenu: call LoadTilemapToTempTilemap ld a, [wMenuCursorY] push af @@ -1423,14 +1427,14 @@ Function28926: pop af ld [wMenuCursorY], a dec a - ld [wd002], a + ld [wCurTradePartyMon], a ld [wPlayerLinkAction], a - farcall Function16d6ce + farcall PrintWaitingTextAndSyncAndExchangeNybble ld a, [wOtherPlayerLinkMode] cp $f jp z, InitTradeMenuDisplay - ld [wd003], a - call Function28b68 + ld [wCurOTTradePartyMon], a + call LinkTradePlaceArrow ld c, 100 call DelayFrames farcall ValidateOTTrademon @@ -1454,7 +1458,7 @@ Function28926: xor a ld [wcf57], a ld [wOtherPlayerLinkAction], a - ld a, [wd003] + ld a, [wCurOTTradePartyMon] ld hl, wOTPartySpecies ld c, a ld b, 0 @@ -1481,7 +1485,7 @@ Function28926: call PlaceString ld a, $1 ld [wPlayerLinkAction], a - farcall Function16d6ce + farcall PrintWaitingTextAndSyncAndExchangeNybble ld c, 100 call DelayFrames jp InitTradeMenuDisplay @@ -1497,7 +1501,7 @@ Function28926: text_far _LinkAbnormalMonText text_end -Function28ac9: +LinkTradeCheckCancel: ld a, [wMenuCursorY] cp 1 jp nz, LinkTradePartiesMenuMasterLoop @@ -1540,18 +1544,18 @@ Function28ade: ldcoord_a 9, 17 ld a, $f ld [wPlayerLinkAction], a - farcall Function16d6ce + farcall PrintWaitingTextAndSyncAndExchangeNybble ld a, [wOtherPlayerLinkMode] cp $f jr nz, .loop1 -Function28b22: +ExitLinkCommunications: call RotateThreePalettesRight call ClearScreen ld b, SCGB_DIPLOMA call GetSGBLayout call WaitBGMap2 xor a - ld [wcfbb], a + ld [wUnusedLinkCommunicationByte], a xor a ldh [rSB], a ldh [hSerialSend], a @@ -1561,15 +1565,18 @@ Function28b22: ldh [rSC], a ret -Function28b42: ; unreferenced +GSPlaceTradeScreenFooter: ; unreferenced +; Fill the screen footer with pattern tile hlcoord 0, 16 - ld a, "┘" + ld a, $7e ld bc, 2 * SCREEN_WIDTH call ByteFill +; Clear out area for cancel string hlcoord 1, 16 ld a, " " ld bc, SCREEN_WIDTH - 2 call ByteFill +; Place the string hlcoord 2, 16 ld de, .CancelString jp PlaceString @@ -1577,7 +1584,8 @@ Function28b42: ; unreferenced .CancelString: db "CANCEL@" -Function28b68: +LinkTradePlaceArrow: +; Indicates which pokemon the other player has selected to trade ld a, [wOtherPlayerLinkMode] hlcoord 6, 9 ld bc, SCREEN_WIDTH @@ -1610,7 +1618,7 @@ LinkTrade: ld c, 18 call LinkTextboxAtHL farcall Link_WaitBGMap - ld a, [wd002] + ld a, [wCurTradePartyMon] ld hl, wPartySpecies ld c, a ld b, 0 @@ -1619,10 +1627,10 @@ LinkTrade: ld [wNamedObjectIndexBuffer], a call GetPokemonName ld hl, wStringBuffer1 - ld de, wd004 + ld de, wBufferTrademonNick ld bc, MON_NAME_LENGTH call CopyBytes - ld a, [wd003] + ld a, [wCurOTTradePartyMon] ld hl, wOTPartySpecies ld c, a ld b, 0 @@ -1638,7 +1646,7 @@ LinkTrade: ld b, 3 ld c, 7 call LinkTextboxAtHL - ld de, String28eab + ld de, String_TradeCancel hlcoord 12, 8 call PlaceString ld a, 8 @@ -1666,12 +1674,12 @@ LinkTrade: call WaitBGMap2 pop af bit 1, a - jr nz, .asm_28c33 + jr nz, .canceled ld a, [wMenuCursorY] dec a - jr z, .asm_28c54 + jr z, .try_trade -.asm_28c33 +.canceled ld a, $1 ld [wPlayerLinkAction], a hlcoord 0, 12 @@ -1681,16 +1689,17 @@ LinkTrade: hlcoord 1, 14 ld de, String_TooBadTheTradeWasCanceled call PlaceString - farcall Function16d6ce - jp Function28ea3 + farcall PrintWaitingTextAndSyncAndExchangeNybble + jp InitTradeMenuDisplay_Delay -.asm_28c54 +.try_trade ld a, $2 ld [wPlayerLinkAction], a - farcall Function16d6ce + farcall PrintWaitingTextAndSyncAndExchangeNybble ld a, [wOtherPlayerLinkMode] dec a - jr nz, .asm_28c7b + jr nz, .do_trade +; If we're here, the other player canceled the trade hlcoord 0, 12 ld b, 4 ld c, 18 @@ -1698,11 +1707,11 @@ LinkTrade: hlcoord 1, 14 ld de, String_TooBadTheTradeWasCanceled call PlaceString - jp Function28ea3 + jp InitTradeMenuDisplay_Delay -.asm_28c7b +.do_trade ld hl, sPartyMail - ld a, [wd002] + ld a, [wCurTradePartyMon] ld bc, MAIL_STRUCT_LENGTH call AddNTimes ld a, BANK(sPartyMail) @@ -1711,20 +1720,20 @@ LinkTrade: ld e, l ld bc, MAIL_STRUCT_LENGTH add hl, bc - ld a, [wd002] + ld a, [wCurTradePartyMon] ld c, a -.asm_28c96 +.copy_mail inc c ld a, c cp PARTY_LENGTH - jr z, .asm_28ca6 + jr z, .copy_player_data push bc ld bc, MAIL_STRUCT_LENGTH call CopyBytes pop bc - jr .asm_28c96 + jr .copy_mail -.asm_28ca6 +.copy_player_data ld hl, sPartyMail ld a, [wPartyCount] dec a @@ -1732,18 +1741,22 @@ LinkTrade: call AddNTimes push hl ld hl, wc9f4 - ld a, [wd003] + ld a, [wCurOTTradePartyMon] ld bc, MAIL_STRUCT_LENGTH call AddNTimes pop de ld bc, MAIL_STRUCT_LENGTH call CopyBytes call CloseSRAM + +; Buffer player data +; nickname ld hl, wPlayerName ld de, wPlayerTrademonSenderName ld bc, NAME_LENGTH call CopyBytes - ld a, [wd002] +; species + ld a, [wCurTradePartyMon] ld hl, wPartySpecies ld b, 0 ld c, a @@ -1751,27 +1764,31 @@ LinkTrade: ld a, [hl] ld [wPlayerTrademonSpecies], a push af - ld a, [wd002] +; OT name + ld a, [wCurTradePartyMon] ld hl, wPartyMonOT call SkipNames ld de, wPlayerTrademonOTName ld bc, NAME_LENGTH call CopyBytes +; ID ld hl, wPartyMon1ID - ld a, [wd002] + ld a, [wCurTradePartyMon] call GetPartyLocation ld a, [hli] ld [wPlayerTrademonID], a ld a, [hl] ld [wPlayerTrademonID + 1], a +; DVs ld hl, wPartyMon1DVs - ld a, [wd002] + ld a, [wCurTradePartyMon] call GetPartyLocation ld a, [hli] ld [wPlayerTrademonDVs], a ld a, [hl] ld [wPlayerTrademonDVs + 1], a - ld a, [wd002] +; caught data + ld a, [wCurTradePartyMon] ld hl, wPartyMon1Species call GetPartyLocation ld b, h @@ -1779,38 +1796,46 @@ LinkTrade: farcall GetCaughtGender ld a, c ld [wPlayerTrademonCaughtData], a + +; Buffer other player data +; nickname ld hl, wOTPlayerName ld de, wOTTrademonSenderName ld bc, NAME_LENGTH call CopyBytes - ld a, [wd003] +; species + ld a, [wCurOTTradePartyMon] ld hl, wOTPartySpecies ld b, 0 ld c, a add hl, bc ld a, [hl] ld [wOTTrademonSpecies], a - ld a, [wd003] +; OT name + ld a, [wCurOTTradePartyMon] ld hl, wOTPartyMonOT call SkipNames ld de, wOTTrademonOTName ld bc, NAME_LENGTH call CopyBytes +; ID ld hl, wOTPartyMon1ID - ld a, [wd003] + ld a, [wCurOTTradePartyMon] call GetPartyLocation ld a, [hli] ld [wOTTrademonID], a ld a, [hl] ld [wOTTrademonID + 1], a +; DVs ld hl, wOTPartyMon1DVs - ld a, [wd003] + ld a, [wCurOTTradePartyMon] call GetPartyLocation ld a, [hli] ld [wOTTrademonDVs], a ld a, [hl] ld [wOTTrademonDVs + 1], a - ld a, [wd003] +; caught data + ld a, [wCurOTTradePartyMon] ld hl, wOTPartyMon1Species call GetPartyLocation ld b, h @@ -1818,14 +1843,16 @@ LinkTrade: farcall GetCaughtGender ld a, c ld [wOTTrademonCaughtData], a - ld a, [wd002] + + ld a, [wCurTradePartyMon] ld [wCurPartyMon], a ld hl, wPartySpecies ld b, 0 ld c, a add hl, bc ld a, [hl] - ld [wd002], a + ld [wCurTradePartyMon], a + xor a ; REMOVE_PARTY ld [wPokemonWithdrawDepositParameter], a callfar RemoveMonFromPartyOrBox @@ -1834,14 +1861,15 @@ LinkTrade: ld [wCurPartyMon], a ld a, TRUE ld [wForceEvolution], a - ld a, [wd003] + ld a, [wCurOTTradePartyMon] push af ld hl, wOTPartySpecies ld b, 0 ld c, a add hl, bc ld a, [hl] - ld [wd003], a + ld [wCurOTTradePartyMon], a + ld c, 100 call DelayFrames call ClearTilemap @@ -1933,7 +1961,7 @@ LinkTrade: ld c, 18 call LinkTextboxAtHL hlcoord 1, 14 - ld de, String28ebd + ld de, String_TradeCompleted call PlaceString farcall Link_WaitBGMap ld c, 50 @@ -1943,12 +1971,12 @@ LinkTrade: jp z, Gen2ToGen1LinkComms jp Gen2ToGen2LinkComms -Function28ea3: +InitTradeMenuDisplay_Delay: ld c, 100 call DelayFrames jp InitTradeMenuDisplay -String28eab: +String_TradeCancel: db "TRADE" next "CANCEL@" @@ -1956,7 +1984,7 @@ LinkAskTradeForText: text_far _LinkAskTradeForText text_end -String28ebd: +String_TradeCompleted: db "Trade completed!@" String_TooBadTheTradeWasCanceled: @@ -2248,7 +2276,7 @@ CheckLinkTimeout_Receptionist: ld a, $1 ld [wPlayerLinkAction], a ld hl, wLinkTimeoutFrames - ld a, $3 + ld a, 3 ld [hli], a xor a ld [hl], a diff --git a/engine/link/link_trade.asm b/engine/link/link_trade.asm index 3bec9c27c..4f4d3c5ce 100644 --- a/engine/link/link_trade.asm +++ b/engine/link/link_trade.asm @@ -15,7 +15,7 @@ Function16d42e: call CopyBytes ret -Function16d43b: +Function16d43b: ; unreferenced call LoadStandardMenuHeader call ClearBGPalettes call ClearTilemap @@ -153,15 +153,15 @@ LinkTextbox: call _LinkTextbox ret -Function16d6ce: +PrintWaitingTextAndSyncAndExchangeNybble: call LoadStandardMenuHeader - call Function16d6e1 + call .PrintWaitingText farcall WaitLinkTransfer call Call_ExitMenu call WaitBGMap2 ret -Function16d6e1: +.PrintWaitingText: hlcoord 4, 10 ld b, 1 ld c, 10 diff --git a/engine/link/mystery_gift.asm b/engine/link/mystery_gift.asm index e28167f14..8b4240c0c 100644 --- a/engine/link/mystery_gift.asm +++ b/engine/link/mystery_gift.asm @@ -1,3 +1,29 @@ +; hMGRole values +IR_RECEIVER EQU 1 +IR_SENDER EQU 2 + +; hMGStatusFlags error bits +MG_WRONG_CHECKSUM_F EQU 0 +MG_TIMED_OUT_F EQU 1 +MG_CANCELED_F EQU 4 +MG_WRONG_PREFIX_F EQU 7 + +; hMGStatusFlags values +MG_WRONG_CHECKSUM EQU 1 << MG_WRONG_CHECKSUM_F +MG_TIMED_OUT EQU 1 << MG_TIMED_OUT_F +MG_CANCELED EQU 1 << MG_CANCELED_F +MG_WRONG_PREFIX EQU 1 << MG_WRONG_PREFIX_F +MG_NOT_OKAY EQU MG_WRONG_CHECKSUM | MG_TIMED_OUT | MG_CANCELED | MG_WRONG_PREFIX +MG_OKAY EQU $ff ^ MG_NOT_OKAY +MG_START_END EQU %11111111 + +REGION_PREFIX EQU $96 +REGION_CODE EQU $90 ; USA + +MESSAGE_PREFIX EQU $5a + +NAME_CARD_PREFIX EQU $3c + DoMysteryGift: call ClearTilemap call ClearSprites @@ -7,22 +33,24 @@ DoMysteryGift: ld de, .String_PressAToLink_BToCancel call PlaceString call WaitBGMap - farcall PrepMysteryGiftDataToSend - call MysteryGift_ClearTrainerData - ld a, $2 - ld [wca01], a - ld a, $14 - ld [wca02], a - ldh a, [rIE] - push af - call Function104a95 + ; Prepare the first of two messages for wMysteryGiftPartnerData + farcall StageDataForMysteryGift + call ClearMysteryGiftTrainer + ld a, 2 + ld [wMysteryGiftMessageCount], a + ld a, wMysteryGiftPartnerDataEnd - wMysteryGiftPartnerData + ld [wMysteryGiftStagedDataLength], a + ldh a, [rIE] + push af + call ExchangeMysteryGiftData ld d, a xor a ldh [rIF], a pop af ldh [rIE], a + push de call ClearTilemap call EnableLCD @@ -31,15 +59,16 @@ DoMysteryGift: call GetSGBLayout call SetPalettes pop de + hlcoord 2, 8 ld a, d ld de, .MysteryGiftCanceledText ; Link has been canceled - cp $10 + cp MG_CANCELED jp z, .LinkCanceled - cp $6c + cp MG_OKAY jp nz, .CommunicationError - ld a, [wc900] - cp 3 + ld a, [wMysteryGiftGameVersion] + cp POKEMON_PIKACHU_2_VERSION jr z, .skip_checks call .CheckAlreadyGotFiveGiftsToday ld hl, .MysteryGiftFiveADayText ; Only 5 gifts a day @@ -54,12 +83,12 @@ DoMysteryGift: ld a, [wMysteryGiftPartnerBackupItem] and a jp nz, .FriendNotReady - ld a, [wc900] - cp 3 + ld a, [wMysteryGiftGameVersion] + cp POKEMON_PIKACHU_2_VERSION jr z, .skip_append_save call .AddMysteryGiftPartnerID - ld a, [wc900] - cp 4 + ld a, [wMysteryGiftGameVersion] + cp 4 ; ??? jr z, .skip_append_save call .SaveMysteryGiftTrainerName farcall RestoreMobileEventIndex @@ -68,14 +97,16 @@ DoMysteryGift: .skip_append_save ld a, [wMysteryGiftPartnerSentDeco] and a - jr z, .item + jr z, .SentItem +; sent decoration ld a, [wMysteryGiftPartnerWhichDeco] ld c, a farcall MysteryGiftGetDecoration push bc - call MysteryGift_CheckAndSetDecorationAlreadyReceived + call CheckAndSetMysteryGiftDecorationAlreadyReceived pop bc - jr nz, .item + jr nz, .SentItem +; keep the decoration if it wasn't already received callfar GetDecorationName_c ld h, d ld l, e @@ -85,17 +116,17 @@ DoMysteryGift: ld hl, .MysteryGiftSentHomeText ; sent decoration to home jr .PrintTextAndExit -.item +.SentItem: call GetMysteryGiftBank ld a, [wMysteryGiftPartnerWhichItem] ld c, a - farcall MysteryGiftGetItemHeldEffect + farcall MysteryGiftGetItem ld a, c ld [sBackupMysteryGiftItem], a ld [wNamedObjectIndexBuffer], a call CloseSRAM call GetItemName - ld hl, .MysteryGiftSentText ; sent item + ld hl, .MysteryGiftSentText ; sent item/decoration jr .PrintTextAndExit .LinkCanceled: @@ -113,6 +144,7 @@ DoMysteryGift: .FriendNotReady: ld hl, .YourFriendIsNotReadyText ; friend not ready + ; fallthrough .PrintTextAndExit: call PrintText @@ -162,7 +194,7 @@ DoMysteryGift: .CheckAlreadyGotFiveGiftsToday: call GetMysteryGiftBank ld a, [sNumDailyMysteryGiftPartnerIDs] - cp $5 + cp MAX_MYSTERY_GIFT_PARTNERS jp CloseSRAM .CheckAlreadyGotAGiftFromThatPerson: @@ -198,9 +230,9 @@ DoMysteryGift: ld hl, sNumDailyMysteryGiftPartnerIDs ld a, [hl] inc [hl] - ld hl, sDailyMysteryGiftPartnerIDs ; inc hl + ld hl, sDailyMysteryGiftPartnerIDs ; could have done "inc hl" instead ld e, a - ld d, $0 + ld d, 0 add hl, de add hl, de ld a, [wMysteryGiftPartnerID] @@ -211,226 +243,268 @@ DoMysteryGift: .SaveMysteryGiftTrainerName: call GetMysteryGiftBank - ld a, $1 + ld a, TRUE ld [sMysteryGiftTrainerHouseFlag], a ld hl, wMysteryGiftPartnerName ld de, sMysteryGiftPartnerName ld bc, NAME_LENGTH call CopyBytes - ld a, $1 + assert sMysteryGiftPartnerName + NAME_LENGTH == sMysteryGiftUnusedFlag + ld a, TRUE ld [de], a inc de - ld hl, wMysteryGiftTrainerData - ld bc, (1 + 1 + NUM_MOVES) * PARTY_LENGTH + 2 + assert sMysteryGiftUnusedFlag + 1 == sMysteryGiftTrainer + ld hl, wMysteryGiftTrainer + ld bc, wMysteryGiftTrainerEnd - wMysteryGiftTrainer call CopyBytes jp CloseSRAM -Function104a95: +ExchangeMysteryGiftData: di farcall ClearChannels - call Function104d5e + call InitializeIRCommunicationInterrupts -.loop2 - call Function104d96 - call Function104ddd +.restart + call BeginIRCommunication + call InitializeIRCommunicationRoles ldh a, [hMGStatusFlags] - cp $10 - jp z, Function104bd0 - cp $6c - jr nz, .loop2 - - ldh a, [hPrintNumBuffer + 8] - cp $2 - jr z, Function104b22 - ld hl, hPrintNumBuffer - ld b, $1 - call Function104d56 - jr nz, .ly_loop - call Function104b49 - jp nz, Function104bd0 - jr Function104b0a + cp MG_CANCELED + jp z, EndOrContinueMysteryGiftIRCommunication + cp MG_OKAY + jr nz, .restart + + ldh a, [hMGRole] + cp IR_SENDER + jr z, SenderExchangeMysteryGiftDataPayloads +; receiver + ld hl, hMGExchangedByte + ld b, 1 + call TryReceivingIRDataBlock + jr nz, .failed + call ReceiveMysteryGiftDataPayload_GotRegionPrefix + jp nz, EndOrContinueMysteryGiftIRCommunication + jr ReceiverExchangeMysteryGiftDataPayloads_GotPayload + +.failed ; Delay frame -.ly_loop +.wait_frame ldh a, [rLY] cp LY_VBLANK - jr c, .ly_loop + jr c, .wait_frame + ld c, LOW(rRP) - ld a, $c0 + ld a, rRP_ENABLE_READ_MASK ldh [c], a - ld b, 240 ; This might have been intended as a 4-second timeout buffer. - ; However, it is reset with each frame. -.loop3 - push bc - call MysteryGift_ReadJoypad - ld b, $2 + ld b, 60 * 4 ; 4 seconds +.continue + push bc + call MysteryGift_UpdateJoypad + ld b, 1 << rRP_RECEIVING ld c, LOW(rRP) - ; Delay frame -.ly_loop2 +.in_vblank ldh a, [c] and b ld b, a ldh a, [rLY] cp LY_VBLANK - jr nc, .ly_loop2 -.ly_loop3 + jr nc, .in_vblank +.wait_vblank ldh a, [c] and b ld b, a ldh a, [rLY] cp LY_VBLANK - jr c, .ly_loop3 - + jr c, .wait_vblank ld a, b pop bc + ; Restart if the 4-second timeout has elapsed dec b - jr z, .loop2 ; we never jump here + jr z, .restart + ; Restart if rRP is not receiving data or a - jr nz, .loop2 - ; Check if we've pressed the B button + jr nz, .restart + ; Check if we've pressed the B button to cancel ldh a, [hMGJoypadReleased] bit B_BUTTON_F, a - jr z, .loop3 - ld a, $10 + jr z, .continue + ld a, MG_CANCELED ldh [hMGStatusFlags], a - jp Function104bd0 - -Function104b04: - call Function104b40 - jp nz, Function104bd0 -Function104b0a: - call Function104d38 - jp nz, Function104bd0 - call Function104b88 - jp nz, Function104bd0 - call Function104d43 - jp nz, Function104bd0 - call Function105033 - jp Function104bd0 - -Function104b22: - call Function104b88 - jp nz, Function104bd0 - call Function104d43 - jp nz, Function104bd0 - call Function104b40 - jp nz, Function104bd0 - call Function104d38 - jp nz, Function104bd0 - call Function10502e - jp Function104bd0 - -Function104b40: - ld hl, hPrintNumBuffer - ld b, $1 - call Function104d56 + jp EndOrContinueMysteryGiftIRCommunication + +ReceiverExchangeMysteryGiftDataPayloads: + ; Receive the data payload + call ReceiveMysteryGiftDataPayload + jp nz, EndOrContinueMysteryGiftIRCommunication + ; fallthrough +ReceiverExchangeMysteryGiftDataPayloads_GotPayload: + ; Switch roles + call BeginSendingIRCommunication + jp nz, EndOrContinueMysteryGiftIRCommunication + ; Send the data payload + call SendMysteryGiftDataPayload + jp nz, EndOrContinueMysteryGiftIRCommunication + ; Switch roles + call BeginReceivingIRCommunication + jp nz, EndOrContinueMysteryGiftIRCommunication + ; Receive an empty block + call ReceiveEmptyIRDataBlock + jp EndOrContinueMysteryGiftIRCommunication + +SenderExchangeMysteryGiftDataPayloads: + ; Send the data payload + call SendMysteryGiftDataPayload + jp nz, EndOrContinueMysteryGiftIRCommunication + ; Switch roles + call BeginReceivingIRCommunication + jp nz, EndOrContinueMysteryGiftIRCommunication + ; Receive the data payload + call ReceiveMysteryGiftDataPayload + jp nz, EndOrContinueMysteryGiftIRCommunication + ; Switch roles + call BeginSendingIRCommunication + jp nz, EndOrContinueMysteryGiftIRCommunication + ; Send an empty block + call SendEmptyIRDataBlock + jp EndOrContinueMysteryGiftIRCommunication + +ReceiveMysteryGiftDataPayload: + ; Receive the region prefix + ld hl, hMGExchangedByte + ld b, 1 + call TryReceivingIRDataBlock ret nz - -Function104b49: - call Function105033 + ; fallthrough +ReceiveMysteryGiftDataPayload_GotRegionPrefix: + ; Receive an empty block + call ReceiveEmptyIRDataBlock ldh a, [hMGStatusFlags] - cp $6c + cp MG_OKAY ret nz - ldh a, [hPrintNumBuffer] - cp $96 - jp nz, Function104d32 - ld a, $90 - ldh [hPrintNumBuffer], a - call Function104d38 + ; Verify the received region prefix + ldh a, [hMGExchangedByte] + cp REGION_PREFIX + jp nz, WrongMysteryGiftRegion + ld a, REGION_CODE + ldh [hMGExchangedByte], a + ; Switch roles + call BeginSendingIRCommunication ret nz - ld hl, hPrintNumBuffer - ld b, $1 - call Function104d4e + ; Send the region code + ld hl, hMGExchangedByte + ld b, 1 + call TrySendingIRDataBlock ret nz - call Function10502e + ; Send an empty block + call SendEmptyIRDataBlock ldh a, [hMGStatusFlags] - cp $6c + cp MG_OKAY ret nz - call Function104d43 + ; Switch roles + call BeginReceivingIRCommunication ret nz - ld hl, wMysteryGiftTrainerData - ld a, [wca02] + ; Receive the staged data + ld hl, wMysteryGiftTrainer + ld a, [wMysteryGiftStagedDataLength] ld b, a - call Function104d56 + call TryReceivingIRDataBlock ret nz - call Function105033 + ; Receive an empty block + call ReceiveEmptyIRDataBlock ldh a, [hMGStatusFlags] - cp $6c + cp MG_OKAY ret -Function104b88: - ld a, $96 - ldh [hPrintNumBuffer], a - ld hl, hPrintNumBuffer - ld b, $1 - call Function104d4e +SendMysteryGiftDataPayload: + ; Send the region prefix + ld a, REGION_PREFIX + ldh [hMGExchangedByte], a + ld hl, hMGExchangedByte + ld b, 1 + call TrySendingIRDataBlock ret nz - call Function10502e + ; Send an empty block + call SendEmptyIRDataBlock ldh a, [hMGStatusFlags] - cp $6c + cp MG_OKAY ret nz - call Function104d43 + ; Switch roles + call BeginReceivingIRCommunication ret nz - ld hl, hPrintNumBuffer - ld b, $1 - call Function104d56 + ; Receive the region code + ld hl, hMGExchangedByte + ld b, 1 + call TryReceivingIRDataBlock ret nz - call Function105033 + ; Receive an empty block + call ReceiveEmptyIRDataBlock ldh a, [hMGStatusFlags] - cp $6c + cp MG_OKAY ret nz - ldh a, [hPrintNumBuffer] - cp $90 - jp nz, Function104d32 - call Function104d38 + ; Verify the received region code + ldh a, [hMGExchangedByte] + cp REGION_CODE + jp nz, WrongMysteryGiftRegion + ; Switch roles + call BeginSendingIRCommunication ret nz - ld hl, wLinkData - ld a, [wca02] + ; Send the staged data + ld hl, wMysteryGiftStaging + ld a, [wMysteryGiftStagedDataLength] ld b, a - call Function104d4e + call TrySendingIRDataBlock ret nz - call Function10502e + ; Send an empty block + call SendEmptyIRDataBlock ldh a, [hMGStatusFlags] - cp $6c + cp MG_OKAY ret -Function104bd0: +EndOrContinueMysteryGiftIRCommunication: nop ldh a, [hMGStatusFlags] - cp $10 + ; Quit if player canceled + cp MG_CANCELED jr z, .quit - cp $6c + ; Quit if there was a communication error + cp MG_OKAY jr nz, .quit - ld hl, wca01 + ; Quit if all messages are sent/received + ld hl, wMysteryGiftMessageCount dec [hl] jr z, .quit - ld hl, wMysteryGiftTrainerData + ; Quit if communicating with Pokémon Pikachu 2 device + ld hl, wMysteryGiftTrainer ld de, wMysteryGiftPartnerData ld bc, wMysteryGiftPartnerDataEnd - wMysteryGiftPartnerData call CopyBytes - ld a, [wMysteryGiftTrainerData] - cp $3 + ld a, [wMysteryGiftTrainer] ; first byte is the version + cp POKEMON_PIKACHU_2_VERSION jr nc, .quit + + ; Prepare the second message for wMysteryGiftTrainer farcall StagePartyDataForMysteryGift - call MysteryGift_ClearTrainerData - ld a, $26 - ld [wca02], a - ldh a, [hPrintNumBuffer + 8] - cp $2 - jr z, .asm_104c10 - call Function104d43 - jr nz, Function104bd0 - jp Function104b04 - -.asm_104c10 - call Function104d38 - jr nz, Function104bd0 - jp Function104b22 + call ClearMysteryGiftTrainer + ld a, wMysteryGiftTrainerEnd - wMysteryGiftTrainer + ld [wMysteryGiftStagedDataLength], a + + ldh a, [hMGRole] + cp IR_SENDER + jr z, .sender +; receiver + call BeginReceivingIRCommunication + jr nz, EndOrContinueMysteryGiftIRCommunication + jp ReceiverExchangeMysteryGiftDataPayloads + +.sender + call BeginSendingIRCommunication + jr nz, EndOrContinueMysteryGiftIRCommunication + jp SenderExchangeMysteryGiftDataPayloads .quit ldh a, [hMGStatusFlags] push af - call Function104da0 + call EndIRCommunication xor a ldh [rIF], a ldh a, [rIE] @@ -441,121 +515,153 @@ Function104bd0: pop af ret -Function104c2d: +ExchangeNameCardData: di farcall ClearChannels - call Function104d5e -.asm_104c37 - call Function104d96 - call Function104ddd + call InitializeIRCommunicationInterrupts + +.restart + call BeginIRCommunication + call InitializeIRCommunicationRoles ldh a, [hMGStatusFlags] - cp $10 - jp z, Function104d1c - cp $6c - jr nz, .asm_104c37 - ldh a, [hPrintNumBuffer + 8] - cp $2 - jr z, .asm_104c6c - call Function104c8a - jp nz, Function104d1c - call Function104d38 - jp nz, Function104d1c - call Function104cd2 - jp nz, Function104d1c - call Function104d43 - jp nz, Function104d1c - call Function105033 - jp Function104d1c -.asm_104c6c - call Function104cd2 - jp nz, Function104d1c - call Function104d43 - jp nz, Function104d1c - call Function104c8a - jp nz, Function104d1c - call Function104d38 - jp nz, Function104d1c - call Function10502e - jp Function104d1c - -Function104c8a: - ld hl, hPrintNumBuffer - ld b, $1 - call Function104d56 + cp MG_CANCELED + jp z, EndNameCardIRCommunication + cp MG_OKAY + jr nz, .restart + + ldh a, [hMGRole] + cp IR_SENDER + jr z, .sender +; receiver + ; Receive the data payload + call ReceiveNameCardDataPayload + jp nz, EndNameCardIRCommunication + ; Switch roles + call BeginSendingIRCommunication + jp nz, EndNameCardIRCommunication + ; Send the data payload + call SendNameCardDataPayload + jp nz, EndNameCardIRCommunication + ; Switch roles + call BeginReceivingIRCommunication + jp nz, EndNameCardIRCommunication + ; Receive an empty block + call ReceiveEmptyIRDataBlock + jp EndNameCardIRCommunication + +.sender + ; Send the data payload + call SendNameCardDataPayload + jp nz, EndNameCardIRCommunication + ; Switch roles + call BeginReceivingIRCommunication + jp nz, EndNameCardIRCommunication + ; Receive the data payload + call ReceiveNameCardDataPayload + jp nz, EndNameCardIRCommunication + ; Switch roles + call BeginSendingIRCommunication + jp nz, EndNameCardIRCommunication + ; Send an empty block + call SendEmptyIRDataBlock + jp EndNameCardIRCommunication + +ReceiveNameCardDataPayload: + ; Receive the Name Card prefix + ld hl, hMGExchangedByte + ld b, 1 + call TryReceivingIRDataBlock ret nz - call Function105033 + ; Receive an empty block + call ReceiveEmptyIRDataBlock ldh a, [hMGStatusFlags] - cp $6c + cp MG_OKAY ret nz - ldh a, [hPrintNumBuffer] - cp $3c - jp nz, Function104d32 + ; Verify the received Name Card prefix + ldh a, [hMGExchangedByte] + cp NAME_CARD_PREFIX + jp nz, WrongMysteryGiftRegion swap a - ldh [hPrintNumBuffer], a - call Function104d38 + ldh [hMGExchangedByte], a + ; Switch roles + call BeginSendingIRCommunication ret nz - ld hl, hPrintNumBuffer - ld b, $1 - call Function104d4e + ; Send the swapped Name Card prefix + ld hl, hMGExchangedByte + ld b, 1 + call TrySendingIRDataBlock ret nz - call Function10502e + ; Send an empty block + call SendEmptyIRDataBlock ldh a, [hMGStatusFlags] - cp $6c + cp MG_OKAY ret nz - call Function104d43 + ; Switch roles + call BeginReceivingIRCommunication ret nz - ld hl, wMysteryGiftTrainerData - ld a, [wca02] + ; Receive the staged data + ld hl, wNameCardData + ld a, [wMysteryGiftStagedDataLength] ld b, a - call Function104d56 + call TryReceivingIRDataBlock ret nz - call Function105033 + ; Receive an empty block + call ReceiveEmptyIRDataBlock ldh a, [hMGStatusFlags] - cp $6c + cp MG_OKAY ret -Function104cd2: - ld a, $3c - ldh [hPrintNumBuffer], a - ld hl, hPrintNumBuffer - ld b, $1 - call Function104d4e +SendNameCardDataPayload: + ; Send the Name Card prefix + ld a, NAME_CARD_PREFIX + ldh [hMGExchangedByte], a + ld hl, hMGExchangedByte + ld b, 1 + call TrySendingIRDataBlock ret nz - call Function10502e + ; Send an empty block + call SendEmptyIRDataBlock ldh a, [hMGStatusFlags] - cp $6c + cp MG_OKAY ret nz - call Function104d43 + ; Switch roles + call BeginReceivingIRCommunication ret nz - ld hl, hPrintNumBuffer - ld b, $1 - call Function104d56 + ; Receive the swapped Name Card prefix + ld hl, hMGExchangedByte + ld b, 1 + call TryReceivingIRDataBlock ret nz - call Function105033 + ; Receive an empty block + call ReceiveEmptyIRDataBlock ldh a, [hMGStatusFlags] - cp $6c + cp MG_OKAY ret nz - ldh a, [hPrintNumBuffer] + ; Verify the received swapped Name Card prefix + ldh a, [hMGExchangedByte] swap a - cp $3c - jp nz, Function104d32 - call Function104d38 + cp NAME_CARD_PREFIX + jp nz, WrongMysteryGiftRegion + ; Switch roles + call BeginSendingIRCommunication ret nz - ld hl, wLinkData - ld a, [wca02] + ; Send the staged data + ld hl, wMysteryGiftStaging + ld a, [wMysteryGiftStagedDataLength] ld b, a - call Function104d4e + call TrySendingIRDataBlock ret nz - call Function10502e + ; Send an empty block + call SendEmptyIRDataBlock ldh a, [hMGStatusFlags] - cp $6c + cp MG_OKAY ret -Function104d1c: +EndNameCardIRCommunication: nop ldh a, [hMGStatusFlags] push af - call Function104da0 + call EndIRCommunication xor a ldh [rIF], a ldh a, [rIE] @@ -566,46 +672,46 @@ Function104d1c: pop af ret -Function104d32: - ld a, $80 +WrongMysteryGiftRegion: + ld a, MG_WRONG_PREFIX ldh [hMGStatusFlags], a and a ret -Function104d38: - call Function104d96 - call Function104e46 +BeginSendingIRCommunication: + call BeginIRCommunication + call SendIRHelloMessage ldh a, [hMGStatusFlags] - cp $6c + cp MG_OKAY ret -Function104d43: - call Function104d96 - call Function104dfe +BeginReceivingIRCommunication: + call BeginIRCommunication + call ReceiveIRHelloMessage ldh a, [hMGStatusFlags] - cp $6c + cp MG_OKAY ret -Function104d4e: - call Function104e93 +TrySendingIRDataBlock: + call SendIRDataBlock ldh a, [hMGStatusFlags] - cp $6c + cp MG_OKAY ret -Function104d56: - call Function104f57 +TryReceivingIRDataBlock: + call ReceiveIRDataBlock ldh a, [hMGStatusFlags] - cp $6c + cp MG_OKAY ret -Function104d5e: - call Function104d74 +InitializeIRCommunicationInterrupts: + call StartFastIRTimer ld a, 1 << TIMER ldh [rIE], a xor a ldh [rIF], a - call Function104d96 -; runs for ~$40400 cycles + call BeginIRCommunication +; waits for ~$40400 cycles = ~0.25 seconds xor a ld b, a .busy_wait @@ -615,69 +721,76 @@ Function104d5e: jr nz, .busy_wait ret -Function104d74: +StartFastIRTimer: +; Starts a 65,536 Hz timer that interrupts every 3 increments (21,845 Hz). xor a ldh [rTAC], a - ld a, $fe + ld a, -2 ldh [rTMA], a ldh [rTIMA], a - ld a, $2 + ld a, rTAC_65536_HZ ldh [rTAC], a - or $4 + or 1 << rTAC_ON ldh [rTAC], a ret -Function104d86: +StartSlowIRTimer: +; Starts a 65,536 Hz timer that interrupts every 256 increments (256 Hz). xor a ldh [rTAC], a ldh [rTMA], a ldh [rTIMA], a - ld a, $2 + ld a, rTAC_65536_HZ ldh [rTAC], a - or $4 + or 1 << rTAC_ON ldh [rTAC], a ret -Function104d96: - ld a, $c0 - call Function104e8c - ld a, $1 - ldh [hPrintNumBuffer + 8], a +BeginIRCommunication: + ld a, rRP_ENABLE_READ_MASK + call ToggleIRCommunication + ld a, IR_RECEIVER + ldh [hMGRole], a ret -Function104da0: +EndIRCommunication: xor a - call Function104e8c - ld a, $2 + call ToggleIRCommunication + ld a, rTAC_65536_HZ ldh [rTAC], a ret -Function104da9: +ReceiveInfraredLEDOn: +; Count interrupts of the partner's IR LED on; quit after 256-d interrupts. +.recv_loop inc d ret z xor a ldh [rIF], a halt ldh a, [c] - bit 1, a - jr z, Function104da9 + bit rRP_RECEIVING, a + jr z, .recv_loop or a ret -Function104db7: +ReceiveInfraredLEDOff: +; Count interrupts of the partner's IR LED off; quit after 256-d interrupts. +.no_recv_loop inc d ret z xor a ldh [rIF], a halt ldh a, [c] - bit 1, a - jr nz, Function104db7 + bit rRP_RECEIVING, a + jr nz, .no_recv_loop or a ret -Function104dc5: - ld a, $c1 +SendInfraredLEDOn: +; Holds the IR LED on for d-1 interrupts. + ld a, rRP_ENABLE_READ_MASK | (1 << rRP_LED_ON) ldh [c], a .wait dec d @@ -687,8 +800,9 @@ Function104dc5: halt jr .wait -Function104dd1: - ld a, $c0 +SendInfraredLEDOff: +; Holds the IR LED off for d-1 interrupts. + ld a, rRP_ENABLE_READ_MASK ldh [c], a .wait dec d @@ -698,175 +812,204 @@ Function104dd1: halt jr .wait -Function104ddd: - ld d, $0 +InitializeIRCommunicationRoles: + ld d, 0 ld e, d - ld a, $1 - ldh [hPrintNumBuffer + 8], a + + ld a, IR_RECEIVER + ldh [hMGRole], a .loop - call MysteryGift_ReadJoypad - ld b, $2 + call MysteryGift_UpdateJoypad + ld b, 1 << rRP_RECEIVING ld c, LOW(rRP) + ; Check if we've pressed the B button to cancel ldh a, [hMGJoypadReleased] bit B_BUTTON_F, a - jr z, .next - ld a, $10 + jr z, .not_canceled + ld a, MG_CANCELED ldh [hMGStatusFlags], a ret -.next - bit 0, a - jr nz, Function104e3a +.not_canceled + ; Check if we've pressed the A button to start sending + bit A_BUTTON_F, a + jr nz, SendIRHelloMessageAfterDelay + ; If rRP is not receiving data, keep checking for input ldh a, [c] and b jr nz, .loop + ; fallthrough -Function104dfe: +ReceiveIRHelloMessage: ld c, LOW(rRP) - ld d, $0 + ld d, 0 ld e, d - call Function104db7 - jp z, Function104f42 + + call ReceiveInfraredLEDOff + jp z, InfraredLEDReceiveTimedOut ld d, e - call Function104da9 - jp z, Function104f42 - call Function104db7 - jp z, Function104f42 - call Function104da9 - jp z, Function104f42 - ld a, $6c + call ReceiveInfraredLEDOn + jp z, InfraredLEDReceiveTimedOut + call ReceiveInfraredLEDOff + jp z, InfraredLEDReceiveTimedOut + call ReceiveInfraredLEDOn + jp z, InfraredLEDReceiveTimedOut + + ld a, MG_OKAY ldh [hMGStatusFlags], a - ld d, $3d - call Function104dd1 - ld d, $5 - call Function104dc5 - ld d, $15 - call Function104dd1 - ld d, $5 - call Function104dc5 - ld d, $5 - call Function104dd1 + + ld d, 61 + call SendInfraredLEDOff + ld d, 5 + call SendInfraredLEDOn + ld d, 21 + call SendInfraredLEDOff + ld d, 5 + call SendInfraredLEDOn + ld d, 5 + call SendInfraredLEDOff ret -Function104e3a: +SendIRHelloMessageAfterDelay: ; Wait a random amount of time call Random ld e, a and $f ld d, a -.loop +.wait_loop dec de ld a, d or e - jr nz, .loop -Function104e46: - ld a, $2 - ldh [hPrintNumBuffer + 8], a + jr nz, .wait_loop + ; fallthrough + +SendIRHelloMessage: + ld a, IR_SENDER + ldh [hMGRole], a + ld c, LOW(rRP) - ld d, $0 + ld d, 0 ld e, d - ld d, $3d - call Function104dd1 - ld d, $5 - call Function104dc5 - ld d, $15 - call Function104dd1 - ld d, $5 - call Function104dc5 - ld d, $5 - call Function104dd1 + + ld d, 61 + call SendInfraredLEDOff + ld d, 5 + call SendInfraredLEDOn + ld d, 21 + call SendInfraredLEDOff + ld d, 5 + call SendInfraredLEDOn + ld d, 5 + call SendInfraredLEDOff + ld d, e - call Function104db7 - jp z, Function104f42 + call ReceiveInfraredLEDOff + jp z, InfraredLEDReceiveTimedOut ld d, e - call Function104da9 - jp z, Function104f42 - call Function104db7 - jp z, Function104f42 - call Function104da9 - jp z, Function104f42 - ld d, $3d - call Function104dd1 - ld a, $6c + call ReceiveInfraredLEDOn + jp z, InfraredLEDReceiveTimedOut + call ReceiveInfraredLEDOff + jp z, InfraredLEDReceiveTimedOut + call ReceiveInfraredLEDOn + jp z, InfraredLEDReceiveTimedOut + + ld d, 61 + call SendInfraredLEDOff + + ld a, MG_OKAY ldh [hMGStatusFlags], a ret -Function104e8c: +ToggleIRCommunication: ldh [rRP], a - ld a, $ff + ld a, MG_START_END ldh [hMGStatusFlags], a ret -Function104e93: +SendIRDataBlock: +; Send b bytes of data in three messages: +; 1. two bytes: MESSAGE_PREFIX and the length b +; 2. b bytes: the actual data +; 3. two bytes: a little-endian checksum +; Then receive a one-byte acknowledgement message: the status. xor a - ldh [hPrintNumBuffer + 4], a - ldh [hPrintNumBuffer + 5], a + ldh [hMGChecksum + 0], a + ldh [hMGChecksum + 1], a push hl push bc ld c, LOW(rRP) - ld d, $3d - call Function104dd1 - ld hl, hPrintNumBuffer + 1 - ld a, $5a + ld d, 61 + call SendInfraredLEDOff + ld hl, hMGExchangedWord + ld a, MESSAGE_PREFIX ld [hli], a ld [hl], b dec hl - ld b, $2 - call Function104ed6 + ld b, 2 + call SendIRDataMessage pop bc pop hl - call Function104ed6 - ldh a, [hPrintNumBuffer + 4] - ldh [hPrintNumBuffer + 1], a - ldh a, [hPrintNumBuffer + 5] - ldh [hPrintNumBuffer + 2], a + call SendIRDataMessage + ldh a, [hMGChecksum + 0] + ldh [hMGExchangedWord + 0], a + ldh a, [hMGChecksum + 1] + ldh [hMGExchangedWord + 1], a push hl - ld hl, hPrintNumBuffer + 1 - ld b, $2 - call Function104ed6 + ld hl, hMGExchangedWord + ld b, 2 + call SendIRDataMessage ld hl, hMGStatusFlags - ld b, $1 - call Function104faf - ldh a, [hPrintNumBuffer + 1] - ldh [hPrintNumBuffer + 4], a - ldh a, [hPrintNumBuffer + 2] - ldh [hPrintNumBuffer + 5], a + ld b, 1 + call ReceiveIRDataMessage + ldh a, [hMGExchangedWord + 0] + ldh [hMGChecksum + 0], a + ldh a, [hMGExchangedWord + 1] + ldh [hMGChecksum + 1], a pop hl ret -Function104ed6: +SendIRDataMessage: +; Send b bytes of data one bit at a time, and update the checksum. ld c, LOW(rRP) - ld d, $5 - call Function104dd1 - ld d, $5 - call Function104dc5 - ld d, $15 - call Function104dd1 + + ld d, 5 + call SendInfraredLEDOff + ld d, 5 + call SendInfraredLEDOn + ld d, 21 + call SendInfraredLEDOff + + ; b = -b - 1; then count up to 0 ld a, b cpl ld b, a - ld a, $f4 + + ld a, -12 ldh [rTMA], a -.main_loop +.byte_loop inc b jr z, .done - ld a, $8 - ldh [hPrintNumBuffer + 3], a + ld a, 8 + ldh [hMGNumBits], a + ; Get the next data byte ld a, [hli] ld e, a - ldh a, [hPrintNumBuffer + 4] + ; Add the next data byte to the checksum + ldh a, [hMGChecksum + 0] add e - ldh [hPrintNumBuffer + 4], a - ldh a, [hPrintNumBuffer + 5] + ldh [hMGChecksum + 0], a + ldh a, [hMGChecksum + 1] adc 0 - ldh [hPrintNumBuffer + 5], a -.inner_loop + ldh [hMGChecksum + 1], a + ; Send each bit of the byte +.bit_loop xor a ldh [rIF], a halt - ld a, $c1 + ld a, rRP_ENABLE_READ_MASK | (1 << rRP_LED_ON) ldh [rRP], a - ld d, $1 + ; Turn the LED off for longer if the bit is 1 + ld d, 1 ld a, e rlca ld e, a @@ -874,9 +1017,9 @@ Function104ed6: inc d .wait ldh a, [rTIMA] - cp $f8 + cp -8 jr c, .wait - ld a, $c0 + ld a, rRP_ENABLE_READ_MASK ldh [rRP], a dec d jr z, .no_halt @@ -884,133 +1027,145 @@ Function104ed6: ldh [rIF], a halt .no_halt - ldh a, [hPrintNumBuffer + 3] + ldh a, [hMGNumBits] dec a - jr z, .main_loop - ldh [hPrintNumBuffer + 3], a - jr .inner_loop + jr z, .byte_loop + ldh [hMGNumBits], a + jr .bit_loop .done - ld a, $fe + ld a, -2 ldh [rTMA], a xor a ldh [rIF], a halt - ld d, $5 - call Function104dc5 - ld d, $11 - call Function104dd1 + + ld d, 5 + call SendInfraredLEDOn + ld d, 17 + call SendInfraredLEDOff ret -Function104f42: +InfraredLEDReceiveTimedOut: ldh a, [hMGStatusFlags] - or $2 + or MG_TIMED_OUT ldh [hMGStatusFlags], a ret -Function104f49: +ReceivedWrongIRChecksum: ldh a, [hMGStatusFlags] - or $1 + or MG_WRONG_CHECKSUM ldh [hMGStatusFlags], a ret -Function104f50: +ReceivedWrongIRMessagePrefix: ldh a, [hMGStatusFlags] - or $80 + or MG_WRONG_PREFIX ldh [hMGStatusFlags], a ret -Function104f57: +ReceiveIRDataBlock: +; Receive b bytes of data in three messages: +; 1. two bytes: MESSAGE_PREFIX and the length b +; 2. b bytes: the actual data +; 3. two bytes: a little-endian checksum +; Then send a one-byte acknowledgement message: the status. xor a - ldh [hPrintNumBuffer + 4], a - ldh [hPrintNumBuffer + 5], a + ldh [hMGChecksum + 0], a + ldh [hMGChecksum + 1], a push bc push hl - ld hl, hPrintNumBuffer + 1 - ld b, $2 - call Function104faf - ldh a, [hPrintNumBuffer + 2] - ldh [hPrintNumBuffer + 7], a + ld hl, hMGExchangedWord + ld b, 2 + call ReceiveIRDataMessage + ldh a, [hMGExchangedWord + 1] + ldh [hMGUnusedMsgLength], a ld b, a pop hl pop af cp b - jp c, Function104f50 - ldh a, [hPrintNumBuffer + 1] - cp $5a - jp nz, Function104f50 - call Function104faf - ldh a, [hPrintNumBuffer + 4] + jp c, ReceivedWrongIRMessagePrefix + ldh a, [hMGExchangedWord + 0] + cp MESSAGE_PREFIX + jp nz, ReceivedWrongIRMessagePrefix + call ReceiveIRDataMessage + ldh a, [hMGChecksum + 0] ld d, a - ldh a, [hPrintNumBuffer + 5] + ldh a, [hMGChecksum + 1] ld e, a push hl push de - ld hl, hPrintNumBuffer + 1 - ld b, $2 - call Function104faf + ld hl, hMGExchangedWord + ld b, 2 + call ReceiveIRDataMessage pop de - ld hl, hPrintNumBuffer + 1 + ld hl, hMGExchangedWord ld a, [hli] xor d ld b, a ld a, [hl] xor e or b - call nz, Function104f49 + call nz, ReceivedWrongIRChecksum push de - ld d, $3d - call Function104dd1 + + ld d, 61 + call SendInfraredLEDOff + ld hl, hMGStatusFlags - ld b, $1 - call Function104ed6 + ld b, 1 + call SendIRDataMessage + pop de pop hl ld a, d - ldh [hPrintNumBuffer + 4], a + ldh [hMGChecksum + 0], a ld a, e - ldh [hPrintNumBuffer + 5], a + ldh [hMGChecksum + 1], a ret -Function104faf: +ReceiveIRDataMessage: ld c, LOW(rRP) - ld d, $0 - call Function104db7 - jp z, Function104f42 - ld d, $0 - call Function104da9 - jp z, Function104f42 - ld d, $0 - call Function104db7 - jp z, Function104f42 + + ld d, 0 + call ReceiveInfraredLEDOff + jp z, InfraredLEDReceiveTimedOut + ld d, 0 + call ReceiveInfraredLEDOn + jp z, InfraredLEDReceiveTimedOut + ld d, 0 + call ReceiveInfraredLEDOff + jp z, InfraredLEDReceiveTimedOut + ld a, b cpl ld b, a xor a ldh [hMGPrevTIMA], a - call Function104d86 + + call StartSlowIRTimer .main_loop inc b jr z, .done - ld a, $8 - ldh [hPrintNumBuffer + 3], a + ld a, 8 + ldh [hMGNumBits], a .inner_loop - ld d, $0 -.wait_one + ld d, 0 +.recv_loop inc d - jr z, .got_one + jr z, .recv_done ldh a, [c] - bit 1, a - jr z, .wait_one - ld d, $0 -.got_one -.wait_zero + bit rRP_RECEIVING, a + jr z, .recv_loop + ld d, 0 +.recv_done +.send_loop inc d - jr z, .got_zero + jr z, .send_done ldh a, [c] - bit 1, a - jr nz, .wait_zero -.got_zero + bit rRP_RECEIVING, a + jr nz, .send_loop +.send_done ldh a, [hMGPrevTIMA] ld d, a ldh a, [rTIMA] @@ -1023,9 +1178,9 @@ Function104faf: .zero res 0, e .ok - ldh a, [hPrintNumBuffer + 3] + ldh a, [hMGNumBits] dec a - ldh [hPrintNumBuffer + 3], a + ldh [hMGNumBits], a jr z, .continue ld a, e rlca @@ -1035,34 +1190,35 @@ Function104faf: .continue ld a, e ld [hli], a - ldh a, [hPrintNumBuffer + 4] + ldh a, [hMGChecksum + 0] add e - ldh [hPrintNumBuffer + 4], a - ldh a, [hPrintNumBuffer + 5] + ldh [hMGChecksum + 0], a + ldh a, [hMGChecksum + 1] adc 0 - ldh [hPrintNumBuffer + 5], a + ldh [hMGChecksum + 1], a jr .main_loop .done - call Function104d74 + call StartFastIRTimer xor a ldh [rIF], a - ld d, $0 - call Function104da9 - jp z, Function104f42 - ld d, $10 - call Function104dd1 + ld d, 0 + call ReceiveInfraredLEDOn + jp z, InfraredLEDReceiveTimedOut + + ld d, 16 + call SendInfraredLEDOff ret -Function10502e: - ld b, $0 - jp Function104e93 +SendEmptyIRDataBlock: + ld b, 0 + jp SendIRDataBlock -Function105033: - ld b, $0 - jp Function104f57 +ReceiveEmptyIRDataBlock: + ld b, 0 + jp ReceiveIRDataBlock -MysteryGift_ReadJoypad: +MysteryGift_UpdateJoypad: ; We can only get four inputs at a time. ; We take d-pad first for no particular reason. ld a, R_DPAD @@ -1107,9 +1263,10 @@ endr ldh [rJOYP], a ret -MysteryGift_CheckAndSetDecorationAlreadyReceived: +CheckAndSetMysteryGiftDecorationAlreadyReceived: +; Return nz if decoration c was already received; otherwise receive it. call GetMysteryGiftBank - ld d, $0 + ld d, 0 ld b, CHECK_FLAG ld hl, sMysteryGiftDecorationsReceived lda_predef SmallFarFlagAction @@ -1129,12 +1286,12 @@ MysteryGift_CheckAndSetDecorationAlreadyReceived: xor a ret -MysteryGift_CopyReceivedDecosToPC: +CopyMysteryGiftReceivedDecorationsToPC: call GetMysteryGiftBank - ld c, $0 + ld c, 0 .loop push bc - ld d, $0 + ld d, 0 ld b, CHECK_FLAG ld hl, sMysteryGiftDecorationsReceived predef SmallFarFlagAction @@ -1148,57 +1305,68 @@ MysteryGift_CopyReceivedDecosToPC: .skip inc c ld a, c - cp TrophyIDs - DecorationIDs + cp NUM_NON_TROPHY_DECOS jr c, .loop jp CloseSRAM UnlockMysteryGift: +; If [sMysteryGiftUnlocked] was -1, this sets both +; [sMysteryGiftUnlocked] and [sMysteryGiftItem] to 0. call GetMysteryGiftBank ld hl, sMysteryGiftUnlocked ld a, [hl] inc a jr nz, .ok ld [hld], a + assert sMysteryGiftUnlocked - 1 == sMysteryGiftItem ld [hl], a .ok jp CloseSRAM -Function1050c8: +ResetDailyMysteryGiftLimitIfUnlocked: call GetMysteryGiftBank ld a, [sNumDailyMysteryGiftPartnerIDs] - cp $ff - jr z, .okay + cp -1 ; locked? + jr z, .dont_clear xor a ld [sNumDailyMysteryGiftPartnerIDs], a -.okay +.dont_clear jp CloseSRAM BackupMysteryGift: +; Copies [sMysteryGiftItem] to [sBackupMysteryGiftItem], +; and [sMysteryGiftUnlocked] to [sNumDailyMysteryGiftPartnerIDs]. call GetMysteryGiftBank ld hl, sMysteryGiftItem ld de, sBackupMysteryGiftItem ld a, [hli] ld [de], a inc de + assert sMysteryGiftItem + 1 == sMysteryGiftUnlocked + assert sBackupMysteryGiftItem + 1 == sNumDailyMysteryGiftPartnerIDs ld a, [hl] ld [de], a jp CloseSRAM RestoreMysteryGift: +; Copies [sBackupMysteryGiftItem] to [sMysteryGiftItem], +; and [sNumDailyMysteryGiftPartnerIDs] to [sMysteryGiftUnlocked]. call GetMysteryGiftBank ld hl, sBackupMysteryGiftItem ld de, sMysteryGiftItem ld a, [hli] ld [de], a inc de + assert sBackupMysteryGiftItem + 1 == sNumDailyMysteryGiftPartnerIDs + assert sMysteryGiftItem + 1 == sMysteryGiftUnlocked ld a, [hl] ld [de], a jp CloseSRAM -MysteryGift_ClearTrainerData: - ld hl, wMysteryGiftTrainerData +ClearMysteryGiftTrainer: + ld hl, wMysteryGiftTrainer xor a - ld b, wMysteryGiftTrainerDataEnd - wMysteryGiftTrainerData + ld b, wMysteryGiftTrainerEnd - wMysteryGiftTrainer .loop ld [hli], a dec b @@ -1206,7 +1374,7 @@ MysteryGift_ClearTrainerData: ret GetMysteryGiftBank: - ld a, BANK(sBackupMysteryGiftItem) + ld a, BANK(sMysteryGiftData) jp OpenSRAM StagePartyDataForMysteryGift: @@ -1256,8 +1424,8 @@ StagePartyDataForMysteryGift: .party_end ld a, -1 ld [de], a - ld a, $26 - ld [wca00], a + ld a, wMysteryGiftTrainerEnd - wMysteryGiftTrainer + ld [wUnusedMysteryGiftStagedDataLength], a jp CloseSRAM InitMysteryGiftLayout: @@ -1399,22 +1567,22 @@ InitMysteryGiftLayout: MysteryGiftGFX: INCBIN "gfx/mystery_gift/mystery_gift.2bpp" -Function105688: +DoNameCardSwap: call ClearTilemap call ClearSprites call WaitBGMap - call Function1057d7 + call InitNameCardLayout hlcoord 3, 8 - ld de, String_PressAToLink_BToCancel_JP + ld de, .String_PressAToLink_BToCancel_JP call PlaceString call WaitBGMap - call Function10578c - call MysteryGift_ClearTrainerData - ld a, $24 - ld [wca02], a + call StageDataForNameCard + call ClearMysteryGiftTrainer + ld a, wNameCardDataEnd - wNameCardData + ld [wMysteryGiftStagedDataLength], a ldh a, [rIE] push af - call Function104c2d + call ExchangeNameCardData ld d, a xor a ldh [rIF], a @@ -1422,25 +1590,25 @@ Function105688: ldh [rIE], a ld a, d cp $10 - jp z, Function105712 - cp $6c - jp nz, Function10571a - call Function1056eb + jp z, .LinkCanceled + cp MG_OKAY + jp nz, .CommunicationError + call .SlideNameCardUpOffScreen ld c, 60 call DelayFrames - call Function105777 - ld hl, MysteryGiftReceivedCardText + call .ClearScreen + ld hl, .NameCardReceivedCardText call PrintText - ld de, wMysteryGiftTrainerData + ld de, wNameCardData farcall Function8ac70 ld a, c ld [wDeciramBuffer], a - ld hl, MysteryGiftNotRegisteredCardText - jr c, PrintTextAndExit_JP - ld hl, MysteryGiftListedCardText - jr PrintTextAndExit_JP + ld hl, .NameCardNotRegisteredCardText + jr c, .PrintTextAndExit + ld hl, .NameCardListedCardText + jr .PrintTextAndExit -Function1056eb: +.SlideNameCardUpOffScreen: ld c, 16 .loop ld hl, wVirtualOAMSprite00YCoord @@ -1469,51 +1637,51 @@ endr pop bc jr .loop -Function105712: - call Function105777 - ld hl, MysteryGiftLinkCancelledText - jr PrintTextAndExit_JP +.LinkCanceled: + call .ClearScreen + ld hl, .NameCardLinkCancelledText + jr .PrintTextAndExit -Function10571a: - call Function105777 - ld hl, MysteryGiftLinkCommErrorText +.CommunicationError: + call .ClearScreen + ld hl, .NameCardCommErrorText call PrintText - jp Function105688 + jp DoNameCardSwap -PrintTextAndExit_JP: +.PrintTextAndExit: call PrintText ld a, LCDC_DEFAULT ldh [rLCDC], a ret -String_PressAToLink_BToCancel_JP: +.String_PressAToLink_BToCancel_JP: db "エーボタン<WO>おすと" next "つうしん<PKMN>おこなわれるよ!" next "ビーボタン<WO>おすと" next "つうしん<WO>ちゅうし します" db "@" -MysteryGiftReceivedCardText: - text_far _MysteryGiftReceivedCardText +.NameCardReceivedCardText: + text_far _NameCardReceivedCardText text_end -MysteryGiftListedCardText: - text_far _MysteryGiftListedCardText +.NameCardListedCardText: + text_far _NameCardListedCardText text_end -MysteryGiftNotRegisteredCardText: - text_far _MysteryGiftNotRegisteredCardText +.NameCardNotRegisteredCardText: + text_far _NameCardNotRegisteredCardText text_end -MysteryGiftLinkCancelledText: - text_far _MysteryGiftLinkCancelledText +.NameCardLinkCancelledText: + text_far _NameCardLinkCancelledText text_end -MysteryGiftLinkCommErrorText: - text_far _MysteryGiftLinkCommErrorText +.NameCardCommErrorText: + text_far _NameCardLinkCommErrorText text_end -Function105777: +.ClearScreen: call ClearSprites call ClearTilemap call EnableLCD @@ -1523,8 +1691,8 @@ Function105777: call SetPalettes ret -Function10578c: - ld de, wLinkData +StageDataForNameCard: + ld de, wMysteryGiftStaging ld a, BANK(sPlayerData) call OpenSRAM ld hl, sPlayerData + wPlayerName - wPlayerData @@ -1545,15 +1713,15 @@ Function10578c: ld a, BANK(s4_a603) ; aka BANK(s4_a007) ; MBC30 bank used by JP Crystal; inaccessible by MBC3 call OpenSRAM ld hl, s4_a603 ; address of MBC30 bank - ld bc, $8 + ld bc, 8 call CopyBytes ld hl, s4_a007 ; address of MBC30 bank - ld bc, $c + ld bc, 12 call CopyBytes call CloseSRAM ret -Function1057d7: +InitNameCardLayout: call ClearBGPalettes call DisableLCD ld hl, CardTradeGFX @@ -1638,13 +1806,13 @@ Function1057d7: hlcoord 17, 15 ld [hl], $3e ld de, wVirtualOAMSprite00 - ld hl, .OAM_data + ld hl, .NameCardOAMData ld bc, 16 * SPRITEOAMSTRUCT_LENGTH call CopyBytes call EnableLCD call WaitBGMap - ld b, $2 - farcall GetMysteryGift_MobileAdapterLayout + ld b, CRYSTAL_CGB_NAME_CARD + farcall GetCrystalCGBLayout jp SetPalettes .Load6Row: @@ -1692,7 +1860,7 @@ Function1057d7: jr nz, .row_loop_no_inc ret -.OAM_data: +.NameCardOAMData: dbsprite 6, 2, 4, 1, $00, 0 dbsprite 7, 2, 4, 1, $01, 0 dbsprite 8, 2, 4, 1, $02, 0 diff --git a/engine/link/mystery_gift_2.asm b/engine/link/mystery_gift_2.asm index f6e9fa320..af3715e09 100644 --- a/engine/link/mystery_gift_2.asm +++ b/engine/link/mystery_gift_2.asm @@ -1,24 +1,24 @@ -PrepMysteryGiftDataToSend: +StageDataForMysteryGift: ld de, wMysteryGiftStaging - ld a, $1 + GS_VERSION + ld a, GS_VERSION + 1 ld [de], a - inc de ; wc801 + inc de ; wMysteryGiftStaging+1 ld a, BANK(sGameData) call OpenSRAM ld hl, sPlayerData + wPlayerID - wPlayerData ld a, [hli] ld [de], a ld b, a - inc de ; wc802 + inc de ; wMysteryGiftStaging+2 ld a, [hl] ld [de], a ld c, a - inc de ; wc803 + inc de ; wMysteryGiftStaging+3 push bc ld hl, sPlayerData + wPlayerName - wPlayerData ld bc, NAME_LENGTH call CopyBytes - push de ; wc80e + push de ; wMysteryGiftStaging+14 ld hl, sPokemonData + wPokedexCaught - wPokemonData ld b, wEndPokedexCaught - wPokedexCaught call CountSetBits @@ -26,30 +26,30 @@ PrepMysteryGiftDataToSend: pop bc ld a, [wNumSetBits] ld [de], a - inc de ; wc80f + inc de ; wMysteryGiftStaging+15 call CloseSRAM call Random and 1 ld [de], a - inc de ; wc810 + inc de ; wMysteryGiftStaging+16 call .RandomSample ld [de], a - inc de ; wc811 + inc de ; wMysteryGiftStaging+17 ld a, c ld c, b ld b, a call .RandomSample ld [de], a - inc de ; wc812 + inc de ; wMysteryGiftStaging+18 ld a, BANK(sBackupMysteryGiftItem) call OpenSRAM ld a, [sBackupMysteryGiftItem] ld [de], a inc de - ld a, [sBackupMysteryGiftItem + 1] + ld a, [sNumDailyMysteryGiftPartnerIDs] ld [de], a - ld a, $14 - ld [wca00], a + ld a, wMysteryGiftPlayerDataEnd - wMysteryGiftPlayerData + ld [wUnusedMysteryGiftStagedDataLength], a call CloseSRAM ld hl, wMysteryGiftStaging ld de, wMysteryGiftPlayerData @@ -121,7 +121,7 @@ PrepMysteryGiftDataToSend: pop de ret -MysteryGiftGetItemHeldEffect: +MysteryGiftGetItem: ld a, c cp MysteryGiftItems.End - MysteryGiftItems jr nc, MysteryGiftFallbackItem diff --git a/engine/link/time_capsule.asm b/engine/link/time_capsule.asm index bacda9c4b..b8c68a32b 100644 --- a/engine/link/time_capsule.asm +++ b/engine/link/time_capsule.asm @@ -1,11 +1,11 @@ ; These functions seem to be related to backwards compatibility ValidateOTTrademon: - ld a, [wd003] + ld a, [wCurOTTradePartyMon] ld hl, wOTPartyMon1Species call GetPartyLocation push hl - ld a, [wd003] + ld a, [wCurOTTradePartyMon] inc a ld c, a ld b, 0 @@ -30,7 +30,7 @@ ValidateOTTrademon: cp LINK_TIMECAPSULE jr nz, .normal ld hl, wOTPartySpecies - ld a, [wd003] + ld a, [wCurOTTradePartyMon] ld c, a ld b, 0 add hl, bc @@ -65,11 +65,11 @@ ValidateOTTrademon: ret CheckAnyOtherAliveMonsForTrade: - ld a, [wd002] + ld a, [wCurTradePartyMon] ld d, a ld a, [wPartyCount] ld b, a - ld c, $0 + ld c, 0 .loop ld a, c cp d @@ -87,7 +87,7 @@ CheckAnyOtherAliveMonsForTrade: inc c dec b jr nz, .loop - ld a, [wd003] + ld a, [wCurOTTradePartyMon] ld hl, wOTPartyMon1HP call GetPartyLocation ld a, [hli] diff --git a/engine/math/print_num.asm b/engine/math/print_num.asm index 409379257..09a10128b 100644 --- a/engine/math/print_num.asm +++ b/engine/math/print_num.asm @@ -35,7 +35,6 @@ _PrintNum:: cp 2 jr z, .word ; maximum 3 bytes -.long ld a, [de] ldh [hPrintNumBuffer + 1], a inc de @@ -81,7 +80,7 @@ _PrintNum:: cp 6 jr z, .six -.seven +; seven ld a, HIGH(1000000 >> 8) ldh [hPrintNumBuffer + 4], a ld a, HIGH(1000000) ; mid diff --git a/engine/menus/intro_menu.asm b/engine/menus/intro_menu.asm index cf1bef554..5849fa0f9 100644 --- a/engine/menus/intro_menu.asm +++ b/engine/menus/intro_menu.asm @@ -9,7 +9,7 @@ Intro_MainMenu: farcall MainMenu jp StartTitleScreen -; unused +IntroMenu_DummyFunction: ; unreferenced ret PrintDayOfWeek: @@ -173,12 +173,13 @@ _ResetWRAM: ld [wRoamMon2MapNumber], a ld [wRoamMon3MapNumber], a - ld a, BANK(sMysteryGiftItem) + ld a, BANK(sMysteryGiftItem) ; aka BANK(sMysteryGiftUnlocked) call OpenSRAM ld hl, sMysteryGiftItem xor a ld [hli], a - dec a + assert sMysteryGiftItem + 1 == sMysteryGiftUnlocked + dec a ; -1 ld [hl], a call CloseSRAM @@ -370,7 +371,7 @@ Continue: ld c, 20 call DelayFrames farcall JumpRoamMons - farcall MysteryGift_CopyReceivedDecosToPC + farcall CopyMysteryGiftReceivedDecorationsToPC farcall ClockContinue ld a, [wSpawnAfterChampion] cp SPAWN_LANCE @@ -464,9 +465,9 @@ FinishContinueFunction: xor a ld [wDontPlayMapMusicOnReload], a ld [wLinkMode], a - ld hl, wGameTimerPause - set GAMETIMERPAUSE_TIMER_PAUSED_F, [hl] - res GAMETIMERPAUSE_MOBILE_7_F, [hl] + ld hl, wGameTimerPaused + set GAME_TIMER_PAUSED_F, [hl] + res GAME_TIMER_MOBILE_F, [hl] ld hl, wEnteredMapFromContinue set 1, [hl] farcall OverworldLoop diff --git a/engine/menus/main_menu.asm b/engine/menus/main_menu.asm index fcbd7d430..63173ec0c 100644 --- a/engine/menus/main_menu.asm +++ b/engine/menus/main_menu.asm @@ -31,8 +31,8 @@ MainMenu: ld b, SCGB_DIPLOMA call GetSGBLayout call SetPalettes - ld hl, wGameTimerPause - res GAMETIMERPAUSE_TIMER_PAUSED_F, [hl] + ld hl, wGameTimerPaused + res GAME_TIMER_PAUSED_F, [hl] call MainMenu_GetWhichMenu ld [wWhichIndexSet], a call MainMenu_PrintCurrentTimeAndDay @@ -206,7 +206,7 @@ MainMenu_GetWhichMenu: ld a, BANK(sNumDailyMysteryGiftPartnerIDs) call OpenSRAM ld a, [sNumDailyMysteryGiftPartnerIDs] - cp -1 + cp -1 ; locked? call CloseSRAM jr nz, .mystery_gift ; This check makes no difference. @@ -316,20 +316,19 @@ MainMenu_PrintCurrentTimeAndDay: call PrintNum ret -.min -; unused +.minString: ; unreferenced db "min.@" .PrintTimeNotSet: hlcoord 1, 14 - ld de, .TimeNotSet + ld de, .TimeNotSetString call PlaceString ret -.TimeNotSet: +.TimeNotSetString: db "TIME NOT SET@" -.MainMenuTimeUnknownText: +.MainMenuTimeUnknownText: ; unreferenced text_far _MainMenuTimeUnknownText text_end diff --git a/engine/menus/menu_2.asm b/engine/menus/menu_2.asm index 64a58a18d..08666bfab 100644 --- a/engine/menus/menu_2.asm +++ b/engine/menus/menu_2.asm @@ -156,18 +156,18 @@ StartMenu_PrintBugContestStatus: set NO_TEXT_SCROLL, [hl] call StartMenu_DrawBugContestStatusBox hlcoord 1, 5 - ld de, .Balls_EN + ld de, .BallsString call PlaceString hlcoord 8, 5 ld de, wParkBallsRemaining lb bc, PRINTNUM_LEFTALIGN | 1, 2 call PrintNum hlcoord 1, 1 - ld de, .CAUGHT + ld de, .CaughtString call PlaceString ld a, [wContestMon] and a - ld de, .None + ld de, .NoneString jr z, .no_contest_mon ld [wNamedObjectIndexBuffer], a call GetPokemonName @@ -179,7 +179,7 @@ StartMenu_PrintBugContestStatus: and a jr z, .skip_level hlcoord 1, 3 - ld de, .LEVEL + ld de, .LevelString call PlaceString ld a, [wContestMonLevel] ld h, b @@ -193,15 +193,15 @@ StartMenu_PrintBugContestStatus: ld [wOptions], a ret -.Balls_JP: +.BallsJPString: ; unreferenced db "ボール こ@" -.CAUGHT: +.CaughtString: db "CAUGHT@" -.Balls_EN: +.BallsString: db "BALLS:@" -.None: +.NoneString: db "None@" -.LEVEL: +.LevelString: db "LEVEL@" FindApricornsInBag: diff --git a/engine/menus/naming_screen.asm b/engine/menus/naming_screen.asm index f95845b51..0a436b273 100644 --- a/engine/menus/naming_screen.asm +++ b/engine/menus/naming_screen.asm @@ -275,6 +275,7 @@ NamingScreen_InitText: NamingScreen_ApplyTextInputMode: call NamingScreen_IsTargetBox jr nz, .not_box + assert BoxNameInputLower - NameInputLower == BoxNameInputUpper - NameInputUpper ld hl, BoxNameInputLower - NameInputLower add hl, de ld d, h @@ -880,7 +881,7 @@ INCBIN "gfx/naming_screen/cursor.2bpp" INCLUDE "data/text/name_input_chars.asm" -NamingScreenGFX_End: ; unused +NamingScreenGFX_End: ; unreferenced INCBIN "gfx/naming_screen/end.1bpp" NamingScreenGFX_MiddleLine: @@ -1333,7 +1334,7 @@ MailComposition_TryAddLastCharacter: ld a, [wNamingScreenLastCharacter] jp MailComposition_TryAddCharacter -; unused +.add_dakuten ; unreferenced ld a, [wNamingScreenCurNameLength] and a ret z diff --git a/engine/menus/trainer_card.asm b/engine/menus/trainer_card.asm index 6a7477e14..8dead3429 100644 --- a/engine/menus/trainer_card.asm +++ b/engine/menus/trainer_card.asm @@ -296,7 +296,8 @@ TrainerCard_Page1_PrintDexCaught_GameTime: db "#DEX" next "PLAY TIME@" - db "@" ; unused +.Unused: ; unreferenced + db "@" .Badges: db " BADGES▶@" diff --git a/engine/movie/credits.asm b/engine/movie/credits.asm index 701b8c57d..6cdbef709 100644 --- a/engine/movie/credits.asm +++ b/engine/movie/credits.asm @@ -199,7 +199,7 @@ Credits_RequestGFX: xor a ldh [hBGMapMode], a ld a, 8 - ld [wRequested2bpp], a + ld [wRequested2bppSize], a jp Credits_Next Credits_LYOverride: diff --git a/engine/movie/intro.asm b/engine/movie/intro.asm index 1da3576e3..623b92ed4 100644 --- a/engine/movie/intro.asm +++ b/engine/movie/intro.asm @@ -21,7 +21,7 @@ CrystalIntro: call DelayFrame jp .loop -.ShutOffMusic: +.ShutOffMusic ld de, MUSIC_NONE call PlayMusic @@ -152,14 +152,14 @@ IntroScene2: cp $80 jr nc, .endscene cp $60 - jr nz, .DontPlaySound + jr nz, .nosound push af depixel 11, 11 call CrystalIntro_InitUnownAnim ld de, SFX_INTRO_UNOWN_1 call PlaySFX pop af -.DontPlaySound: +.nosound ld [wIntroSceneTimer], a xor a call CrystalIntro_UnownFade @@ -971,7 +971,8 @@ IntroScene20: xor a call Intro_Scene20_AppearUnown ret -; unused + +.AppearUnownPal2: ; unreferenced ld a, c and $1c srl a @@ -981,7 +982,7 @@ IntroScene20: call Intro_Scene20_AppearUnown ret -.finished +.finished: call NextIntroScene ret diff --git a/engine/movie/trade_animation.asm b/engine/movie/trade_animation.asm index 71e438767..0b65ccfc9 100644 --- a/engine/movie/trade_animation.asm +++ b/engine/movie/trade_animation.asm @@ -20,7 +20,7 @@ ENDM TradeAnimation: xor a - ld [wcf66], a + ld [wUnusedTradeAnimPlayEvolutionMusic], a ld hl, wPlayerTrademonSenderName ld de, wOTTrademonSenderName call LinkTradeAnim_LoadTradePlayerNames @@ -71,7 +71,7 @@ TradeAnimation: TradeAnimationPlayer2: xor a - ld [wcf66], a + ld [wUnusedTradeAnimPlayEvolutionMusic], a ld hl, wOTTrademonSenderName ld de, wPlayerTrademonSenderName call LinkTradeAnim_LoadTradePlayerNames @@ -137,7 +137,7 @@ RunTradeAnimScript: push af set NO_TEXT_SCROLL, [hl] call .TradeAnimLayout - ld a, [wcf66] + ld a, [wUnusedTradeAnimPlayEvolutionMusic] and a jr nz, .anim_loop ld de, MUSIC_EVOLUTION @@ -225,7 +225,7 @@ DoTradeAnimation: jr nz, .finished call .DoTradeAnimCommand callfar PlaySpriteAnimations - ld hl, wcf65 + ld hl, wFrameCounter2 inc [hl] call DelayFrame and a @@ -273,8 +273,8 @@ DoTradeAnimation: add_tradeanim TradeAnim_TextboxScrollStart ; 1e add_tradeanim TradeAnim_ScrollOutRight ; 1f add_tradeanim TradeAnim_ScrollOutRight2 ; 20 - add_tradeanim TradeAnim_Wait80 ; 21 - add_tradeanim TradeAnim_Wait40 ; 22 + add_tradeanim TradeAnim_Wait80 ; 21 + add_tradeanim TradeAnim_Wait40 ; 22 add_tradeanim TradeAnim_RockingBall ; 23 add_tradeanim TradeAnim_DropBall ; 24 add_tradeanim TradeAnim_WaitAnim ; 25 @@ -285,9 +285,9 @@ DoTradeAnimation: add_tradeanim TradeAnim_GetTrademonSFX ; 2a add_tradeanim TradeAnim_End ; 2b add_tradeanim TradeAnim_AnimateFrontpic ; 2c - add_tradeanim TradeAnim_Wait96 ; 2d - add_tradeanim TradeAnim_Wait80IfOTEgg ; 2e - add_tradeanim TradeAnim_Wait180IfOTEgg ; 2f + add_tradeanim TradeAnim_Wait96 ; 2d + add_tradeanim TradeAnim_Wait80IfOTEgg ; 2e + add_tradeanim TradeAnim_Wait180IfOTEgg ; 2f TradeAnim_IncrementJumptableIndex: ld hl, wJumptableIndex @@ -1333,7 +1333,7 @@ LinkTradeAnim_LoadTradeMonSpecies: ret TradeAnim_FlashBGPals: - ld a, [wcf65] + ld a, [wFrameCounter2] and $7 ret nz ldh a, [rBGP] diff --git a/engine/movie/unused_title.asm b/engine/movie/unused_title.asm index 615d92d36..4b8845f6f 100644 --- a/engine/movie/unused_title.asm +++ b/engine/movie/unused_title.asm @@ -1,4 +1,4 @@ -UnusedTitleScreen: +UnusedTitleScreen: ; unreferenced call ClearBGPalettes call ClearTilemap call DisableLCD @@ -154,7 +154,7 @@ UnusedTitleFG_OAM: dbsprite 13, 11, 0, 0, $4c, 1 dbsprite 14, 11, 0, 0, $4e, 1 -Function10ed51: +Function10ed51: ; unreferenced call _TitleScreen .loop call JoyTextDelay diff --git a/engine/overworld/decorations.asm b/engine/overworld/decorations.asm index 6c56330ed..6cc86181a 100644 --- a/engine/overworld/decorations.asm +++ b/engine/overworld/decorations.asm @@ -44,7 +44,7 @@ _PlayerDecorationMenu: .MenuData: db STATICMENU_CURSOR | STATICMENU_WRAP ; flags db 0 ; items - dw wd002 + dw wNumOwnedDecoCategories dw PlaceNthMenuStrings dw .pointers @@ -75,7 +75,7 @@ _PlayerDecorationMenu: ld a, 7 call .AppendToStringBuffer2 ld hl, wStringBuffer2 - ld de, wd002 + ld de, wDecoNameBuffer ld bc, ITEM_NAME_LENGTH call CopyBytes ret @@ -133,10 +133,11 @@ _PlayerDecorationMenu: Deco_FillTempWithMinusOne: xor a - ld hl, wd002 + ld hl, wNumOwnedDecoCategories ld [hli], a + assert wNumOwnedDecoCategories + 1 == wOwnedDecoCategories ld a, -1 - ld bc, $10 + ld bc, 16 call ByteFill ret @@ -161,10 +162,11 @@ CheckAllDecorationFlags: ret AppendDecoIndex: - ld hl, wd002 + ld hl, wNumOwnedDecoCategories inc [hl] + assert wNumOwnedDecoCategories + 1 == wOwnedDecoCategories ld e, [hl] - ld d, $0 + ld d, 0 add hl, de ld [hl], a ret @@ -176,7 +178,7 @@ FindOwnedDecosInCategory: pop hl call CheckAllDecorationFlags pop bc - ld a, [wd002] + ld a, [wNumOwnedDecoCategories] and a ret z @@ -335,7 +337,7 @@ DecoExitMenu: ret PopulateDecoCategoryMenu: - ld a, [wd002] + ld a, [wNumOwnedDecoCategories] and a jr z, .empty cp 8 @@ -353,9 +355,10 @@ PopulateDecoCategoryMenu: ret .beyond_eight - ld hl, wd002 + ld hl, wNumOwnedDecoCategories ld e, [hl] dec [hl] + assert wNumOwnedDecoCategories + 1 == wOwnedDecoCategories ld d, 0 add hl, de ld [hl], -1 @@ -395,7 +398,7 @@ PopulateDecoCategoryMenu: .NonscrollingMenuData: db STATICMENU_CURSOR | STATICMENU_WRAP ; flags db 0 ; items - dw wd002 + dw wDecoNameBuffer dw DecorationMenuFunction dw DecorationAttributes @@ -409,10 +412,10 @@ PopulateDecoCategoryMenu: db SCROLLINGMENU_DISPLAY_ARROWS ; flags db 8, 0 ; rows, columns db SCROLLINGMENU_ITEMS_NORMAL ; item format - dbw 0, wd002 ; text pointer + dbw 0, wDecoNameBuffer ; text pointer dba DecorationMenuFunction - dbw 0, 0 - dbw 0, 0 + dbw 0, NULL + dbw 0, NULL GetDecorationData: ld hl, DecorationAttributes @@ -549,7 +552,7 @@ GetDecoName: ld a, e jr .getpokename -.unused +.unused ; unreferenced push de call .getdeconame pop de @@ -939,7 +942,7 @@ GetDecorationID: pop hl ret -SetAllDecorationFlags: +SetAllDecorationFlags: ; unreferenced ld hl, DecorationIDs .loop ld a, [hli] diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm index 218b7efc0..822b9ebf9 100644 --- a/engine/overworld/events.asm +++ b/engine/overworld/events.asm @@ -25,76 +25,76 @@ OverworldLoop:: DisableEvents: xor a - ld [wScriptFlags3], a + ld [wScriptFlags2], a ret EnableEvents:: ld a, $ff - ld [wScriptFlags3], a + ld [wScriptFlags2], a ret -CheckBit5_ScriptFlags3: - ld hl, wScriptFlags3 +CheckBit5_ScriptFlags2: + ld hl, wScriptFlags2 bit 5, [hl] ret -DisableWarpsConnxns: - ld hl, wScriptFlags3 +DisableWarpsConnxns: ; unreferenced + ld hl, wScriptFlags2 res 2, [hl] ret -DisableCoordEvents: - ld hl, wScriptFlags3 +DisableCoordEvents: ; unreferenced + ld hl, wScriptFlags2 res 1, [hl] ret -DisableStepCount: - ld hl, wScriptFlags3 +DisableStepCount: ; unreferenced + ld hl, wScriptFlags2 res 0, [hl] ret -DisableWildEncounters: - ld hl, wScriptFlags3 +DisableWildEncounters: ; unreferenced + ld hl, wScriptFlags2 res 4, [hl] ret -EnableWarpsConnxns: - ld hl, wScriptFlags3 +EnableWarpsConnxns: ; unreferenced + ld hl, wScriptFlags2 set 2, [hl] ret -EnableCoordEvents: - ld hl, wScriptFlags3 +EnableCoordEvents: ; unreferenced + ld hl, wScriptFlags2 set 1, [hl] ret -EnableStepCount: - ld hl, wScriptFlags3 +EnableStepCount: ; unreferenced + ld hl, wScriptFlags2 set 0, [hl] ret EnableWildEncounters: - ld hl, wScriptFlags3 + ld hl, wScriptFlags2 set 4, [hl] ret CheckWarpConnxnScriptFlag: - ld hl, wScriptFlags3 + ld hl, wScriptFlags2 bit 2, [hl] ret CheckCoordEventScriptFlag: - ld hl, wScriptFlags3 + ld hl, wScriptFlags2 bit 1, [hl] ret CheckStepCountScriptFlag: - ld hl, wScriptFlags3 + ld hl, wScriptFlags2 bit 0, [hl] ret CheckWildEncountersScriptFlag: - ld hl, wScriptFlags3 + ld hl, wScriptFlags2 bit 4, [hl] ret @@ -135,7 +135,7 @@ EnterMap: ld [wMapStatus], a ret -UnusedWait30Frames: +UnusedWait30Frames: ; unreferenced ld c, 30 call DelayFrames ret @@ -248,7 +248,7 @@ PlayerEvents: and a ret nz - call Dummy_CheckScriptFlags3Bit5 ; This is a waste of time + call Dummy_CheckScriptFlags2Bit5 ; This is a waste of time call CheckTrainerBattle_GetPlayerEvent jr c, .ok @@ -395,8 +395,8 @@ SetMinTwoStepWildEncounterCooldown: ld [wWildEncounterCooldown], a ret -Dummy_CheckScriptFlags3Bit5: - call CheckBit5_ScriptFlags3 +Dummy_CheckScriptFlags2Bit5: + call CheckBit5_ScriptFlags2 ret z call SetXYCompareFlags ret @@ -480,8 +480,8 @@ CheckTimeEvents: scf ret -.unused - ld a, 8 +.unused ; unreferenced + ld a, $8 ; ??? scf ret @@ -812,7 +812,7 @@ PlayerMovement: CheckMenuOW: xor a ldh [hMenuReturn], a - ldh [hUnusedFFA1], a + ldh [hUnusedByte], a ldh a, [hJoyPressed] bit SELECT_F, a diff --git a/engine/overworld/map_object_action.asm b/engine/overworld/map_object_action.asm index 35de22030..5c68f6b0f 100644 --- a/engine/overworld/map_object_action.asm +++ b/engine/overworld/map_object_action.asm @@ -273,7 +273,8 @@ SetFacingBoulderDust: and 2 ld a, FACING_BOULDER_DUST_1 jr z, .ok - inc a ; FACING_BOULDER_DUST_2 + inc a + assert FACING_BOULDER_DUST_1 + 1 == FACING_BOULDER_DUST_2 .ok ld [hl], a ret diff --git a/engine/overworld/map_objects.asm b/engine/overworld/map_objects.asm index 59b8abf84..f6157ce83 100644 --- a/engine/overworld/map_objects.asm +++ b/engine/overworld/map_objects.asm @@ -2894,20 +2894,20 @@ InitSprites: ldh [hCurSpriteTile], a xor a bit 7, [hl] - jr nz, .skip1 + jr nz, .not_vram1 or VRAM_BANK_1 -.skip1 +.not_vram1 ld hl, OBJECT_FLAGS2 add hl, bc ld e, [hl] bit OBJ_FLAGS2_7, e - jr z, .skip2 + jr z, .not_priority or PRIORITY -.skip2 +.not_priority bit USE_OBP1_F, e - jr z, .skip3 + jr z, .not_obp_num or OBP_NUM -.skip3 +.not_obp_num ld hl, OBJECT_PALETTE add hl, bc ld d, a @@ -2917,9 +2917,9 @@ InitSprites: ld d, a xor a bit OVERHEAD_F, e - jr z, .skip4 + jr z, .not_overhead or PRIORITY -.skip4 +.not_overhead ldh [hCurSpriteOAMFlags], a ld hl, OBJECT_SPRITE_X add hl, bc diff --git a/engine/overworld/map_setup.asm b/engine/overworld/map_setup.asm index 9a96d6700..e70f9ab7b 100644 --- a/engine/overworld/map_setup.asm +++ b/engine/overworld/map_setup.asm @@ -82,7 +82,7 @@ LoadMapObjects: farcall InitializeVisibleSprites ret -; unused +MapSetup_DummyFunction: ; unreferenced ret ResetPlayerObjectAction: diff --git a/engine/overworld/player_movement.asm b/engine/overworld/player_movement.asm index fcf147dd0..4ef04d79b 100644 --- a/engine/overworld/player_movement.asm +++ b/engine/overworld/player_movement.asm @@ -311,7 +311,7 @@ DoPlayerMovement:: scf ret -; unused +.unused ; unreferenced xor a ret diff --git a/engine/overworld/scripting.asm b/engine/overworld/scripting.asm index 7e86795fc..d9878269b 100644 --- a/engine/overworld/scripting.asm +++ b/engine/overworld/scripting.asm @@ -458,11 +458,11 @@ Script_verbosegiveitem: ld de, GiveItemScript jp ScriptCall -ret_96f76: +GiveItemScript_DummyFunction: ret GiveItemScript: - callasm ret_96f76 + callasm GiveItemScript_DummyFunction writetext .ReceivedItemText iffalse .Full waitsfx @@ -1703,7 +1703,7 @@ Script_givepokemail: push bc inc hl ld bc, MAIL_MSG_LENGTH - ld de, wd002 + ld de, wMonMailMessageBuffer ld a, [wScriptBank] call FarCopyBytes pop bc @@ -2173,8 +2173,7 @@ Script_warpcheck: farcall EnableEvents ret -Script_enableevents: -; unused +Script_enableevents: ; unreferenced farcall EnableEvents ret @@ -2204,7 +2203,8 @@ Script_writeunusedbytebuffer: ld [wUnusedScriptByteBuffer], a ret - db closetext_command ; unused +UnusedClosetextScript: ; unreferenced + closetext Script_closetext: call _OpenAndCloseMenu_HDMATransferTilemapAndAttrmap @@ -2316,13 +2316,13 @@ Script_endall: ret Script_halloffame: - ld hl, wGameTimerPause - res GAMETIMERPAUSE_TIMER_PAUSED_F, [hl] + ld hl, wGameTimerPaused + res GAME_TIMER_PAUSED_F, [hl] farcall StubbedTrainerRankings_HallOfFame farcall StubbedTrainerRankings_HallOfFame2 farcall HallOfFame - ld hl, wGameTimerPause - set GAMETIMERPAUSE_TIMER_PAUSED_F, [hl] + ld hl, wGameTimerPaused + set GAME_TIMER_PAUSED_F, [hl] jr ReturnFromCredits Script_credits: @@ -2353,7 +2353,7 @@ Script_checksave: ld [wScriptVar], a ret -; unused +Script_checkver_duplicate: ; unreferenced ld a, [.gs_version] ld [wScriptVar], a ret diff --git a/engine/overworld/time.asm b/engine/overworld/time.asm index 86807119d..4299a69ab 100644 --- a/engine/overworld/time.asm +++ b/engine/overworld/time.asm @@ -203,7 +203,7 @@ CheckPokerusTick:: xor a ret -SetUnusedTwoDayTimer: +SetUnusedTwoDayTimer: ; unreferenced ld a, 2 ld hl, wUnusedTwoDayTimer ld [hl], a @@ -220,12 +220,12 @@ CheckUnusedTwoDayTimer: call UpdateTimeRemaining ret -; unused +UnusedSetSwarmFlag: ; unreferenced ld hl, wDailyFlags1 set DAILYFLAGS1_FISH_SWARM_F, [hl] ret -; unused +UnusedCheckSwarmFlag: ; unreferenced and a ld hl, wDailyFlags1 bit DAILYFLAGS1_FISH_SWARM_F, [hl] @@ -272,7 +272,7 @@ DoMysteryGiftIfDayHasPassed: ld hl, wBuffer1 call InitOneDayCountdown call CloseSRAM - farcall Function1050c8 + farcall ResetDailyMysteryGiftLimitIfUnlocked .not_timed_out ld a, BANK(sMysteryGiftTimer) @@ -308,7 +308,7 @@ UpdateTimeRemaining: scf ret -GetSecondsSinceIfLessThan60: +GetSecondsSinceIfLessThan60: ; unreferenced ld a, [wDaysSince] and a jr nz, GetTimeElapsed_ExceedsUnitLimit @@ -330,7 +330,7 @@ GetMinutesSinceIfLessThan60: ld a, [wMinutesSince] ret -GetHoursSinceIfLessThan24: +GetHoursSinceIfLessThan24: ; unreferenced ld a, [wDaysSince] and a jr nz, GetTimeElapsed_ExceedsUnitLimit @@ -349,7 +349,7 @@ CalcDaysSince: xor a jr _CalcDaysSince -CalcHoursDaysSince: +CalcHoursDaysSince: ; unreferenced inc hl xor a jr _CalcHoursDaysSince @@ -423,7 +423,7 @@ CopyDayToHL: ld [hl], a ret -CopyDayHourToHL: +CopyDayHourToHL: ; unreferenced ld a, [wCurDay] ld [hli], a ldh a, [hHours] diff --git a/engine/overworld/warp_connection.asm b/engine/overworld/warp_connection.asm index 866480d5c..0b87de722 100644 --- a/engine/overworld/warp_connection.asm +++ b/engine/overworld/warp_connection.asm @@ -175,7 +175,8 @@ EnterMapWarp: ; MOUNT_MOON_SQUARE and TIN_TOWER_ROOF are outdoor maps within indoor maps. ; Dig and Escape Rope should not take you to them. ld a, [wPrevMapGroup] - cp GROUP_MOUNT_MOON_SQUARE ; aka GROUP_TIN_TOWER_ROOF + cp GROUP_MOUNT_MOON_SQUARE + assert GROUP_MOUNT_MOON_SQUARE == GROUP_TIN_TOWER_ROOF jr nz, .not_mt_moon_or_tin_tower ld a, [wPrevMapNumber] cp MAP_MOUNT_MOON_SQUARE @@ -390,44 +391,42 @@ GetMapScreenCoords:: ld hl, wOverworldMapBlocks ld a, [wXCoord] bit 0, a - jr nz, .increment_then_halve1 + jr nz, .odd_x +; even x srl a - add $1 - jr .resume - -.increment_then_halve1 - add $1 + add 1 + jr .got_block_x +.odd_x + add 1 srl a - -.resume +.got_block_x ld c, a - ld b, $0 + ld b, 0 add hl, bc ld a, [wMapWidth] - add $6 + add MAP_CONNECTION_PADDING_WIDTH * 2 ld c, a - ld b, $0 + ld b, 0 ld a, [wYCoord] bit 0, a - jr nz, .increment_then_halve2 + jr nz, .odd_y +; even y srl a - add $1 - jr .resume2 - -.increment_then_halve2 - add $1 + add 1 + jr .got_block_y +.odd_y + add 1 srl a - -.resume2 +.got_block_y call AddNTimes ld a, l ld [wOverworldMapAnchor], a ld a, h ld [wOverworldMapAnchor + 1], a ld a, [wYCoord] - and $1 + and 1 ld [wMetatileStandingY], a ld a, [wXCoord] - and $1 + and 1 ld [wMetatileStandingX], a ret diff --git a/engine/phone/phone.asm b/engine/phone/phone.asm index 18533678c..5b808cf67 100644 --- a/engine/phone/phone.asm +++ b/engine/phone/phone.asm @@ -437,7 +437,7 @@ Script_SpecialBillCall:: ld e, PHONE_BILL jp LoadCallerScript -LoadElmCallScript: +Script_SpecialElmCall: ; unreferenced callasm .LoadElmScript pause 30 sjump Script_ReceivePhoneCall @@ -720,7 +720,7 @@ PhoneJustTalkToThemText: text_far _PhoneJustTalkToThemText text_end -PhoneThankYouTextScript: +PhoneThankYouTextScript: ; unreferenced writetext PhoneThankYouText end diff --git a/engine/phone/scripts/elm.asm b/engine/phone/scripts/elm.asm index 4760d8505..b8341541d 100644 --- a/engine/phone/scripts/elm.asm +++ b/engine/phone/scripts/elm.asm @@ -95,7 +95,7 @@ ElmPhoneCallerScript: specialphonecall SPECIALCALL_NONE end -.unused +.neat ; unreferenced farwritetext ElmPhoneGotAholdOfSomethingNeatText specialphonecall SPECIALCALL_NONE end diff --git a/engine/phone/scripts/generic_callee.asm b/engine/phone/scripts/generic_callee.asm index f8a5f7394..51bcd4947 100644 --- a/engine/phone/scripts/generic_callee.asm +++ b/engine/phone/scripts/generic_callee.asm @@ -1103,7 +1103,7 @@ PhoneScript_Generic_Male: promptbutton end -.Unknown: +.Unknown: ; unreferenced farwritetext UnknownGenericText promptbutton end diff --git a/engine/phone/scripts/hangups_2.asm b/engine/phone/scripts/hangups_2.asm index aad10df21..197845fa8 100644 --- a/engine/phone/scripts/hangups_2.asm +++ b/engine/phone/scripts/hangups_2.asm @@ -3,7 +3,7 @@ BeverlyComePickUpScript: promptbutton sjump PhoneScript_HangUpText_Female -JoseComePickUpScript: +JoseComePickUpScript: ; unreferenced farwritetext JoseComePickUpText promptbutton sjump PhoneScript_HangUpText_Male diff --git a/engine/pokedex/pokedex.asm b/engine/pokedex/pokedex.asm index 245cbf11f..10cd6ef8d 100644 --- a/engine/pokedex/pokedex.asm +++ b/engine/pokedex/pokedex.asm @@ -91,7 +91,7 @@ InitPokedex: ld [wJumptableIndex], a ld [wPrevDexEntryJumptableIndex], a ld [wPrevDexEntryBackup], a - ld [wcf66], a + ld [wUnusedPokedexByte], a call Pokedex_CheckUnlockedUnownMode @@ -1166,7 +1166,7 @@ Pokedex_DrawDexEntryScreenBG: call Pokedex_PlaceFrontpicTopLeftCorner ret -.Unused: +.Number: ; unreferenced db $5c, $5d, -1 ; No. .Height: db "HT ?", $5e, "??", $5f, -1 ; HT ?'??" @@ -2480,6 +2480,7 @@ Pokedex_LoadUnownFont: ld a, BANK(sScratch) call OpenSRAM ld hl, UnownFont + ; sScratch + $188 was the address of sDecompressBuffer in pokegold ld de, sScratch + $188 ld bc, 39 tiles ld a, BANK(UnownFont) diff --git a/engine/pokegear/pokegear.asm b/engine/pokegear/pokegear.asm index 02fb65fea..ad06ad059 100644 --- a/engine/pokegear/pokegear.asm +++ b/engine/pokegear/pokegear.asm @@ -92,7 +92,7 @@ PokeGear: ld [wJumptableIndex], a ; POKEGEARSTATE_CLOCKINIT ld [wPokegearCard], a ; POKEGEARCARD_CLOCK ld [wPokegearMapRegion], a ; JOHTO_REGION - ld [wcf66], a + ld [wUnusedPokegearByte], a ld [wPokegearPhoneScrollPosition], a ld [wPokegearPhoneCursorPosition], a ld [wPokegearPhoneSelectedPerson], a @@ -1271,7 +1271,7 @@ PokegearPhoneContactSubmenu: dw .Call dw .Cancel -; unused +GetAMPMHours: ; unreferenced ldh a, [hHours] cp 12 jr c, .am @@ -1442,7 +1442,7 @@ UpdateRadioStation: ldh [hBGMapMode], a ret -; unused +LoadPokegearRadioChannelPointer: ; unreferenced ld [wPokegearRadioChannelBank], a ld a, [hli] ld [wPokegearRadioChannelAddr], a @@ -1546,7 +1546,7 @@ RadioChannels: jr z, .johto cp KANTO_LANDMARK jr c, .johto -.kanto +; kanto and a ret @@ -2038,7 +2038,7 @@ _FlyMap: lb bc, BANK(FlyMapLabelBorderGFX), 6 call Request1bpp call FlyMap - call ret_91c8f + call Pokegear_DummyFunction ld b, SCGB_POKEGEAR_PALS call GetSGBLayout call SetPalettes @@ -2243,7 +2243,7 @@ HasVisitedSpawn: INCLUDE "data/maps/flypoints.asm" -ret_91c8f: +Pokegear_DummyFunction: ret FlyMap: @@ -2265,7 +2265,7 @@ FlyMap: ; The first 46 locations are part of Johto. The rest are in Kanto. cp KANTO_LANDMARK jr nc, .KantoFlyMap -.JohtoFlyMap: +; Johto fly map ; Note that .NoKanto should be modified in tandem with this branch push af ld a, JOHTO_FLYPOINT ; first Johto flypoint @@ -2569,7 +2569,7 @@ Pokedex_GetArea: jr z, .johto cp KANTO_LANDMARK jr c, .johto -.kanto +; kanto ld a, [wTownMapCursorLandmark] and a jr z, .clear diff --git a/engine/pokegear/radio.asm b/engine/pokegear/radio.asm index 803a7b036..bc7c3195d 100644 --- a/engine/pokegear/radio.asm +++ b/engine/pokegear/radio.asm @@ -141,7 +141,7 @@ PrintRadioLine: ld [wRadioTextDelay], a ret -ReplacePeriodsWithSpaces: +ReplacePeriodsWithSpaces: ; unreferenced push hl ld b, SCREEN_WIDTH * 2 .loop @@ -149,7 +149,6 @@ ReplacePeriodsWithSpaces: cp "." jr nz, .next ld [hl], " " - .next inc hl dec b @@ -335,6 +334,7 @@ OaksPKMNTalk8: ; so no need for a retry loop call Random maskbits NUM_OAKS_POKEMON_TALK_ADVERBS + assert_power_of_2 NUM_OAKS_POKEMON_TALK_ADVERBS ld e, a ld d, 0 ld hl, .Adverbs @@ -434,6 +434,7 @@ OaksPKMNTalk9: ; so no need for a retry loop call Random maskbits NUM_OAKS_POKEMON_TALK_ADJECTIVES + assert_power_of_2 NUM_OAKS_POKEMON_TALK_ADJECTIVES ld e, a ld d, 0 ld hl, .Adjectives @@ -1131,6 +1132,7 @@ PeoplePlaces5: ; so no need for a retry loop call Random maskbits NUM_PNP_PEOPLE_ADJECTIVES + assert_power_of_2 NUM_PNP_PEOPLE_ADJECTIVES ld e, a ld d, 0 ld hl, .Adjectives @@ -1264,6 +1266,7 @@ PeoplePlaces7: ; so no need for a retry loop call Random maskbits NUM_PNP_PLACES_ADJECTIVES + assert_power_of_2 NUM_PNP_PLACES_ADJECTIVES ld e, a ld d, 0 ld hl, .Adjectives @@ -1779,7 +1782,7 @@ CopyRadioTextToRAM: cp TX_FAR jp z, FarCopyRadioText ld de, wRadioText - ld bc, SCREEN_WIDTH * 2 + ld bc, 2 * SCREEN_WIDTH jp CopyBytes StartRadioStation: diff --git a/engine/pokemon/bills_pc.asm b/engine/pokemon/bills_pc.asm index ed7856957..2c5145b9f 100644 --- a/engine/pokemon/bills_pc.asm +++ b/engine/pokemon/bills_pc.asm @@ -101,7 +101,7 @@ _DepositPKMN: ld [wJumptableIndex], a ret -.go_back +.go_back ; unreferenced ld hl, wJumptableIndex dec [hl] ret @@ -358,7 +358,7 @@ _WithdrawPKMN: ld [wJumptableIndex], a ret -.unused +.go_back ; unreferenced ld hl, wJumptableIndex dec [hl] ret @@ -609,7 +609,7 @@ _MovePKMNWithoutMail: ld [wJumptableIndex], a ret -.unused +.go_back ; unreferenced ld hl, wJumptableIndex dec [hl] ret @@ -782,9 +782,9 @@ BillsPC_InitRAM: call ByteFill xor a ld [wJumptableIndex], a - ld [wcf64], a - ld [wcf65], a - ld [wcf66], a + ld [wUnusedBillsPCData], a + ld [wUnusedBillsPCData+1], a + ld [wUnusedBillsPCData+2], a ld [wBillsPC_CursorPosition], a ld [wBillsPC_ScrollPosition], a ret @@ -1377,20 +1377,20 @@ copy_box_data: MACRO jr z, .done\@ and a jr z, .done\@ - ld [de], a + ld [de], a ; species inc de ld a, [wBillsPC_LoadedBox] - ld [de], a + ld [de], a ; box number inc de - ld a, [wd003] - ld [de], a + ld a, [wBillsPCTempListIndex] + ld [de], a ; list index inc a - ld [wd003], a + ld [wBillsPCTempListIndex], a inc de inc hl - ld a, [wd004] + ld a, [wBillsPCTempBoxCount] inc a - ld [wd004], a + ld [wBillsPCTempBoxCount], a jr .loop\@ .done\@ @@ -1399,7 +1399,7 @@ if \1 endc ld a, -1 ld [de], a - ld a, [wd004] + ld a, [wBillsPCTempBoxCount] inc a ld [wBillsPC_NumMonsInBox], a ENDM @@ -1411,8 +1411,8 @@ CopyBoxmonSpecies: call ByteFill ld de, wBillsPCPokemonList xor a - ld [wd003], a - ld [wd004], a + ld [wBillsPCTempListIndex], a + ld [wBillsPCTempBoxCount], a ld a, [wBillsPC_LoadedBox] and a jr z, .party @@ -2222,7 +2222,7 @@ PCString_ReleasedPKMN: db "Released <PK><MN>.@" PCString_Bye: db "Bye,@" PCString_Stored: db "Stored @" PCString_Got: db "Got @" -PCString_Non: db "Non.@" +PCString_Non: db "Non.@" ; unreferenced PCString_BoxFull: db "The BOX is full.@" PCString_PartyFull: db "The party's full!@" PCString_NoReleasingEGGS: db "No releasing EGGS!@" @@ -2268,16 +2268,16 @@ _ChangeBox_MenuHeader: dw .MenuData db 1 ; default option -.MenuData +.MenuData: db SCROLLINGMENU_CALL_FUNCTION3_NO_SWITCH | SCROLLINGMENU_ENABLE_FUNCTION3 ; flags db 4, 0 ; rows, columns db SCROLLINGMENU_ITEMS_NORMAL ; item format - dba .boxes - dba .boxnames + dba .Boxes + dba .PrintBoxNames dba NULL dba BillsPC_PrintBoxCountAndCapacity -.boxes +.Boxes: db NUM_BOXES x = 1 rept NUM_BOXES @@ -2286,7 +2286,7 @@ x = x + 1 endr db -1 -.boxnames +.PrintBoxNames: push de ld a, [wMenuSelection] dec a @@ -2455,7 +2455,7 @@ BillsPC_ChangeBoxSubmenu: .Name: ld b, NAME_BOX - ld de, wd002 + ld de, wBoxNameBuffer farcall NamingScreen call ClearTilemap call LoadStandardFont @@ -2465,17 +2465,17 @@ BillsPC_ChangeBoxSubmenu: call GetBoxName ld e, l ld d, h - ld hl, wd002 + ld hl, wBoxNameBuffer ld c, BOX_NAME_LENGTH - 1 call InitString ld a, [wMenuSelection] dec a call GetBoxName - ld de, wd002 + ld de, wBoxNameBuffer call CopyName2 ret - hlcoord 11, 7 ; unused + hlcoord 11, 7 ; unreferenced .MenuHeader: db MENU_BACKUP_TILES ; flags diff --git a/engine/pokemon/breedmon_level_growth.asm b/engine/pokemon/breedmon_level_growth.asm index c6356dd6e..f64bd6ca0 100644 --- a/engine/pokemon/breedmon_level_growth.asm +++ b/engine/pokemon/breedmon_level_growth.asm @@ -1,5 +1,5 @@ GetBreedMon1LevelGrowth: - ld hl, wBreedMon1Stats + ld hl, wBreedMon1 ld de, wTempMon ld bc, BOXMON_STRUCT_LENGTH call CopyBytes @@ -13,7 +13,7 @@ GetBreedMon1LevelGrowth: ret GetBreedMon2LevelGrowth: - ld hl, wBreedMon2Stats + ld hl, wBreedMon2 ld de, wTempMon ld bc, BOXMON_STRUCT_LENGTH call CopyBytes diff --git a/engine/pokemon/evolve.asm b/engine/pokemon/evolve.asm index 1fbca90d5..3e6c4f969 100644 --- a/engine/pokemon/evolve.asm +++ b/engine/pokemon/evolve.asm @@ -327,7 +327,7 @@ EvolveAfterBattle_MasterLoop: inc hl jp .loop -; unused +.UnusedReturnToMap: ; unreferenced pop hl .ReturnToMap: pop de @@ -512,7 +512,7 @@ FillMoves: ld a, [wEvolutionOldSpecies] and a jr z, .CheckMove - ld a, [wd002] + ld a, [wPrevPartyLevel] cp b jr nc, .GetMove diff --git a/engine/pokemon/mail.asm b/engine/pokemon/mail.asm index acf6626b1..940061461 100644 --- a/engine/pokemon/mail.asm +++ b/engine/pokemon/mail.asm @@ -8,7 +8,7 @@ SendMailToPC: cp MAILBOX_CAPACITY jr nc, .full ld bc, MAIL_STRUCT_LENGTH - ld hl, sMailbox + ld hl, sMailboxes call AddNTimes ld d, h ld e, l @@ -44,7 +44,7 @@ DeleteMailFromPC: call OpenSRAM ld a, b push bc - ld hl, sMailbox + ld hl, sMailboxes ld bc, MAIL_STRUCT_LENGTH call AddNTimes push hl @@ -73,7 +73,7 @@ DeleteMailFromPC: ReadMailMessage: ld a, b - ld hl, sMailbox + ld hl, sMailboxes ld bc, MAIL_STRUCT_LENGTH call AddNTimes ld d, h @@ -87,7 +87,7 @@ MoveMailFromPCToParty: push bc ld a, b ld bc, MAIL_STRUCT_LENGTH - ld hl, sMailbox + ld hl, sMailboxes call AddNTimes push hl ld a, [wCurPartyMon] @@ -206,7 +206,7 @@ GivePokeMail:: call AddNTimes ld d, h ld e, l - ld hl, wd002 + ld hl, wMonMailMessageBuffer ld bc, MAIL_MSG_LENGTH + 1 ld a, BANK(sPartyMail) call OpenSRAM @@ -314,19 +314,19 @@ _PlayerMailBoxMenu: text_end InitMail: -; initialize wMailboxCount and beyond with incrementing values, one per mail -; set z if no mail +; return z if no mail ld a, BANK(sMailboxCount) call OpenSRAM ld a, [sMailboxCount] call CloseSRAM + +; initialize wMailboxCount from sMailboxCount ld hl, wMailboxCount - ld [hli], a + ld [hli], a ; now hl = wMailboxItems and a - jr z, .done ; if no mail, we're done - ; load values in memory with incrementing values starting at wMailboxCount +; initialize wMailboxItems with incrementing values starting at 1 ld b, a ld a, 1 .loop @@ -334,6 +334,7 @@ InitMail: inc a dec b jr nz, .loop + .done ld [hl], -1 ; terminate diff --git a/engine/pokemon/mail_2.asm b/engine/pokemon/mail_2.asm index b7fc57e8e..934a6bece 100644 --- a/engine/pokemon/mail_2.asm +++ b/engine/pokemon/mail_2.asm @@ -404,7 +404,7 @@ LoadBlueSkyMailGFX: ld de, BlueSkyMailGrassGFX ld c, 1 * LEN_1BPP_TILE call LoadMailGFX_Color3 - ld de, MailDragoniteGFX + ld de, MailDragoniteAndSentretGFX ld c, 23 * LEN_1BPP_TILE call LoadMailGFX_Color3 ld de, MailCloudGFX @@ -767,7 +767,7 @@ Mail_Place14TileAlternatingRow: ld b, 14 / 2 jr Mail_PlaceAlternatingRow -Mail_Place16TileAlternatingRow: +Mail_Place16TileAlternatingRow: ; unreferenced push af ld b, 16 / 2 jr Mail_PlaceAlternatingRow @@ -775,6 +775,7 @@ Mail_Place16TileAlternatingRow: Mail_Place18TileAlternatingRow: push af ld b, 18 / 2 + ; fallthrough Mail_PlaceAlternatingRow: .loop @@ -812,16 +813,16 @@ Mail_PlaceAlternatingColumn: pop af ret -Mail_Draw7TileRow: - ld b, $7 +Mail_Draw7TileRow: ; unreferenced + ld b, 7 jr Mail_DrawRowLoop Mail_Draw13TileRow: - ld b, $d + ld b, 13 jr Mail_DrawRowLoop Mail_Draw16TileRow: - ld b, $10 + ld b, 16 jr Mail_DrawRowLoop Mail_DrawTopBottomBorder: @@ -830,6 +831,7 @@ Mail_DrawTopBottomBorder: Mail_DrawFullWidthBorder: ld b, SCREEN_WIDTH + ; fallthrough Mail_DrawRowLoop: .loop diff --git a/engine/pokemon/move_mon.asm b/engine/pokemon/move_mon.asm index 36d8c4fd3..3fc4dbc73 100644 --- a/engine/pokemon/move_mon.asm +++ b/engine/pokemon/move_mon.asm @@ -780,7 +780,7 @@ RetrieveMonFromDayCareMan: call WaitSFX call GetBreedMon1LevelGrowth ld a, b - ld [wd002], a + ld [wPrevPartyLevel], a ld a, e ld [wCurPartyLevel], a xor a @@ -795,12 +795,12 @@ RetrieveMonFromDayCareLady: call WaitSFX call GetBreedMon2LevelGrowth ld a, b - ld [wd002], a + ld [wPrevPartyLevel], a ld a, e ld [wCurPartyLevel], a ld a, PC_DEPOSIT ld [wPokemonWithdrawDepositParameter], a - jp RetrieveBreedmon + jp RetrieveBreedmon ; pointless RetrieveBreedmon: ld hl, wPartyCount diff --git a/engine/pokemon/party_menu.asm b/engine/pokemon/party_menu.asm index fe470ed96..e318a0430 100644 --- a/engine/pokemon/party_menu.asm +++ b/engine/pokemon/party_menu.asm @@ -758,12 +758,10 @@ TeachWhichPKMNString: MoveToWhereString: db "Move to where?@" -ChooseAFemalePKMNString: -; unused +ChooseAFemalePKMNString: ; unreferenced db "Choose a ♀<PK><MN>.@" -ChooseAMalePKMNString: -; unused +ChooseAMalePKMNString: ; unreferenced db "Choose a ♂<PK><MN>.@" ToWhichPKMNString: diff --git a/engine/pokemon/stats_screen.asm b/engine/pokemon/stats_screen.asm index a6ad0818e..c9a5fbbe3 100644 --- a/engine/pokemon/stats_screen.asm +++ b/engine/pokemon/stats_screen.asm @@ -33,7 +33,7 @@ StatsScreenInit_gotaddress: push af ld a, [wJumptableIndex] ld b, a - ld a, [wcf64] + ld a, [wStatsScreenFlags] ld c, a push bc @@ -52,7 +52,7 @@ StatsScreenInit_gotaddress: ld a, b ld [wJumptableIndex], a ld a, c - ld [wcf64], a + ld [wStatsScreenFlags], a pop af ld [wBoxAlignment], a pop af @@ -63,11 +63,11 @@ StatsScreenMain: xor a ld [wJumptableIndex], a ; ??? - ld [wcf64], a - ld a, [wcf64] + ld [wStatsScreenFlags], a + ld a, [wStatsScreenFlags] and $ff ^ STAT_PAGE_MASK or PINK_PAGE ; first_page - ld [wcf64], a + ld [wStatsScreenFlags], a .loop ld a, [wJumptableIndex] and $ff ^ (1 << 7) @@ -83,11 +83,11 @@ StatsScreenMobile: xor a ld [wJumptableIndex], a ; ??? - ld [wcf64], a - ld a, [wcf64] + ld [wStatsScreenFlags], a + ld a, [wStatsScreenFlags] and $ff ^ STAT_PAGE_MASK or PINK_PAGE ; first_page - ld [wcf64], a + ld [wStatsScreenFlags], a .loop farcall Mobile_SetOverworldDelay ld a, [wJumptableIndex] @@ -115,7 +115,7 @@ StatsScreenPointerTable: dw StatsScreen_Exit StatsScreen_WaitAnim: - ld hl, wcf64 + ld hl, wStatsScreenFlags bit 6, [hl] jr nz, .try_anim bit 5, [hl] @@ -126,10 +126,10 @@ StatsScreen_WaitAnim: .try_anim farcall SetUpPokeAnim jr nc, .finish - ld hl, wcf64 + ld hl, wStatsScreenFlags res 6, [hl] .finish - ld hl, wcf64 + ld hl, wStatsScreenFlags res 5, [hl] farcall HDMATransferTilemapToWRAMBank3 ret @@ -147,7 +147,7 @@ StatsScreen_Exit: ret MonStatsInit: - ld hl, wcf64 + ld hl, wStatsScreenFlags res 6, [hl] call ClearBGPalettes call ClearTilemap @@ -157,7 +157,7 @@ MonStatsInit: cp EGG jr z, .egg call StatsScreen_InitUpperHalf - ld hl, wcf64 + ld hl, wStatsScreenFlags set 4, [hl] ld h, 4 call StatsScreen_SetJumptableIndex @@ -217,7 +217,7 @@ if DEF(_DEBUG) ld de, .HatchSoonString hlcoord 8, 17 call PlaceString - ld hl, wcf64 + ld hl, wStatsScreenFlags set 5, [hl] pop hl pop de @@ -232,7 +232,7 @@ endc StatsScreen_LoadPage: call StatsScreen_LoadGFX - ld hl, wcf64 + ld hl, wStatsScreenFlags res 4, [hl] ld a, [wJumptableIndex] inc a @@ -314,7 +314,7 @@ StatsScreen_GetJoypad: StatsScreen_JoypadAction: push af - ld a, [wcf64] + ld a, [wStatsScreenFlags] maskbits NUM_STAT_PAGES ld c, a pop af @@ -393,10 +393,10 @@ StatsScreen_JoypadAction: ret .set_page - ld a, [wcf64] + ld a, [wStatsScreenFlags] and $ff ^ STAT_PAGE_MASK or c - ld [wcf64], a + ld [wStatsScreenFlags], a ld h, 4 call StatsScreen_SetJumptableIndex ret @@ -530,7 +530,7 @@ StatsScreen_LoadGFX: call .ClearBox call .PageTilemap call .LoadPals - ld hl, wcf64 + ld hl, wStatsScreenFlags bit 4, [hl] jr nz, .place_frontpic call SetPalettes @@ -541,7 +541,7 @@ StatsScreen_LoadGFX: ret .ClearBox: - ld a, [wcf64] + ld a, [wStatsScreenFlags] maskbits NUM_STAT_PAGES ld c, a call StatsScreen_LoadPageIndicators @@ -551,17 +551,17 @@ StatsScreen_LoadGFX: ret .LoadPals: - ld a, [wcf64] + ld a, [wStatsScreenFlags] maskbits NUM_STAT_PAGES ld c, a farcall LoadStatsScreenPals call DelayFrame - ld hl, wcf64 + ld hl, wStatsScreenFlags set 5, [hl] ret .PageTilemap: - ld a, [wcf64] + ld a, [wStatsScreenFlags] maskbits NUM_STAT_PAGES dec a ld hl, .Jumptable @@ -848,7 +848,7 @@ StatsScreen_PlaceFrontpic: ret .AnimateMon: - ld hl, wcf64 + ld hl, wStatsScreenFlags set 5, [hl] ld a, [wCurPartySpecies] cp UNOWN @@ -890,7 +890,7 @@ StatsScreen_PlaceFrontpic: ld d, $0 ld e, ANIM_MON_MENU predef LoadMonAnimation - ld hl, wcf64 + ld hl, wStatsScreenFlags set 6, [hl] ret @@ -1033,7 +1033,7 @@ endc .picked hlcoord 1, 9 call PlaceString - ld hl, wcf64 + ld hl, wStatsScreenFlags set 5, [hl] call SetPalettes ; pals call DelayFrame @@ -1099,7 +1099,7 @@ StatsScreen_AnimateEgg: hlcoord 0, 0 ld d, $0 predef LoadMonAnimation - ld hl, wcf64 + ld hl, wStatsScreenFlags set 6, [hl] ret diff --git a/engine/pokemon/switchpartymons.asm b/engine/pokemon/switchpartymons.asm index 26aa6e5fa..2c00b34b4 100644 --- a/engine/pokemon/switchpartymons.asm +++ b/engine/pokemon/switchpartymons.asm @@ -65,7 +65,7 @@ _SwitchPartyMons: ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes push hl - ld de, wd002 + ld de, wSwitchMonBuffer ld bc, PARTYMON_STRUCT_LENGTH call CopyBytes ld a, [wBuffer3] @@ -77,14 +77,14 @@ _SwitchPartyMons: ld bc, PARTYMON_STRUCT_LENGTH call CopyBytes pop de - ld hl, wd002 + ld hl, wSwitchMonBuffer ld bc, PARTYMON_STRUCT_LENGTH call CopyBytes ld a, [wBuffer2] ld hl, wPartyMonOT call SkipNames push hl - call .CopyNameTowd002 + call .CopyNameToSwitchMonBuffer ld a, [wBuffer3] ld hl, wPartyMonOT call SkipNames @@ -92,13 +92,13 @@ _SwitchPartyMons: push hl call .CopyName pop de - ld hl, wd002 + ld hl, wSwitchMonBuffer call .CopyName ld hl, wPartyMonNicknames ld a, [wBuffer2] call SkipNames push hl - call .CopyNameTowd002 + call .CopyNameToSwitchMonBuffer ld hl, wPartyMonNicknames ld a, [wBuffer3] call SkipNames @@ -106,14 +106,14 @@ _SwitchPartyMons: push hl call .CopyName pop de - ld hl, wd002 + ld hl, wSwitchMonBuffer call .CopyName ld hl, sPartyMail ld a, [wBuffer2] ld bc, MAIL_STRUCT_LENGTH call AddNTimes push hl - ld de, wd002 + ld de, wSwitchMonBuffer ld bc, MAIL_STRUCT_LENGTH ld a, BANK(sPartyMail) call OpenSRAM @@ -127,7 +127,7 @@ _SwitchPartyMons: ld bc, MAIL_STRUCT_LENGTH call CopyBytes pop de - ld hl, wd002 + ld hl, wSwitchMonBuffer ld bc, MAIL_STRUCT_LENGTH call CopyBytes call CloseSRAM @@ -136,8 +136,8 @@ _SwitchPartyMons: pop hl ret -.CopyNameTowd002: - ld de, wd002 +.CopyNameToSwitchMonBuffer: + ld de, wSwitchMonBuffer .CopyName: ld bc, NAME_LENGTH diff --git a/engine/printer/printer.asm b/engine/printer/printer.asm index fcfd4be39..e8e93bf2d 100644 --- a/engine/printer/printer.asm +++ b/engine/printer/printer.asm @@ -447,9 +447,11 @@ CheckCancelPrint: ret .pressed_b - ld a, [wca80] + ld a, [wUnusedGameboyPrinterSafeCancelFlag] cp $0c jr nz, .cancel + +; wait for printer activity to finish before canceling? .loop ld a, [wPrinterOpcode] and a diff --git a/engine/printer/printer_serial.asm b/engine/printer/printer_serial.asm index 9d0bd907d..f717ad381 100644 --- a/engine/printer/printer_serial.asm +++ b/engine/printer/printer_serial.asm @@ -304,7 +304,7 @@ Printer_ResetData: xor a ld [wPrinterSendByteCounter], a ld [wPrinterSendByteCounter + 1], a - ld hl, wGameboyPrinterRAM + ld hl, wGameboyPrinter2bppSource ld bc, wGameboyPrinter2bppSourceEnd - wGameboyPrinter2bppSource call Printer_ByteFill ret @@ -435,10 +435,10 @@ PrinterDataPacket3: PrinterDataPacket4: db 4, 0, $00, 0 dw 4 -PrinterDataPacket5: ; unused +PrinterDataPacket5: ; unreferenced db 8, 0, $00, 0 dw 8 -PrinterDataPacket6: ; unused +PrinterDataPacket6: ; unreferenced db 15, 0, $00, 0 dw 15 diff --git a/engine/smallflag.asm b/engine/smallflag.asm index 04cbfcc23..316ae6aa6 100644 --- a/engine/smallflag.asm +++ b/engine/smallflag.asm @@ -36,9 +36,9 @@ SmallFarFlagAction: jr z, .set ; 1 = SET_FLAG dec b jr z, .check ; 2 = CHECK_FLAG -; 0 = RESET_FLAG + ; 0 = RESET_FLAG -.reset +; reset ld a, c cpl and [hl] diff --git a/engine/tilesets/tileset_anims.asm b/engine/tilesets/tileset_anims.asm index d59c750a8..8ed05c625 100644 --- a/engine/tilesets/tileset_anims.asm +++ b/engine/tilesets/tileset_anims.asm @@ -305,7 +305,7 @@ ScrollTileRightLeft: jr nz, ScrollTileLeft jr ScrollTileRight -ScrollTileUpDown: +ScrollTileUpDown: ; unreferenced ; Scroll up for 4 ticks, then down for 4 ticks. ld a, [wTileAnimationTimer] inc a @@ -891,7 +891,7 @@ AnimateWaterPalette: cp %100 ; frame 4 jr z, .color2 -.color1 +; color1 ld hl, wBGPals1 palette PAL_BG_WATER color 1 ld a, [hli] ldh [rBGPD], a |