SF [ 2046985 ] SRAM not wiped on power cycle (during movies)

This commit is contained in:
zeromus 2008-08-12 06:52:48 +00:00
parent 595df73847
commit 3e983865df
11 changed files with 69 additions and 52 deletions

View File

@ -1,5 +1,6 @@
---version 2.0.2 released---
11-aug-2008 - zeromus - SF [ 2046985 ] SRAM not wiped on power cycle (during movies)
11-aug-2008 - zeromus - restore IPS patching capability which was lost when archive support was added
11-aug-2008 - zeromus - SF [ 2011550 ] Buffer overflow (change vsprintf to vsnprintf)
11-aug-2008 - zeromus - SF [ 2047004 ] Moviefilenames without extension don't automatically get fm2

View File

@ -636,25 +636,21 @@ void FCEU_SaveGameSave(CartInfo *LocalHWInfo)
if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0])
{
FILE *sp;
char *soot;
soot=strdup(FCEU_MakeFName(FCEUMKF_SAV,0,"sav").c_str());
std::string soot = FCEU_MakeFName(FCEUMKF_SAV,0,"sav");
if((sp=FCEUD_UTF8fopen(soot,"wb"))==NULL)
{
FCEU_PrintError("WRAM file \"%s\" cannot be written to.\n",soot);
}
else
{
int x;
for(x=0;x<4;x++)
for(int x=0;x<4;x++)
if(LocalHWInfo->SaveGame[x])
{
fwrite(LocalHWInfo->SaveGame[x],1,
LocalHWInfo->SaveGameLen[x],sp);
}
}
free(soot);
}
}
@ -666,19 +662,26 @@ void FCEU_LoadGameSave(CartInfo *LocalHWInfo)
if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0] && !disableBatteryLoading)
{
FILE *sp;
char *soot;
soot=strdup(FCEU_MakeFName(FCEUMKF_SAV,0,"sav").c_str());
std::string soot = FCEU_MakeFName(FCEUMKF_SAV,0,"sav");
sp=FCEUD_UTF8fopen(soot,"rb");
if(sp!=NULL)
{
int x;
for(x=0;x<4;x++)
for(int x=0;x<4;x++)
if(LocalHWInfo->SaveGame[x])
fread(LocalHWInfo->SaveGame[x],1,LocalHWInfo->SaveGameLen[x],sp);
}
free(soot);
}
}
//clears all save memory. call this if you want to pretend the saveram has been reset (it doesnt touch what is on disk though)
void FCEU_ClearGameSave(CartInfo *LocalHWInfo)
{
if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0])
{
FILE *sp;
for(int x=0;x<4;x++)
if(LocalHWInfo->SaveGame[x])
memset(LocalHWInfo->SaveGame[x],0,LocalHWInfo->SaveGameLen[x]);
}
}

View File

