Saving game data

digithree

Saving game data

Post by digithree » Mon Jan 31, 2011 12:17 am

Just wondering if anyone knows anything about the DS native save format. Specifically I'd like to now how SAV files (that emulators and thr R4i use for instance) are written to by DS code.

Any help appreciated a lot, thanks :D

JanMulder
Posts: 15
Joined: Wed Jan 26, 2011 2:52 pm

Re: Saving game data

Post by JanMulder » Mon Jan 31, 2011 4:37 pm

Include:

Code: Select all

#include <fat.h>
Init:

Code: Select all

fatInitDefault();
Declare the variables:

Code: Select all

FILE* savefile;
struct VariablesToSave {
u8 var1;
int var2;
char var3[10];
} SaveFile;
Set the to be saved variables to a certain value:

Code: Select all

SaveFile.var1 = 100;
SaveFile.var2 = 1000;
strcpy(SaveFile.var3,"Hello");
To write the to be saved variables to a file:

Code: Select all

savefile = fopen("fat:/savefile.sav","wb");
fwrite(&SaveFile,1,sizeof(SaveFile),savefile);
fclose(savefile);
To read the variables:

Code: Select all

savefile = fopen("fat:/savefile.sav","rb");
fread(&SaveFile,1,sizeof(SaveFile),savefile);
fclose(savefile);

User avatar
Izhido
Posts: 107
Joined: Fri Oct 19, 2007 10:57 pm
Location: Costa Rica
Contact:

Re: Saving game data

Post by Izhido » Mon Jan 31, 2011 8:13 pm

I don't think there is a general industry-defined standard to write game save data (unless Nintendo steps in and tell us what's theirs, if they ever had one, please, pretty please, with a cherry on top? :D ). Therefore, it is up to you to define a way to save / retrieve your own data for your application; the suggestion by JanMulder above to use the filesystem is actually a good one.

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

Re: Saving game data

Post by WinterMute » Mon Jan 31, 2011 10:49 pm

Save file formats are specific to the game they relate to, there's no real "standard"
Help keep devkitPro toolchains free, Donate today

Personal Blog

Rexhunter99
Posts: 23
Joined: Thu Sep 09, 2010 1:28 pm
Location: Australia
Contact:

Re: Saving game data

Post by Rexhunter99 » Fri Feb 04, 2011 2:58 pm

WinterMute wrote:Save file formats are specific to the game they relate to, there's no real "standard"
I think the problem here is the mis-interpretation of the constant size of the save games (which depends on the kind of save it is, eg; EEEPROM) but yeah just to add another useless comment, the save formats are whatever you make them.
Move over Mario... and cruise by Crash... Croc Rocks!
It's a serious adventure 3D platformer for all retro gamers to drool over =D

digithree

Re: Saving game data

Post by digithree » Fri Mar 11, 2011 2:28 pm

Thanks a lot for help on this one. I've another problem though!

I've only just tried to get this to work and I'm getting a linker error saying

Code: Select all

game.cpp:(.text+0x2): undefined reference to `fatInitDefault'
Everything seems to be in order. Maybe I have to modify my makefile to link an extra library?

Also, on the libnds online documentation there is no mention of fat.h in the file list, nor of any of its functions. Is it not a standard part of the library?

lazyprogramer
Posts: 85
Joined: Mon Sep 27, 2010 5:26 pm

Re: Saving game data

Post by lazyprogramer » Fri Mar 11, 2011 8:27 pm

Yes, you have to add

Code: Select all

LIBS	:= 	-lfat -lnds9
to your Makefile.

digithree

Re: Saving game data

Post by digithree » Mon Mar 14, 2011 3:41 pm

Cheers!

ENAY
Posts: 15
Joined: Mon Aug 16, 2010 7:29 am
Location: Japan

Re: Saving game data

Post by ENAY » Sat May 21, 2011 2:59 pm

Hi,

Sorry to blatantly resurrect an old post but I am now experimenting with saving files and found this topic most useful. :)

One thing I have noticed is that this code only works on a real DS but on a PC, nothing happens.

I tried changing the code to "fopen("c:/savefile.sav","wb");" and nothing happened.
How does one go about saving files when you are running on a PC?

zeromus
Posts: 212
Joined: Wed Mar 31, 2010 6:05 pm

Re: Saving game data

Post by zeromus » Sun May 22, 2011 4:02 am

that code should work. you must be confused, or you must have no c: drive. unless, of course, by running on PC, you mean, running on an emulator. in which case you are very badly confused.

Post Reply

Who is online

Users browsing this forum: No registered users and 50 guests