WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit e92d1af

Browse files
authored
Avoid magic numbers for most CopyData calls (#542)
1 parent 308189b commit e92d1af

22 files changed

+68
-57
lines changed

constants/gfx_constants.asm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ DEF SCREEN_BLOCK_HEIGHT EQU 5 ; blocks
77
DEF SURROUNDING_WIDTH EQU SCREEN_BLOCK_WIDTH * BLOCK_WIDTH ; tiles
88
DEF SURROUNDING_HEIGHT EQU SCREEN_BLOCK_HEIGHT * BLOCK_HEIGHT ; tiles
99

10-
DEF SPRITEBUFFERSIZE EQU 7 * 7 * TILE_1BPP_SIZE
10+
DEF PIC_WIDTH EQU 7 ; tiles
11+
DEF PIC_HEIGHT EQU PIC_WIDTH ; tiles
12+
DEF PIC_SIZE EQU PIC_WIDTH * PIC_HEIGHT ; tiles
13+
14+
DEF SPRITEBUFFERSIZE EQU PIC_WIDTH * PIC_HEIGHT * TILE_1BPP_SIZE
1115

1216
; HP bar
1317
DEF HP_BAR_GREEN EQU 0

constants/text_constants.asm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
DEF NAME_LENGTH EQU 11
22
DEF ITEM_NAME_LENGTH EQU 13
33
DEF NAME_BUFFER_LENGTH EQU 20
4+
DEF GYM_CITY_LENGTH EQU 17
45

56
; PrintNumber, PrintBCDNumber
67
const_def 5

engine/battle/animations.asm

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,12 +1213,12 @@ _AnimationSlideMonUp:
12131213
push bc
12141214

12151215
; In each iteration, slide up all rows but the top one (which is overwritten).
1216-
ld b, 6
1216+
ld b, PIC_HEIGHT - 1
12171217
.slideLoop
12181218
push bc
12191219
push de
12201220
push hl
1221-
ld bc, 7
1221+
ld bc, PIC_WIDTH
12221222
call CopyData
12231223
; Note that de and hl are popped in the same order they are pushed, swapping
12241224
; their values. When CopyData is called, hl points to a tile 1 row below
@@ -1242,10 +1242,10 @@ _AnimationSlideMonUp:
12421242
ld a, [wSlideMonUpBottomRowLeftTile]
12431243
inc a
12441244
ld [wSlideMonUpBottomRowLeftTile], a
1245-
ld c, 7
1245+
ld c, PIC_WIDTH
12461246
.fillBottomRowLoop
12471247
ld [hli], a
1248-
add 7
1248+
add PIC_WIDTH
12491249
dec c
12501250
jr nz, .fillBottomRowLoop
12511251

@@ -1723,10 +1723,10 @@ AnimationMinimizeMon:
17231723
ld hl, wTempPic
17241724
push hl
17251725
xor a
1726-
ld bc, (7 * 7) tiles
1726+
ld bc, PIC_SIZE tiles
17271727
call FillMemory
17281728
pop hl
1729-
ld de, (7 * 3 + 4) tiles + TILE_SIZE / 4
1729+
ld de, (PIC_WIDTH * 3 + 4) tiles + TILE_SIZE / 4
17301730
add hl, de
17311731
ld de, MinimizedMonSprite
17321732
ld c, MinimizedMonSpriteEnd - MinimizedMonSprite
@@ -1774,7 +1774,7 @@ AnimationSlideMonDownAndHide:
17741774
jr nz, .loop
17751775
call AnimationHideMonPic
17761776
ld hl, wTempPic
1777-
ld bc, 7 * 7 tiles
1777+
ld bc, PIC_SIZE tiles
17781778
xor a
17791779
call FillMemory
17801780
jp CopyTempPicToMonPic
@@ -1867,7 +1867,7 @@ CopyTempPicToMonPic:
18671867
ld hl, vFrontPic ; enemy turn
18681868
.next
18691869
ld de, wTempPic
1870-
ld bc, 7 * 7
1870+
ld bc, PIC_SIZE
18711871
jp CopyVideoData
18721872

18731873
AnimationWavyScreen:
@@ -1935,7 +1935,7 @@ AnimationSubstitute:
19351935
; Changes the pokemon's sprite to the mini sprite
19361936
ld hl, wTempPic
19371937
xor a
1938-
ld bc, 7 * 7 tiles
1938+
ld bc, PIC_SIZE tiles
19391939
call FillMemory
19401940
ldh a, [hWhoseTurn]
19411941
and a
@@ -2473,7 +2473,7 @@ AnimationShakeEnemyHUD:
24732473
; Make a copy of the back pic's tile patterns in sprite tile pattern VRAM.
24742474
ld de, vBackPic
24752475
ld hl, vSprites
2476-
ld bc, 7 * 7
2476+
ld bc, PIC_SIZE
24772477
call CopyVideoData
24782478

24792479
xor a

engine/battle/core.asm

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,17 +1183,17 @@ SlideDownFaintedMonPic:
11831183
push af
11841184
set BIT_NO_TEXT_DELAY, a
11851185
ld [wStatusFlags5], a
1186-
ld b, 7 ; number of times to slide
1186+
ld b, PIC_HEIGHT ; number of times to slide
11871187
.slideStepLoop ; each iteration, the mon is slid down one row
11881188
push bc
11891189
push de
11901190
push hl
1191-
ld b, 6 ; number of rows
1191+
ld b, PIC_HEIGHT - 1 ; number of rows
11921192
.rowLoop
11931193
push bc
11941194
push hl
11951195
push de
1196-
ld bc, $7
1196+
ld bc, PIC_WIDTH
11971197
call CopyData
11981198
pop de
11991199
pop hl
@@ -1225,7 +1225,8 @@ SlideDownFaintedMonPic:
12251225
ret
12261226

12271227
SevenSpacesText:
1228-
db " @"
1228+
ds PIC_WIDTH, ' '
1229+
db "@"
12291230

12301231
; slides the player or enemy trainer off screen
12311232
; 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:
12371238
.slideStepLoop ; each iteration, the trainer pic is slid one tile left/right
12381239
push bc
12391240
push hl
1240-
ld b, 7 ; number of rows
1241+
ld b, PIC_HEIGHT ; number of rows
12411242
.rowLoop
12421243
push hl
12431244
ldh a, [hSlideAmount]
@@ -1794,7 +1795,7 @@ AnimateRetreatingPlayerMon:
17941795
lb bc, 7, 7
17951796
jp ClearScreenArea
17961797

1797-
; Copies player's current pokemon's current HP and status into the party
1798+
; Copies player's current pokemon's current HP, party pos, and status into the party
17981799
; struct data so it stays after battle or switching
17991800
ReadPlayerMonCurHPAndStatus:
18001801
ld a, [wPlayerMonNumber]
@@ -1804,7 +1805,7 @@ ReadPlayerMonCurHPAndStatus:
18041805
ld d, h
18051806
ld e, l
18061807
ld hl, wBattleMonHP
1807-
ld bc, $4 ; 2 bytes HP, 1 byte unknown (unused?), 1 byte status
1808+
ld bc, MON_STATUS + 1 - MON_HP ; also copies party pos in-between HP and status
18081809
jp CopyData
18091810

18101811
DrawHUDsAndHPBars:
@@ -6352,7 +6353,7 @@ LoadPlayerBackPic:
63526353
ld [hl], d ; OAM Y
63536354
inc hl
63546355
ld [hl], e ; OAM X
6355-
ld a, $8 ; height of tile
6356+
ld a, TILE_HEIGHT
63566357
add d ; increase Y by height of tile
63576358
ld d, a
63586359
inc hl
@@ -6366,7 +6367,7 @@ LoadPlayerBackPic:
63666367
ldh a, [hOAMTile]
63676368
add $4 ; increase tile number by 4
63686369
ldh [hOAMTile], a
6369-
ld a, $8 ; width of tile
6370+
ld a, TILE_WIDTH
63706371
add e ; increase X by width of tile
63716372
ld e, a
63726373
dec b
@@ -6381,7 +6382,7 @@ LoadPlayerBackPic:
63816382
ld de, sSpriteBuffer1
63826383
ldh a, [hLoadedROMBank]
63836384
ld b, a
6384-
ld c, 7 * 7
6385+
ld c, PIC_SIZE
63856386
call CopyVideoData
63866387
xor a
63876388
ld [rRAMG], a

engine/battle/draw_hud_pokeball_gfx.asm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ WritePokeballOAMData:
119119
PlacePlayerHUDTiles:
120120
ld hl, PlayerBattleHUDGraphicsTiles
121121
ld de, wHUDGraphicsTiles
122-
ld bc, $3
122+
ld bc, wHUDGraphicsTilesEnd - wHUDGraphicsTiles
123123
call CopyData
124124
hlcoord 18, 10
125125
ld de, -1
@@ -134,7 +134,7 @@ PlayerBattleHUDGraphicsTiles:
134134
PlaceEnemyHUDTiles:
135135
ld hl, EnemyBattleHUDGraphicsTiles
136136
ld de, wHUDGraphicsTiles
137-
ld bc, $3
137+
ld bc, wHUDGraphicsTilesEnd - wHUDGraphicsTiles
138138
call CopyData
139139
hlcoord 1, 2
140140
ld de, $1
@@ -150,7 +150,7 @@ PlaceHUDTiles:
150150
ld [hl], $73
151151
ld bc, SCREEN_WIDTH
152152
add hl, bc
153-
ld a, [wHUDGraphicsTiles + 1] ; leftmost tile
153+
ld a, [wHUDCornerTile] ; leftmost tile
154154
ld [hl], a
155155
ld a, 8
156156
.loop
@@ -159,7 +159,7 @@ PlaceHUDTiles:
159159
dec a
160160
jr nz, .loop
161161
add hl, de
162-
ld a, [wHUDGraphicsTiles + 2] ; rightmost tile
162+
ld a, [wHUDTriangleTile] ; rightmost tile
163163
ld [hl], a
164164
ret
165165

engine/battle/effects.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ PrintStatText:
754754
jr .findStatName_inner
755755
.foundStatName
756756
ld de, wStringBuffer
757-
ld bc, $a
757+
ld bc, NAME_LENGTH - 1 ; all StatModTextStrings are at most 10 bytes
758758
jp CopyData
759759

760760
INCLUDE "data/battle/stat_mod_names.asm"

engine/battle/ghost_marowak_anim.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ MarowakAnim:
5252
CopyMonPicFromBGToSpriteVRAM:
5353
ld de, vFrontPic
5454
ld hl, vSprites
55-
ld bc, 7 * 7
55+
ld bc, PIC_SIZE
5656
call CopyVideoData
5757
ld a, $10
5858
ld [wBaseCoordY], a

engine/battle/move_effects/transform.asm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,15 @@ TransformEffect_:
8282
ld a, [hli]
8383
ld [de], a
8484
inc de
85-
; Attack, Defense, Speed, and Special stats
85+
; Skip level and max HP
8686
inc hl
8787
inc hl
8888
inc hl
8989
inc de
9090
inc de
9191
inc de
92-
ld bc, $8
92+
; Attack, Defense, Speed, and Special stats
93+
ld bc, (NUM_STATS - 1) * 2
9394
call CopyData
9495
ld bc, wBattleMonMoves - wBattleMonPP
9596
add hl, bc ; ld hl, wBattleMonMoves
@@ -99,7 +100,7 @@ TransformEffect_:
99100
ld a, [hli]
100101
and a
101102
jr z, .lessThanFourMoves
102-
ld a, $5
103+
ld a, 5
103104
ld [de], a
104105
inc de
105106
dec b
@@ -136,7 +137,7 @@ TransformEffect_:
136137
ld l, e
137138
pop de
138139
.gotStatsOrModsToCopy
139-
ld bc, $8
140+
ld bc, (NUM_STATS - 1) * 2
140141
jp CopyData
141142

142143
.failed

engine/battle/trainer_ai.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ AISwitchIfEnoughMons:
583583

584584
SwitchEnemyMon:
585585

586-
; prepare to withdraw the active monster: copy hp, number, and status to roster
586+
; prepare to withdraw the active monster: copy HP, party pos, and status to roster
587587

588588
ld a, [wEnemyMonPartyPos]
589589
ld hl, wEnemyMon1HP
@@ -592,7 +592,7 @@ SwitchEnemyMon:
592592
ld d, h
593593
ld e, l
594594
ld hl, wEnemyMonHP
595-
ld bc, 4
595+
ld bc, MON_STATUS + 1 - MON_HP ; also copies party pos in-between HP and status
596596
call CopyData
597597

598598
ld hl, AIBattleWithdrawText

engine/events/in_game_trades.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ InGameTrade_CopyDataToReceivedMon:
226226
ld bc, wPartyMon2 - wPartyMon1
227227
call InGameTrade_GetReceivedMonPointer
228228
ld hl, wTradedEnemyMonOTID
229-
ld bc, $2
229+
ld bc, 2
230230
jp CopyData
231231

232232
; the received mon's index is (partyCount - 1),

0 commit comments

Comments
 (0)