@ -23,6 +23,7 @@ typedef struct {
void FCEU_SaveGameSave(CartInfo *LocalHWInfo);
void FCEU_LoadGameSave(CartInfo *LocalHWInfo);
void FCEU_ClearGameSave(CartInfo *LocalHWInfo);
extern uint8 *Page[32],*VPage[8],*MMC5SPRVPage[8],*MMC5BGVPage[8];

View File

@ -1282,7 +1282,7 @@ BOOL CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
return FALSE; //TRUE;
}
extern void iNESGI(int h);
extern void iNESGI(GI h);
void DoPatcher(int address,HWND hParent){
iapoffset=address;

View File

@ -84,8 +84,6 @@ static void CloseGame(void)
FCEUD_NetworkClose();
}
FCEUI_StopMovie();
if(GameInfo->name)
{
free(GameInfo->name);
@ -99,6 +97,8 @@ static void CloseGame(void)
GameInterface(GI_CLOSE);
FCEUI_StopMovie();
ResetExState(0,0);
//mbg 5/9/08 - clear screen when game is closed
@ -120,7 +120,7 @@ uint64 timestampbase;
FCEUGI *GameInfo = 0;
void (*GameInterface)(int h);
void (*GameInterface)(GI h);
void (*GameStateRestore)(int version);
readfunc ARead[0x10000];
@ -656,8 +656,8 @@ void hand(X6502 *X, int type, unsigned int A)
int suppressAddPowerCommand=0; // hack... yeah, I know...
void PowerNES(void)
{
/*void MapperInit();
MapperInit();*/
//void MapperInit();
//MapperInit();
if(!suppressAddPowerCommand)
FCEUMOV_AddCommand(FCEUNPCMD_POWER);
@ -689,6 +689,12 @@ void PowerNES(void)
if(GameInfo->type==GIT_VSUNI)
FCEU_VSUniPower();
//if we are in a movie, then reset the saveram
extern int disableBatteryLoading;
if(disableBatteryLoading)
GameInterface(GI_RESETSAVE);
timestampbase=0;
LagCounterReset();

View File

@ -47,12 +47,17 @@ extern int EmulationPaused;
extern readfunc ARead[0x10000];
extern writefunc BWrite[0x10000];
extern void (*GameInterface)(int h);
enum GI {
GI_RESETM2 =1,
GI_POWER =2,
GI_CLOSE =3,
GI_RESETSAVE = 4
};
extern void (*GameInterface)(GI h);
extern void (*GameStateRestore)(int version);
#define GI_RESETM2 1
#define GI_POWER 2
#define GI_CLOSE 3
#include "git.h"
extern FCEUGI *GameInfo;

View File

@ -84,7 +84,7 @@ static uint8 SelectDisk,InDisk;
#define DC_INC 1
void FDSGI(int h)
void FDSGI(GI h)
{
switch(h)
{

View File

@ -89,10 +89,14 @@ static DECLFR(TrainerRead)
}
void iNESGI(int h) //bbit edited: removed static keyword
void iNESGI(GI h) //bbit edited: removed static keyword
{
switch(h)
{
case GI_RESETSAVE:
FCEU_ClearGameSave(&iNESCart);
break;
case GI_RESETM2:
if(MapperReset)
MapperReset();

View File

@ -595,37 +595,30 @@ void FCEUI_StopMovie()
static void poweron(bool shouldDisableBatteryLoading)
{
//// make a for-movie-recording power-on clear the game's save data, too
// extern char lastLoadedGameName [2048];
// extern int disableBatteryLoading, suppressAddPowerCommand;
// suppressAddPowerCommand=1;
// if(shouldDisableBatteryLoading) disableBatteryLoading=1;
// suppressMovieStop=true;
// {
// //we need to save the pause state through this process
// int oldPaused = EmulationPaused;
//extern char lastLoadedGameName [2048];
//extern int disableBatteryLoading, suppressAddPowerCommand;
//suppressAddPowerCommand=1;
//if(shouldDisableBatteryLoading) disableBatteryLoading=1;
//suppressMovieStop=true;
//{
// //we need to save the pause state through this process
// int oldPaused = EmulationPaused;
// // NOTE: this will NOT write an FCEUNPCMD_POWER into the movie file
// FCEUGI* gi = FCEUI_LoadGame(lastLoadedGameName, 0);
// //mbg 5/23/08 - wtf? why would this return null?
// //if(!gi) PowerNES();
// assert(gi);
// // NOTE: this will NOT write an FCEUNPCMD_POWER into the movie file
// FCEUGI* gi = FCEUI_LoadGame(lastLoadedGameName, 0);
// assert(gi);
// PowerNES();
// EmulationPaused = oldPaused;
// }
// suppressMovieStop=false;
// if(shouldDisableBatteryLoading) disableBatteryLoading=0;
// suppressAddPowerCommand=0;
// EmulationPaused = oldPaused;
//}
//suppressMovieStop=false;
//if(shouldDisableBatteryLoading) disableBatteryLoading=0;
//suppressAddPowerCommand=0;
//mbg 6/25/08
//ok this pissed me off
//the only reason for lastLoadedGameName and all these hacks was for this fix:
//"hack for movie WRAM clearing on record from poweron"
//but W-T-F. are you telling me that there is some problem with the poweron sequence?
//screw that. we're using the main poweron sequence, even if that breaks old movie compatibility (unlikely)
extern int disableBatteryLoading;
if(shouldDisableBatteryLoading) disableBatteryLoading=1;
disableBatteryLoading = 1;
PowerNES();
if(shouldDisableBatteryLoading) disableBatteryLoading=0;
disableBatteryLoading = 0;
}

View File

@ -121,7 +121,7 @@ NSF_HEADER NSFHeader; //mbg merge 6/29/06 - needs to be global
void NSFMMC5_Close(void);
static uint8 *ExWRAM=0;
void NSFGI(int h)
void NSFGI(GI h)
{
switch(h)
{

View File

@ -501,10 +501,14 @@ static int InitializeBoard(void)
return(0);
}
static void UNIFGI(int h)
static void UNIFGI(GI h)
{
switch(h)
{
case GI_RESETSAVE:
FCEU_ClearGameSave(&UNIFCart);
break;
case GI_RESETM2:
if(UNIFCart.Reset)
UNIFCart.Reset();