fix sdl savestates?

This commit is contained in:
zeromus 2008-06-06 06:34:39 +00:00
parent d40ffb715c
commit 2a190f3c74
7 changed files with 63 additions and 42 deletions

View File

@ -32,6 +32,7 @@
#include "gui.h" #include "gui.h"
#include "fceu.h" #include "fceu.h"
#include "movie.h" #include "movie.h"
#include "window.h"
#include "keyscan.h" #include "keyscan.h"
@ -336,7 +337,6 @@ static uint8 fkbkeys[0x48];
static uint8 suborkbkeys[0x60]; static uint8 suborkbkeys[0x60];
void KeyboardUpdateState(void); //mbg merge 7/17/06 yech had to add this 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() void FCEUD_UpdateInput()
{ {

View File

@ -502,11 +502,6 @@ void win_AllocBuffers(uint8 **GameMemBlock, uint8 **RAM)
*RAM = (uint8 *)MapViewOfFile(mapRAM, FILE_MAP_WRITE, 0, 0, 0); *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 //Bot input
// qfox: tossed mapping alltogether // qfox: tossed mapping alltogether
//mapBotInput = CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE,0, BOT_MAXFRAMES*sizeof(int), "fceu.BotInput"); //mapBotInput = CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE,0, BOT_MAXFRAMES*sizeof(int), "fceu.BotInput");

View File

@ -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) if(FCEUMOV_Mode() == MOVIEMODE_PLAY)
{ {

View File

@ -28,5 +28,6 @@ void LoadNewGamey(HWND hParent, const char *initialdir);
int BrowseForFolder(HWND hParent, const char *htext, char *buf); int BrowseForFolder(HWND hParent, const char *htext, char *buf);
void UpdateCheckedMenuItems(); void UpdateCheckedMenuItems();
void SetMainWindowStuff(); void SetMainWindowStuff();
void GetMouseData(uint32 (&md)[3]);
#endif #endif

View File

@ -36,6 +36,7 @@
#include "utils/endian.h" #include "utils/endian.h"
#include "utils/memory.h" #include "utils/memory.h"
#include "utils/memorystream.h" #include "utils/memorystream.h"
#include "utils/xstring.h"
#include "file.h" #include "file.h"
#include "fds.h" #include "fds.h"
#include "state.h" #include "state.h"
@ -72,11 +73,7 @@ SFORMAT SFCPU[]={
{ &X.X, 1, "X\0\0"}, { &X.X, 1, "X\0\0"},
{ &X.Y, 1, "Y\0\0"}, { &X.Y, 1, "Y\0\0"},
{ &X.S, 1, "S\0\0"}, { &X.S, 1, "S\0\0"},
#ifdef _USE_SHARED_MEMORY_ { &RAM, 0x800 | FCEUSTATE_INDIRECT, "RAM", },
{ NULL, 0x800, "RAM"}, //will be initialized later after getting a pointer to RAM
#else
{ RAM, 0x800, "RAM"},
#endif
{ 0 } { 0 }
}; };
@ -96,7 +93,7 @@ static int SubWrite(std::ostream* os, SFORMAT *sf)
while(sf->v) while(sf->v)
{ {
if(sf->s==~0) /* Link to another struct. */ if(sf->s==~0) //Link to another struct
{ {
uint32 tmp; uint32 tmp;
@ -107,24 +104,28 @@ static int SubWrite(std::ostream* os, SFORMAT *sf)
continue; continue;
} }
acc+=8; /* Description + size */ acc+=8; //Description + size
acc+=sf->s&(~RLSB); 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); os->write(sf->desc,4);
write32le(sf->s&(~RLSB),os); write32le(sf->s&(~FCEUSTATE_FLAGS),os);
#ifndef LSB_FIRST #ifndef LSB_FIRST
if(sf->s&RLSB) if(sf->s&RLSB)
FlipByteOrder(sf->v,sf->s&(~RLSB)); FlipByteOrder(sf->v,sf->s&(~FCEUSTATE_FLAGS));
#endif #endif
os->write((char*)sf->v,sf->s&(~RLSB)); if(sf->s&FCEUSTATE_INDIRECT)
/* Now restore the original byte order. */ 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 #ifndef LSB_FIRST
if(sf->s&RLSB) if(sf->s&RLSB)
FlipByteOrder(sf->v,sf->s&(~RLSB)); FlipByteOrder(sf->v,sf->s&(~FCEUSTATE_FLAGS));
#endif #endif
} }
sf++; sf++;
@ -139,7 +140,7 @@ static int SubWrite(FILE *st, SFORMAT *sf)
while(sf->v) while(sf->v)
{ {
if(sf->s==~0) /* Link to another struct. */ if(sf->s==~0) //Link to another struct
{ {
uint32 tmp; uint32 tmp;
@ -150,24 +151,24 @@ static int SubWrite(FILE *st, SFORMAT *sf)
continue; continue;
} }
acc+=8; /* Description + size */ acc+=8; //Description + size
acc+=sf->s&(~RLSB); 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); fwrite(sf->desc,1,4,st);
write32le(sf->s&(~RLSB),st); write32le(sf->s&(~FCEUSTATE_FLAGS),st);
#ifndef LSB_FIRST #ifndef LSB_FIRST
if(sf->s&RLSB) if(sf->s&RLSB)
FlipByteOrder(sf->v,sf->s&(~RLSB)); FlipByteOrder(sf->v,sf->s&(~FCEUSTATE_FLAGS));
#endif #endif
fwrite((uint8 *)sf->v,1,sf->s&(~RLSB),st); fwrite((uint8 *)sf->v,1,sf->s&(~FCEUSTATE_FLAGS),st);
/* Now restore the original byte order. */ //Now restore the original byte order.
#ifndef LSB_FIRST #ifndef LSB_FIRST
if(sf->s&RLSB) if(sf->s&RLSB)
FlipByteOrder(sf->v,sf->s&(~RLSB)); FlipByteOrder(sf->v,sf->s&(~FCEUSTATE_FLAGS));
#endif #endif
} }
sf++; sf++;
@ -219,7 +220,7 @@ static SFORMAT *CheckS(SFORMAT *sf, uint32 tsize, char *desc)
} }
if(!memcmp(desc,sf->desc,4)) if(!memcmp(desc,sf->desc,4))
{ {
if(tsize!=(sf->s&(~RLSB))) if(tsize!=(sf->s&(~FCEUSTATE_FLAGS)))
return(0); return(0);
return(sf); return(sf);
} }
@ -251,11 +252,14 @@ static int ReadStateChunk(FILE *st, SFORMAT *sf, int size)
if((tmp=CheckS(sf,tsize,toa))) 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 #ifndef LSB_FIRST
if(tmp->s&RLSB) if(tmp->s&RLSB)
FlipByteOrder(tmp->v,tmp->s&(~RLSB)); FlipByteOrder(tmp->v,tmp->s&(~FCEUSTATE_FLAGS));
#endif #endif
} }
else else
@ -485,7 +489,7 @@ void FCEUSS_Save(char *fname)
return; return;
} }
FCEUSS_SaveFP(st,-1); FCEUSS_SaveFP(st,0);
fclose(st); fclose(st);
@ -770,7 +774,13 @@ int FCEUSS_Load(char *fname)
//states are being loaded. //states are being loaded.
if(FCEUSS_LoadFP(st,FCEU_BotMode()?SSLOADPARAM_NOBACKUP:SSLOADPARAM_BACKUP)) 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:) //This looks redudant to me... but why bother deleting it:)
SaveStateStatus[CurrentState]=1; SaveStateStatus[CurrentState]=1;

