diff src/gb/GB.cpp @ 76:d7c38ce83421

working on disk-backup for save-states
author Robert McIntyre <rlm@mit.edu>
date Thu, 08 Mar 2012 19:48:54 -0600
parents 4699c7bab77d
children 1ff2c546f5ad
line wrap: on
line diff
     1.1 --- a/src/gb/GB.cpp	Thu Mar 08 06:01:09 2012 -0600
     1.2 +++ b/src/gb/GB.cpp	Thu Mar 08 19:48:54 2012 -0600
     1.3 @@ -2463,14 +2463,16 @@
     1.4  
     1.5  bool gbWriteSaveStateToStream(gzFile gzFile)
     1.6  {
     1.7 +  
     1.8    utilWriteInt(gzFile, GBSAVE_GAME_VERSION);
     1.9  
    1.10 +  
    1.11    utilGzWrite(gzFile, &gbRom[0x134], 15);
    1.12  
    1.13    utilWriteData(gzFile, gbSaveGameStruct);
    1.14 -
    1.15 +  
    1.16    utilGzWrite(gzFile, &IFF, 2);
    1.17 -
    1.18 +  
    1.19    if (gbSgbMode)
    1.20      {
    1.21        gbSgbSaveGame(gzFile);
    1.22 @@ -2549,11 +2551,12 @@
    1.23      utilGzWrite(gzFile, &GBSystemCounters.laggedLast, sizeof(GBSystemCounters.laggedLast));
    1.24    }
    1.25  
    1.26 +  utilWriteInt(gzFile, 0x07); // RLM this is the end of file marker.
    1.27    return true;
    1.28  }
    1.29  
    1.30 -bool gbWriteMemSaveState(char *memory, int available)
    1.31 -{
    1.32 +
    1.33 +long gbWriteMemSaveStatePos(char *memory, int available){
    1.34    gzFile gzFile = utilMemGzOpen(memory, available, "w");
    1.35  
    1.36    if (gzFile == NULL)
    1.37 @@ -2565,12 +2568,21 @@
    1.38  
    1.39    long pos = utilGzTell(gzFile) + 8;
    1.40  
    1.41 -  if (pos >= (available))
    1.42 -    res = false;
    1.43 +  if (pos >= available){
    1.44 +    pos = 0;
    1.45 +  }
    1.46  
    1.47    utilGzClose(gzFile);
    1.48  
    1.49 -  return res;
    1.50 +  return pos;
    1.51 +
    1.52 +}
    1.53 +
    1.54 +bool gbWriteMemSaveState(char *memory, int available)
    1.55 +{
    1.56 +  long pos = gbWriteMemSaveStatePos(memory, available);
    1.57 +  if (pos > 0) { return true; }
    1.58 +  else{ return false; }
    1.59  }
    1.60  
    1.61  bool gbWriteSaveState(const char *name)