Skip to content

Commit 4d2594c

Browse files
authored
Label and constant cleanup (#528)
* Label cleanup, add some constants instead of raw numbers * Rename load/save game functions to be more explicit
1 parent d98b5e6 commit 4d2594c

30 files changed

+221
-214
lines changed

constants/ram_constants.asm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ DEF BIT_NO_PREVIOUS_MAP EQU 7
4949

5050
; wCurrentBoxNum
5151
DEF BIT_HAS_CHANGED_BOXES EQU 7
52+
DEF BOX_NUM_MASK EQU %01111111
5253

5354
; wObtainedBadges, wBeatGymFlags
5455
const_def
@@ -153,3 +154,6 @@ DEF NUM_BADGES EQU const_value
153154
const_def
154155
const BIT_PLAYER_LOWER_Y ; 0
155156
const BIT_PLAYER_LOWER_X ; 1
157+
158+
; rLCDC
159+
DEF LCDC_DEFAULT EQU LCDC_ON | LCDC_WIN_9C00 | LCDC_WIN_ON | LCDC_BLOCK21 | LCDC_BG_9800 | LCDC_OBJ_8 | LCDC_OBJ_ON | LCDC_BG_ON

data/maps/objects/Route2Gate.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object_const_def
2-
const_export ROUTE2_OAKS_AIDE
3-
const_export ROUTE2_YOUNGSTER
2+
const_export ROUTE2GATE_OAKS_AIDE
3+
const_export ROUTE2GATE_YOUNGSTER
44

55
Route2Gate_Object:
66
db $a ; border block

data/predef_pointers.asm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ PredefPointers::
5353
add_predef DoubleOrHalveSelectedStats
5454
add_predef ShowPokedexMenu
5555
add_predef EvolutionAfterBattle
56-
add_predef SaveSAVtoSRAM0
56+
add_predef SaveMainData
5757
add_predef InitOpponent
5858
add_predef CableClub_Run
5959
add_predef DrawBadges
@@ -73,7 +73,7 @@ PredefPointers::
7373
add_predef UsedCut
7474
add_predef ShowPokedexData
7575
add_predef WriteMonMoves
76-
add_predef SaveSAV
76+
add_predef SaveMenu
7777
add_predef LoadSGB
7878
add_predef MarkTownVisitedAndLoadMissableObjects
7979
add_predef SetPartyMonTypes
@@ -90,10 +90,10 @@ PredefPointers::
9090
add_predef EmptyFunc ; return immediately
9191
add_predef AskName
9292
add_predef PewterGuys
93-
add_predef SaveSAVtoSRAM2
94-
add_predef LoadSAV2
95-
add_predef LoadSAV
96-
add_predef SaveSAVtoSRAM1
93+
add_predef SavePartyAndDexData
94+
add_predef LoadPartyAndDexData
95+
add_predef TryLoadSaveFile
96+
add_predef SaveCurrentBoxData
9797
add_predef DoInGameTradeDialogue
9898
add_predef HallOfFamePC
9999
add_predef DisplayDexRating

engine/battle/core.asm

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,30 +3137,30 @@ PlayerCalcMoveDamage:
31373137
jp c, .moveHitTest ; SetDamageEffects moves (e.g. Seismic Toss and Super Fang) skip damage calculation
31383138
call CriticalHitTest
31393139
call HandleCounterMove
3140-
jr z, handleIfPlayerMoveMissed
3140+
jr z, HandleIfPlayerMoveMissed
31413141
call GetDamageVarsForPlayerAttack
31423142
call CalculateDamage
3143-
jp z, playerCheckIfFlyOrChargeEffect ; for moves with 0 BP, skip any further damage calculation and, for now, skip MoveHitTest
3143+
jp z, PlayerCheckIfFlyOrChargeEffect ; for moves with 0 BP, skip any further damage calculation and, for now, skip MoveHitTest
31443144
; for these moves, accuracy tests will only occur if they are called as part of the effect itself
31453145
call AdjustDamageForMoveType
31463146
call RandomizeDamage
31473147
.moveHitTest
31483148
call MoveHitTest
3149-
handleIfPlayerMoveMissed:
3149+
HandleIfPlayerMoveMissed:
31503150
ld a, [wMoveMissed]
31513151
and a
3152-
jr z, getPlayerAnimationType
3152+
jr z, GetPlayerAnimationType
31533153
ld a, [wPlayerMoveEffect]
31543154
sub EXPLODE_EFFECT
3155-
jr z, playPlayerMoveAnimation ; don't play any animation if the move missed, unless it was EXPLODE_EFFECT
3156-
jr playerCheckIfFlyOrChargeEffect
3157-
getPlayerAnimationType:
3155+
jr z, PlayPlayerMoveAnimation ; don't play any animation if the move missed, unless it was EXPLODE_EFFECT
3156+
jr PlayerCheckIfFlyOrChargeEffect
3157+
GetPlayerAnimationType:
31583158
ld a, [wPlayerMoveEffect]
31593159
and a
31603160
ld a, ANIMATIONTYPE_BLINK_ENEMY_MON_SPRITE ; move has no effect other than dealing damage
3161-
jr z, playPlayerMoveAnimation
3161+
jr z, PlayPlayerMoveAnimation
31623162
ld a, ANIMATIONTYPE_SHAKE_SCREEN_HORIZONTALLY_LIGHT ; move has effect
3163-
playPlayerMoveAnimation:
3163+
PlayPlayerMoveAnimation:
31643164
push af
31653165
ld a, [wPlayerBattleStatus2]
31663166
bit HAS_SUBSTITUTE_UP, a
@@ -3179,7 +3179,7 @@ playPlayerMoveAnimation:
31793179
ld b, BANK(ReshowSubstituteAnim)
31803180
call nz, Bankswitch
31813181
jr MirrorMoveCheck
3182-
playerCheckIfFlyOrChargeEffect:
3182+
PlayerCheckIfFlyOrChargeEffect:
31833183
ld c, 30
31843184
call DelayFrames
31853185
ld a, [wPlayerMoveEffect]
@@ -3246,7 +3246,7 @@ MirrorMoveCheck:
32463246
ld a, [wPlayerNumAttacksLeft]
32473247
dec a
32483248
ld [wPlayerNumAttacksLeft], a
3249-
jp nz, getPlayerAnimationType ; for multi-hit moves, apply attack until PlayerNumAttacksLeft hits 0 or the enemy faints.
3249+
jp nz, GetPlayerAnimationType ; for multi-hit moves, apply attack until PlayerNumAttacksLeft hits 0 or the enemy faints.
32503250
; damage calculation and accuracy tests only happen for the first hit
32513251
res ATTACKING_MULTIPLE_TIMES, [hl] ; clear attacking multiple times status when all attacks are over
32523252
ld hl, MultiHitText
@@ -3523,7 +3523,7 @@ CheckPlayerStatusConditions:
35233523
ld [hl], a
35243524
ld a, BIDE
35253525
ld [wPlayerMoveNum], a
3526-
ld hl, handleIfPlayerMoveMissed ; skip damage calculation, DecrementPP and MoveHitTest
3526+
ld hl, HandleIfPlayerMoveMissed ; skip damage calculation, DecrementPP and MoveHitTest
35273527
jp .returnToHL
35283528

35293529
.ThrashingAboutCheck
@@ -3557,7 +3557,7 @@ CheckPlayerStatusConditions:
35573557
ld a, [wPlayerNumAttacksLeft]
35583558
dec a ; did multi-turn move end?
35593559
ld [wPlayerNumAttacksLeft], a
3560-
ld hl, getPlayerAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit),
3560+
ld hl, GetPlayerAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit),
35613561
; DecrementPP and MoveHitTest
35623562
jp nz, .returnToHL
35633563
jp .returnToHL
@@ -5567,7 +5567,7 @@ RandomizeDamage:
55675567
.loop
55685568
call BattleRandom
55695569
rrca
5570-
cp 217
5570+
cp 85 percent + 1
55715571
jr c, .loop
55725572
ldh [hMultiplier], a
55735573
call Multiply ; multiply damage by the random number, which is in the range [217, 255]
@@ -5660,7 +5660,7 @@ EnemyCalcMoveDamage:
56605660
jp c, EnemyMoveHitTest
56615661
call CriticalHitTest
56625662
call HandleCounterMove
5663-
jr z, handleIfEnemyMoveMissed
5663+
jr z, HandleIfEnemyMoveMissed
56645664
call SwapPlayerAndEnemyLevels
56655665
call GetDamageVarsForEnemyAttack
56665666
call SwapPlayerAndEnemyLevels
@@ -5671,13 +5671,13 @@ EnemyCalcMoveDamage:
56715671

