flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [fasmg] Can I Make a Custom Macro for the label: syntax?

Author
Thread Post new topic Reply to topic
zicklag



Joined: 10 May 2025
Posts: 3
zicklag 10 May 2025, 02:12
I'm trying to create a custom label macro that will output all of the label names and their memory positions out to a separate file to use as a source map in an NES emulator.

It seems that there's a way to do that easy enough if I make a `label` macro and use the `label name` syntax, but I would like to continue being able to use the normal `label:` syntax.

Is there any way to do that?
Post 10 May 2025, 02:12
View user's profile Send private message Visit poster's website Reply with quote
zicklag



Joined: 10 May 2025
Posts: 3
zicklag 10 May 2025, 02:26
Oh, actually I just realized that it's pretty easy to use an unconditional macroinstruction to intercept all of the labels with a custom macro, but unfortunately I'm not seeing a way to generate the source map as a separate file.

As far as I can see fasmg only supports writing output to its main output file.

Code:
macro ?! line&
  match label_name:,line
    ; do custom stuff
    label label_name 
  else
    line
  end match
end macro
    
[/quote]
Post 10 May 2025, 02:26
View user's profile Send private message Visit poster's website Reply with quote
dosmancer



Joined: 20 Feb 2025
Posts: 17
Location: Kingdom of Sweden
dosmancer 10 May 2025, 03:29
zicklag wrote:
Oh, actually I just realized that it's pretty easy to use an unconditional macroinstruction to intercept all of the labels with a custom macro, but unfortunately I'm not seeing a way to generate the source map as a separate file.

As far as I can see fasmg only supports writing output to its main output file.

Code:
macro ?! line&
  match label_name:,line
    ; do custom stuff
    label label_name 
  else
    line
  end match
end macro
    

I slightly more lightway approach than a "catch-all" macro is a "catch-all" struc

See chapter 9 in https://flatassembler.net/docs.php?article=fasmg_manual#9
Code:
struc (label) ? line&
        . line
        ; need to collect the label and address too somehow
end struc    

To catch labels created with the `label` command you need to override the label command too:
Code:
macro label? line&
        label line
        ; need to collect the label and address too somehow
end macro    

To output data to a separate other file you need to use `virtual`. See chapter 13 https://flatassembler.net/docs.php?article=fasmg_manual#13

So you need to collect label names together with the addresses and then output them in your desired format into the virtual output area with the store command.
Post 10 May 2025, 03:29
View user's profile Send private message Visit poster's website Reply with quote
zicklag



Joined: 10 May 2025
Posts: 3
zicklag 10 May 2025, 16:07
Ah, the virtual blocks are exactly what I needed, thanks!

And now I understand labeled macroinstructions with the `struc` syntax.

After some reading and experimenting I was able to get fasmg to output an MLB file so that I can get the labels imported to the Mesen NES emulator debugger!

Thanks for the help!

I'm having fun trying to get started writing an NES game with fasmg. So cool to be able to customize the assembler for a new platform like this.
Post 10 May 2025, 16:07
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.