This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

ASM6 variadic macro possible?

ASM6 variadic macro possible?
by on (#236135)
I'm trying to translate to ASM6 a sound driver including a macro that takes different number of parameters. In ca65, I'd use .ifblank to test whether an argument is present.
Code:
.macro sfxpairdef name, sfx1, sfx2
name = <(* - sfxpairs_base) / 2
  .byte sfx1
  .ifblank sfx2
    .byte $80
  .else
    .byte sfx2
  .endif
.endmacro

sfxpairs_base:
sfxpairdef D_JUMP, 2
sfxpairdef D_FIRE, 3
sfxpairdef D_EXPLOSION, 4, 5

Which expands as follows:
Code:
sfxpairs_base:
D_JUMP = <(* - sfxpairs_base) / 2
  .byte 2
  .byte $80
D_FIRE = <(* - sfxpairs_base) / 2
  .byte 3
  .byte $80
D_EXPLOSION = <(* - sfxpairs_base) / 2
  .byte 4
  .byte 5


How would this be done in ASM6?


Related issue on GitHub
Re: ASM6 variadic macro possible?
by on (#236141)
I guess use regular expressions to add a "BLANK" to everything, or a separate macro for a blank-including version?
Re: ASM6 variadic macro possible?
by on (#236147)
Dwedit wrote:
or a separate macro for a blank-including version

That is practical only if two things are true, which are the case for this particular application but not for all applications that might need variadic macros.

  1. I control the input and can require the programmer to use separate macros sfxpairdef_1 and sfxpairdef_2, as opposed to having to interoperate with existing code that uses the existing variadic sfxpairdef macro. Currently, a Python script that I control generates sfxpairdef calls from source input. I can modify it to provide a command-line switch to generate ASM6-compatible output, which contains sfxpairdef_1 and sfxpairdef_2, instead of ca65-compatible output, which contains sfxpairdef. But I won't always control the process that generates calls to variadic macros, such as the case of building an assembler for another architecture as a macro pack for ASM6. (This in fact has been done with ca65.)
  2. The number of possibilities is small enough to avoid combinatorial explosion. This is the case for sfxpairdef but not for another project I have worked on. It has a macro with 24 arguments that creates an entry for a level in a platform game, where 14 of the 24 arguments can be either blank or filled in. Separate macros for each variation would mean 214 = 16,384 different macros.