load sprites from filesystem

vralfy
Posts: 4
Joined: Tue Dec 15, 2009 2:10 pm

load sprites from filesystem

Post by vralfy » Sat Mar 13, 2010 10:13 pm

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

dheart88
Posts: 44
Joined: Sun Dec 13, 2009 3:00 pm

Re: load sprites from filesystem

Post by dheart88 » Wed Apr 21, 2010 8:59 am

I got the same problem... some one pls help us...

StevenH
Posts: 133
Joined: Sun Feb 22, 2009 7:59 pm

Re: load sprites from filesystem

Post by StevenH » Wed Apr 21, 2010 11:42 am

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.

dheart88
Posts: 44
Joined: Sun Dec 13, 2009 3:00 pm

Re: load sprites from filesystem

Post by dheart88 » Thu Apr 22, 2010 6:16 pm

I haven't use IRC for years.. btw, what is the channel number?

dheart88
Posts: 44
Joined: Sun Dec 13, 2009 3:00 pm

Re: load sprites from filesystem

Post by dheart88 » Thu Apr 22, 2010 8:56 pm

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...

StevenH
Posts: 133
Joined: Sun Feb 22, 2009 7:59 pm

Re: load sprites from filesystem

Post by StevenH » Fri Apr 23, 2010 1:01 am

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

User avatar
coreyh2
Posts: 33
Joined: Tue Feb 02, 2010 12:43 am

Re: load sprites from filesystem

Post by coreyh2 » Fri Apr 23, 2010 6:00 am

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.

StevenH
Posts: 133
Joined: Sun Feb 22, 2009 7:59 pm

Re: load sprites from filesystem

Post by StevenH » Fri Apr 23, 2010 12:01 pm

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...

dheart88
Posts: 44
Joined: Sun Dec 13, 2009 3:00 pm

Re: load sprites from filesystem

Post by dheart88 » Tue May 04, 2010 2:19 am

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...

User avatar
coreyh2
Posts: 33
Joined: Tue Feb 02, 2010 12:43 am

Re: load sprites from filesystem

Post by coreyh2 » Tue May 04, 2010 3:30 am

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.

Post Reply

Who is online

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