summaryrefslogtreecommitdiff
path: root/source/snapshot.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/snapshot.c')
-rw-r--r--source/snapshot.c51
1 files changed, 35 insertions, 16 deletions
diff --git a/source/snapshot.c b/source/snapshot.c
index 14f0e30..1d5aa37 100644
--- a/source/snapshot.c
+++ b/source/snapshot.c
@@ -28,6 +28,7 @@
#include <ctype.h>
#include <nds.h>
+#include "snapshot.h"
#include "zx81.h"
#include "gui.h"
@@ -47,12 +48,13 @@
/* ---------------------------------------- STATICS
*/
static int enabled;
-static const char *magic = "V00_DS81";
+static const char *magic = "V01_DS81";
+static const char *extension[2] = {".D81", ".K81"};
/* ---------------------------------------- PRIVATE FUNCTIONS
*/
-static void WriteMagic(FILE *fp)
+static void WriteMagic(FILE *fp, SnapshotType t)
{
const char *p = magic;
@@ -60,9 +62,11 @@ static void WriteMagic(FILE *fp)
{
fputc(*p++, fp);
}
+
+ fputc(t, fp);
}
-static int CheckMagic(FILE *fp)
+static int CheckMagic(FILE *fp, SnapshotType t)
{
const char *p = magic;
@@ -74,7 +78,7 @@ static int CheckMagic(FILE *fp)
}
}
- return TRUE;
+ return (fgetc(fp) == t);
}
@@ -85,7 +89,7 @@ void SNAP_Enable(int enable)
enabled = enable;
}
-void SNAP_Save(Z80 *cpu)
+void SNAP_Save(Z80 *cpu, SnapshotType type)
{
char base[FILENAME_MAX] = "";
char file[FILENAME_MAX];
@@ -96,12 +100,13 @@ void SNAP_Save(Z80 *cpu)
return;
}
- if(!GUI_InputName("enter snapshot filename", ".d81", base, 8) || !base[0])
+ if(!GUI_InputName("enter snapshot filename",
+ extension[type], base, 8) || !base[0])
{
return;
}
- strcat(base, ".D81");
+ strcat(base, extension[type]);
strcpy(file, DEFAULT_SNAPDIR);
strcat(file, base);
@@ -115,10 +120,16 @@ void SNAP_Save(Z80 *cpu)
if (fp)
{
- WriteMagic(fp);
+ WriteMagic(fp, type);
+
SK_SaveSnapshot(fp);
- Z80SaveSnapshot(cpu, fp);
- ZX81SaveSnapshot(fp);
+
+ if (type == SNAP_TYPE_FULL)
+ {
+ Z80SaveSnapshot(cpu, fp);
+ ZX81SaveSnapshot(fp);
+ }
+
fclose(fp);
}
else
@@ -127,7 +138,7 @@ void SNAP_Save(Z80 *cpu)
}
}
-void SNAP_Load(Z80 *cpu, const char *optional_name)
+void SNAP_Load(Z80 *cpu, const char *optional_name, SnapshotType type)
{
static char last_dir[FILENAME_MAX] = "/";
char file[FILENAME_MAX];
@@ -142,17 +153,21 @@ void SNAP_Load(Z80 *cpu, const char *optional_name)
{
strcpy(file, DEFAULT_SNAPDIR);
strcat(file, optional_name);
+ strcat(file, extension[type]);
fp = fopen(file, "rb");
if (!fp)
{
- fp = fopen(optional_name, "rb");
+ strcpy(file, optional_name);
+ strcat(file, extension[type]);
+
+ fp = fopen(file, "rb");
}
}
else
{
- if (GUI_FileSelect(last_dir, file, ".D81"))
+ if (GUI_FileSelect(last_dir, file, extension[type]))
{
fp = fopen(file, "rb");
}
@@ -160,15 +175,19 @@ void SNAP_Load(Z80 *cpu, const char *optional_name)
if (fp)
{
- if (!CheckMagic(fp))
+ if (!CheckMagic(fp, type))
{
GUI_Alert(FALSE, "Not a valid snapshot");
}
else
{
SK_LoadSnapshot(fp);
- Z80LoadSnapshot(cpu, fp);
- ZX81LoadSnapshot(fp);
+
+ if (type == SNAP_TYPE_FULL)
+ {
+ Z80LoadSnapshot(cpu, fp);
+ ZX81LoadSnapshot(fp);
+ }
}
fclose(fp);