mirror of
https://github.com/dborth/fceugx.git
synced 2025-01-07 14:28:18 +01:00
code cleanup
This commit is contained in:
parent
5b8602dadf
commit
e22f34ec7f
@ -50,8 +50,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
void (*SPreSave)(void);
|
||||
void (*SPostSave)(void);
|
||||
static void (*SPreSave)(void);
|
||||
static void (*SPostSave)(void);
|
||||
|
||||
static int SaveStateStatus[10];
|
||||
static int StateShow;
|
||||
@ -68,7 +68,7 @@ bool undoLS = false; //This will be true if a backupstate was made and it was
|
||||
bool redoLS = false; //This will be true if a backupstate was loaded, meaning redoLoadState can be run
|
||||
|
||||
#define SFMDATA_SIZE (64)
|
||||
SFORMAT SFMDATA[SFMDATA_SIZE];
|
||||
static SFORMAT SFMDATA[SFMDATA_SIZE];
|
||||
static int SFEXINDEX;
|
||||
|
||||
#define RLSB FCEUSTATE_RLSB //0x80000000
|
||||
|
@ -185,7 +185,7 @@ private:
|
||||
throw new std::runtime_error("memory_streambuf is not expandable");
|
||||
|
||||
size_t newcapacity;
|
||||
if(upto == -1)
|
||||
if(upto == 0)
|
||||
newcapacity = capacity + capacity/2 + 2;
|
||||
else
|
||||
newcapacity = std::max(upto,capacity);
|
||||
|
@ -29,38 +29,15 @@ bool romLoaded = false;
|
||||
|
||||
#define SAMPLERATE 48000
|
||||
|
||||
static FCEUFILE *fceufp = NULL;
|
||||
static memorystream* fceumem = NULL;
|
||||
|
||||
static void MakeFCEUFile(char * membuffer, int length)
|
||||
{
|
||||
if(fceufp != NULL)
|
||||
{
|
||||
delete fceufp;
|
||||
fceufp = NULL;
|
||||
}
|
||||
|
||||
fceumem = new memorystream(membuffer, length); // we never need to delete this...?
|
||||
|
||||
fceufp = new FCEUFILE();
|
||||
fceufp->size = length;
|
||||
fceufp->stream = fceumem;
|
||||
fceufp->filename = romFilename;
|
||||
}
|
||||
|
||||
int GCMemROM(int method, int size)
|
||||
{
|
||||
ResetGameLoaded();
|
||||
|
||||
//AutosaveStatus[0] = AutosaveStatus[1] = 0;
|
||||
//AutosaveStatus[2] = AutosaveStatus[3] = 0;
|
||||
|
||||
CloseGame();
|
||||
GameInfo = new FCEUGI();
|
||||
memset(GameInfo, 0, sizeof(FCEUGI));
|
||||
|
||||
GameInfo->filename = strdup(romFilename);
|
||||
//if(fceufp->archiveFilename != "") GameInfo->archiveFilename = strdup(fceufp->archiveFilename.c_str());
|
||||
GameInfo->archiveCount = 0;
|
||||
|
||||
/*** Set some default values ***/
|
||||
@ -78,7 +55,12 @@ int GCMemROM(int method, int size)
|
||||
FCEUI_SetSoundVolume(100); // 0-100
|
||||
FCEUI_SetLowPass(0);
|
||||
|
||||
MakeFCEUFile((char *) nesrom, size);
|
||||
memorystream * fceumem = new memorystream((char *) nesrom, size);
|
||||
|
||||
FCEUFILE * fceufp = new FCEUFILE();
|
||||
fceufp->size = size;
|
||||
fceufp->stream = fceumem;
|
||||
fceufp->filename = romFilename;
|
||||
|
||||
nesGameType = 0;
|
||||
|
||||
@ -121,6 +103,9 @@ int GCMemROM(int method, int size)
|
||||
nesGameType = 4;
|
||||
}
|
||||
|
||||
//delete fceufp;
|
||||
//delete fceumem;
|
||||
|
||||
if (nesGameType > 0)
|
||||
{
|
||||
FCEU_ResetVidSys();
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include <fat.h>
|
||||
#include <zlib.h>
|
||||
#include "pngu/pngu.h"
|
||||
|
||||
#include "fceugx.h"
|
||||
@ -27,247 +28,6 @@
|
||||
#include "fileop.h"
|
||||
#include "gcvideo.h"
|
||||
|
||||
#define RLSB 0x80000000
|
||||
|
||||
/****************************************************************************
|
||||
* Memory based file functions
|
||||
****************************************************************************/
|
||||
static int sboffset; // Used as a basic fileptr
|
||||
|
||||
/*** Open a file ***/
|
||||
static void memopen()
|
||||
{
|
||||
sboffset = 0;
|
||||
}
|
||||
|
||||
/*** Write to the file ***/
|
||||
static void memfwrite(void *buffer, int len)
|
||||
{
|
||||
if ((sboffset + len) > SAVEBUFFERSIZE)
|
||||
ErrorPrompt("Buffer Exceeded");
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
memcpy(&savebuffer[sboffset], buffer, len);
|
||||
sboffset += len;
|
||||
}
|
||||
}
|
||||
|
||||
/*** Read from a file ***/
|
||||
static void memfread(void *buffer, int len)
|
||||
{
|
||||
if ((sboffset + len) > SAVEBUFFERSIZE)
|
||||
ErrorPrompt("Buffer exceeded");
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
memcpy(buffer, &savebuffer[sboffset], len);
|
||||
sboffset += len;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* GCReadChunk
|
||||
*
|
||||
* Read the array of SFORMAT structures to memory
|
||||
****************************************************************************/
|
||||
static int GCReadChunk(int chunkid, SFORMAT *sf)
|
||||
{
|
||||
uint32 csize;
|
||||
static char chunk[6];
|
||||
int chunklength;
|
||||
int thischunk;
|
||||
char info[128];
|
||||
|
||||
memfread(&chunk, 4);
|
||||
memfread(&thischunk, 4);
|
||||
memfread(&chunklength, 4);
|
||||
|
||||
if (memcmp(&chunk, "CHNK", 4) == 0)
|
||||
{
|
||||
if (chunkid == thischunk)
|
||||
{
|
||||
/*** Now decode the array of chunks to this one ***/
|
||||
while (sf->v)
|
||||
{
|
||||
memfread(&chunk, 4);
|
||||
if (memcmp(&chunk, "CHKE", 4) == 0)
|
||||
return 1;
|
||||
|
||||
if (memcmp(&chunk, sf->desc, 4) == 0)
|
||||
{
|
||||
memfread(&csize, 4);
|
||||
if (csize == (sf->s & (~RLSB)))
|
||||
{
|
||||
memfread(sf->v, csize);
|
||||
sprintf(info, "%s %d", chunk, csize);
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorPrompt("Bad chunk link");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(info, "No Sync %s %s", chunk, sf->desc);
|
||||
ErrorPrompt(info);
|
||||
return 0;
|
||||
}
|
||||
sf++;
|
||||
}
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* GCFCEUSS_Load
|
||||
*
|
||||
* Reads the SFORMAT arrays
|
||||
****************************************************************************/
|
||||
static int GCFCEUSS_Load(int method)
|
||||
{
|
||||
memopen(); // reset file pointer
|
||||
|
||||
sboffset += 16; // skip FCEU header
|
||||
|
||||
// Now read the chunks back
|
||||
if (GCReadChunk(1, SFCPU))
|
||||
{
|
||||
if (GCReadChunk(2, SFCPUC))
|
||||
{
|
||||
X.mooPI = X.P; // Quick and dirty hack.
|
||||
if (GCReadChunk(3, FCEUPPU_STATEINFO))
|
||||
{
|
||||
if (GCReadChunk(4, FCEUCTRL_STATEINFO))
|
||||
{
|
||||
if (GCReadChunk(5, FCEUSND_STATEINFO))
|
||||
{
|
||||
if (GCReadChunk(0x10, SFMDATA))
|
||||
{
|
||||
if (GameStateRestore)
|
||||
GameStateRestore(FCEU_VERSION_NUMERIC);
|
||||
|
||||
FCEUPPU_LoadState(FCEU_VERSION_NUMERIC);
|
||||
FCEUSND_LoadState(FCEU_VERSION_NUMERIC);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* GCSaveChunk
|
||||
*
|
||||
* Write the array of SFORMAT structures to the file
|
||||
****************************************************************************/
|
||||
static int GCSaveChunk(int chunkid, SFORMAT *sf)
|
||||
{
|
||||
int chnkstart;
|
||||
int csize = 0;
|
||||
int chsize = 0;
|
||||
char chunk[] = "CHNK";
|
||||
|
||||
/*** Add chunk marker ***/
|
||||
memfwrite(&chunk, 4);
|
||||
memfwrite(&chunkid, 4);
|
||||
chnkstart = sboffset; /*** Save ptr ***/
|
||||
sboffset += 4; /*** Space for length ***/
|
||||
csize += 12;
|
||||
|
||||
/*** Now run through this structure ***/
|
||||
while (sf->v)
|
||||
{
|
||||
/*** Check that there is a decription ***/
|
||||
if (sf->desc == NULL)
|
||||
break;
|
||||
|
||||
/*** Write out the description ***/
|
||||
memfwrite(sf->desc, 4);
|
||||
|
||||
/*** Write the length of this chunk ***/
|
||||
chsize = (sf->s & (~RLSB));
|
||||
memfwrite(&chsize, 4);
|
||||
|
||||
if (chsize > 0)
|
||||
{
|
||||
/*** Write the actual data ***/
|
||||
memfwrite(sf->v, chsize);
|
||||
}
|
||||
|
||||
csize += 8;
|
||||
csize += chsize;
|
||||
|
||||
sf++;
|
||||
}
|
||||
|
||||
/*** Update CHNK length ***/
|
||||
memcpy(&savebuffer[chnkstart], &csize, 4);
|
||||
|
||||
return csize;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* GCFCEUSS_Save
|
||||
*
|
||||
* This is a modified version of FCEUSS_Save
|
||||
* It uses memory for it's I/O and has an added CHNK block.
|
||||
* The file is terminated with CHNK length of 0.
|
||||
****************************************************************************/
|
||||
extern void (*SPreSave)(void);
|
||||
extern void (*SPostSave)(void);
|
||||
|
||||
static int GCFCEUSS_Save(int method)
|
||||
{
|
||||
int totalsize = 0;
|
||||
unsigned char header[16] = "FCS\xff";
|
||||
char chunk[] = "CHKE";
|
||||
int zero = 0;
|
||||
int version = 0x981211;
|
||||
memcpy(&header[8], &version, 4); // Add version ID
|
||||
|
||||
memopen(); // Reset Memory File
|
||||
|
||||
// Do internal Saving
|
||||
FCEUPPU_SaveState();
|
||||
FCEUSND_SaveState();
|
||||
|
||||
// Write header
|
||||
memfwrite(&header, 16);
|
||||
totalsize += 16;
|
||||
totalsize += GCSaveChunk(1, SFCPU);
|
||||
totalsize += GCSaveChunk(2, SFCPUC);
|
||||
totalsize += GCSaveChunk(3, FCEUPPU_STATEINFO);
|
||||
totalsize += GCSaveChunk(4, FCEUCTRL_STATEINFO);
|
||||
totalsize += GCSaveChunk(5, FCEUSND_STATEINFO);
|
||||
|
||||
if(nesGameType == 4) // FDS
|
||||
SPreSave();
|
||||
|
||||
totalsize += GCSaveChunk(0x10, SFMDATA);
|
||||
|
||||
if(nesGameType == 4) // FDS
|
||||
SPostSave();
|
||||
|
||||
// Add terminating CHNK
|
||||
memfwrite(&chunk,4);
|
||||
memfwrite(&zero,4);
|
||||
totalsize += 8;
|
||||
|
||||
return totalsize;
|
||||
}
|
||||
|
||||
bool SaveState (char * filepath, int method, bool silent)
|
||||
{
|
||||
bool retval = false;
|
||||
@ -306,9 +66,12 @@ bool SaveState (char * filepath, int method, bool silent)
|
||||
FreeSaveBuffer ();
|
||||
}
|
||||
|
||||
AllocSaveBuffer ();
|
||||
|
||||
datasize = GCFCEUSS_Save(method);
|
||||
std::vector<char> tmpbuffer(SAVEBUFFERSIZE);
|
||||
memorystream save(&tmpbuffer);
|
||||
FCEUSS_SaveMS(&save, Z_NO_COMPRESSION);
|
||||
save.sync();
|
||||
save.trim();
|
||||
datasize = save.size();
|
||||
|
||||
if (datasize)
|
||||
{
|
||||
@ -322,9 +85,11 @@ bool SaveState (char * filepath, int method, bool silent)
|
||||
SetMCSaveComments(comments);
|
||||
}
|
||||
|
||||
AllocSaveBuffer ();
|
||||
memcpy(savebuffer, save.buf(), datasize);
|
||||
offset = SaveFile(filepath, datasize, method, silent);
|
||||
FreeSaveBuffer ();
|
||||
}
|
||||
FreeSaveBuffer ();
|
||||
|
||||
if (offset > 0)
|
||||
{
|
||||
@ -369,7 +134,8 @@ bool LoadState (char * filepath, int method, bool silent)
|
||||
|
||||
if (offset > 0)
|
||||
{
|
||||
GCFCEUSS_Load(method);
|
||||
memorystream save((char *)savebuffer, offset);
|
||||
FCEUSS_LoadFP(&save, SSLOADPARAM_NOBACKUP);
|
||||
retval = true;
|
||||
}
|
||||
else
|
||||
|
@ -1,8 +1,6 @@
|
||||
#ifndef _FCEUSUPPORT_H_
|
||||
#define _FCEUSUPPORT_H_
|
||||
|
||||
extern unsigned char * nesrom;
|
||||
|
||||
#include <gccore.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
@ -23,6 +21,8 @@ extern unsigned char * nesrom;
|
||||
#include "file.h"
|
||||
#include "cheat.h"
|
||||
|
||||
extern unsigned char * nesrom;
|
||||
|
||||
extern int FDSLoad(const char *name, FCEUFILE *fp);
|
||||
extern int iNESLoad(const char *name, FCEUFILE *fp, int o);
|
||||
extern int UNIFLoad(const char *name, FCEUFILE *fp);
|
||||
@ -40,24 +40,6 @@ extern CartInfo UNIFCart;
|
||||
extern INPUTC *FCEU_InitZapper(int w);
|
||||
extern void FCEU_ResetPalette(void);
|
||||
|
||||
/*** External functions ***/
|
||||
extern void FCEUPPU_SaveState(void);
|
||||
extern void FCEUSND_SaveState(void);
|
||||
extern void FCEUPPU_LoadState(int version);
|
||||
extern void FCEUSND_LoadState(int version);
|
||||
extern void FlipByteOrder(uint8 *src, uint32 count);
|
||||
extern void (*GameStateRestore)(int version);
|
||||
|
||||
/*** External save structures ***/
|
||||
extern SFORMAT SFCPU[];
|
||||
extern SFORMAT SFCPUC[];
|
||||
extern SFORMAT FCEUPPU_STATEINFO[];
|
||||
extern SFORMAT FCEUCTRL_STATEINFO[];
|
||||
extern SFORMAT FCEUSND_STATEINFO[];
|
||||
extern SFORMAT SFMDATA[64];
|
||||
extern u32 iNESGameCRC32;
|
||||
|
||||
extern int eoptions;
|
||||
#define EO_NO8LIM 1
|
||||
#define EO_SUBASE 2
|
||||
#define EO_CLIPSIDES 8
|
||||
|
Loading…
Reference in New Issue
Block a user