fadden / 6502bench

A workbench for developing 6502 code
https://6502bench.com
Apache License 2.0
166 stars 33 forks source link

Export labels #151

Closed BacchusFLT closed 4 months ago

BacchusFLT commented 8 months ago

In my deeds where I use 6502 bench, I most often use it to document the code I am working with. So the modus operandi is running the code in an emulator and in prallell document things in 6502 bench,

Here the emulator's debugger (I use VICE and RetroDebugger) have support for labels, so I can import a label file and have the debugger present them in the disassembly.

Request: So it would be most handy if 6502 bench could export the labels in the current project in a format that my debugger can read.

This is the format for such a file for VICE (it shows that several formats are supported):

l [<address_space>] "<filename>"
Load a file containing a mapping of labels to addresses. If no address space is specified, the default readspace is used. The file must contain commands the monitor understands, e.g. add_label. The compiler cc65 can create such label files. Vice can also load label files created by the Acme assembler. Their syntax is e.g. "labelname = $1234 ; Maybe a comment". A dot will be added automatically to label names assigned in this way to fit to the Vice label syntax. Normally the semicolon seperates commands but after an assignment of this kind it may be used to start a comment to end of line, so unchanged Acme label files can be fed into Vice.

https://vice-emu.sourceforge.io/vice_12.html

I haven't been able to find the ACME file format, but at least these two options can generate them: -l, --labeldump FILE select label dump file. This can also be given using the "!sl" pseudo opcode.

-vl, --vicelabeldump FILE   select label dump file for VICE.
    This can also be given using the "!svl" pseudo opcode.

KickAssembler generates two different formats: (.sym and .vs) http://theweb.dk/KickAssembler/webhelp/content/ch12s06.html

My assumption is that trhe Assebler step could be given an extra parameter to have the assemblers generate these files, without any additional code in 6502 bench.

phillipeaton commented 8 months ago

I'm taking the output .lst file of an assembler (a09 for 6809) and using it to create an EQU file for a compiler (CamelForth for Vectrex 6809), which allows the Forth code to call the assembly routines in a combined target binary.

This is similar to what you're looking to do, here's the command line (Windows 10 command line), it might give you some ideas:
sed -n "/SYMBOL TABLE/,/SYMBOLS/p" vectrex_sargon.lst | sed -e "$d; 1d;" | awk -f sargon_equs_awk.txt | sort > sargon_equs.fs

I also do something similar (simpler) to this to create a comment file for MAME Debugger from my disassembler (dasmfw for 6809, not 6502bench) "info" files as they're manually-edited plain text, again.

I'm no expert with this, but it's worth spending the time to learn about it as it can make life a lot easier to work around functionality gaps.

Good luck!

BacchusFLT commented 8 months ago

Many thanks for the suggestion. I guess my first option would still have a checkbox in the setting conditioning adding a parameter to the assembly. That would have the assembler generate it and it would take no post processing.

fadden commented 8 months ago

ca65 docs say:

-g, --debug-info When this option (or the equivalent control command .DEBUGINFO) is used, the assembler will add a section to the object file that contains all symbols (including local ones) together with the symbol values and source file positions. The linker will put these additional symbols into the VICE label file, so even local symbols can be seen in the VICE monitor.

According to this it's also necessary to add -Ln out.lbl. A quick experiment suggests that the output is what VICE wants:

al 008002 .foo

Letting the assembler generate the output would potentially be less work, but has some drawbacks:

  1. Not all assemblers support this.
  2. SourceGen would have no control over the contents, e.g. it wouldn't be possible to omit auto-generated ("L1234") labels that don't really add information.
  3. VICE isn't the only emulator that can make use of the symbols (e.g. issue #77).

I don't think there's a scenario where the assembler has information that SourceGen doesn't, in terms of mapping a label to an absolute address in memory, so there's no technical reason SourceGen can't do it.

fadden commented 4 months ago

I added a feature to the File menu, next to the assemble/export commands. It has been published in https://github.com/fadden/6502bench/releases/tag/v1.8.6-dev1

I don't have VICE set up so I haven't tried to actually use it. I'm generating essentially the same thing that ca65 does (described at https://www.cc65.org/doc/debugging-4.html), so hopefully it's correct and useful. Please give it a try and see if it does what you need it to.

fadden commented 4 months ago

I poked at VICE a little. It accepts the generated label files, but only keeps one copy of each symbol. So if you have multiple local labels called "@loop", it only keeps the last one. It rejects the internal uniquified name (which has a '§' in it), but if I replace that with '_' then you get the whole set.