Mercurial > repos > blastem
annotate gst.c @ 1331:9bba5ff5beb8
Add 128K VRAM bit to VDP register print in debugger
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 26 Apr 2017 01:12:28 -0700 |
parents | 58bfbed6cdb5 |
children | 69c25e1188e5 |
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); |
1181
0928b68fef2a
Update gst loader to deal with VDP changes
Michael Pavone <pavone@retrodev.com>
parents:
1120
diff
changeset
|
225 if (fread(tmp_buf, 1, VDP_REGS, state_file) != VDP_REGS) { |
451
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 } |
1181
0928b68fef2a
Update gst loader to deal with VDP changes
Michael Pavone <pavone@retrodev.com>
parents:
1120
diff
changeset
|
229 for (uint16_t i = 0; i < VDP_REGS; i++) |
0928b68fef2a
Update gst loader to deal with VDP changes
Michael Pavone <pavone@retrodev.com>
parents:
1120
diff
changeset
|
230 { |
0928b68fef2a
Update gst loader to deal with VDP changes
Michael Pavone <pavone@retrodev.com>
parents:
1120
diff
changeset
|
231 vdp_control_port_write(context, 0x8000 | (i << 8) | tmp_buf[i]); |
0928b68fef2a
Update gst loader to deal with VDP changes
Michael Pavone <pavone@retrodev.com>
parents:
1120
diff
changeset
|
232 } |
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
|
233 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
|
234 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
|
235 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 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
|
238 uint16_t value; |
1181
0928b68fef2a
Update gst loader to deal with VDP changes
Michael Pavone <pavone@retrodev.com>
parents:
1120
diff
changeset
|
239 write_cram(context, i*2, (tmp_buf[i*2+1] << 8) | tmp_buf[i*2]); |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 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
|
242 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
|
243 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 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
|
246 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
|
247 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 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
|
249 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
|
250 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
|
251 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 } |
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
|
253 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
|
254 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
|
255 } |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 return 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 } |
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 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
|
260 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 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
|
262 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
|
263 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
|
264 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
|
265 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 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
|
268 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 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
|
270 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
|
271 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 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
|
273 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
|
274 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 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
|
277 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
278 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
|
279 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
|
280 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
281 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
|
282 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
|
283 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 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
|
286 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
|
287 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
|
288 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
289 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
290 return 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
291 } |
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 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
|
294 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
295 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
|
296 uint8_t * curpos = regdata; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
297 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
|
298 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
|
299 f <<= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
300 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
|
301 f <<= 2; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
302 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
|
303 f <<= 2; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
304 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
|
305 f <<= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
306 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
|
307 f <<= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
308 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
|
309 *(curpos++) = f; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
310 *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
|
311 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
312 curpos += 3; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
313 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
|
314 *(curpos++) = context->regs[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 += 3; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
317 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 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
|
319 curpos += 4; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 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
|
321 curpos += 4; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
322 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
|
323 f <<= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
324 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
|
325 f <<= 2; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
326 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
|
327 f <<= 2; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
328 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
|
329 f <<= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
330 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
|
331 f <<= 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
332 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
|
333 *(curpos++) = f; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
334 *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
|
335 curpos += 3; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
336 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
|
337 *(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
|
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 += 3; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
340 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
341 *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
|
342 curpos += 2; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
343 *curpos = context->iff1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
344 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
|
345 *(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
|
346 *curpos = context->busreq; |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
347 curpos += 3; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
348 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
|
349 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
|
350 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
|
351 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
|
352 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
353 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
354 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
|
355 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
|
356 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
|
357 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
358 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
359 return 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
360 } |
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 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
|
363 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
364 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
|
365 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
|
366 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
|
367 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
368 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
369 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
|
370 if (i & 0x100) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
371 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
|
372 } else { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
373 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
|
374 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
375 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
|
376 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
377 return 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
378 } |
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 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
|
381 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
382 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
|
383 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
|
384 if (i & 0x100) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
385 int reg = (i & 0xFF); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
386 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
|
387 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
|
388 } else { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
389 regdata[i] = 0xFF; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
390 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
391 } else { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
392 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
|
393 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
|
394 } else { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
395 regdata[i] = 0xFF; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
396 } |
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 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
|
400 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
|
401 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
402 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 return 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
404 } |
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 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
|
407 { |
962
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
408 char buffer[4096]; |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
409 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
|
410 if (!gstfile) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
411 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
|
412 goto error; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
413 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
414 char ident[5]; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
415 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
|
416 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
|
417 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
418 } |
708
61faa298af07
Small horizontal interrupt fixes
Michael Pavone <pavone@retrodev.com>
parents:
668
diff
changeset
|
419 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
|
420 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
|
421 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
422 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
423 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
|
424 if (!pc) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
425 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
426 } |
962
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
427 |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
428 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
|
429 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
430 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
431 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
|
432 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
433 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
434 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
|
435 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
436 } |
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
|
437 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
|
438 gen->io.ports[1].control = 0x40; |
962
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
439 |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
440 fseek(gstfile, GST_68K_RAM, SEEK_SET); |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
441 for (int i = 0; i < (32*1024);) { |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
442 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
|
443 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
|
444 return 0; |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
445 } |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
446 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
|
447 uint16_t word = read_be_16(curpos); |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
448 if (word != gen->work_ram[i]) { |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
449 gen->work_ram[i] = word; |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
450 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
|
451 } |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
452 i++; |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
453 } |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
454 } |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
455 fclose(gstfile); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
456 return pc; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
457 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
458 error_close: |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
459 fclose(gstfile); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
460 error: |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
461 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
462 } |
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 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
|
465 { |
962
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
466 char buffer[4096]; |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
467 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
|
468 if (!gstfile) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
469 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
|
470 goto error; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
471 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
472 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
|
473 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
|
474 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
475 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
476 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
|
477 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
478 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
479 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
|
480 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
481 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
482 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
|
483 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
484 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
485 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
|
486 goto error_close; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
487 } |
962
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
488 fseek(gstfile, GST_68K_RAM, SEEK_SET); |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
489 for (int i = 0; i < (32*1024);) { |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
490 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
|
491 write_be_16(curpos, gen->work_ram[i++]); |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
492 } |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
493 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
|
494 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
|
495 return 0; |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
496 } |
f52cb02a1466
Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents:
961
diff
changeset
|
497 } |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
498 return 1; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
500 error_close: |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
501 fclose(gstfile); |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
502 error: |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
503 return 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
504 } |