nesdev.com
http://forums.nesdev.com/

ca65: space left in bank/segment?
http://forums.nesdev.com/viewtopic.php?f=2&t=16677
Page 1 of 1

Author:  gauauu [ Mon Nov 06, 2017 10:04 pm ]
Post subject:  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.

Author:  rainwarrior [ Mon Nov 06, 2017 10:13 pm ]
Post subject:  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.

Author:  dougeff [ Mon Nov 06, 2017 10:19 pm ]
Post subject:  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).

Author:  gauauu [ Mon Nov 06, 2017 10:25 pm ]
Post subject:  Re: ca65: space left in bank/segment?

rainwarrior 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.


That was my plan as well :-)

(Particularly since I'm already using an old version of your python script to generate the FCEUX debug files)

Author:  gauauu [ Mon Nov 06, 2017 10:31 pm ]
Post subject:  Re: ca65: space left in bank/segment?

dougeff wrote:
. And, it (the linker) will give you an error if you overflow a bank (memory area).


Yeah, I don't really care about segments as much as the entire bank.

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!"

Author:  FrankenGraphics [ Tue Nov 07, 2017 12:06 am ]
Post subject:  Re: ca65: space left in bank/segment?

Shiru's space checker (already mentioned) provides visual feedback in a way that's quick to overview.

Author:  calima [ Tue Nov 07, 2017 1:25 am ]
Post subject:  Re: ca65: space left in bank/segment?

od65 -S *.o | grep mybank | summer 2

where summer is a custom script:
Code:
#!/bin/sh

count=$1
[ -z "$count" ] && echo "Usage: $0 column" && exit

awk --non-dec "{s+=\$$count} END {print s}"

Author:  tepples [ Tue Nov 07, 2017 12:28 pm ]
Post subject:  Re: ca65: space left in bank/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?

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.

Author:  pubby [ Tue Nov 07, 2017 1:28 pm ]
Post subject:  Re: ca65: space left in bank/segment?

Add dummy segments at the very end of the cfg file:

Code:
    BANK0_END:    load = PRG0, type = ro;
    BANK1_END:    load = PRG1, type = ro;
    BANK2_END:    load = PRG2, type = ro;

Then the 'Start' value in the map file shows where each bank ends.
Code:
Name                   Start     End    Size  Align
----------------------------------------------------
BANK0_END             00BA80  00BA80  000001  00001
BANK1_END             008AB6  008AB6  000001  00001
BANK2_END             00BF00  00BF00  000001  00001

Subtract from 0xC000 to get the size.

You might need to fill these dummy segments with a single byte.

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/