-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSavestates.hpp
171 lines (134 loc) · 4.86 KB
/
Savestates.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// *****************************************************************************
// start include guard
#ifndef SAVESTATES_HPP
#define SAVESTATES_HPP
// include Vircon32 headers
#include "ConsoleLogic/V32Console.hpp"
#include "VirconDefinitions/Constants.hpp"
#include "VirconDefinitions/Enumerations.hpp"
// *****************************************************************************
// =============================================================================
// STRUCTURES TO HANDLE CONSOLE STATE
// =============================================================================
typedef struct
{
// all CPU registers
V32::V32Word Registers[ 16 ];
V32::V32Word InternalRegisters[ 3 ];
// control flags
int32_t Halted;
int32_t Waiting;
}
CPUState;
// -----------------------------------------------------------------------------
typedef struct
{
// all exposed GPU registers that are not
// affected by texture and region selection
// (12 words in total)
V32::V32Word Registers[ 12 ];
// configuration for the BIOS texture
// (note that this ties each savestate to a particular BIOS)
V32::GPUTexture BiosTexture;
// configuration for cartridge textures
V32::GPUTexture CartridgeTextures[ V32::Constants::GPUMaximumCartridgeTextures ];
}
GPUState;
// -----------------------------------------------------------------------------
typedef struct
{
// same as SPUSound but not including the sound samples
int32_t Length;
int32_t PlayWithLoop;
int32_t LoopStart;
int32_t LoopEnd;
}
SPUSoundState;
// -----------------------------------------------------------------------------
typedef struct
{
// all exposed SPU registers that are not
// affected by channel and sound selection
// (4 words in total)
V32::V32Word Registers[ 4 ];
// all SPU channels
V32::SPUChannel Channels[ V32::Constants::SPUSoundChannels ];
// configuration for the BIOS sound
// (note that this ties each savestate to a particular BIOS)
SPUSoundState BiosSound;
// configuration for cartridge sounds
SPUSoundState CartridgeSounds[ V32::Constants::SPUMaximumCartridgeSounds ];
}
SPUState;
// -----------------------------------------------------------------------------
typedef struct
{
// the single gamepad controller exposed register
// that is not affected by gamepad selection
int32_t SelectedGamepad;
// state of all gamepads (both real-time and provided)
V32::GamepadState GamepadStates[ 2 * V32::Constants::GamepadPorts ];
}
GamepadControllerState;
// -----------------------------------------------------------------------------
typedef struct
{
// RAM contents
V32::V32Word RAM[ V32::Constants::RAMSize ];
// state for minor chips
V32::V32Word TimerRegisters[ 4 ];
int32_t RNGCurrentValue;
// NOTE 1: Power is assumed to be on when saving a
// state. On a core this should always be the case.
// NOTE 2: Screen contents are persistent, so the
// drawing buffer should also be part of the state.
// However taking and redrawing screenshots would
// add significant size and complexity. Nearly all
// games redraw the whole screen every frame, so
// we will skip saving the screen.
}
OtherConsoleState;
// -----------------------------------------------------------------------------
typedef struct
{
char Title[ 64 ];
uint32_t Version;
uint32_t Revision;
int32_t ProgramROMSize;
int32_t NumberOfTextures;
int32_t NumberOfSounds;
}
ROMInfo;
// -----------------------------------------------------------------------------
typedef struct
{
// data for the game itself; this is just a
// basic attempt at distinguish different
// games to prevent loading an incompatible
// savestate and messing things up
ROMInfo Game;
// data to identify the BIOS; this is much
// less important than the game itself, but
// if different BIOSes are used to save and
// load it can produce graphic errors
ROMInfo Bios;
// data for all stateful console components;
// make GPU last so that we can adjust size
// using a texture array (the last field)
// only as large as needed for each game
OtherConsoleState Others;
GamepadControllerState GamepadController;
CPUState CPU;
SPUState SPU;
GPUState GPU;
}
ConsoleState;
// =============================================================================
// SERIALIZATION FUNCTIONS
// =============================================================================
bool SaveState( ConsoleState* State );
bool LoadState( const ConsoleState* State );
// *****************************************************************************
// end include guard
#endif
// *****************************************************************************