save states work now, other misc bugfixes/improvements

This commit is contained in:
dborth 2009-07-20 06:18:06 +00:00
parent e22f34ec7f
commit aec5667532
10 changed files with 56 additions and 50 deletions

View File

@ -341,7 +341,11 @@ bool FCEUSS_SaveMS(std::ostream* outstream, int compressionLevel)
//a temp memory stream. we'll dump some data here and then compress //a temp memory stream. we'll dump some data here and then compress
//TODO - support dumping directly without compressing to save a buffer copy //TODO - support dumping directly without compressing to save a buffer copy
#ifdef GEKKO
memorystream ms(512*1024); // set aside some space, otherwise expand fails on Wii!
#else
memorystream ms; memorystream ms;
#endif
std::ostream* os = (std::ostream*)&ms; std::ostream* os = (std::ostream*)&ms;
uint32 totalsize = 0; uint32 totalsize = 0;
@ -386,7 +390,11 @@ bool FCEUSS_SaveMS(std::ostream* outstream, int compressionLevel)
if(SPreSave) SPostSave(); if(SPreSave) SPostSave();
//save the length of the file //save the length of the file
#ifdef GEKKO
int len = ms.tellp();
#else
int len = ms.size(); int len = ms.size();
#endif
//sanity check: len and totalsize should be the same //sanity check: len and totalsize should be the same
if(len != totalsize) if(len != totalsize)

View File

@ -62,14 +62,14 @@ int GCMemROM(int method, int size)
fceufp->stream = fceumem; fceufp->stream = fceumem;
fceufp->filename = romFilename; fceufp->filename = romFilename;
nesGameType = 0; romLoaded = false;
if (iNESLoad(romFilename, fceufp, 1)) if (iNESLoad(romFilename, fceufp, 1))
nesGameType = 1; romLoaded = true;
else if (UNIFLoad(romFilename, fceufp)) else if (UNIFLoad(romFilename, fceufp))
nesGameType = 2; romLoaded = true;
else if (NSFLoad(fceufp)) else if (NSFLoad(fceufp))
nesGameType = 3; romLoaded = true;
else else
{ {
// read FDS BIOS into FDSBIOS - should be 8192 bytes // read FDS BIOS into FDSBIOS - should be 8192 bytes
@ -93,39 +93,38 @@ int GCMemROM(int method, int size)
{ {
if (biosSize > 0) if (biosSize > 0)
ErrorPrompt("FDS BIOS file is invalid!"); ErrorPrompt("FDS BIOS file is invalid!");
else
ErrorPrompt("FDS BIOS file not found!");
return 0; // BIOS not loaded, do not load game return 0; // BIOS not loaded, do not load game
} }
free(tmpbuffer); free(tmpbuffer);
} }
// load game // load game
if (FDSLoad(NULL, fceufp)) if (FDSLoad(romFilename, fceufp))
nesGameType = 4; romLoaded = true;
} }
//delete fceufp; delete fceufp;
//delete fceumem;
if (nesGameType > 0) if (romLoaded)
{ {
FCEU_ResetVidSys(); FCEU_ResetVidSys();
if(GameInfo->type!=GIT_NSF) //if(GameInfo->type!=GIT_NSF)
if(FSettings.GameGenie) // if(FSettings.GameGenie)
OpenGenie(); // OpenGenie();
PowerNES(); PowerNES();
if(GameInfo->type!=GIT_NSF) //if(GameInfo->type!=GIT_NSF)
FCEU_LoadGamePalette(); // FCEU_LoadGamePalette();
FCEU_ResetPalette(); FCEU_ResetPalette();
FCEU_ResetMessages(); // Save state, status messages, etc. FCEU_ResetMessages(); // Save state, status messages, etc.
if(GameInfo->type!=GIT_NSF) //if(GameInfo->type!=GIT_NSF)
FCEU_LoadGameCheats(0); // FCEU_LoadGameCheats(0);
ResetAudio(); ResetAudio();
romLoaded = true;
return 1; return 1;
} }
else else

View File

@ -56,7 +56,7 @@ bool SaveRAM (char * filepath, int method, bool silent)
int datasize = 0; int datasize = 0;
int offset = 0; int offset = 0;
if(nesGameType == 4) if(GameInfo->type == GIT_FDS)
{ {
if(!silent) if(!silent)
InfoPrompt("RAM saving is not available for FDS games!"); InfoPrompt("RAM saving is not available for FDS games!");
@ -72,9 +72,9 @@ bool SaveRAM (char * filepath, int method, bool silent)
AllocSaveBuffer (); AllocSaveBuffer ();
// save game save to savebuffer // save game save to savebuffer
if(nesGameType == 1) if(GameInfo->type == GIT_CART)
datasize = NGCFCEU_GameSave(&iNESCart, 0, method); datasize = NGCFCEU_GameSave(&iNESCart, 0, method);
else if(nesGameType == 2) else if(GameInfo->type == GIT_VSUNI)
datasize = NGCFCEU_GameSave(&UNIFCart, 0, method); datasize = NGCFCEU_GameSave(&UNIFCart, 0, method);
if (datasize) if (datasize)
@ -129,7 +129,7 @@ bool LoadRAM (char * filepath, int method, bool silent)
int offset = 0; int offset = 0;
bool retval = false; bool retval = false;
if(nesGameType == 4) // RAM saves don't exist for FDS games if(GameInfo->type == GIT_FDS) // RAM saves don't exist for FDS games
return false; return false;
if(method == METHOD_AUTO) if(method == METHOD_AUTO)
@ -144,9 +144,9 @@ bool LoadRAM (char * filepath, int method, bool silent)
if (offset > 0) if (offset > 0)
{ {
if(nesGameType == 1) if(GameInfo->type == GIT_CART)
NGCFCEU_GameSave(&iNESCart, 1, method); NGCFCEU_GameSave(&iNESCart, 1, method);
else if(nesGameType == 2) else if(GameInfo->type == GIT_VSUNI)
NGCFCEU_GameSave(&UNIFCart, 1, method); NGCFCEU_GameSave(&UNIFCart, 1, method);
ResetNES(); ResetNES();

View File

@ -66,12 +66,10 @@ bool SaveState (char * filepath, int method, bool silent)
FreeSaveBuffer (); FreeSaveBuffer ();
} }
std::vector<char> tmpbuffer(SAVEBUFFERSIZE); memorystream save(SAVEBUFFERSIZE);
memorystream save(&tmpbuffer); FCEUSS_SaveMS(&save, Z_BEST_COMPRESSION);
FCEUSS_SaveMS(&save, Z_NO_COMPRESSION);
save.sync(); save.sync();
save.trim(); datasize = save.tellp();
datasize = save.size();
if (datasize) if (datasize)
{ {
@ -84,11 +82,7 @@ bool SaveState (char * filepath, int method, bool silent)
snprintf (comments[1], 32, romFilename); snprintf (comments[1], 32, romFilename);
SetMCSaveComments(comments); SetMCSaveComments(comments);
} }
offset = SaveFile(save.buf(), filepath, datasize, method, silent);
AllocSaveBuffer ();
memcpy(savebuffer, save.buf(), datasize);
offset = SaveFile(filepath, datasize, method, silent);
FreeSaveBuffer ();
} }
if (offset > 0) if (offset > 0)

