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++ > DMA Example?

#178 - Japster - Sat Jan 04, 2003 3:51 pm

Where can I find a good C/C++ example using DMA?

Jasper

#188 - imikeyi - Sun Jan 05, 2003 12:21 am

Here's some code I use for DMA:

#define REG_DMA3SAD *(volatile u32*) 0x40000D4
#define REG_DMA3DAD *(volatile u32*) 0x40000D8
#define REG_DMA3CNT_L *(volatile u16*) 0x40000DC
#define REG_DMA3CNT_H *(volatile u16*) 0x40000DE

void DMA3(u32 source, u32 dest, u16 ctrlLow, u16 ctrlHigh)
{
REG_DMA3SAD = source;
REG_DMA3DAD = dest;
REG_DMA3CNT_L = ctrlLow;
REG_DMA3CNT_H = ctrlHigh;
}

Eg.
DMA3((u32) &backgroundPalette, (u32) PALETTE_RAM, 256, 0x8000);

#246 - Japster - Sun Jan 05, 2003 2:52 pm

Thanks. BTW What does "volatile" mean? Could missing "volatiles" be the reason for that my programs don't work correctly?

Jasper

#252 - MHz - Sun Jan 05, 2003 4:18 pm

'Volatile' simply means the defined data may change from outside your code (certain memory locations such as counters, in/out ports etc). Because of this, the compiler will not make any assumptions about the data (in order to optimize it for instance).

I hope the explanation is clear enough... :)

#272 - regularkid - Sun Jan 05, 2003 8:24 pm

Check out "The PERN Project" website. He has some really good tutorials on the GBA and one specifically on DMA transfers.

http://216.167.73.47/~dovoto/English/tutorial.html
_________________
- RegularKid

#481 - tubooboo - Wed Jan 08, 2003 1:46 am

in HAM , theres examples of DMA all over the sample sources. Check the obj sample for instance

Best
Emanuel
_________________
HAM author
http://www.ngine.de