Quantcast
Channel: nesdev.org
Viewing all articles
Browse latest Browse all 782

wla-dx, strings and labels

$
0
0
Hi, I'm new here!

I'm working on Advent Of Code on the SNES (I considered posting in the SNES board, but only the NES board had a newbie corner, and my question isn't SNES specific). I've built a font, set up graphics and made printing and sorting routines etc, and I have the first problem mostly working now, but I'm having some friction with wla-dx that feels like it's probably just me being a noob.

1. I'm defining strings with `label: .ASC "string here"`. After doing so, how do I get at its length? `"string here".length` works, but then I have to repeat it. I'm looking for something like `label.length`, or `_sizeof_label`, but that doesn't seem to exist. Do I have to do something like `label: .ASC "string here" label_end` and then use `label_end-label` to get the size?

2. Is there a way to generate labels dynamically, e.g. by pasting tokens together like the C preprocessor does? I use most strings only once, so i thought I could make a macro like this:

Code:

.MACRO prints ARGS str  _str: .ASC str  print _str _str.length.ENDM
where `print` is a macro that calls my print subroutine. However, this fails due to `_str` being multiply defined when I call this macro multiple times. Undefining it doesn't work, presumably because it's needed for the commands I've already issued(?), and I haven't found a way to make a label local to a single invocation of a macro. So i thought I could get around this by making a unique label for each time the macro is called, but I can't see any way to use a label defined with `.DEFINE` as a label (meta-label?), nor a way to paste labels together (for example `_str + counter`).

Maybe there's a completely different way to do all this, and I'm barking up the wrong tree? I thought `.STRINGTABLE` sounded promising based on its name, but it seems to just be a fancier version of `.ASC`. I can get by with just defining the strings and lengths as I currently am, but I thought I'd ask to be safe.

Statistics: Posted by amaurea — Fri Dec 27, 2024 7:01 am — Replies 0 — Views 32



Viewing all articles
Browse latest Browse all 782

Trending Articles