Estimating ram and rom usage?

SGDK only sub forum

Moderator: Stef

Post Reply
djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Estimating ram and rom usage?

Post by djcouchycouch »

Hi,

Is there a way to estimate how much ram is being used by my game? Without having to count every variable in my code, that is.

Also, how can I tell how large my game rom is without the padding?

(as usual, I'm using SGDK)

Thanks!
DJCC
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

First, set your makefile to generate a link map.

Code: Select all

LDFLAGS = -T $(LDSCRIPTSDIR)/mars.ld -Wl,-Map=output.map -nostdlib
That will tell you the address and size of nearly everything. Second, make padding the rom a separate step with a different name than the binary. That way you can see what size the binary alone was.

Code: Select all

$(TARGET).bin: $(TARGET).elf
	$(OBJC) -O binary $< temp.bin
	$(DD) if=temp.bin of=$@ bs=4096K conv=sync

$(TARGET).elf: $(OBJS)
	$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $(TARGET).elf
Notice that making the elf file uses the flag that produces the link map. Then making the bin file makes the bin under a set name (temp.bin), and THEN pads it out to the desired size/multiple with the final name for the binary.
KanedaFr
Administrateur
Posts: 1154
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr »

It's why I use Ucon for padding ;)
it tells you what is the size w/o padding

I'm not sure 'dd' is available on SGDK, no ?
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

I think you already have memory managements methods in last version of SGDK so you should have

Code: Select all

u32 MEM_getFree()
which returns the number if free bytes.
Basically you have 64 KB of memory so 64 KB - MEM_getFree() will return you the consumed memory :)
djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch »

Stef wrote:I think you already have memory managements methods in last version of SGDK so you should have

Code: Select all

u32 MEM_getFree()
which returns the number if free bytes.
Basically you have 64 KB of memory so 64 KB - MEM_getFree() will return you the consumed memory :)

Heh! I didn't even know there was a memory manager. :) I just have a whole bunch of static global variables at the moment.
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

KanedaFr wrote:It's why I use Ucon for padding ;)
it tells you what is the size w/o padding

I'm not sure 'dd' is available on SGDK, no ?
It's a default part of EVERY *nix system out, and an installable part of cygwin and mingw. Ucon is great as well, but not a default thing, nor in any repo - you have to go get it from sourceforge. It's also a bit overkill for just padding a rom. :lol:

One of the reasons I like dd is that it's very flexible... if the blocksize is smaller than the filesize, it makes it the next multiple of the blocksize. If it's bigger than the filesize, it pads it to the blocksize. So if you just want the rom to be a multiple of 8K, you just use bs=8K (or bs=8192).
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

djcouchycouch wrote: Heh! I didn't even know there was a memory manager. :) I just have a whole bunch of static global variables at the moment.
The memory manager was introduced in the last SGDK version so it is not surprising you didn't know about it ;)
djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch »

One year later...

I've figured out how to generated a map file, but I'm having a bit of trouble interpreting it.

I posted Propeller's map file here: http://pastebin.com/R9yVam4J

Does line 264 (the one with __DYNAMIC = 0x0) indicate where the data stored in ROM starts? "playerSprite" is an import from genres, so I think so.

Does line 891 (first instance of .data) indicate where variables mapped to RAM starts? The .bss section seems related.
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

The linker script (ld) file sets things like where the rom and ram are. The map shows them like this (line 225):

Code: Select all

Memory Configuration
 
Name             Origin             Length             Attributes
rom              0x00000000         0x00a00000
ram              0x00ff0000         0x00010000
Things like "__DYNAMIC = 0x0" are symbols set by the linker script and only make sense to the code that uses said symbols.

Starting at line 267 you get a list of the files that contributed to the .text section, at line 800 you get other sections that go into rom, at line 891 you get the .data section list, at line 975 you get the .bss section list, and at line 1086 you get all the common vars that wind up in the bss.

Line 1201 gives you this:

Code: Select all

 0x00ff2508                _bend = .
That is the end of ram usage by the program. Line 889 gives you this:

Code: Select all

0x0002aafc                _stext = SIZEOF (.text)
That is the end of rom usage by the program.
Post Reply