2017-12-14 05:36:24 +00:00
|
|
|
; Syntactic sugar macros
|
|
|
|
|
|
|
|
lb: MACRO ; r, hi, lo
|
|
|
|
ld \1, (\2 & $ff) << 8 + (\3 & $ff)
|
2017-12-28 21:31:16 +00:00
|
|
|
ENDM
|
2017-12-14 05:36:24 +00:00
|
|
|
|
|
|
|
ln: MACRO ; r, hi, lo
|
|
|
|
ld \1, (\2 & $f) << 4 + (\3 & $f)
|
2017-12-28 21:31:16 +00:00
|
|
|
ENDM
|
2017-12-14 05:36:24 +00: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 21:31:16 +00:00
|
|
|
ENDM
|
2017-12-14 05:36:24 +00: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 21:31:16 +00:00
|
|
|
ENDM
|
2017-12-14 05:36:24 +00:00
|
|
|
|
2017-12-28 12:23:44 +00:00
|
|
|
maskbits: MACRO
|
2018-01-10 16:57:28 +00:00
|
|
|
; masks just enough bits to cover the argument
|
2018-01-16 22:27:50 +00:00
|
|
|
; e.g. "maskbits 26" becomes "and %00011111" (since 26 - 1 = %00011001)
|
2017-12-14 05:36:24 +00:00
|
|
|
; example usage in rejection sampling:
|
|
|
|
; .loop
|
|
|
|
; call Random
|
2018-02-03 18:26:34 +00:00
|
|
|
; maskbits 26
|
|
|
|
; cp 26
|
2017-12-14 05:36:24 +00:00
|
|
|
; jr nc, .loop
|
|
|
|
x = 1
|
|
|
|
rept 8
|
2018-01-16 22:27:50 +00:00
|
|
|
if x + 1 < (\1)
|
|
|
|
x = x << 1 | 1
|
2017-12-24 17:47:30 +00:00
|
|
|
endc
|
2017-12-14 05:36:24 +00:00
|
|
|
endr
|
|
|
|
and x
|
2017-12-28 21:31:16 +00:00
|
|
|
ENDM
|