56725672
EnemyMoveHitTest:
56735673
call MoveHitTest
5674-
handleIfEnemyMoveMissed:
5674+
HandleIfEnemyMoveMissed:
56755675
ld a, [wMoveMissed]
56765676
and a
56775677
jr z, .moveDidNotMiss
56785678
ld a, [wEnemyMoveEffect]
56795679
cp EXPLODE_EFFECT
5680-
jr z, handleExplosionMiss
5680+
jr z, HandleExplosionMiss
56815681
jr EnemyCheckIfFlyOrChargeEffect
56825682
.moveDidNotMiss
56835683
call SwapPlayerAndEnemyLevels
@@ -5686,13 +5686,13 @@ GetEnemyAnimationType:
56865686
ld a, [wEnemyMoveEffect]
56875687
and a
56885688
ld a, ANIMATIONTYPE_SHAKE_SCREEN_VERTICALLY
5689-
jr z, playEnemyMoveAnimation
5689+
jr z, PlayEnemyMoveAnimation
56905690
ld a, ANIMATIONTYPE_SHAKE_SCREEN_HORIZONTALLY_HEAVY
5691-
jr playEnemyMoveAnimation
5692-
handleExplosionMiss:
5691+
jr PlayEnemyMoveAnimation
5692+
HandleExplosionMiss:
56935693
call SwapPlayerAndEnemyLevels
56945694
xor a
5695-
playEnemyMoveAnimation:
5695+
PlayEnemyMoveAnimation:
56965696
push af
56975697
ld a, [wEnemyBattleStatus2]
56985698
bit HAS_SUBSTITUTE_UP, a ; does mon have a substitute?
@@ -6031,7 +6031,7 @@ CheckEnemyStatusConditions:
60316031
ld a, BIDE
60326032
ld [wEnemyMoveNum], a
60336033
call SwapPlayerAndEnemyLevels
6034-
ld hl, handleIfEnemyMoveMissed ; skip damage calculation, DecrementPP and MoveHitTest
6034+
ld hl, HandleIfEnemyMoveMissed ; skip damage calculation, DecrementPP and MoveHitTest
60356035
jp .enemyReturnToHL
60366036
.checkIfThrashingAbout
60376037
bit THRASHING_ABOUT, [hl] ; is mon using thrash or petal dance?
@@ -6881,12 +6881,12 @@ _InitBattleCommon:
68816881
call PrintText
68826882
call SaveScreenTilesToBuffer1
68836883
call ClearScreen
6884-
ld a, $98
6884+
ld a, HIGH(vBGMap0)
68856885
ldh [hAutoBGTransferDest + 1], a
68866886
ld a, $1
68876887
ldh [hAutoBGTransferEnabled], a
68886888
call Delay3
6889-
ld a, $9c
6889+
ld a, HIGH(vBGMap1)
68906890
ldh [hAutoBGTransferDest + 1], a
68916891
call LoadScreenTilesFromBuffer1
68926892
hlcoord 9, 7

