Use more assertions to ensure correct code and data

This commit is contained in:
Rangi 2020-10-26 22:24:38 -04:00
parent 9dcdad5e60
commit c85ba78b77
16 changed files with 50 additions and 17 deletions

View File

@ -21,7 +21,8 @@ Sfx_Menu:
Sfx_ReadText:
Sfx_ReadText2:
channel_count 1
channel 5, Sfx_ReadText_Ch5 ; aka Sfx_ReadText2_Ch5
channel 5, Sfx_ReadText_Ch5
assert Sfx_ReadText_Ch5 == Sfx_ReadText2_Ch5
Sfx_Poison:
channel_count 1
@ -486,10 +487,14 @@ Sfx_Elevator:
Sfx_LevelUp:
Sfx_DexFanfare5079:
channel_count 4
channel 5, Sfx_LevelUp_Ch5 ; aka Sfx_DexFanfare5079_Ch5
channel 6, Sfx_LevelUp_Ch6 ; aka Sfx_DexFanfare5079_Ch6
channel 7, Sfx_LevelUp_Ch7 ; aka Sfx_DexFanfare5079_Ch7
channel 8, Sfx_LevelUp_Ch8 ; aka Sfx_DexFanfare5079_Ch8
channel 5, Sfx_LevelUp_Ch5
channel 6, Sfx_LevelUp_Ch6
channel 7, Sfx_LevelUp_Ch7
channel 8, Sfx_LevelUp_Ch8
assert Sfx_LevelUp_Ch5 == Sfx_DexFanfare5079_Ch5
assert Sfx_LevelUp_Ch6 == Sfx_DexFanfare5079_Ch6
assert Sfx_LevelUp_Ch7 == Sfx_DexFanfare5079_Ch7
assert Sfx_LevelUp_Ch8 == Sfx_DexFanfare5079_Ch8
Sfx_LevelUp_Ch5:
Sfx_DexFanfare5079_Ch5:

View File

@ -144,7 +144,7 @@ SFX:
dba Sfx_MilkDrink
dba Sfx_Present
dba Sfx_MorningSun
dba Sfx_LevelUp ; aka Sfx_DexFanfare5079
dba Sfx_LevelUp
dba Sfx_KeyItem
dba Sfx_Fanfare2
dba Sfx_RegisterPhoneNumber

View File

@ -7781,7 +7781,8 @@ HandleSafariAngerEatingStatus: ; unreferenced
jr .finish
.angry
dec hl ; wSafariMonAngerCount
dec hl
assert wSafariMonEating - 1 == wSafariMonAngerCount
ld a, [hl]
and a
ret z

View File

@ -245,7 +245,8 @@ BattleAnim_ClearOAM:
ld c, NUM_SPRITE_OAM_STRUCTS
.loop
ld a, [hl]
and $ff ^ (PALETTE_MASK | VRAM_BANK_1) ; PAL_BATTLE_OB_ENEMY (0)
and $ff ^ (PALETTE_MASK | VRAM_BANK_1) ; zeros out the palette bits
assert PAL_BATTLE_OB_ENEMY == 0
ld [hli], a
rept SPRITEOAMSTRUCT_LENGTH - 1
inc hl

View File

@ -68,7 +68,8 @@ ContestJudging_ThirdPlaceScoreText:
LoadContestantName:
; If a = 1, get your name.
dec a ; BUG_CONTEST_PLAYER
assert BUG_CONTEST_PLAYER == 1
dec a
jr z, .player
; Find the pointer for the trainer class of the Bug Catching Contestant whose ID is in a.
ld c, a

View File

@ -208,7 +208,8 @@ GetMonBackpic:
push de
; These are assumed to be at the same address in their respective banks.
ld hl, PokemonPicPointers ; UnownPicPointers
assert PokemonPicPointers == UnownPicPointers
ld hl, PokemonPicPointers
ld a, b
ld d, BANK(PokemonPicPointers)
cp UNOWN

View File

@ -273,7 +273,8 @@ SetFacingBoulderDust:
and 2
ld a, FACING_BOULDER_DUST_1
jr z, .ok
inc a ; FACING_BOULDER_DUST_2
inc a
assert FACING_BOULDER_DUST_1 + 1 == FACING_BOULDER_DUST_2
.ok
ld [hl], a
ret

View File