View File

@ -6,8 +6,7 @@
#include "gcaudio.h" #include "gcaudio.h"
#include "gcvideo.h" #include "gcvideo.h"
#include "fceugx.h" #include "fceugx.h"
#include "menu.h"
extern int gametype;
/** /**
* Closes a game. Frees memory, and deinitializes the drivers. * Closes a game. Frees memory, and deinitializes the drivers.
@ -36,20 +35,14 @@ std::fstream* FCEUD_UTF8_fstream(const char *fn, const char *m)
bool FCEUD_ShouldDrawInputAids() bool FCEUD_ShouldDrawInputAids()
{ {
return false; return GCSettings.crosshair;
} }
// General Logging // General Logging
void FCEUD_PrintError(char *s)
{
}
void FCEUD_PrintError(const char *errormsg) void FCEUD_PrintError(const char *errormsg)
{ {
} if(GuiLoaded())
ErrorPrompt(errormsg);
void FCEUD_Message(char *text)
{
} }
void FCEUD_Message(const char *text) void FCEUD_Message(const char *text)

View File

@ -41,7 +41,6 @@ static char szpath[MAXPATHLEN];
static bool inSz = false; static bool inSz = false;
char romFilename[256]; char romFilename[256];
int nesGameType;
/**************************************************************************** /****************************************************************************
* autoLoadMethod() * autoLoadMethod()

View File

@ -39,7 +39,6 @@ extern BROWSERENTRY * browserList;
extern char rootdir[10]; extern char rootdir[10];
extern char romFilename[]; extern char romFilename[];
extern int nesGameType;
bool MakeFilePath(char filepath[], int type, int method, char * filename = NULL, int filenum = -2); bool MakeFilePath(char filepath[], int type, int method, char * filename = NULL, int filenum = -2);
int UpdateDirName(int method); int UpdateDirName(int method);

View File

@ -74,6 +74,14 @@ static char progressMsg[200];
static int progressDone = 0; static int progressDone = 0;
static int progressTotal = 0; static int progressTotal = 0;
bool GuiLoaded()
{
if(mainWindow)
return true;
else
return false;
}
/**************************************************************************** /****************************************************************************
* ResumeGui * ResumeGui
* *

View File

@ -14,6 +14,7 @@
#include <ogcsys.h> #include <ogcsys.h>
bool GuiLoaded();
void InitGUIThreads(); void InitGUIThreads();
void MainMenu (int menuitem); void MainMenu (int menuitem);
void ErrorPrompt(const char * msg); void ErrorPrompt(const char * msg);

View File

@ -173,7 +173,7 @@ void SetControllers()
if(GCSettings.Controller == CTRL_ZAPPER) if(GCSettings.Controller == CTRL_ZAPPER)
{ {
int p; int p;
if(nesGameType == 2) p = 0; if(GameInfo->type == GIT_VSUNI) p = 0;
else p = 1; else p = 1;
zapperdata[p] = FCEU_InitZapper(p); zapperdata[p] = FCEU_InitZapper(p);
FCEUI_SetInput(p, SI_ZAPPER, myzappers[p], 1); FCEUI_SetInput(p, SI_ZAPPER, myzappers[p], 1);
@ -532,7 +532,7 @@ static unsigned char DecodeJoy( unsigned short pad )
} }
else else
{ {
if(nesGameType == 4) // FDS if(GameInfo->type == GIT_FDS) // FDS
{ {
/* the commands shouldn't be issued in parallel so /* the commands shouldn't be issued in parallel so
* we'll delay them so the virtual FDS has a chance * we'll delay them so the virtual FDS has a chance
@ -565,7 +565,12 @@ static unsigned char DecodeJoy( unsigned short pad )
// zapper enabled // zapper enabled
if(GCSettings.Controller == CTRL_ZAPPER) if(GCSettings.Controller == CTRL_ZAPPER)
{ {
int z = 1; // NES port # (0 or 1) int z; // NES port # (0 or 1)
if(GameInfo->type == GIT_VSUNI)
z = 0;
else
z = 1;
myzappers[z][2] = 0; // reset trigger to not pressed myzappers[z][2] = 0; // reset trigger to not pressed