-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemulation.h
258 lines (221 loc) · 8.01 KB
/
emulation.h
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/************************************************************************
* emulation.h
* Main emulation routines
*
************************************************************************
*
* Phoinix,
* Nintendo Gameboy(TM) emulator for the Palm OS(R) Computing Platform
*
* (c)2000-2007 Bodo Wenzel
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
************************************************************************
* History:
*
* $Log: emulation.h,v $
* Revision 1.14 2007/02/11 17:14:43 bodowenzel
* Multiple saved state feature implemented
*
* Revision 1.13 2005/05/03 08:39:11 bodowenzel
* Moved coldReset, ime, im and error into EmulationCpuState
*
* Revision 1.12 2005/04/03 14:08:33 bodowenzel
* Option to save the state for each game
*
* Revision 1.11 2005/02/17 19:42:35 bodowenzel
* Added pace control
*
* Revision 1.10 2005/01/29 10:25:37 bodowenzel
* Added const qualifier to pointer parameters
*
* Revision 1.9 2004/12/28 13:56:35 bodowenzel
* Split up all C-Code to multi-segmented
*
* Revision 1.8 2004/12/02 20:01:22 bodowenzel
* New configurable screen layout
*
* Revision 1.7 2004/10/24 09:11:05 bodowenzel
* New button mapping
*
* Revision 1.6 2004/09/19 12:36:25 bodowenzel
* New info type (None)
*
* Revision 1.5 2004/06/06 09:25:01 bodowenzel
* Change game's location to RAM on error saving states
*
* Revision 1.4 2002/10/19 08:08:10 bodowenzel
* History cleanup, Javadoc-style header
*
* Revision 1.3 2001/12/30 18:47:11 bodowenzel
* CVS keyword Log was faulty
*
* Revision 1.2 2001/12/28 18:28:04 bodowenzel
* Bug found, if restarted twice without running (GB-PC was reset)
*
* Revision 1.1.1.1 2001/12/16 13:37:54 bodowenzel
* Import
*
************************************************************************
*/
#ifndef EMULATION_H
#define EMULATION_H
/* === Includes ======================================================= */
#include "sections.h"
#include "gbemu.h"
/* === Constants ====================================================== */
#define emulationKeyCount (8)
/* offsets, depending on Gameboy hardware */
#define emulationJoypadBoth (0x0)
#define emulationJoypadCtrl (0x1)
#define emulationJoypadCurs (0x2)
#define emulationJoypadNone (0x3)
#define emulationMaxTime (100UL * 60 * 60)
/* === Type definitions =============================================== */
#ifdef __GNUC__ /* only if C preprocessing */
typedef struct {
/* NOTE: this has to match the .bss section in emulation_s.S! */
UInt8 *pcBase;
Int16 pcOffset;
UInt8 *spBase;
Int16 spOffset;
UInt8 a;
UInt8 f;
UInt8 b;
UInt8 c;
UInt8 d;
UInt8 e;
UInt8 h;
UInt8 l;
UInt8 coldReset;
UInt8 ime;
UInt8 im;
UInt8 error;
} EmulationCpuStateType;
typedef struct {
/* NOTES:
* This has to match the .bss section in emulation_s.S!
* The layout has to be equal to the layout of the GB!
*/
UInt8 p1; /* joypad, used bit 1 and 0 */
UInt8 sb; /* serial transfer data */
UInt8 sc; /* serial transfer control */
UInt8 nonExists03;
UInt8 div; /* divider, not used */
UInt8 tima; /* timer counter, not used */
UInt8 tma; /* timer modulo */
UInt8 tca; /* timer control */
UInt8 nonExists08_0e[0x07];
UInt8 if_; /* interrupt flags */
UInt8 ch1_ent; /* sound, not emulated */
UInt8 ch1_wave; /* sound, not emulated */
UInt8 ch1_env; /* sound, not emulated */
UInt8 ch1_freq_lo; /* sound, not emulated */
UInt8 ch1_freq_hi_kick; /* sound, not emulated */
UInt8 nonExists15;
UInt8 ch2_wave; /* sound, not emulated */
UInt8 ch2_env; /* sound, not emulated */
UInt8 ch2_freq_lo; /* sound, not emulated */
UInt8 ch2_freq_hi_kick; /* sound, not emulated */
UInt8 ch3_onoff; /* sound, not emulated */
UInt8 ch2_length; /* sound, not emulated */
UInt8 ch3_volume; /* sound, not emulated */
UInt8 ch3_freq_lo; /* sound, not emulated */
UInt8 ch3_freq_hi_kick; /* sound, not emulated */
UInt8 nonExists1f;
UInt8 ch4_length; /* sound, not emulated */
UInt8 ch4_env; /* sound, not emulated */
UInt8 ch4_poly; /* sound, not emulated */
UInt8 ch4_kick; /* sound, not emulated */
UInt8 snd_vin; /* sound, not emulated */
UInt8 snd_stereo; /* sound, not emulated */
UInt8 snd_stat; /* sound, not emulated */
UInt8 nonExists27_2f[0x09];
UInt8 wave[0x10]; /* sound, not emulated */
UInt8 lcdc; /* LCD control */
UInt8 stat; /* LCD status */
UInt8 scy; /* LCD scroll y */
UInt8 scx; /* LCD scroll x */
UInt8 ly; /* LCD y coordinate */
UInt8 lyc; /* LCD y compare */
UInt8 dma; /* LCD DMA transfer */
UInt8 bgp; /* LCD background palette */
UInt8 obp0; /* LCD object palette 0 */
UInt8 obp1; /* LCD object palette 1 */
UInt8 wy; /* LCD window y */
UInt8 wx; /* LCD window x */
UInt8 nonExists4c_7f[0x34];
UInt8 ram[0x7f]; /* CPU RAM */
UInt8 ie; /* interrupt enable */
} EmulationIoType;
typedef struct {
Boolean paused;
Boolean boosted;
UInt32 time;
} EmulationMiscType;
typedef struct {
EmulationMiscType misc;
EmulationCpuStateType cpuState;
EmulationIoType io;
} EmulationStateType;
#endif
/* === Global variables =============================================== */
#ifdef __GNUC__ /* only if C preprocessing */
extern EventType EmulationTheEvent;
/* Address of emulator kernel; NOTE: This points to combo 0x00 at offset
* 0x8000 because of SInt16 indices!
*/
extern GbemuComboType *EmulationEmulator;
extern EmulationCpuStateType EmulationCpuState;
extern EmulationIoType EmulationIo; /* input/output space */
extern UInt8 *EmulationJoypadPtr;
extern UInt8 EmulationJoypad[4];
extern UInt8 EmulationJoypadOld; /* saved joypad value before user poll */
#endif
/* === Function prototypes in C part ================================== */
#ifdef __GNUC__ /* only if C preprocessing */
void EmulationGetEvent(void)
EMULATION_SECTION;
Boolean EmulationFormHandleEvent(EventType *evtP)
EMULATION_SECTION;
Boolean EmulationUserPoll(void)
EMULATION_SECTION;
Boolean EmulationSetupAll(void)
EMULATION_SECTION;
Boolean EmulationSetup(void)
EMULATION_SECTION;
void EmulationCleanup(void)
EMULATION_SECTION;
void EmulationResetState(void *recP, UInt32 offset)
EMULATION_SECTION;
void EmulationLoadState(const EmulationStateType *stateP)
EMULATION_SECTION;
void EmulationSaveState(void *recP, UInt32 offset)
EMULATION_SECTION;
#endif
/* === Function prototypes in assembler part ========================== */
#ifdef __GNUC__ /* only if C preprocessing */
void EmulationStartKernel(void)
EMULATION_SECTION;
/* NOTE:
* These functions are called from the emulation and get their parameters
* via several registers. This is not documented here, the prototypes are
* just for exporting the names.
*/
void EmulationOpcodeStop(void)
EMULATION_SECTION;
#endif
/* === The end ======================================================== */
#endif