Arakula / dasmfw

The DisASseMbler FrameWork
GNU General Public License v2.0
13 stars 4 forks source link

Feature Suggestion: Add ability to declare labels for defined ranges (i.e. per-subroutine Zero-Page local variables) #20

Open phillipeaton opened 1 year ago

phillipeaton commented 1 year ago

The 6502 CPU doesn't have many registers, but Zero-Page memory would appear to be used by many programs to perform a similar function to registers.

In practice, this means that many program subroutines use the same Zero-Page memory locations for different short-term purposes (i.e. like a register or local variable), such that you are not able to globally label some Zero-Page memory locations for any given program with useful names, when using dasmfw.

A clunky workaround I'm using is to run a sed script (see listing) on the output from dasmfw to insert additional EQUs with extended names (lines 3-12) and update the usage of the plain ZPnn labels with the extended names on a particular range of addresses ($3601 to $3734, lines 15-24).

(It's possible that dasmfw multilabel functionality provides this local label ability, but I can't figure out how it works.)

image

Additional Info: I've learned that the 6502bench disassembler program has functionality that inserts locals into the listing, as can be seen in the picture below; $98 and $99 are used in many places throughout this assembly listing, with different names each time. It's documented here: https://6502bench.com/sgtutorial/local-variables.html

image

Thanks for reading.

Arakula commented 1 year ago

Definitely a good idea. Unfortunately, I'm currently deep into other things, so it will take a while until I could do anything about it.

Syntax could be something like locallabel addr[-addr[/step]] addr[-addr] name where the first range defines the region in which the second address range is mapped to name. This would then insert the local label declaration directly before the disassembly of the first range and use it from there on until the end end of the first range (or EOF, if only a start is given).

Should do it, I think. Thoughts?

phillipeaton commented 1 year ago

Thanks for the positive feedback, your proposal sounds pretty good to me. You could use local[label], like used[label], which would save some typing. We'll see what the spacing looks like when implemented.

Good luck with whatever else you're working on, I'll get by with sed for now 👍

FWIW, my setup is getting quite structured now: image

This is half of my dasmfw output: image