add multitouch fixes
[drnoksnes] / snapshot.cpp
index 478a400..7e259bf 100644 (file)
 #include <ctype.h>
 #include <stdlib.h>
 
-#if defined(__unix) || defined(__linux) || defined(__sun) || defined(__DJGPP)
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#endif
-
 #include "snapshot.h"
 #include "memmap.h"
 #include "snes9x.h"
 #include "65c816.h"
 #include "ppu.h"
 #include "cpuexec.h"
-#include "display.h"
 #include "apu.h"
 #include "soundux.h"
 #ifdef USE_SA1
 #endif
 #include "srtc.h"
 #include "sdd1.h"
+#include "screenshot.h"
 
 #define dprintf(...) /* disabled */
 
-extern uint8 *SRAM;
-
 #ifdef ZSNES_FX
 START_EXTERN_C
 void S9xSuperFXPreSaveState ();
@@ -399,6 +391,7 @@ static STREAM ss_st;
 
 static void Freeze ();
 static int Unfreeze ();
+
 static void FreezeStruct (const char *name, void *base, FreezeData *fields,
                   int num_fields);
 static void FreezeBlock (const char *name, uint8 *block, int size);
@@ -473,7 +466,7 @@ static void Freeze ()
     }
     sprintf (buffer, "%s:%04d\n", SNAPSHOT_MAGIC, SNAPSHOT_VERSION);
     WRITE_STREAM(buffer, strlen(buffer), ss_st);
-    sprintf (buffer, "NAM:%06d:%s%c", strlen (Memory.ROMFilename) + 1,
+    sprintf (buffer, "NAM:%06zu:%s%c", strlen(Memory.ROMFilename) + 1,
             Memory.ROMFilename, 0);
     WRITE_STREAM(buffer, strlen(buffer) + 1, ss_st);
     FreezeStruct ("CPU", &CPU, SnapCPU, COUNT (SnapCPU));
@@ -519,6 +512,15 @@ static void Freeze ()
     if (Settings.SuperFX)
        S9xSuperFXPostSaveState ();
 #endif
+#ifdef CONF_PNG
+       /* Save a PNG screenshot for convenience. */
+       size_t png_size;
+       uint8 *png = (uint8*) S9xScreenshot(&png_size);
+       if (png) {
+               FreezeBlock("PNG", png, png_size);
+               free(png);
+       }
+#endif
 }
 
 static int Unfreeze()
@@ -646,16 +648,16 @@ static int Unfreeze()
        S9xSetSoundMute (TRUE);
     }
 #ifdef USE_SA1
-    if ((result = UnfreezeStruct ("SA1", &SA1, SnapSA1, 
+       if ((result = UnfreezeStruct ("SA1", &SA1, SnapSA1,
                                  COUNT(SnapSA1))) == SUCCESS)
-    {
-       if ((result = UnfreezeStruct ("SAR", &SA1Registers, 
-                                     SnapSA1Registers, COUNT (SnapSA1Registers))) != SUCCESS)
-           return (result);
+       {
+               if ((result = UnfreezeStruct ("SAR", &SA1Registers,
+                                               SnapSA1Registers, COUNT (SnapSA1Registers))) != SUCCESS)
+                       return result;
 
-       S9xFixSA1AfterSnapshotLoad ();
-       SA1.Flags |= sa1_old_flags & (TRACE_FLAG);
-    }
+               S9xFixSA1AfterSnapshotLoad ();
+               SA1.Flags |= sa1_old_flags & (TRACE_FLAG);
+       }
 #endif
     S9xFixSoundAfterSnapshotLoad ();
     ICPU.ShiftedPB = Registers.PB << 16;
@@ -679,7 +681,7 @@ static int Unfreeze()
     return (SUCCESS);
 }
 
-int FreezeSize (int size, int type)
+static int FreezeSize (int size, int type)
 {
     switch (type)
     {
@@ -708,8 +710,7 @@ void FreezeStruct(const char *name, void *base, FreezeData *fields,
                                                  fields [i].type);
     }
 
-//    uint8 *block = new uint8 [len];
-    uint8 *block = (uint8*)malloc(len);
+    uint8 *block = new uint8[len];
     uint8 *ptr = block;
     uint16 word;
     uint32 dword;
@@ -778,7 +779,7 @@ void FreezeStruct(const char *name, void *base, FreezeData *fields,
 
     FreezeBlock (name, block, len);
 
-       free(block);
+    delete[] block;
 }
 
 void FreezeBlock (const char *name, uint8 *block, int size)
@@ -805,7 +806,7 @@ int UnfreezeStruct (const char *name, void *base, FreezeData *fields,
                                                  fields [i].type);
     }
 
-       uint8 *block = (uint8*)malloc(len);
+       uint8 *block = new uint8 [len];
     uint8 *ptr = block;
     uint16 word;
     uint32 dword;
@@ -814,7 +815,7 @@ int UnfreezeStruct (const char *name, void *base, FreezeData *fields,
 
     if ((result = UnfreezeBlock (name, block, len)) != SUCCESS)
     {
-       free(block);
+       delete[] block;
        return (result);
     }
 
@@ -879,8 +880,8 @@ int UnfreezeStruct (const char *name, void *base, FreezeData *fields,
        }
     }
 
-//    delete block;
-       free(block);
+    delete[] block;
+
     return (result);
 }
 
@@ -912,9 +913,9 @@ int UnfreezeBlock(const char *name, uint8 *block, int size)
        
     if (rem)
     {
-               char *junk = (char*)malloc(rem);
+               char *junk = new char [rem];
                READ_STREAM(junk, rem, ss_st);
-               free(junk);
+               delete[] junk;
     }
 
     return SUCCESS;