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.

DS development > Why DmaSet and DmaClear won't work on real nds?

#97160 - cold_as_ice - Tue Aug 08, 2006 7:05 am

Hello i've got a question about dmaset:

when i run this code:

DmaSet(VRAM_A,RGB(31,0,31),256 * 192);

it works on the emulator but somehow it crashes on the real hardware.
can someone explain that. O yeah i already tried it with flushing cache memory.
here's my code for dmaset since ndslib doens't have it:

void DmaSet(void *dest,int value,int len)
{
DMA_SRC(DMACHANNEL) = (u32)&value;
DMA_DEST(DMACHANNEL) = (u32)dest;
DMA_CR(DMACHANNEL) = DMA_COPY_HALFWORDS | DMA_SRC_FIX| ((len >> 1) & ~1);
while(DMA_CR(3) & DMA_BUSY);
}

#97162 - wintermute - Tue Aug 08, 2006 7:14 am

The stack on the DS is placed in dtcm which is fast on chip memory for the arm9. The DMA hardware doesn't have access to this memory. Your code will place a temporary variable on the stack and attempt to DMA from that address. Try this instead.

Code:

void DmaSet(void *dest,int value,int len)
{
*(u16*)dest = value;
DMA_SRC(DMACHANNEL) = (u32)dest;
DMA_DEST(DMACHANNEL) = (u32)dest;
DMA_CR(DMACHANNEL) = DMA_COPY_HALFWORDS | DMA_SRC_FIX| ((len >> 1) & ~1);
while(DMA_CR(3) & DMA_BUSY);
}

_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#97218 - cold_as_ice - Tue Aug 08, 2006 6:25 pm

Yeah it works:) Thank you very much!!