pokecrystal-board/macros/code.asm
Remy Oukaour 5c28d05bb4 Merge branch 'master' of https://github.com/xCrystal/pokecrystal (resolve PR #459)
# Conflicts:
#	data/items/descriptions.asm
#	data/sprite_anims/framesets.asm
#	engine/crystal_colors.asm
#	engine/events/kurt.asm
#	engine/events/special.asm
#	engine/events/std_scripts.asm
#	engine/events_3.asm
#	engine/item_effects.asm
#	engine/namingscreen.asm
#	engine/scripting.asm
#	engine/stats_screen.asm
#	engine/trade_animation.asm
#	home/audio.asm
#	main.asm
#	maps/BattleTower1F.asm
#	maps/BattleTowerBattleRoom.asm
#	maps/BurnedTowerB1F.asm
#	maps/ElmsLab.asm
#	maps/GoldenrodDeptStore5F.asm
#	maps/GoldenrodUnderground.asm
#	maps/HallOfFame.asm
#	maps/MahoganyTown.asm
#	maps/ManiasHouse.asm
#	maps/MobileBattleRoom.asm
#	maps/MobileTradeRoomMobile.asm
#	maps/RadioTower2F.asm
#	maps/Route35NationalParkGate.asm
#	maps/Route36NationalParkGate.asm
#	maps/Route39Farmhouse.asm
#	tilesets/palette_maps.asm
2018-01-14 22:56:36 -05:00

55 lines
749 B
NASM

; Syntactic sugar macros
lb: MACRO ; r, hi, lo
ld \1, (\2 & $ff) << 8 + (\3 & $ff)
ENDM
ln: MACRO ; r, hi, lo
ld \1, (\2 & $f) << 4 + (\3 & $f)
ENDM
ldpixel: MACRO
if _NARG >= 5
lb \1, \2 * 8 + \4, \3 * 8 + \5
else
lb \1, \2 * 8, \3 * 8
endc
ENDM
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
ENDM
maskbits: MACRO
; masks just enough bits to cover the argument
; e.g. "maskbits %00010100" becomes "and %00011111"
; example usage in rejection sampling:
; .loop
; call Random
; maskbits 30 +- 1
; cp 30
; jr nc, .loop
x = 1
rept 8
if x < (\1)
x = (x + 1) * 2 +- 1
endc
endr
and x
ENDM