Page 1 of 3
load sprites from filesystem
Posted: Sat Mar 13, 2010 10:13 pm
by vralfy
Hi,
i managed to load some informations from the filesystem. Now i'm trying to load some sprites from it.
Is there a tutorial or something like this?
Thanks, vralfy
Re: load sprites from filesystem
Posted: Wed Apr 21, 2010 8:59 am
by dheart88
I got the same problem... some one pls help us...
Re: load sprites from filesystem
Posted: Wed Apr 21, 2010 11:42 am
by StevenH
There's a set of functions being written for this exact issue, if you check the IRC channel one of the guys in there will be able to help you out.
There are a few improvements coming in the next release, but if you need some bleeding edge updates you should check the IRC channel.
Re: load sprites from filesystem
Posted: Thu Apr 22, 2010 6:16 pm
by dheart88
I haven't use IRC for years.. btw, what is the channel number?
Re: load sprites from filesystem
Posted: Thu Apr 22, 2010 8:56 pm
by dheart88
It's 4 am here, I'm a bit sleepy. After overnight work, this is my function to load binary file from nitrofs, like tiles, map, and palette... Feel free to use it...
Code: Select all
void loadBinary(u16* memAddress,char *filename)
{
FILE *pFile=fopen (filename,"rb");
if (pFile!=NULL)
{
//file size
fseek (pFile, 0 , SEEK_END);
long lSize = ftell (pFile);
u8 *buffer= (u8*) malloc (sizeof(u8)*lSize);
rewind (pFile);
if (fread (buffer,1,lSize,pFile) != lSize)
printf("error reading file\n");
//copy from buffer
dmaCopy(buffer, memAddress, lSize);
//close file and clean buffer
fclose (pFile);
free (buffer);
}
else
printf("file not exist");
}
here is the full example ->
http://www.mediafire.com/?rn2tdni3k1u
time to sleep...
Re: load sprites from filesystem
Posted: Fri Apr 23, 2010 1:01 am
by StevenH
The channel is irc://irc.blitzed.org/dsdev
and the functions for reading grt files (generated by GRIT) have been posted:
<TheLazy1> Here we go:
http://www.mediafire.com/file/4kxhnjyck ... le.tar.bz2 -- flame away
Re: load sprites from filesystem
Posted: Fri Apr 23, 2010 6:00 am
by coreyh2
Thanks for posting these pieces of code.
I've read that the speeds of microSD varies. I'm guessing writing directly to vram might not always work depending on how much data you are moving and the speed of the card. I wonder if its possible to steam sound this way on some cards.
Re: load sprites from filesystem
Posted: Fri Apr 23, 2010 12:01 pm
by StevenH
coreyh2 wrote:Thanks for posting these pieces of code.
I've read that the speeds of microSD varies. I'm guessing writing directly to vram might not always work depending on how much data you are moving and the speed of the card. I wonder if its possible to steam sound this way on some cards.
There is some example code on gbadev.org forums for streaming music, IIRC it's by ekid...
Re: load sprites from filesystem
Posted: Tue May 04, 2010 2:19 am
by dheart88
My function above isn't working in my real DS , it works perfectly on emulator. I use sandisk microSD + EDGE cards, and the sprite/background not fully loaded.. some one pls help me...
Or should I give delay to read each file?
EDIT:
I already solved this problem, my function above is a bit wrong, memcpy is the solution, don't use DMA... thx 4 the link above, I realized this after read GRF_LoadVRAM function...
Re: load sprites from filesystem
Posted: Tue May 04, 2010 3:30 am
by coreyh2
http://www.coranac.com/2010/03/dma-vs-arm9-round-2/
This is a useful link about dma. Talks about using it correctly.
If you look at the code for oamUpdate or oamInit in libnds you'll see how its done with vram. It just involves using DC_FlushRange on main or stack memory that has been changed. There is a lot more too it when using dma to move to main memory. Tests show assembly versions of memcpy working better in those situations too. Asynchronous dma can still be useful maybe. DMA is the fastest way to to move to vram with assembly being a close second.
I've done a bit of research but I haven't done any tests myself. If you go through Cearn's blog you'll find much more detailed information.