27 static const Uint8 ep128emu_snapshot_marker[] = {
28 0x5D, 0x12, 0xE4, 0xF4, 0xC9, 0xDA, 0xB6, 0x42, 0x01, 0x33, 0xDE, 0x07, 0xD2, 0x34, 0xF2, 0x22
41 static const char *block_names[
BLOCK_TYPES] = {
"Z80",
"MEM",
"IO",
"DAVE",
"NICK",
"MACHINE" };
43 static const Uint32 block_types[
BLOCK_TYPES] = { 0x45508001, 0x45508002, 0x45508003, 0x45508004, 0x45508005, 0x45508009 };
44 static const int block_versions[
BLOCK_TYPES] = { 0x1000002, 0x1000000, 0x1000000, 0x1000000, 0x4000000, -1 };
48 static Uint8 *snap = NULL;
69 char pathbuffer[PATH_MAX + 1];
75 if (fseek(f, 0, SEEK_END)) {
76 ERROR_WINDOW(
"Cannot seek snapshot file: %s", pathbuffer);
81 if (snapsize < 16 || snapsize >= 0x500000) {
82 ERROR_WINDOW(
"Too short or long snapshot file: %s", pathbuffer);
86 snap = malloc(snapsize);
91 if (fread(snap, snapsize, 1, f) != 1) {
97 if (memcmp(snap, ep128emu_snapshot_marker,
sizeof ep128emu_snapshot_marker)) {
98 ERROR_WINDOW(
"Invalid ep128emu snapshot (identifier not found)");
102 block_offsets[pos] = 0;
107 if (pos + 8 >= snapsize) {
108 ERROR_WINDOW(
"Invalid snapshot file: truncated (during block header)");
111 btype = getSnapDword(snap, pos);
114 bsize = getSnapDword(snap, pos + 4);
116 if (pos + bsize + 4 >= snapsize) {
117 ERROR_WINDOW(
"Invalid snapshot file: truncated (during block data)");
120 for (bindex = 0 ;; bindex++)
122 ERROR_WINDOW(
"Invalid snapshot file: Unknown block type: %Xh", btype);
124 }
else if (btype == block_types[bindex])
126 if (block_offsets[bindex]) {
127 ERROR_WINDOW(
"Invalid snapshot file: duplicated block %Xh", block_types[bindex]);
130 if (block_versions[bindex] != -1) {
131 Uint32 bver = getSnapDword(snap, pos);
132 if (bver != block_versions[bindex]) {
133 ERROR_WINDOW(
"Invalid snapshot file: bad block version %Xh (should be %Xh) for block %Xh",
134 bver, block_versions[bindex], block_types[bindex]
141 block_offsets[bindex] = pos;
142 block_sizes[bindex] = bsize;
143 DEBUG(
"SNAPSHOT: block #%d %Xh(%s) @%06Xh" NL, bindex, block_types[bindex], block_names[bindex], block_offsets[bindex]);
148 if (block_versions[pos] != -1 && !block_offsets[pos]) {
149 ERROR_WINDOW(
"Invalid snapshot file: missing block %Xh", block_types[pos]);
153 if ((block_sizes[
BLOCK_MEM] - 4) % 0x4002) {
154 ERROR_WINDOW(
"Invalid snapshot file: memory dump size is not multiple of 16Ks");
163 memset(
memory, 0xFF, 0x400000);
164 for (pos = 0; pos < 0x100; pos++) {
172 if (snap[pos] < 0xFC)
178 memcpy(
memory + (snap[pos] << 14), snap + pos + 2, 0x4000);
197 Z80_PC = getSnapWord(snap, pos);
203 Z80_SP = getSnapWord(snap, pos + 10);
210 Z80_I = snap[pos + 24];
211 Z80_R = snap[pos + 25] & 127;
215 Z80_R7 = snap[pos + 32] & 128;
218 for (pos = 0; pos < 256; pos++)
219 ports[pos] = snap[block_offsets[
BLOCK_IO] + pos];
220 for (pos = 0xA0; pos <= 0xBF; pos++)
222 for (pos = 0; pos < 4; pos++) {