diff --git a/audio/sfx.asm b/audio/sfx.asm index 512b46349..c97f41522 100644 --- a/audio/sfx.asm +++ b/audio/sfx.asm @@ -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: diff --git a/audio/sfx_pointers.asm b/audio/sfx_pointers.asm index 025ef5a53..815a65708 100644 --- a/audio/sfx_pointers.asm +++ b/audio/sfx_pointers.asm @@ -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 diff --git a/engine/battle/core.asm b/engine/battle/core.asm index 56b20b9cc..97a4a4cda 100644 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -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 diff --git a/engine/battle_anims/anim_commands.asm b/engine/battle_anims/anim_commands.asm index cd14b7c67..34ef87f61 100644 --- a/engine/battle_anims/anim_commands.asm +++ b/engine/battle_anims/anim_commands.asm @@ -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 diff --git a/engine/events/bug_contest/judging.asm b/engine/events/bug_contest/judging.asm index 361aef81a..abb9d60da 100644 --- a/engine/events/bug_contest/judging.asm +++ b/engine/events/bug_contest/judging.asm @@ -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 diff --git a/engine/gfx/load_pics.asm b/engine/gfx/load_pics.asm index a8dc82892..98dbdc17b 100644 --- a/engine/gfx/load_pics.asm +++ b/engine/gfx/load_pics.asm @@ -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 diff --git a/engine/overworld/map_object_action.asm b/engine/overworld/map_object_action.asm index 35de22030..5c68f6b0f 100644 --- a/engine/overworld/map_object_action.asm +++ b/engine/overworld/map_object_action.asm @@ -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 diff --git a/engine/overworld/warp_connection.asm b/engine/overworld/warp_connection.asm index 866480d5c..a74f2015f 100644 --- a/engine/overworld/warp_connection.asm +++ b/engine/overworld/warp_connection.asm @@ -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 diff --git a/engine/pokegear/radio.asm b/engine/pokegear/radio.asm index 985657198..bc7c3195d 100644 --- a/engine/pokegear/radio.asm +++ b/engine/pokegear/radio.asm @@ -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 diff --git a/gfx/trade/mobile_border.pal b/gfx/trade/mobile_border.pal index 93e884046..95a727db3 100644 --- a/gfx/trade/mobile_border.pal +++ b/gfx/trade/mobile_border.pal @@ -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 diff --git a/macros/code.asm b/macros/code.asm index e393d4951..a5d8c7560 100644 --- a/macros/code.asm +++ b/macros/code.asm @@ -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) diff --git a/macros/data.asm b/macros/data.asm index a6656af32..3e1177f78 100644 --- a/macros/data.asm +++ b/macros/data.asm @@ -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 diff --git a/macros/gfx.asm b/macros/gfx.asm index 2c67cfc8a..b42b1440b 100644 --- a/macros/gfx.asm +++ b/macros/gfx.asm @@ -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 diff --git a/macros/scripts/audio.asm b/macros/scripts/audio.asm index 2776c293f..127f2d1e3 100644 --- a/macros/scripts/audio.asm +++ b/macros/scripts/audio.asm @@ -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 diff --git a/macros/scripts/battle_anims.asm b/macros/scripts/battle_anims.asm index 123a262ab..a6ebe4310 100644 --- a/macros/scripts/battle_anims.asm +++ b/macros/scripts/battle_anims.asm @@ -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 diff --git a/macros/scripts/maps.asm b/macros/scripts/maps.asm index d9ffd83e1..a30e0c06a 100644 --- a/macros/scripts/maps.asm +++ b/macros/scripts/maps.asm @@ -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