pokecrystal-board/macros/code.asm

58 lines
826 B
NASM
Raw Normal View History

2017-12-13 21:36:24 -08:00
; Syntactic sugar macros
lb: MACRO ; r, hi, lo
ld \1, (\2 & $ff) << 8 + (\3 & $ff)
2017-12-28 13:31:16 -08:00
ENDM
2017-12-13 21:36:24 -08:00
ln: MACRO ; r, hi, lo
ld \1, (\2 & $f) << 4 + (\3 & $f)
2017-12-28 13:31:16 -08:00
ENDM
2017-12-13 21:36:24 -08:00
ldpixel: MACRO
if _NARG >= 5
lb \1, \2 * 8 + \4, \3 * 8 + \5
else
lb \1, \2 * 8, \3 * 8
endc
2017-12-28 13:31:16 -08:00
ENDM
2017-12-13 21:36:24 -08:00
depixel EQUS "ldpixel de,"
bcpixel EQUS "ldpixel bc,"
; Design patterns
jumptable: MACRO
ld a, [\2]
ld e, a
ld d, 0
ld hl, \1
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
2017-12-28 13:31:16 -08:00
ENDM
2017-12-13 21:36:24 -08:00
; Many mobile functions were dummied out in localization.
mobile EQUS "ret"
maskbits: MACRO
; masks just enough bits to cover the argument
; e.g. "maskbits %00010100" becomes "and %00011111"
2017-12-13 21:36:24 -08:00
; example usage in rejection sampling:
; .loop
; call Random
; maskbits 30 +- 1
2017-12-13 21:36:24 -08:00
; cp 30
; jr nc, .loop
x = 1
rept 8
if x < (\1)
2017-12-13 21:36:24 -08:00
x = (x + 1) * 2 +- 1
2017-12-24 09:47:30 -08:00
endc
2017-12-13 21:36:24 -08:00
endr
and x
2017-12-28 13:31:16 -08:00
ENDM