gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > serious memory issues

#168243 - moonlightcheese - Thu Apr 16, 2009 8:12 pm

ok so i'm building my first gba game and running into some serious memory woes. i've moved all data into source files and used externs in headers and i can't get enough room for background music. is there some way to access gamepak memory and actually use it in an emulator or some way to get a little more out of this system?

i'm able to make a single level of this game by copying everything directly into tile memory (backgrounds, sprites, etc) but how can i possibly get enough memory to contain other levels, sprite data and audio for more levels and content?

#168245 - kusma - Thu Apr 16, 2009 9:35 pm

put data in ROM, by declaring it as "const".

#168246 - moonlightcheese - Thu Apr 16, 2009 11:04 pm

that... solved it. god i feel like an idiot. thanks!

#168249 - kusma - Fri Apr 17, 2009 12:01 am

No stress. Everyone makes that mistake at some point :)

#172255 - Kensai - Wed Jan 27, 2010 7:59 pm

I've read that the GBA has 32K "in-chip" + 256K "on-board" memory. What's the difference actually? And which memory is accessed if I don't use "const"?

#172258 - Dwedit - Wed Jan 27, 2010 8:21 pm

The In-chip memory is much faster.

And apparently, data is all declared in IWRAM, unless you allocate it with malloc, or explicitly declare it elsewhere.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#172260 - Kensai - Wed Jan 27, 2010 8:33 pm

Thank you for the fast answer! So if I got you right, I have to use "malloc" if I want to access the slower on-board memory?

#172261 - Exophase - Wed Jan 27, 2010 8:34 pm

Kensai wrote:
I've read that the GBA has 32K "in-chip" + 256K "on-board" memory. What's the difference actually? And which memory is accessed if I don't use "const"?


The 32KB IWRAM is faster than the 256KB EWRAM.

The devkitAdvance link script reveals the following defaults:

.data (initialized global variables) defaults to IWRAM.
.bss (uninitialized variables) defaults to IWRAM.
.text (code) defaults to ROM.
.rodata (const global variables) defaults to ROM.

You can override this per-variable using attributes:

int global_in_ewram __attribute__((section (".ewram")));

You can also cause .data and .bss to be in EWRAM by declaring the following somewhere in your code:

int __gba_ewram_data __attribute__((section(".devkitadv.config")));

#172262 - Dwedit - Wed Jan 27, 2010 9:20 pm

DevKitAdvance? People still use that?
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#172268 - brave_orakio - Thu Jan 28, 2010 2:54 am

I thought that local variables go to EWRAM and global variables go to IWRAM? And malloc goes to IWRAM if not explicitly declared to go to EWRAM?
_________________
help me

#172273 - Cearn - Thu Jan 28, 2010 10:37 am

No, local variable go into registers, which use up no memory at all, or the stack, which is in IWRAM. Globals go into IWRAM if not explicitly declared otherwise. Malloc goes to EWRAM.

#172279 - Kensai - Thu Jan 28, 2010 8:10 pm

Quote:
The In-chip memory is much faster.


Maybe this is a silly question. But do emulators like Mappy or VBA simulate these different speeds of IWRAM, EWRAM and ROM?

#172280 - Dwedit - Thu Jan 28, 2010 8:46 pm

NO$GBA does the best job of simulating RAM speed, but it depends on whether you are using an old version of VisualBoyAdvance or not. Old versions don't simulate RAM speed accurately, newer versions do a better job.

Also don't forget that Video RAM can also be used as fast RAM if you need it.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#172306 - Kensai - Fri Jan 29, 2010 11:43 pm

How do I malloc in IWRAM? (I want to copy dynamic arrays from EWRAM to IWRAM.)

#172308 - Exophase - Sat Jan 30, 2010 3:45 am

Dwedit wrote:
DevKitAdvance? People still use that?


I have no idea what people use, but the link script I looked up was from whatever is current.

Dwedit wrote:
Also don't forget that Video RAM can also be used as fast RAM if you need it.


It still isn't clear if VRAM is 32bit or 16bit, but 16bit would be more realistic. In which case you could say that it's not quite as fast as IWRAM, at least when writing quantities of 32bits or more.

#172309 - Dwedit - Sat Jan 30, 2010 3:51 am

I use it as fast 8-bit read ram. It is indeed 16-bit memory.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."