View File

@ -39,18 +39,29 @@ bool FCEUSS_LoadFP(FILE *, ENUM_SSLOADPARAMS);
extern int CurrentState; extern int CurrentState;
void FCEUSS_CheckStates(void); void FCEUSS_CheckStates(void);
typedef struct { struct SFORMAT
void *v; {
uint32 s; //a void* to the data or a void** to the data
char *desc; void *v;
} SFORMAT;
//size, plus flags
uint32 s;
//a string description of the element
char *desc;
};
void ResetExState(void (*PreSave)(void),void (*PostSave)(void)); void ResetExState(void (*PreSave)(void),void (*PostSave)(void));
void AddExState(void *v, uint32 s, int type, char *desc); 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 #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); void FCEU_DrawSaveStates(uint8 *XBuf);

View File

@ -324,7 +324,7 @@ void splitpath(const char* path, char* drv, char* dir, char* name, char* ext)
*drv++ = *path++; *drv++ = *path++;
*drv++ = *path++; *drv++ = *path++;
*drv = '\0'; *drv = '\0';
} } else path+=2;
} else if (drv) } else if (drv)
*drv = '\0'; *drv = '\0';
@ -342,6 +342,8 @@ void splitpath(const char* path, char* drv, char* dir, char* name, char* ext)
if (ext) if (ext)
for(s=end; (*ext=*s++); ) for(s=end; (*ext=*s++); )
ext++; ext++;
else
for(s=end; *s++; )
/* search for end of directory name */ /* search for end of directory name */
for(p=end; p>path; ) 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++ = *s++;
*name = '\0'; *name = '\0';
} } else
for(s=p; s<end; )
*s++;
if (dir) { if (dir) {
for(s=path; s<p; ) for(s=path; s<p; )