src/platform/qt/GameController.h (view raw)
1/* Copyright (c) 2013-2015 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef QGBA_GAME_CONTROLLER
7#define QGBA_GAME_CONTROLLER
8
9#include <QFile>
10#include <QImage>
11#include <QObject>
12#include <QMutex>
13#include <QString>
14
15extern "C" {
16#include "gba/cheats.h"
17#include "gba/hardware.h"
18#include "gba/supervisor/thread.h"
19#ifdef BUILD_SDL
20#include "sdl-events.h"
21#endif
22}
23
24struct GBAAudio;
25struct GBAOptions;
26struct GBAVideoSoftwareRenderer;
27struct Configuration;
28
29class QThread;
30
31namespace QGBA {
32
33class AudioProcessor;
34class InputController;
35
36class GameController : public QObject {
37Q_OBJECT
38
39public:
40 static const bool VIDEO_SYNC = false;
41 static const bool AUDIO_SYNC = true;
42
43 GameController(QObject* parent = nullptr);
44 ~GameController();
45
46 const uint32_t* drawContext() const { return m_drawContext; }
47 GBAThread* thread() { return &m_threadContext; }
48 GBACheatDevice* cheatDevice() { return &m_cheatDevice; }
49
50 void threadInterrupt();
51 void threadContinue();
52
53 bool isPaused();
54 bool isLoaded() { return m_gameOpen; }
55
56 bool audioSync() const { return m_audioSync; }
57 bool videoSync() const { return m_videoSync; }
58
59 void setInputController(InputController* controller) { m_inputController = controller; }
60 void setOverrides(Configuration* overrides) { m_threadContext.overrides = overrides; }
61
62 void setOverride(const GBACartridgeOverride& override);
63 void clearOverride() { m_threadContext.hasOverride = false; }
64
65 void setOptions(const GBAOptions*);
66
67#ifdef USE_GDB_STUB
68 ARMDebugger* debugger();
69 void setDebugger(ARMDebugger*);
70#endif
71
72signals:
73 void frameAvailable(const uint32_t*);
74 void gameStarted(GBAThread*);
75 void gameStopped(GBAThread*);
76 void gamePaused(GBAThread*);
77 void gameUnpaused(GBAThread*);
78 void gameCrashed(const QString& errorMessage);
79 void gameFailed();
80 void stateLoaded(GBAThread*);
81
82 void luminanceValueChanged(int);
83
84 void postLog(int level, const QString& log);
85
86public slots:
87 void loadGame(const QString& path, bool dirmode = false);
88 void loadBIOS(const QString& path);
89 void setSkipBIOS(bool);
90 void loadPatch(const QString& path);
91 void openGame();
92 void closeGame();
93 void setPaused(bool paused);
94 void reset();
95 void frameAdvance();
96 void setRewind(bool enable, int capacity, int interval);
97 void rewind(int states = 0);
98 void keyPressed(int key);
99 void keyReleased(int key);
100 void clearKeys();
101 void setAudioBufferSamples(int samples);
102 void setFPSTarget(float fps);
103 void loadState(int slot);
104 void saveState(int slot);
105 void setVideoSync(bool);
106 void setAudioSync(bool);
107 void setFrameskip(int);
108 void setTurbo(bool, bool forced = true);
109 void setAVStream(GBAAVStream*);
110 void clearAVStream();
111 void reloadAudioDriver();
112
113 void setLuminanceValue(uint8_t value);
114 uint8_t luminanceValue() const { return m_luxValue; }
115 void setLuminanceLevel(int level);
116 void increaseLuminanceLevel() { setLuminanceLevel(m_luxLevel + 1); }
117 void decreaseLuminanceLevel() { setLuminanceLevel(m_luxLevel - 1); }
118
119 void setRealTime();
120 void setFixedTime(const QDateTime& time);
121 void setFakeEpoch(const QDateTime& time);
122
123 void setLogLevel(int);
124 void enableLogLevel(int);
125 void disableLogLevel(int);
126
127private slots:
128 void crashGame(const QString& crashMessage);
129
130#ifdef BUILD_SDL
131 void testSDLEvents();
132
133private:
134 GBASDLEvents m_sdlEvents;
135 int m_activeButtons;
136#endif
137
138private:
139 void updateKeys();
140 void redoSamples(int samples);
141
142 uint32_t* m_drawContext;
143 GBAThread m_threadContext;
144 GBAVideoSoftwareRenderer* m_renderer;
145 GBACheatDevice m_cheatDevice;
146 int m_activeKeys;
147 int m_logLevels;
148
149 bool m_gameOpen;
150 bool m_dirmode;
151
152 QString m_fname;
153 QString m_bios;
154 QString m_patch;
155
156 QThread* m_audioThread;
157 AudioProcessor* m_audioProcessor;
158
159 QMutex m_pauseMutex;
160 bool m_pauseAfterFrame;
161
162 bool m_videoSync;
163 bool m_audioSync;
164 bool m_turbo;
165 bool m_turboForced;
166
167 InputController* m_inputController;
168
169 struct GameControllerLux : GBALuminanceSource {
170 GameController* p;
171 uint8_t value;
172 } m_lux;
173 uint8_t m_luxValue;
174 int m_luxLevel;
175
176 static const int LUX_LEVELS[10];
177
178 struct GameControllerRTC : GBARTCSource {
179 GameController* p;
180 enum {
181 NO_OVERRIDE,
182 FIXED,
183 FAKE_EPOCH
184 } override;
185 int64_t value;
186 } m_rtc;
187};
188
189}
190
191#endif