corrections to SRAM/snapshot saving and loading

This commit is contained in:
dborth 2009-04-08 08:11:46 +00:00
parent 52179a367c
commit 9ed52afbb7
2 changed files with 16 additions and 14 deletions

View File

@ -1441,9 +1441,9 @@ static int MenuGameSaves(int action)
// find matching files
if(len2 > 5 && strncmp(browserList[i].filename, ROMFilename, len) == 0)
{
if(strncmp(&browserList[i].filename[len2-4], ".srm", 4) == 0)
if(strncmp(&browserList[i].filename[len2-4], ".sav", 4) == 0)
saves.type[j] = FILE_SRAM;
else if(strncmp(&browserList[i].filename[len2-4], ".frz", 4) == 0)
else if(strncmp(&browserList[i].filename[len2-4], ".sgm", 4) == 0)
saves.type[j] = FILE_SNAPSHOT;
else
saves.type[j] = -1;
@ -1522,10 +1522,12 @@ static int MenuGameSaves(int action)
switch(saves.type[ret])
{
case FILE_SRAM:
case FILE_SNAPSHOT:
result = LoadBatteryOrState(filepath, GCSettings.SaveMethod, saves.type[ret], NOTSILENT);
emulator.emuReset();
break;
case FILE_SNAPSHOT:
result = LoadBatteryOrState(filepath, GCSettings.SaveMethod, saves.type[ret], NOTSILENT);
break;
}
if(result)
menu = MENU_EXIT;

View File

@ -261,11 +261,9 @@ bool LoadBatteryOrState(char * filepath, int method, int action, bool silent)
if(method == METHOD_AUTO)
method = autoSaveMethod(silent); // we use 'Save' because we need R/W
if(!MakeFilePath(filepath, action, method))
if(method == METHOD_AUTO)
return false;
ShowAction ("Loading...");
AllocSaveBuffer();
// load the file into savebuffer
@ -319,7 +317,7 @@ bool LoadBatteryOrStateAuto(int method, int action, bool silent)
char filepath[1024];
if(!MakeFilePath(filepath, FILE_SNAPSHOT, method, ROMFilename, 0))
if(!MakeFilePath(filepath, action, method, ROMFilename, 0))
return false;
return LoadBatteryOrState(filepath, method, action, silent);
@ -332,9 +330,8 @@ bool LoadBatteryOrStateAuto(int method, int action, bool silent)
* action = 1 - Save state
****************************************************************************/
bool SaveBatteryOrState(char * filename, int method, int action, bool silent)
bool SaveBatteryOrState(char * filepath, int method, int action, bool silent)
{
char filepath[1024];
bool result = false;
int offset = 0;
int datasize = 0; // we need the actual size of the data written
@ -343,6 +340,9 @@ bool SaveBatteryOrState(char * filename, int method, int action, bool silent)
if(method == METHOD_AUTO)
method = autoSaveMethod(silent);
if(method == METHOD_AUTO)
return false;
AllocSaveBuffer();
// set comments for Memory Card saves
@ -355,7 +355,7 @@ bool SaveBatteryOrState(char * filename, int method, int action, bool silent)
if(action == FILE_SRAM)
sprintf(savetype, "SRAM");
else
sprintf(savetype, "Freeze");
sprintf(savetype, "Snapshot");
sprintf (savecomments[0], "%s %s", APPNAME, savetype);
snprintf (savecomments[1], 32, ROMFilename);
@ -366,13 +366,13 @@ bool SaveBatteryOrState(char * filename, int method, int action, bool silent)
if(action == FILE_SRAM)
{
if(cartridgeType == 1)
datasize = MemgbWriteBatteryFile((char *)savebuffer+offset);
datasize = MemgbWriteBatteryFile((char *)savebuffer);
else
datasize = MemCPUWriteBatteryFile((char *)savebuffer+offset);
datasize = MemCPUWriteBatteryFile((char *)savebuffer);
}
else
{
bool written = emulator.emuWriteMemState((char *)savebuffer+offset, SAVEBUFFERSIZE-offset);
bool written = emulator.emuWriteMemState((char *)savebuffer, SAVEBUFFERSIZE);
// we need to set datasize to the exact memory size written
// but emuWriteMemState doesn't return that for us
// so instead we'll find the end of the save the old fashioned way
@ -467,7 +467,7 @@ bool SaveBatteryOrStateAuto(int method, int action, bool silent)
char filepath[1024];
if(!MakeFilePath(filepath, FILE_SNAPSHOT, method, ROMFilename, 0))
if(!MakeFilePath(filepath, action, method, ROMFilename, 0))
return false;
return SaveBatteryOrState(filepath, method, action, silent);