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?
ld65 can be set to output a map file, one of whose sections is the size of each 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:
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;
}
Then
title.s picks up these symbols:
Code:
.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"
The
.MOD stuff is needed because it's the only way to convert a integer that isn't constant at assembly time to decimal digits.
BUILDDAY is known at assembly time, but the sizes aren't known until link time.