fceugx/source/fceustate.cpp

134 lines
2.6 KiB
C++
Raw Normal View History

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-04-06 09:27:40 +02: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 "fileop.h"
2009-04-06 09:27:40 +02:00
#include "gcvideo.h"
2010-03-22 00:49:24 +01:00
#include "utils/pngu.h"
2008-09-02 03:57:21 +02:00
2009-10-02 00:21:25 +02:00
bool SaveState (char * filepath, bool silent)
2008-09-02 03:57:21 +02:00
{
bool retval = false;
int datasize;
int offset = 0;
2009-10-02 00:21:25 +02:00
int device;
if(!FindDevice(filepath, &device))
return 0;
2008-11-12 09:40:09 +01:00
if(gameScreenPngSize > 0)
2009-04-06 09:27:40 +02:00
{
char screenpath[1024];
strncpy(screenpath, filepath, 1024);
screenpath[strlen(screenpath)-4] = 0;
sprintf(screenpath, "%s.png", screenpath);
SaveFile((char *)gameScreenPng, screenpath, gameScreenPngSize, silent);
2009-04-06 09:27:40 +02:00
}
2010-08-29 23:15:42 +02:00
EMUFILE_MEMFILE save(SAVEBUFFERSIZE);
FCEUSS_SaveMS(&save, Z_BEST_COMPRESSION);
2010-08-29 23:15:42 +02:00
datasize = save.size();
if (datasize)
2009-10-02 00:21:25 +02:00
offset = SaveFile(save.buf(), filepath, datasize, silent);
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
2009-10-02 00:21:25 +02:00
SaveStateAuto (bool silent)
2008-09-02 03:57:21 +02:00
{
2008-11-12 09:40:09 +01:00
char filepath[1024];
2009-03-28 18:23:08 +01:00
2009-10-02 00:21:25 +02:00
if(!MakeFilePath(filepath, FILE_STATE, romFilename, 0))
2009-03-28 18:23:08 +01:00
return false;
2009-10-02 00:21:25 +02:00
return SaveState(filepath, silent);
2009-03-28 18:23:08 +01:00
}
2009-10-02 00:21:25 +02:00
bool LoadState (char * filepath, bool silent)
2009-03-28 18:23:08 +01:00
{
2008-11-12 09:40:09 +01:00
int offset = 0;
bool retval = false;
2009-10-02 00:21:25 +02:00
int device;
2008-09-02 03:57:21 +02:00
2009-10-02 00:21:25 +02:00
if(!FindDevice(filepath, &device))
return 0;
2008-09-09 20:03:41 +02:00
AllocSaveBuffer ();
2008-09-02 03:57:21 +02:00
2009-10-02 00:21:25 +02:00
offset = LoadFile(filepath, silent);
2008-09-02 03:57:21 +02:00
if (offset > 0)
{
2010-08-29 23:15:42 +02:00
EMUFILE_MEMFILE save(savebuffer, offset);
2009-07-18 08:19:04 +02:00
FCEUSS_LoadFP(&save, SSLOADPARAM_NOBACKUP);
retval = true;
2008-09-02 03:57:21 +02:00
}
else
{
// if we reached here, nothing was done!
if(!silent)
2009-03-28 18:23:08 +01:00
ErrorPrompt ("State file not found");
}
FreeSaveBuffer ();
return retval;
2008-09-02 03:57:21 +02:00
}
2009-03-28 18:23:08 +01:00
bool
2009-10-02 00:21:25 +02:00
LoadStateAuto (bool silent)
2009-03-28 18:23:08 +01:00
{
char filepath[1024];
2009-10-02 00:21:25 +02:00
if(!MakeFilePath(filepath, FILE_STATE, romFilename, 0))
2009-03-28 18:23:08 +01:00
return false;
2009-10-02 00:21:25 +02:00
return LoadState(filepath, silent);
2009-03-28 18:23:08 +01:00
}
2016-09-18 05:43:24 +02:00
bool SavePreviewImg (char * filepath, bool silent)
{
int device;
if(!FindDevice(filepath, &device))
return 0;
if(gameScreenPngSize > 0)
{
char screenpath[1024];
strncpy(screenpath, filepath, 1024);
screenpath[strlen(screenpath)] = 0;
sprintf(screenpath, "%s.png", screenpath);
SaveFile((char *)gameScreenPng, screenpath, gameScreenPngSize, silent);
}
return 1;
}