It is currently Fri Mar 22, 2019 6:16 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sat Mar 16, 2019 9:22 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21209
Location: NE Indiana, USA (NTSC)
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


Top
 Profile  
 
PostPosted: Sat Mar 16, 2019 11:09 am 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 4152
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!


Top
 Profile  
 
PostPosted: Sat Mar 16, 2019 7:20 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21209
Location: NE Indiana, USA (NTSC)
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group