Skip to content

Commit

Permalink
Use compound assignment operators
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 committed Aug 4, 2024
1 parent 701be47 commit e5305b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
20 changes: 10 additions & 10 deletions src/macros/asserts.asm
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
; Macros to verify assumptions about the data or code

MACRO table_width
DEF CURRENT_TABLE_WIDTH = \1
IF _NARG == 2
REDEF CURRENT_TABLE_START EQUS "\2"
ELSE
REDEF CURRENT_TABLE_START EQUS "._table_width\@"
{CURRENT_TABLE_START}:
ENDC
DEF CURRENT_TABLE_WIDTH = \1
IF _NARG == 2
REDEF CURRENT_TABLE_START EQUS "\2"
ELSE
REDEF CURRENT_TABLE_START EQUS "._table_width\@"
{CURRENT_TABLE_START}:
ENDC
ENDM

MACRO assert_table_length
DEF x = \1
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
DEF x = 0
DEF x = 0
ENDM

; \1 = card ID
; \2 = quantity
MACRO card_item
DEF x = x + \2
DEF x += \2
db \2, \1
ENDM

Expand Down
27 changes: 11 additions & 16 deletions src/macros/data.asm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ MACRO dx
DEF x = 8 * ((\1) - 1)
REPT \1
db ((\2) >> x) & $ff
DEF x = x - 8
DEF x -= 8
ENDR
ENDM

Expand All @@ -33,18 +33,18 @@ MACRO bigdw ; big-endian word
ENDM

MACRO sgb
db \1 << 3 + \2 ; sgb_command * 8 + length
db (\1) << 3 + (\2) ; sgb_command * 8 + length
ENDM

MACRO rgb
dw (\3 << 10 | \2 << 5 | \1)
dw ((\3) << 10 | (\2) << 5 | (\1))
ENDM

; poketcg specific macros below

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
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
Expand All @@ -53,22 +53,21 @@ MACRO energy
DEF en = 0
IF _NARG > 1
REPT _NARG / 2
DEF x = 4 - 8 * (\1 % 2)
DEF en = en + \2 << ((\1 * 4) + x)
SHIFT
SHIFT
DEF x = 4 - 8 * ((\1) % 2)
DEF en += \2 << (((\1) * 4) + x)
SHIFT 2
ENDR
REPT NUM_TYPES / 2
db LOW(en)
DEF en = en >> 8
DEF en >>= 8
ENDR
ELSE
db 0, 0, 0, 0
ENDC
ENDM

MACRO gfx
dw ($4000 * (BANK(\1) - BANK(CardGraphics)) + (\1 - $4000)) / 8
dw ($4000 * (BANK(\1) - BANK(CardGraphics)) + ((\1) - $4000)) / 8
ENDM

MACRO frame_table
Expand Down Expand Up @@ -96,9 +95,5 @@ ENDM
; 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
db \1, \2, \3
REPT 4
db \4
SHIFT
ENDR
db \1, \2, \3, \4, \5, \6, \7
ENDM

0 comments on commit e5305b5

Please sign in to comment.