Page 1 of 2
Saving game data
Posted: Mon Jan 31, 2011 12:17 am
by digithree
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
Re: Saving game data
Posted: Mon Jan 31, 2011 4:37 pm
by JanMulder
Include:
Init:
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);
Re: Saving game data
Posted: Mon Jan 31, 2011 8:13 pm
by Izhido
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?
). 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.
Re: Saving game data
Posted: Mon Jan 31, 2011 10:49 pm
by WinterMute
Save file formats are specific to the game they relate to, there's no real "standard"
Re: Saving game data
Posted: Fri Feb 04, 2011 2:58 pm
by Rexhunter99
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.
Re: Saving game data
Posted: Fri Mar 11, 2011 2:28 pm
by digithree
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?
Re: Saving game data
Posted: Fri Mar 11, 2011 8:27 pm
by lazyprogramer
Yes, you have to add
to your Makefile.
Re: Saving game data
Posted: Mon Mar 14, 2011 3:41 pm
by digithree
Cheers!
Re: Saving game data
Posted: Sat May 21, 2011 2:59 pm
by ENAY
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?
Re: Saving game data
Posted: Sun May 22, 2011 4:02 am
by zeromus
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.