engine/battle/effects.asm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ _JumpMoveEffect:
77
ldh a, [hWhoseTurn]
88
and a
99
ld a, [wPlayerMoveEffect]
10-
jr z, .next1
10+
jr z, .next
1111
ld a, [wEnemyMoveEffect]
12-
.next1
12+
.next
1313
dec a ; subtract 1, there is no special effect for 00
1414
add a ; x2, 16bit pointers
1515
ld hl, MoveEffectPointerTable
@@ -680,14 +680,14 @@ UpdateLoweredStatDone:
680680
call PrintStatText
681681
pop de
682682
ld a, [de]
683-
cp $44
683+
cp ATTACK_DOWN_SIDE_EFFECT ; for all side effects, move animation has already played, skip it
684684
jr nc, .ApplyBadgeBoostsAndStatusPenalties
685685
call PlayCurrentMoveAnimation2
686686
.ApplyBadgeBoostsAndStatusPenalties
687687
ldh a, [hWhoseTurn]
688688
and a
689689
call nz, ApplyBadgeStatBoosts ; whenever the player uses a stat-down move, badge boosts get reapplied again to every stat,
690-
; even to those not affected by the stat-up move (will be boosted further)
690+
; even to those not affected by the stat-down move (will be boosted further)
691691
ld hl, MonsStatsFellText
692692
call PrintText
693693

