ca65: space left in bank/segment?
Moderator: Moderators
ca65: space left in bank/segment?
This is probably already posted out there somewhere, but I couldn't find it: How do y'all easily track how much space you have left in each bank and/or segment?
I can think of a few ways to do it, but was curious what you all do -- I imagine somebody has already solved this in a more elegant way than I'll come up with on my own.
I can think of a few ways to do it, but was curious what you all do -- I imagine somebody has already solved this in a more elegant way than I'll come up with on my own.
My games: http://www.bitethechili.com
- rainwarrior
- Posts: 8735
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: ca65: space left in bank/segment?
1. Link with -m map.txt will spit out a "map" file with the addresses and sizes of all segments and memory blocks, as well as some other useful info.
2. You can use shiru's space checker tool for a visual inspection.
https://shiru.untergrund.net/software.shtml
In my own project, since I already have a python script processing the label output into FCEUX debug files, at the same time I have it parse the map file and compute empty space for me.
2. You can use shiru's space checker tool for a visual inspection.
https://shiru.untergrund.net/software.shtml
In my own project, since I already have a python script processing the label output into FCEUX debug files, at the same time I have it parse the map file and compute empty space for me.
Re: ca65: space left in bank/segment?
Ok, so in the cfg file, there are 2 areas. The "memory" map and the "segments".
Generally, a segment can go anywhere in the ROM of the memory map, except rarely (vectors, dmc samples).
So, I believe, it doesn't matter,... the segments can expand and contract, as needed. Just check how much free space you have in each BANK. And, it (the linker) will give you an error if you overflow a bank (memory area).
Generally, a segment can go anywhere in the ROM of the memory map, except rarely (vectors, dmc samples).
So, I believe, it doesn't matter,... the segments can expand and contract, as needed. Just check how much free space you have in each BANK. And, it (the linker) will give you an error if you overflow a bank (memory area).
nesdoug.com -- blog/tutorial on programming for the NES
Re: ca65: space left in bank/segment?
That was my plan as wellrainwarrior wrote: In my own project, since I already have a python script processing the label output into FCEUX debug files, at the same time I have it parse the map file and compute empty space for me.
(Particularly since I'm already using an old version of your python script to generate the FCEUX debug files)
Last edited by gauauu on Mon Nov 06, 2017 10:35 pm, edited 1 time in total.
My games: http://www.bitethechili.com
Re: ca65: space left in bank/segment?
Yeah, I don't really care about segments as much as the entire bank.dougeff wrote:. And, it (the linker) will give you an error if you overflow a bank (memory area).
But I do want it to report numbers (preferably dumped out on the console as my makefile runs) so I can see how quickly I'm using up space, and not just the default behavior of saying nothing until "oops, you've gone over!"
My games: http://www.bitethechili.com
- FrankenGraphics
- Formerly WheelInventor
- Posts: 2064
- Joined: Thu Apr 14, 2016 2:55 am
- Location: Gothenburg, Sweden
- Contact:
Re: ca65: space left in bank/segment?
Shiru's space checker (already mentioned) provides visual feedback in a way that's quick to overview.
Re: ca65: space left in bank/segment?
od65 -S *.o | grep mybank | summer 2
where summer is a custom script:
where summer is a custom script:
Code: Select all
#!/bin/sh
count=$1
[ -z "$count" ] && echo "Usage: $0 column" && exit
awk --non-dec "{s+=\$$count} END {print s}"
Re: ca65: space left in bank/segment?
ld65 can be set to output a map file, one of whose sections is the size of each segment.gauauu wrote:This is probably already posted out there somewhere, but I couldn't find it: How do y'all easily track how much space you have left in each bank and/or segment?
It can also export symbols representing the size of each segment (see descriptions of define = yes in ld65 Users Guide), and code and string constants can use these symbols to calculate and display ROM fullness. I use define = yes in RHDE's linker configuration to have it define labels for the starting address and size of two segments:
Code: Select all
SEGMENTS {
ZEROPAGE: load=ZP, type=zp;
BSS: load=RAM, type=bss, define=yes, align=$100;
INESHDR: load=HEADER, type=ro, align=$10;
DMC: load=ROM7, type=ro, align=64, optional=yes;
CODE: load=ROM7, type=ro, align=$100, define=yes;
RODATA: load=ROM7, type=ro, align=$100, define=yes;
VECTORS: load=ROM7, type=ro, start=$FFFA;
}
Code: Select all
.import __RODATA_LOAD__, __RODATA_SIZE__, __CODE_LOAD__, __CODE_SIZE__
ROMSIZE = __CODE_SIZE__ + __RODATA_SIZE__ + 6
ROMPCT = (1000 * ROMSIZE + 16384) / 32768
; started this project on Sun 2013-08-11
BUILDDAY = (.TIME / 86400) - 15928
uctions5_txt:
.byte .sprintf("Day %d: ROM ", BUILDDAY)
.byte '0'|<(ROMPCT / 100 .MOD 10)
.byte '0'|<(ROMPCT / 10 .MOD 10)
.byte '.','0'|<(ROMPCT .MOD 10),"% full"
Re: ca65: space left in bank/segment?
Add dummy segments at the very end of the cfg file:
Then the 'Start' value in the map file shows where each bank ends.
Subtract from 0xC000 to get the size.
You might need to fill these dummy segments with a single byte.
Code: Select all
BANK0_END: load = PRG0, type = ro;
BANK1_END: load = PRG1, type = ro;
BANK2_END: load = PRG2, type = ro;
Code: Select all
Name Start End Size Align
----------------------------------------------------
BANK0_END 00BA80 00BA80 000001 00001
BANK1_END 008AB6 008AB6 000001 00001
BANK2_END 00BF00 00BF00 000001 00001
You might need to fill these dummy segments with a single byte.