annotate gst.c @ 1892:1afd6e85ec26

Properly mask addresses to 24-bit in disassembler
author Michael Pavone <pavone@retrodev.com>
date Thu, 05 Dec 2019 09:32:52 -0800
parents d6d4c006a7b3
children 2d462aa78349
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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++);
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1429
diff changeset
147 #ifndef NEW_CORE
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
148 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
149 f >>= 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
150 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
151 f >>= 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
152 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
153 f >>= 2;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
154 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
155 f >>= 2;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
156 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
157 f >>= 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
158 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
159
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
160 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
161 curpos += 3;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
162 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
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 context->regs[reg] = *curpos;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
165 curpos += 3;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
166 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
167 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
168 curpos += 4;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
169 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
170 curpos += 4;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
171 f = *(curpos++);
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
172 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
173 f >>= 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
174 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
175 f >>= 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
176 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
177 f >>= 2;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
178 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
179 f >>= 2;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
180 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
181 f >>= 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
182 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
183 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
184 curpos += 3;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
185 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
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 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
188 curpos += 3;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
189 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
190 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
191 curpos += 2;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
192 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
193 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
194 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
195 context->busreq = *curpos;
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
196 curpos += 3;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
197 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
198 if (bank < 0x400000) {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
199 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
200 } else {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
201 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
202 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
203 context->bank_reg = bank >> 15;
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1429
diff changeset
204 #endif
962
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
205 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
206 fseek(gstfile, GST_Z80_RAM, SEEK_SET);
962
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
207 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
208 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
209 return 0;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
210 }
962
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
211 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
212 {
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
213 if (context->mem_pointers[0][i] != buffer[i]) {
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
214 context->mem_pointers[0][i] = buffer[i];
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1429
diff changeset
215 #ifndef NEW_CORE
962
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
216 z80_handle_code_write(i, context);
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1429
diff changeset
217 #endif
962
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
218 }
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
219 }
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1429
diff changeset
220 #ifndef NEW_CORE
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
221 context->native_pc = NULL;
1112
7ab7c8fb34ba Fix intermittent crash in GST savestate loading
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
222 context->extra_pc = NULL;
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1429
diff changeset
223 #endif
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
224 return 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
225 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
226
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
227 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
228 {
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
229 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
230 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
231 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
232 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
233 return 0;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
234 }
1181
0928b68fef2a Update gst loader to deal with VDP changes
Michael Pavone <pavone@retrodev.com>
parents: 1120
diff changeset
235 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
236 {
0928b68fef2a Update gst loader to deal with VDP changes
Michael Pavone <pavone@retrodev.com>
parents: 1120
diff changeset
237 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
238 }
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
239 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
240 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
241 return 0;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
242 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
243 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
244 uint16_t value;
1429
7e67f8a37051 write_cram_internal takes a CRAM index, not a CRAM address
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
245 write_cram_internal(context, i, (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
246 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
247 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
248 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
249 return 0;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
250 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
251 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
252 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
253 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
254 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
255 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
256 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
257 return 0;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
258 }
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
259 for (int i = 0; i < VRAM_SIZE; i++) {
1333
69c25e1188e5 Small tweak to how SAT cache updates are done. Mostly fixes the rotating cube scene in Overdrive 2
Michael Pavone <pavone@retrodev.com>
parents: 1325
diff changeset
260 context->vdpmem[i] = tmp_buf[i];
69c25e1188e5 Small tweak to how SAT cache updates are done. Mostly fixes the rotating cube scene in Overdrive 2
Michael Pavone <pavone@retrodev.com>
parents: 1325
diff changeset
261 vdp_check_update_sat_byte(context, i, tmp_buf[i]);
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
262 }
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
263 return 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
264 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
265
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
266 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
267 {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
268 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
269 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
270 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
271 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
272 return 0;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
273 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
274 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
275 {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
276 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
277 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
278 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
279 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
280 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
281 return 0;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
282 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
283 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
284 {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
285 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
286 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
287 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
288 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
289 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
290 return 0;
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 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
293 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
294 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
295 return 0;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
296 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
297 return 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
298 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
299
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
300 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
301 {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
302 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
303 uint8_t * curpos = regdata;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
304 memset(regdata, 0, sizeof(regdata));
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1429
diff changeset
305 #ifndef NEW_CORE
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
306 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
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_Z] ;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
309 f <<= 2;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
310 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
311 f <<= 2;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
312 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
313 f <<= 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
314 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
315 f <<= 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
316 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
317 *(curpos++) = f;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
318 *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
319
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
320 curpos += 3;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
321 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
322 *(curpos++) = context->regs[reg++];
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
323 *curpos = context->regs[reg];
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
324 curpos += 3;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
325 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
326 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
327 curpos += 4;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
328 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
329 curpos += 4;
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_S];
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_Z] ;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
333 f <<= 2;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
334 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
335 f <<= 2;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
336 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
337 f <<= 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
338 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
339 f <<= 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
340 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
341 *(curpos++) = f;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
342 *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
343 curpos += 3;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
344 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
345 *(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
346 *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
347 curpos += 3;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
348 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
349 *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
350 curpos += 2;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
351 *curpos = context->iff1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
352 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
353 *(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
354 *curpos = context->busreq;
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
355 curpos += 3;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
356 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
357 write_le_32(curpos, bank);
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1429
diff changeset
358 #endif
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
359 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
360 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
361 return 0;
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 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
364 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
365 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
366 return 0;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
367 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
368 return 1;
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
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
371 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
372 {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
373 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
374 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
375 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
376 return 0;
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 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
379 if (i & 0x100) {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
380 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
381 } else {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
382 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
383 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
384 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
385 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
386 return 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
387 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
388
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
389 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
390 {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
391 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
392 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
393 if (i & 0x100) {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
394 int reg = (i & 0xFF);
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
395 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
396 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
397 } else {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
398 regdata[i] = 0xFF;
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 } else {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
401 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
402 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
403 } else {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
404 regdata[i] = 0xFF;
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 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
408 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
409 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
410 return 0;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
411 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
412 return 1;
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
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
415 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
416 {
962
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
417 char buffer[4096];
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
418 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
419 if (!gstfile) {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
420 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
421 goto error;
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 char ident[5];
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
424 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
425 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
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 }
708
61faa298af07 Small horizontal interrupt fixes
Michael Pavone <pavone@retrodev.com>
parents: 668
diff changeset
428 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
429 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
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 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
433 if (!pc) {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
434 goto error_close;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
435 }
962
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
436
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
437 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
438 goto error_close;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
439 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
440 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
441 goto error_close;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
442 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
443 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
444 goto error_close;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
445 }
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
446 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
447 gen->io.ports[1].control = 0x40;
962
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
448
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
449 fseek(gstfile, GST_68K_RAM, SEEK_SET);
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
450 for (int i = 0; i < (32*1024);) {
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
451 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
452 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
453 return 0;
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 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
456 uint16_t word = read_be_16(curpos);
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
457 if (word != gen->work_ram[i]) {
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
458 gen->work_ram[i] = word;
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
459 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
460 }
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
461 i++;
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
462 }
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
463 }
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
464 fclose(gstfile);
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
465 return pc;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
466
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
467 error_close:
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
468 fclose(gstfile);
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
469 error:
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
470 return 0;
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
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
473 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
474 {
962
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
475 char buffer[4096];
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
476 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
477 if (!gstfile) {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
478 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
479 goto error;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
480 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
481 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
482 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
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 (!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
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 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
488 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
489 goto error_close;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
490 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
491 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
492 goto error_close;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
493 }
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
494 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
495 goto error_close;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
496 }
962
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
497 fseek(gstfile, GST_68K_RAM, SEEK_SET);
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
498 for (int i = 0; i < (32*1024);) {
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
499 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
500 write_be_16(curpos, gen->work_ram[i++]);
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
501 }
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
502 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
503 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
504 return 0;
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
505 }
f52cb02a1466 Fixed loading save states from menu
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
506 }
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
507 return 1;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
508
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
509 error_close:
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
510 fclose(gstfile);
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
511 error:
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
512 return 0;
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
513 }