#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"
-extern uint8 *SRAM;
+#define dprintf(...) /* disabled */
#ifdef ZSNES_FX
START_EXTERN_C
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);
}
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));
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()
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;
ICPU.ShiftedDB = Registers.DB << 16;
S9xSetPCBase (ICPU.ShiftedPB + Registers.PC);
-
-
- //S9xUnpackStatus (); // not needed
- //S9xFixCycles (); // also not needed?
+
+#if !CONF_BUILD_ASM_CPU
+ S9xUnpackStatus ();
+ S9xFixCycles ();
+#endif
+
S9xReschedule ();
#ifdef ZSNES_FX
if (Settings.SuperFX)
return (SUCCESS);
}
-int FreezeSize (int size, int type)
+static int FreezeSize (int size, int type)
{
switch (type)
{
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;
FreezeBlock (name, block, len);
- free(block);
+ delete[] block;
}
void FreezeBlock (const char *name, uint8 *block, int size)
fields [i].type);
}
- uint8 *block = (uint8*)malloc(len);
+ uint8 *block = new uint8 [len];
uint8 *ptr = block;
uint16 word;
uint32 dword;
if ((result = UnfreezeBlock (name, block, len)) != SUCCESS)
{
- free(block);
+ delete[] block;
return (result);
}
}
}
-// delete block;
- free(block);
+ delete[] block;
+
return (result);
}
strncmp (buffer, name, 3) != 0 || buffer [3] != ':' ||
(len = atoi (&buffer [4])) == 0)
{
- printf("%s: %s: Invalid block header\n", __func__, name);
+ dprintf("%s: %s: Invalid block header\n", __func__, name);
return WRONG_FORMAT;
}
if (READ_STREAM(block, len, ss_st) != len)
{
- printf("%s: Invalid block\n", __func__);
+ dprintf("%s: Invalid block\n", __func__);
return WRONG_FORMAT;
}
if (rem)
{
- char *junk = (char*)malloc(rem);
+ char *junk = new char [rem];
READ_STREAM(junk, rem, ss_st);
- free(junk);
+ delete[] junk;
}
return SUCCESS;