After playing with RGBDS for Game Boy Color development, I noticed that it lets you skip specifying what bank a section is located in entirely and it just tries to pack it somewhere where there's room.
Because I found it super useful, I wrote a Python script to shove that feature into ca65/ld65. For any segments not declared in your linker config, it scans through your object files with od65 to find out how big those segments actually are, and splices a new segment declaration into the linker config that puts the segment somewhere where there's room, using the first-fit decreasing strategy.
The script has a lot of stuff hardcoded but I think it could easily be adapted to 16KB bank mappers like UNROM, rather than just LoROM SNES games. There's probably a lot of problems I don't solve yet (like I don't know how aligns play into segment sizes), and I had some difficult-to-solve issues when putting things in the bank the vectors reside in, so it doesn't try to allocate anything in there right now. You also can't yet specify that specific segments must go in the same bank together, so in that case they must either be renamed to be the same thing or they should be manually placed.
Ideally it'd be cool to have this sort of feature directly in ld65!
Automatic ca65/ld65 bank chooser
Moderator: Moderators
- NovaSquirrel
- Posts: 483
- Joined: Fri Feb 27, 2009 2:35 pm
- Location: Fort Wayne, Indiana
- Contact:
Re: Automatic ca65/ld65 bank chooser
Does it do anything to help you when switching to the bank you want? Since you don't know where a segment will end up?
My games: http://www.bitethechili.com
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Automatic ca65/ld65 bank chooser
A SEGMENT has a "bank" attribute, which is exactly the right tool that purpose. See .bank.
E.g.
Code: Select all
lda #.bank(mything)
sta $8000
jsr mything
Re: Automatic ca65/ld65 bank chooser
Huh. I'm wondering how I missed this for so long. Thanks.rainwarrior wrote: ↑Mon Jan 20, 2020 5:28 pmA SEGMENT has a "bank" attribute, which is exactly the right tool that purpose. See .bank.
E.g.Code: Select all
lda #.bank(mything) sta $8000 jsr mything
My games: http://www.bitethechili.com
Re: Automatic ca65/ld65 bank chooser
Though on 65816 you're more likely to use .bankbyte(addr) or ^addr, both of which mean ((addr >> 16) & $FF).