#4434 - regularkid - Mon Mar 31, 2003 4:22 am
I'm having a problem with some of my code. The problem is that I have a large amount of code that I need am running out of space for my other code. Is there a way to place this code (it is in ASM by the way) in a different part in memory in order to save space for the rest of my code?
Thanks?
_________________
- RegularKid
#4438 - DekuTree64 - Mon Mar 31, 2003 8:07 am
Umm, not sure exactly what you mean. Are you putting it in IWRAM and running out of space? You can change where the compiler puts thing in IWRAM in your linkscript (just look near the start where it defines iwram_start as 0x3000000, and change it to 0x3000400 or something (that would give you 1KB free)), and copy code into that first KB with DMA or whatever, and then branch to 0x3000000. That way, you can just have whatever code you need at the time in IWRAM. Of course it does take just as long to copy the code as it does to execute it from ROM to begin with, except for loops where it reads the same part over and over (or short functions that are called all the time or whatever).
Or did you mean something else? I'm half asleep, so I might have guessed wrong^^;
#4464 - regularkid - Mon Mar 31, 2003 6:17 pm
Kind of. :) Basically, I was wondering if there was a way to place code in a different part of memory to save room in ram. However, I don't want to have to DMA stuff in. Is it possible to just tell the hardware to run code from a different part in memory instead of ram?
_________________
- RegularKid
#4465 - DekuTree64 - Mon Mar 31, 2003 7:09 pm
Well, normally you just run code from ROM, which is where it starts off anyway (if you put it in IWRAM, it just copies it there from ROM when the game starts up). You can put code in EWRAM if you want to, but it's a little slower than ROM (doesn't drain the battery quite as fast though). It depends on how you manage EWRAM how to put code there. I just use it like a huge stack, so if you're doing that, just take a hunk of it, and DMA while doing your initial setup, and use a variable to store where you put it to branch later (like a function name). Or if you're letting the compiler handle everything, just do it the same way as IWRAM, but change the I to an E. Since you said it's in ASM, I think you'd just put something like
.global func
.section ewram
.arm (or thumb)
func:
do stuff
Or if your actual function is in C with inline ASM, use the __attribute() thing (don't remember the exact syntax off hand) to do it. But like I said, EWRAM is slow, so generally you should run code from ROM, and anything speed-critical from IWRAM. Then non-speed critical, but frequently called code is good in EWRAM to save battery power, but not really necessary.
#4466 - regularkid - Mon Mar 31, 2003 7:30 pm
Great. Thanks. How much space do I have for EWRAM and IWRAM?
_________________
- RegularKid
#4468 - Torlus - Mon Mar 31, 2003 8:37 pm
32 Ko in IWRAM and 256 Ko in EWRAM
for code execution, in my opinion you have 2 choices :
- run thumb code from rom. thumb code runs 40% faster from rom than arm code.
- run arm code from iwram.
you should have a look at GBATEK documentation, and Jeff F's faq, which will give you a lot of information about advantages and drawbacks for all that stuff.
#4470 - regularkid - Mon Mar 31, 2003 10:40 pm
Wait, I'm confused...so code can be put into ROM? That would be great because ROM is huge, right? (size of cartridge, eg. 64mb, 128mb or 256mb?) This makes way more sense than putting it in RAM which only has 256k or 32k. Am I correct in thinking this?
_________________
- RegularKid
#4472 - ampz - Mon Mar 31, 2003 11:57 pm
Someone should really read some of the newbie tutorials I think. *caugh*
If you have a flashcart, then put your code on the flashcart and be happy.
flash=ROM
#4736 - Burre - Tue Apr 08, 2003 10:03 am
regularkid wrote: |
Wait, I'm confused...so code can be put into ROM? That would be great because ROM is huge, right? (size of cartridge, eg. 64mb, 128mb or 256mb?) This makes way more sense than putting it in RAM which only has 256k or 32k. Am I correct in thinking this? |
Hehehe...
Really sorry for laughing but your thread was kind of funny. You see, if this were a PC game forum that question would be similar to: "oh, so I can actually distribute my games on CD? Great, that means that I won't have to give them pre-loaded RAM-modules with my game on it."
_________________
"The best optimizer is between your ears..."
#4754 - Unciaa - Tue Apr 08, 2003 4:31 pm
ampz wrote: |
Someone should really read some of the newbie tutorials I think. *caugh* |
Newbie tutorials discuss RAM? ;)
To add a question, how well does the compiler handle code control [using gcc here]? AKA, do I need to delve into the regions of manually telling my code when to copy certain portions to active memory just to keep the thing running smoothly or is that usually unnecessary?
#4759 - tepples - Tue Apr 08, 2003 5:20 pm
Burre wrote: |
You see, if this were a PC game forum that question would be similar to: "oh, so I can actually distribute my games on CD? Great, that means that I won't have to give them pre-loaded RAM-modules with my game on it." |
Of course, it's different when an XBOO cable is an order of magnitude cheaper than a flash cart and linker.
That said, when you compile a program to run from 0x08000000 (Devkit Advance's default setting, used when there does not exist a symbol called "__gba_multiboot"), it will normally place all code in ROM. You can tell it to put a piece of code in IWRAM by naming the object file something ending in ".text.iwram.o".
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#4764 - regularkid - Tue Apr 08, 2003 11:22 pm
Thanks for all the help. I researched it some more (mostly Jeff Frohwein's FAQ) and learned all about where the different variables and code are put into memory and can track it all very well now with the use of the "-Map game.map" compiler option to output a memory map for me. I'm learning more and more eveyday! :) I was able to find out that my code WAS infact being put into ROM after all and that the problem I had was I had too many global variables (and a few large tables) being put into IWRAM (32k) and that was causing my problems (I went over the 32k limit). But now, with the help of these:
Code: |
#define VAR_IN_IWRAM __attribute__ ((section (".iwram")))
#define VAR_IN_EWRAM __attribute__ ((section (".ewram")))
|
I am able to put variables in either section of RAM (plus "const" to be able to put globals into ROM...but I already knew that). Now I have much much more control over where everything is going into memory! Sweet!
I tried to get the same stuff working for functions as well, but no luck. But it was late and I was tired :) . I will keep trying, though.
As a side question: Does anyone know how to specify in C code whether a peice of code should be translated into THUMB or into ARM (I'm looking for something similar to the above defines)? This would be very useful.
Thanks again.
_________________
- RegularKid
#4768 - tepples - Wed Apr 09, 2003 3:15 am
regularkid wrote: |
Does anyone know how to specify in C code whether a peice of code should be translated into THUMB or into ARM (I'm looking for something similar to the above defines)? |
I don't know if GCC supports choosing the instruction set for a particular function from within a C source file. You can choose the instruction set for a particular module at the command line (look for 'interwork' in Jeff F's FAQ).
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.