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 else
{ {
bool written = emulator.emuWriteMemState((char *)savebuffer, SAVEBUFFERSIZE); datasize = 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
}
} }
// write savebuffer into file // write savebuffer into file

View File

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

View File

@ -163,7 +163,7 @@ void utilWriteData(gzFile gzFile, variable_desc *data)
gzFile utilGzOpen(const char *file, const char *mode) 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; utilGzReadFunc = gzread;
utilGzCloseFunc = gzclose; utilGzCloseFunc = gzclose;
utilGzSeekFunc = gzseek; 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 /* gzio.c -- IO on .gz files
* Copyright (C) 1995-2002 Jean-loup Gailly. * Copyright (C) 1995-2002 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
@ -8,27 +11,13 @@
/* memgzio.c - IO on .gz files in memory /* memgzio.c - IO on .gz files in memory
* Adapted from original gzio.c from zlib library by Forgotten * Adapted from original gzio.c from zlib library by Forgotten
*/ */
#ifndef HAVE_ZUTIL_H
#include "../win32/include/zlib/zutil.h"
#else
#include <zlib.h> #include <zlib.h>
#endif
#ifndef local gzFile ZEXPORT memgzopen(char *memory, int available, const char *mode);
# define local static int ZEXPORT memgzread(gzFile file, voidp buf, unsigned len);
#endif 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 #endif // MEMGZIO_H
# 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);

View File

@ -3550,24 +3550,23 @@ static bool gbWriteSaveState(gzFile gzFile)
return true; 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) { if(gzFile == NULL)
return false; return 0;
}
bool res = gbWriteSaveState(gzFile); if(gbWriteSaveState(gzFile))
{
long pos = utilGzMemTell(gzFile)+8; pos = utilGzMemTell(gzFile)+8;
if(pos >= (available)) if(pos >= (available))
res = false; pos = 0;
}
utilGzClose(gzFile); utilGzClose(gzFile);
return pos;
return res;
} }
bool gbWriteSaveState(const char *name) bool gbWriteSaveState(const char *name)

View File

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

View File

@ -634,24 +634,23 @@ bool CPUWriteState(const char *file)
return res; 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) { if(gzFile == NULL)
return false; return 0;
}
bool res = CPUWriteState(gzFile); if(CPUWriteState(gzFile))
{
long pos = utilGzMemTell(gzFile)+8; pos = utilGzMemTell(gzFile)+8;
if(pos >= (available)) if(pos >= (available))
res = false; pos = 0;
}
utilGzClose(gzFile); utilGzClose(gzFile);
return pos;
return res;
} }
static bool CPUReadState(gzFile gzFile) static bool CPUReadState(gzFile gzFile)

View File

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