-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathvbaFunctions.cpp
296 lines (252 loc) · 8.19 KB
/
vbaFunctions.cpp
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#include "vbam/System.h"
#include "VirtualControllerInput.h"
#include "KeyboardInput.h"
#include "ControllerInput.h"
#include "Emulator.h"
#include "EmulatorSettings.h"
#include "HIDControllerInput.h"
using namespace VBA10;
void log(const char *,...) { }
bool systemPauseOnFrame() { return false; }
void systemGbPrint(u8 *,int,int,int,int) { }
void systemScreenCapture(int) { }
// updates the joystick data
bool systemReadJoypads() { return true; }
u32 systemGetClock() { return (u32) GetTickCount64(); }
void systemMessage(int, const char *, ...) { }
void systemSetTitle(const char *) { }
void systemWriteDataToSoundBuffer() { }
void systemSoundShutdown() { }
void systemSoundPause() { }
void systemSoundResume() { }
void systemSoundReset() { }
//SoundDriver *systemSoundInit() { return NULL; }
void systemScreenMessage(const char *) { }
void systemUpdateMotionSensor() { }
int systemGetSensorX() { return 0; }
int systemGetSensorY() { return 0; }
bool systemCanChangeSoundQuality() { return false; }
void systemShowSpeed(int){ }
void system10Frames(int){ }
void systemFrame(){ }
void systemGbBorderOn(){ }
void winlog(const char *, ...) { }
void systemOnWriteDataToSoundBuffer(const u16 * finalWave, int length) { }
void systemOnSoundShutdown() { }
extern SoundDriver *newXAudio2_Output();
extern void soundShutdown();
void systemGbPrint(unsigned char *, int, int, int, int, int) { }
SoundDriver * systemSoundInit()
{
SoundDriver * drv = 0;
soundShutdown();
if(SoundEnabled())
{
drv = newXAudio2_Output();
}
return drv;
}
ControllerState oldKeyboardState;
ControllerState oldControllerState;
ControllerState oldvControllerState;
ControllerState oldHidState;
long long AUnpressedTime = 9999999999;
long long BUnpressedTime = 9999999999;
long long LUnpressedTime = 9999999999;
long long RUnpressedTime = 9999999999;
long long LeftUnpressedTime = 9999999999;
long long RightUnpressedTime = 9999999999;
long long UpUnpressedTime = 9999999999;
long long DownUnpressedTime = 9999999999;
u32 systemReadJoypad(int gamepad)
{
u32 res = 0;
EmulatorGame *emulator = EmulatorGame::GetInstance();
KeyboardInput *keyboard = emulator->GetKeyboardInput();
#ifndef NO_XBOX
ControllerInput *controller = emulator->GetControllerInput();
#endif
HIDControllerInput ^hidController = emulator->GetHidControllerInput();
VirtualControllerInput *vController = VirtualControllerInput::GetInstance();
if (
#ifndef NO_XBOX
!controller ||
#endif
!vController || !keyboard)
return res;
//const ControllerState *state = controller->GetControllerState();
const ControllerState *keyboardState = keyboard->GetControllerState();
#ifndef NO_XBOX
const ControllerState *controllerState = controller->GetControllerState();
#else
ControllerState controllerState1 = { false, false, false, false, false, false, false, false, false, false, false, false, false, false };
const ControllerState *controllerState = &controllerState1;
#endif
const ControllerState *hidState = hidController->GetControllerState();
const ControllerState *vControllerState = vController->GetControllerState();
int smoothButton = EmulatorSettings::Current->SmoothButton;
if(keyboardState->APressed || controllerState->APressed || vControllerState->APressed || hidState->APressed)
{
res |= 1;
AUnpressedTime = 0; //reset to 0
}
else
{
if (AUnpressedTime < smoothButton) //if not pressed for less than 3 frames
res |= 1;
AUnpressedTime++;
}
if (keyboardState->BPressed || controllerState->BPressed || vControllerState->BPressed || hidState->BPressed)
{
res |= 2;
BUnpressedTime = 0; //reset to 0
}
else
{
if (BUnpressedTime < smoothButton) //if not pressed for less than 3 frames
res |= 2;
BUnpressedTime++;
}
if(keyboardState->SelectPressed || controllerState->SelectPressed || vControllerState->SelectPressed || hidState->SelectPressed)
res |= 4;
if(keyboardState->StartPressed || controllerState->StartPressed || vControllerState->StartPressed || hidState->StartPressed)
res |= 8;
if(keyboardState->RightPressed || controllerState->RightPressed || vControllerState->RightPressed || hidState->RightPressed)
{
res |= 16;
RightUnpressedTime = 0; //reset to 0
}
else
{
if (RightUnpressedTime < smoothButton) //if not pressed for less than 3 frames
res |= 16;
RightUnpressedTime++;
}
if(keyboardState->LeftPressed || controllerState->LeftPressed || vControllerState->LeftPressed || hidState->LeftPressed)
{
res |= 32;
LeftUnpressedTime = 0; //reset to 0
}
else
{
if (LeftUnpressedTime < smoothButton) //if not pressed for less than 3 frames
res |= 32;
LeftUnpressedTime++;
}
if(keyboardState->UpPressed || controllerState->UpPressed || vControllerState->UpPressed || hidState->UpPressed)
{
res |= 64;
UpUnpressedTime = 0; //reset to 0
}
else
{
if (UpUnpressedTime < smoothButton) //if not pressed for less than 3 frames
res |= 64;
UpUnpressedTime++;
}
if(keyboardState->DownPressed || controllerState->DownPressed || vControllerState->DownPressed || hidState->DownPressed)
{
res |= 128;
DownUnpressedTime = 0; //reset to 0
}
else
{
if (DownUnpressedTime < smoothButton) //if not pressed for less than 3 frames
res |= 128;
DownUnpressedTime++;
}
if(keyboardState->RPressed || controllerState->RPressed || vControllerState->RPressed || hidState->RPressed)
{
res |= 256;
RUnpressedTime = 0; //reset to 0
}
else
{
if (RUnpressedTime < smoothButton) //if not pressed for less than 3 frames
res |= 256;
RUnpressedTime++;
}
if(keyboardState->LPressed || controllerState->LPressed || vControllerState->LPressed || hidState->LPressed)
{
res |= 512;
LUnpressedTime = 0; //reset to 0
}
else
{
if (LUnpressedTime < smoothButton) //if not pressed for less than 3 frames
res |= 512;
LUnpressedTime++;
}
// disallow L+R or U+D of being pressed at the same time
if((res & 48) == 48)
res &= ~16;
if((res & 192) == 192)
res &= ~128;
// Speed
bool toggledThisUpdate = false;
if(!toggledThisUpdate)
{
if(!vControllerState->TurboTogglePressed && oldvControllerState.TurboTogglePressed)
{
EmulatorSettings::Current->EnableTurbo = !EmulatorSettings::Current->EnableTurbo;
toggledThisUpdate = true;
}
}
if(!toggledThisUpdate)
{
if(!keyboardState->TurboTogglePressed && oldKeyboardState.TurboTogglePressed)
{
EmulatorSettings::Current->EnableTurbo = !EmulatorSettings::Current->EnableTurbo;
toggledThisUpdate = true;
}
}
if(!toggledThisUpdate)
{
if(!controllerState->TurboTogglePressed && oldControllerState.TurboTogglePressed)
{
EmulatorSettings::Current->EnableTurbo = !EmulatorSettings::Current->EnableTurbo;
toggledThisUpdate = true;
}
}
if (!toggledThisUpdate)
{
if (!hidState->TurboTogglePressed && oldHidState.TurboTogglePressed)
{
EmulatorSettings::Current->EnableTurbo = !EmulatorSettings::Current->EnableTurbo;
toggledThisUpdate = true;
}
}
//if(EmulatorSettings::Current->EnableTurbo &&
// (oldKeyboardState.TurboPressed && !keyboardState->TurboPressed) ||
// (oldControllerState.TurboPressed && !controllerState->TurboPressed) ||
// (oldvControllerState.TurboPressed && !vControllerState->TurboPressed) ||
// (oldHidState.TurboPressed && !hidState->TurboPressed))
//{
// EmulatorSettings::Current->EnableTurbo = false;
//}
bool useTurbo = EmulatorSettings::Current->EnableTurbo;
//reverse function if turbopressed
if (keyboardState->TurboPressed || controllerState->TurboPressed || vControllerState->TurboPressed || hidState->TurboPressed)
useTurbo = !useTurbo;
if(useTurbo )
res |= 1024;
oldControllerState = *controllerState;
oldKeyboardState = *keyboardState;
oldvControllerState = *vControllerState;
oldHidState = *hidState;
return res;
}
int RGB_LOW_BITS_MASK = 65793;
int emulating;
bool systemSoundOn;
u16 systemColorMap16[0x10000];
u32 systemColorMap32[0x10000];
u16 systemGbPalette[24];
int systemRedShift;
int systemGreenShift;
int systemBlueShift;
int systemColorDepth;
int systemDebug;
int systemVerbose;
int systemFrameSkip;
int systemSaveUpdateCounter;