- Joined: 30 Apr 2024
- Posts: 28
|
MACROs you enjoy using
Posted: Thu Sep 19, 2024 8:57 pm
|
Hi!
What MACROS do you find (if any) yourself using a ton?
I'm quite proud of:
.MACRO MACRO_BIT_BRANCH_Z
ld a,(GameMode_Flags)
bit \1,a
jp z,\2
.ENDM
.MACRO MACRO_BIT_BRANCH_NZ
ld a,(GameMode_Flags)
bit \1,a
jp nz,\2
.ENDM
They are invoked like:
MACRO_BIT_BRANCH_Z GameMode_Flags_Macro,@SomeLabel
; OR
MACRO_BIT_BRANCH_Z 2,@SomeLabel
I'd love to see some other nice ones. I was thinking the following would be good:
.MACRO MACRO_DEC_BC_JPNZ
dec bc
ld a,c
or b
jp nz,\1
|
- Site Admin
- Joined: 19 Oct 1999
- Posts: 14876
- Location: London
|
Posted: Thu Sep 19, 2024 9:09 pm
|
I get scared that I can’t see the registers being clobbered in some of these. WLA DX supports function-style macros now so I can have this:
.function TilemapAddress(x, y) TilemapBaseAddress+2*(x+y*32)
ld hl, TilemapAddress(5,5)
Also this one has proved useful for “palette based profiling”:
.function colour(r,g,b) (r+(g<<2)+(b<<4))
.macro SetDebugColour(r,g,b)
.ifdef Debug
push af
ld a,$10
out ($bf),a
ld a,$c0
out ($bf),a
ld a,colour(r,g,b)
out ($be),a
pop af
.endif
.endm
|
- Joined: 05 Sep 2013
- Posts: 3926
- Location: Stockholm, Sweden
|
Posted: Wed Sep 25, 2024 8:29 am
|
I recently used the newer WLA-DX function for the first time, this is my contribution - it turns an hex 24-bit $RRGGBB constant into the corresponding SMS 6-bit BGR color constant:
.function RGB(value) ((value & $C00000) >> 22)|((value & $C000) >> 12)|((value & $C0) >> 2)
so you can for instance do:
ld a,RGB($55AA00)
|