all repos — mgba @ 4f1788b2e05744fbb6e5ee24af3d02e2ba2304ba

mGBA Game Boy Advance Emulator

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 <QAtomicInt>
 10#include <QFile>
 11#include <QImage>
 12#include <QObject>
 13#include <QString>
 14#include <QTimer>
 15
 16#include <memory>
 17
 18extern "C" {
 19#include "gba/cheats.h"
 20#include "gba/hardware.h"
 21#include "gba/supervisor/thread.h"
 22#ifdef BUILD_SDL
 23#include "sdl-events.h"
 24#endif
 25}
 26
 27struct GBAAudio;
 28struct GBAOptions;
 29struct GBAVideoSoftwareRenderer;
 30struct Configuration;
 31
 32class QThread;
 33
 34namespace QGBA {
 35
 36class AudioProcessor;
 37class InputController;
 38class MultiplayerController;
 39
 40class GameController : public QObject {
 41Q_OBJECT
 42
 43public:
 44	static const bool VIDEO_SYNC = false;
 45	static const bool AUDIO_SYNC = true;
 46
 47	GameController(QObject* parent = nullptr);
 48	~GameController();
 49
 50	const uint32_t* drawContext() const { return m_drawContext; }
 51	GBAThread* thread() { return &m_threadContext; }
 52	GBACheatDevice* cheatDevice() { return &m_cheatDevice; }
 53
 54	void threadInterrupt();
 55	void threadContinue();
 56
 57	bool isPaused();
 58	bool isLoaded() { return m_gameOpen && GBAThreadIsActive(&m_threadContext); }
 59
 60	bool audioSync() const { return m_audioSync; }
 61	bool videoSync() const { return m_videoSync; }
 62
 63	void setInputController(InputController* controller) { m_inputController = controller; }
 64	void setOverrides(Configuration* overrides) { m_threadContext.overrides = overrides; }
 65
 66	void setMultiplayerController(MultiplayerController* controller);
 67	MultiplayerController* multiplayerController() { return m_multiplayer; }
 68	void clearMultiplayerController();
 69
 70	void setOverride(const GBACartridgeOverride& override);
 71	void clearOverride() { m_threadContext.hasOverride = false; }
 72
 73	void setOptions(const GBAOptions*);
 74
 75	int stateSlot() const { return m_stateSlot; }
 76
 77#ifdef USE_GDB_STUB
 78	ARMDebugger* debugger();
 79	void setDebugger(ARMDebugger*);
 80#endif
 81
 82signals:
 83	void frameAvailable(const uint32_t*);
 84	void gameStarted(GBAThread*);
 85	void gameStopped(GBAThread*);
 86	void gamePaused(GBAThread*);
 87	void gameUnpaused(GBAThread*);
 88	void gameCrashed(const QString& errorMessage);
 89	void gameFailed();
 90	void stateLoaded(GBAThread*);
 91	void rewound(GBAThread*);
 92	void unimplementedBiosCall(int);
 93
 94	void luminanceValueChanged(int);
 95
 96	void statusPosted(const QString& message);
 97	void postLog(int level, const QString& log);
 98
 99public slots:
100	void loadGame(const QString& path);
101	void loadBIOS(const QString& path);
102	void yankPak();
103	void replaceGame(const QString& path);
104	void setSkipBIOS(bool);
105	void setUseBIOS(bool);
106	void loadPatch(const QString& path);
107	void importSharkport(const QString& path);
108	void exportSharkport(const QString& path);
109	void bootBIOS();
110	void closeGame();
111	void setPaused(bool paused);
112	void reset();
113	void frameAdvance();
114	void setRewind(bool enable, int capacity, int interval);
115	void rewind(int states = 0);
116	void startRewinding();
117	void stopRewinding();
118	void keyPressed(int key);
119	void keyReleased(int key);
120	void clearKeys();
121	void setAutofire(int key, bool enable);
122	void setAudioBufferSamples(int samples);
123	void setAudioSampleRate(unsigned rate);
124	void setAudioChannelEnabled(int channel, bool enable = true);
125	void setVideoLayerEnabled(int layer, bool enable = true);
126	void setFPSTarget(float fps);
127	void loadState(int slot = 0);
128	void saveState(int slot = 0);
129	void loadBackupState();
130	void saveBackupState();
131	void setVideoSync(bool);
132	void setAudioSync(bool);
133	void setFrameskip(int);
134	void setVolume(int);
135	void setMute(bool);
136	void setTurbo(bool, bool forced = true);
137	void setTurboSpeed(float ratio = -1);
138	void setAVStream(GBAAVStream*);
139	void clearAVStream();
140	void reloadAudioDriver();
141	void setSaveStateExtdata(int flags);
142	void setLoadStateExtdata(int flags);
143
144#ifdef USE_PNG
145	void screenshot();
146#endif
147
148	void setLuminanceValue(uint8_t value);
149	uint8_t luminanceValue() const { return m_luxValue; }
150	void setLuminanceLevel(int level);
151	void increaseLuminanceLevel() { setLuminanceLevel(m_luxLevel + 1); }
152	void decreaseLuminanceLevel() { setLuminanceLevel(m_luxLevel - 1); }
153
154	void setRealTime();
155	void setFixedTime(const QDateTime& time);
156	void setFakeEpoch(const QDateTime& time);
157
158	void setLogLevel(int);
159	void enableLogLevel(int);
160	void disableLogLevel(int);
161
162private slots:
163	void openGame(bool bios = false);
164	void crashGame(const QString& crashMessage);
165
166	void pollEvents();
167	void updateAutofire();
168
169private:
170	void updateKeys();
171	void redoSamples(int samples);
172	void enableTurbo();
173
174	uint32_t* m_drawContext;
175	uint32_t* m_frontBuffer;
176	GBAThread m_threadContext;
177	GBAVideoSoftwareRenderer* m_renderer;
178	GBACheatDevice m_cheatDevice;
179	int m_activeKeys;
180	int m_activeButtons;
181	int m_inactiveKeys;
182	int m_logLevels;
183
184	bool m_gameOpen;
185
186	QString m_fname;
187	QString m_bios;
188	bool m_useBios;
189	QString m_patch;
190
191	QThread* m_audioThread;
192	AudioProcessor* m_audioProcessor;
193
194	QAtomicInt m_pauseAfterFrame;
195
196	bool m_videoSync;
197	bool m_audioSync;
198	float m_fpsTarget;
199	bool m_turbo;
200	bool m_turboForced;
201	float m_turboSpeed;
202	QTimer m_rewindTimer;
203	bool m_wasPaused;
204
205	bool m_audioChannels[6];
206	bool m_videoLayers[5];
207
208	bool m_autofire[GBA_KEY_MAX];
209	int m_autofireStatus[GBA_KEY_MAX];
210
211	int m_stateSlot;
212	GBASerializedState* m_backupLoadState;
213	QByteArray m_backupSaveState;
214	int m_saveStateFlags;
215	int m_loadStateFlags;
216
217	InputController* m_inputController;
218	MultiplayerController* m_multiplayer;
219
220	struct GameControllerLux : GBALuminanceSource {
221		GameController* p;
222		uint8_t value;
223	} m_lux;
224	uint8_t m_luxValue;
225	int m_luxLevel;
226
227	GBARTCGenericSource m_rtc;
228};
229
230}
231
232#endif