@@ -1438,9 +1438,9 @@ CheckTargetSubstitute:
14381438
ld hl, wEnemyBattleStatus2
14391439
ldh a, [hWhoseTurn]
14401440
and a
1441-
jr z, .next1
1441+
jr z, .next
14421442
ld hl, wPlayerBattleStatus2
1443-
.next1
1443+
.next
14441444
bit HAS_SUBSTITUTE_UP, [hl]
14451445
pop hl
14461446
ret

engine/events/give_pokemon.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ _GivePokemon::
2020
callfar SendNewMonToBox
2121
ld hl, wStringBuffer
2222
ld a, [wCurrentBoxNum]
23-
and $7f
23+
and BOX_NUM_MASK
2424
cp 9
2525
jr c, .singleDigitBoxNum
2626
sub 9

engine/events/prize_menu.asm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ CeladonPrizeMenu::
22
ld b, COIN_CASE
33
call IsItemInBag
44
jr nz, .havingCoinCase
5-
ld hl, RequireCoinCaseTextPtr
5+
ld hl, RequireCoinCaseText
66
jp PrintText
77
.havingCoinCase
88
ld hl, wStatusFlags5
99
set BIT_NO_TEXT_DELAY, [hl]
10-
ld hl, ExchangeCoinsForPrizesTextPtr
10+
ld hl, ExchangeCoinsForPrizesText
1111
call PrintText
1212
; the following are the menu settings
1313
xor a
@@ -28,7 +28,7 @@ CeladonPrizeMenu::
2828
call TextBoxBorder
2929
call GetPrizeMenuId
3030
call UpdateSprites
31-
ld hl, WhichPrizeTextPtr
31+
ld hl, WhichPrizeText
3232
call PrintText
3333
call HandleMenuInput ; menu choice handler
3434
bit B_PAD_B, a
@@ -42,16 +42,16 @@ CeladonPrizeMenu::
4242
res BIT_NO_TEXT_DELAY, [hl]
4343
ret
4444

45-
RequireCoinCaseTextPtr:
45+
RequireCoinCaseText:
4646
text_far _RequireCoinCaseText
4747
text_waitbutton
4848
text_end
4949

50-
ExchangeCoinsForPrizesTextPtr:
50+
ExchangeCoinsForPrizesText:
5151
text_far _ExchangeCoinsForPrizesText
5252
text_end
5353

54-
WhichPrizeTextPtr:
54+
WhichPrizeText:
5555
text_far _WhichPrizeText
5656
text_end
5757

engine/gfx/palettes.asm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,15 +523,15 @@ CopyGfxToSuperNintendoVRAM:
523523
call CopySGBBorderTiles
524524
jr .next
525525
.notCopyingTileData
526-
ld bc, $1000
526+
ld bc, 256 tiles
527527
call CopyData
528528
.next
529529
ld hl, vBGMap0
530-
ld de, $c
530+
ld de, TILEMAP_WIDTH - SCREEN_WIDTH
531531
ld a, $80
532-
ld c, $d
532+
ld c, (256 + SCREEN_WIDTH - 1) / SCREEN_WIDTH ; enough rows to fit 256 tiles
533533
.loop
534-
ld b, $14
534+
ld b, SCREEN_WIDTH
535535
.innerLoop
536536
ld [hli], a
537537
inc a
@@ -540,7 +540,7 @@ CopyGfxToSuperNintendoVRAM:
540540
add hl, de
541541
dec c
542542
jr nz, .loop
543-
ld a, $e3
543+
ld a, LCDC_DEFAULT
544544
ldh [rLCDC], a
545545
pop hl
546546
call SendSGBPacket

engine/link/cable_club.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ TradeCenter_Trade:
861861
hlcoord 1, 14
862862
ld de, TradeCompleted
863863
call PlaceString
864-
predef SaveSAVtoSRAM2
864+
predef SavePartyAndDexData ; this allows reset into Pokecenter
865865
vc_hook Trade_save_game_end
866866
ld c, 50
867867
call DelayFrames

engine/link/cable_club_npc.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ CableClubNPC::
6464
and a
6565
jr nz, .choseNo
6666
vc_hook Wireless_TryQuickSave_block_input
67-
callfar SaveSAVtoSRAM
67+
callfar SaveGameData
6868
call WaitForSoundToFinish
6969
ld a, SFX_SAVE
7070
call PlaySoundWaitForCurrent

0 commit comments

Comments
 (0)