DMA vs for loop

Post Reply
nullflux
Posts: 2
Joined: Sat Dec 12, 2009 1:03 am

DMA vs for loop

Post by nullflux » Sat Dec 12, 2009 1:16 am

Hello!

Several weeks ago I decided to learn NDS homebrew and found some old tutorials, got devkitPro set up, libnds, etc. I have been working on some simple tests (multiple backgrounds, sprites, animated sprites, text systems) with some great success. However, recently I stumbled upon a CPU profiling method (http://forums.devkitpro.org/viewtopic.php?p=2128#p2128) and decided to test a few of my functions and other doodads. One of the most critical things I noticed was that using a simple for loop to copy a 32x32 map took up about 14,800 cycles compared to the 559 of a dmaCopy. After seeing this gargantuan gap between these numbers, I now have a dilemma. Using dmaCopy is about 26x quicker, but I can't switch the palette of the tiles...

e.g.

Code: Select all

dmaCopy(pictureTiles,bgGetMapPtr(bg),1024); // ~559 cycles
vs

Code: Select all

for(for(i=0;i<1024;i++) { // ~14,800 cycles
	mapPtr[i]=pictureTiles[i] | TILE_PALETTE(2);
}

Is there any way to apply a palette swap quicker? It seems outrageous that it takes an extra 14,000 cycles to change the palette.

edit: spelling and grammar.

WinterMute
Site Admin
Posts: 2003
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: DMA vs for loop

Post by WinterMute » Sat Dec 12, 2009 4:21 am

Simplest answer, change the palette at compile time rather than run time.

This code also looks like setup code to me which should be run once and unlikely to be every game loop. There are also approximately 560190 cycles in one frame so you'll be able to manage that code just under 40 times a frame. Really, you have better things to worry about :p

You could also probably swap the palette directly rather than messing with the tilemap ... depends what it is you're trying to do really.
Help keep devkitPro toolchains free, Donate today

Personal Blog

nullflux
Posts: 2
Joined: Sat Dec 12, 2009 1:03 am

Re: DMA vs for loop

Post by nullflux » Sun Dec 13, 2009 3:31 am

Thanks for the response :)

I suppose you're right; it's not used too often and I should be worrying about other things. Just seemed like something there would be a simple fix for it *shrug*

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 9 guests