#140001 - Leevon - Wed Sep 12, 2007 3:51 pm
First of all, sorry for my english guys, but i really can't figure this out alone.
I begin to write C GBA code just few days ago, and I think i'm missing something important, because my program acts quite weird.
I've written a structure to keep all the sprites informations. So the OAM of the sprite is in this structure, but when i try to pass the address of the oam field in order to be modified, this is totally erased from the stack, and then from mem when I call the update function, wich is "static inline" and works just well. This happens even if i just pass it to a totally empty function, but i can pass other types without problems, like u8* or u32*. What I'm missing?
#140008 - sajiimori - Wed Sep 12, 2007 6:46 pm
Hard to say. Can you give a very small code example that illustrates the problem? The example should include the definition of anything that the example uses.
#140037 - Leevon - Wed Sep 12, 2007 11:03 pm
Here is the structure:
typedef struct Oam_entry
{
u16 attr0;
u16 attr1;
u16 attr2;
s16 fill;
}Oam_entry;
The problem is simple, every non inline function destroy this, even if I pass just the pointer, even if I pass a const pointer, and now i was trying using a global variable: Nothing.
The program works well if I use the Oam_entry only in the main(), the working loop is this:
int main()
{
u8 x = 1, y=1;
u32 i;
Oam_entry oam;
// set memory and oam....
while(1)
{
for(i=0; i<2000; i++) // I know, this sucks
while(REG_VCOUNT < 160);
key_check(key_buff);
movement(&x, &y); // obviously move the sprite
oam_set_pos(&oam, x,y ); // this is inline and works
oam_update ( &oam, 0 ); // this too
}
Whit this, the sprite shows up and moves just like I want. But if I try todo this:
while(1)
{
for(i=0; i<2000; i++) // I know, this sucks
while(REG_VCOUNT < 160);
key_check(key_buff);
movement(&x, &y, &oam); // positioning and update are in the function itself
}
There is no sign of the sprite, and neither the OAM, in fact using VBA I can't see the OAM in ram.
So, I tried doing NOTHING inside the function, and keeping oam_set_pos and oam_update in the main: no sprite again. Then I tried passing the whole Oam_entry, not just the pointer, in something like
oam = movement (&x, &y, oam);
Wich is definitely the worst thing i could ever think, but nothing, it seems that just putting the struct as a parameter screws everything up.
Again, sorry for my english :P Hope i'ts not too messed up :P
#140092 - Leevon - Thu Sep 13, 2007 2:25 pm
Sorry got a problem with the site. I'll put everything as soon as is solved...
#140114 - Leevon - Thu Sep 13, 2007 6:05 pm
Thank you so much *_________*
For everything *_* from the technical things to the right spell of beahaviour!
Now everything works! The behaviour func now takes a Struct*, so i can just made an array of sprites and move them in a single-line for loop *_*
Thanks so much ^_^