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.

C/C++ > Const arrays

#1068 - Japster - Tue Jan 14, 2003 9:51 am

Are arrays that are constants stored in the internal ram in GBA or in the ROM in game cart? I noticed that internal ram is so small that few arrays overlaps each other.(sorry for my english skills...)

Thanks, Jasper.

#1069 - anli - Tue Jan 14, 2003 10:09 am

It will be stored in ROM!

An easy way to find out is to use the address operator & and print
out the address of a variable.

/anli

#1070 - Touchstone - Tue Jan 14, 2003 10:29 am

An even easier way to figure out where your data is located is by having the linker produce a map file. This is done by passing the switch '-Map myproject.map' to the linker.
_________________
You can't beat our meat

#1072 - bomberman - Tue Jan 14, 2003 11:05 am

How do you force your code to run in ram rather than in rom?

#1073 - anli - Tue Jan 14, 2003 11:16 am

Here is how you put it in .iwram, however, I didnt manage to use .wram instead of .iwram:

Code:

void foo(void) __attribute__ ((section(".iwram")));

void foo()
{
}

void AgbMain()
{
  foo();
}


/anli

#1074 - Quirky - Tue Jan 14, 2003 11:34 am

Code:

#define CODE_IN_IWRAM __attribute__ ((section (".iwram"), long_call))

void foo(void) CODE_IN_IWRAM;

CODE_IN_IWRAM void foo()
{
}

void AgbMain()
{
  foo();
}


That's it taken from devrs.com. foo should be in a seperate object file to the calling routine. And I you may well need -mthumb-interwork on your cflags in the make file for the objects calling that bit of code.

#1077 - anli - Tue Jan 14, 2003 12:29 pm

You can also to put the code in .ewram.

(Which you have plenty of compared to the .iwram:
256K compared to 32K, but it is slower).

#1083 - Touchstone - Tue Jan 14, 2003 2:00 pm

I belive external RAM accesses are slower than ROM accesses. Can someone confirm?
_________________
You can't beat our meat

#1088 - Splam - Tue Jan 14, 2003 2:24 pm

afaik the cache doesn't work on ram so you can set the 1st access waitstates for ram and rom to be the same speed but 2nd sequential access (and any from there) will be faster in rom than ram due to the cache (not to be confused with the iwram prefetch which only works on instructions not ram access).

#1117 - tepples - Tue Jan 14, 2003 8:05 pm

Touchstone wrote:
I belive external RAM accesses are slower than ROM accesses. Can someone confirm?


EWRAM and ROM run at about the same speed for data tables or for code with a lot of branches. A typical ROM has 3 wait states for random access and 1 for sequential access; EWRAM has 2 for both. One advantage of EWRAM is that accessing EWRAM drains the battery less than accessing ROM.

Another trick: Store variables in unused areas of VRAM; it's 16-bit wide with less than 1 wait state on average, but byte writes don't work. It should work well for DMA buffers such as mode 1/2 scanline parameter tables and audio mix buffers that have to persist across IWRAM overlays.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.