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 postLog(int level, const QString& log);
83
84public slots:
85 void loadGame(const QString& path, bool dirmode = false);
86 void loadBIOS(const QString& path);
87 void setSkipBIOS(bool);
88 void loadPatch(const QString& path);
89 void openGame();
90 void closeGame();
91 void setPaused(bool paused);
92 void reset();
93 void frameAdvance();
94 void setRewind(bool enable, int capacity, int interval);
95 void rewind(int states = 0);
96 void keyPressed(int key);
97 void keyReleased(int key);
98 void clearKeys();
99 void setAudioBufferSamples(int samples);
100 void setFPSTarget(float fps);
101 void loadState(int slot);
102 void saveState(int slot);
103 void setVideoSync(bool);
104 void setAudioSync(bool);
105 void setFrameskip(int);
106 void setTurbo(bool, bool forced = true);
107 void setAVStream(GBAAVStream*);
108 void clearAVStream();
109
110 void setLuminanceValue(uint8_t value);
111 void setLuminanceLevel(int level);
112 void increaseLuminanceLevel() { setLuminanceLevel(m_luxLevel + 1); }
113 void decreaseLuminanceLevel() { setLuminanceLevel(m_luxLevel - 1); }
114
115 void setRealTime();
116 void setFixedTime(const QDateTime& time);
117 void setFakeEpoch(const QDateTime& time);
118
119 void setLogLevel(int);
120 void enableLogLevel(int);
121 void disableLogLevel(int);
122
123private slots:
124 void crashGame(const QString& crashMessage);
125
126#ifdef BUILD_SDL
127 void testSDLEvents();
128
129private:
130 GBASDLEvents m_sdlEvents;
131 int m_activeButtons;
132#endif
133
134private:
135 void updateKeys();
136 void redoSamples(int samples);
137
138 uint32_t* m_drawContext;
139 GBAThread m_threadContext;
140 GBAVideoSoftwareRenderer* m_renderer;
141 GBACheatDevice m_cheatDevice;
142 int m_activeKeys;
143 int m_logLevels;
144
145 bool m_gameOpen;
146 bool m_dirmode;
147
148 QString m_fname;
149 QString m_bios;
150 QString m_patch;
151
152 QThread* m_audioThread;
153 AudioProcessor* m_audioProcessor;
154
155 QMutex m_pauseMutex;
156 bool m_pauseAfterFrame;
157
158 bool m_videoSync;
159 bool m_audioSync;
160 bool m_turbo;
161 bool m_turboForced;
162
163 InputController* m_inputController;
164
165 struct GameControllerLux : GBALuminanceSource {
166 GameController* p;
167 uint8_t value;
168 } m_lux;
169 uint8_t m_luxValue;
170 int m_luxLevel;
171
172 static const int LUX_LEVELS[10];
173
174 struct GameControllerRTC : GBARTCSource {
175 GameController* p;
176 enum {
177 NO_OVERRIDE,
178 FIXED,
179 FAKE_EPOCH
180 } override;
181 int64_t value;
182 } m_rtc;
183};
184
185}
186
187#endif