Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libgambatte/src/savestate.h
2 views
1
/***************************************************************************
2
* Copyright (C) 2008 by Sindre AamÄs *
3
* [email protected] *
4
* *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License version 2 as *
7
* published by the Free Software Foundation. *
8
* *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License version 2 for more details. *
13
* *
14
* You should have received a copy of the GNU General Public License *
15
* version 2 along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18
***************************************************************************/
19
#ifndef SAVESTATE_H
20
#define SAVESTATE_H
21
22
#include <cstdint>
23
24
namespace gambatte {
25
26
class SaverList;
27
28
struct SaveState {
29
template<typename T>
30
class Ptr {
31
T *ptr;
32
unsigned long sz;
33
34
public:
35
Ptr() : ptr(0), sz(0) {}
36
const T* get() const { return ptr; }
37
unsigned long getSz() const { return sz; }
38
void set(T *ptr, const unsigned long sz) { this->ptr = ptr; this->sz = sz; }
39
40
friend class SaverList;
41
friend void setInitState(SaveState &, bool, bool, std::uint32_t);
42
};
43
44
struct CPU {
45
unsigned long cycleCounter;
46
unsigned short PC;
47
unsigned short SP;
48
unsigned char A;
49
unsigned char B;
50
unsigned char C;
51
unsigned char D;
52
unsigned char E;
53
unsigned char F;
54
unsigned char H;
55
unsigned char L;
56
bool skip;
57
} cpu;
58
59
struct Mem {
60
Ptr<unsigned char> vram;
61
Ptr<unsigned char> sram;
62
Ptr<unsigned char> wram;
63
Ptr<unsigned char> ioamhram;
64
unsigned long divLastUpdate;
65
unsigned long timaLastUpdate;
66
unsigned long tmatime;
67
unsigned long nextSerialtime;
68
unsigned long lastOamDmaUpdate;
69
unsigned long minIntTime;
70
unsigned long unhaltTime;
71
unsigned short rombank;
72
unsigned short dmaSource;
73
unsigned short dmaDestination;
74
unsigned char rambank;
75
unsigned char oamDmaPos;
76
bool IME;
77
bool halted;
78
bool enableRam;
79
bool rambankMode;
80
bool hdmaTransfer;
81
} mem;
82
83
struct PPU {
84
Ptr<unsigned char> bgpData;
85
Ptr<unsigned char> objpData;
86
//SpriteMapper::OamReader
87
Ptr<unsigned char> oamReaderBuf;
88
Ptr<bool> oamReaderSzbuf;
89
90
unsigned long videoCycles;
91
unsigned long enableDisplayM0Time;
92
unsigned short lastM0Time;
93
unsigned short nextM0Irq;
94
unsigned short tileword;
95
unsigned short ntileword;
96
unsigned char spAttribList[10];
97
unsigned char spByte0List[10];
98
unsigned char spByte1List[10];
99
unsigned char winYPos;
100
unsigned char xpos;
101
unsigned char endx;
102
unsigned char reg0;
103
unsigned char reg1;
104
unsigned char attrib;
105
unsigned char nattrib;
106
unsigned char state;
107
unsigned char nextSprite;
108
unsigned char currentSprite;
109
unsigned char lyc;
110
unsigned char m0lyc;
111
unsigned char oldWy;
112
unsigned char winDrawState;
113
unsigned char wscx;
114
bool weMaster;
115
bool pendingLcdstatIrq;
116
} ppu;
117
118
struct SPU {
119
struct Duty {
120
unsigned long nextPosUpdate;
121
unsigned char nr3;
122
unsigned char pos;
123
};
124
125
struct Env {
126
unsigned long counter;
127
unsigned char volume;
128
};
129
130
struct LCounter {
131
unsigned long counter;
132
unsigned short lengthCounter;
133
};
134
135
struct {
136
struct {
137
unsigned long counter;
138
unsigned short shadow;
139
unsigned char nr0;
140
bool negging;
141
} sweep;
142
Duty duty;
143
Env env;
144
LCounter lcounter;
145
unsigned char nr4;
146
bool master;
147
} ch1;
148
149
struct {
150
Duty duty;
151
Env env;
152
LCounter lcounter;
153
unsigned char nr4;
154
bool master;
155
} ch2;
156
157
struct {
158
Ptr<unsigned char> waveRam;
159
LCounter lcounter;
160
unsigned long waveCounter;
161
unsigned long lastReadTime;
162
unsigned char nr3;
163
unsigned char nr4;
164
unsigned char wavePos;
165
unsigned char sampleBuf;
166
bool master;
167
} ch3;
168
169
struct {
170
struct {
171
unsigned long counter;
172
unsigned short reg;
173
} lfsr;
174
Env env;
175
LCounter lcounter;
176
unsigned char nr4;
177
bool master;
178
} ch4;
179
180
unsigned long cycleCounter;
181
} spu;
182
183
struct RTC {
184
unsigned long baseTime;
185
unsigned long haltTime;
186
unsigned char dataDh;
187
unsigned char dataDl;
188
unsigned char dataH;
189
unsigned char dataM;
190
unsigned char dataS;
191
bool lastLatchData;
192
} rtc;
193
};
194
195
}
196
197
#endif
198
199