#21104 - aleister - Sun May 23, 2004 10:17 pm
Searching this forum, I came across several threads explaining that data should be placed in a .c-file, not in a header-file. To my pleasant surprise this approach also provided an answer to the problem of running out of memory since it would not automatically try to put all the data I define into the working RAM...
What I can't figure out however, is how to address the data when it is included like this. Upon compiling I keep getting the message that the variables are undeclared (first use in this function).
I used to do it like this: an array containing the different frames of animation for a sprite were located in, for example, gfxsprite0.h, like this:
In the main c-source, I would include it using #include gfxsprite0.h and copy the desired part of the array to VRAM using:
(in this example 4096 since I'm working with a 64x64 sprite using 256 colors in mode4)
The above code compiles and works perfectly, but I run into the undeclared variable problem when I attempt to do it the proper way, and change gfxsprite0.h to:
and move the actual data to a file named gfxsprite0.c:
I am slowly getting the idea that this may have something to do with the make.bat-file; my make.bat looks like this:
For all completeness: I'm compiling this using devkitadvance.
My sincere apologies if this issue has already been explained, but if it has, I'm afraid I couldn't find it while searching through this forum. Thanks ever so much in advance for any help you can offer.
What I can't figure out however, is how to address the data when it is included like this. Upon compiling I keep getting the message that the variables are undeclared (first use in this function).
I used to do it like this: an array containing the different frames of animation for a sprite were located in, for example, gfxsprite0.h, like this:
Code: |
const u16 gfxsprite0Data[] = { 0xFFFF, 0xFFFD, 0x0000, 0xFFFF, etc...etc... 0x0000, 0x0000,}; const u16 gfxsprite0Palette[] = { 0x7FFF, 0x35B8, 0x0850, etc... etc.. 0x67FF, 0x7FFF,}; |
In the main c-source, I would include it using #include gfxsprite0.h and copy the desired part of the array to VRAM using:
Code: |
memcpy( (u16 *)0x06014000, &gfxsprite0Data[0], 4096 ); |
(in this example 4096 since I'm working with a 64x64 sprite using 256 colors in mode4)
The above code compiles and works perfectly, but I run into the undeclared variable problem when I attempt to do it the proper way, and change gfxsprite0.h to:
Code: |
#ifndef PLAYERGFX #define PLAYERGFX extern const u16 gfxsprite0Data[]; #endif |
and move the actual data to a file named gfxsprite0.c:
Code: |
extern const u16 gfxsprite0Data[] = { 0xFFFF, 0xFFFD, 0x0000, 0xFFFF, etc...etc... 0x0000, 0x0000,}; extern const u16 gfxsprite0Palette[] = { 0x7FFF, 0x35B8, 0x0850, etc... etc.. 0x67FF, 0x7FFF,}; |
I am slowly getting the idea that this may have something to do with the make.bat-file; my make.bat looks like this:
Code: |
path=C:\devkitadv\bin gcc -o maingame.elf maingame.c -lm objcopy -O binary maingame.elf maingame.gba |
For all completeness: I'm compiling this using devkitadvance.
My sincere apologies if this issue has already been explained, but if it has, I'm afraid I couldn't find it while searching through this forum. Thanks ever so much in advance for any help you can offer.