changes for save states. although there's still save corruption :(

This commit is contained in:
dborth 2009-12-02 22:26:44 +00:00
parent a7b1ba9ae3
commit 6bb71834d3
9 changed files with 417 additions and 517 deletions

View File

@ -394,42 +394,7 @@ bool SaveBatteryOrState(char * filepath, int action, bool silent)
}
else
{
bool written = emulator.emuWriteMemState((char *)savebuffer, SAVEBUFFERSIZE);
// we need to set datasize to the exact memory size written
// but emuWriteMemState doesn't return that for us
// so instead we'll find the end of the save the old fashioned way
if(written)
{
datasize = (1024*192); // we'll start at 192K - no save should be larger
char check = savebuffer[datasize];
while(check == 0)
{
datasize -= 16384;
check = savebuffer[datasize];
}
datasize += 16384;
check = savebuffer[datasize];
while(check == 0)
{
datasize -= 1024;
check = savebuffer[datasize];
}
datasize += 1024;
check = savebuffer[datasize];
while(check == 0)
{
datasize -= 64;
check = savebuffer[datasize];
}
datasize += 64;
check = savebuffer[datasize];
while(check == 0)
{
datasize -= 1;
check = savebuffer[datasize];
}
datasize += 2; // include last byte AND a null byte
}
datasize = emulator.emuWriteMemState((char *)savebuffer, SAVEBUFFERSIZE);
}
// write savebuffer into file

View File

@ -25,7 +25,7 @@ struct EmulatedSystem {
// load memory state (rewind)
bool (*emuReadMemState)(char *, int);
// write memory state (rewind)
bool (*emuWriteMemState)(char *, int);
int (*emuWriteMemState)(char *, int);
// write PNG file
bool (*emuWritePNG)(const char *);
// write BMP file

View File

@ -163,7 +163,7 @@ void utilWriteData(gzFile gzFile, variable_desc *data)
gzFile utilGzOpen(const char *file, const char *mode)
{
utilGzWriteFunc = (int (*)(void *,void * const, unsigned int))gzwrite;
utilGzWriteFunc = (int (ZEXPORT *)(void *,void * const, unsigned int))gzwrite;
utilGzReadFunc = gzread;
utilGzCloseFunc = gzclose;
utilGzSeekFunc = gzseek;

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,6 @@
#ifndef MEMGZIO_H
#define MEMGZIO_H
/* gzio.c -- IO on .gz files
* Copyright (C) 1995-2002 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
@ -8,27 +11,13 @@
/* memgzio.c - IO on .gz files in memory
* Adapted from original gzio.c from zlib library by Forgotten
*/
#ifndef HAVE_ZUTIL_H
#include "../win32/include/zlib/zutil.h"
#else
#include <zlib.h>
#endif
#ifndef local
# define local static
#endif
gzFile ZEXPORT memgzopen(char *memory, int available, const char *mode);
int ZEXPORT memgzread(gzFile file, voidp buf, unsigned len);
int ZEXPORT memgzwrite(gzFile file, const voidp buf, unsigned len);
int ZEXPORT memgzclose(gzFile file);
long ZEXPORT memtell(gzFile file);
#if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
#else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
#endif
#define OS_CODE 0x03 /* assume Unix */
#define zmemcpy memcpy
gzFile ZEXPORT memgzopen(char *memory, int, const char *);
int ZEXPORT memgzread(gzFile, voidp, unsigned);
int ZEXPORT memgzwrite(gzFile, const voidp, unsigned);
int ZEXPORT memgzclose(gzFile);
long ZEXPORT memtell(gzFile);
#endif // MEMGZIO_H

View File

@ -3550,24 +3550,23 @@ static bool gbWriteSaveState(gzFile gzFile)
return true;
}
bool gbWriteMemSaveState(char *memory, int available)
int gbWriteMemSaveState(char *memory, int available)
{
gzFile gzFile = utilMemGzOpen(memory, available, "w");
int pos = 0;
gzFile gzFile = utilMemGzOpen(memory, available, "w");
if(gzFile == NULL) {
return false;
}
if(gzFile == NULL)
return 0;
bool res = gbWriteSaveState(gzFile);
long pos = utilGzMemTell(gzFile)+8;
if(pos >= (available))
res = false;
utilGzClose(gzFile);
return res;
if(gbWriteSaveState(gzFile))
{
pos = utilGzMemTell(gzFile)+8;
if(pos >= (available))
pos = 0;
}
utilGzClose(gzFile);
return pos;
}
bool gbWriteSaveState(const char *name)

View File

@ -30,7 +30,7 @@ bool gbWriteBatteryFile(const char *);
bool gbWriteBatteryFile(const char *, bool);
bool gbReadBatteryFile(const char *);
bool gbWriteSaveState(const char *);
bool gbWriteMemSaveState(char *, int);
int gbWriteMemSaveState(char *, int);
bool gbReadSaveState(const char *);
bool gbReadMemSaveState(char *, int);
void gbSgbRenderBorder();

View File

@ -634,24 +634,23 @@ bool CPUWriteState(const char *file)
return res;
}
bool CPUWriteMemState(char *memory, int available)
int CPUWriteMemState(char *memory, int available)
{
gzFile gzFile = utilMemGzOpen(memory, available, "w");
int pos = 0;
gzFile gzFile = utilMemGzOpen(memory, available, "w");
if(gzFile == NULL) {
return false;
}
if(gzFile == NULL)
return 0;
bool res = CPUWriteState(gzFile);
long pos = utilGzMemTell(gzFile)+8;
if(pos >= (available))
res = false;
utilGzClose(gzFile);
return res;
if(CPUWriteState(gzFile))
{
pos = utilGzMemTell(gzFile)+8;
if(pos >= (available))
pos = 0;
}
utilGzClose(gzFile);
return pos;
}
static bool CPUReadState(gzFile gzFile)

View File

@ -90,7 +90,7 @@ extern void CPUUpdateRender();
extern void CPUUpdateRenderBuffers(bool);
extern bool CPUReadMemState(char *, int);
extern bool CPUReadState(const char *);
extern bool CPUWriteMemState(char *, int);
extern int CPUWriteMemState(char *, int);
extern bool CPUWriteState(const char *);
extern int CPULoadRom(const char *);
extern void doMirroring(bool);