From 146e2f111f896474f875494d0c4910221b1041e9 Mon Sep 17 00:00:00 2001 From: dborth Date: Sat, 1 Nov 2008 07:31:24 +0000 Subject: [PATCH] determine correct size for snapshot files --- source/ngc/vbasupport.cpp | 48 +++++++++++++++++++++++++++------------ source/vba/agb/GBA.cpp | 4 ---- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/source/ngc/vbasupport.cpp b/source/ngc/vbasupport.cpp index 7307858..78dc90e 100644 --- a/source/ngc/vbasupport.cpp +++ b/source/ngc/vbasupport.cpp @@ -247,17 +247,6 @@ int MemCPUWriteBatteryFile(char * membuffer) 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 * Load Battery/State file into memory @@ -416,10 +405,41 @@ bool SaveBatteryOrState(int method, int action, bool silent) else { bool written = emulator.emuWriteMemState((char *)savebuffer+offset, SAVEBUFFERSIZE-offset); - // we really should set datasize to the exact memory size written - // but instead we'll set it at 192K - although much of it will go unused + // 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); + { + 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 diff --git a/source/vba/agb/GBA.cpp b/source/vba/agb/GBA.cpp index e0b12e0..5e5febd 100644 --- a/source/vba/agb/GBA.cpp +++ b/source/vba/agb/GBA.cpp @@ -652,8 +652,6 @@ bool CPUWriteState(const char *file) return res; } -extern void SetFileBytesWritten(int bytes); // Tantric - Wii/GameCube addition - store # bytes written - bool CPUWriteMemState(char *memory, int available) { gzFile gzFile = utilMemGzOpen(memory, available, "w"); @@ -669,8 +667,6 @@ bool CPUWriteMemState(char *memory, int available) if(pos >= (available)) res = false; - SetFileBytesWritten((int)pos); // Tantric - Wii/GameCube addition - store # bytes written - utilGzClose(gzFile); return res;