Use ? to silence macros

This commit is contained in:
Rangi42 2025-11-12 14:15:07 -05:00
parent 2e4dece164
commit 13729e1b4f
6 changed files with 65 additions and 51 deletions

View File

@ -1,6 +1,6 @@
; Macros to verify assumptions about the data or code
MACRO table_width
MACRO? table_width
DEF CURRENT_TABLE_WIDTH = \1
IF _NARG == 2
REDEF CURRENT_TABLE_START EQUS "\2"
@ -10,24 +10,24 @@ MACRO table_width
ENDC
ENDM
MACRO assert_table_length
MACRO? assert_table_length
DEF x = \1
ASSERT x * CURRENT_TABLE_WIDTH == @ - {CURRENT_TABLE_START}, \
"{CURRENT_TABLE_START}: expected {d:x} entries, each {d:CURRENT_TABLE_WIDTH} bytes"
ENDM
MACRO deck_list_start
MACRO? deck_list_start
DEF x = 0
ENDM
; \1 = card ID
; \2 = quantity
MACRO card_item
MACRO? card_item
DEF x += \2
db \2, \1
ENDM
MACRO deck_list_end
MACRO? deck_list_end
db 0 ; end of list
ASSERT x == DECK_SIZE, "expected {d:DECK_SIZE} cards, got {d:x}"
ENDM

View File

@ -1,8 +1,8 @@
MACRO lb ; r, hi, lo
MACRO? lb ; r, hi, lo
ld \1, (\2) << 8 + ((\3) & $ff)
ENDM
MACRO ldtx
MACRO? ldtx
IF _NARG == 2
ld \1, \2_
ELSE
@ -10,12 +10,12 @@ MACRO ldtx
ENDC
ENDM
MACRO bank1call
MACRO? bank1call
rst $18
dw \1
ENDM
MACRO farcall
MACRO? farcall
rst $28
IF _NARG == 1
db BANK(\1)
@ -27,49 +27,51 @@ MACRO farcall
ENDM
; runs SetEventValue with the next byte as the event, c as the new value
MACRO set_event_value
MACRO? set_event_value
call SetStackEventValue
db \1
ENDM
; runs ZeroOutEventValue with the next byte as the event
; functionally identical to set_event_zero but intended for single-bit events
MACRO set_event_false
MACRO? set_event_false
call SetStackEventFalse
db \1
ENDM
; runs ZeroOutEventValue with the next byte as the event
; functionally identical to set_event_false but intended for multi-bit events
MACRO set_event_zero
MACRO? set_event_zero
call SetStackEventZero
db \1
ENDM
; runs MaxOutEventValue with the next byte as the event
MACRO max_event_value
MACRO? max_event_value
call MaxStackEventValue
db \1
ENDM
; runs GetEventValue with the next byte as the event. returns value in a
MACRO get_event_value
MACRO? get_event_value
call GetStackEventValue
db \1
ENDM
; the rst $38 handler is a single ret instruction
; probably used for testing purposes during development
DEF debug_nop EQUS "rst $38"
MACRO? debug_nop
rst $38
ENDM
; Returns to the pointer in bc instead of where the stack was.
MACRO retbc
MACRO? retbc
push bc
ret
ENDM
; loads into a register the GameBoy (DMG) palette given
; by the arguments as SHADE_* constants
MACRO ldgbpal
MACRO? ldgbpal
ld \1, (\2 << 0) | (\3 << 2) | (\4 << 4) | (\5 << 6)
ENDM

View File

@ -1,4 +1,4 @@
MACRO const_def
MACRO? const_def
IF _NARG > 0
DEF const_value = \1
ELSE
@ -6,12 +6,12 @@ MACRO const_def
ENDC
ENDM
MACRO const
MACRO? const
DEF \1 EQU const_value
DEF const_value += 1
ENDM
MACRO const_skip
MACRO? const_skip
if _NARG > 0
DEF const_value += \1
else
@ -19,7 +19,7 @@ MACRO const_skip
endc
ENDM
MACRO event_def
MACRO? event_def
db \1
db \2
ENDM

View File

