Saving like a commerical game

Post Reply
Derrik
Posts: 63
Joined: Wed Aug 14, 2013 8:28 pm

Saving like a commerical game

Post by Derrik » Fri Oct 10, 2014 8:16 pm

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.

Derrik
Posts: 63
Joined: Wed Aug 14, 2013 8:28 pm

Re: Saving like a commerical game

Post by Derrik » Fri Oct 24, 2014 5:30 pm

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.

Post Reply

Who is online

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