2008-09-02 03:57:21 +02:00
|
|
|
/****************************************************************************
|
2009-07-22 04:05:49 +02:00
|
|
|
* FCE Ultra
|
2008-09-02 03:57:21 +02:00
|
|
|
* Nintendo Wii/Gamecube Port
|
|
|
|
*
|
2009-03-28 18:23:08 +01:00
|
|
|
* Tantric 2008-2009
|
2008-09-02 03:57:21 +02:00
|
|
|
*
|
2009-03-28 18:23:08 +01:00
|
|
|
* fceustate.cpp
|
2008-09-02 03:57:21 +02:00
|
|
|
*
|
|
|
|
* Memory Based Load/Save State Manager
|
|
|
|
*
|
|
|
|
* These are simply the state routines, brought together as GCxxxxx
|
|
|
|
* The original file I/O is replaced with Memory Read/Writes to the
|
|
|
|
* statebuffer below
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <fat.h>
|
2009-07-18 08:19:04 +02:00
|
|
|
#include <zlib.h>
|
2009-08-25 19:19:21 +02:00
|
|
|
#include "pngu.h"
|
2009-04-06 09:27:40 +02:00
|
|
|
|
2008-11-17 01:09:31 +01:00
|
|
|
#include "fceugx.h"
|
2009-07-17 19:27:04 +02:00
|
|
|
#include "fceusupport.h"
|
2009-03-28 18:23:08 +01:00
|
|
|
#include "menu.h"
|
|
|
|
#include "filebrowser.h"
|
2008-09-02 03:57:21 +02:00
|
|
|
#include "memcardop.h"
|
|
|
|
#include "fileop.h"
|
2009-04-06 09:27:40 +02:00
|
|
|
#include "gcvideo.h"
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
bool SaveState (char * filepath, int method, bool silent)
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
|
|
|
bool retval = false;
|
|
|
|
int datasize;
|
|
|
|
int offset = 0;
|
2009-04-06 09:27:40 +02:00
|
|
|
int imgSize = 0; // image screenshot bytes written
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2008-11-12 09:40:09 +01:00
|
|
|
if(method == METHOD_AUTO)
|
2008-12-22 09:38:49 +01:00
|
|
|
method = autoSaveMethod(silent);
|
2008-11-12 09:40:09 +01:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
if(method == METHOD_AUTO)
|
2008-11-12 09:40:09 +01:00
|
|
|
return false;
|
|
|
|
|
2009-04-06 09:27:40 +02:00
|
|
|
// save screenshot - I would prefer to do this from gameScreenTex
|
|
|
|
if(gameScreenTex2 != NULL && method != METHOD_MC_SLOTA && method != METHOD_MC_SLOTB)
|
|
|
|
{
|
|
|
|
AllocSaveBuffer ();
|
|
|
|
|
|
|
|
IMGCTX pngContext = PNGU_SelectImageFromBuffer(savebuffer);
|
|
|
|
|
|
|
|
if (pngContext != NULL)
|
|
|
|
{
|
2009-04-15 07:56:33 +02:00
|
|
|
imgSize = PNGU_EncodeFromGXTexture(pngContext, screenwidth, screenheight, gameScreenTex2, 0);
|
2009-04-06 09:27:40 +02:00
|
|
|
PNGU_ReleaseImageContext(pngContext);
|
|
|
|
}
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2009-04-06 09:27:40 +02:00
|
|
|
if(imgSize > 0)
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
2009-04-06 09:27:40 +02:00
|
|
|
char screenpath[1024];
|
2009-04-15 07:56:33 +02:00
|
|
|
strncpy(screenpath, filepath, 1024);
|
|
|
|
screenpath[strlen(screenpath)-4] = 0;
|
|
|
|
sprintf(screenpath, "%s.png", screenpath);
|
2009-04-06 09:27:40 +02:00
|
|
|
SaveFile(screenpath, imgSize, method, silent);
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
2009-04-06 09:27:40 +02:00
|
|
|
|
|
|
|
FreeSaveBuffer ();
|
|
|
|
}
|
|
|
|
|
2009-07-20 08:18:06 +02:00
|
|
|
memorystream save(SAVEBUFFERSIZE);
|
|
|
|
FCEUSS_SaveMS(&save, Z_BEST_COMPRESSION);
|
2009-07-18 08:19:04 +02:00
|
|
|
save.sync();
|
2009-07-20 08:18:06 +02:00
|
|
|
datasize = save.tellp();
|
2009-04-15 07:56:33 +02:00
|
|
|
|
|
|
|
if (datasize)
|
|
|
|
{
|
|
|
|
if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
|
|
|
{
|
|
|
|
// Set the comments
|
|
|
|
char comments[2][32];
|
|
|
|
memset(comments, 0, 64);
|
|
|
|
sprintf (comments[0], "%s State", APPNAME);
|
|
|
|
snprintf (comments[1], 32, romFilename);
|
|
|
|
SetMCSaveComments(comments);
|
|
|
|
}
|
2009-07-20 08:18:06 +02:00
|
|
|
offset = SaveFile(save.buf(), filepath, datasize, method, silent);
|
2009-04-15 07:56:33 +02:00
|
|
|
}
|
|
|
|
|
2009-04-06 09:27:40 +02:00
|
|
|
if (offset > 0)
|
|
|
|
{
|
|
|
|
if (!silent)
|
|
|
|
InfoPrompt("Save successful");
|
|
|
|
retval = true;
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
bool
|
|
|
|
SaveStateAuto (int method, bool silent)
|
2008-09-02 03:57:21 +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_STATE, method, romFilename, 0))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return SaveState(filepath, method, silent);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LoadState (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-09-02 03:57:21 +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-02 03:57:21 +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-09 20:03:41 +02:00
|
|
|
|
2008-12-19 23:04:55 +01:00
|
|
|
AllocSaveBuffer ();
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2008-11-12 09:40:09 +01:00
|
|
|
offset = LoadFile(filepath, method, silent);
|
2008-09-02 03:57:21 +02:00
|
|
|
|
|
|
|
if (offset > 0)
|
|
|
|
{
|
2009-07-18 08:19:04 +02:00
|
|
|
memorystream save((char *)savebuffer, offset);
|
|
|
|
FCEUSS_LoadFP(&save, SSLOADPARAM_NOBACKUP);
|
2008-12-19 23:04:55 +01:00
|
|
|
retval = true;
|
2008-09-02 03:57:21 +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
|
|
|
ErrorPrompt ("State file not found");
|
2008-12-19 23:04:55 +01:00
|
|
|
}
|
|
|
|
FreeSaveBuffer ();
|
|
|
|
return retval;
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
2009-03-28 18:23:08 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
LoadStateAuto (int method, bool silent)
|
|
|
|
{
|
|
|
|
if(method == METHOD_AUTO)
|
|
|
|
method = autoSaveMethod(silent);
|
|
|
|
|
|
|
|
if(method == METHOD_AUTO)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
char filepath[1024];
|
|
|
|
|
|
|
|
if(!MakeFilePath(filepath, FILE_STATE, method, romFilename, 0))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return LoadState(filepath, method, silent);
|
|
|
|
}
|