Skip to content

Commit

Permalink
Add more assert cases in the codebase (#1115)
Browse files Browse the repository at this point in the history
* Add assert for FACING_GRASS_1 and FACING_GRASS_2

* Add more assert cases

* Add assert for HP bar colors

* Assert LINK_NULL == 0

* Fix assert syntax

* Add asserts for WILD_BATTLE == 1

* Add additional WILD assert

- I need to sleep more...

* Revert asserts for WILD_BATTLE and LINK_NULL

* Commit suggested changes

* Add more assert cases

* Fix syntax error
  • Loading branch information
Idain authored Apr 27, 2024
1 parent b9dce73 commit 4432df0
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 38 deletions.
6 changes: 4 additions & 2 deletions engine/battle/core.asm
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,8 @@ ParsePlayerAction:
jr nz, .locked_in
xor a
ld [wMoveSelectionMenuType], a
inc a ; POUND
assert POUND == 1
inc a
ld [wFXAnimID], a
call MoveSelectionScreen
push af
Expand Down Expand Up @@ -3826,7 +3827,8 @@ TryToRunAwayFromBattle:
cp BATTLEACTION_FORFEIT
ld a, DRAW
jr z, .fled
dec a ; LOSE
assert DRAW - 1 == LOSE
dec a
.fled
ld b, a
ld a, [wBattleResult]
Expand Down
63 changes: 42 additions & 21 deletions engine/battle_anims/functions.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,9 @@ BattleAnimFunc_Sing:
ld hl, BATTLEANIMSTRUCT_PARAM
add hl, bc
ld a, BATTLE_ANIM_FRAMESET_MUSIC_NOTE_1
add [hl] ; BATTLE_ANIM_FRAMESET_MUSIC_NOTE_2 BATTLE_ANIM_FRAMESET_MUSIC_NOTE_3
assert BATTLE_ANIM_FRAMESET_MUSIC_NOTE_1 + 1 == BATTLE_ANIM_FRAMESET_MUSIC_NOTE_2 \
&& BATTLE_ANIM_FRAMESET_MUSIC_NOTE_2 + 1 == BATTLE_ANIM_FRAMESET_MUSIC_NOTE_3
add [hl]
call ReinitBattleAnimFrameset

.one
Expand Down Expand Up @@ -1510,15 +1512,15 @@ BattleAnimFunc_Clamp_Encore:
ld hl, BATTLEANIMSTRUCT_VAR2
add hl, bc
ld a, [hl]
inc a ; BATTLE_ANIM_FRAMESET_3B (Clamp Flipped)
; BATTLE_ANIM_FRAMESET_A1 (Hands Flipped)
assert BATTLE_ANIM_FRAMESET_CLAMP + 1 == BATTLE_ANIM_FRAMESET_CLAMP_FLIPPED
assert BATTLE_ANIM_FRAMESET_ENCORE_HAND + 1 == BATTLE_ANIM_FRAMESET_ENCORE_HAND_FLIPPED
inc a
jr .reinit

.load_no_inc
ld hl, BATTLEANIMSTRUCT_VAR2
add hl, bc
ld a, [hl] ; BATTLE_ANIM_FRAMESET_3A (Clamp)
; BATTLE_ANIM_FRAMESET_A0 (Hands)
ld a, [hl] ; BATTLE_ANIM_FRAMESET_CLAMP or BATTLE_ANIM_FRAMESET_ENCORE_HAND
.reinit
call ReinitBattleAnimFrameset
ld hl, BATTLEANIMSTRUCT_VAR1
Expand Down Expand Up @@ -1844,8 +1846,10 @@ BattleAnimFunc_Wrap:
ld hl, BATTLEANIMSTRUCT_FRAMESET_ID
add hl, bc
ld a, [hl]
inc a ; BATTLE_ANIM_FRAMESET_BIND_2
; BATTLE_ANIM_FRAMESET_BIND_4
assert BATTLE_ANIM_FRAMESET_BIND_1 + 1 == BATTLE_ANIM_FRAMESET_BIND_2 \
&& BATTLE_ANIM_FRAMESET_BIND_2 + 1 == BATTLE_ANIM_FRAMESET_BIND_3 \
&& BATTLE_ANIM_FRAMESET_BIND_3 + 1 == BATTLE_ANIM_FRAMESET_BIND_4
inc a
call ReinitBattleAnimFrameset
call BattleAnim_IncAnonJumptableIndex
ld hl, BATTLEANIMSTRUCT_VAR1 ; Unused?
Expand Down Expand Up @@ -2344,7 +2348,9 @@ BattleAnimFunc_Sound:
ld hl, BATTLEANIMSTRUCT_PARAM
add hl, bc
ld a, BATTLE_ANIM_FRAMESET_SOUND_1
add [hl] ; BATTLE_ANIM_FRAMESET_SOUND_2 BATTLE_ANIM_FRAMESET_SOUND_3
assert BATTLE_ANIM_FRAMESET_SOUND_1 + 1 == BATTLE_ANIM_FRAMESET_SOUND_2 \
&& BATTLE_ANIM_FRAMESET_SOUND_2 + 1 == BATTLE_ANIM_FRAMESET_SOUND_3
add [hl]
call ReinitBattleAnimFrameset
ret

Expand Down Expand Up @@ -2420,7 +2426,8 @@ BattleAnimFunc_ConfuseRay:
and $80
rlca
ld [hl], a
add BATTLE_ANIM_FRAMESET_CONFUSE_RAY_1 ; BATTLE_ANIM_FRAMESET_CONFUSE_RAY_2
assert BATTLE_ANIM_FRAMESET_CONFUSE_RAY_1 + 1 == BATTLE_ANIM_FRAMESET_CONFUSE_RAY_2
add BATTLE_ANIM_FRAMESET_CONFUSE_RAY_1
call ReinitBattleAnimFrameset
ret

Expand Down Expand Up @@ -2490,8 +2497,9 @@ BattleAnimFunc_Dizzy:
rlca
ld hl, BATTLEANIMSTRUCT_VAR1
add hl, bc
add [hl] ; BATTLE_ANIM_FRAMESET_61 BATTLE_ANIM_FRAMESET_62
; BATTLE_ANIM_FRAMESET_9C BATTLE_ANIM_FRAMESET_9D
assert BATTLE_ANIM_FRAMESET_CHICK_1 + 1 == BATTLE_ANIM_FRAMESET_CHICK_2
assert BATTLE_ANIM_FRAMESET_IMP + 1 == BATTLE_ANIM_FRAMESET_IMP_FLIPPED
add [hl]
call ReinitBattleAnimFrameset
ld hl, BATTLEANIMSTRUCT_PARAM
add hl, bc
Expand Down Expand Up @@ -2528,15 +2536,15 @@ BattleAnimFunc_Dizzy:
ld hl, BATTLEANIMSTRUCT_VAR1
add hl, bc
ld a, [hl]
inc a ; BATTLE_ANIM_FRAMESET_62
; BATTLE_ANIM_FRAMESET_9D
assert BATTLE_ANIM_FRAMESET_CHICK_1 + 1 == BATTLE_ANIM_FRAMESET_CHICK_2
assert BATTLE_ANIM_FRAMESET_IMP + 1 == BATTLE_ANIM_FRAMESET_IMP_FLIPPED
inc a
jr .got_frameset

.not_flipped
ld hl, BATTLEANIMSTRUCT_VAR1
add hl, bc
ld a, [hl] ; BATTLE_ANIM_FRAMESET_61
; BATTLE_ANIM_FRAMESET_9C
ld a, [hl] ; BATTLE_ANIM_FRAMESET_CHICK_1 or BATTLE_ANIM_FRAMESET_IMP
.got_frameset
call ReinitBattleAnimFrameset
ret
Expand All @@ -2556,7 +2564,9 @@ BattleAnimFunc_Amnesia:
ld hl, BATTLEANIMSTRUCT_PARAM
add hl, bc
ld a, [hl]
add BATTLE_ANIM_FRAMESET_AMNESIA_1 ; BATTLE_ANIM_FRAMESET_AMNESIA_2 BATTLE_ANIM_FRAMESET_AMNESIA_3
assert BATTLE_ANIM_FRAMESET_AMNESIA_1 + 1 == BATTLE_ANIM_FRAMESET_AMNESIA_2 \
&& BATTLE_ANIM_FRAMESET_AMNESIA_2 + 1 == BATTLE_ANIM_FRAMESET_AMNESIA_3
add BATTLE_ANIM_FRAMESET_AMNESIA_1
call ReinitBattleAnimFrameset
ld hl, BATTLEANIMSTRUCT_PARAM
add hl, bc
Expand Down Expand Up @@ -2644,7 +2654,9 @@ BattleAnimFunc_String:
add hl, bc
set OAM_Y_FLIP, [hl]
.not_param_zero
add BATTLE_ANIM_FRAMESET_STRING_SHOT_1 ; BATTLE_ANIM_FRAMESET_STRING_SHOT_2 BATTLE_ANIM_FRAMESET_STRING_SHOT_3
assert BATTLE_ANIM_FRAMESET_STRING_SHOT_1 + 1 == BATTLE_ANIM_FRAMESET_STRING_SHOT_2 \
&& BATTLE_ANIM_FRAMESET_STRING_SHOT_2 + 1 == BATTLE_ANIM_FRAMESET_STRING_SHOT_3
add BATTLE_ANIM_FRAMESET_STRING_SHOT_1
call ReinitBattleAnimFrameset
.one
ret
Expand Down Expand Up @@ -3541,7 +3553,9 @@ BattleAnimFunc_SpeedLine:
add hl, bc
ld a, [hl]
and $7f
add BATTLE_ANIM_FRAMESET_SPEED_LINE_1 ; BATTLE_ANIM_FRAMESET_SPEED_LINE_2 BATTLE_ANIM_FRAMESET_SPEED_LINE_3
assert BATTLE_ANIM_FRAMESET_SPEED_LINE_1 + 1 == BATTLE_ANIM_FRAMESET_SPEED_LINE_2 \
&& BATTLE_ANIM_FRAMESET_SPEED_LINE_2 + 1 == BATTLE_ANIM_FRAMESET_SPEED_LINE_3
add BATTLE_ANIM_FRAMESET_SPEED_LINE_1
call ReinitBattleAnimFrameset
.one
ld hl, BATTLEANIMSTRUCT_PARAM
Expand Down Expand Up @@ -3713,8 +3727,13 @@ BattleAnimFunc_LockOnMindReader:
and $f
ld hl, BATTLEANIMSTRUCT_FRAMESET_ID
add hl, bc
add [hl] ; BATTLE_ANIM_FRAMESET_8F BATTLE_ANIM_FRAMESET_90 BATTLE_ANIM_FRAMESET_91
; BATTLE_ANIM_FRAMESET_93 BATTLE_ANIM_FRAMESET_94 BATTLE_ANIM_FRAMESET_95
assert BATTLE_ANIM_FRAMESET_LOCK_ON_1 + 1 == BATTLE_ANIM_FRAMESET_LOCK_ON_2 \
&& BATTLE_ANIM_FRAMESET_LOCK_ON_2 + 1 == BATTLE_ANIM_FRAMESET_LOCK_ON_3 \
&& BATTLE_ANIM_FRAMESET_LOCK_ON_3 + 1 == BATTLE_ANIM_FRAMESET_LOCK_ON_4
assert BATTLE_ANIM_FRAMESET_MIND_READER_1 + 1 == BATTLE_ANIM_FRAMESET_MIND_READER_2 \
&& BATTLE_ANIM_FRAMESET_MIND_READER_2 + 1 == BATTLE_ANIM_FRAMESET_MIND_READER_3 \
&& BATTLE_ANIM_FRAMESET_MIND_READER_3 + 1 == BATTLE_ANIM_FRAMESET_MIND_READER_4
add [hl]
call ReinitBattleAnimFrameset
ld hl, BATTLEANIMSTRUCT_PARAM
add hl, bc
Expand Down Expand Up @@ -3774,7 +3793,9 @@ BattleAnimFunc_HealBellNotes:
ld hl, BATTLEANIMSTRUCT_PARAM
add hl, bc
ld a, BATTLE_ANIM_FRAMESET_MUSIC_NOTE_1
add [hl] ; BATTLE_ANIM_FRAMESET_MUSIC_NOTE_2 BATTLE_ANIM_FRAMESET_MUSIC_NOTE_3
assert BATTLE_ANIM_FRAMESET_MUSIC_NOTE_1 + 1 == BATTLE_ANIM_FRAMESET_MUSIC_NOTE_2 \
&& BATTLE_ANIM_FRAMESET_MUSIC_NOTE_2 + 1 == BATTLE_ANIM_FRAMESET_MUSIC_NOTE_3
add [hl]
call ReinitBattleAnimFrameset
.one
ld hl, BATTLEANIMSTRUCT_YOFFSET
Expand Down
9 changes: 6 additions & 3 deletions engine/items/pack.asm
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,14 @@ TossMenu:

ResetPocketCursorPositions: ; unreferenced
ld a, [wCurPocket]
and a ; ITEM_POCKET
assert ITEM_POCKET == 0
and a
jr z, .items
dec a ; BALL_POCKET
assert BALL_POCKET == 1
dec a
jr z, .balls
dec a ; KEY_ITEM_POCKET
assert KEY_ITEM_POCKET == 2
dec a
jr z, .key
ret

Expand Down
5 changes: 3 additions & 2 deletions engine/link/link.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2212,7 +2212,8 @@ endc
call DelayFrames
xor a
ldh [hVBlank], a
inc a ; LINK_TIMECAPSULE
assert LINK_TIMECAPSULE == 1
inc a
ld [wLinkMode], a
ret

Expand Down Expand Up @@ -2285,7 +2286,7 @@ SetBitsForTimeCapsuleRequest:
ldh [rSC], a
ld a, (1 << rSC_ON) | (0 << rSC_CLOCK)
ldh [rSC], a
xor a ; LINK_TIMECAPSULE - 1
xor a ; LINK_NULL
ld [wPlayerLinkAction], a
ld [wChosenCableClubRoom], a
ret
Expand Down
6 changes: 3 additions & 3 deletions engine/overworld/map_object_action.asm
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ SetFacingBoulderDust:
and 2
ld a, FACING_BOULDER_DUST_1
jr z, .ok
inc a
assert FACING_BOULDER_DUST_1 + 1 == FACING_BOULDER_DUST_2
inc a
.ok
ld [hl], a
ret
Expand All @@ -291,8 +291,8 @@ SetFacingGrassShake:
and 4
ld a, FACING_GRASS_1
jr z, .ok
inc a ; FACING_GRASS_2

assert FACING_GRASS_1 + 1 == FACING_GRASS_2
inc a
.ok
ld [hl], a
ret
3 changes: 2 additions & 1 deletion engine/pokegear/pokegear.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2539,7 +2539,8 @@ Pokedex_GetArea:
ld a, [wPlayerGender]
bit PLAYERGENDER_FEMALE_F, a
jr z, .male
inc c ; PAL_OW_BLUE
assert PAL_OW_RED + 1 == PAL_OW_BLUE
inc c
.male
ld a, c
ld [hli], a ; attributes
Expand Down
12 changes: 8 additions & 4 deletions engine/pokemon/european_mail.asm
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ ParseMailLanguage:
cp "E"
ret nz
ld a, [hli]
inc c ; MAIL_LANG_FRENCH
assert MAIL_LANG_ENGLISH + 1 == MAIL_LANG_FRENCH
inc c
cp "F"
ret z
inc c ; MAIL_LANG_GERMAN
assert MAIL_LANG_FRENCH + 1 == MAIL_LANG_GERMAN
inc c
cp "G"
ret z
inc c ; MAIL_LANG_ITALIAN
assert MAIL_LANG_GERMAN + 1 == MAIL_LANG_ITALIAN
inc c
cp "I"
ret z
inc c ; MAIL_LANG_SPANISH
assert MAIL_LANG_ITALIAN + 1 == MAIL_LANG_SPANISH
inc c
cp "S"
ret z
ld c, MAIL_LANG_ENGLISH
Expand Down
6 changes: 4 additions & 2 deletions home/tilemap.asm
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,10 @@ GetHPPal::
ld a, e
cp (HP_BAR_LENGTH_PX * 50 / 100) ; 24
ret nc
inc d ; HP_YELLOW
assert HP_GREEN + 1 == HP_YELLOW
inc d
cp (HP_BAR_LENGTH_PX * 21 / 100) ; 10
ret nc
inc d ; HP_RED
assert HP_YELLOW + 1 == HP_RED
inc d
ret

0 comments on commit 4432df0

Please sign in to comment.