Page 1 of 1

Saving like a commerical game

Posted: Fri Oct 10, 2014 8:16 pm
by Derrik
I am aware that it is possible to write to the microSD using stdio calls with libfat, for example:

Code: Select all

FILE *f = fopen("gameSave.bin", "wb");
fwrite(data, dataLen, 1, f);
fclose(f);
However I was wondering if it is possible to write data the same way as a commercial game, so that the flashcard handles the file writing, so that game.nds writes to game.sav for example. This would mean saving would have higher compatibility with flashcards since they are primarily designed for commercial games.

I came across the example found at "devkitPro\examples\nds\card\eeprom", however could not get it to work for saving data to the flashcard.

I tried adding this code to the example (while keeping all of the init stuff like sysSetBusOwners(true, true);):

Code: Select all

memset(data, 'a', 512);
cardWriteEeprom(0, data, 512, type);
cardReadEeprom(0, data, 512, type);
But it doesn't work.

Re: Saving like a commerical game

Posted: Fri Oct 24, 2014 5:30 pm
by Derrik
This isn't possible, however, you can use argv[0] to get the name of the nds file and use it to get [the name of the nds].sav, giving the illusion of saving like a commercial game.

Here's some sample code:

Code: Select all

	char saveName[256] = { '\0' };
	
	if(argc > 0 && strlen(argv[0]) > 4) {
		snprintf(saveName, 255, "%.*s.sav", strlen(argv[0]) - 4, argv[0]);
	}
	else {
		sprintf(saveName, "game.sav");
	}
	
	printf("%s\n", saveName);
It defaults to "game.sav" if you are using a card which doesn't implement argv correctly.