Mercurial > repos > blastem
annotate gst.c @ 1116:fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 22 Dec 2016 10:51:33 -0800 |
parents | 7ab7c8fb34ba |
children | e9369d6f0101 |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
451
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
451
diff
changeset
|
2 Copyright 2013 Michael Pavone |
668
5439ae7946ca
Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
3 This file is part of BlastEm. |
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
451
diff
changeset
|
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
451
diff
changeset
|
5 */ |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
6 #include "genesis.h" |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include "gst.h" |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include <string.h> |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
9 #include <stdio.h> |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 #define GST_68K_REGS 0x80 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 #define GST_68K_REG_SIZE (0xDA-GST_68K_REGS) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 #define GST_68K_PC_OFFSET (0xC8-GST_68K_REGS) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 #define GST_68K_SR_OFFSET (0xD0-GST_68K_REGS) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 #define GST_68K_USP_OFFSET (0xD2-GST_68K_REGS) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 #define GST_68K_SSP_OFFSET (0xD6-GST_68K_REGS) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 #define GST_68K_RAM 0x2478 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 #define GST_Z80_REGS 0x404 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 #define GST_Z80_REG_SIZE (0x440-GST_Z80_REGS) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 #define GST_Z80_RAM 0x474 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 #define GST_VDP_REGS 0xFA |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 #define GST_VDP_MEM 0x12478 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 #define GST_YM_OFFSET 0x1E4 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 #define GST_YM_SIZE (0x3E4-GST_YM_OFFSET) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 uint32_t read_le_32(uint8_t * data) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 return data[3] << 24 | data[2] << 16 | data[1] << 8 | data[0]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 uint16_t read_le_16(uint8_t * data) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 return data[1] << 8 | data[0]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 uint16_t read_be_16(uint8_t * data) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 return data[0] << 8 | data[1]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 void write_le_32(uint8_t * dst, uint32_t val) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 dst[0] = val; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 dst[1] = val >> 8; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 dst[2] = val >> 16; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 dst[3] = val >> 24; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 void write_le_16(uint8_t * dst, uint16_t val) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 dst[0] = val; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 dst[1] = val >> 8; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 void write_be_32(uint8_t * dst, uint32_t val) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 dst[0] = val >> 24; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 dst[1] = val >> 16; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 dst[2] = val >> 8; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 dst[3] = val; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 void write_be_16(uint8_t * dst, uint16_t val) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 dst[0] = val >> 8; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 dst[1] = val; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 uint32_t m68k_load_gst(m68k_context * context, FILE * gstfile) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 { |
962
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
71 uint8_t buffer[GST_68K_REG_SIZE]; |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 fseek(gstfile, GST_68K_REGS, SEEK_SET); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 if (fread(buffer, 1, GST_68K_REG_SIZE, gstfile) != GST_68K_REG_SIZE) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 fputs("Failed to read 68K registers from savestate\n", stderr); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 uint8_t * curpos = buffer; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 for (int i = 0; i < 8; i++) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 context->dregs[i] = read_le_32(curpos); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 curpos += sizeof(uint32_t); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 for (int i = 0; i < 8; i++) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 context->aregs[i] = read_le_32(curpos); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 curpos += sizeof(uint32_t); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 uint32_t pc = read_le_32(buffer + GST_68K_PC_OFFSET); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 uint16_t sr = read_le_16(buffer + GST_68K_SR_OFFSET); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 context->status = sr >> 8; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 for (int flag = 4; flag >= 0; flag--) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 context->flags[flag] = sr & 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 sr >>= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 if (context->status & (1 << 5)) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 context->aregs[8] = read_le_32(buffer + GST_68K_USP_OFFSET); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 } else { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 context->aregs[8] = read_le_32(buffer + GST_68K_SSP_OFFSET); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 } |
962
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
98 |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 return pc; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 uint8_t m68k_save_gst(m68k_context * context, uint32_t pc, FILE * gstfile) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 { |
962
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
104 uint8_t buffer[GST_68K_REG_SIZE]; |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 uint8_t * curpos = buffer; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 for (int i = 0; i < 8; i++) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 write_le_32(curpos, context->dregs[i]); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 curpos += sizeof(uint32_t); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 for (int i = 0; i < 8; i++) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 write_le_32(curpos, context->aregs[i]); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 curpos += sizeof(uint32_t); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 write_le_32(buffer + GST_68K_PC_OFFSET, pc); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 uint16_t sr = context->status << 3; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 for (int flag = 4; flag >= 0; flag--) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 sr <<= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 sr |= context->flags[flag]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 write_le_16(buffer + GST_68K_SR_OFFSET, sr); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 if (context->status & (1 << 5)) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 write_le_32(buffer + GST_68K_USP_OFFSET, context->aregs[8]); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 write_le_32(buffer + GST_68K_SSP_OFFSET, context->aregs[7]); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 } else { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 write_le_32(buffer + GST_68K_USP_OFFSET, context->aregs[7]); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 write_le_32(buffer + GST_68K_SSP_OFFSET, context->aregs[8]); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 fseek(gstfile, GST_68K_REGS, SEEK_SET); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 if (fwrite(buffer, 1, GST_68K_REG_SIZE, gstfile) != GST_68K_REG_SIZE) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 fputs("Failed to write 68K registers to savestate\n", stderr); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 return 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 uint8_t z80_load_gst(z80_context * context, FILE * gstfile) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 uint8_t regdata[GST_Z80_REG_SIZE]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 fseek(gstfile, GST_Z80_REGS, SEEK_SET); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 if (fread(regdata, 1, sizeof(regdata), gstfile) != sizeof(regdata)) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 fputs("Failed to read Z80 registers from savestate\n", stderr); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 uint8_t * curpos = regdata; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 uint8_t f = *(curpos++); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 context->flags[ZF_C] = f & 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 f >>= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 context->flags[ZF_N] = f & 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 f >>= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 context->flags[ZF_PV] = f & 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 f >>= 2; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 context->flags[ZF_H] = f & 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 f >>= 2; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 context->flags[ZF_Z] = f & 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 f >>= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 context->flags[ZF_S] = f; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 context->regs[Z80_A] = *curpos; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 curpos += 3; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 for (int reg = Z80_C; reg <= Z80_IYH; reg++) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 context->regs[reg++] = *(curpos++); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 context->regs[reg] = *curpos; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 curpos += 3; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 context->pc = read_le_16(curpos); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 curpos += 4; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 context->sp = read_le_16(curpos); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 curpos += 4; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 f = *(curpos++); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 context->alt_flags[ZF_C] = f & 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 f >>= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 context->alt_flags[ZF_N] = f & 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 f >>= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 context->alt_flags[ZF_PV] = f & 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 f >>= 2; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 context->alt_flags[ZF_H] = f & 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 f >>= 2; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 context->alt_flags[ZF_Z] = f & 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 f >>= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 context->alt_flags[ZF_S] = f; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 context->alt_regs[Z80_A] = *curpos; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 curpos += 3; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 for (int reg = Z80_C; reg <= Z80_H; reg++) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 context->alt_regs[reg++] = *(curpos++); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 context->alt_regs[reg] = *curpos; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 curpos += 3; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 context->regs[Z80_I] = *curpos; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 curpos += 2; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 context->iff1 = context->iff2 = *curpos; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 curpos += 2; |
668
5439ae7946ca
Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
193 context->reset = !*(curpos++); |
5439ae7946ca
Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
194 context->busreq = *curpos; |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 curpos += 3; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 uint32_t bank = read_le_32(curpos); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 if (bank < 0x400000) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 context->mem_pointers[1] = context->mem_pointers[2] + bank; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 } else { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 context->mem_pointers[1] = NULL; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 context->bank_reg = bank >> 15; |
962
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
203 uint8_t buffer[Z80_RAM_BYTES]; |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 fseek(gstfile, GST_Z80_RAM, SEEK_SET); |
962
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
205 if(fread(buffer, 1, sizeof(buffer), gstfile) != (8*1024)) { |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 fputs("Failed to read Z80 RAM from savestate\n", stderr); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 } |
962
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
209 for (int i = 0; i < Z80_RAM_BYTES; i++) |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
210 { |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
211 if (context->mem_pointers[0][i] != buffer[i]) { |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
212 context->mem_pointers[0][i] = buffer[i]; |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
213 z80_handle_code_write(i, context); |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
214 } |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
215 } |
1019
e34334e6c682
Fix GST savestate loading to deal with SAT cache to fix sprite corruption on savestate load. Clear out Z80 native_pc so the Z80 state does not get hosed when loading a savestate while the emulator is already running
Michael Pavone <pavone@retrodev.com>
parents:
962
diff
changeset
|
216 context->native_pc = NULL; |
1112
7ab7c8fb34ba
Fix intermittent crash in GST savestate loading
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
217 context->extra_pc = NULL; |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 return 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
220 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 uint8_t vdp_load_gst(vdp_context * context, FILE * state_file) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 { |
1019
e34334e6c682
Fix GST savestate loading to deal with SAT cache to fix sprite corruption on savestate load. Clear out Z80 native_pc so the Z80 state does not get hosed when loading a savestate while the emulator is already running
Michael Pavone <pavone@retrodev.com>
parents:
962
diff
changeset
|
223 uint8_t tmp_buf[VRAM_SIZE]; |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 fseek(state_file, GST_VDP_REGS, SEEK_SET); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 if (fread(context->regs, 1, VDP_REGS, state_file) != VDP_REGS) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 fputs("Failed to read VDP registers from savestate\n", stderr); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
227 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
229 context->double_res = (context->regs[REG_MODE_4] & (BIT_INTERLACE | BIT_DOUBLE_RES)) == (BIT_INTERLACE | BIT_DOUBLE_RES); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 latch_mode(context); |
1019
e34334e6c682
Fix GST savestate loading to deal with SAT cache to fix sprite corruption on savestate load. Clear out Z80 native_pc so the Z80 state does not get hosed when loading a savestate while the emulator is already running
Michael Pavone <pavone@retrodev.com>
parents:
962
diff
changeset
|
231 if (fread(tmp_buf, 1, CRAM_SIZE*2, state_file) != CRAM_SIZE*2) { |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 fputs("Failed to read CRAM from savestate\n", stderr); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
233 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
235 for (int i = 0; i < CRAM_SIZE; i++) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 uint16_t value; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 context->cram[i] = value = (tmp_buf[i*2+1] << 8) | tmp_buf[i*2]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 context->colors[i] = color_map[value & 0xEEE]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 context->colors[i + CRAM_SIZE] = color_map[(value & 0xEEE) | FBUF_SHADOW]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 context->colors[i + CRAM_SIZE*2] = color_map[(value & 0xEEE) | FBUF_HILIGHT]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
242 if (fread(tmp_buf, 2, VSRAM_SIZE, state_file) != VSRAM_SIZE) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
243 fputs("Failed to read VSRAM from savestate\n", stderr); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 for (int i = 0; i < VSRAM_SIZE; i++) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
247 context->vsram[i] = (tmp_buf[i*2+1] << 8) | tmp_buf[i*2]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 fseek(state_file, GST_VDP_MEM, SEEK_SET); |
1019
e34334e6c682
Fix GST savestate loading to deal with SAT cache to fix sprite corruption on savestate load. Clear out Z80 native_pc so the Z80 state does not get hosed when loading a savestate while the emulator is already running
Michael Pavone <pavone@retrodev.com>
parents:
962
diff
changeset
|
250 if (fread(tmp_buf, 1, VRAM_SIZE, state_file) != VRAM_SIZE) { |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 fputs("Failed to read VRAM from savestate\n", stderr); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 } |
1019
e34334e6c682
Fix GST savestate loading to deal with SAT cache to fix sprite corruption on savestate load. Clear out Z80 native_pc so the Z80 state does not get hosed when loading a savestate while the emulator is already running
Michael Pavone <pavone@retrodev.com>
parents:
962
diff
changeset
|
254 for (int i = 0; i < VRAM_SIZE; i++) { |
e34334e6c682
Fix GST savestate loading to deal with SAT cache to fix sprite corruption on savestate load. Clear out Z80 native_pc so the Z80 state does not get hosed when loading a savestate while the emulator is already running
Michael Pavone <pavone@retrodev.com>
parents:
962
diff
changeset
|
255 write_vram_byte(context, i, tmp_buf[i]); |
e34334e6c682
Fix GST savestate loading to deal with SAT cache to fix sprite corruption on savestate load. Clear out Z80 native_pc so the Z80 state does not get hosed when loading a savestate while the emulator is already running
Michael Pavone <pavone@retrodev.com>
parents:
962
diff
changeset
|
256 } |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 return 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 uint8_t vdp_save_gst(vdp_context * context, FILE * outfile) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 uint8_t tmp_buf[CRAM_SIZE*2]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 fseek(outfile, GST_VDP_REGS, SEEK_SET); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 if(fwrite(context->regs, 1, VDP_REGS, outfile) != VDP_REGS) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 fputs("Error writing VDP regs to savestate\n", stderr); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 for (int i = 0; i < CRAM_SIZE; i++) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 tmp_buf[i*2] = context->cram[i]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 tmp_buf[i*2+1] = context->cram[i] >> 8; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 if (fwrite(tmp_buf, 1, sizeof(tmp_buf), outfile) != sizeof(tmp_buf)) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 fputs("Error writing CRAM to savestate\n", stderr); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 for (int i = 0; i < VSRAM_SIZE; i++) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
278 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
279 tmp_buf[i*2] = context->vsram[i]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
280 tmp_buf[i*2+1] = context->vsram[i] >> 8; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
281 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
282 if (fwrite(tmp_buf, 2, VSRAM_SIZE, outfile) != VSRAM_SIZE) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 fputs("Error writing VSRAM to savestate\n", stderr); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
286 fseek(outfile, GST_VDP_MEM, SEEK_SET); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
287 if (fwrite(context->vdpmem, 1, VRAM_SIZE, outfile) != VRAM_SIZE) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
288 fputs("Error writing VRAM to savestate\n", stderr); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
289 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
290 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
291 return 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
292 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
293 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
294 uint8_t z80_save_gst(z80_context * context, FILE * gstfile) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
295 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
296 uint8_t regdata[GST_Z80_REG_SIZE]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
297 uint8_t * curpos = regdata; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
298 memset(regdata, 0, sizeof(regdata)); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
299 uint8_t f = context->flags[ZF_S]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
300 f <<= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
301 f |= context->flags[ZF_Z] ; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
302 f <<= 2; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
303 f |= context->flags[ZF_H]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
304 f <<= 2; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
305 f |= context->flags[ZF_PV]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
306 f <<= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
307 f |= context->flags[ZF_N]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
308 f <<= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
309 f |= context->flags[ZF_C]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
310 *(curpos++) = f; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
311 *curpos = context->regs[Z80_A]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
312 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
313 curpos += 3; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
314 for (int reg = Z80_C; reg <= Z80_IYH; reg++) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
315 *(curpos++) = context->regs[reg++]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 *curpos = context->regs[reg]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
317 curpos += 3; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
319 write_le_16(curpos, context->pc); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 curpos += 4; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
321 write_le_16(curpos, context->sp); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
322 curpos += 4; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
323 f = context->alt_flags[ZF_S]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
324 f <<= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
325 f |= context->alt_flags[ZF_Z] ; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
326 f <<= 2; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
327 f |= context->alt_flags[ZF_H]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
328 f <<= 2; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
329 f |= context->alt_flags[ZF_PV]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
330 f <<= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
331 f |= context->alt_flags[ZF_N]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
332 f <<= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
333 f |= context->alt_flags[ZF_C]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
334 *(curpos++) = f; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
335 *curpos = context->alt_regs[Z80_A]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
336 curpos += 3; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
337 for (int reg = Z80_C; reg <= Z80_H; reg++) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
338 *(curpos++) = context->alt_regs[reg++]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
339 *curpos = context->alt_regs[reg]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
340 curpos += 3; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
341 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
342 *curpos = context->regs[Z80_I]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
343 curpos += 2; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
344 *curpos = context->iff1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
345 curpos += 2; |
668
5439ae7946ca
Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
346 *(curpos++) = !context->reset; |
5439ae7946ca
Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
347 *curpos = context->busreq; |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
348 curpos += 3; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
349 uint32_t bank = context->bank_reg << 15; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
350 write_le_32(curpos, bank); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
351 fseek(gstfile, GST_Z80_REGS, SEEK_SET); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
352 if (fwrite(regdata, 1, sizeof(regdata), gstfile) != sizeof(regdata)) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
353 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
354 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
355 fseek(gstfile, GST_Z80_RAM, SEEK_SET); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
356 if(fwrite(context->mem_pointers[0], 1, 8*1024, gstfile) != (8*1024)) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
357 fputs("Failed to write Z80 RAM to savestate\n", stderr); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
358 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
359 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
360 return 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
361 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
362 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
363 uint8_t ym_load_gst(ym2612_context * context, FILE * gstfile) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
364 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
365 uint8_t regdata[GST_YM_SIZE]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
366 fseek(gstfile, GST_YM_OFFSET, SEEK_SET); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
367 if (fread(regdata, 1, sizeof(regdata), gstfile) != sizeof(regdata)) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
368 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
369 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
370 for (int i = 0; i < sizeof(regdata); i++) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
371 if (i & 0x100) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
372 ym_address_write_part2(context, i & 0xFF); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
373 } else { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
374 ym_address_write_part1(context, i); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
375 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
376 ym_data_write(context, regdata[i]); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
377 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
378 return 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
379 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
380 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
381 uint8_t ym_save_gst(ym2612_context * context, FILE * gstfile) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
382 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
383 uint8_t regdata[GST_YM_SIZE]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
384 for (int i = 0; i < sizeof(regdata); i++) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
385 if (i & 0x100) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
386 int reg = (i & 0xFF); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
387 if (reg >= YM_PART2_START && reg < YM_REG_END) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
388 regdata[i] = context->part2_regs[reg-YM_PART2_START]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
389 } else { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
390 regdata[i] = 0xFF; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
391 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
392 } else { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
393 if (i >= YM_PART1_START && i < YM_REG_END) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
394 regdata[i] = context->part1_regs[i-YM_PART1_START]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
395 } else { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
396 regdata[i] = 0xFF; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
397 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
398 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
399 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
400 fseek(gstfile, GST_YM_OFFSET, SEEK_SET); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
401 if (fwrite(regdata, 1, sizeof(regdata), gstfile) != sizeof(regdata)) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
402 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
404 return 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
405 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
406 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
407 uint32_t load_gst(genesis_context * gen, char * fname) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
408 { |
962
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
409 char buffer[4096]; |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
410 FILE * gstfile = fopen(fname, "rb"); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
411 if (!gstfile) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
412 fprintf(stderr, "Could not open file %s for reading\n", fname); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
413 goto error; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
414 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
415 char ident[5]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
416 if (fread(ident, 1, sizeof(ident), gstfile) != sizeof(ident)) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
417 fprintf(stderr, "Could not read ident code from %s\n", fname); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
418 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
419 } |
708
61faa298af07
Small horizontal interrupt fixes
Michael Pavone <pavone@retrodev.com>
parents:
668
diff
changeset
|
420 if (memcmp(ident, "GST\x40\xE0", 3) != 0) { |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
421 fprintf(stderr, "%s doesn't appear to be a GST savestate. The ident code is %c%c%c\\x%X\\x%X instead of GST\\x40\\xE0.\n", fname, ident[0], ident[1], ident[2], ident[3], ident[4]); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
422 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
423 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
424 uint32_t pc = m68k_load_gst(gen->m68k, gstfile); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
425 if (!pc) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
426 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
427 } |
962
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
428 |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
429 if (!vdp_load_gst(gen->vdp, gstfile)) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
430 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
431 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
432 if (!ym_load_gst(gen->ym, gstfile)) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
433 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
434 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
435 if (!z80_load_gst(gen->z80, gstfile)) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
436 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
437 } |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
438 gen->io.ports[0].control = 0x40; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
439 gen->io.ports[1].control = 0x40; |
962
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
440 |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
441 fseek(gstfile, GST_68K_RAM, SEEK_SET); |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
442 for (int i = 0; i < (32*1024);) { |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
443 if (fread(buffer, 1, sizeof(buffer), gstfile) != sizeof(buffer)) { |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
444 fputs("Failed to read 68K RAM from savestate\n", stderr); |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
445 return 0; |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
446 } |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
447 for(char *curpos = buffer; curpos < (buffer + sizeof(buffer)); curpos += sizeof(uint16_t)) { |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
448 uint16_t word = read_be_16(curpos); |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
449 if (word != gen->work_ram[i]) { |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
450 gen->work_ram[i] = word; |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
451 m68k_handle_code_write(0xFF0000 | (i << 1), gen->m68k); |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
452 } |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
453 i++; |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
454 } |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
455 } |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
456 fclose(gstfile); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
457 return pc; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
458 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
459 error_close: |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
460 fclose(gstfile); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
461 error: |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
462 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
463 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
464 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
465 uint8_t save_gst(genesis_context * gen, char *fname, uint32_t m68k_pc) |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
466 { |
962
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
467 char buffer[4096]; |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
468 FILE * gstfile = fopen(fname, "wb"); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
469 if (!gstfile) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
470 fprintf(stderr, "Could not open %s for writing\n", fname); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
471 goto error; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
472 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
473 if (fwrite("GST\x40\xE0", 1, 5, gstfile) != 5) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
474 fputs("Error writing signature to savestate\n", stderr); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
475 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
476 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
477 if (!m68k_save_gst(gen->m68k, m68k_pc, gstfile)) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
478 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
479 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
480 if (!z80_save_gst(gen->z80, gstfile)) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
481 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
482 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
483 if (!vdp_save_gst(gen->vdp, gstfile)) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
484 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
485 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
486 if (!ym_save_gst(gen->ym, gstfile)) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
487 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
488 } |
962
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
489 fseek(gstfile, GST_68K_RAM, SEEK_SET); |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
490 for (int i = 0; i < (32*1024);) { |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
491 for(char *curpos = buffer; curpos < (buffer + sizeof(buffer)); curpos += sizeof(uint16_t)) { |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
492 write_be_16(curpos, gen->work_ram[i++]); |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
493 } |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
494 if (fwrite(buffer, 1, sizeof(buffer), gstfile) != sizeof(buffer)) { |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
495 fputs("Failed to write 68K RAM to savestate\n", stderr); |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
496 return 0; |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
497 } |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
498 } |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 return 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
500 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
501 error_close: |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
502 fclose(gstfile); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
503 error: |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
504 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
505 } |