DMA vs ARM9 - fight!

[brevs FILEBASE="/files/nds/" IMGBASE="/img/post/arm9vsdma/" GBATEK="http://nocash.emubase.de/gbatek.htm" /] [[toc]]

DMA, or Direct Memory Access, is a hardware method for transferring data. As it's hardware-driven, it's pretty damn fast[fnote]Well, quite fast anyway. In some circumstances CPU-based transfers are faster, but that's a story for another day.[/fnote]. As such, it's pretty much the standard method for copying on the NDS. Unfortunately, as many people have noticed, it doesn't always work.

There are two principle reasons for this: cache and TCM. These are two memory regions of the ARM9 that DMA is unaware of, which can lead to incorrect transfers. In this post, I'll discuss the cache, TCM and their interactions (or lack thereof) with DMA.

The majority of the post is actually about cache. Cache basically determines the speed of your app, so it's worth looking into in more detail. Why it and DMA don't like each other much will become clear along the way. I'll also present a number of test cases that show the conflicting areas, and some functions to deal with these problems.

Continue reading