fix sdl savestates?
This commit is contained in:
parent
d40ffb715c
commit
2a190f3c74
|
@ -32,6 +32,7 @@
|
|||
#include "gui.h"
|
||||
#include "fceu.h"
|
||||
#include "movie.h"
|
||||
#include "window.h"
|
||||
|
||||
#include "keyscan.h"
|
||||
|
||||
|
@ -336,7 +337,6 @@ static uint8 fkbkeys[0x48];
|
|||
static uint8 suborkbkeys[0x60];
|
||||
|
||||
void KeyboardUpdateState(void); //mbg merge 7/17/06 yech had to add this
|
||||
void GetMouseData(uint32 *md); //mbg merge 7/17/06 yech had to add this
|
||||
|
||||
void FCEUD_UpdateInput()
|
||||
{
|
||||
|
|
|
@ -502,11 +502,6 @@ void win_AllocBuffers(uint8 **GameMemBlock, uint8 **RAM)
|
|||
*RAM = (uint8 *)MapViewOfFile(mapRAM, FILE_MAP_WRITE, 0, 0, 0);
|
||||
}
|
||||
|
||||
// Give RAM pointer to state structure
|
||||
//mbg 7/28/06 - wtf?
|
||||
extern SFORMAT SFCPU[];
|
||||
SFCPU[6].v = *RAM;
|
||||
|
||||
//Bot input
|
||||
// qfox: tossed mapping alltogether
|
||||
//mapBotInput = CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE,0, BOT_MAXFRAMES*sizeof(int), "fceu.BotInput");
|
||||
|
|
|
@ -538,7 +538,7 @@ void LoadNewGamey(HWND hParent, const char *initialdir)
|
|||
}
|
||||
}
|
||||
|
||||
void GetMouseData(uint32 *md)
|
||||
void GetMouseData(uint32 (&md)[3])
|
||||
{
|
||||
if(FCEUMOV_Mode() == MOVIEMODE_PLAY)
|
||||
{
|
||||
|
|
|
@ -28,5 +28,6 @@ void LoadNewGamey(HWND hParent, const char *initialdir);
|
|||
int BrowseForFolder(HWND hParent, const char *htext, char *buf);
|
||||
void UpdateCheckedMenuItems();
|
||||
void SetMainWindowStuff();
|
||||
void GetMouseData(uint32 (&md)[3]);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "utils/endian.h"
|
||||
#include "utils/memory.h"
|
||||
#include "utils/memorystream.h"
|
||||
#include "utils/xstring.h"
|
||||
#include "file.h"
|
||||
#include "fds.h"
|
||||
#include "state.h"
|
||||
|
@ -72,11 +73,7 @@ SFORMAT SFCPU[]={
|
|||
{ &X.X, 1, "X\0\0"},
|
||||
{ &X.Y, 1, "Y\0\0"},
|
||||
{ &X.S, 1, "S\0\0"},
|
||||
#ifdef _USE_SHARED_MEMORY_
|
||||
{ NULL, 0x800, "RAM"}, //will be initialized later after getting a pointer to RAM
|
||||
#else
|
||||
{ RAM, 0x800, "RAM"},
|
||||
#endif
|
||||
{ &RAM, 0x800 | FCEUSTATE_INDIRECT, "RAM", },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
|
@ -96,7 +93,7 @@ static int SubWrite(std::ostream* os, SFORMAT *sf)
|
|||
|
||||
while(sf->v)
|
||||
{
|
||||
if(sf->s==~0) /* Link to another struct. */
|
||||
if(sf->s==~0) //Link to another struct
|
||||
{
|
||||
uint32 tmp;
|
||||
|
||||
|
@ -107,24 +104,28 @@ static int SubWrite(std::ostream* os, SFORMAT *sf)
|
|||
continue;
|
||||
}
|
||||
|
||||
acc+=8; /* Description + size */
|
||||
acc+=sf->s&(~RLSB);
|
||||
acc+=8; //Description + size
|
||||
acc+=sf->s&(~FCEUSTATE_FLAGS);
|
||||
|
||||
if(os) /* Are we writing or calculating the size of this block? */
|
||||
if(os) //Are we writing or calculating the size of this block?
|
||||
{
|
||||
os->write(sf->desc,4);
|
||||
write32le(sf->s&(~RLSB),os);
|
||||
write32le(sf->s&(~FCEUSTATE_FLAGS),os);
|
||||
|
||||
#ifndef LSB_FIRST
|
||||
if(sf->s&RLSB)
|
||||
FlipByteOrder(sf->v,sf->s&(~RLSB));
|
||||
FlipByteOrder(sf->v,sf->s&(~FCEUSTATE_FLAGS));
|
||||
#endif
|
||||
|
||||
os->write((char*)sf->v,sf->s&(~RLSB));
|
||||
/* Now restore the original byte order. */
|
||||
if(sf->s&FCEUSTATE_INDIRECT)
|
||||
os->write(*(char **)sf->v,sf->s&(~FCEUSTATE_FLAGS));
|
||||
else
|
||||
os->write((char*)sf->v,sf->s&(~FCEUSTATE_FLAGS));
|
||||
|
||||
//Now restore the original byte order.
|
||||
#ifndef LSB_FIRST
|
||||
if(sf->s&RLSB)
|
||||
FlipByteOrder(sf->v,sf->s&(~RLSB));
|
||||
FlipByteOrder(sf->v,sf->s&(~FCEUSTATE_FLAGS));
|
||||
#endif
|
||||
}
|
||||
sf++;
|
||||
|
@ -139,7 +140,7 @@ static int SubWrite(FILE *st, SFORMAT *sf)
|
|||
|
||||
while(sf->v)
|
||||
{
|
||||
if(sf->s==~0) /* Link to another struct. */
|
||||
if(sf->s==~0) //Link to another struct
|
||||
{
|
||||
uint32 tmp;
|
||||
|
||||
|
@ -150,24 +151,24 @@ static int SubWrite(FILE *st, SFORMAT *sf)
|
|||
continue;
|
||||
}
|
||||
|
||||
acc+=8; /* Description + size */
|
||||
acc+=sf->s&(~RLSB);
|
||||
acc+=8; //Description + size
|
||||
acc+=sf->s&(~FCEUSTATE_FLAGS);
|
||||
|
||||
if(st) /* Are we writing or calculating the size of this block? */
|
||||
if(st) // Are we writing or calculating the size of this block?
|
||||
{
|
||||
fwrite(sf->desc,1,4,st);
|
||||
write32le(sf->s&(~RLSB),st);
|
||||
write32le(sf->s&(~FCEUSTATE_FLAGS),st);
|
||||
|
||||
#ifndef LSB_FIRST
|
||||
if(sf->s&RLSB)
|
||||
FlipByteOrder(sf->v,sf->s&(~RLSB));
|
||||
FlipByteOrder(sf->v,sf->s&(~FCEUSTATE_FLAGS));
|
||||
#endif
|
||||
|
||||
fwrite((uint8 *)sf->v,1,sf->s&(~RLSB),st);
|
||||
/* Now restore the original byte order. */
|
||||
fwrite((uint8 *)sf->v,1,sf->s&(~FCEUSTATE_FLAGS),st);
|
||||
//Now restore the original byte order.
|
||||
#ifndef LSB_FIRST
|
||||
if(sf->s&RLSB)
|
||||
FlipByteOrder(sf->v,sf->s&(~RLSB));
|
||||
FlipByteOrder(sf->v,sf->s&(~FCEUSTATE_FLAGS));
|
||||
#endif
|
||||
}
|
||||
sf++;
|
||||
|
@ -219,7 +220,7 @@ static SFORMAT *CheckS(SFORMAT *sf, uint32 tsize, char *desc)
|
|||
}
|
||||
if(!memcmp(desc,sf->desc,4))
|
||||
{
|
||||
if(tsize!=(sf->s&(~RLSB)))
|
||||
if(tsize!=(sf->s&(~FCEUSTATE_FLAGS)))
|
||||
return(0);
|
||||
return(sf);
|
||||
}
|
||||
|
@ -251,11 +252,14 @@ static int ReadStateChunk(FILE *st, SFORMAT *sf, int size)
|
|||
|
||||
if((tmp=CheckS(sf,tsize,toa)))
|
||||
{
|
||||
fread((uint8 *)tmp->v,1,tmp->s&(~RLSB),st);
|
||||
if(tmp->s&FCEUSTATE_INDIRECT)
|
||||
fread(*(uint8 **)tmp->v,1,tmp->s&(~FCEUSTATE_FLAGS),st);
|
||||
else
|
||||
fread((uint8 *)tmp->v,1,tmp->s&(~FCEUSTATE_FLAGS),st);
|
||||
|
||||
#ifndef LSB_FIRST
|
||||
if(tmp->s&RLSB)
|
||||
FlipByteOrder(tmp->v,tmp->s&(~RLSB));
|
||||
FlipByteOrder(tmp->v,tmp->s&(~FCEUSTATE_FLAGS));
|
||||
#endif
|
||||
}
|
||||
else
|
||||
|
@ -485,7 +489,7 @@ void FCEUSS_Save(char *fname)
|
|||
return;
|
||||
}
|
||||
|
||||
FCEUSS_SaveFP(st,-1);
|
||||
FCEUSS_SaveFP(st,0);
|
||||
|
||||
fclose(st);
|
||||
|
||||
|
@ -770,7 +774,13 @@ int FCEUSS_Load(char *fname)
|
|||
//states are being loaded.
|
||||
if(FCEUSS_LoadFP(st,FCEU_BotMode()?SSLOADPARAM_NOBACKUP:SSLOADPARAM_BACKUP))
|
||||
{
|
||||
if(!fname)
|
||||
if(fname)
|
||||
{
|
||||
char szFilename[260]={0};
|
||||
splitpath(fname, 0, 0, szFilename, 0);
|
||||
FCEU_DispMessage("State %s loaded.",szFilename);
|
||||
}
|
||||
else
|
||||
{
|
||||
//This looks redudant to me... but why bother deleting it:)
|
||||
SaveStateStatus[CurrentState]=1;
|
||||
|
|
21
src/state.h
21
src/state.h
|
@ -39,18 +39,29 @@ bool FCEUSS_LoadFP(FILE *, ENUM_SSLOADPARAMS);
|
|||
extern int CurrentState;
|
||||
void FCEUSS_CheckStates(void);
|
||||
|
||||
typedef struct {
|
||||
void *v;
|
||||
uint32 s;
|
||||
char *desc;
|
||||
} SFORMAT;
|
||||
struct SFORMAT
|
||||
{
|
||||
//a void* to the data or a void** to the data
|
||||
void *v;
|
||||
|
||||
//size, plus flags
|
||||
uint32 s;
|
||||
|
||||
//a string description of the element
|
||||
char *desc;
|
||||
};
|
||||
|
||||
void ResetExState(void (*PreSave)(void),void (*PostSave)(void));
|
||||
void AddExState(void *v, uint32 s, int type, char *desc);
|
||||
|
||||
//indicates that the value is a multibyte integer that needs to be put in the correct byte order
|
||||
#define FCEUSTATE_RLSB 0x80000000
|
||||
|
||||
//void*v is actually a void** which will be indirected before reading
|
||||
#define FCEUSTATE_INDIRECT 0x40000000
|
||||
|
||||
//all FCEUSTATE flags together so that we can mask them out and get the size
|
||||
#define FCEUSTATE_FLAGS (FCEUSTATE_RLSB|FCEUSTATE_INDIRECT)
|
||||
|
||||
void FCEU_DrawSaveStates(uint8 *XBuf);
|
||||
|
||||
|
|
|
@ -324,7 +324,7 @@ void splitpath(const char* path, char* drv, char* dir, char* name, char* ext)
|
|||
*drv++ = *path++;
|
||||
*drv++ = *path++;
|
||||
*drv = '\0';
|
||||
}
|
||||
} else path+=2;
|
||||
} else if (drv)
|
||||
*drv = '\0';
|
||||
|
||||
|
@ -342,6 +342,8 @@ void splitpath(const char* path, char* drv, char* dir, char* name, char* ext)
|
|||
if (ext)
|
||||
for(s=end; (*ext=*s++); )
|
||||
ext++;
|
||||
else
|
||||
for(s=end; *s++; )
|
||||
|
||||
/* search for end of directory name */
|
||||
for(p=end; p>path; )
|
||||
|
@ -355,7 +357,9 @@ void splitpath(const char* path, char* drv, char* dir, char* name, char* ext)
|
|||
*name++ = *s++;
|
||||
|
||||
*name = '\0';
|
||||
}
|
||||
} else
|
||||
for(s=p; s<end; )
|
||||
*s++;
|
||||
|
||||
if (dir) {
|
||||
for(s=path; s<p; )
|
||||
|
|
Loading…
Reference in New Issue