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

ASM6 symbol file output.

ASM6 symbol file output.
by on (#99003)
First post \o/

After learning Z80 assembly (SMS and MSX) I decided to give a go at another platform with all new challenges.

I'm pretty charmed by Loopy's ASM6 assembler due to its simplicity. But I miss an option to output a symbol file that can be used by emulator debuggers. Debugging without symbols is insane ;) Well at least with my buggy code.

Did anyone ever tinkered with ASM6 and implemented their own symbol output?
I would be very grateful to have such a feature. I'm not very comfortable with ca65.
Re: ASM6 symbol file output.
by on (#99004)
CA65 has such thing, And it uses the same syntax as ASM6, but it uses cfg files to build binaries via a linker (unlike ASM6)

This, or the piece of crap known as WLA DX (no offense)!
Re: ASM6 symbol file output.
by on (#99005)
I would think it might be worth exploring what you don't like about ca65 and see if you can work past those things or learn to appreciate them.
Re: ASM6 symbol file output.
by on (#99029)
Movax12 wrote:
I would think it might be worth exploring what you don't like about ca65 and see if you can work past those things or learn to appreciate them.

That would probably be the smart thing you do. Or, if you're nuts like me, you can write your own "ASM6-compatible" assembler that outputs FCEUX debug files.

For what it's worth, ASM6 comes with code. It's written in C, but it's hard to follow. You could add your desired feature and share the fruits of your labor. I also converted ASM6 to C#. It's probably a little easier to follow since it is necessarily a little more strongly typed and object-oriented.
Re: ASM6 symbol file output.
by on (#99031)
I'd recommend somehow taking the map that ld65 already emits, either the map file (-vm -m map.txt) or the VICE label file (-Ln labels.txt) (source: ld65 options), and writing some short program to turn that into the format expected by FCEUX. I seem to remember someone having already done this, but phpBB has been having search problems.
Re: ASM6 symbol file output.
by on (#99046)
tepples wrote:
I'd recommend somehow...

Tsk tsk tepples. You wouldn't recommend your slate of "Learners Permit Included" ready-to-use cc65 projects such as russian roulette?

I *know* there's a program out there somewhere that will let you build/run/debug cc65-built projects symbolically. :wink:
Re: ASM6 symbol file output.
by on (#99047)
Yeah, and it needs a somewhat beefier PC than the one I use daily. I need to remind myself to make a -Ln to .nl converter and include it in the templates for people stuck on machines that can't quite handle NESICIDE.
Re: ASM6 symbol file output.
by on (#99049)
tepples wrote:
Yeah, and it needs a somewhat beefier PC than the one I use daily. I need to remind myself to make a -Ln to .nl converter and include it in the templates for people stuck on machines that can't quite handle NESICIDE.


Here's a simple one for python:

Code:
def lab_to_nl(label_file, nl_file, range_min, range_max):
    labels = open(label_file, "r").readlines()
    sout = ""
    for line in labels:
        words = line.split()
        if (words[0] == "al"):
            adr = int(words[1], 16)
            sym = words[2]
            if (adr >= range_min and adr <= range_max):
                sout += ("$%04X#%s#\n" % (adr, sym))
    open(nl_file, "w").write(sout)


Usage is something like this for a simple NROM project:
Code:
lab_to_nl("labels.txt", "mything.nes.ram.nl", 0x0000, 0x07FF)
lab_to_nl("labels.txt", "mything.nes.0.nl", 0x8000, 0xBFFF)
lab_to_nl("labels.txt", "mything.nes.1.nl", 0xC000, 0xFFFF)


Note the number before .nl in the filename denotes the 16k iNES bank number (hexadecimal).

For bankswitching it gets more complicated; you need to link each bank separately so the label file doesn't end up containing overlapping symbols. If you're using a mapper with 8k bank switching, overlap may be unavoidable if you happen to use two 8k banks from the same 16k iNES bank at the same memory address.

Remember to add the -g flag to your ca65 step, and -Ln labels.txt to your ld65.
Re: ASM6 symbol file output.
by on (#99055)
Thanks for the quick replies and pointers.

snarfblam wrote:
That would probably be the smart thing you do. Or, if you're nuts like me, you can write your own "ASM6-compatible" assembler that outputs FCEUX debug files.


Is that version available? I'd really would like to use that version you made.
The issue is that ca65 is making this unnecessary complex (probably due its C related nature) for my liking. But it for sure has more functionality than asm6.

I'm probably nuts but I am thinking on trying to port my preferred z80 assembler to 6502. The source is pretty clean (but rarely commented), source is freely available and has some very nice features. In worst case it will help me to learn the 6502 opcodes in better detail. ;)
Re: ASM6 symbol file output.
by on (#99056)
rainwarrior wrote:
Code:
    labels = open(label_file, "rt").readlines()
    open(nl_file, "wt").write(sout)


Off-topicish: the "t" character for the mode parameter is useless and ignored by open().
Re: ASM6 symbol file output.
by on (#99062)
I'll remember that for the future, thanks.
Re: ASM6 symbol file output.
by on (#99151)
I decided to make a little converter to convert an .lst into separate .nl files using Blitz+. Implementing 6502 support for sjasm would take too much time (for now).

Thanks for the help/pointers.
Now the fun of exploration can begin! 8)
Re: ASM6 symbol file output.
by on (#116928)
I want this feature too (it's too late for me to go back to ca65 now). I'm having a look over the asm6 source. It doesn't seem too bad to me. I may attempt adding the feature.
Re: ASM6 symbol file output.
by on (#116929)
It's probably not as difficult as you think to switch to ca65, between using a text editor's search-replace and using the .define feature to support asm6 directives, etc.
Re: ASM6 symbol file output.
by on (#116930)
Movax12 wrote:
It's probably not as difficult as you think to switch to ca65, between using a text editor's search-replace and using the .define feature to support asm6 directives, etc.


no, it probably is. the lack of +/- labels that work the same as asm6 in particular stands out. also i've written just a lot of code in a lot of files, and i'd have to make significant changes to my Forth compiler and work out a way to support ca65 without throwing out asm6. it's way more work than this seems to be. besides it'll help a lot of other people...
Re: ASM6 symbol file output.
by on (#116931)
Oh, I never use those. That could be a problem.
Re: ASM6 symbol file output.
by on (#116932)
Movax12 wrote:
Oh, I never use those. That could be a problem.

Ha. Give them a try. You might learn why I prefer asm6... ;)
Re: ASM6 symbol file output.
by on (#116934)
Movax12 wrote:
Oh, I never use those. That could be a problem.

Heh, I, on the other hand, am probably abusing them... For example, I do this for placing code/data at the very end of a bank (the "Game.FixedBank = $" is so I can include this multiple times):
Code:
   .org $10000 - (+FixedBankEnd - +FixedBankStart)

Game.FixedBank = $

+FixedBankStart:

   .include "interrupts\System.NMI.asm"
   .include "interrupts\System.IRQ.asm"
   .include "interrupts\System.Reset.asm"
   .include "tables\System.BankIndexes.asm"
   .include "tables\System.InterruptVectors.asm"

+FixedBankEnd:

I don't know how easy/possible this is in other assemblers.
Re: ASM6 symbol file output.
by on (#116935)
OK. I cleaned up the source's formatting (Loopy apparently hated whitespace) and got it compiling and assembling my project.

Now to add the symbol file output. Can anyone help me with the format? I tried looking at an output file from a cc65 project thinking I could figure it out... and I can't.
Re: ASM6 symbol file output.
by on (#116939)
sonder wrote:
Movax12 wrote:
Oh, I never use those. That could be a problem.

Ha. Give them a try. You might learn why I prefer asm6... ;)


I agree that asm6 does a better job here, but I have other means. https://www.assembla.com/spaces/ca65hl/wiki

Regarding debug output format, maybe try to talk to thefox or qbradq on these forums.
Re: ASM6 symbol file output.
by on (#116949)
sonder wrote:
Now to add the symbol file output. Can anyone help me with the format? I tried looking at an output file from a cc65 project thinking I could figure it out... and I can't.

There's a file called "dbginfo.c" (and the corresponding header) in the CC65 sources, NintendulatorDX and NESICIDE use it to parse debug info files generated by CC65. The source can be helpful in figuring out the format, and you can also use it to fairly easily test if the debug files you have generated parse correctly.

It's probably not straightforward to generate them from other assemblers though because of how closely the format is tied to CC65. Especially if you want to support everything like source line infos.

I also seem to remember there is a small command line utility in the CC65 package that could be used to browse debug files.
Re: ASM6 symbol file output.
by on (#116964)
Don't forget that ASM6 can already make listing files, which are useful in their own way.
Re: ASM6 symbol file output.
by on (#116966)
Dwedit wrote:
Don't forget that ASM6 can already make listing files, which are useful in their own way.

yeah that's what i've been relying on to do my debugging. manually tabbing back and forth and noting addresses. it's not much fun. :P
Re: ASM6 symbol file output.
by on (#117042)
sonder wrote:
OK. I cleaned up the source's formatting (Loopy apparently hated whitespace) and got it compiling and assembling my project.

Now to add the symbol file output. Can anyone help me with the format? I tried looking at an output file from a cc65 project thinking I could figure it out... and I can't.


I just added FCEUX label file export to asm6 since it had clear documentation and a straightforward format.

Here's the modded version + source. There's no commandline option, it just always outputs the nl files. I'll let someone else take care of that.
Re: ASM6 symbol file output.
by on (#117044)
sonder wrote:
sonder wrote:
Here's the modded version + source. There's no commandline option, it just always outputs the nl files. I'll let someone else take care of that.

It's 64 bit? Can you make win32?
Re: ASM6 symbol file output.
by on (#117045)
Ti_ wrote:
sonder wrote:
sonder wrote:
Here's the modded version + source. There's no commandline option, it just always outputs the nl files. I'll let someone else take care of that.

It's 64 bit? Can you make win32?


Grab Tiny C compiler and compile it, the source is included. I'm sure people would appreciate it if you posted a 32bit version, I just don't wanna mess with that.
Re: ASM6 symbol file output.
by on (#117046)
Well, ok. It's works, thank you.

Symbols files for labels and ram created. The only thing not working is equ's (like objects_X_low equ $300).
Re: ASM6 symbol file output.
by on (#117053)
Ti_ wrote:
Well, ok. It's works, thank you.

Symbols files for labels and ram created. The only thing not working is equ's (like objects_X_low equ $300).


Ah, yeah. Nice catch. I meant to add those, should be fairly easy. Will post an update.
Re: ASM6 symbol file output.
by on (#117056)
sonder wrote:
Ti_ wrote:
Well, ok. It's works, thank you.

Symbols files for labels and ram created. The only thing not working is equ's (like objects_X_low equ $300).


Ah, yeah. Nice catch. I meant to add those, should be fairly easy. Will post an update.


Here. Note that I made it ignore all equates and values that are 1 character, so that indexes and such aren't included.
Re: ASM6 symbol file output.
by on (#117844)
Great work sonder!!! Thanks.