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 > DMA and Memcpy

#165821 - MaesterRowen - Wed Jan 07, 2009 11:37 pm

Why does the dmaCopy corrupt on hardware (fine on emulator) and memcpy works perfect on both hardware and emulator?

See code snippet below:

Code:

   fread(buffer, 1, size, file);
   dmaCopyHalfWords(3, buffer, BG_MAP_RAM(0), size);


Code:

   fread(buffer, 1, size, file);
   memcpy(BG_MAP_RAM(0), buffer, size);


I thought it might be something with the 2byte write/read limit and VRAM, but I thought the two lines of code did the same exact thing.

#165822 - Dwedit - Wed Jan 07, 2009 11:44 pm

When you write to memory using the CPU, it doesn't immediately go into memory. It might sit around in the cache for a while. DMA reads the actual content of memory, so it will get the older stuff. Either continue using memcpy to perform the copy, or flush the write cache before using DMA.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#165824 - MaesterRowen - Thu Jan 08, 2009 12:54 am

That appears to be the trick.

Thank you very much.