It's been a couple years since I started this thread, and since I'm much more familiar with ca65 now than I was back then, I decided to revisit some of the ideas presented here.
The one thing I have in mind right now is how to automatically align the end portion of a PRG-ROM bank to the end of the bank, so that interrupt vectors, reset stub, trampoline routines, etc. are placed at the same position in every bank (simulating a fixed bank on mappers that don't have one) without wasting any space or needing manual tweaking of addresses or padding.
So far I've been using rainwarrior's suggestion
of using two segments and padding the first one according to how much I've used of both, pushing the second one up. The main problem with this is that the amount of used space can only be calculated based on the relative distance between two labels, so the whole bank must be assembled as a single module.
Then there was this post from thefox
, which I didn't understand at the time, but now I realize I can use a similar trick to have the linker automatically pad the lower part of the bank:
Code: Select all
# this outputs the upper part and calculates its size
FIXED: start = $0000, size = $8000, file = "fixed.bin", fill = no, define = yes;
# this provides the correct PC for the upper part
DUMMY: start = $10000 - __FIXED_LAST__, size = $8000, file = "", fill = no;
# this outputs the lower portion and pads it as necessary
BANK: start = $8000, size = $8000 - __FIXED_LAST__, file = "bank.bin", fill = yes;
Code: Select all
BANK: load = BANK, run = BANK, type = ro;
FIXED: load = FIXED, run = DUMMY, type = ro;
This works fine, the only catch is that since the fixed area has to be output first so we know its size, we have to output the two parts to separate files and concatenate them later (using copy /b
or whatever) to put everything in the correct order. Of course I would rather have the assembler output the final ROM directly, instead of dealing with 32 temporary files for 16 PRG-ROM banks, so I decided to run this by you guys to see if there's anything I'm missing, or if this is indeed as close as it gets to "automatic right justifying".
I still don't understand why we can't use the symbols created by define = yes
in the SEGMENTS section... That would definitely make things easier.