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++ > Large OAM initialisation problem

#26897 - twistee - Tue Sep 28, 2004 3:55 pm

Hi,

I made a bunch of sprites and wanted to load them into the OAM. I did:

Code:
    for(loop = 0; loop < 26112; loop++){ //51 32x32 256 colour sprites
        OAMData[loop] = wozzaData[loop];
    }


But when I actually load the game no sprites come up, and when I check the memory for the OAM there is nothing there. I read about the troubles with arrays larger than 16k, but im not sure what to do with OAM...

#26898 - poslundc - Tue Sep 28, 2004 4:06 pm

OAM is object attribute memory, key word "attribute". It contains meta-information about the sprite, like x and y coordinate, shape and size, etc. Not the actual pixel map itself.

OAMData looks like it comes from one of the tutorials like Pern and is a bad misnomer for Sprite VRAM. This is where the actual pixel-plot of the sprite is stored.

There is nothing wrong with using the name OAMData so long as you keep it distinct from actual OAM. In order for a sprite to display you need to populate two sections of data: the Sprite VRAM and the OAM. The Sprite VRAM tells the GBA what to display; the OAM tells it how to display it.

Unless you provide correct data in both Sprite VRAM and OAM, you won't get any sprites showing properly. Your code is only populating Sprite VRAM, not OAM.

Dan.

#26899 - expos1994 - Tue Sep 28, 2004 4:39 pm

Open up your ROM in Visual Boy and select Tools/Tile Viewer, click the radio button at 0x6010000. If OAMData is pointing to the right spot in memory (and it will be if you are using the Pern Project Tutorials), you should see your data. (You may have to click the 256 colors radio button).

If you still don't see anything, did you load the 256 color palette?

If you did those two steps and you still see blank tile memory, then I would check the data from wozzaData[].

Also you are going to be cutting it close loading that many 256 color tiles. With 256 colors you can only load half as many tiles as you could with 16-color. So if your 51 sprites are just frames of animation, you might want to think about copying in frames as they are needed so you only use 32 tiles of tile memory at a time.

Actually, I think you may be over already. A 32x32 sprites takes 16 tiles. In 256 color mode that's 32 tiles (twice as much memory to store 256 color tiles). 32 * 51 sprites = 1632 tiles. I can't recall off the top of my head, but I think you only get 1024 tiles for your sprites. Either way, you really should think about copying data in frame by frame. The GBA doesn't skip a beat loading a 32x32 frame. Especially if you use DMA.

#27168 - twistee - Tue Oct 05, 2004 8:12 am

Ok, I have decided to do it frame by frame. Although, I am not too sure how to do this. I tried a simple method using basically the same code I had, but added a function to load the specific frame into the memory when needed:

Code:
void LoadSprite(int i){
    for(int loop = i*512; loop < (i*512+512); loop++){
        OAMData[loop] = wozzawalkData[loop];
    }
}


But it only shows the very first sprite (as its the first loaded), and then never changes...even though it should be attempting to load the other sprites. Is there anything I should add or completely change to do this properly?

#27175 - expos1994 - Tue Oct 05, 2004 2:47 pm

I'm not exactly sure what you are trying to do there. Below is the way I do it. This would load 512 elements from wozzawalkData at the beginning of OAMData. On frame 0, it would grab the first 512, frame 1 would grab the second 512, and so on.

If this weren't the first sprite in VRAM. You would want to do this OAMData[loop + offset].

You might also check up on using DMA. it works well for tasks like this, but doing it this way shouldn't slow you down.

Code:

for (loop = 0; loop < 512; loop++)
       OAMData[loop] = wozzawalkData[loop + (framenumber * 512)];

#27244 - twistee - Thu Oct 07, 2004 12:00 pm

Yeah I wasnt sure what i was doing with the code either looking at it now, what you gave me worked, thanks for the help!