2008-09-06 05:30:42 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* FCE Ultra 0.98.12
|
|
|
|
* Nintendo Wii/Gamecube Port
|
|
|
|
*
|
2009-03-28 18:23:08 +01:00
|
|
|
* Tantric 2008-2009
|
2008-09-06 05:30:42 +02:00
|
|
|
*
|
2009-03-28 18:23:08 +01:00
|
|
|
* fceustate.cpp
|
2008-09-06 05:30:42 +02:00
|
|
|
*
|
|
|
|
* Memory Based Load/Save RAM Manager
|
|
|
|
*
|
|
|
|
* These are the battery-backed RAM (save data) routines, brought together
|
|
|
|
* as GCxxxxx
|
|
|
|
* The original file I/O is replaced with Memory Read/Writes to the
|
|
|
|
* savebuffer below
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <fat.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-11-17 01:09:31 +01:00
|
|
|
#include "fceugx.h"
|
2009-03-28 18:23:08 +01:00
|
|
|
#include "menu.h"
|
|
|
|
#include "filebrowser.h"
|
2008-09-06 05:30:42 +02:00
|
|
|
#include "memcardop.h"
|
|
|
|
#include "fileop.h"
|
|
|
|
|
2009-01-25 07:53:21 +01:00
|
|
|
extern "C" {
|
|
|
|
#include "types.h"
|
|
|
|
#include "fceu.h"
|
|
|
|
#include "ppu.h"
|
|
|
|
#include "cart.h"
|
|
|
|
#include "x6502.h"
|
|
|
|
#include "general.h"
|
2008-09-06 05:30:42 +02:00
|
|
|
extern u32 iNESGameCRC32;
|
|
|
|
extern CartInfo iNESCart;
|
2008-10-01 07:25:38 +02:00
|
|
|
extern CartInfo UNIFCart;
|
2009-01-25 07:53:21 +01:00
|
|
|
}
|
2008-09-06 05:30:42 +02:00
|
|
|
|
2008-12-30 01:05:57 +01:00
|
|
|
static u32 NGCFCEU_GameSave(CartInfo *LocalHWInfo, int operation, int method)
|
2008-09-06 05:30:42 +02:00
|
|
|
{
|
2008-12-30 01:05:57 +01:00
|
|
|
u32 offset = 0;
|
2008-12-22 09:38:49 +01:00
|
|
|
|
2008-09-06 05:30:42 +02:00
|
|
|
if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0])
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
|
|
|
for(x=0;x<4;x++)
|
|
|
|
{
|
|
|
|
if(LocalHWInfo->SaveGame[x])
|
|
|
|
{
|
|
|
|
if(operation == 0) // save to file
|
2008-12-22 09:38:49 +01:00
|
|
|
memcpy(savebuffer+offset, LocalHWInfo->SaveGame[x], LocalHWInfo->SaveGameLen[x]);
|
2008-09-06 05:30:42 +02:00
|
|
|
else // load from file
|
2008-12-22 09:38:49 +01:00
|
|
|
memcpy(LocalHWInfo->SaveGame[x], savebuffer+offset, LocalHWInfo->SaveGameLen[x]);
|
|
|
|
offset += LocalHWInfo->SaveGameLen[x];
|
2008-09-06 05:30:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-22 09:38:49 +01:00
|
|
|
return offset;
|
2008-09-06 05:30:42 +02:00
|
|
|
}
|
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
bool SaveRAM (char * filepath, int method, bool silent)
|
2008-09-06 05:30:42 +02:00
|
|
|
{
|
2008-11-12 09:40:09 +01:00
|
|
|
bool retval = false;
|
|
|
|
int datasize = 0;
|
|
|
|
int offset = 0;
|
|
|
|
|
2008-10-03 20:11:32 +02:00
|
|
|
if(nesGameType == 4)
|
|
|
|
{
|
|
|
|
if(!silent)
|
2009-03-28 18:23:08 +01:00
|
|
|
InfoPrompt("RAM saving is not available for FDS games!");
|
2008-10-03 20:11:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-09-06 05:30:42 +02:00
|
|
|
if(method == METHOD_AUTO)
|
2008-12-22 09:38:49 +01:00
|
|
|
method = autoSaveMethod(silent);
|
2008-09-06 05:30:42 +02:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
if(method == METHOD_AUTO)
|
2008-11-12 09:40:09 +01:00
|
|
|
return false;
|
|
|
|
|
2008-12-19 23:04:55 +01:00
|
|
|
AllocSaveBuffer ();
|
2008-09-06 05:30:42 +02:00
|
|
|
|
2008-10-01 07:25:38 +02:00
|
|
|
// save game save to savebuffer
|
|
|
|
if(nesGameType == 1)
|
2008-12-22 09:38:49 +01:00
|
|
|
datasize = NGCFCEU_GameSave(&iNESCart, 0, method);
|
2008-10-01 07:25:38 +02:00
|
|
|
else if(nesGameType == 2)
|
2008-12-22 09:38:49 +01:00
|
|
|
datasize = NGCFCEU_GameSave(&UNIFCart, 0, method);
|
2008-09-06 05:30:42 +02:00
|
|
|
|
2008-11-12 09:40:09 +01:00
|
|
|
if (datasize)
|
2008-09-06 05:30:42 +02:00
|
|
|
{
|
2009-03-28 18:23:08 +01:00
|
|
|
if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
|
|
|
{
|
|
|
|
// Set the comments
|
|
|
|
char comments[2][32];
|
|
|
|
memset(comments, 0, 64);
|
|
|
|
sprintf (comments[0], "%s RAM", APPNAME);
|
|
|
|
snprintf (comments[1], 32, romFilename);
|
|
|
|
SetMCSaveComments(comments);
|
|
|
|
}
|
|
|
|
|
2008-11-12 09:40:09 +01:00
|
|
|
offset = SaveFile(filepath, datasize, method, silent);
|
2008-09-06 05:30:42 +02:00
|
|
|
|
|
|
|
if (offset > 0)
|
|
|
|
{
|
2009-03-28 18:23:08 +01:00
|
|
|
if (!silent)
|
|
|
|
InfoPrompt("Save successful");
|
2008-09-06 05:30:42 +02:00
|
|
|
retval = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-28 18:23:08 +01:00
|
|
|
if (!silent)
|
|
|
|
InfoPrompt("No data to save!");
|
2008-09-06 05:30:42 +02:00
|
|
|
}
|
2008-12-19 23:04:55 +01:00
|
|
|
FreeSaveBuffer ();
|
2008-09-06 05:30:42 +02:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
bool
|
|
|
|
SaveRAMAuto (int method, bool silent)
|
2008-09-06 05:30:42 +02:00
|
|
|
{
|
2009-03-28 18:23:08 +01:00
|
|
|
if(method == METHOD_AUTO)
|
|
|
|
method = autoSaveMethod(silent);
|
|
|
|
|
|
|
|
if(method == METHOD_AUTO)
|
|
|
|
return false;
|
|
|
|
|
2008-11-12 09:40:09 +01:00
|
|
|
char filepath[1024];
|
2009-03-28 18:23:08 +01:00
|
|
|
|
|
|
|
if(!MakeFilePath(filepath, FILE_RAM, method, romFilename, 0))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return SaveRAM(filepath, method, silent);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LoadRAM (char * filepath, int method, bool silent)
|
|
|
|
{
|
2008-11-12 09:40:09 +01:00
|
|
|
int offset = 0;
|
2008-12-19 23:04:55 +01:00
|
|
|
bool retval = false;
|
2008-11-12 09:40:09 +01:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
if(nesGameType == 4) // RAM saves don't exist for FDS games
|
2008-10-03 20:11:32 +02:00
|
|
|
return false;
|
|
|
|
|
2008-09-06 05:30:42 +02:00
|
|
|
if(method == METHOD_AUTO)
|
2008-12-22 09:38:49 +01:00
|
|
|
method = autoSaveMethod(silent); // we use 'Save' because we need R/W
|
2008-09-06 05:30:42 +02:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
if(method == METHOD_AUTO)
|
2008-11-12 09:40:09 +01:00
|
|
|
return false;
|
2008-09-06 05:30:42 +02:00
|
|
|
|
2008-12-19 23:04:55 +01:00
|
|
|
AllocSaveBuffer ();
|
2008-09-06 05:30:42 +02:00
|
|
|
|
2008-11-12 09:40:09 +01:00
|
|
|
offset = LoadFile(filepath, method, silent);
|
2008-09-06 05:30:42 +02:00
|
|
|
|
|
|
|
if (offset > 0)
|
|
|
|
{
|
2008-10-01 07:25:38 +02:00
|
|
|
if(nesGameType == 1)
|
2008-12-22 09:38:49 +01:00
|
|
|
NGCFCEU_GameSave(&iNESCart, 1, method);
|
2008-10-01 07:25:38 +02:00
|
|
|
else if(nesGameType == 2)
|
2008-12-22 09:38:49 +01:00
|
|
|
NGCFCEU_GameSave(&UNIFCart, 1, method);
|
2008-10-01 07:25:38 +02:00
|
|
|
|
2008-09-06 05:30:42 +02:00
|
|
|
ResetNES();
|
2008-12-19 23:04:55 +01:00
|
|
|
retval = true;
|
2008-09-06 05:30:42 +02:00
|
|
|
}
|
2008-12-19 23:04:55 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// if we reached here, nothing was done!
|
|
|
|
if(!silent)
|
2009-03-28 18:23:08 +01:00
|
|
|
InfoPrompt ("Save file not found");
|
2008-12-19 23:04:55 +01:00
|
|
|
}
|
|
|
|
FreeSaveBuffer ();
|
|
|
|
return retval;
|
2008-09-06 05:30:42 +02:00
|
|
|
}
|
2009-03-28 18:23:08 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
LoadRAMAuto (int method, bool silent)
|
|
|
|
{
|
|
|
|
if(method == METHOD_AUTO)
|
|
|
|
method = autoSaveMethod(silent);
|
|
|
|
|
|
|
|
if(method == METHOD_AUTO)
|
|
|
|
return false;
|
|
|
|
|
2009-04-09 09:49:28 +02:00
|
|
|
char filepath[MAXPATHLEN];
|
|
|
|
char fullpath[MAXPATHLEN];
|
|
|
|
char filepath2[MAXPATHLEN];
|
|
|
|
char fullpath2[MAXPATHLEN];
|
2009-03-28 18:23:08 +01:00
|
|
|
|
2009-04-09 09:49:28 +02:00
|
|
|
// look for Auto save file
|
2009-03-28 18:23:08 +01:00
|
|
|
if(!MakeFilePath(filepath, FILE_RAM, method, romFilename, 0))
|
|
|
|
return false;
|
|
|
|
|
2009-04-09 09:49:28 +02:00
|
|
|
if (LoadRAM(filepath, method, silent))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// look for file with no number or Auto appended
|
2009-04-10 09:50:10 +02:00
|
|
|
if(!MakeFilePath(filepath2, FILE_RAM, method, romFilename, -1))
|
2009-04-09 09:49:28 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if(LoadRAM(filepath2, method, silent))
|
|
|
|
{
|
|
|
|
// rename this file - append Auto
|
|
|
|
sprintf(fullpath, "%s%s", rootdir, filepath); // add device to path
|
|
|
|
sprintf(fullpath2, "%s%s", rootdir, filepath2); // add device to path
|
|
|
|
rename(fullpath2, fullpath); // rename file (to avoid duplicates)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2009-03-28 18:23:08 +01:00
|
|
|
}
|