determine correct size for snapshot files

This commit is contained in:
dborth 2008-11-01 07:31:24 +00:00
parent 0b4ca7509f
commit 146e2f111f
2 changed files with 34 additions and 18 deletions

View File

@ -247,17 +247,6 @@ int MemCPUWriteBatteryFile(char * membuffer)
return result; return result;
} }
/****************************************************************************
* SetFileBytesWritten
* Sets the # of bytes written into a file
* Used by GBA.cpp and GB.cpp
****************************************************************************/
void SetFileBytesWritten(int bytes)
{
//datasize = bytes;
}
/**************************************************************************** /****************************************************************************
* LoadBatteryOrState * LoadBatteryOrState
* Load Battery/State file into memory * Load Battery/State file into memory
@ -416,10 +405,41 @@ bool SaveBatteryOrState(int method, int action, bool silent)
else else
{ {
bool written = emulator.emuWriteMemState((char *)savebuffer+offset, SAVEBUFFERSIZE-offset); bool written = emulator.emuWriteMemState((char *)savebuffer+offset, SAVEBUFFERSIZE-offset);
// we really should set datasize to the exact memory size written // we need to set datasize to the exact memory size written
// but instead we'll set it at 192K - although much of it will go unused // but emuWriteMemState doesn't return that for us
// so instead we'll find the end of the save the old fashioned way
if(written) if(written)
datasize = (1024*192); {
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

@ -652,8 +652,6 @@ bool CPUWriteState(const char *file)
return res; return res;
} }
extern void SetFileBytesWritten(int bytes); // Tantric - Wii/GameCube addition - store # bytes written
bool CPUWriteMemState(char *memory, int available) bool CPUWriteMemState(char *memory, int available)
{ {
gzFile gzFile = utilMemGzOpen(memory, available, "w"); gzFile gzFile = utilMemGzOpen(memory, available, "w");
@ -669,8 +667,6 @@ bool CPUWriteMemState(char *memory, int available)
if(pos >= (available)) if(pos >= (available))
res = false; res = false;
SetFileBytesWritten((int)pos); // Tantric - Wii/GameCube addition - store # bytes written
utilGzClose(gzFile); utilGzClose(gzFile);
return res; return res;