ASFLAGS ?= -march=armv6j -mfpu=vfp -mfloat-abi=softfp
CXXFLAGS ?= $(CFLAGS)
-GAME_VERSION ?= 0.9.3
+GAME_VERSION ?= 0.9.4
export GAME_VERSION
export DESTDIR
"Enable mouse on controller NUM", "NUM"},
{ "superscope", 'e', POPT_ARG_NONE, 0, 12,
"Enable SuperScope", 0},
+ { "snapshot", 'o', POPT_ARG_NONE, 0, 13,
+ "Unfreeze previous game on start and freeze game on exit", 0 },
{ "scancode", '\0', POPT_ARG_INT, 0, 100,
"Scancode to map", "CODE" },
{ "button", '\0', POPT_ARG_STRING, 0, 101,
Settings.SuperScope = TRUE;
Settings.ControllerOption = SNES_SUPERSCOPE;
break;
+ case 13:
+ Config.snapshotLoad = true;
+ Config.snapshotSave = true;
+ break;
case 100:
scancode = atoi(poptGetOptArg(optCon));
break;
hgwLaunched = true;
HgwStartCommand cmd = hgw_context_get_start_command(hgw);
- // TODO Handle cmd in some way other than assuming HGW_COMM_RESTART
-
+
+ switch (cmd) {
+ default:
+ case HGW_COMM_NONE: // called from libosso
+ case HGW_COMM_CONT:
+ Config.snapshotLoad = true;
+ Config.snapshotSave = true;
+ break;
+ case HGW_COMM_RESTART:
+ Config.snapshotLoad = false;
+ Config.snapshotSave = true;
+ break;
+ case HGW_COMM_QUIT:
+ // hum, what?
+ Config.snapshotLoad = false;
+ Config.snapshotSave = false;
+ Config.quitting = true;
+ break;
+ }
+
printf("Loading in HGW mode\n");
}
void HgwDeinit()
{
if (!hgwLaunched) return;
-
- hgw_context_destroy(hgw, HGW_BYE_INACTIVE); // TODO
+
+ hgw_context_destroy(hgw,
+ (Config.snapshotSave ? HGW_BYE_PAUSED : HGW_BYE_INACTIVE));
+
hgw = 0;
}
break;
}
break;
+ case HGW_MSG_TYPE_DEVSTATE:
+ switch (msg.e_val) {
+ case HGW_DEVICE_STATE_SHUTDOWN:
+ Config.quitting = true; // try to quit gracefully
+ break;
+ }
+ break;
+ default:
+ // do nothing
+ break;
}
hgw_msg_free_data(&msg);
void S9xLoadConfig(int argc, const char ** argv);
void S9xSetRomFile(const char * file);
extern struct config {
- char romFile[PATH_MAX];
- char hacksFile[PATH_MAX];
+ char romFile[PATH_MAX + 1];
+ char hacksFile[PATH_MAX + 1];
+ /** Unfreeze from .frz.gz snapshot on start */
+ bool snapshotLoad;
+ /** Freeze to .frz.gz on exit */
+ bool snapshotSave;
+ /** Create fullscreen surface */
bool fullscreen;
+ /** Using xsp (thus take care of doubling coordinates where appropiate) */
bool xsp;
+ /** Audio output enabled */
bool enableAudio;
unsigned short joypad1Mapping[256];
unsigned char action[256];
#include "memmap.h"
#include "soundux.h"
#include "hacks.h"
+#include "snapshot.h"
#include "hgw.h"
#define kPollEveryNFrames 5 //Poll input only every this many frames
Memory.LoadSRAM(file);
}
+static void resumeGame()
+{
+ if (!Config.snapshotLoad) return;
+
+ const char * file = S9xGetFilename(".frz.gz");
+ int result = S9xUnfreezeGame(file);
+
+ printf("Unfreeze: %s", file);
+
+ if (!result) {
+ printf(" failed");
+ FILE* fp = fopen(file, "rb");
+ if (fp) {
+ if (Config.snapshotSave) {
+ puts(", but the file exists, so I'm not going to overwrite it");
+ Config.snapshotSave = false;
+ } else {
+ puts(" (bad file?)");
+ }
+ fclose(fp);
+ } else {
+ puts(" (file does not exist)");
+ }
+ } else {
+ puts(" ok");
+ }
+}
+
+static void pauseGame()
+{
+ if (!Config.snapshotSave) return;
+
+ const char * file = S9xGetFilename(".frz.gz");
+ int result = S9xFreezeGame(file);
+
+ printf("Freeze: %s", file);
+
+ if (!result) {
+ Config.snapshotSave = false; // Serves as a flag to Hgw
+ puts(" failed");
+ } else {
+ puts(" ok");
+ }
+}
+
/* This comes nearly straight from snes9x */
static void frameSync() {
static struct timeval next1 = {0, 0};
S9xInit();
S9xReset();
- // Load rom and related files: state
+ // Load rom and related files: state, unfreeze if needed
loadRom();
+ resumeGame();
// Late initialization
sprintf(String, "DrNokSnes - %s", Memory.ROMName);
// Save state
Memory.SaveSRAM(S9xGetFilename(".srm"));
+ pauseGame();
// Late deinitialization
S9xGraphicsDeinit();
-int (*statef_open)(const char *fname, const char *mode);
-int (*statef_read)(void *p, int l);
-int (*statef_write)(void *p, int l);
-void (*statef_close)();
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+#include <zlib.h>
+#include "port.h"
+
+static gzFile gfd;
+
+static int zlib_open(const char *fname, const char *mode)
+{
+ gfd = gzopen(fname, mode);
+ if (!gfd) return 0;
+
+ return 1;
+}
+
+static int zlib_read(void *p, int l)
+{
+ return gzread(gfd, p, l);
+}
+
+static int zlib_write(void *p, int l)
+{
+ return gzwrite(gfd, p, l);
+}
+
+static void zlib_close()
+{
+ gzclose(gfd);
+}
+
+int (*statef_open)(const char *fname, const char *mode) = zlib_open;
+int (*statef_read)(void *p, int l) = zlib_read;
+int (*statef_write)(void *p, int l) = zlib_write;
+void (*statef_close)() = zlib_close;
int num_fields);
static int UnfreezeBlock (const char *name, uint8 *block, int size);
-bool8 Snapshot (const char *filename)
-{
- return (S9xFreezeGame (filename));
-}
-
bool8 S9xFreezeGame (const char *filename)
{
if(statef_open(filename, "wb"))
START_EXTERN_C
bool8 S9xFreezeGame (const char *filename);
bool8 S9xUnfreezeGame (const char *filename);
-bool8 Snapshot (const char *filename);
-bool8 S9xLoadSnapshot (const char *filename);
bool8 S9xSPCDump (const char *filename);
END_EXTERN_C