#17953 - Darmstadium - Wed Mar 17, 2004 10:46 pm
I can not figure out what the heck is wrong with this code to display a sprite:
Code: |
#include "gba.h"
#include "dispcnt.h"
#include "keypad.h"
#include "sprite.h"
//#include "bg.h"
#include "dma.h"
#include "box.pal.c"
#include "box.raw.c"
void CopyOAM()
{
/*REG_DM3SAD = (u32)sprites;
REG_DM3DAD = (u32)OAM;
REG_DM3CNT = 256 | DMA_ENABLE | DMA_TIMEING_IMMEDIATE | DMA_32;*/
u16 loop;
u16 * temp = (u16*)sprites;
for(loop = 0; loop < 512; loop++)
OAM[loop] = temp[loop];
}
void WaitForVsync()
{
while((volatile u16)REG_VCOUNT != 160){}
}
void InitializeSprites()
{
u16 loop;
for(loop = 0; loop < 128; loop++)
{
sprites[loop].attribute0 = 160;
sprites[loop].attribute1 = 240;
}
}
int main()
{
u16 loop;
SetMode(MODE_1 | OBJ_MAP_1D | OBJ_ENABLE);
for(loop = 0; loop < 256; loop++)
OBJPaletteMem[loop] = box_Palette[loop];
for(loop = 0; loop < 128; loop++)
OAMData[loop] = box_Bitmap[loop];
InitializeSprites();
sprites[0].attribute0 = COLOR_256 | SQUARE | 50;
sprites[0].attribute1 = SIZE_32 | 100;
sprites[0].attribute2 = 0;
while(1)
{
WaitForVsync();
CopyOAM();
}
return 0;
}
|
If you could tell me what is wrong with this code, I will worship you.
#17954 - sajiimori - Wed Mar 17, 2004 10:56 pm
I don't see anything wrong with your code. Use VBA's tools to check if your palette and graphics are being loaded correctly.
#17955 - poslundc - Wed Mar 17, 2004 10:57 pm
Well, for one, you're #including C files. You should only ever #include header files (.h), and those files should never contain any variable definitions (unless they are extern variable references) or executable code (unless they are in #define macros or static inline functions).
Data should be put into C files (or other types of files appropriate for data; not .h!) and then compiled and linked to the rest of your project using gcc.
Oh, and I'm not looking for worship, but if you're looking for help debugging your program it's a good idea to post what happens when you try to compile or run it.
Dan.
#17992 - Lupin - Thu Mar 18, 2004 4:07 am
i think he just used the file names that his converter gave him, some gfx converters compile images to .c file and not to .h file, i don't think that really matters... I also can't see anything wrong, i am just wondering why you want to display a sprite that's consuming all your OAM entries.
_________________
Team Pokeme
My blog and PM ASM tutorials
#17996 - sajiimori - Thu Mar 18, 2004 4:58 am
I don't see anything that suggests that the sprite consumes more than 1 OAM entry. In fact, that might not be a meaningful statement, since each OAM entry represents exactly 1 sprite (though a conceptual game-object might be represented by multiple sprites).
#18000 - yaustar - Thu Mar 18, 2004 6:30 am
doesn't OAM and sprites need to be defined?
Code: |
u16* OAM = (u16*)0x7000000;
OAMEntry sprites[128]; |
and I think a 32x32x256 sprite is a 512 array
_________________
[Blog] [Portfolio]
#18012 - XeroxBoy - Thu Mar 18, 2004 5:54 pm
The fact that he never loads his sprite graphics might be the problem.
#18015 - sajiimori - Thu Mar 18, 2004 6:27 pm
yaustar, if those things weren't defined, it wouldn't even compile. Those definitions could be in any one of the included files (though sprites[] shouldn't be in a header, but whatever).
XeroxBoy, I don't know how you came to your conclusion. You might avoid throwing around words like "fact".
#18018 - yaustar - Thu Mar 18, 2004 6:53 pm
The guy didn't mention that it compiled...just it didn't work :p
Code: |
for(loop = 0; loop < 128; loop++)
OAMData[loop] = box_Bitmap[loop];
InitializeSprites();
sprites[0].attribute0 = COLOR_256 | SQUARE | 50;
sprites[0].attribute1 = SIZE_32 | 100;
sprites[0].attribute2 = 0;
|
If I am assuming that it does compile and the sprite is not displayed properly, then I put it down that only a quarter of the actual tile data is transfered to OAM.
Code: |
for(loop = 0; loop < 512; loop++)
OAMData[loop] = box_Bitmap[loop]; |
Until the guy replies again we really cannot do much by assumptions alone ;)
_________________
[Blog] [Portfolio]
#18020 - XeroxBoy - Thu Mar 18, 2004 7:19 pm
sajiimori wrote: |
XeroxBoy, I don't know how you came to your conclusion. You might avoid throwing around words like "fact". |
Sorry if I sounded a bit stuck-up. Yaustar's probably right - when I saw OAMData and 128, my brain automatically assumed that he was copying his OAM data and not the actual tile data.
#18022 - sajiimori - Thu Mar 18, 2004 8:50 pm
yaustar, there's still no way to know how much tile data is actually being transferred. A 32x32 8-bit image is not a specific number of "elements" -- you can divide it into 1024 bytes, 512 shorts, 256 longs, 128 long-longs, or even 4 structs that are 256 bytes each.
So while it's unlikely that OAMData and box_Bitmap are both of type long long*, it's possible to copy a 32x32 8-bit image with a for-loop that does 128 iterations. ;-)
#18024 - yaustar - Thu Mar 18, 2004 9:01 pm
So true.. :)
_________________
[Blog] [Portfolio]