ASM6 variadic macro possible?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
tepples
Posts: 21748
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

ASM6 variadic macro possible?

Post by tepples » Sat Mar 16, 2019 9:22 am

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: Select all

.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: Select all

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

User avatar
Dwedit
Posts: 4236
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: ASM6 variadic macro possible?

Post by Dwedit » Sat Mar 16, 2019 11:09 am

I guess use regular expressions to add a "BLANK" to everything, or a separate macro for a blank-including version?
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

tepples
Posts: 21748
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: ASM6 variadic macro possible?

Post by tepples » Sat Mar 16, 2019 7:20 pm

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.

Post Reply