samophlange wrote:
One thing I liked about compiling with NESASM3 is that it would list out the "USED/FREE" bytes of each bank. Is there a way of getting something equivalent with ca65?
In the .CFG file you can put
"define = yes" in the segment definitions to generate symbols containing their size, which you can subtract from the total size to see how much space you have left.
Since this number is not a constant during assembly time, you can't easily print it using
.out. You can either write it to a file in binary form using
.word or
.dword and read it using an hex editor, or use a macro to convert it into a string.
For example, here's what the segment definitions for my first PRG-ROM bank look like (the second one is aligned to the end of the bank, so I can reliably put the CPU vectors, reset stub and other stuff that needs to be in the same location in multiple banks):
Code:
PROGRAM_ROM_LOWER_00: load = PROGRAM_ROM_LOWER_00, type = ro, define = yes;
PROGRAM_ROM_UPPER_00: load = PROGRAM_ROM_UPPER_LOAD_00, run = PROGRAM_ROM_UPPER_RUN_00, type = ro, define = yes;
Then, I have a macro that uses the SIZE symbols to calculate how much space I have left:
Code:
;writes the amount of space left in a program ROM bank of the specified size to the debug file
.macro Assembler_DEBUG_BANK _Bank, _Size
.import .ident(.sprintf("__PROGRAM_ROM_LOWER_%02d_SIZE__", _Bank))
.import .ident(.sprintf("__PROGRAM_ROM_UPPER_%02d_SIZE__", _Bank))
Assembler_START_DEBUG
.byte .sprintf("Bytes left in bank %02d: ", _Bank)
Assembler_WRITE_NUMBER (_Size) - .ident(.sprintf("__PROGRAM_ROM_LOWER_%02d_SIZE__", _Bank)) - .ident(.sprintf("__PROGRAM_ROM_UPPER_%02d_SIZE__", _Bank)), 10, 5
.byte $0d, $0a
Assembler_END_DEBUG
.endmacro
It makes use of 2 other macros to output the information to a debug file (anything in the DEBUG segment goes to a file named debug.txt):
Code:
;starts a block of debug information
.macro Assembler_START_DEBUG
.pushseg
.segment "DEBUG"
.endmacro
;ends a block of debug information
.macro Assembler_END_DEBUG
.popseg
.endmacro
And this is the macro that converts the number into an ASCII string:
Code:
;writes the specified number of places of a non-constant number in the specified base to the active segment
.macro Assembler_WRITE_NUMBER _Number, _Base, _Places, _Divisor
.ifblank _Divisor
Assembler_WRITE_NUMBER _Number, _Base, _Places, 1
.else
.if _Places > 0
.local __Digit
__Digit = (_Number) / (_Divisor) .mod (_Base)
Assembler_WRITE_NUMBER _Number, _Base, (_Places) - 1, (_Divisor) * (_Base)
.lobytes __Digit + '0' * (__Digit < 10) + ('A' - 10) * (__Digit > 9)
.endif
.endif
.endmacro
Then, at the end of the .BAT file I use for assembling, I use
type debug.txt to display whatever debug.txt contains, so I can see the amount of free space every time I assemble.