workaround a problem with the harmattan gcc
[drnoksnes] / snapshot.cpp
index b968a09..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"
 #endif
 #include "srtc.h"
 #include "sdd1.h"
+#include "screenshot.h"
 
 #define dprintf(...) /* disabled */
 
-extern uint8 *SRAM;
-
 #ifdef ZSNES_FX
 START_EXTERN_C
 void S9xSuperFXPreSaveState ();
@@ -398,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);
@@ -518,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()
@@ -678,7 +681,7 @@ static int Unfreeze()
     return (SUCCESS);
 }
 
-int FreezeSize (int size, int type)
+static int FreezeSize (int size, int type)
 {
     switch (type)
     {
@@ -707,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;
@@ -777,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)
@@ -804,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;
@@ -813,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);
     }
 
@@ -878,8 +880,8 @@ int UnfreezeStruct (const char *name, void *base, FreezeData *fields,
        }
     }
 
-//    delete block;
-       free(block);
+    delete[] block;
+
     return (result);
 }
 
@@ -911,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;