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++ > GBA adaptation of x86 program

#19311 - gbanoob - Sat Apr 17, 2004 12:18 am

Hi !

I'm really new on GBA(for 3 days lol), so I don't really know how hardware works.
I'm trying to make an adaptation of a C++ x86 prog on GBA. (it works fine on x86 ;) )
All the compilation process works fine with devkitadv-r5-b3.
But when I'm testing my code on an gba emulator(mappy), when I try to create an c++ object, the emulator restarts my code from the beginning (maybe there is a general error and the gba reboot)
In the main code I use a 5k const array.
In the oject there is a 65k array, and some malloc, memcpy, string from STL and base code nothing more.
Could it be a memory problem ?
I had try to debug it with mappy but when I'm loading the .elf mappy crashs ...

thanks in advance.

ps:sorry for my bad english ;)

#19312 - Lord Graga - Sat Apr 17, 2004 1:02 am

are you using any windows/linux targetted libaries?

GBA has a totally different layout and way of acting than x86, so you'll have to port it over....

#19313 - gbanoob - Sat Apr 17, 2004 1:22 am

No I don't use any targetted libraries.

#19315 - sajiimori - Sat Apr 17, 2004 4:18 am

Have you tried writing some smaller test apps in C++? Perhaps you can narrow it down to something more specific.

#19316 - DekuTree64 - Sat Apr 17, 2004 4:46 am

Is the 65K array in RAM, or is it const too? If RAM, you'll need to make sure it goes into EWRAM some way or another, because IWRAM is only 32K, and that's where variables go by default.
To put it in EWRAM, you can either use an __attribute (don't remember the exact syntax), or put it there in code, by using EWRAM like a large stack, just initializing a pointer to the top of it (0x2040000) and subtracting 65K from that, and replace the array with a pointer which you then set to your EWRAM pointer. Then you can subtract more from the main pointer later and use that for more storage space, and add them back when you're done with them. That's exactly how the 'real' stack works too.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#19318 - sajiimori - Sat Apr 17, 2004 5:15 am

Code:

   for(i=0; i < 7; i++)
   {
      for(b=0; b < Mem_Length; b++)
      {
         if(Data[b] & (1 << i ))
            channels[i] |= 1 << ((Mem_Length - 1) - b);
      }
   }

If Mem_Length is greater than 32, you're shifting off the edge of the 32-bit long. Try long long for 64 bits (if your compiler supports it), or use a custom structure.

#19332 - gbanoob - Sat Apr 17, 2004 4:19 pm

Ah yes thanks so much, it was the too small IWRAM ;)

Hum but if I need more memory than IWRAM+EWRAM, there is a space where I can put my other datas ?

** edited **
hum I found this :
http://www.ziegler.desaign.de/GBA/gba.htm#GBA%20memory%20map
It seems except in ROM there is no more space ;)

#19340 - Miked0801 - Sat Apr 17, 2004 7:02 pm

Welcome to handheld RAM concerns. The GBC/DMG was even worse :)

#19342 - tepples - Sat Apr 17, 2004 7:05 pm

If you have data that won't change, it's best to make it const. The popular linker scripts will put const data in ROM if you're making a cartridge-based program. If you need to store more non-const state than the capacity of IWRAM + EWRAM + those parts of VRAM you aren't using for video, then consider developing for Palm or Pocket PC rather than for GBA.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#19345 - sajiimori - Sat Apr 17, 2004 7:11 pm

Oops, my earlier post was to the wrong thread!! lol

#19348 - gbanoob - Sat Apr 17, 2004 7:26 pm

tepples wrote:
then consider developing for Palm or Pocket PC rather than for GBA.

Lol, you are malicious with me tepples. Sure that, like me, you understand that is why dev on GBA may be fun.

#19354 - tepples - Sat Apr 17, 2004 8:33 pm

What arrays do you need to store that take more than 256 KB (capacity of EWRAM)?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#19362 - gbanoob - Sat Apr 17, 2004 11:14 pm

tepples wrote:
What arrays do you need to store that take more than 256 KB (capacity of EWRAM)?


Actually I don't need more, it was just a question ....