Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - MACROs you enjoy using

Reply to topic
Author Message
  • Joined: 30 Apr 2024
  • Posts: 28
Reply with quote
MACROs you enjoy using
Post 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
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14876
  • Location: London
Reply with quote
Post 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
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3926
  • Location: Stockholm, Sweden
Reply with quote
Post 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)
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!