freem / asm6f

A fork of loopy's ASM6, a 6502 assembler.
96 stars 24 forks source link

Symbol to fetch the output address of a label #15

Open Drakim opened 7 years ago

Drakim commented 7 years ago

NESASM has a built-in function called BANK() which returns an integer indicating what bank a certain label belongs to. This can be quite the useful piece of functionality as you can create a primitive type of pointer, or simply make your code truly relocatable, or allow for data sets that expand over more than one bank and automatically adapts.

It's perhaps the only piece of functionality I truly miss when moving from NESASM to asm6f, as I now have to manually hard-code the bank integers and hope I remember to change it by hand later if need be.

asm6f doesn't have the concept of banks so the same functionality is impossible at first glance, but, if there was a way to fetch out the real address of a label (the actual offset into the output file as opposed to the virtual address often changed by .base directives) then the programmer could easily calculate what bank a label belongs to.

My suggestion is to add some symbol you can put before a label to indicate that you want it's output address, something like ?MyLabel.

nicklausw commented 7 years ago

Fetching a bank in WLA is done by preceding a label with a colon (lda #:myLabel), but this doesn't work well with asm6's parser which considers a colon to be white space. Maybe that could be changed.