@ -1,66 +1,66 @@
MACRO dn
REPT _NARG / 2
db ((\1) << 4) | (\2)
SHIFT 2
ENDR
MACRO? dn
REPT _NARG / 2
db ((\1) << 4) | (\2)
SHIFT 2
ENDR
ENDM
MACRO dbw
MACRO? dbw
db \1
dw \2
ENDM
MACRO dwb
MACRO? dwb
dw \1
db \2
ENDM
MACRO dx
MACRO? dx
DEF x = 8 * ((\1) - 1)
REPT \1
REPT? \1
db ((\2) >> x) & $ff
DEF x -= 8
ENDR
ENDM
MACRO dt ; three-byte (big-endian)
MACRO? dt ; three-byte (big-endian)
dx 3, \1
ENDM
MACRO dd ; four-byte (big-endian)
MACRO? dd ; four-byte (big-endian)
dx 4, \1
ENDM
MACRO bigdw ; big-endian word
MACRO? bigdw ; big-endian word
dx 2, \1
ENDM
MACRO sgb
MACRO? sgb
db (\1) << 3 + (\2) ; sgb_command * 8 + length
ENDM
MACRO rgb
MACRO? rgb
dw ((\3) << 10 | (\2) << 5 | (\1))
ENDM
; poketcg specific macros below
MACRO textpointer
MACRO? textpointer
dw (((\1) + ($4000 * (BANK(\1) - 1))) - (TextOffsets + ($4000 * (BANK(TextOffsets) - 1)))) & $ffff
db (((\1) + ($4000 * (BANK(\1) - 1))) - (TextOffsets + ($4000 * (BANK(TextOffsets) - 1)))) >> 16
const \1_
EXPORT \1_
ENDM
MACRO energy
MACRO? energy
DEF en = 0
IF _NARG > 1
REPT _NARG / 2
REPT? _NARG / 2
DEF x = 4 - 8 * ((\1) % 2)
DEF en += \2 << (((\1) * 4) + x)
SHIFT 2
ENDR
REPT NUM_TYPES / 2
REPT? NUM_TYPES / 2
db LOW(en)
DEF en >>= 8
ENDR
@ -69,27 +69,27 @@ MACRO energy
ENDC
ENDM
MACRO gfx
MACRO? gfx
dw ($4000 * (BANK(\1) - BANK(CardGraphics)) + ((\1) - $4000)) / 8
ENDM
MACRO frame_table
MACRO? frame_table
db BANK(\1) - BANK(AnimData1) ; maybe use better reference for Bank20?
dw \1
ENDM
MACRO frame_data
MACRO? frame_data
db \1 ; frame index
db \2 ; anim count
db \3 ; x translation
db \4 ; y translation
ENDM
MACRO tx
MACRO? tx
dw \1_
ENDM
MACRO textitem
MACRO? textitem
db \1, \2
tx \3
ENDM
@ -97,10 +97,10 @@ ENDM
; cursor x / cursor y / attribute / idx-up / idx-down / idx-right / idx-left
; idx-[direction] means the index to get when the input is in the direction.
; its attribute is used for drawing a flipped cursor.
MACRO cursor_transition
MACRO? cursor_transition
db \1, \2, \3, \4, \5, \6, \7
ENDM
MACRO gbpal
MACRO? gbpal
db (\1 << 0) | (\2 << 2) | (\3 << 4) | (\4 << 6)
ENDM

View File

@ -1,4 +1,6 @@
DEF start_script EQUS "rst $20"
MACRO start_script
rst $20
ENDM
MACRO run_command
db \1_index

View File

@ -1,8 +1,18 @@
DEF text EQUS "db TX_HALFWIDTH, "
DEF line EQUS "db TX_LINE, "
DEF done EQUS "db TX_END"
MACRO text
db TX_HALFWIDTH, \#
ENDM
DEF half2full EQUS "db TX_HALF2FULL"
MACRO line
db TX_LINE, \#
ENDM
MACRO done
db TX_END
ENDM
MACRO half2full
db TX_HALF2FULL
ENDM
MACRO get_charset
PUSHC katakana