X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=snapshot.cpp;h=7e259bf5979c48bf299bf75b3ea39d4f9d5cf312;hb=refs%2Fheads%2Fmaster;hp=94ae8d02af259f47495b0022b8820742c1514a39;hpb=c4ad928fce260890f56e1360b2a2aa3fe84213bd;p=drnoksnes diff --git a/snapshot.cpp b/snapshot.cpp index 94ae8d0..7e259bf 100644 --- a/snapshot.cpp +++ b/snapshot.cpp @@ -43,19 +43,12 @@ #include #include -#if defined(__unix) || defined(__linux) || defined(__sun) || defined(__DJGPP) -#include -#include -#include -#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 @@ -63,11 +56,10 @@ #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() @@ -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;