ca65: space left in bank/segment?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
gauauu
Posts: 648
Joined: Sat Jan 09, 2016 9:21 pm
Location: Central Illinois, USA
Contact:

ca65: space left in bank/segment?

Post by gauauu » Mon Nov 06, 2017 10:04 pm

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.

User avatar
rainwarrior
Posts: 7669
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: ca65: space left in bank/segment?

Post by rainwarrior » Mon Nov 06, 2017 10:13 pm

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.

User avatar
dougeff
Posts: 2614
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: ca65: space left in bank/segment?

Post by dougeff » Mon Nov 06, 2017 10:19 pm

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).
nesdoug.com -- blog/tutorial on programming for the NES

User avatar
gauauu
Posts: 648
Joined: Sat Jan 09, 2016 9:21 pm
Location: Central Illinois, USA
Contact:

Re: ca65: space left in bank/segment?

Post by gauauu » Mon Nov 06, 2017 10:25 pm

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)
Last edited by gauauu on Mon Nov 06, 2017 10:35 pm, edited 1 time in total.

User avatar
gauauu
Posts: 648
Joined: Sat Jan 09, 2016 9:21 pm
Location: Central Illinois, USA
Contact:

Re: ca65: space left in bank/segment?

Post by gauauu » Mon Nov 06, 2017 10:31 pm

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

User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2032
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: ca65: space left in bank/segment?

Post by FrankenGraphics » Tue Nov 07, 2017 12:06 am

Shiru's space checker (already mentioned) provides visual feedback in a way that's quick to overview.
http://www.frankengraphics.com - personal NES blog

calima
Posts: 1016
Joined: Tue Oct 06, 2015 10:16 am

Re: ca65: space left in bank/segment?

Post by calima » Tue Nov 07, 2017 1:25 am

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

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

tepples
Posts: 21748
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: ca65: space left in bank/segment?

Post by tepples » Tue Nov 07, 2017 12:28 pm

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: 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;
}
Then title.s picks up these symbols:

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

User avatar
pubby
Posts: 543
Joined: Thu Mar 31, 2016 11:15 am

Re: ca65: space left in bank/segment?

Post by pubby » Tue Nov 07, 2017 1:28 pm

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

Code: Select all

    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: 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
Subtract from 0xC000 to get the size.

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

Post Reply