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 > question about DMA

#17793 - Darmstadium - Sun Mar 14, 2004 8:41 pm

I use dma channel 3 to transfer a lot of stuff. For example, let's say I want to transfer my palette data for my sprites into object palette memory. I'd usually use this code:

Code:

REG_DM3SAD = (u32)spritespalette;
REG_DM3DAD = (u32)0x5000200;
REG_DM3CNT = 256 | DMA_ENABLE | DMA_TIMEING_IMMEDIATE | DMA_16;


But I tried halving the amount copied and doubling the word size and it worked too:
Code:

REG_DM3SAD = (u32)spritespalette;
REG_DM3DAD = (u32)0x5000200;
REG_DM3CNT = 128 | DMA_ENABLE | DMA_TIMEING_IMMEDIATE | DMA_32;


What is the difference between these two ways?

#17796 - DekuTree64 - Sun Mar 14, 2004 9:28 pm

This definitely belongs in the beginners section.
The difference is that 2 bytes are copied at a time on the first, and 4 bytes at a time on the second. 4 bytes at a time is faster, but if you need to copy something with a size that's not a multiple of 4, or isn't at an address aligned to 4 bytes, you need to use 2 at a time. Unless it's not a multiple of 2 either, then you're in trouble and will have to use a regular memcpy() or something.

EDIT: Oh, and yes, the count is the number of transfers to make of the specified size, which means you'll have to transfer twice as many 16-bit values as you would 32-bit ones.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#17798 - Lupin - Sun Mar 14, 2004 9:51 pm

hmm, you got 3 threads now... i am sure your threads will fill up a whole page when you're done with the stuff you are currently working on :P

That definately belongs to the beginners zone...

In the first code you carry 2 apples in your basket, so you have to walk more often as carring 4 apples in your basket and your grandma will be pleased to have 4 apples every day, but be aware of the evil wolf! :P

Yes, i am a retard :)
_________________
Team Pokeme
My blog and PM ASM tutorials

#17809 - tepples - Mon Mar 15, 2004 4:09 am

Between areas of 16-bit GBA memory (that is, everything but registers, IWRAM, and the savegame), 16-bit DMA and 32-bit DMA run at exactly the same speed. A 16-bit DMA will look like fetch, store, fetch, store, fetch, store, fetch, store, etc., while a 32-bit DMA will look like fetch, fetch, store, store, fetch, fetch, store, store, etc.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.