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

@@ -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