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.

Coding > DMA Loading + Clearing...

#19283 - darknet - Fri Apr 16, 2004 3:47 am

I am writing a game that is a bunch of mini-games all independent of each other and work through a main driver program.

I successfully wrote a breakout clone and a gradius clone in that order. Both use Harbours (the GBA book) DMAFastCopy function to load in the tiled backgrounds.

When I finished the Breakout clone (before I began writing the gradius clone), the background loaded up just fine. Then I wrote the gradius clone and THAT background loads up fine as well. However, now the tiles in the breakout clone are corrupt (and I didnt change that code whatsoever from when it was working!)

So since I use the same DMA copy function in both, I am assuming that I may have to reset the DMA registers or somehow clear it for BOTH minigames to work? Here's some of the code I've mentioned...

The DMAFastCopy function:

Code:

void DMAFastCopy(void* source, void* destination, unsigned int count,
                 unsigned int mode) {

    if(mode == DMA_16NOW || mode == DMA_32NOW) {
            REG_DMA3DAD = (unsigned int)destination;
            REG_DMA3SAD = (unsigned int)source;
            REG_DMA3CNT = count | mode;
    }
}


and the code that Breakout uses to load its background:
Code:

 //copy the palette into the background palette memory
 DMAFastCopy((void*)boback_Palette, (void*)BGPaletteMem, 256, DMA_16NOW);

 //now copy the tile images into tile memory
 DMAFastCopy((void*)background_Tiles, (void*)charBaseBlock(0), 65088/4, DMA_32NOW);

//Finally, draw the background's map.
 DMAFastCopy((void*)background_Map, (void*)bgOneMap, 1024, DMA_32NOW);


and the code that Gradius uses to load its background:
Code:

 //copy the palette into the background palette memory
 DMAFastCopy((void*)defenderMap_Palette, (void*)BGPaletteMem, 256, DMA_16NOW);

 //now copy the tile images into tile memory
 DMAFastCopy((void*)defenderMap_Tiles, (void*)charBaseBlock(0), 6848/4, DMA_32NOW);

 //Finally, draw the background's map.
 DMAFastCopy((void*)defenderMap_Map, (void*)bgOneDefendMap, 1024, DMA_32NOW);


Once again, the Breakout worked just fine before I wrote the gradius game. The gradius one works fine now but the breakout one has corrupt tiles.

I actually run the entire project through a main.cpp that simply switches appropiately between the two games' start functions. Selecting the two also involves switching to mode 3 and displaying a menu, if that may have anything to do with it. I wrote both games as if the other did not exist.

I hope I asked my question clearly, thanks very very much for reading and any reply is greatly appreciated.

-Mike

#19284 - poslundc - Fri Apr 16, 2004 4:07 am

A few notes:

1. Make sure that your GBA header file declares the various REG_DMA3XXX registers as being volatile (or vu32 as opposed to just u32).

2. Try inserting the line REG_DMA3DCNT = 0; at the beginning of the if-block in the DMAFastCopy function. The DMA needs to be disabled in order for the source and destination to be written to.

3. If neither of those make a difference, try replacing your DMA function with a simple loop that copies the data from one location to the other. This will tell you if it's the DMA or if it's some other problem with your code.

Dan.

#19287 - darknet - Fri Apr 16, 2004 6:22 am

I did set that register equal to 0 as you suggested, that sounded like a good idea regardless of my problem.

I followed your other instructions and nothing was working yet. I then loaded the data the traditional way with the Background struct. It was there that I found my problem.

The conversion program I use converts tiles as chars, not shorts. My background struct (and loop) was loading them as shorts, thus the problem.

I changed the tileData pointer to a char and everything is all good.

Thanks alot,
-Mike