diff options
| author | Rangi <35663410+Rangi42@users.noreply.github.com> | 2025-11-25 17:53:29 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-25 16:53:29 -0600 |
| commit | e92d1af478c8381fde30f709c2619abe90104d3a (patch) | |
| tree | 7be135926706fabcf23d2b278378d0fdd7f7eda7 | |
| parent | Use `ld_hli_a_string` macro to make byte-by-byte strings more obvious (#540) (diff) | |
| download | pokeyellow-e92d1af478c8381fde30f709c2619abe90104d3a.tar.gz pokeyellow-e92d1af478c8381fde30f709c2619abe90104d3a.tar.xz pokeyellow-e92d1af478c8381fde30f709c2619abe90104d3a.zip | |
Avoid magic numbers for most `CopyData` calls (#542)
| -rw-r--r-- | constants/gfx_constants.asm | 6 | ||||
| -rw-r--r-- | constants/text_constants.asm | 1 | ||||
| -rw-r--r-- | engine/battle/animations.asm | 20 | ||||
| -rw-r--r-- | engine/battle/core.asm | 21 | ||||
| -rw-r--r-- | engine/battle/draw_hud_pokeball_gfx.asm | 8 | ||||
| -rw-r--r-- | engine/battle/effects.asm | 2 | ||||
| -rw-r--r-- | engine/battle/ghost_marowak_anim.asm | 2 | ||||
| -rw-r--r-- | engine/battle/move_effects/transform.asm | 9 | ||||
| -rw-r--r-- | engine/battle/trainer_ai.asm | 4 | ||||
| -rw-r--r-- | engine/events/in_game_trades.asm | 2 | ||||
| -rw-r--r-- | engine/items/item_effects.asm | 6 | ||||
| -rw-r--r-- | engine/items/town_map.asm | 4 | ||||
| -rw-r--r-- | engine/movie/evolution.asm | 2 | ||||
| -rw-r--r-- | engine/movie/hall_of_fame.asm | 2 | ||||
| -rw-r--r-- | engine/movie/splash.asm | 2 | ||||
| -rw-r--r-- | engine/overworld/cut2.asm | 6 | ||||
| -rw-r--r-- | engine/overworld/player_animations.asm | 6 | ||||
| -rw-r--r-- | engine/pokemon/add_mon.asm | 2 | ||||
| -rw-r--r-- | engine/slots/slot_machine.asm | 2 | ||||
| -rw-r--r-- | home/trainers.asm | 2 | ||||
| -rw-r--r-- | ram/vram.asm | 6 | ||||
| -rw-r--r-- | ram/wram.asm | 10 |
22 files changed, 68 insertions, 57 deletions
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 |
