-
-
Notifications
You must be signed in to change notification settings - Fork 745
/
CoreController.h
254 lines (192 loc) · 5.5 KB
/
CoreController.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
/* Copyright (c) 2013-2017 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#pragma once
#include <QByteArray>
#include <QList>
#include <QMutex>
#include <QObject>
#include <QSize>
#include "VFileDevice.h"
#include <functional>
#include <memory>
#include <mgba/core/core.h>
#include <mgba/core/interface.h>
#include <mgba/core/thread.h>
#include <mgba/core/cache-set.h>
#ifdef M_CORE_GB
#include <mgba/internal/gb/sio/printer.h>
#endif
#ifdef M_CORE_GBA
#include <mgba/gba/interface.h>
#endif
struct mCore;
namespace QGBA {
class ConfigController;
class InputController;
class LogController;
class MultiplayerController;
class Override;
class CoreController : public QObject {
Q_OBJECT
public:
static const bool VIDEO_SYNC = false;
static const bool AUDIO_SYNC = true;
enum class Feature {
OPENGL = mCORE_FEATURE_OPENGL,
};
class Interrupter {
public:
Interrupter(CoreController*, bool fromThread = false);
Interrupter(std::shared_ptr<CoreController>, bool fromThread = false);
Interrupter(const Interrupter&);
~Interrupter();
private:
CoreController* m_parent;
};
CoreController(mCore* core, QObject* parent = nullptr);
~CoreController();
mCoreThread* thread() { return &m_threadContext; }
const color_t* drawContext();
bool isPaused();
bool hasStarted();
mPlatform platform() const;
QSize screenDimensions() const;
bool supportsFeature(Feature feature) const { return m_threadContext.core->supportsFeature(m_threadContext.core, static_cast<mCoreFeature>(feature)); }
bool hardwareAccelerated() const { return m_hwaccel; }
void loadConfig(ConfigController*);
mCheatDevice* cheatDevice() { return m_threadContext.core->cheatDevice(m_threadContext.core); }
#ifdef USE_DEBUGGERS
mDebugger* debugger() { return m_threadContext.core->debugger; }
void setDebugger(mDebugger*);
#endif
void setMultiplayerController(MultiplayerController*);
void clearMultiplayerController();
MultiplayerController* multiplayerController() { return m_multiplayer; }
mCacheSet* graphicCaches();
int stateSlot() const { return m_stateSlot; }
void setOverride(std::unique_ptr<Override> override);
Override* override() { return m_override.get(); }
void setInputController(InputController*);
void setLogger(LogController*);
public slots:
void start();
void stop();
void reset();
void setPaused(bool paused);
void frameAdvance();
void setSync(bool enable);
void setRewinding(bool);
void rewind(int count = 0);
void setFastForward(bool);
void forceFastForward(bool);
void loadState(int slot = 0);
void loadState(const QString& path);
void saveState(int slot = 0);
void saveState(const QString& path);
void loadBackupState();
void saveBackupState();
void loadSave(const QString&, bool temporary);
void loadPatch(const QString&);
void replaceGame(const QString&);
void yankPak();
void addKey(int key);
void clearKey(int key);
void setAutofire(int key, bool enable);
#ifdef USE_PNG
void screenshot();
#endif
void setRealTime();
void setFixedTime(const QDateTime& time);
void setFakeEpoch(const QDateTime& time);
void importSharkport(const QString& path);
void exportSharkport(const QString& path);
#ifdef M_CORE_GB
void attachPrinter();
void detachPrinter();
void endPrint();
#endif
#ifdef M_CORE_GBA
void attachBattleChipGate();
void detachBattleChipGate();
void setBattleChipId(uint16_t id);
void setBattleChipFlavor(int flavor);
#endif
void setAVStream(mAVStream*);
void clearAVStream();
void clearOverride();
void startVideoLog(const QString& path);
void endVideoLog();
void setFramebufferHandle(int fb);
signals:
void started();
void paused();
void unpaused();
void stopping();
void crashed(const QString& errorMessage);
void failed();
void frameAvailable();
void didReset();
void stateLoaded();
void rewound();
void rewindChanged(bool);
void fastForwardChanged(bool);
void unimplementedBiosCall(int);
void statusPosted(const QString& message);
void logPosted(int level, int category, const QString& log);
void imagePrinted(const QImage&);
private:
void updateKeys();
int updateAutofire();
void finishFrame();
void updateFastForward();
mCoreThread m_threadContext{};
bool m_patched = false;
QByteArray m_buffers[2];
QByteArray* m_activeBuffer;
QByteArray m_completeBuffer;
bool m_hwaccel = false;
std::unique_ptr<mCacheSet> m_cacheSet;
std::unique_ptr<Override> m_override;
QList<std::function<void()>> m_resetActions;
QList<std::function<void()>> m_frameActions;
QMutex m_mutex;
int m_activeKeys = 0;
bool m_autofire[32] = {};
int m_autofireStatus[32] = {};
int m_autofireThreshold = 1;
VFileDevice m_backupLoadState;
QByteArray m_backupSaveState{nullptr};
int m_stateSlot = 1;
QString m_statePath;
int m_loadStateFlags;
int m_saveStateFlags;
bool m_audioSync = AUDIO_SYNC;
bool m_videoSync = VIDEO_SYNC;
bool m_autosave;
bool m_autoload;
int m_autosaveCounter;
int m_fastForward = false;
int m_fastForwardForced = false;
int m_fastForwardVolume = -1;
int m_fastForwardMute = -1;
float m_fastForwardRatio = -1.f;
float m_fpsTarget;
InputController* m_inputController = nullptr;
LogController* m_log = nullptr;
MultiplayerController* m_multiplayer = nullptr;
mVideoLogContext* m_vl = nullptr;
VFile* m_vlVf = nullptr;
#ifdef M_CORE_GB
struct QGBPrinter {
GBPrinter d;
CoreController* parent;
} m_printer;
#endif
#ifdef M_CORE_GBA
GBASIOBattlechipGate m_battlechip;
#endif
};
}