@ -175,7 +175,8 @@ EnterMapWarp:
; MOUNT_MOON_SQUARE and TIN_TOWER_ROOF are outdoor maps within indoor maps.
; Dig and Escape Rope should not take you to them.
ld a, [wPrevMapGroup]
cp GROUP_MOUNT_MOON_SQUARE ; aka GROUP_TIN_TOWER_ROOF
cp GROUP_MOUNT_MOON_SQUARE
assert GROUP_MOUNT_MOON_SQUARE == GROUP_TIN_TOWER_ROOF
jr nz, .not_mt_moon_or_tin_tower
ld a, [wPrevMapNumber]
cp MAP_MOUNT_MOON_SQUARE

View File

@ -334,6 +334,7 @@ OaksPKMNTalk8:
; so no need for a retry loop
call Random
maskbits NUM_OAKS_POKEMON_TALK_ADVERBS
assert_power_of_2 NUM_OAKS_POKEMON_TALK_ADVERBS
ld e, a
ld d, 0
ld hl, .Adverbs
@ -433,6 +434,7 @@ OaksPKMNTalk9:
; so no need for a retry loop
call Random
maskbits NUM_OAKS_POKEMON_TALK_ADJECTIVES
assert_power_of_2 NUM_OAKS_POKEMON_TALK_ADJECTIVES
ld e, a
ld d, 0
ld hl, .Adjectives
@ -1130,6 +1132,7 @@ PeoplePlaces5:
; so no need for a retry loop
call Random
maskbits NUM_PNP_PEOPLE_ADJECTIVES
assert_power_of_2 NUM_PNP_PEOPLE_ADJECTIVES
ld e, a
ld d, 0
ld hl, .Adjectives
@ -1263,6 +1266,7 @@ PeoplePlaces7:
; so no need for a retry loop
call Random
maskbits NUM_PNP_PLACES_ADJECTIVES
assert_power_of_2 NUM_PNP_PLACES_ADJECTIVES
ld e, a
ld d, 0
ld hl, .Adjectives

View File

@ -1,9 +1,9 @@
RGB 31, 31, 63
dw $ffff ; RGB 31, 31, 63
RGB 00, 00, 00
RGB 00, 00, 00
RGB 00, 00, 00
RGB 31, 31, 63
dw $ffff ; RGB 31, 31, 63
RGB 00, 00, 00
RGB 00, 00, 00
RGB 00, 00, 00

View File

@ -38,6 +38,7 @@ maskbits: MACRO
; maskbits 26
; cp 26
; jr nc, .loop
assert 0 < (\1) && (\1) <= $100, "bitmask must be 8-bit"
x = 1
rept 8
if x + 1 < (\1)

View File

@ -25,6 +25,10 @@ percent EQUS "* $ff / 100"
; e.g. 1 out_of 2 == 50 percent + 1 == $80
out_of EQUS "* $100 /"
assert_power_of_2: MACRO
assert (\1) & ((\1) - 1) == 0, "\1 must be a power of 2"
ENDM
; Constant data (db, dw, dl) macros
dwb: MACRO

View File

@ -1,5 +1,13 @@
assert_valid_rgb: MACRO
rept _NARG
assert 0 <= (\1) && (\1) <= 31, "RGB channel must be 0-31"
shift
endr
ENDM
RGB: MACRO
rept _NARG / 3
assert_valid_rgb \1, \2, \3
dw palred (\1) + palgreen (\2) + palblue (\3)
shift 3
endr

View File

@ -1,8 +1,12 @@
channel_count: MACRO
assert 0 < (\1) && (\1) <= NUM_MUSIC_CHANS, \
"channel_count must be 1-{d:NUM_MUSIC_CHANS}"
_num_channels = \1 - 1
ENDM
channel: MACRO
assert 0 < (\1) && (\1) <= NUM_CHANNELS, \
"channel id must be 1-{d:NUM_CHANNELS}"
dn (_num_channels << 2), \1 - 1 ; channel id
dw \2 ; address
_num_channels = 0
@ -46,6 +50,7 @@ FIRST_MUSIC_CMD EQU const_value
const octave_cmd ; $d0
octave: MACRO
assert 0 < (\1) && (\1) < 8, "octave must be 1-8"
db octave_cmd | 8 - (\1) ; octave
ENDM

View File

@ -1,7 +1,5 @@
anim_wait: MACRO
if \1 >= $d0
fail "anim_wait argument must be less than $d0."
endc
assert (\1) < $d0, "anim_wait argument must be less than $d0"
db \1
ENDM

View File

@ -1,5 +1,7 @@
map_id: MACRO
;\1: map id
assert DEF(GROUP_\1) && DEF(MAP_\1), \
"Missing 'map_const \1' in constants/map_constants.asm"
db GROUP_\1, MAP_\1
ENDM