From f3326786259f4e53c06b7565369add7605bea8ba Mon Sep 17 00:00:00 2001 From: Narishma-gb <194818981+Narishma-gb@users.noreply.github.com> Date: Tue, 18 Nov 2025 21:17:31 +0100 Subject: Use more hardware and graphics constants (#532) - Use `OBJ_SIZE` and `TILE_SIZE` from hardware.inc. - `SPRITESTATEDATA1_LENGTH`, `NUM_SPRITESTATEDATA_STRUCTS` and `TILE_1BPP_SIZE` are used in some places. - Highlight an oversight in `OakSpeech` where several direct MBC bank switches are requested. - Remove redundant comments in home/overworld.asm. - Add unreferenced `FillBgMap` function to avoid a byte of dead code. - Some constants added in wram.asm. - Correctly separate the commented code in `SaveMainData`. --- engine/items/town_map.asm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'engine/items') diff --git a/engine/items/town_map.asm b/engine/items/town_map.asm index 6758adea..573ba581 100644 --- a/engine/items/town_map.asm +++ b/engine/items/town_map.asm @@ -24,7 +24,7 @@ DisplayTownMap: call CopyData ld hl, vSprites tile BIRD_BASE_TILE ld de, TownMapCursor - lb bc, BANK(TownMapCursor), (TownMapCursorEnd - TownMapCursor) / $8 + lb bc, BANK(TownMapCursor), (TownMapCursorEnd - TownMapCursor) / TILE_1BPP_SIZE call CopyVideoDataDouble xor a ld [wWhichTownMapLocation], a @@ -149,7 +149,7 @@ LoadTownMap_Fly:: call CopyVideoData ld de, TownMapUpArrow ld hl, vChars1 tile $6d - lb bc, BANK(TownMapUpArrow), (TownMapUpArrowEnd - TownMapUpArrow) / $8 + lb bc, BANK(TownMapUpArrow), (TownMapUpArrowEnd - TownMapUpArrow) / TILE_1BPP_SIZE call CopyVideoDataDouble call BuildFlyLocationsList ld hl, wUpdateSpritesEnabled @@ -609,11 +609,11 @@ TownMapSpriteBlinkingAnimation:: xor a jr .done .hideSprites - ld hl, wShadowOAM + ld hl, wShadowOAMSprite00YCoord ld b, OAM_COUNT - 4 - ld de, $4 + ld de, OBJ_SIZE .hideSpritesLoop - ld [hl], $a0 + ld [hl], SCREEN_HEIGHT_PX + OAM_Y_OFS add hl, de dec b jr nz, .hideSpritesLoop -- cgit v1.3.1-sl0p From e92d1af478c8381fde30f709c2619abe90104d3a Mon Sep 17 00:00:00 2001 From: Rangi <35663410+Rangi42@users.noreply.github.com> Date: Tue, 25 Nov 2025 17:53:29 -0500 Subject: Avoid magic numbers for most `CopyData` calls (#542) --- constants/gfx_constants.asm | 6 +++++- constants/text_constants.asm | 1 + engine/battle/animations.asm | 20 ++++++++++---------- engine/battle/core.asm | 21 +++++++++++---------- engine/battle/draw_hud_pokeball_gfx.asm | 8 ++++---- engine/battle/effects.asm | 2 +- engine/battle/ghost_marowak_anim.asm | 2 +- engine/battle/move_effects/transform.asm | 9 +++++---- engine/battle/trainer_ai.asm | 4 ++-- engine/events/in_game_trades.asm | 2 +- engine/items/item_effects.asm | 6 +++--- engine/items/town_map.asm | 4 ++-- engine/movie/evolution.asm | 2 +- engine/movie/hall_of_fame.asm | 2 +- engine/movie/splash.asm | 2 +- engine/overworld/cut2.asm | 6 +++--- engine/overworld/player_animations.asm | 6 +++--- engine/pokemon/add_mon.asm | 2 +- engine/slots/slot_machine.asm | 2 +- home/trainers.asm | 2 +- ram/vram.asm | 6 +++--- ram/wram.asm | 10 +++++++--- 22 files changed, 68 insertions(+), 57 deletions(-) (limited to 'engine/items') diff --git a/constants/gfx_constants.asm b/constants/gfx_constants.asm index 1a06238c..c3f29ca5 100644 --- a/constants/gfx_constants.asm +++ b/constants/gfx_constants.asm @@ -7,7 +7,11 @@ DEF SCREEN_BLOCK_HEIGHT EQU 5 ; blocks DEF SURROUNDING_WIDTH EQU SCREEN_BLOCK_WIDTH * BLOCK_WIDTH ; tiles DEF SURROUNDING_HEIGHT EQU SCREEN_BLOCK_HEIGHT * BLOCK_HEIGHT ; tiles -DEF SPRITEBUFFERSIZE EQU 7 * 7 * TILE_1BPP_SIZE +DEF PIC_WIDTH EQU 7 ; tiles +DEF PIC_HEIGHT EQU PIC_WIDTH ; tiles +DEF PIC_SIZE EQU PIC_WIDTH * PIC_HEIGHT ; tiles + +DEF SPRITEBUFFERSIZE EQU PIC_WIDTH * PIC_HEIGHT * TILE_1BPP_SIZE ; HP bar DEF HP_BAR_GREEN EQU 0 diff --git a/constants/text_constants.asm b/constants/text_constants.asm index 4dbdf666..ed195172 100644 --- a/constants/text_constants.asm +++ b/constants/text_constants.asm @@ -1,6 +1,7 @@ DEF NAME_LENGTH EQU 11 DEF ITEM_NAME_LENGTH EQU 13 DEF NAME_BUFFER_LENGTH EQU 20 +DEF GYM_CITY_LENGTH EQU 17 ; PrintNumber, PrintBCDNumber const_def 5 diff --git a/engine/battle/animations.asm b/engine/battle/animations.asm index 711ebda4..f66be640 100644 --- a/engine/battle/animations.asm +++ b/engine/battle/animations.asm @@ -1213,12 +1213,12 @@ _AnimationSlideMonUp: push bc ; In each iteration, slide up all rows but the top one (which is overwritten). - ld b, 6 + ld b, PIC_HEIGHT - 1 .slideLoop push bc push de push hl - ld bc, 7 + ld bc, PIC_WIDTH call CopyData ; Note that de and hl are popped in the same order they are pushed, swapping ; their values. When CopyData is called, hl points to a tile 1 row below @@ -1242,10 +1242,10 @@ _AnimationSlideMonUp: ld a, [wSlideMonUpBottomRowLeftTile] inc a ld [wSlideMonUpBottomRowLeftTile], a - ld c, 7 + ld c, PIC_WIDTH .fillBottomRowLoop ld [hli], a - add 7 + add PIC_WIDTH dec c jr nz, .fillBottomRowLoop @@ -1723,10 +1723,10 @@ AnimationMinimizeMon: ld hl, wTempPic push hl xor a - ld bc, (7 * 7) tiles + ld bc, PIC_SIZE tiles call FillMemory pop hl - ld de, (7 * 3 + 4) tiles + TILE_SIZE / 4 + ld de, (PIC_WIDTH * 3 + 4) tiles + TILE_SIZE / 4 add hl, de ld de, MinimizedMonSprite ld c, MinimizedMonSpriteEnd - MinimizedMonSprite @@ -1774,7 +1774,7 @@ AnimationSlideMonDownAndHide: jr nz, .loop call AnimationHideMonPic ld hl, wTempPic - ld bc, 7 * 7 tiles + ld bc, PIC_SIZE tiles xor a call FillMemory jp CopyTempPicToMonPic @@ -1867,7 +1867,7 @@ CopyTempPicToMonPic: ld hl, vFrontPic ; enemy turn .next ld de, wTempPic - ld bc, 7 * 7 + ld bc, PIC_SIZE jp CopyVideoData AnimationWavyScreen: @@ -1935,7 +1935,7 @@ AnimationSubstitute: ; Changes the pokemon's sprite to the mini sprite ld hl, wTempPic xor a - ld bc, 7 * 7 tiles + ld bc, PIC_SIZE tiles call FillMemory ldh a, [hWhoseTurn] and a @@ -2473,7 +2473,7 @@ AnimationShakeEnemyHUD: ; Make a copy of the back pic's tile patterns in sprite tile pattern VRAM. ld de, vBackPic ld hl, vSprites - ld bc, 7 * 7 + ld bc, PIC_SIZE call CopyVideoData xor a diff --git a/engine/battle/core.asm b/engine/battle/core.asm index 672bd416..4c25373a 100644 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -1183,17 +1183,17 @@ SlideDownFaintedMonPic: push af set BIT_NO_TEXT_DELAY, a ld [wStatusFlags5], a - ld b, 7 ; number of times to slide + ld b, PIC_HEIGHT ; number of times to slide .slideStepLoop ; each iteration, the mon is slid down one row push bc push de push hl - ld b, 6 ; number of rows + ld b, PIC_HEIGHT - 1 ; number of rows .rowLoop push bc push hl push de - ld bc, $7 + ld bc, PIC_WIDTH call CopyData pop de pop hl @@ -1225,7 +1225,8 @@ SlideDownFaintedMonPic: ret SevenSpacesText: - db " @" + ds PIC_WIDTH, ' ' + db "@" ; slides the player or enemy trainer off screen ; a is the number of tiles to slide it horizontally (always 9 for the player trainer or 8 for the enemy trainer) @@ -1237,7 +1238,7 @@ SlideTrainerPicOffScreen: .slideStepLoop ; each iteration, the trainer pic is slid one tile left/right push bc push hl - ld b, 7 ; number of rows + ld b, PIC_HEIGHT ; number of rows .rowLoop push hl ldh a, [hSlideAmount] @@ -1794,7 +1795,7 @@ AnimateRetreatingPlayerMon: lb bc, 7, 7 jp ClearScreenArea -; Copies player's current pokemon's current HP and status into the party +; Copies player's current pokemon's current HP, party pos, and status into the party ; struct data so it stays after battle or switching ReadPlayerMonCurHPAndStatus: ld a, [wPlayerMonNumber] @@ -1804,7 +1805,7 @@ ReadPlayerMonCurHPAndStatus: ld d, h ld e, l ld hl, wBattleMonHP - ld bc, $4 ; 2 bytes HP, 1 byte unknown (unused?), 1 byte status + ld bc, MON_STATUS + 1 - MON_HP ; also copies party pos in-between HP and status jp CopyData DrawHUDsAndHPBars: @@ -6352,7 +6353,7 @@ LoadPlayerBackPic: ld [hl], d ; OAM Y inc hl ld [hl], e ; OAM X - ld a, $8 ; height of tile + ld a, TILE_HEIGHT add d ; increase Y by height of tile ld d, a inc hl @@ -6366,7 +6367,7 @@ LoadPlayerBackPic: ldh a, [hOAMTile] add $4 ; increase tile number by 4 ldh [hOAMTile], a - ld a, $8 ; width of tile + ld a, TILE_WIDTH add e ; increase X by width of tile ld e, a dec b @@ -6381,7 +6382,7 @@ LoadPlayerBackPic: ld de, sSpriteBuffer1 ldh a, [hLoadedROMBank] ld b, a - ld c, 7 * 7 + ld c, PIC_SIZE call CopyVideoData xor a ld [rRAMG], a diff --git a/engine/battle/draw_hud_pokeball_gfx.asm b/engine/battle/draw_hud_pokeball_gfx.asm index 983e7cdf..011b4b33 100644 --- a/engine/battle/draw_hud_pokeball_gfx.asm +++ b/engine/battle/draw_hud_pokeball_gfx.asm @@ -119,7 +119,7 @@ WritePokeballOAMData: PlacePlayerHUDTiles: ld hl, PlayerBattleHUDGraphicsTiles ld de, wHUDGraphicsTiles - ld bc, $3 + ld bc, wHUDGraphicsTilesEnd - wHUDGraphicsTiles call CopyData hlcoord 18, 10 ld de, -1 @@ -134,7 +134,7 @@ PlayerBattleHUDGraphicsTiles: PlaceEnemyHUDTiles: ld hl, EnemyBattleHUDGraphicsTiles ld de, wHUDGraphicsTiles - ld bc, $3 + ld bc, wHUDGraphicsTilesEnd - wHUDGraphicsTiles call CopyData hlcoord 1, 2 ld de, $1 @@ -150,7 +150,7 @@ PlaceHUDTiles: ld [hl], $73 ld bc, SCREEN_WIDTH add hl, bc - ld a, [wHUDGraphicsTiles + 1] ; leftmost tile + ld a, [wHUDCornerTile] ; leftmost tile ld [hl], a ld a, 8 .loop @@ -159,7 +159,7 @@ PlaceHUDTiles: dec a jr nz, .loop add hl, de - ld a, [wHUDGraphicsTiles + 2] ; rightmost tile + ld a, [wHUDTriangleTile] ; rightmost tile ld [hl], a ret diff --git a/engine/battle/effects.asm b/engine/battle/effects.asm index e107853c..003592aa 100644 --- a/engine/battle/effects.asm +++ b/engine/battle/effects.asm @@ -754,7 +754,7 @@ PrintStatText: jr .findStatName_inner .foundStatName ld de, wStringBuffer - ld bc, $a + ld bc, NAME_LENGTH - 1 ; all StatModTextStrings are at most 10 bytes jp CopyData INCLUDE "data/battle/stat_mod_names.asm" diff --git a/engine/battle/ghost_marowak_anim.asm b/engine/battle/ghost_marowak_anim.asm index 4b1eb452..1040f85f 100644 --- a/engine/battle/ghost_marowak_anim.asm +++ b/engine/battle/ghost_marowak_anim.asm @@ -52,7 +52,7 @@ MarowakAnim: CopyMonPicFromBGToSpriteVRAM: ld de, vFrontPic ld hl, vSprites - ld bc, 7 * 7 + ld bc, PIC_SIZE call CopyVideoData ld a, $10 ld [wBaseCoordY], a diff --git a/engine/battle/move_effects/transform.asm b/engine/battle/move_effects/transform.asm index 6f2e705c..343fa3ca 100644 --- a/engine/battle/move_effects/transform.asm +++ b/engine/battle/move_effects/transform.asm @@ -82,14 +82,15 @@ TransformEffect_: ld a, [hli] ld [de], a inc de -; Attack, Defense, Speed, and Special stats +; Skip level and max HP inc hl inc hl inc hl inc de inc de inc de - ld bc, $8 +; Attack, Defense, Speed, and Special stats + ld bc, (NUM_STATS - 1) * 2 call CopyData ld bc, wBattleMonMoves - wBattleMonPP add hl, bc ; ld hl, wBattleMonMoves @@ -99,7 +100,7 @@ TransformEffect_: ld a, [hli] and a jr z, .lessThanFourMoves - ld a, $5 + ld a, 5 ld [de], a inc de dec b @@ -136,7 +137,7 @@ TransformEffect_: ld l, e pop de .gotStatsOrModsToCopy - ld bc, $8 + ld bc, (NUM_STATS - 1) * 2 jp CopyData .failed diff --git a/engine/battle/trainer_ai.asm b/engine/battle/trainer_ai.asm index 4134047f..546dd60e 100644 --- a/engine/battle/trainer_ai.asm +++ b/engine/battle/trainer_ai.asm @@ -583,7 +583,7 @@ AISwitchIfEnoughMons: SwitchEnemyMon: -; prepare to withdraw the active monster: copy hp, number, and status to roster +; prepare to withdraw the active monster: copy HP, party pos, and status to roster ld a, [wEnemyMonPartyPos] ld hl, wEnemyMon1HP @@ -592,7 +592,7 @@ SwitchEnemyMon: ld d, h ld e, l ld hl, wEnemyMonHP - ld bc, 4 + ld bc, MON_STATUS + 1 - MON_HP ; also copies party pos in-between HP and status call CopyData ld hl, AIBattleWithdrawText diff --git a/engine/events/in_game_trades.asm b/engine/events/in_game_trades.asm index 4c6041b0..5cc251f4 100644 --- a/engine/events/in_game_trades.asm +++ b/engine/events/in_game_trades.asm @@ -226,7 +226,7 @@ InGameTrade_CopyDataToReceivedMon: ld bc, wPartyMon2 - wPartyMon1 call InGameTrade_GetReceivedMonPointer ld hl, wTradedEnemyMonOTID - ld bc, $2 + ld bc, 2 jp CopyData ; the received mon's index is (partyCount - 1), diff --git a/engine/items/item_effects.asm b/engine/items/item_effects.asm index 1b68e47a..7fffae59 100644 --- a/engine/items/item_effects.asm +++ b/engine/items/item_effects.asm @@ -1302,13 +1302,13 @@ ItemUseMedicine: .statNameInnerLoop ld a, [hli] ld b, a - ld a, $50 + ld a, '@' cp b jr nz, .statNameInnerLoop jr .statNameLoop .gotStatName ld de, wStringBuffer - ld bc, 10 + ld bc, NAME_LENGTH - 1 ; all VitaminStats are at most 10 bytes call CopyData ; copy the stat's name to wStringBuffer ld a, SFX_HEAL_AILMENT call PlaySound @@ -2029,7 +2029,7 @@ ItemUsePPRestore: ld bc, wPartyMon2 - wPartyMon1 call AddNTimes ld de, wBattleMonPP - ld bc, 4 + ld bc, NUM_MOVES call CopyData ; copy party data to in-battle data .skipUpdatingInBattleData ld a, SFX_HEAL_AILMENT diff --git a/engine/items/town_map.asm b/engine/items/town_map.asm index 573ba581..35acaa29 100644 --- a/engine/items/town_map.asm +++ b/engine/items/town_map.asm @@ -20,7 +20,7 @@ DisplayTownMap: call PlaceString ld hl, wShadowOAMSprite00 ld de, wShadowOAMBackupSprite00 - ld bc, 4 * 4 + ld bc, OBJ_SIZE * 4 call CopyData ld hl, vSprites tile BIRD_BASE_TILE ld de, TownMapCursor @@ -64,7 +64,7 @@ DisplayTownMap: call PlaceString ld hl, wShadowOAMSprite04 ld de, wShadowOAMBackupSprite04 - ld bc, 4 * 4 + ld bc, OBJ_SIZE * 4 call CopyData .inputLoop call TownMapSpriteBlinkingAnimation diff --git a/engine/movie/evolution.asm b/engine/movie/evolution.asm index 4258b94d..b6e541c5 100644 --- a/engine/movie/evolution.asm +++ b/engine/movie/evolution.asm @@ -30,7 +30,7 @@ EvolveMon: call Evolution_LoadPic ld de, vFrontPic ld hl, vBackPic - ld bc, 7 * 7 + ld bc, PIC_SIZE call CopyVideoData ld a, [wEvoOldSpecies] ld [wCurPartySpecies], a diff --git a/engine/movie/hall_of_fame.asm b/engine/movie/hall_of_fame.asm index b2c0de42..88e777af 100644 --- a/engine/movie/hall_of_fame.asm +++ b/engine/movie/hall_of_fame.asm @@ -188,7 +188,7 @@ HoFLoadPlayerPics: call UncompressSpriteFromDE ld hl, sSpriteBuffer1 ld de, sSpriteBuffer0 - ld bc, $310 + ld bc, 2 * SPRITEBUFFERSIZE call CopyData ld de, vFrontPic call InterlaceMergeSpriteBuffers diff --git a/engine/movie/splash.asm b/engine/movie/splash.asm index 7f06c68b..cc5526ae 100644 --- a/engine/movie/splash.asm +++ b/engine/movie/splash.asm @@ -133,7 +133,7 @@ AnimateShootingStar: ; shift the existing OAM entries down to make room for the next wave ld hl, wShadowOAMSprite04 ld de, wShadowOAM - ld bc, $50 + ld bc, OBJ_SIZE * 20 call CopyData pop af diff --git a/engine/overworld/cut2.asm b/engine/overworld/cut2.asm index 69c8cb13..7697d430 100644 --- a/engine/overworld/cut2.asm +++ b/engine/overworld/cut2.asm @@ -77,13 +77,13 @@ AnimCutGrass_UpdateOAMEntries: AnimCutGrass_SwapOAMEntries: ld hl, wShadowOAMSprite36 ld de, wBuffer - ld bc, $8 + ld bc, 2 * OBJ_SIZE call CopyData ld hl, wShadowOAMSprite38 ld de, wShadowOAMSprite36 - ld bc, $8 + ld bc, 2 * OBJ_SIZE call CopyData ld hl, wBuffer ld de, wShadowOAMSprite38 - ld bc, $8 + ld bc, 2 * OBJ_SIZE jp CopyData diff --git a/engine/overworld/player_animations.asm b/engine/overworld/player_animations.asm index 4ed1f49f..657c001e 100644 --- a/engine/overworld/player_animations.asm +++ b/engine/overworld/player_animations.asm @@ -264,7 +264,7 @@ InitFacingDirectionList: ld [wSavedPlayerScreenY], a ld hl, PlayerSpinningFacingOrder ld de, wFacingDirectionList - ld bc, 4 + ld bc, OBJ_SIZE call CopyData ld a, [wSpritePlayerStateData1ImageIndex] ; (image index is locked to standing images) ld hl, wFacingDirectionList @@ -288,7 +288,7 @@ SpinPlayerSprite: push hl ld hl, wFacingDirectionList ld de, wFacingDirectionList - 1 - ld bc, 4 + ld bc, OBJ_SIZE call CopyData ld a, [wFacingDirectionList - 1] ld [wFacingDirectionList + 3], a @@ -393,7 +393,7 @@ FishingAnim: ld hl, FishingRodOAM add hl, bc ld de, wShadowOAMSprite39 - ld bc, $4 + ld bc, OBJ_SIZE call CopyData ld c, 100 call DelayFrames diff --git a/engine/pokemon/add_mon.asm b/engine/pokemon/add_mon.asm index 7eaca222..a7c201ea 100644 --- a/engine/pokemon/add_mon.asm +++ b/engine/pokemon/add_mon.asm @@ -231,7 +231,7 @@ _AddPartyMon:: dec a jr nz, .calcFreshStats ld hl, wEnemyMonMaxHP - ld bc, $a + ld bc, NUM_STATS * 2 call CopyData ; copy stats of cur enemy mon pop hl jr .done diff --git a/engine/slots/slot_machine.asm b/engine/slots/slot_machine.asm index 147519c7..2e02caf3 100644 --- a/engine/slots/slot_machine.asm +++ b/engine/slots/slot_machine.asm @@ -447,7 +447,7 @@ SlotMachine_CheckForMatches: ld h, [hl] ld l, a ld de, wStringBuffer - ld bc, 4 + ld bc, 4 ; every SlotReward*Text is at most 4 bytes call CopyData pop hl ld de, .flashScreenLoop diff --git a/home/trainers.asm b/home/trainers.asm index ab8d5fff..f00c4df9 100644 --- a/home/trainers.asm +++ b/home/trainers.asm @@ -31,7 +31,7 @@ ExecuteCurMapScriptInTable:: LoadGymLeaderAndCityName:: push de ld de, wGymCityName - ld bc, $11 + ld bc, GYM_CITY_LENGTH call CopyData ; load city name pop hl ld de, wGymLeaderName diff --git a/ram/vram.asm b/ram/vram.asm index fafb5d8e..0819fe0a 100644 --- a/ram/vram.asm +++ b/ram/vram.asm @@ -12,8 +12,8 @@ NEXTU ; battle/menu vSprites:: ds $80 tiles vFont:: ds $80 tiles -vFrontPic:: ds 7 * 7 tiles -vBackPic:: ds 7 * 7 tiles +vFrontPic:: ds PIC_SIZE tiles +vBackPic:: ds PIC_SIZE tiles NEXTU ; overworld @@ -25,7 +25,7 @@ NEXTU ; title ds $80 tiles vTitleLogo:: ds $80 tiles - ds 7 * 7 tiles + ds PIC_SIZE tiles vTitleLogo2:: ds 30 tiles ENDU diff --git a/ram/wram.asm b/ram/wram.asm index ff7d10ae..0b00d272 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -191,7 +191,7 @@ wOverworldMap:: ds 1300 wOverworldMapEnd:: NEXTU -wTempPic:: ds 7 * 7 tiles +wTempPic:: ds PIC_SIZE tiles ENDU @@ -688,7 +688,11 @@ NEXTU ds 1 ; difference in X between the next ball and the current one wHUDPokeballGfxOffsetX:: db -wHUDGraphicsTiles:: ds 3 +wHUDGraphicsTiles:: +wHUDUnusedTopTile:: db +wHUDCornerTile:: db +wHUDTriangleTile:: db +wHUDGraphicsTilesEnd:: NEXTU ; the level of the mon at the time it entered day care @@ -1079,7 +1083,7 @@ wExpAmountGained:: dw wGainBoostedExp:: db ENDU -wGymCityName:: ds 17 +wGymCityName:: ds GYM_CITY_LENGTH wGymLeaderName:: ds NAME_LENGTH -- cgit v1.3.1-sl0p From 3a4382c6055e21da72357dd18638947a2acbbda9 Mon Sep 17 00:00:00 2001 From: Narishma-gb <194818981+Narishma-gb@users.noreply.github.com> Date: Thu, 27 Nov 2025 19:39:25 +0100 Subject: Use more Pokemon data constants, create MOVE_NAME_LENGTH (#543) --- constants/pokemon_data_constants.asm | 4 +- constants/text_constants.asm | 2 + engine/battle/battle_transitions.asm | 4 +- engine/battle/core.asm | 52 +++++++------- engine/battle/decrement_pp.asm | 2 +- engine/battle/draw_hud_pokeball_gfx.asm | 2 +- engine/battle/effects.asm | 4 +- engine/battle/end_of_battle.asm | 6 +- engine/battle/experience.asm | 26 +++---- engine/battle/read_trainer_party.asm | 2 +- engine/battle/trainer_ai.asm | 6 +- engine/events/heal_party.asm | 10 +-- engine/events/in_game_trades.asm | 6 +- engine/events/poison.asm | 4 +- engine/items/item_effects.asm | 124 +++++++++++++++++--------------- engine/items/tmhm.asm | 2 +- engine/link/cable_club.asm | 12 ++-- engine/menus/naming_screen.asm | 4 +- engine/menus/start_sub_menus.asm | 14 ++-- engine/menus/text_box.asm | 2 +- engine/movie/hall_of_fame.asm | 2 +- engine/pokemon/add_mon.asm | 33 ++++----- engine/pokemon/bills_pc.asm | 4 +- engine/pokemon/evos_moves.asm | 10 +-- engine/pokemon/learn_move.asm | 6 +- engine/pokemon/load_mon_data.asm | 6 +- engine/pokemon/remove_mon.asm | 70 ++++++++++-------- engine/pokemon/set_types.asm | 2 +- engine/pokemon/status_screen.asm | 2 +- home/list_menu.asm | 2 +- home/move_mon.asm | 2 +- macros/ram.asm | 2 - ram/wram.asm | 7 +- scripts/Daycare.asm | 4 +- scripts/NameRatersHouse.asm | 2 +- 35 files changed, 235 insertions(+), 207 deletions(-) (limited to 'engine/items') diff --git a/constants/pokemon_data_constants.asm b/constants/pokemon_data_constants.asm index 1234acab..16d21f54 100644 --- a/constants/pokemon_data_constants.asm +++ b/constants/pokemon_data_constants.asm @@ -44,7 +44,7 @@ DEF MON_SPD_EXP rw DEF MON_SPC_EXP rw DEF MON_DVS rw DEF MON_PP rb NUM_MOVES -DEF BOXMON_STRUCT_LENGTH EQU _RS +DEF BOXMON_STRUCT_LENGTH EQU _RS ; $21 DEF MON_LEVEL rb DEF MON_STATS rw NUM_STATS rsset MON_STATS @@ -53,7 +53,7 @@ DEF MON_ATK rw DEF MON_DEF rw DEF MON_SPD rw DEF MON_SPC rw -DEF PARTYMON_STRUCT_LENGTH EQU _RS +DEF PARTYMON_STRUCT_LENGTH EQU _RS ; $2c DEF PARTY_LENGTH EQU 6 diff --git a/constants/text_constants.asm b/constants/text_constants.asm index ed195172..88a42bbe 100644 --- a/constants/text_constants.asm +++ b/constants/text_constants.asm @@ -1,5 +1,7 @@ +DEF PLAYER_NAME_LENGTH EQU 8 DEF NAME_LENGTH EQU 11 DEF ITEM_NAME_LENGTH EQU 13 +DEF MOVE_NAME_LENGTH EQU 14 DEF NAME_BUFFER_LENGTH EQU 20 DEF GYM_CITY_LENGTH EQU 17 diff --git a/engine/battle/battle_transitions.asm b/engine/battle/battle_transitions.asm index 3670cddc..a37a5054 100644 --- a/engine/battle/battle_transitions.asm +++ b/engine/battle/battle_transitions.asm @@ -104,11 +104,11 @@ GetBattleTransitionID_CompareLevels: ld a, [hli] or [hl] jr nz, .notFainted - ld de, wPartyMon2 - (wPartyMon1 + 1) + ld de, PARTYMON_STRUCT_LENGTH - 1 add hl, de jr .faintedLoop .notFainted - ld de, wPartyMon1Level - (wPartyMon1HP + 1) + ld de, MON_LEVEL - (MON_HP + 1) add hl, de ld a, [hl] add $3 diff --git a/engine/battle/core.asm b/engine/battle/core.asm index 4c25373a..44fd9a70 100644 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -137,7 +137,7 @@ StartBattle: inc a ld [wFirstMonsNotOutYet], a ld hl, wEnemyMon1HP - ld bc, wEnemyMon2 - wEnemyMon1 - 1 + ld bc, PARTYMON_STRUCT_LENGTH - 1 ld d, $3 .findFirstAliveEnemyMonLoop inc d @@ -736,7 +736,7 @@ FaintEnemyPokemon: jr z, .wild ld a, [wEnemyMonPartyPos] ld hl, wEnemyMon1HP - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes xor a ld [hli], a @@ -876,7 +876,7 @@ AnyEnemyPokemonAliveCheck: ld b, a xor a ld hl, wEnemyMon1HP - ld de, wEnemyMon2 - wEnemyMon1 + ld de, PARTYMON_STRUCT_LENGTH .nextPokemon or [hl] inc hl @@ -1330,7 +1330,7 @@ EnemySendOutFirstMon: ld a, b ld [wWhichPokemon], a push bc - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes pop bc inc hl @@ -1342,7 +1342,7 @@ EnemySendOutFirstMon: .next3 ld a, [wWhichPokemon] ld hl, wEnemyMon1Level - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hl] ld [wCurEnemyLevel], a @@ -1457,7 +1457,7 @@ AnyPartyAlive:: ld e, a xor a ld hl, wPartyMon1HP - ld bc, wPartyMon2 - wPartyMon1 - 1 + ld bc, PARTYMON_STRUCT_LENGTH - 1 .partyMonsLoop or [hl] inc hl @@ -1473,7 +1473,7 @@ AnyPartyAlive:: HasMonFainted: ld a, [wWhichPokemon] ld hl, wPartyMon1HP - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hli] or [hl] @@ -1625,16 +1625,16 @@ GotAwayText: ; copies from party data to battle mon data when sending out a new player mon LoadBattleMonFromParty: ld a, [wWhichPokemon] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld hl, wPartyMon1Species call AddNTimes ld de, wBattleMonSpecies ld bc, wBattleMonDVs - wBattleMonSpecies call CopyData - ld bc, wPartyMon1DVs - wPartyMon1OTID + ld bc, MON_DVS - MON_OTID add hl, bc ld de, wBattleMonDVs - ld bc, wPartyMon1PP - wPartyMon1DVs + ld bc, MON_PP - MON_DVS call CopyData ld de, wBattleMonPP ld bc, NUM_MOVES @@ -1669,16 +1669,16 @@ LoadBattleMonFromParty: ; copies from enemy party data to current enemy mon data when sending out a new enemy mon LoadEnemyMonFromParty: ld a, [wWhichPokemon] - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld hl, wEnemyMons call AddNTimes ld de, wEnemyMonSpecies ld bc, wEnemyMonDVs - wEnemyMonSpecies call CopyData - ld bc, wEnemyMon1DVs - wEnemyMon1OTID + ld bc, MON_DVS - MON_OTID add hl, bc ld de, wEnemyMonDVs - ld bc, wEnemyMon1PP - wEnemyMon1DVs + ld bc, MON_PP - MON_DVS call CopyData ld de, wEnemyMonPP ld bc, NUM_MOVES @@ -1800,7 +1800,7 @@ AnimateRetreatingPlayerMon: ReadPlayerMonCurHPAndStatus: ld a, [wPlayerMonNumber] ld hl, wPartyMon1HP - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld d, h ld e, l @@ -2520,7 +2520,7 @@ MoveSelectionMenu: .relearnmenu ld a, [wWhichPokemon] ld hl, wPartyMon1Moves - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes call .loadmoves hlcoord 4, 7 @@ -2798,12 +2798,12 @@ SwapMovesInMenu: .swapMovesInPartyMon ld hl, wPartyMon1Moves ld a, [wPlayerMonNumber] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes push hl call .swapBytes ; swap moves pop hl - ld bc, wPartyMon1PP - wPartyMon1Moves + ld bc, MON_PP - MON_MOVES add hl, bc call .swapBytes ; swap move PP xor a @@ -3451,7 +3451,7 @@ CheckPlayerStatusConditions: bit PAR, [hl] jr z, .BideCheck call BattleRandom - cp $3F ; 25% to be fully paralyzed + cp 25 percent ; chance to be fully paralyzed jr nc, .BideCheck ld hl, FullyParalyzedText call PrintText @@ -3970,7 +3970,7 @@ CheckForDisobedience: ; compare the mon's original trainer ID with the player's ID to see if it was traded .checkIfMonIsTraded ld hl, wPartyMon1OTID - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wPlayerMonNumber] call AddNTimes ld a, [wPlayerID] @@ -4197,7 +4197,7 @@ GetDamageVarsForPlayerAttack: push bc ld hl, wPartyMon1Attack ld a, [wPlayerMonNumber] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes pop bc jr .scaleStats @@ -4229,7 +4229,7 @@ GetDamageVarsForPlayerAttack: push bc ld hl, wPartyMon1Special ld a, [wPlayerMonNumber] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes pop bc ; if either the offensive or defensive stat is too large to store in a byte, scale both stats by dividing them by 4 @@ -4303,7 +4303,7 @@ GetDamageVarsForEnemyAttack: ; in the case of a critical hit, reset the player's defense and the enemy's attack to their base values ld hl, wPartyMon1Defense ld a, [wPlayerMonNumber] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hli] ld b, a @@ -4335,7 +4335,7 @@ GetDamageVarsForEnemyAttack: ; in the case of a critical hit, reset the player's and enemy's specials to their base values ld hl, wPartyMon1Special ld a, [wPlayerMonNumber] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hli] ld b, a @@ -4398,7 +4398,7 @@ GetEnemyMonStat: ld b, $0 add hl, bc ld a, [wEnemyMonPartyPos] - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hli] ldh [hMultiplicand + 1], a @@ -5197,7 +5197,7 @@ IncrementMovePP: jr z, .updatePP ld a, [wEnemyMonPartyPos] ; value for enemy turn .updatePP - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes inc [hl] ; increment PP in the party memory location ret @@ -6206,7 +6206,7 @@ LoadEnemyMonData: ; if it's a trainer battle, copy moves from enemy party data ld hl, wEnemyMon1Moves ld a, [wWhichPokemon] - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld bc, NUM_MOVES call CopyData diff --git a/engine/battle/decrement_pp.asm b/engine/battle/decrement_pp.asm index 441bbb81..93515224 100644 --- a/engine/battle/decrement_pp.asm +++ b/engine/battle/decrement_pp.asm @@ -31,7 +31,7 @@ DecrementPP: ld hl, wPartyMon1PP ; PP of first move (in party) ld a, [wPlayerMonNumber] ; which mon in party is active - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ; calculate address of the mon to modify .DecrementPP: ld a, [wPlayerMoveListIndex] ; which move (0, 1, 2, 3) did we use? diff --git a/engine/battle/draw_hud_pokeball_gfx.asm b/engine/battle/draw_hud_pokeball_gfx.asm index 011b4b33..768a6e20 100644 --- a/engine/battle/draw_hud_pokeball_gfx.asm +++ b/engine/battle/draw_hud_pokeball_gfx.asm @@ -90,7 +90,7 @@ PickPokeball: .done ld a, b ld [de], a - ld bc, wPartyMon2 - wPartyMon1Status + ld bc, PARTYMON_STRUCT_LENGTH - MON_STATUS add hl, bc ; next mon struct ret diff --git a/engine/battle/effects.asm b/engine/battle/effects.asm index 003592aa..2cef2521 100644 --- a/engine/battle/effects.asm +++ b/engine/battle/effects.asm @@ -323,7 +323,7 @@ CheckDefrost: ld [wEnemyMonStatus], a ; set opponent status to 00 ["defrost" a frozen monster] ld hl, wEnemyMon1Status ld a, [wEnemyMonPartyPos] - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes xor a ld [hl], a ; clear status in roster @@ -336,7 +336,7 @@ CheckDefrost: ld [wBattleMonStatus], a ld hl, wPartyMon1Status ld a, [wPlayerMonNumber] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes xor a ld [hl], a diff --git a/engine/battle/end_of_battle.asm b/engine/battle/end_of_battle.asm index 80fdf002..2feb50bd 100644 --- a/engine/battle/end_of_battle.asm +++ b/engine/battle/end_of_battle.asm @@ -5,7 +5,7 @@ EndOfBattle: ; link battle ld a, [wEnemyMonPartyPos] ld hl, wEnemyMon1Status - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [wEnemyMonStatus] ld [hl], a @@ -60,8 +60,8 @@ EndOfBattle: ld [hli], a ld [hl], a ld [wListScrollOffset], a - ld hl, wPlayerStatsToDouble - ld b, $18 + ld hl, wBattleStatusData + ld b, wBattleStatusDataEnd - wBattleStatusData .loop ld [hli], a dec b diff --git a/engine/battle/experience.asm b/engine/battle/experience.asm index a8ee6747..4e44643c 100644 --- a/engine/battle/experience.asm +++ b/engine/battle/experience.asm @@ -21,7 +21,7 @@ GainExperience: and a ; is mon's gain exp flag set? pop hl jp z, .nextMon ; if mon's gain exp flag not set, go to next mon - ld de, (wPartyMon1HPExp + 1) - (wPartyMon1HP + 1) + ld de, (MON_HP_EXP + 1) - (MON_HP + 1) add hl, de ld d, h ld e, l @@ -66,9 +66,9 @@ GainExperience: ldh [hDivisor], a ld b, 4 call Divide - ld hl, wPartyMon1OTID - (wPartyMon1DVs - 1) + ld hl, MON_OTID - (MON_DVS - 1) add hl, de - ld b, [hl] ; party mon OTID + ld b, [hl] ; wPartyMon*OTID inc hl ld a, [wPlayerID] cp b @@ -152,7 +152,7 @@ GainExperience: ld [wMonDataLocation], a call LoadMonData pop hl - ld bc, wPartyMon1Level - wPartyMon1Exp + ld bc, MON_LEVEL - MON_EXP add hl, bc push hl farcall CalcLevelFromExperience @@ -166,13 +166,13 @@ GainExperience: ld a, d ld [wCurEnemyLevel], a ld [hl], a - ld bc, wPartyMon1Species - wPartyMon1Level + ld bc, MON_SPECIES - MON_LEVEL add hl, bc ld a, [hl] ld [wCurSpecies], a ld [wPokedexNum], a call GetMonHeader - ld bc, (wPartyMon1MaxHP + 1) - wPartyMon1Species + ld bc, (MON_MAXHP + 1) - MON_SPECIES add hl, bc push hl ld a, [hld] @@ -181,7 +181,7 @@ GainExperience: push bc ; push max HP (from before levelling up) ld d, h ld e, l - ld bc, (wPartyMon1HPExp - 1) - wPartyMon1MaxHP + ld bc, (MON_HP_EXP - 1) - MON_MAXHP add hl, bc ld b, $1 ; consider stat exp when calculating stats call CalcStats @@ -193,15 +193,15 @@ GainExperience: ld a, [hl] sbc b ld b, a ; bc = difference between old max HP and new max HP after levelling - ld de, (wPartyMon1HP + 1) - wPartyMon1MaxHP + ld de, (MON_HP + 1) - MON_MAXHP add hl, de ; add to the current HP the amount of max HP gained when levelling - ld a, [hl] ; wPartyMon1HP + 1 + ld a, [hl] ; wPartyMon*HP + 1 add c ld [hld], a - ld a, [hl] ; wPartyMon1HP + 1 + ld a, [hl] ; wPartyMon*HP + 1 adc b - ld [hl], a ; wPartyMon1HP + ld [hl], a ; wPartyMon*HP ld a, [wPlayerMonNumber] ld b, a ld a, [wWhichPokemon] @@ -216,7 +216,7 @@ GainExperience: ld a, [hl] ld [de], a ; copy other stats from party mon to battle mon - ld bc, wPartyMon1Level - (wPartyMon1HP + 1) + ld bc, MON_LEVEL - (MON_HP + 1) add hl, bc push hl ld de, wBattleMonLevel @@ -271,7 +271,7 @@ GainExperience: cp b jr z, .done ld [wWhichPokemon], a - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld hl, wPartyMon1 call AddNTimes jp .partyMonLoop diff --git a/engine/battle/read_trainer_party.asm b/engine/battle/read_trainer_party.asm index df1132ea..1e173690 100644 --- a/engine/battle/read_trainer_party.asm +++ b/engine/battle/read_trainer_party.asm @@ -92,7 +92,7 @@ ReadTrainer: ld a, [hli] ld d, [hl] ld hl, wEnemyMon1Moves + 2 - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld [hl], d jr .FinishUp diff --git a/engine/battle/trainer_ai.asm b/engine/battle/trainer_ai.asm index 546dd60e..b9447779 100644 --- a/engine/battle/trainer_ai.asm +++ b/engine/battle/trainer_ai.asm @@ -569,7 +569,7 @@ AISwitchIfEnoughMons: inc d .Fainted push bc - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH add hl, bc pop bc dec c @@ -587,7 +587,7 @@ SwitchEnemyMon: ld a, [wEnemyMonPartyPos] ld hl, wEnemyMon1HP - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld d, h ld e, l @@ -626,7 +626,7 @@ AICureStatus: ; cures the status of enemy's active pokemon ld a, [wEnemyMonPartyPos] ld hl, wEnemyMon1Status - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes xor a ld [hl], a ; clear status in enemy team roster diff --git a/engine/events/heal_party.asm b/engine/events/heal_party.asm index e6551bcd..5532fd92 100644 --- a/engine/events/heal_party.asm +++ b/engine/events/heal_party.asm @@ -11,7 +11,7 @@ HealParty: push hl push de - ld hl, wPartyMon1Status - wPartyMon1HP + ld hl, MON_STATUS - MON_HP add hl, de xor a ld [hl], a @@ -19,7 +19,7 @@ HealParty: push de ld b, NUM_MOVES ; A Pokémon has 4 moves .pp - ld hl, wPartyMon1Moves - wPartyMon1HP + ld hl, MON_MOVES - MON_HP add hl, de ld a, [hl] @@ -27,7 +27,7 @@ HealParty: jr z, .nextmove dec a - ld hl, wPartyMon1PP - wPartyMon1HP + ld hl, MON_PP - MON_HP add hl, de push hl @@ -60,7 +60,7 @@ HealParty: jr nz, .pp pop de - ld hl, wPartyMon1MaxHP - wPartyMon1HP + ld hl, MON_MAXHP - MON_HP add hl, de ld a, [hli] ld [de], a @@ -72,7 +72,7 @@ HealParty: pop hl push hl - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld h, d ld l, e add hl, bc diff --git a/engine/events/in_game_trades.asm b/engine/events/in_game_trades.asm index 5cc251f4..3107550f 100644 --- a/engine/events/in_game_trades.asm +++ b/engine/events/in_game_trades.asm @@ -115,7 +115,7 @@ InGameTrade_DoTrade: jr nz, .tradeFailed ; jump if the selected mon's species is not the required one ld a, [wWhichPokemon] ld hl, wPartyMon1Level - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hl] ld [wCurEnemyLevel], a @@ -190,7 +190,7 @@ InGameTrade_PrepareTradeData: ld de, wLinkEnemyTrainerName call InGameTrade_CopyData ld hl, wPartyMon1OTID - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wWhichPokemon] call AddNTimes ld de, wTradedPlayerMonOTID @@ -223,7 +223,7 @@ InGameTrade_CopyDataToReceivedMon: ld bc, NAME_LENGTH call CopyData ld hl, wPartyMon1OTID - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call InGameTrade_GetReceivedMonPointer ld hl, wTradedEnemyMonOTID ld bc, 2 diff --git a/engine/events/poison.asm b/engine/events/poison.asm index beb1a312..8c3dc8b3 100644 --- a/engine/events/poison.asm +++ b/engine/events/poison.asm @@ -65,7 +65,7 @@ ApplyOutOfBattlePoisonDamage: ld a, [de] inc a jr z, .applyDamageLoopDone - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH add hl, bc push hl ld hl, wWhichPokemon @@ -82,7 +82,7 @@ ApplyOutOfBattlePoisonDamage: and 1 << PSN or e ld e, a - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH add hl, bc dec d jr nz, .countPoisonedLoop diff --git a/engine/items/item_effects.asm b/engine/items/item_effects.asm index 7fffae59..a716ebb7 100644 --- a/engine/items/item_effects.asm +++ b/engine/items/item_effects.asm @@ -834,7 +834,7 @@ ItemUseMedicine: .getPartyMonDataAddress jp c, .canceledItemUse ld hl, wPartyMons - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wWhichPokemon] call AddNTimes ld a, [wWhichPokemon] @@ -866,7 +866,7 @@ ItemUseMedicine: jr nc, .healHP ; if it's a Full Restore or one of the potions ; fall through if it's one of the status-specific healing items .cureStatusAilment - ld bc, wPartyMon1Status - wPartyMon1 + ld bc, MON_STATUS add hl, bc ; hl now points to status ld a, [wCurItem] lb bc, ANTIDOTE_MSG, 1 << PSN @@ -904,7 +904,7 @@ ItemUseMedicine: ld hl, wPlayerBattleStatus3 res BADLY_POISONED, [hl] ; heal Toxic status pop hl - ld bc, wPartyMon1Stats - wPartyMon1Status + ld bc, MON_STATS - MON_STATUS add hl, bc ; hl now points to party stats ld de, wBattleMonStats ld bc, NUM_STATS * 2 @@ -962,7 +962,7 @@ ItemUseMedicine: .compareCurrentHPToMaxHP push hl push bc - ld bc, wPartyMon1MaxHP - (wPartyMon1HP + 1) + ld bc, MON_MAXHP - (MON_HP + 1) add hl, bc ; hl now points to max HP pop bc ld a, [hli] @@ -994,7 +994,7 @@ ItemUseMedicine: ld [wChannelSoundIDs + CHAN5], a push hl push de - ld bc, wPartyMon1MaxHP - (wPartyMon1HP + 1) + ld bc, MON_MAXHP - (MON_HP + 1) add hl, bc ; hl now points to max HP ld a, [hli] ld [wHPBarMaxHP+1], a @@ -1015,7 +1015,7 @@ ItemUseMedicine: push af ld hl, wPartyMon1MaxHP ld a, [wWhichPokemon] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hli] ld [wHPBarMaxHP + 1], a @@ -1027,7 +1027,7 @@ ItemUseMedicine: ldh [hDivisor], a ld b, 2 ; number of bytes call Divide ; get 1/5 of max HP of pokemon that used Softboiled - ld bc, (wPartyMon1HP + 1) - (wPartyMon1MaxHP + 1) + ld bc, (MON_HP + 1) - (MON_MAXHP + 1) add hl, bc ; hl now points to LSB of current HP of pokemon that used Softboiled ; subtract 1/5 of max HP from current HP of pokemon that used Softboiled ldh a, [hQuotient + 3] @@ -1106,7 +1106,7 @@ ItemUseMedicine: inc hl ld d, h ld e, l ; de now points to current HP - ld hl, (wPartyMon1MaxHP + 1) - (wPartyMon1HP + 1) + ld hl, (MON_MAXHP + 1) - (MON_HP + 1) add hl, de ; hl now points to max HP ld a, [wCurItem] cp REVIVE @@ -1153,7 +1153,7 @@ ItemUseMedicine: ld a, [wCurItem] cp FULL_RESTORE jr nz, .updateInBattleData - ld bc, wPartyMon1Status - (wPartyMon1MaxHP + 1) + ld bc, MON_STATUS - (MON_MAXHP + 1) add hl, bc xor a ld [hl], a ; remove the status ailment in the party data @@ -1256,7 +1256,7 @@ ItemUseMedicine: ld a, [hl] ld [wCurSpecies], a ld [wPokedexNum], a - ld bc, wPartyMon1Level - wPartyMon1 + ld bc, MON_LEVEL add hl, bc ; hl now points to level ld a, [hl] ; a = level ld [wCurEnemyLevel], a ; store level @@ -1273,7 +1273,7 @@ ItemUseMedicine: push hl sub HP_UP add a - ld bc, wPartyMon1HPExp - wPartyMon1 + ld bc, MON_HP_EXP add hl, bc add l ld l, a @@ -1321,17 +1321,17 @@ ItemUseMedicine: call PrintText jp GBPalWhiteOut .recalculateStats - ld bc, wPartyMon1Stats - wPartyMon1 + ld bc, MON_STATS add hl, bc ld d, h ld e, l ; de now points to stats - ld bc, (wPartyMon1Exp + 2) - wPartyMon1Stats + ld bc, (MON_EXP + 2) - MON_STATS add hl, bc ; hl now points to LSB of experience ld b, 1 jp CalcStats ; recalculate stats .useRareCandy push hl - ld bc, wPartyMon1Level - wPartyMon1 + ld bc, MON_LEVEL add hl, bc ; hl now points to level ld a, [hl] ; a = level cp MAX_LEVEL @@ -1345,7 +1345,7 @@ ItemUseMedicine: callfar CalcExperience ; calculate experience for next level and store it at hExperience pop de pop hl - ld bc, wPartyMon1Exp - wPartyMon1Level + ld bc, MON_EXP - MON_LEVEL add hl, bc ; hl now points to MSB of experience ; update experience to minimum for new level ldh a, [hExperience] @@ -1361,7 +1361,7 @@ ItemUseMedicine: push af push de push hl - ld bc, wPartyMon1MaxHP - wPartyMon1 + ld bc, MON_MAXHP add hl, bc ; hl now points to MSB of max HP ld a, [hli] ld b, a @@ -1371,7 +1371,7 @@ ItemUseMedicine: push hl call .recalculateStats pop hl - ld bc, (wPartyMon1MaxHP + 1) - wPartyMon1 + ld bc, (MON_MAXHP + 1) add hl, bc ; hl now points to LSB of max HP pop bc ld a, [hld] @@ -1381,7 +1381,7 @@ ItemUseMedicine: sbc b ld b, a ; bc = the amount of max HP gained from leveling up ; add the amount gained to the current HP - ld de, (wPartyMon1HP + 1) - wPartyMon1MaxHP + ld de, (MON_HP + 1) - MON_MAXHP add hl, de ; hl now points to LSB of current HP ld a, [hl] add c @@ -1984,7 +1984,7 @@ ItemUsePPRestore: ld [wPlayerMoveListIndex], a jr nz, .chooseMon ld hl, wPartyMon1Moves - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call GetSelectedMoveOffset push hl ld a, [hl] @@ -1996,7 +1996,7 @@ ItemUsePPRestore: cp ETHER jr nc, .useEther ; if Ether or Max Ether .usePPUp - ld bc, wPartyMon1PP - wPartyMon1Moves + ld bc, MON_PP - MON_MOVES add hl, bc ld a, [hl] ; move PP cp 3 << 6 ; have 3 PP Ups already been used? @@ -2026,7 +2026,7 @@ ItemUsePPRestore: cp b ; is the pokemon whose PP was restored active in battle? jr nz, .skipUpdatingInBattleData ld hl, wPartyMon1PP - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld de, wBattleMonPP ld bc, NUM_MOVES @@ -2048,9 +2048,9 @@ ItemUsePPRestore: ld [wMonDataLocation], a call GetMaxPP ld hl, wPartyMon1Moves - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call GetSelectedMoveOffset - ld bc, wPartyMon1PP - wPartyMon1Moves + ld bc, MON_PP - MON_MOVES add hl, bc ; hl now points to move's PP ld a, [wMaxPP] ld b, a @@ -2098,7 +2098,7 @@ ItemUsePPRestore: .elixirLoop push bc ld hl, wPartyMon1Moves - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call GetSelectedMoveOffset ld a, [hl] and a ; does the current slot have a move? @@ -2195,7 +2195,7 @@ ItemUseTMHM: .chooseMon ld hl, wStringBuffer ld de, wTempMoveNameBuffer - ld bc, ITEM_NAME_LENGTH + 1 + ld bc, MOVE_NAME_LENGTH call CopyData ; save the move name because DisplayPartyMenu will overwrite it ld a, $ff ld [wUpdateSpritesEnabled], a @@ -2205,7 +2205,7 @@ ItemUseTMHM: push af ld hl, wTempMoveNameBuffer ld de, wStringBuffer - ld bc, ITEM_NAME_LENGTH + 1 + ld bc, MOVE_NAME_LENGTH call CopyData pop af jr nc, .checkIfAbleToLearnMove @@ -2375,14 +2375,14 @@ GotOffBicycleText: ; [wCurrentMenuItem] = index of move (when using a PP Up) RestoreBonusPP: ld hl, wPartyMon1Moves - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wWhichPokemon] call AddNTimes push hl ld de, wNormalMaxPPList - 1 predef LoadMovePPs ; loads the normal max PP of each of the pokemon's moves to wNormalMaxPPList pop hl - ld c, wPartyMon1PP - wPartyMon1Moves + ld c, MON_PP - MON_MOVES ld b, 0 add hl, bc ; hl now points to move 1 PP ld de, wNormalMaxPPList @@ -2468,13 +2468,13 @@ GetMaxPP: ld a, [wMonDataLocation] and a ld hl, wPartyMon1Moves - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH jr z, .sourceWithMultipleMon ld hl, wEnemyMon1Moves dec a jr z, .sourceWithMultipleMon ld hl, wBoxMon1Moves - ld bc, wBoxMon2 - wBoxMon1 + ld bc, BOXMON_STRUCT_LENGTH dec a jr z, .sourceWithMultipleMon ld hl, wDayCareMonMoves @@ -2501,7 +2501,7 @@ GetMaxPP: ld b, a ; b = normal max PP pop hl push bc - ld bc, wPartyMon1PP - wPartyMon1Moves ; PP offset if not player's in-battle pokemon data + ld bc, MON_PP - MON_MOVES ; PP offset if not player's in-battle pokemon data ld a, [wMonDataLocation] cp 4 ; player's in-battle pokemon? jr nz, .addPPOffset @@ -2645,29 +2645,33 @@ IsKeyItem_:: INCLUDE "data/items/key_items.asm" +; store the new mon in the first slot, shifting all existing box data down SendNewMonToBox: ld de, wBoxCount ld a, [de] inc a ld [de], a + ld a, [wCurPartySpecies] ld [wCurSpecies], a ld c, a -.loop +.shiftSpeciesLoop inc de ld a, [de] ld b, a ld a, c ld c, b ld [de], a - cp $ff - jr nz, .loop + cp -1 + jr nz, .shiftSpeciesLoop + call GetMonHeader ld hl, wBoxMonOT ld bc, NAME_LENGTH ld a, [wBoxCount] dec a - jr z, .skip + jr z, .skipOTshift ; if the box was empty, there is nothing to shift + dec a call AddNTimes push hl @@ -2679,7 +2683,7 @@ SendNewMonToBox: ld a, [wBoxCount] dec a ld b, a -.loop2 +.shiftMonOTLoop push bc push hl ld bc, NAME_LENGTH @@ -2691,15 +2695,18 @@ SendNewMonToBox: add hl, bc pop bc dec b - jr nz, .loop2 -.skip + jr nz, .shiftMonOTLoop + +.skipOTshift ld hl, wPlayerName - ld de, wBoxMonOT + ld de, wBoxMon1OT ld bc, NAME_LENGTH call CopyData + ld a, [wBoxCount] dec a - jr z, .skip2 + jr z, .skipNickShift + ld hl, wBoxMonNicks ld bc, NAME_LENGTH dec a @@ -2713,7 +2720,7 @@ SendNewMonToBox: ld a, [wBoxCount] dec a ld b, a -.loop3 +.shiftNickLoop push bc push hl ld bc, NAME_LENGTH @@ -2725,21 +2732,24 @@ SendNewMonToBox: add hl, bc pop bc dec b - jr nz, .loop3 -.skip2 - ld hl, wBoxMonNicks + jr nz, .shiftNickLoop + +.skipNickShift + ld hl, wBoxMon1Nick ld a, NAME_MON_SCREEN ld [wNamingScreenType], a predef AskName + ld a, [wBoxCount] dec a - jr z, .skip3 + jr z, .skipMonDataShift + ld hl, wBoxMons - ld bc, wBoxMon2 - wBoxMon1 + ld bc, BOXMON_STRUCT_LENGTH dec a call AddNTimes push hl - ld bc, wBoxMon2 - wBoxMon1 + ld bc, BOXMON_STRUCT_LENGTH add hl, bc ld d, h ld e, l @@ -2747,20 +2757,21 @@ SendNewMonToBox: ld a, [wBoxCount] dec a ld b, a -.loop4 +.shiftMonDataLoop push bc push hl - ld bc, wBoxMon2 - wBoxMon1 + ld bc, BOXMON_STRUCT_LENGTH call CopyData pop hl ld d, h ld e, l - ld bc, wBoxMon1 - wBoxMon2 + ld bc, -BOXMON_STRUCT_LENGTH add hl, bc pop bc dec b - jr nz, .loop4 -.skip3 + jr nz, .shiftMonDataLoop + +.skipMonDataShift ld a, [wEnemyMonLevel] ld [wEnemyMonBoxLevel], a ld hl, wEnemyMon @@ -2790,11 +2801,12 @@ SendNewMonToBox: inc de xor a ld b, NUM_STATS * 2 -.loop5 +.statLoop ld [de], a inc de dec b - jr nz, .loop5 + jr nz, .statLoop + ld hl, wEnemyMonDVs ld a, [hli] ld [de], a @@ -2803,12 +2815,12 @@ SendNewMonToBox: ld [de], a ld hl, wEnemyMonPP ld b, NUM_MOVES -.loop6 +.movePPLoop ld a, [hli] inc de ld [de], a dec b - jr nz, .loop6 + jr nz, .movePPLoop ret ; checks if the tile in front of the player is a shore or water tile diff --git a/engine/items/tmhm.asm b/engine/items/tmhm.asm index a11cd736..bac92f5d 100644 --- a/engine/items/tmhm.asm +++ b/engine/items/tmhm.asm @@ -2,7 +2,7 @@ CheckIfMoveIsKnown: ld a, [wWhichPokemon] ld hl, wPartyMon1Moves - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [wMoveNum] ld b, a diff --git a/engine/link/cable_club.asm b/engine/link/cable_club.asm index ea39b938..4a300164 100644 --- a/engine/link/cable_club.asm +++ b/engine/link/cable_club.asm @@ -763,9 +763,9 @@ TradeCenter_Trade: call CopyData ld hl, wPartyMon1Species ld a, [wTradingWhichPlayerMon] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes - ld bc, wPartyMon1OTID - wPartyMon1 + ld bc, MON_OTID add hl, bc ld a, [hli] ld [wTradedPlayerMonOTID], a @@ -779,9 +779,9 @@ TradeCenter_Trade: call CopyData ld hl, wEnemyMons ld a, [wTradingWhichEnemyMon] - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes - ld bc, wEnemyMon1OTID - wEnemyMon1 + ld bc, MON_OTID add hl, bc ld a, [hli] ld [wTradedEnemyMonOTID], a @@ -809,10 +809,10 @@ TradeCenter_Trade: ld [wCurPartySpecies], a ld hl, wEnemyMons ld a, c - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld de, wLoadedMon - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call CopyData call AddEnemyMonToPlayerParty ld a, [wPartyCount] diff --git a/engine/menus/naming_screen.asm b/engine/menus/naming_screen.asm index 9c0cd0a8..24b172f0 100644 --- a/engine/menus/naming_screen.asm +++ b/engine/menus/naming_screen.asm @@ -241,11 +241,11 @@ DisplayNamingScreen: cp NAME_MON_SCREEN jr nc, .checkMonNameLength ld a, [wNamingScreenNameLength] - cp $7 ; max length of player/rival names + cp PLAYER_NAME_LENGTH - 1 jr .checkNameLength .checkMonNameLength ld a, [wNamingScreenNameLength] - cp $a ; max length of pokemon nicknames + cp NAME_LENGTH - 1 .checkNameLength jr c, .addLetter ret diff --git a/engine/menus/start_sub_menus.asm b/engine/menus/start_sub_menus.asm index c27e58a9..ec10dd11 100644 --- a/engine/menus/start_sub_menus.asm +++ b/engine/menus/start_sub_menus.asm @@ -236,7 +236,7 @@ StartMenu_Pokemon:: .softboiled ld hl, wPartyMon1MaxHP ld a, [wWhichPokemon] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hli] ldh [hDividend], a @@ -246,7 +246,7 @@ StartMenu_Pokemon:: ldh [hDivisor], a ld b, 2 ; number of bytes call Divide - ld bc, wPartyMon1HP - wPartyMon1MaxHP + ld bc, MON_HP - MON_MAXHP add hl, bc ld a, [hld] ld b, a @@ -743,24 +743,24 @@ SwitchPartyMon_InitVarOrSwapData: ldh a, [hSwapTemp] ld [de], a ld hl, wPartyMons - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wCurrentMenuItem] call AddNTimes push hl ld de, wSwitchPartyMonTempBuffer - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call CopyData ld hl, wPartyMons - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wMenuItemToSwap] call AddNTimes pop de push hl - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call CopyData pop de ld hl, wSwitchPartyMonTempBuffer - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call CopyData ld hl, wPartyMonOT ld a, [wCurrentMenuItem] diff --git a/engine/menus/text_box.asm b/engine/menus/text_box.asm index 94c432c7..e618b1d0 100644 --- a/engine/menus/text_box.asm +++ b/engine/menus/text_box.asm @@ -509,7 +509,7 @@ PokemonMenuEntries: GetMonFieldMoves: ld a, [wWhichPokemon] ld hl, wPartyMon1Moves - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld d, h ld e, l diff --git a/engine/movie/hall_of_fame.asm b/engine/movie/hall_of_fame.asm index 88e777af..ec457141 100644 --- a/engine/movie/hall_of_fame.asm +++ b/engine/movie/hall_of_fame.asm @@ -49,7 +49,7 @@ AnimateHallOfFame: ld a, c ld [wHoFPartyMonIndex], a ld hl, wPartyMon1Level - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hl] ld [wHoFMonLevel], a diff --git a/engine/pokemon/add_mon.asm b/engine/pokemon/add_mon.asm index a7c201ea..455221ce 100644 --- a/engine/pokemon/add_mon.asm +++ b/engine/pokemon/add_mon.asm @@ -59,7 +59,7 @@ _AddPartyMon:: .next3 ldh a, [hNewPartyLength] dec a - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld e, l ld d, h @@ -117,12 +117,12 @@ _AddPartyMon:: .next4 push bc - ld bc, wPartyMon1DVs - wPartyMon1 + ld bc, MON_DVS add hl, bc pop bc ld [hli], a ld [hl], b ; write IVs - ld bc, (wPartyMon1HPExp - 1) - (wPartyMon1DVs + 1) + ld bc, (MON_HP_EXP - 1) - (MON_DVS + 1) add hl, bc ld a, 1 ld c, a @@ -142,7 +142,7 @@ _AddPartyMon:: inc de jr .copyMonTypesAndMoves .copyEnemyMonData - ld bc, wEnemyMon1DVs - wEnemyMon1 + ld bc, MON_DVS add hl, bc ld a, [wEnemyMonDVs] ; copy IVs from cur enemy mon ld [hli], a @@ -237,7 +237,7 @@ _AddPartyMon:: jr .done .calcFreshStats pop hl - ld bc, wPartyMon1HPExp - 1 - wPartyMon1 + ld bc, MON_HP_EXP - 1 add hl, bc ld b, $0 call CalcStats ; calculate fresh set of stats @@ -294,7 +294,7 @@ _AddEnemyMonToPlayerParty:: ld hl, wPartyMons ld a, [wPartyCount] dec a - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld e, l ld d, h @@ -379,12 +379,12 @@ _MoveMon:: ld a, [wMoveMonType] dec a ld hl, wPartyMons - ld bc, wPartyMon2 - wPartyMon1 ; $2c + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wPartyCount] jr nz, .addMonOffset ; if it's PARTY_TO_BOX ld hl, wBoxMons - ld bc, wBoxMon2 - wBoxMon1 ; $21 + ld bc, BOXMON_STRUCT_LENGTH ld a, [wBoxCount] .addMonOffset dec a @@ -396,20 +396,20 @@ _MoveMon:: ld a, [wMoveMonType] and a ld hl, wBoxMons - ld bc, wBoxMon2 - wBoxMon1 ; $21 + ld bc, BOXMON_STRUCT_LENGTH jr z, .addMonOffset2 cp DAYCARE_TO_PARTY ld hl, wDayCareMon jr z, .copyMonData ld hl, wPartyMons - ld bc, wPartyMon2 - wPartyMon1 ; $2c + ld bc, PARTYMON_STRUCT_LENGTH .addMonOffset2 ld a, [wWhichPokemon] call AddNTimes .copyMonData push hl push de - ld bc, wBoxMon2 - wBoxMon1 + ld bc, BOXMON_STRUCT_LENGTH call CopyData pop de pop hl @@ -418,7 +418,7 @@ _MoveMon:: jr z, .findOTdest cp DAYCARE_TO_PARTY jr z, .findOTdest - ld bc, wBoxMon2 - wBoxMon1 + ld bc, BOXMON_STRUCT_LENGTH add hl, bc ld a, [hl] ; hl = Level inc de @@ -493,6 +493,7 @@ _MoveMon:: jr z, .done cp PARTY_TO_DAYCARE jr z, .done + ; returning mon to party, compute level and stats push hl srl a add $2 @@ -502,13 +503,13 @@ _MoveMon:: ld a, d ld [wCurEnemyLevel], a pop hl - ld bc, wBoxMon2 - wBoxMon1 - add hl, bc + ld bc, BOXMON_STRUCT_LENGTH + add hl, bc ; hl = wPartyMon*Level ld [hli], a ld d, h ld e, l - ld bc, -18 - add hl, bc + ld bc, (MON_HP_EXP - 1) - MON_STATS + add hl, bc ; hl = wPartyMon*HPExp - 1 ld b, $1 call CalcStats .done diff --git a/engine/pokemon/bills_pc.asm b/engine/pokemon/bills_pc.asm index 0fcdedc6..09adfa37 100644 --- a/engine/pokemon/bills_pc.asm +++ b/engine/pokemon/bills_pc.asm @@ -352,11 +352,11 @@ BoxNoPCText: KnowsHMMove:: ; returns whether mon with party index [wWhichPokemon] knows an HM move ld hl, wPartyMon1Moves - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH jr .next ; unreachable ld hl, wBoxMon1Moves - ld bc, wBoxMon2 - wBoxMon1 + ld bc, BOXMON_STRUCT_LENGTH .next ld a, [wWhichPokemon] call AddNTimes diff --git a/engine/pokemon/evos_moves.asm b/engine/pokemon/evos_moves.asm index 1b92a093..794cb164 100644 --- a/engine/pokemon/evos_moves.asm +++ b/engine/pokemon/evos_moves.asm @@ -177,13 +177,13 @@ Evolution_PartyMonLoop: ; loop over party mons call CalcStats ld a, [wWhichPokemon] ld hl, wPartyMon1 - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld e, l ld d, h push hl push bc - ld bc, wPartyMon1MaxHP - wPartyMon1 + ld bc, MON_MAXHP add hl, bc ld a, [hli] ld b, a @@ -357,7 +357,7 @@ LearnMoveFromLevelUp: ; If it is not 0, this function will not work properly. ld hl, wPartyMon1Moves ld a, [wWhichPokemon] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes .next ld b, NUM_MOVES @@ -458,7 +458,7 @@ WriteMonMoves: ; shift PP as well if learning moves from day care push de - ld bc, wPartyMon1PP - (wPartyMon1Moves + 3) + ld bc, MON_PP - (MON_MOVES + 3) add hl, bc ld d, h ld e, l @@ -477,7 +477,7 @@ WriteMonMoves: ; write move PP value if learning moves from day care push hl ld a, [hl] - ld hl, wPartyMon1PP - wPartyMon1Moves + ld hl, MON_PP - MON_MOVES add hl, de push hl dec a diff --git a/engine/pokemon/learn_move.asm b/engine/pokemon/learn_move.asm index 62ffeefd..b57fedcd 100644 --- a/engine/pokemon/learn_move.asm +++ b/engine/pokemon/learn_move.asm @@ -10,7 +10,7 @@ LearnMove: DontAbandonLearning: ld hl, wPartyMon1Moves - ld bc, wPartyMon2Moves - wPartyMon1Moves + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wWhichPokemon] call AddNTimes ld d, h @@ -38,7 +38,7 @@ DontAbandonLearning: .next ld a, [wMoveNum] ld [hl], a - ld bc, wPartyMon1PP - wPartyMon1Moves + ld bc, MON_PP - MON_MOVES add hl, bc push hl push de @@ -66,7 +66,7 @@ DontAbandonLearning: ld de, wBattleMonMoves ld bc, NUM_MOVES call CopyData - ld bc, wPartyMon1PP - wPartyMon1OTID + ld bc, MON_PP - MON_OTID add hl, bc ld de, wBattleMonPP ld bc, NUM_MOVES diff --git a/engine/pokemon/load_mon_data.asm b/engine/pokemon/load_mon_data.asm index 7a39f083..d90b9cd8 100644 --- a/engine/pokemon/load_mon_data.asm +++ b/engine/pokemon/load_mon_data.asm @@ -23,7 +23,7 @@ LoadMonData_:: call GetMonHeader ld hl, wPartyMons - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wMonDataLocation] cp ENEMY_PARTY_DATA jr c, .getMonEntry @@ -33,7 +33,7 @@ LoadMonData_:: cp 2 ld hl, wBoxMons - ld bc, wBoxMon2 - wBoxMon1 + ld bc, BOXMON_STRUCT_LENGTH jr z, .getMonEntry ld hl, wDayCareMon @@ -45,5 +45,5 @@ LoadMonData_:: .copyMonData ld de, wLoadedMon - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH jp CopyData diff --git a/engine/pokemon/remove_mon.asm b/engine/pokemon/remove_mon.asm index 60ec8c27..ee47f0c8 100644 --- a/engine/pokemon/remove_mon.asm +++ b/engine/pokemon/remove_mon.asm @@ -2,15 +2,16 @@ _RemovePokemon:: ld hl, wPartyCount ld a, [wRemoveMonFromBox] and a - jr z, .usePartyCount + jr z, .gotCount ld hl, wBoxCount -.usePartyCount +.gotCount ld a, [hl] dec a ld [hli], a + ld a, [wWhichPokemon] ld c, a - ld b, $0 + ld b, 0 add hl, bc ld e, l ld d, h @@ -21,21 +22,27 @@ _RemovePokemon:: ld [hli], a inc a ; reached terminator? jr nz, .shiftMonSpeciesLoop ; if not, continue shifting species + ld hl, wPartyMonOT ld d, PARTY_LENGTH - 1 ; max number of pokemon to shift ld a, [wRemoveMonFromBox] and a - jr z, .usePartyMonOTs + jr z, .gotOTsPointer ld hl, wBoxMonOT ld d, MONS_PER_BOX - 1 -.usePartyMonOTs +.gotOTsPointer ld a, [wWhichPokemon] call SkipFixedLengthTextEntries ld a, [wWhichPokemon] cp d ; are we removing the last pokemon? jr nz, .notRemovingLastMon ; if not, shift the pokemon below - ld [hl], $ff ; else, write the terminator and return + + ; bug: to erase a string, this should be ld [hl], '@' + ; This is not needed, as wBoxSpecies/wPartySpecies determine if a slot is used. + ; Besides, existing mon nick is left untouched + ld [hl], $ff ret + .notRemovingLastMon ld d, h ld e, l @@ -44,44 +51,49 @@ _RemovePokemon:: ld bc, wPartyMonNicks ld a, [wRemoveMonFromBox] and a - jr z, .usePartyMonNicks + jr z, .gotNicksPointer ld bc, wBoxMonNicks -.usePartyMonNicks +.gotNicksPointer call CopyDataUntil + ld hl, wPartyMons - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wRemoveMonFromBox] and a - jr z, .usePartyMonStructs + jr z, .gotMonStructs ld hl, wBoxMons - ld bc, wBoxMon2 - wBoxMon1 -.usePartyMonStructs + ld bc, BOXMON_STRUCT_LENGTH +.gotMonStructs ld a, [wWhichPokemon] call AddNTimes ; get address of the pokemon removed - ld d, h ; store in de for CopyDataUntil + + ld d, h ; de = start address for CopyDataUntil ld e, l ld a, [wRemoveMonFromBox] and a - jr z, .copyUntilPartyMonOTs - ld bc, wBoxMon2 - wBoxMon1 - add hl, bc ; get address of pokemon after the pokemon removed - ld bc, wBoxMonOT ; address of when to stop copying - jr .continue -.copyUntilPartyMonOTs - ld bc, wPartyMon2 - wPartyMon1 - add hl, bc ; get address of pokemon after the pokemon removed - ld bc, wPartyMonOT ; address of when to stop copying -.continue - call CopyDataUntil ; shift all pokemon data after the removed mon to the removed mon's location + jr z, .copyUntilPartyMonOT +; copy until wBoxMonOT + ld bc, BOXMON_STRUCT_LENGTH + add hl, bc ; get address of next slot + ld bc, wBoxMonOT + jr .shiftOTs +.copyUntilPartyMonOT + ld bc, PARTYMON_STRUCT_LENGTH + add hl, bc ; get address of next slot + ld bc, wPartyMonOT +.shiftOTs + call CopyDataUntil ; shift all pokemon data up one slot + ld hl, wPartyMonNicks ld a, [wRemoveMonFromBox] and a - jr z, .usePartyMonNicks2 + jr z, .gotNicksPointer2 ld hl, wBoxMonNicks -.usePartyMonNicks2 +.gotNicksPointer2 ld bc, NAME_LENGTH ld a, [wWhichPokemon] call AddNTimes + ld d, h ld e, l ld bc, NAME_LENGTH @@ -89,7 +101,7 @@ _RemovePokemon:: ld bc, wPartyMonNicksEnd ld a, [wRemoveMonFromBox] and a - jr z, .copyUntilPartyMonNicksEnd + jr z, .shiftMonNicks ld bc, wBoxMonNicksEnd -.copyUntilPartyMonNicksEnd - jp CopyDataUntil +.shiftMonNicks + jp CopyDataUntil ; shift all pokemon nicknames up one slot diff --git a/engine/pokemon/set_types.asm b/engine/pokemon/set_types.asm index 2cf8f14c..d42c3cf3 100644 --- a/engine/pokemon/set_types.asm +++ b/engine/pokemon/set_types.asm @@ -1,7 +1,7 @@ ; updates the types of a party mon (pointed to in hl) to the ones of the mon specified in [wPokedexNum] SetPartyMonTypes: call GetPredefRegisters - ld bc, wPartyMon1Type - wPartyMon1 ; $5 + ld bc, MON_TYPE add hl, bc ld a, [wPokedexNum] ld [wCurSpecies], a diff --git a/engine/pokemon/status_screen.asm b/engine/pokemon/status_screen.asm index 80cdfb17..9c708a22 100644 --- a/engine/pokemon/status_screen.asm +++ b/engine/pokemon/status_screen.asm @@ -361,7 +361,7 @@ StatusScreen2: pop de pop hl push hl - ld bc, wPartyMon1PP - wPartyMon1Moves - 1 + ld bc, MON_PP - MON_MOVES - 1 add hl, bc ld a, [hl] and PP_MASK diff --git a/home/list_menu.asm b/home/list_menu.asm index 00b5704a..d0d3f732 100644 --- a/home/list_menu.asm +++ b/home/list_menu.asm @@ -456,7 +456,7 @@ PrintListMenuEntries:: ld [wLoadedMonLevel], a .skipCopyingLevel pop hl - ld bc, $1c + ld bc, SCREEN_WIDTH + 8 ; 1 row down and 8 columns right add hl, bc call PrintLevel pop af diff --git a/home/move_mon.asm b/home/move_mon.asm index 45b10322..cb19d0e3 100644 --- a/home/move_mon.asm +++ b/home/move_mon.asm @@ -94,7 +94,7 @@ CalcStat:: srl c pop hl push bc - ld bc, wPartyMon1DVs - (wPartyMon1HPExp - 1) ; also wEnemyMonDVs - wEnemyMonHP + ld bc, MON_DVS - (MON_HP_EXP - 1) add hl, bc pop bc ld a, c diff --git a/macros/ram.asm b/macros/ram.asm index 61358434..5f7c5228 100644 --- a/macros/ram.asm +++ b/macros/ram.asm @@ -4,8 +4,6 @@ MACRO? flag_array ds ((\1) + 7) / 8 ENDM -DEF BOX_STRUCT_LENGTH EQU 25 + NUM_MOVES * 2 - MACRO box_struct \1Species:: db \1HP:: dw diff --git a/ram/wram.asm b/ram/wram.asm index 0b00d272..fff7f703 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -1212,7 +1212,7 @@ wTrainerPicPointer:: dw ds 1 UNION -wTempMoveNameBuffer:: ds ITEM_NAME_LENGTH + 1 +wTempMoveNameBuffer:: ds MOVE_NAME_LENGTH NEXTU ; The name of the mon that is learning a move. @@ -1274,6 +1274,7 @@ wCriticalHitOrOHKO:: db wMoveMissed:: db +wBattleStatusData:: ; always 0 wPlayerStatsToDouble:: db ; always 0 @@ -1331,6 +1332,7 @@ wPlayerNumHits:: db ENDU ds 2 +wBattleStatusDataEnd:: ; non-zero when an item or move that allows escape from battle was used wEscapedFromBattle:: db @@ -1560,7 +1562,8 @@ wMoves:: ds NUM_MOVES wMoveNum:: db -wMovesString:: ds 56 +; concatenated move name list where intermediate '@' are replaced with '' +wMovesString:: ds NUM_MOVES * MOVE_NAME_LENGTH wUnusedCurMapTilesetCopy:: db diff --git a/scripts/Daycare.asm b/scripts/Daycare.asm index 05b69935..f7354e37 100644 --- a/scripts/Daycare.asm +++ b/scripts/Daycare.asm @@ -173,7 +173,7 @@ DaycareGentlemanText: ld a, [wPartyCount] dec a push af - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH push bc ld hl, wPartyMon1Moves call AddNTimes @@ -190,7 +190,7 @@ DaycareGentlemanText: call AddNTimes ld d, h ld e, l - ld bc, wPartyMon1MaxHP - wPartyMon1HP + ld bc, MON_MAXHP - MON_HP add hl, bc ld a, [hli] ld [de], a diff --git a/scripts/NameRatersHouse.asm b/scripts/NameRatersHouse.asm index 61b10a3e..b1e3bf95 100644 --- a/scripts/NameRatersHouse.asm +++ b/scripts/NameRatersHouse.asm @@ -19,7 +19,7 @@ NameRatersHouseCheckMonOTScript: call .check_match_loop jr c, .no_match ld hl, wPartyMon1OTID - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wWhichPokemon] call AddNTimes ld de, wPlayerID -- cgit v1.3.1-sl0p From 8bb03542bd0dd01b1e4fce990751edc0822a878f Mon Sep 17 00:00:00 2001 From: Narishma-gb <194818981+Narishma-gb@users.noreply.github.com> Date: Mon, 1 Dec 2025 20:46:28 +0100 Subject: Update `StatusScreen`, add `*_STATS_BOX` constants (#546) --- constants/menu_constants.asm | 5 +++ engine/battle/experience.asm | 2 +- engine/items/item_effects.asm | 22 ++++++------- engine/pokemon/status_screen.asm | 70 ++++++++++++++++++---------------------- home/pics.asm | 4 +-- 5 files changed, 51 insertions(+), 52 deletions(-) (limited to 'engine/items') diff --git a/constants/menu_constants.asm b/constants/menu_constants.asm index a6e035e7..c4476e03 100644 --- a/constants/menu_constants.asm +++ b/constants/menu_constants.asm @@ -90,3 +90,8 @@ DEF FIRST_PARTY_MENU_TEXT_ID EQU const_value const NAME_PLAYER_SCREEN ; 0 const NAME_RIVAL_SCREEN ; 1 const NAME_MON_SCREEN ; 2 + +; Stats box layout (see engine/pokemon/status_screen.asm) + const_def + const STATUS_SCREEN_STATS_BOX ; 0 + const LEVEL_UP_STATS_BOX ; 1 diff --git a/engine/battle/experience.asm b/engine/battle/experience.asm index 4e44643c..f9f47f82 100644 --- a/engine/battle/experience.asm +++ b/engine/battle/experience.asm @@ -245,7 +245,7 @@ GainExperience: xor a ; PLAYER_PARTY_DATA ld [wMonDataLocation], a call LoadMonData - ld d, $1 + ld d, LEVEL_UP_STATS_BOX callfar PrintStatsBox call WaitForTextScrollButtonPress call LoadScreenTilesFromBuffer1 diff --git a/engine/items/item_effects.asm b/engine/items/item_effects.asm index a716ebb7..90853bee 100644 --- a/engine/items/item_effects.asm +++ b/engine/items/item_effects.asm @@ -1400,15 +1400,15 @@ ItemUseMedicine: xor a ; PLAYER_PARTY_DATA ld [wMonDataLocation], a call LoadMonData - ld d, $01 - callfar PrintStatsBox ; display new stats text box - call WaitForTextScrollButtonPress ; wait for button press + ld d, LEVEL_UP_STATS_BOX + callfar PrintStatsBox + call WaitForTextScrollButtonPress xor a ; PLAYER_PARTY_DATA ld [wMonDataLocation], a - predef LearnMoveFromLevelUp ; learn level up move, if any + predef LearnMoveFromLevelUp xor a ld [wForceEvolution], a - callfar TryEvolvingMon ; evolve pokemon, if appropriate + callfar TryEvolvingMon ld a, $01 ld [wUpdateSpritesEnabled], a pop af @@ -1433,11 +1433,11 @@ INCLUDE "data/battle/stat_names.asm" ItemUseBait: ld hl, ThrewBaitText call PrintText - ld hl, wEnemyMonActualCatchRate ; catch rate + ld hl, wEnemyMonActualCatchRate srl [hl] ; halve catch rate ld a, BAIT_ANIM - ld hl, wSafariBaitFactor ; bait factor - ld de, wSafariEscapeFactor ; escape factor + ld hl, wSafariBaitFactor + ld de, wSafariEscapeFactor jr BaitRockCommon ; for CASCADEBADGE when used from the @@ -1446,7 +1446,7 @@ ItemUseBait: ItemUseRock: ld hl, ThrewRockText call PrintText - ld hl, wEnemyMonActualCatchRate ; catch rate + ld hl, wEnemyMonActualCatchRate ld a, [hl] add a ; double catch rate jr nc, .noCarry @@ -1454,8 +1454,8 @@ ItemUseRock: .noCarry ld [hl], a ld a, ROCK_ANIM - ld hl, wSafariEscapeFactor ; escape factor - ld de, wSafariBaitFactor ; bait factor + ld hl, wSafariEscapeFactor + ld de, wSafariBaitFactor BaitRockCommon: ld [wAnimationID], a diff --git a/engine/pokemon/status_screen.asm b/engine/pokemon/status_screen.asm index 9c708a22..84a56d5a 100644 --- a/engine/pokemon/status_screen.asm +++ b/engine/pokemon/status_screen.asm @@ -61,8 +61,6 @@ DrawHP_: pop de ret - -; Predef 0x37 StatusScreen: call LoadMonData ld a, [wMonDataLocation] @@ -75,7 +73,7 @@ StatusScreen: ld hl, wLoadedMonHPExp - 1 ld de, wLoadedMonStats ld b, $1 - call CalcStats ; Recalculate stats + call CalcStats .DontRecalculate ld hl, wStatusFlags2 set BIT_NO_AUDIO_FADE_OUT, [hl] @@ -117,8 +115,8 @@ StatusScreen: lb bc, 8, 6 call DrawLineBox ; Draws the box around types, ID No. and OT hlcoord 10, 9 - ld de, Type1Text - call PlaceString ; "TYPE1/" + ld de, TypesIDNoOTText + call PlaceString hlcoord 11, 3 predef DrawHP ld hl, wStatusScreenHPBarColor @@ -137,7 +135,7 @@ StatusScreen: ld de, StatusText call PlaceString ; "STATUS/" hlcoord 14, 2 - call PrintLevel ; Pokémon level + call PrintLevel ld a, [wMonHIndex] ld [wPokedexNum], a ld [wCurSpecies], a @@ -164,7 +162,7 @@ StatusScreen: ld de, wLoadedMonOTID lb bc, LEADING_ZEROES | 2, 5 call PrintNumber ; ID Number - ld d, $0 + ld d, STATUS_SCREEN_STATS_BOX call PrintStatsBox call Delay3 call GBPalNormal @@ -204,20 +202,11 @@ NamePointers2: dw wBoxMonNicks dw wDayCareMonName -Type1Text: +TypesIDNoOTText: db "TYPE1/" - next "" - ; fallthrough -Type2Text: - db "TYPE2/" - next "" - ; fallthrough -IDNoText: - db "№/" - next "" - ; fallthrough -OTText: - db "OT/" + next "TYPE2/" + next "№/" + next "OT/" next "@" StatusText: @@ -248,40 +237,42 @@ PTile: INCBIN "gfx/font/P.1bpp" PrintStatsBox: ld a, d - and a ; a is 0 from the status screen - jr nz, .DifferentBox + ASSERT STATUS_SCREEN_STATS_BOX == 0 + and a + jr nz, .LevelUpStatsBox ; battle or Rare Candy hlcoord 0, 8 ld b, 8 ld c, 8 - call TextBoxBorder ; Draws the box - hlcoord 1, 9 ; Start printing stats from here - ld bc, $19 ; Number offset + call TextBoxBorder + hlcoord 1, 9 + ld bc, SCREEN_WIDTH + 5 ; one row down and 5 columns right jr .PrintStats -.DifferentBox +.LevelUpStatsBox hlcoord 9, 2 ld b, 8 ld c, 9 call TextBoxBorder hlcoord 11, 3 - ld bc, $18 + ld bc, SCREEN_WIDTH + 4 ; one row down and 4 columns right .PrintStats push bc push hl - ld de, StatsText + ld de, .StatsText call PlaceString pop hl pop bc add hl, bc ld de, wLoadedMonAttack lb bc, 2, 3 - call PrintStat + call .PrintStat ld de, wLoadedMonDefense - call PrintStat + call .PrintStat ld de, wLoadedMonSpeed - call PrintStat + call .PrintStat ld de, wLoadedMonSpecial jp PrintNumber -PrintStat: + +.PrintStat: push hl call PrintNumber pop hl @@ -289,7 +280,7 @@ PrintStat: add hl, de ret -StatsText: +.StatsText: db "ATTACK" next "DEFENSE" next "SPEED" @@ -323,10 +314,10 @@ StatusScreen2: call PlaceString ; Print moves ld a, [wNumMovesMinusOne] inc a - ld c, a - ld a, $4 + ld c, a ; number of known moves + ld a, NUM_MOVES sub c - ld b, a ; Number of moves ? + ld b, a ; number of blank moves hlcoord 11, 10 ld de, SCREEN_WIDTH * 2 ld a, '' @@ -386,7 +377,7 @@ StatusScreen2: pop bc inc b ld a, b - cp $4 + cp NUM_MOVES jr nz, .PrintPP .PPDone hlcoord 9, 3 @@ -415,8 +406,11 @@ StatusScreen2: hlcoord 7, 6 lb bc, 3, 7 call PrintNumber ; exp needed to level up + + ; unneeded, this clears the diacritic characters in JPN versions hlcoord 9, 0 call StatusScreen_ClearName + hlcoord 9, 1 call StatusScreen_ClearName ld a, [wMonHIndex] @@ -468,7 +462,7 @@ StatusScreenExpText: next "LEVEL UP@" StatusScreen_ClearName: - ld bc, 10 + ld bc, NAME_LENGTH - 1 ld a, ' ' jp FillMemory diff --git a/home/pics.asm b/home/pics.asm index 475e834d..5ebb8f82 100644 --- a/home/pics.asm +++ b/home/pics.asm @@ -188,9 +188,9 @@ InterlaceMergeSpriteBuffers:: or c jr nz, .swapLoop .notFlipped - pop hl + pop hl ; hl = output address ld de, sSpriteBuffer1 - ld c, (2 * SPRITEBUFFERSIZE) / TILE_SIZE ; $31, number of 16 byte chunks to be copied + ld c, PIC_SIZE ; tiles ldh a, [hLoadedROMBank] ld b, a jp CopyVideoData -- cgit v1.3.1-sl0p From e9d3324bc06faa7de3b7a35d1f9429e610e8a761 Mon Sep 17 00:00:00 2001 From: Narishma-gb <194818981+Narishma-gb@users.noreply.github.com> Date: Mon, 15 Dec 2025 21:14:17 +0100 Subject: Comment more unreferenced local labels (#550) --- engine/battle/animations.asm | 18 +++++++------- engine/battle/core.asm | 39 ++++++++++++++++--------------- engine/battle/draw_hud_pokeball_gfx.asm | 2 +- engine/battle/effects.asm | 12 ++++++---- engine/battle/ghost_marowak_anim.asm | 2 +- engine/battle/move_effects/substitute.asm | 4 ++-- engine/battle/move_effects/transform.asm | 5 ++++ engine/events/diploma.asm | 4 ++-- engine/events/pokemart.asm | 4 ++-- engine/events/prize_menu.asm | 14 +++++------ engine/flag_action.asm | 4 ++-- engine/items/inventory.asm | 1 - engine/items/item_effects.asm | 18 +++++++------- engine/link/cable_club.asm | 2 +- engine/menus/main_menu.asm | 7 +++--- engine/menus/naming_screen.asm | 36 ++++++++++++++-------------- engine/menus/party_menu.asm | 4 ++-- engine/menus/pokedex.asm | 14 +++++------ engine/menus/start_sub_menus.asm | 6 ++--- engine/menus/swap_items.asm | 2 +- engine/movie/credits.asm | 21 ++++++++++------- engine/overworld/auto_movement.asm | 4 ++-- engine/overworld/missable_objects.asm | 4 ++-- engine/overworld/movement.asm | 11 +++++---- engine/overworld/pathfinding.asm | 4 ++-- engine/overworld/push_boulder.asm | 2 +- engine/pokemon/add_mon.asm | 4 ++-- engine/pokemon/load_mon_data.asm | 2 +- home/joypad2.asm | 4 ++-- home/list_menu.asm | 14 +++++------ home/load_font.asm | 6 ++--- home/map_objects.asm | 4 ++-- home/move_mon.asm | 2 +- home/overworld.asm | 9 ++++--- home/print_bcd.asm | 4 ++-- home/print_num.asm | 17 +++++++++----- home/print_text.asm | 2 +- home/start_menu.asm | 2 +- home/trainers.asm | 24 +++++++++---------- home/window.asm | 12 +++++----- macros/scripts/events.asm | 2 +- scripts/BillsHouse.asm | 4 ++-- scripts/Colosseum.asm | 1 + 43 files changed, 189 insertions(+), 168 deletions(-) (limited to 'engine/items') diff --git a/engine/battle/animations.asm b/engine/battle/animations.asm index f66be640..eac4115a 100644 --- a/engine/battle/animations.asm +++ b/engine/battle/animations.asm @@ -22,7 +22,7 @@ DrawFrameBlock: jp z, .flipHorizontalTranslateDown ; SUBANIMTYPE_HFLIP dec a jr z, .flipBaseCoords ; SUBANIMTYPE_COORDFLIP -.noTransformation +; no transformation ld a, [wBaseCoordY] add [hl] ld [de], a ; store Y @@ -130,7 +130,7 @@ DrawFrameBlock: ld a, [wNumFBTiles] cp c jp nz, .loop ; go back up if there are more tiles to draw -.afterDrawingTiles +; after drawing tiles ld a, [wFBMode] cp FRAMEBLOCKMODE_02 jr z, .advanceFrameBlockDestAddr ; skip delay and don't clean OAM buffer @@ -185,7 +185,7 @@ PlayAnimation: jr z, .AnimationOver cp FIRST_SE_ID ; is this subanimation or a special effect? jr c, .playSubanimation -.doSpecialEffect +; do Special Effect ld c, a ld de, SpecialEffectPointers .searchSpecialEffectTableLoop @@ -295,11 +295,11 @@ LoadSubanimation: and %11100000 cp SUBANIMTYPE_ENEMY << 5 vc_hook_blue Reduce_move_anim_flashing_Blizzard - jr nz, .isNotType5 -.isType5 + jr nz, .isNotTypeEnemy +; subanim type enemy call GetSubanimationTransform2 jr .saveTransformation -.isNotType5 +.isNotTypeEnemy vc_hook Reduce_move_anim_flashing_Hyper_Beam call GetSubanimationTransform1 .saveTransformation @@ -427,11 +427,11 @@ MoveAnimation: call PlayAnimation vc_hook_red Stop_reducing_move_anim_flashing_Bubblebeam_Mega_Kick vc_hook_blue Stop_reducing_move_anim_flashing_Spore - jr .next4 + jr .next .animationsDisabled ld c, 30 call DelayFrames -.next4 +.next vc_hook_red Stop_reducing_move_anim_flashing vc_hook_blue Stop_reducing_move_anim_flashing_Rock_Slide_Dream_Eater call PlayApplyingAttackAnimation ; shake the screen or flash the pic in and out (to show damage) @@ -1097,6 +1097,8 @@ SetAnimationBGPalette: ldh [rBGP], a ret +AnimationUnusedShakeScreen: ; unreferenced +; Shakes the screen for a while. ld b, $5 AnimationShakeScreenVertically: diff --git a/engine/battle/core.asm b/engine/battle/core.asm index 44fd9a70..dd9fbc71 100644 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -1247,7 +1247,7 @@ SlideTrainerPicOffScreen: ldh a, [hSlideAmount] cp 8 jr z, .slideRight -.slideLeft ; slide player sprite off screen +; slide player sprite left off screen ld a, [hld] ld [hli], a inc hl @@ -3557,11 +3557,12 @@ CheckPlayerStatusConditions: ld hl, AttackContinuesText call PrintText ld a, [wPlayerNumAttacksLeft] - dec a ; did multi-turn move end? + dec a ld [wPlayerNumAttacksLeft], a - ld hl, GetPlayerAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit), - ; DecrementPP and MoveHitTest - jp nz, .returnToHL + ld hl, GetPlayerAnimationType ; skip damage calculation (deal damage equal to last hit), + ; DecrementPP and MoveHitTest + jp nz, .returnToHL ; redundant leftover code, the case wEnemyNumAttacksLeft == 0 + ; is handled within CheckNumAttacksLeft jp .returnToHL .RageCheck @@ -3626,7 +3627,7 @@ ConfusedNoMoreText: text_far _ConfusedNoMoreText text_end -SavingEnergyText: +SavingEnergyText: ; unreferenced text_far _SavingEnergyText text_end @@ -4171,7 +4172,7 @@ GetDamageVarsForPlayerAttack: ld a, [hl] ; a = [wPlayerMoveType] cp SPECIAL ; types >= SPECIAL are all special jr nc, .specialAttack -.physicalAttack +; physical attack ld hl, wEnemyMonDefense ld a, [hli] ld b, a @@ -4284,7 +4285,7 @@ GetDamageVarsForEnemyAttack: ld a, [hl] ; a = [wEnemyMoveType] cp SPECIAL ; types >= SPECIAL are all special jr nc, .specialAttack -.physicalAttack +; physical attack ld hl, wBattleMonDefense ld a, [hli] ld b, a @@ -5301,7 +5302,6 @@ AdjustDamageForMoveType: ld [hl], a or b ; is damage 0? jr nz, .skipTypeImmunity -.typeImmunity ; if damage is 0, make the move miss ; this only occurs if a move that would do 2 or 3 damage is 0.25x effective against the target inc a @@ -5394,7 +5394,7 @@ MoveHitTest: ldh a, [hWhoseTurn] and a jr nz, .enemyTurn -.playerTurn +; player's turn ; this checks if the move effect is disallowed by mist ld a, [wPlayerMoveEffect] cp ATTACK_DOWN1_EFFECT @@ -5466,12 +5466,12 @@ MoveHitTest: ld [wMoveMissed], a ldh a, [hWhoseTurn] and a - jr z, .playerTurn2 -.enemyTurn2 + jr z, .playerTurn +; enemy's turn ld hl, wEnemyBattleStatus1 res USING_TRAPPING_MOVE, [hl] ; end multi-turn attack e.g. wrap ret -.playerTurn2 +.playerTurn ld hl, wPlayerBattleStatus1 res USING_TRAPPING_MOVE, [hl] ; end multi-turn attack e.g. wrap ret @@ -6063,10 +6063,11 @@ CheckEnemyStatusConditions: ld hl, AttackContinuesText call PrintText ld hl, wEnemyNumAttacksLeft - dec [hl] ; did multi-turn move end? - ld hl, GetEnemyAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit), + dec [hl] + ld hl, GetEnemyAnimationType ; skip damage calculation (deal damage equal to last hit), ; DecrementPP and MoveHitTest - jp nz, .enemyReturnToHL + jp nz, .enemyReturnToHL ; redundant leftover code, the case wEnemyNumAttacksLeft == 0 + ; is handled within CheckNumAttacksLeft jp .enemyReturnToHL .checkIfUsingRage ld a, [wEnemyBattleStatus2] @@ -6415,7 +6416,7 @@ QuarterSpeedDueToParalysis: ldh a, [hWhoseTurn] and a jr z, .playerTurn -.enemyTurn ; quarter the player's speed +; enemy's turn, quarter the player's speed ld a, [wBattleMonStatus] and 1 << PAR ret z ; return if player not paralysed @@ -6458,7 +6459,7 @@ HalveAttackDueToBurn: ldh a, [hWhoseTurn] and a jr z, .playerTurn -.enemyTurn ; halve the player's attack +; enemy's turn, halve the player's attack ld a, [wBattleMonStatus] and 1 << BRN ret z ; return if player not burnt @@ -6642,7 +6643,7 @@ LoadHudTilePatterns: ldh a, [rLCDC] add a ; is LCD disabled? jr c, .lcdEnabled -.lcdDisabled +; LCD disabled ld hl, BattleHudTiles1 ld de, vChars2 tile $6d ld bc, BattleHudTiles1End - BattleHudTiles1 diff --git a/engine/battle/draw_hud_pokeball_gfx.asm b/engine/battle/draw_hud_pokeball_gfx.asm index 768a6e20..adeaaf62 100644 --- a/engine/battle/draw_hud_pokeball_gfx.asm +++ b/engine/battle/draw_hud_pokeball_gfx.asm @@ -18,7 +18,7 @@ LoadPartyPokeballGfx: SetupOwnPartyPokeballs: call PlacePlayerHUDTiles - ld hl, wPartyMon1 + ld hl, wPartyMons ld de, wPartyCount call SetupPokeballs ld a, $60 diff --git a/engine/battle/effects.asm b/engine/battle/effects.asm index 2cef2521..22765140 100644 --- a/engine/battle/effects.asm +++ b/engine/battle/effects.asm @@ -230,7 +230,7 @@ FreezeBurnParalyzeEffect: jr z, .burn1 cp FREEZE_SIDE_EFFECT1 jr z, .freeze1 -; .paralyze1 +; paralyze1 ld a, 1 << PAR ld [wEnemyMonStatus], a call QuarterSpeedDueToParalysis ; quarter speed of affected mon @@ -283,7 +283,7 @@ FreezeBurnParalyzeEffect: jr z, .burn2 cp FREEZE_SIDE_EFFECT1 jr z, .freeze2 -; .paralyze2 +; paralyze2 ld a, 1 << PAR ld [wBattleMonStatus], a call QuarterSpeedDueToParalysis @@ -593,7 +593,7 @@ StatModifierDownEffect: ld a, [de] cp ATTACK_DOWN2_EFFECT - $16 ; $24 jr c, .ok - cp EVASION_DOWN2_EFFECT + $5 ; $44 + cp ATTACK_DOWN_SIDE_EFFECT ; move side effects, stat mod decrease is always 1 jr nc, .ok dec b ; stat down 2 effects only (dec mod again) jr nz, .ok @@ -711,7 +711,7 @@ CantLowerAnymore: MoveMissed: ld a, [de] - cp $44 + cp ATTACK_DOWN_SIDE_EFFECT ret nc jp ConditionalPrintButItFailed @@ -1321,7 +1321,7 @@ DisableEffect: cp LINK_STATE_BATTLING pop hl ; wEnemyMonMoves jr nz, .playerTurnNotLinkBattle -; .playerTurnLinkBattle +; player's turn, Link Battle push hl ld hl, wEnemyMonPP .enemyTurn @@ -1456,6 +1456,7 @@ PlayCurrentMoveAnimation2: .notEnemyTurn and a ret z +; fallthrough PlayBattleAnimation2: ; play animation ID at a and animation type 6 or 3 @@ -1482,6 +1483,7 @@ PlayCurrentMoveAnimation: .notEnemyTurn and a ret z +; fallthrough PlayBattleAnimation: ; play animation ID at a and predefined animation type diff --git a/engine/battle/ghost_marowak_anim.asm b/engine/battle/ghost_marowak_anim.asm index 1040f85f..efda9f8f 100644 --- a/engine/battle/ghost_marowak_anim.asm +++ b/engine/battle/ghost_marowak_anim.asm @@ -48,7 +48,7 @@ MarowakAnim: call Delay3 jp ClearSprites -; copies a mon pic's from background VRAM to sprite VRAM and sets up OAM +; copies a mon pic's from background VRAM to sprite VRAM and sets up OAM CopyMonPicFromBGToSpriteVRAM: ld de, vFrontPic ld hl, vSprites diff --git a/engine/battle/move_effects/substitute.asm b/engine/battle/move_effects/substitute.asm index e4311209..01d5a8a3 100644 --- a/engine/battle/move_effects/substitute.asm +++ b/engine/battle/move_effects/substitute.asm @@ -37,8 +37,8 @@ SubstituteEffect_: sbc 0 pop bc jr c, .notEnoughHP ; underflow means user would be left with negative health - ; bug: since it only branches on carry, it will possibly leave user with 0 HP -.userHasZeroOrMoreHP + ; bug: since it only branches on carry, it will possibly leave user with 0 HP +; user has 0 or more HP ld [hli], a ; save resulting HP after subtraction into current HP ld [hl], d ld h, b diff --git a/engine/battle/move_effects/transform.asm b/engine/battle/move_effects/transform.asm index 343fa3ca..95e17833 100644 --- a/engine/battle/move_effects/transform.asm +++ b/engine/battle/move_effects/transform.asm @@ -2,17 +2,22 @@ TransformEffect_: ld hl, wBattleMonSpecies ld de, wEnemyMonSpecies ld bc, wEnemyBattleStatus3 + ; bug: on enemy's turn, a is overloaded with hWhoseTurn, + ; before the check for INVULNERABLE ld a, [wEnemyBattleStatus1] ldh a, [hWhoseTurn] and a jr nz, .hitTest +; player's turn ld hl, wEnemyMonSpecies ld de, wBattleMonSpecies ld bc, wPlayerBattleStatus3 ld [wPlayerMoveListIndex], a + ; bug: this should be target's BattleStatus1 (i.e. wEnemyBattleStatus1) ld a, [wPlayerBattleStatus1] .hitTest bit INVULNERABLE, a ; is mon invulnerable to typical attacks? (fly/dig) + ; this check doesn't work due to above bugs jp nz, .failed push hl push de diff --git a/engine/events/diploma.asm b/engine/events/diploma.asm index 3d181210..e2a34a3b 100644 --- a/engine/events/diploma.asm +++ b/engine/events/diploma.asm @@ -73,8 +73,8 @@ DisplayDiploma:: jp GBPalNormal UnusedPlayerNameLengthFunc: -; Unused function that does a calculation involving the length of the player's -; name. +; Unused function that performs bc = -(player name's length) +; leftover from the JPN versions ld hl, wPlayerName lb bc, $ff, $00 .loop diff --git a/engine/events/pokemart.asm b/engine/events/pokemart.asm index b280c711..cb25ab4c 100644 --- a/engine/events/pokemart.asm +++ b/engine/events/pokemart.asm @@ -99,7 +99,7 @@ DisplayPokemartDialogue_:: dec a jr z, .sellMenuLoop -.sellItem +; sell item ld a, [wBoughtOrSoldItemInMart] and a jr nz, .skipSettingFlag1 @@ -177,7 +177,7 @@ DisplayPokemartDialogue_:: dec a jr z, .buyMenuLoop -.buyItem +; buy item call .isThereEnoughMoney jr c, .notEnoughMoney ld hl, wNumBagItems diff --git a/engine/events/prize_menu.asm b/engine/events/prize_menu.asm index 15b991ed..1f71af42 100644 --- a/engine/events/prize_menu.asm +++ b/engine/events/prize_menu.asm @@ -195,7 +195,7 @@ HandlePrizeChoice: .getMonName call GetMonName .givePrize - ld hl, SoYouWantPrizeTextPtr + ld hl, SoYouWantPrizeText call PrintText call YesNoChoice ld a, [wCurrentMenuItem] ; yes/no answer (Y=0, N=1) @@ -243,25 +243,25 @@ HandlePrizeChoice: predef SubBCDPredef jp PrintPrizePrice .bagFull - ld hl, PrizeRoomBagIsFullTextPtr + ld hl, PrizeRoomBagIsFullText jp PrintText .notEnoughCoins ld hl, SorryNeedMoreCoinsText jp PrintText .printOhFineThen - ld hl, OhFineThenTextPtr + ld hl, OhFineThenText jp PrintText UnknownPrizeData: ; XXX what's this? db $00,$01,$00,$01,$00,$01,$00,$00,$01 -HereYouGoTextPtr: +HereYouGoText: ; unreferenced text_far _HereYouGoText text_waitbutton text_end -SoYouWantPrizeTextPtr: +SoYouWantPrizeText: text_far _SoYouWantPrizeText text_end @@ -270,12 +270,12 @@ SorryNeedMoreCoinsText: text_waitbutton text_end -PrizeRoomBagIsFullTextPtr: +PrizeRoomBagIsFullText: text_far _OopsYouDontHaveEnoughRoomText text_waitbutton text_end -OhFineThenTextPtr: +OhFineThenText: text_far _OhFineThenText text_waitbutton text_end diff --git a/engine/flag_action.asm b/engine/flag_action.asm index dc516887..150bebab 100644 --- a/engine/flag_action.asm +++ b/engine/flag_action.asm @@ -43,10 +43,10 @@ FlagAction: ld a, b and a jr z, .reset - cp 2 + cp FLAG_TEST jr z, .read -.set +; set ld b, [hl] ld a, d or b diff --git a/engine/items/inventory.asm b/engine/items/inventory.asm index 6ac75ec7..84950a4e 100644 --- a/engine/items/inventory.asm +++ b/engine/items/inventory.asm @@ -118,7 +118,6 @@ RemoveItemFromInventory_:: jr nz, .skipMovingUpSlots ; if the remaining quantity is 0, ; remove the emptied item slot and move up all the following item slots -.moveSlotsUp ld e, l ld d, h inc de diff --git a/engine/items/item_effects.asm b/engine/items/item_effects.asm index 90853bee..12b5bd00 100644 --- a/engine/items/item_effects.asm +++ b/engine/items/item_effects.asm @@ -156,7 +156,7 @@ ItemUseBall: dec a jr nz, .notOldManBattle -.oldManBattle +; Old Man battle ld hl, wGrassRate ld de, wPlayerName ld bc, NAME_LENGTH @@ -645,7 +645,7 @@ ItemUseBicycle: jp z, ItemUseNotTime dec a ; is player already bicycling? jr nz, .tryToGetOnBike -.getOffBike +; get off bike call ItemUseReloadOverworldData xor a ld [wWalkBikeSurfState], a ; change player state to walking @@ -671,13 +671,13 @@ ItemUseSurfboard: ld [wWalkBikeSurfStateCopy], a cp 2 ; is the player already surfing? jr z, .tryToStopSurfing -.tryToSurf +; try to Surf call IsNextTileShoreOrWater jp c, SurfingAttemptFailed ld hl, TilePairCollisionsWater call CheckForTilePairCollisions jp c, SurfingAttemptFailed -.surf +; surfing call .makePlayerMoveForward ld hl, wStatusFlags5 set BIT_SCRIPTED_MOVEMENT_STATE, [hl] @@ -921,7 +921,7 @@ ItemUseMedicine: ld [wHPBarOldHP], a ; current HP stored at wHPBarOldHP (2 bytes, big-endian) or b jr nz, .notFainted -.fainted +; fainted ld a, [wCurItem] cp REVIVE jr z, .updateInBattleFaintedData @@ -973,7 +973,7 @@ ItemUseMedicine: .skipComparingLSB pop hl jr nz, .notFullHP -.fullHP ; if the pokemon's current HP equals its max HP +; if the pokemon's current HP equals its max HP ld a, [wCurItem] cp FULL_RESTORE jp nz, .healingItemNoEffect @@ -1753,8 +1753,8 @@ ItemUsePokeFlute: ; OUTPUT: ; [wWereAnyMonsAsleep]: set to 1 if any pokemon were asleep WakeUpEntireParty: - ld de, 44 - ld c, 6 + ld de, PARTYMON_STRUCT_LENGTH + ld c, PARTY_LENGTH .loop ld a, [hl] push af @@ -1995,7 +1995,7 @@ ItemUsePPRestore: ld a, [wPPRestoreItem] cp ETHER jr nc, .useEther ; if Ether or Max Ether -.usePPUp +; use PP Up ld bc, MON_PP - MON_MOVES add hl, bc ld a, [hl] ; move PP diff --git a/engine/link/cable_club.asm b/engine/link/cable_club.asm index 4a300164..6ffb2aea 100644 --- a/engine/link/cable_club.asm +++ b/engine/link/cable_club.asm @@ -673,7 +673,7 @@ TradeCenter_PrintPartyListNames: pop de inc de pop hl - ld bc, 20 + ld bc, SCREEN_WIDTH add hl, bc pop bc inc c diff --git a/engine/menus/main_menu.asm b/engine/menus/main_menu.asm index f4d8ec03..84af085f 100644 --- a/engine/menus/main_menu.asm +++ b/engine/menus/main_menu.asm @@ -495,6 +495,7 @@ DisplayOptionMenu: jr nz, .exitMenu bit B_PAD_A, b jr z, .checkDirectionKeys +; A was pressed ld a, [wTopMenuItemY] cp 16 ; is the cursor on Cancel? jr nz, .loop @@ -518,7 +519,7 @@ DisplayOptionMenu: jr z, .cursorInBattleStyle cp 16 ; cursor on Cancel? jr z, .loop -.cursorInTextSpeed +; cursor in Text Speed bit B_PAD_LEFT, b jp nz, .pressedLeftInTextSpeed jp .pressedRightInTextSpeed @@ -625,7 +626,7 @@ SetOptionsFromCursorPositions: ld a, [wOptionsBattleAnimCursorX] ; battle animation cursor X coordinate dec a jr z, .battleAnimationOn -.battleAnimationOff +; battle animation Off set BIT_BATTLE_ANIMATION, d jr .checkBattleStyle .battleAnimationOn @@ -634,7 +635,7 @@ SetOptionsFromCursorPositions: ld a, [wOptionsBattleStyleCursorX] ; battle style cursor X coordinate dec a jr z, .battleStyleShift -.battleStyleSet +; battle style Set set BIT_BATTLE_SHIFT, d jr .storeOptions .battleStyleShift diff --git a/engine/menus/naming_screen.asm b/engine/menus/naming_screen.asm index 24b172f0..9356cc66 100644 --- a/engine/menus/naming_screen.asm +++ b/engine/menus/naming_screen.asm @@ -379,12 +379,13 @@ PrintNicknameAndUnderscores: hlcoord 10, 3 ld a, [wNamingScreenType] cp NAME_MON_SCREEN - jr nc, .pokemon1 - ld b, 7 ; player or rival max name length - jr .playerOrRival1 -.pokemon1 - ld b, 10 ; pokemon max name length -.playerOrRival1 + jr nc, .pokemon +; player or rival + ld b, PLAYER_NAME_LENGTH - 1 + jr .gotUnderscoreCount +.pokemon + ld b, NAME_LENGTH - 1 +.gotUnderscoreCount ld a, $76 ; underscore tile id .placeUnderscoreLoop ld [hli], a @@ -394,13 +395,15 @@ PrintNicknameAndUnderscores: cp NAME_MON_SCREEN ld a, [wNamingScreenNameLength] jr nc, .pokemon2 - cp 7 ; player or rival max name length - jr .playerOrRival2 +; player or rival + cp PLAYER_NAME_LENGTH - 1 + jr .checkEmptySpaces .pokemon2 - cp 10 ; pokemon max name length -.playerOrRival2 - jr nz, .emptySpacesRemaining - ; when all spaces are filled, force the cursor onto the ED tile + cp NAME_LENGTH - 1 +.checkEmptySpaces + jr nz, .placeRaisedUnderscore ; jump if empty spaces remain + ; when all spaces are filled, force the cursor onto the ED tile, + ; and keep the last underscore raised call EraseMenuCursor ld a, $11 ; "ED" x coord ld [wTopMenuItemX], a @@ -408,11 +411,10 @@ PrintNicknameAndUnderscores: ld [wCurrentMenuItem], a ld a, [wNamingScreenType] cp NAME_MON_SCREEN - ld a, 9 ; keep the last underscore raised - jr nc, .pokemon3 - ld a, 6 ; keep the last underscore raised -.pokemon3 -.emptySpacesRemaining + ld a, NAME_LENGTH - 2 + jr nc, .placeRaisedUnderscore + ld a, PLAYER_NAME_LENGTH - 2 +.placeRaisedUnderscore ld c, a ld b, $0 hlcoord 10, 3 diff --git a/engine/menus/party_menu.asm b/engine/menus/party_menu.asm index f2688b52..15fd62be 100644 --- a/engine/menus/party_menu.asm +++ b/engine/menus/party_menu.asm @@ -90,7 +90,7 @@ RedrawPartyMenu_:: jr nz, .placeMoveLearnabilityString ld de, .notAbleToLearnMoveText .placeMoveLearnabilityString - ld bc, 20 + 9 ; down 1 row and right 9 columns + ld bc, SCREEN_WIDTH + 9 ; 1 row down and 9 columns right push hl add hl, bc call PlaceString @@ -102,7 +102,7 @@ RedrawPartyMenu_:: pop hl pop de inc de - ld bc, 2 * 20 + ld bc, 2 * SCREEN_WIDTH add hl, bc pop bc inc c diff --git a/engine/menus/pokedex.asm b/engine/menus/pokedex.asm index 3e4096bc..3d2fcbca 100644 --- a/engine/menus/pokedex.asm +++ b/engine/menus/pokedex.asm @@ -105,7 +105,7 @@ HandlePokedexSideMenu: jr z, .choseCry dec a jr z, .choseArea -.choseQuit +; chose Quit ld b, 1 .exitSideMenu pop af @@ -286,7 +286,7 @@ HandlePokedexListMenu: call HandleMenuInput bit B_PAD_B, a jp nz, .buttonBPressed -.checkIfUpPressed +; check if Up pressed bit B_PAD_UP, a jr z, .checkIfDownPressed .upPressed ; scroll up one row @@ -299,7 +299,7 @@ HandlePokedexListMenu: .checkIfDownPressed bit B_PAD_DOWN, a jr z, .checkIfRightPressed -.downPressed ; scroll down one row +; Down pressed, scroll down one row ld a, [wDexMaxSeenMon] cp 7 jp c, .loop ; can't if the list is shorter than 7 @@ -314,7 +314,7 @@ HandlePokedexListMenu: .checkIfRightPressed bit B_PAD_RIGHT, a jr z, .checkIfLeftPressed -.rightPressed ; scroll down 7 rows +; Right pressed, scroll down 7 rows ld a, [wDexMaxSeenMon] cp 7 jp c, .loop ; can't if the list is shorter than 7 @@ -332,7 +332,7 @@ HandlePokedexListMenu: .checkIfLeftPressed ; scroll up 7 rows bit B_PAD_LEFT, a jr z, .buttonAPressed -.leftPressed +; Left pressed ld a, [wListScrollOffset] sub 7 ld [wListScrollOffset], a @@ -593,8 +593,8 @@ HeightWeightText: db "HT ?′??″" next "WT ???lb@" -; XXX does anything point to this? -PokeText: +; leftover from JPN Pokedex, where species have the suffix "Pokemon" +PokeText: ; unreferenced db "#@" ; horizontal line that divides the pokedex text description from the rest of the data diff --git a/engine/menus/start_sub_menus.asm b/engine/menus/start_sub_menus.asm index ec10dd11..817dceb8 100644 --- a/engine/menus/start_sub_menus.asm +++ b/engine/menus/start_sub_menus.asm @@ -340,7 +340,7 @@ StartMenu_Item:: ld a, [wCurItem] cp BICYCLE jp z, .useOrTossItem -.notBicycle1 +; not Bicycle ld a, USE_TOSS_MENU_TEMPLATE ld [wTextBoxID], a call DisplayTextBoxID @@ -370,14 +370,14 @@ StartMenu_Item:: call CopyToStringBuffer ld a, [wCurItem] cp BICYCLE - jr nz, .notBicycle2 + jr nz, .notBicycle ld a, [wStatusFlags6] bit BIT_ALWAYS_ON_BIKE, a jr z, .useItem_closeMenu ld hl, CannotGetOffHereText call PrintText jp ItemMenuLoop -.notBicycle2 +.notBicycle ld a, [wCurrentMenuItem] and a jr nz, .tossItem diff --git a/engine/menus/swap_items.asm b/engine/menus/swap_items.asm index 2d506ce2..dc54b645 100644 --- a/engine/menus/swap_items.asm +++ b/engine/menus/swap_items.asm @@ -76,7 +76,7 @@ HandleItemListSwapping:: ld a, [hli] cp b jr z, .swapSameItemType -.swapDifferentItems +; swap different items ldh [hSwapItemID], a ; save second item ID ld a, [hld] ldh [hSwapItemQuantity], a ; save second item quantity diff --git a/engine/movie/credits.asm b/engine/movie/credits.asm index b1ca7c91..77484a80 100644 --- a/engine/movie/credits.asm +++ b/engine/movie/credits.asm @@ -6,10 +6,10 @@ HallOfFamePC: call DisableLCD ld hl, vFont ld bc, ($80 tiles) / 2 - call ZeroMemory + call ShiftFontColorIndex ld hl, vChars2 tile $60 ld bc, ($20 tiles) / 2 - call ZeroMemory + call ShiftFontColorIndex ld hl, vChars2 tile $7e ld bc, TILE_SIZE ld a, $ff ; solid black @@ -33,7 +33,7 @@ HallOfFamePC: ld [wNumCreditsMonsDisplayed], a jp Credits -FadeInCreditsText: +FadeInCredits: ld hl, HoFGBPalettes ld b, 4 .loop @@ -145,15 +145,18 @@ CreditsCopyTileMapToVRAM: ldh [hAutoBGTransferEnabled], a jp Delay3 -ZeroMemory: -; zero bc bytes at hl +ShiftFontColorIndex: +; Zero every second byte at hl, writing a total of bc bytes. +; When used on VRAM font characters that contain only black and white shades, +; it shifts the color index: black -> light gray, allowing palette-controlled +; text fade-in during the Credits roll, while the black bars remain solid. ld [hl], 0 inc hl inc hl dec bc ld a, b or c - jr nz, ZeroMemory + jr nz, ShiftFontColorIndex ret FillFourRowsWithBlack: @@ -215,7 +218,7 @@ Credits: pop de jr .nextCreditsCommand .fadeInTextAndShowMon - call FadeInCreditsText + call FadeInCredits ld c, 90 jr .next1 .showTextAndShowMon @@ -225,7 +228,7 @@ Credits: call DisplayCreditsMon jr .nextCreditsScreen .fadeInText - call FadeInCreditsText + call FadeInCredits ld c, 120 jr .next2 .showText @@ -254,7 +257,7 @@ Credits: hlcoord 4, 9 inc de call PlaceString - jp FadeInCreditsText + jp FadeInCredits TheEndTextString: ; "T H E E N D" diff --git a/engine/overworld/auto_movement.asm b/engine/overworld/auto_movement.asm index bed2ffb9..13d30cca 100644 --- a/engine/overworld/auto_movement.asm +++ b/engine/overworld/auto_movement.asm @@ -1,6 +1,6 @@ PlayerStepOutFromDoor:: - ld hl, wStatusFlags5 ; should this be wMovementFlags? - res BIT_EXITING_DOOR, [hl] + ld hl, wStatusFlags5 + res BIT_UNKNOWN_5_1, [hl] call IsPlayerStandingOnDoorTile jr nc, .notStandingOnDoor ld a, PAD_SELECT | PAD_START | PAD_CTRL_PAD diff --git a/engine/overworld/missable_objects.asm b/engine/overworld/missable_objects.asm index 1660a894..8ea79980 100644 --- a/engine/overworld/missable_objects.asm +++ b/engine/overworld/missable_objects.asm @@ -178,10 +178,10 @@ MissableObjectFlagAction: ld a, b and a jr z, .reset - cp 2 + cp FLAG_TEST jr z, .read -.set +; set ld a, [hl] ld b, a ld a, d diff --git a/engine/overworld/movement.asm b/engine/overworld/movement.asm index 8d02f0fe..a353c4f1 100644 --- a/engine/overworld/movement.asm +++ b/engine/overworld/movement.asm @@ -140,7 +140,7 @@ UpdateNPCSprite: ld b, a ld a, [wFontLoaded] bit BIT_FONT_LOADED, a - jp nz, notYetMoving + jp nz, NotYetMoving ld a, b cp $2 jp z, UpdateSpriteMovementDelay ; [x#SPRITESTATEDATA1_MOVEMENTSTATUS] == 2 @@ -389,14 +389,15 @@ UpdateSpriteMovementDelay: jr .moving .tickMoveCounter dec [hl] ; x#SPRITESTATEDATA2_MOVEMENTDELAY - jr nz, notYetMoving + jr nz, NotYetMoving .moving dec h ldh a, [hCurrentSpriteOffset] inc a ld l, a ld [hl], $1 ; [x#SPRITESTATEDATA1_MOVEMENTSTATUS] = 1 (mark as ready to move) -notYetMoving: + ; fallthrough +NotYetMoving: ld h, HIGH(wSpriteStateData1) ldh a, [hCurrentSpriteOffset] add SPRITESTATEDATA1_ANIMFRAMECOUNTER @@ -411,7 +412,7 @@ MakeNPCFacePlayer: ; disabled. This is only done when rubbing the S.S. Anne captain's back. ld a, [wStatusFlags3] bit BIT_NO_NPC_FACE_PLAYER, a - jr nz, notYetMoving + jr nz, NotYetMoving res BIT_FACE_PLAYER, [hl] ld a, [wPlayerDirection] bit PLAYER_DIR_BIT_UP, a @@ -435,7 +436,7 @@ MakeNPCFacePlayer: add $9 ld l, a ld [hl], c ; [x#SPRITESTATEDATA1_FACINGDIRECTION]: set facing direction - jr notYetMoving + jr NotYetMoving InitializeSpriteStatus: ld [hl], $1 ; [x#SPRITESTATEDATA1_MOVEMENTSTATUS] = ready diff --git a/engine/overworld/pathfinding.asm b/engine/overworld/pathfinding.asm index 878ca07d..d6e0d009 100644 --- a/engine/overworld/pathfinding.asm +++ b/engine/overworld/pathfinding.asm @@ -94,7 +94,7 @@ CalcPositionOfPlayerRelativeToNPC: ld a, [hli] ; NPC sprite screen Y position in pixels call CalcDifference jr nc, .NPCSouthOfOrAlignedWithPlayer -.NPCNorthOfPlayer +; NPC north of player push hl ld hl, hNPCPlayerRelativePosFlags bit BIT_PLAYER_LOWER_Y, [hl] @@ -122,7 +122,7 @@ CalcPositionOfPlayerRelativeToNPC: ld a, [hl] ; NPC sprite screen X position in pixels call CalcDifference jr nc, .NPCEastOfOrAlignedWithPlayer -.NPCWestOfPlayer +; NPC west of player push hl ld hl, hNPCPlayerRelativePosFlags bit BIT_PLAYER_LOWER_X, [hl] diff --git a/engine/overworld/push_boulder.asm b/engine/overworld/push_boulder.asm index 2328b07a..5e7393d2 100644 --- a/engine/overworld/push_boulder.asm +++ b/engine/overworld/push_boulder.asm @@ -43,7 +43,7 @@ TryPushingBoulder:: jr z, .pushBoulderLeft cp SPRITE_FACING_RIGHT jr z, .pushBoulderRight -.pushBoulderDown +; push boulder down bit B_PAD_DOWN, b ret z ld de, PushBoulderDownMovementData diff --git a/engine/pokemon/add_mon.asm b/engine/pokemon/add_mon.asm index 455221ce..c92acfcb 100644 --- a/engine/pokemon/add_mon.asm +++ b/engine/pokemon/add_mon.asm @@ -375,7 +375,7 @@ _MoveMon:: .copySpecies ld [hli], a ; write new mon ID ld [hl], $ff ; write new sentinel -.findMonDataDest +; find mon data dest ld a, [wMoveMonType] dec a ld hl, wPartyMons @@ -457,7 +457,7 @@ _MoveMon:: ld bc, NAME_LENGTH call CopyData ld a, [wMoveMonType] -.findNickDest +; find nick dest cp PARTY_TO_DAYCARE ld de, wDayCareMonName jr z, .findNickSrc diff --git a/engine/pokemon/load_mon_data.asm b/engine/pokemon/load_mon_data.asm index d90b9cd8..87a2be8b 100644 --- a/engine/pokemon/load_mon_data.asm +++ b/engine/pokemon/load_mon_data.asm @@ -31,7 +31,7 @@ LoadMonData_:: ld hl, wEnemyMons jr z, .getMonEntry - cp 2 + cp BOX_DATA ld hl, wBoxMons ld bc, BOXMON_STRUCT_LENGTH jr z, .getMonEntry diff --git a/home/joypad2.asm b/home/joypad2.asm index a07b9ee4..11ef9a99 100644 --- a/home/joypad2.asm +++ b/home/joypad2.asm @@ -25,7 +25,7 @@ JoypadLowSensitivity:: ldh a, [hJoyPressed] ; newly pressed buttons and a ; have any buttons been newly pressed since last check? jr z, .noNewlyPressedButtons -.newlyPressedButtons +; newly pressed buttons ld a, 30 ; half a second delay ldh [hFrameCounter], a ret @@ -33,7 +33,7 @@ JoypadLowSensitivity:: ldh a, [hFrameCounter] and a ; is the delay over? jr z, .delayOver -.delayNotOver +; delay not over xor a ldh [hJoy5], a ; report no buttons as pressed ret diff --git a/home/list_menu.asm b/home/list_menu.asm index d0d3f732..bd1197bb 100644 --- a/home/list_menu.asm +++ b/home/list_menu.asm @@ -65,7 +65,7 @@ DisplayListMenuIDLoop:: ld a, [wBattleType] and a ; is it the Old Man battle? jr z, .notOldManBattle -.oldManBattle +; Old Man battle ld a, '▶' ldcoord_a 5, 4 ; place menu cursor in front of first menu entry ld c, 80 @@ -178,7 +178,7 @@ DisplayListMenuIDLoop:: bit B_PAD_DOWN, b ld hl, wListScrollOffset jr z, .upPressed -.downPressed +; Down pressed ld a, [hl] add 3 ld b, a @@ -380,7 +380,7 @@ PrintListMenuEntries:: jr z, .pokemonPCMenu cp MOVESLISTMENU jr z, .movesMenu -.itemMenu +; item menu call GetItemName jr .placeNameString .pokemonPCMenu @@ -411,7 +411,7 @@ PrintListMenuEntries:: ld a, [wPrintItemPrices] and a ; should prices be printed? jr z, .skipPrintingItemPrice -.printItemPrice +; print item price push hl ld a, [de] ld de, ItemPrices @@ -426,7 +426,7 @@ PrintListMenuEntries:: ld a, [wListMenuID] and a ; PCPOKEMONLISTMENU? jr nz, .skipPrintingPokemonLevel -.printPokemonLevel +; print Pokemon level ld a, [wNamedObjectIndex] push af push hl @@ -451,7 +451,7 @@ PrintListMenuEntries:: ld a, [wMonDataLocation] and a ; is it a list of party pokemon or box pokemon? jr z, .skipCopyingLevel -.copyLevel +; copy level ld a, [wLoadedMonBoxLevel] ld [wLoadedMonLevel], a .skipCopyingLevel @@ -468,7 +468,7 @@ PrintListMenuEntries:: ld a, [wListMenuID] cp ITEMLISTMENU jr nz, .nextListEntry -.printItemQuantity +; print item quantity ld a, [wNamedObjectIndex] ld [wCurItem], a call IsKeyItem ; check if item is unsellable diff --git a/home/load_font.asm b/home/load_font.asm index 47ad60f1..e6e04113 100644 --- a/home/load_font.asm +++ b/home/load_font.asm @@ -2,7 +2,7 @@ LoadFontTilePatterns:: ldh a, [rLCDC] bit B_LCDC_ENABLE, a jr nz, .on -.off +; off ld hl, FontGraphics ld de, vFont ld bc, FontGraphicsEnd - FontGraphics @@ -18,7 +18,7 @@ LoadTextBoxTilePatterns:: ldh a, [rLCDC] bit B_LCDC_ENABLE, a jr nz, .on -.off +; off ld hl, TextBoxGraphics ld de, vChars2 tile $60 ld bc, TextBoxGraphicsEnd - TextBoxGraphics @@ -34,7 +34,7 @@ LoadHpBarAndStatusTilePatterns:: ldh a, [rLCDC] bit B_LCDC_ENABLE, a jr nz, .on -.off +; off ld hl, HpBarAndStatusGraphics ld de, vChars2 tile $62 ld bc, HpBarAndStatusGraphicsEnd - HpBarAndStatusGraphics diff --git a/home/map_objects.asm b/home/map_objects.asm index 44b012e6..57364518 100644 --- a/home/map_objects.asm +++ b/home/map_objects.asm @@ -115,7 +115,7 @@ CheckCoords:: ld hl, wCoordIndex inc [hl] pop hl -.compareYCoord +; compare Y coord cp b jr z, .compareXCoord inc hl @@ -124,7 +124,7 @@ CheckCoords:: ld a, [hli] cp c jr nz, .loop -.inArray +; in array scf ret .notInArray diff --git a/home/move_mon.asm b/home/move_mon.asm index cb19d0e3..def60bc1 100644 --- a/home/move_mon.asm +++ b/home/move_mon.asm @@ -106,7 +106,7 @@ CalcStat:: jr z, .getSpeedIV cp $5 jr z, .getSpecialIV -.getHpIV +; get HP IV push bc ld a, [hl] ; Atk IV swap a diff --git a/home/overworld.asm b/home/overworld.asm index f837815b..e994f694 100644 --- a/home/overworld.asm +++ b/home/overworld.asm @@ -546,7 +546,7 @@ ContinueCheckWarpsNoCollisionLoop:: ; if no matching warp was found CheckMapConnections:: -.checkWestMap +; check west map ld a, [wXCoord] cp $ff jr nz, .checkEastMap @@ -1097,8 +1097,7 @@ IsSpriteOrSignInFrontOfPlayer:: ld a, [hli] ; sign X cp e jr nz, .retry -.xCoordMatched -; found sign +; X coord matched: found sign push hl push bc ld hl, wSignTextIDs @@ -2047,7 +2046,7 @@ LoadMapHeader:: ; copy connection data (if any) to WRAM ld a, [wCurMapConnections] ld b, a -.checkNorth +; check north bit NORTH_F, b jr z, .checkSouth ld de, wNorthConnectionHeader @@ -2080,7 +2079,7 @@ LoadMapHeader:: ld de, wMapBackgroundTile ld a, [hli] ld [de], a -.loadWarpData +; load warp data ld a, [hli] ld [wNumberOfWarps], a and a diff --git a/home/print_bcd.asm b/home/print_bcd.asm index 2e501be5..cac6aba3 100644 --- a/home/print_bcd.asm +++ b/home/print_bcd.asm @@ -31,9 +31,9 @@ PrintBCDNumber:: inc de dec c jr nz, .loop - bit BIT_LEADING_ZEROES, b + bit BIT_LEADING_ZEROES, b ; were any non-zero digits printed? jr z, .done ; if so, we are done -.numberEqualsZero ; if every digit of the BCD number is zero +; if every digit of the BCD number is zero, print the last 0 bit BIT_LEFT_ALIGN, b jr nz, .skipRightAlignmentAdjustment dec hl ; if the string is right-aligned, it needs to be moved back one space diff --git a/home/print_num.asm b/home/print_num.asm index 32fae363..8027a764 100644 --- a/home/print_num.asm +++ b/home/print_num.asm @@ -82,11 +82,16 @@ MACRO print_digit call .NextDigit ENDM -.millions print_digit 1000000 -.hundred_thousands print_digit 100000 -.ten_thousands print_digit 10000 -.thousands print_digit 1000 -.hundreds print_digit 100 +; millions + print_digit 1000000 +.hundred_thousands + print_digit 100000 +.ten_thousands + print_digit 10000 +.thousands + print_digit 1000 +.hundreds + print_digit 100 .tens ld c, 0 @@ -113,7 +118,7 @@ ENDM .next call .NextDigit -.ones +; ones ld a, '0' add b ld [hli], a diff --git a/home/print_text.asm b/home/print_text.asm index fe784350..8e351ba3 100644 --- a/home/print_text.asm +++ b/home/print_text.asm @@ -24,7 +24,7 @@ PrintLetterDelay:: .checkButtons call Joypad ldh a, [hJoyHeld] -.checkAButton +; check A button bit B_PAD_A, a jr z, .checkBButton jr .endWait diff --git a/home/start_menu.asm b/home/start_menu.asm index 6de15182..9504d536 100644 --- a/home/start_menu.asm +++ b/home/start_menu.asm @@ -14,7 +14,7 @@ RedisplayStartMenu:: .loop call HandleMenuInput ld b, a -.checkIfUpPressed +; check if Up pressed bit B_PAD_UP, a jr z, .checkIfDownPressed ld a, [wCurrentMenuItem] ; menu selection diff --git a/home/trainers.asm b/home/trainers.asm index f00c4df9..8d2cceaf 100644 --- a/home/trainers.asm +++ b/home/trainers.asm @@ -19,7 +19,7 @@ ExecuteCurMapScriptInTable:: ld hl, wStatusFlags7 bit BIT_USE_CUR_MAP_SCRIPT, [hl] res BIT_USE_CUR_MAP_SCRIPT, [hl] - jr z, .useProvidedIndex ; test if map script index was overridden manually + jr z, .useProvidedIndex ; test if map script index was overridden manually ld a, [wCurMapScript] .useProvidedIndex pop hl @@ -32,11 +32,11 @@ LoadGymLeaderAndCityName:: push de ld de, wGymCityName ld bc, GYM_CITY_LENGTH - call CopyData ; load city name + call CopyData ; load city name pop hl ld de, wGymLeaderName ld bc, NAME_LENGTH - jp CopyData ; load gym leader name + jp CopyData ; load gym leader name ; reads specific information from trainer header (pointed to at wTrainerHeaderPtr) ; a: offset in header data @@ -155,7 +155,7 @@ ENDC ldh [hJoyHeld], a call TrainerWalkUpToPlayer_Bank0 ld hl, wCurMapScript - inc [hl] ; increment map script index (next script function is usually DisplayEnemyTrainerTextAndStartBattle) + inc [hl] ; increment map script index (next script function is usually DisplayEnemyTrainerTextAndStartBattle) ret ; display the before battle text after the enemy trainer has walked up to the player's sprite @@ -179,7 +179,7 @@ StartTrainerBattle:: ld hl, wStatusFlags4 set BIT_UNKNOWN_4_1, [hl] ld hl, wCurMapScript - inc [hl] ; increment map script index (next script function is usually EndTrainerBattle) + inc [hl] ; increment map script index (next script function is usually EndTrainerBattle) ret EndTrainerBattle:: @@ -201,14 +201,14 @@ EndTrainerBattle:: call TrainerFlagAction ; flag trainer as fought ld a, [wEnemyMonOrTrainerClass] cp OPP_ID_OFFSET - jr nc, .skipRemoveSprite ; test if trainer was fought (in that case skip removing the corresponding sprite) + jr nc, .skipRemoveSprite ; test if trainer was fought (in that case skip removing the corresponding sprite) ld hl, wMissableObjectList ld de, $2 ld a, [wSpriteIndex] - call IsInArray ; search for sprite ID + call IsInArray ; search for sprite ID inc hl ld a, [hl] - ld [wMissableObjectIndex], a ; load corresponding missable object index and remove it + ld [wMissableObjectIndex], a ; load corresponding missable object index and remove it predef HideObject .skipRemoveSprite ld hl, wStatusFlags5 @@ -269,7 +269,7 @@ CheckForEngagingTrainers:: .trainerLoop call StoreTrainerHeaderPointer ; set trainer header pointer to current trainer ld a, [de] - ld [wSpriteIndex], a ; store trainer flag's bit + ld [wSpriteIndex], a ; store trainer flag's bit ld [wTrainerHeaderFlagBit], a cp -1 ret z @@ -278,7 +278,7 @@ CheckForEngagingTrainers:: ld b, FLAG_TEST ld a, [wTrainerHeaderFlagBit] ld c, a - call TrainerFlagAction ; read trainer flag + call TrainerFlagAction ; read trainer flag ld a, c and a ; has the trainer already been defeated? jr nz, .continue @@ -299,7 +299,7 @@ CheckForEngagingTrainers:: pop hl ld a, [wTrainerSpriteOffset] and a - ret nz ; break if the trainer is engaging + ret nz ; break if the trainer is engaging .continue ld hl, $c add hl, de @@ -364,8 +364,8 @@ PrintEndBattleText:: GetSavedEndBattleTextPointer:: ld a, [wBattleResult] and a -; won battle jr nz, .lostBattle +; won battle ld a, [wEndBattleWinTextPointer] ld h, a ld a, [wEndBattleWinTextPointer + 1] diff --git a/home/window.asm b/home/window.asm index 6885a138..2f2609d7 100644 --- a/home/window.asm +++ b/home/window.asm @@ -52,11 +52,11 @@ HandleMenuInput_:: ld b, a bit B_PAD_UP, a jr z, .checkIfDownPressed -.upPressed +; Up pressed ld a, [wCurrentMenuItem] ; selected menu item and a ; already at the top of the menu? jr z, .alreadyAtTop -.notAtTop +; not at top dec a ld [wCurrentMenuItem], a ; move selected menu item up one space jr .checkOtherKeys @@ -70,14 +70,14 @@ HandleMenuInput_:: .checkIfDownPressed bit B_PAD_DOWN, a jr z, .checkOtherKeys -.downPressed +; Down pressed ld a, [wCurrentMenuItem] inc a ld c, a ld a, [wMaxMenuItem] cp c jr nc, .notAtBottom -.alreadyAtBottom +; already at bottom ld a, [wMenuWrappingEnabled] and a ; is wrapping around enabled? jr z, .noWrappingAround @@ -93,7 +93,7 @@ HandleMenuInput_:: ldh a, [hJoy5] and PAD_A | PAD_B jr z, .skipPlayingSound -.AButtonOrBButtonPressed +; A or B pressed push hl ld hl, wMiscFlags bit BIT_NO_MENU_BUTTON_SOUND, [hl] @@ -153,7 +153,7 @@ PlaceMenuCursor:: ld a, [hl] cp '▶' ; was an arrow next to the previously selected menu item? jr nz, .skipClearingArrow -.clearArrow +; clear arrow ld a, [wTileBehindCursor] ld [hl], a .skipClearingArrow diff --git a/macros/scripts/events.asm b/macros/scripts/events.asm index b07a38f3..740184dd 100644 --- a/macros/scripts/events.asm +++ b/macros/scripts/events.asm @@ -343,7 +343,7 @@ MACRO ResetEventRange IF event_fill_count > 1 ld hl, wEventFlags + event_fill_start - ; force xor a if we just to wrote to it above + ; force xor a if we just wrote to it above IF (_NARG < 3) || (((\1) % 8) != 0) xor a ENDC diff --git a/scripts/BillsHouse.asm b/scripts/BillsHouse.asm index 6b65aa38..d43ae546 100644 --- a/scripts/BillsHouse.asm +++ b/scripts/BillsHouse.asm @@ -82,13 +82,13 @@ BillsHouseBillExitsMachineScript: call DelayFrames ld a, BILLSHOUSE_BILL1 ldh [hSpriteIndex], a - ld de, BillExitMachineMovement + ld de, .BillExitMachineMovement call MoveSprite ld a, SCRIPT_BILLSHOUSE_CLEANUP ld [wBillsHouseCurScript], a ret -BillExitMachineMovement: +.BillExitMachineMovement: db NPC_MOVEMENT_DOWN db NPC_MOVEMENT_RIGHT db NPC_MOVEMENT_RIGHT diff --git a/scripts/Colosseum.asm b/scripts/Colosseum.asm index 4aaa4236..1489fd2c 100644 --- a/scripts/Colosseum.asm +++ b/scripts/Colosseum.asm @@ -1,4 +1,5 @@ Colosseum_Script: + ASSERT TRADECENTER_OPPONENT == COLOSSEUM_OPPONENT jp TradeCenter_Script Colosseum_TextPointers: -- cgit v1.3.1-sl0p From d79c578abd993f7eee4e85462a8cd5b7c4e14646 Mon Sep 17 00:00:00 2001 From: Rangi <35663410+Rangi42@users.noreply.github.com> Date: Mon, 15 Dec 2025 15:16:40 -0500 Subject: Specify a max item length for `list_start` (#552) --- constants/text_constants.asm | 14 ++++++++------ data/battle/stat_mod_names.asm | 2 +- data/battle/stat_names.asm | 2 +- data/items/names.asm | 2 +- data/moves/names.asm | 3 ++- data/player/names_list.asm | 4 ++-- data/trainers/move_choices.asm | 8 +++++--- data/trainers/names.asm | 2 +- engine/battle/effects.asm | 2 +- engine/battle/get_trainer_name.asm | 2 +- engine/items/item_effects.asm | 2 +- macros/asserts.asm | 18 ++++++++++++++---- 12 files changed, 38 insertions(+), 23 deletions(-) (limited to 'engine/items') diff --git a/constants/text_constants.asm b/constants/text_constants.asm index 88a42bbe..f4587736 100644 --- a/constants/text_constants.asm +++ b/constants/text_constants.asm @@ -1,9 +1,11 @@ -DEF PLAYER_NAME_LENGTH EQU 8 -DEF NAME_LENGTH EQU 11 -DEF ITEM_NAME_LENGTH EQU 13 -DEF MOVE_NAME_LENGTH EQU 14 -DEF NAME_BUFFER_LENGTH EQU 20 -DEF GYM_CITY_LENGTH EQU 17 +DEF PLAYER_NAME_LENGTH EQU 8 +DEF STAT_NAME_LENGTH EQU 10 +DEF NAME_LENGTH EQU 11 +DEF ITEM_NAME_LENGTH EQU 13 +DEF TRAINER_NAME_LENGTH EQU 13 +DEF MOVE_NAME_LENGTH EQU 14 +DEF GYM_CITY_LENGTH EQU 17 +DEF NAME_BUFFER_LENGTH EQU 20 ; PrintNumber, PrintBCDNumber const_def 5 diff --git a/data/battle/stat_mod_names.asm b/data/battle/stat_mod_names.asm index 63c956d7..6c68db4e 100644 --- a/data/battle/stat_mod_names.asm +++ b/data/battle/stat_mod_names.asm @@ -2,7 +2,7 @@ ; The relevant move effect IDs correspond to the stats StatModTextStrings: - list_start + list_start STAT_NAME_LENGTH - 1 li "ATTACK" li "DEFENSE" li "SPEED" diff --git a/data/battle/stat_names.asm b/data/battle/stat_names.asm index 30401a99..08685e83 100644 --- a/data/battle/stat_names.asm +++ b/data/battle/stat_names.asm @@ -1,7 +1,7 @@ ; Stats that vitamins can raise or lower VitaminStats: - list_start + list_start STAT_NAME_LENGTH - 1 li "HEALTH" li "ATTACK" li "DEFENSE" diff --git a/data/items/names.asm b/data/items/names.asm index bab26efc..f5c0f27e 100644 --- a/data/items/names.asm +++ b/data/items/names.asm @@ -1,5 +1,5 @@ ItemNames:: - list_start + list_start ITEM_NAME_LENGTH - 1 li "MASTER BALL" li "ULTRA BALL" li "GREAT BALL" diff --git a/data/moves/names.asm b/data/moves/names.asm index 025172d5..caecc06c 100644 --- a/data/moves/names.asm +++ b/data/moves/names.asm @@ -1,5 +1,6 @@ MoveNames:: - list_start + ; in-battle "used !" text can only fit 12 (MOVE_NAME_LENGTH - 2) characters + list_start MOVE_NAME_LENGTH - 2 li "POUND" li "KARATE CHOP" li "DOUBLESLAP" diff --git a/data/player/names_list.asm b/data/player/names_list.asm index 786c1229..44f3c7f1 100644 --- a/data/player/names_list.asm +++ b/data/player/names_list.asm @@ -2,7 +2,7 @@ DefaultNamesPlayerList: db "NEW NAME@" - list_start + list_start PLAYER_NAME_LENGTH - 1 FOR n, 1, NUM_PLAYER_NAMES + 1 li #PLAYERNAME{d:n} ENDR @@ -10,7 +10,7 @@ ENDR DefaultNamesRivalList: db "NEW NAME@" - list_start + list_start PLAYER_NAME_LENGTH - 1 FOR n, 1, NUM_PLAYER_NAMES + 1 li #RIVALNAME{d:n} ENDR diff --git a/data/trainers/move_choices.asm b/data/trainers/move_choices.asm index 1624b326..98c068a1 100644 --- a/data/trainers/move_choices.asm +++ b/data/trainers/move_choices.asm @@ -1,14 +1,15 @@ +DEF __move_choices__ = 0 + MACRO move_choices IF _NARG db \# ; all args ENDC db 0 ; end - DEF list_index += 1 + DEF __move_choices__ += 1 ENDM ; move choice modification methods that are applied for each trainer class TrainerClassMoveChoiceModifications: - list_start move_choices ; YOUNGSTER move_choices 1 ; BUG CATCHER move_choices 1 ; LASS @@ -56,4 +57,5 @@ TrainerClassMoveChoiceModifications: move_choices 1 ; CHANNELER move_choices 1 ; AGATHA move_choices 1, 3 ; LANCE - assert_list_length NUM_TRAINERS + assert __move_choices__ == NUM_TRAINERS, \ + "TrainerClassMoveChoiceModifications: expected {d:NUM_TRAINERS} entries, got {d:__move_choices__}" diff --git a/data/trainers/names.asm b/data/trainers/names.asm index d7c5677c..1b6f2382 100644 --- a/data/trainers/names.asm +++ b/data/trainers/names.asm @@ -1,5 +1,5 @@ TrainerNames:: - list_start + list_start TRAINER_NAME_LENGTH - 1 li "YOUNGSTER" li "BUG CATCHER" li "LASS" diff --git a/engine/battle/effects.asm b/engine/battle/effects.asm index 22765140..394e07e5 100644 --- a/engine/battle/effects.asm +++ b/engine/battle/effects.asm @@ -754,7 +754,7 @@ PrintStatText: jr .findStatName_inner .foundStatName ld de, wStringBuffer - ld bc, NAME_LENGTH - 1 ; all StatModTextStrings are at most 10 bytes + ld bc, STAT_NAME_LENGTH jp CopyData INCLUDE "data/battle/stat_mod_names.asm" diff --git a/engine/battle/get_trainer_name.asm b/engine/battle/get_trainer_name.asm index a0e869fc..1983b08a 100644 --- a/engine/battle/get_trainer_name.asm +++ b/engine/battle/get_trainer_name.asm @@ -20,5 +20,5 @@ GetTrainerName_:: ld hl, wNameBuffer .foundName ld de, wTrainerName - ld bc, ITEM_NAME_LENGTH + ld bc, TRAINER_NAME_LENGTH jp CopyData diff --git a/engine/items/item_effects.asm b/engine/items/item_effects.asm index 12b5bd00..c4ce13de 100644 --- a/engine/items/item_effects.asm +++ b/engine/items/item_effects.asm @@ -1308,7 +1308,7 @@ ItemUseMedicine: jr .statNameLoop .gotStatName ld de, wStringBuffer - ld bc, NAME_LENGTH - 1 ; all VitaminStats are at most 10 bytes + ld bc, STAT_NAME_LENGTH call CopyData ; copy the stat's name to wStringBuffer ld a, SFX_HEAL_AILMENT call PlaySound diff --git a/macros/asserts.asm b/macros/asserts.asm index e2de1505..11e0ee99 100644 --- a/macros/asserts.asm +++ b/macros/asserts.asm @@ -4,8 +4,8 @@ MACRO? _redef_current_label IF DEF(\1) PURGE \1 ENDC - IF _NARG == 3 + (\3) - DEF \1 EQUS "\<_NARG>" + IF _NARG > 2 + DEF \1 EQUS "\3" ELIF STRLEN(#__SCOPE__) IF {{__SCOPE__}} - @ == 0 DEF \1 EQUS #{__SCOPE__} @@ -19,7 +19,8 @@ ENDM MACRO? table_width DEF CURRENT_TABLE_WIDTH = \1 - _redef_current_label CURRENT_TABLE_START, "._table_width\@", 2, \# + SHIFT + _redef_current_label CURRENT_TABLE_START, "._table_width\@", \# ENDM MACRO? assert_table_length @@ -40,11 +41,20 @@ ENDM MACRO? list_start DEF list_index = 0 - _redef_current_label CURRENT_LIST_START, "._list_start\@", 1, \# + DEF list_item_length = 0 + IF _NARG > 0 + DEF list_item_length = \1 + SHIFT + ENDC + _redef_current_label CURRENT_LIST_START, "._list_start\@", \# ENDM MACRO? li ASSERT STRFIND(\1, "@") == -1, "String terminator \"@\" in list entry: \1" + IF list_item_length + ASSERT CHARLEN(\1) <= list_item_length, \ + "List entry longer than {d:list_item_length} characters: \1" + ENDC db \1, "@" DEF list_index += 1 ENDM -- cgit v1.3.1-sl0p