Fix code so that FCEUGI fully constructs properly and is not clobbered after the construction by a memset. Also, some minor code cleanup in related areas.
This commit is contained in:
parent
c97e2c9ad3
commit
94975d7dbe
41
src/fceu.cpp
41
src/fceu.cpp
|
@ -121,23 +121,27 @@ static unsigned int pauseTimer = 0;
|
||||||
|
|
||||||
|
|
||||||
FCEUGI::FCEUGI()
|
FCEUGI::FCEUGI()
|
||||||
: filename(0),
|
|
||||||
archiveFilename(0)
|
|
||||||
{
|
{
|
||||||
//printf("%08x",opsize); // WTF?!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FCEUGI::~FCEUGI()
|
FCEUGI::~FCEUGI()
|
||||||
{
|
{
|
||||||
|
if (name)
|
||||||
|
{
|
||||||
|
free(name);
|
||||||
|
name = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
if (filename)
|
if (filename)
|
||||||
{
|
{
|
||||||
free(filename);
|
free(filename);
|
||||||
filename = NULL;
|
filename = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (archiveFilename)
|
if (archiveFilename)
|
||||||
{
|
{
|
||||||
free(archiveFilename);
|
free(archiveFilename);
|
||||||
archiveFilename = NULL;
|
archiveFilename = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +198,7 @@ static void FCEU_CloseGame(void)
|
||||||
|
|
||||||
if (GameInfo->name) {
|
if (GameInfo->name) {
|
||||||
free(GameInfo->name);
|
free(GameInfo->name);
|
||||||
GameInfo->name = NULL;
|
GameInfo->name = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GameInfo->type != GIT_NSF) {
|
if (GameInfo->type != GIT_NSF) {
|
||||||
|
@ -224,7 +228,7 @@ static void FCEU_CloseGame(void)
|
||||||
FCEU_CloseGenie();
|
FCEU_CloseGenie();
|
||||||
|
|
||||||
delete GameInfo;
|
delete GameInfo;
|
||||||
GameInfo = NULL;
|
GameInfo = nullptr;
|
||||||
|
|
||||||
currFrameCounter = 0;
|
currFrameCounter = 0;
|
||||||
|
|
||||||
|
@ -243,7 +247,7 @@ static void FCEU_CloseGame(void)
|
||||||
uint64 timestampbase;
|
uint64 timestampbase;
|
||||||
|
|
||||||
|
|
||||||
FCEUGI *GameInfo = NULL;
|
FCEUGI *GameInfo = nullptr;
|
||||||
|
|
||||||
void (*GameInterface)(GI h);
|
void (*GameInterface)(GI h);
|
||||||
void (*GameStateRestore)(int version);
|
void (*GameStateRestore)(int version);
|
||||||
|
@ -308,8 +312,8 @@ void FlushGenieRW(void) {
|
||||||
}
|
}
|
||||||
free(AReadG);
|
free(AReadG);
|
||||||
free(BWriteG);
|
free(BWriteG);
|
||||||
AReadG = NULL;
|
AReadG = nullptr;
|
||||||
BWriteG = NULL;
|
BWriteG = nullptr;
|
||||||
RWWrap = 0;
|
RWWrap = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -375,7 +379,7 @@ static void AllocBuffers() {
|
||||||
|
|
||||||
static void FreeBuffers() {
|
static void FreeBuffers() {
|
||||||
FCEU_free(RAM);
|
FCEU_free(RAM);
|
||||||
RAM = NULL;
|
RAM = nullptr;
|
||||||
}
|
}
|
||||||
//------
|
//------
|
||||||
|
|
||||||
|
@ -402,14 +406,14 @@ void ResetGameLoaded(void) {
|
||||||
if (GameInfo) FCEU_CloseGame();
|
if (GameInfo) FCEU_CloseGame();
|
||||||
EmulationPaused = 0; //mbg 5/8/08 - loading games while paused was bad news. maybe this fixes it
|
EmulationPaused = 0; //mbg 5/8/08 - loading games while paused was bad news. maybe this fixes it
|
||||||
GameStateRestore = 0;
|
GameStateRestore = 0;
|
||||||
PPU_hook = NULL;
|
PPU_hook = nullptr;
|
||||||
GameHBIRQHook = NULL;
|
GameHBIRQHook = nullptr;
|
||||||
FFCEUX_PPURead = NULL;
|
FFCEUX_PPURead = nullptr;
|
||||||
FFCEUX_PPUWrite = NULL;
|
FFCEUX_PPUWrite = nullptr;
|
||||||
if (GameExpSound.Kill)
|
if (GameExpSound.Kill)
|
||||||
GameExpSound.Kill();
|
GameExpSound.Kill();
|
||||||
memset(&GameExpSound, 0, sizeof(GameExpSound));
|
memset(&GameExpSound, 0, sizeof(GameExpSound));
|
||||||
MapIRQHook = NULL;
|
MapIRQHook = nullptr;
|
||||||
MMC5Hack = 0;
|
MMC5Hack = 0;
|
||||||
PEC586Hack = 0;
|
PEC586Hack = 0;
|
||||||
QTAIHack = 0;
|
QTAIHack = 0;
|
||||||
|
@ -474,7 +478,6 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode, bool silen
|
||||||
|
|
||||||
FCEU_CloseGame();
|
FCEU_CloseGame();
|
||||||
GameInfo = new FCEUGI();
|
GameInfo = new FCEUGI();
|
||||||
memset( (void*)GameInfo, 0, sizeof(FCEUGI));
|
|
||||||
|
|
||||||
GameInfo->filename = strdup(fp->filename.c_str());
|
GameInfo->filename = strdup(fp->filename.c_str());
|
||||||
if (fp->archiveFilename != "")
|
if (fp->archiveFilename != "")
|
||||||
|
@ -1344,7 +1347,7 @@ void UpdateAutosave(void) {
|
||||||
FCEUSS_Save(f, false);
|
FCEUSS_Save(f, false);
|
||||||
AutoSS = true; //Flag that an auto-savestate was made
|
AutoSS = true; //Flag that an auto-savestate was made
|
||||||
free(f);
|
free(f);
|
||||||
f = NULL;
|
f = nullptr;
|
||||||
AutosaveStatus[AutosaveIndex] = 1;
|
AutosaveStatus[AutosaveIndex] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1358,7 +1361,7 @@ void FCEUI_RewindToLastAutosave(void) {
|
||||||
f = strdup(FCEU_MakeFName(FCEUMKF_AUTOSTATE, AutosaveIndex, 0).c_str());
|
f = strdup(FCEU_MakeFName(FCEUMKF_AUTOSTATE, AutosaveIndex, 0).c_str());
|
||||||
FCEUSS_Load(f);
|
FCEUSS_Load(f);
|
||||||
free(f);
|
free(f);
|
||||||
f = NULL;
|
f = nullptr;
|
||||||
|
|
||||||
//Set pointer to previous available slot
|
//Set pointer to previous available slot
|
||||||
if (AutosaveStatus[(AutosaveIndex + AutosaveQty - 1) % AutosaveQty] == 1) {
|
if (AutosaveStatus[(AutosaveIndex + AutosaveQty - 1) % AutosaveQty] == 1) {
|
||||||
|
|
31
src/git.h
31
src/git.h
|
@ -153,27 +153,28 @@ struct FCEUGI
|
||||||
FCEUGI();
|
FCEUGI();
|
||||||
~FCEUGI();
|
~FCEUGI();
|
||||||
|
|
||||||
uint8 *name; //Game name, UTF8 encoding
|
uint8 *name = nullptr; //Game name, UTF8 encoding
|
||||||
int mappernum;
|
int mappernum = 0;
|
||||||
|
|
||||||
EGIT type;
|
EGIT type = GIT_CART;
|
||||||
EGIV vidsys; //Current emulated video system;
|
EGIV vidsys = GIV_USER; //Current emulated video system;
|
||||||
ESI input[2]; //Desired input for emulated input ports 1 and 2; -1 for unknown desired input.
|
ESI input[2] = { SI_UNSET, SI_UNSET }; //Desired input for emulated input ports 1 and 2; -1 for unknown desired input.
|
||||||
ESIFC inputfc; //Desired Famicom expansion port device. -1 for unknown desired input.
|
ESIFC inputfc = SIFC_UNSET; //Desired Famicom expansion port device. -1 for unknown desired input.
|
||||||
ESIS cspecial; //Special cart expansion: DIP switches, barcode reader, etc.
|
ESIS cspecial = SIS_NONE; //Special cart expansion: DIP switches, barcode reader, etc.
|
||||||
EGIPPU vs_ppu; //PPU type for Vs. System
|
EGIPPU vs_ppu = GIPPU_USER; //PPU type for Vs. System
|
||||||
EGIVS vs_type; //Vs. System type
|
EGIVS vs_type = EGIVS_NORMAL; //Vs. System type
|
||||||
uint8 vs_cswitch; // Switch first and second controllers for Vs. System
|
uint8 vs_cswitch = SIS_NONE; // Switch first and second controllers for Vs. System
|
||||||
|
|
||||||
MD5DATA MD5;
|
MD5DATA MD5;
|
||||||
|
|
||||||
//mbg 6/8/08 - ???
|
//mbg 6/8/08 - ???
|
||||||
int soundrate; //For Ogg Vorbis expansion sound wacky support. 0 for default.
|
int soundrate = 0; //For Ogg Vorbis expansion sound wacky support. 0 for default.
|
||||||
int soundchan; //Number of sound channels.
|
int soundchan = 0; //Number of sound channels.
|
||||||
|
|
||||||
char* filename;
|
char* filename = nullptr;
|
||||||
char* archiveFilename;
|
char* archiveFilename = nullptr;
|
||||||
int archiveCount;
|
int archiveCount = 0;
|
||||||
|
bool loadedFromTmpFile = false; // Was loaded from temporary file, file most likely no longer exists
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -161,9 +161,9 @@ static int NAME(FCEUFILE *fp) {
|
||||||
namebuf[index] = 0;
|
namebuf[index] = 0;
|
||||||
FCEU_printf("%s\n", namebuf);
|
FCEU_printf("%s\n", namebuf);
|
||||||
|
|
||||||
if (!GameInfo->name) {
|
if (GameInfo->name == nullptr)
|
||||||
GameInfo->name = (uint8*)malloc(strlen(namebuf) + 1); //mbg merge 7/17/06 added cast
|
{
|
||||||
strcpy((char*)GameInfo->name, namebuf); //mbg merge 7/17/06 added cast
|
GameInfo->name = (uint8*)strdup(namebuf);
|
||||||
}
|
}
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue