all repos — mgba @ df11c9d7f31dbb261747281b793a70a723b21b47

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#ifdef USE_GDB_STUB
 76	ARMDebugger* debugger();
 77	void setDebugger(ARMDebugger*);
 78#endif
 79
 80signals:
 81	void frameAvailable(const uint32_t*);
 82	void gameStarted(GBAThread*);
 83	void gameStopped(GBAThread*);
 84	void gamePaused(GBAThread*);
 85	void gameUnpaused(GBAThread*);
 86	void gameCrashed(const QString& errorMessage);
 87	void gameFailed();
 88	void stateLoaded(GBAThread*);
 89	void rewound(GBAThread*);
 90	void unimplementedBiosCall(int);
 91
 92	void luminanceValueChanged(int);
 93
 94	void statusPosted(const QString& message);
 95	void postLog(int level, const QString& log);
 96
 97public slots:
 98	void loadGame(const QString& path, bool dirmode = false);
 99	void loadBIOS(const QString& path);
100	void yankPak();
101	void replaceGame(const QString& path);
102	void setSkipBIOS(bool);
103	void setUseBIOS(bool);
104	void loadPatch(const QString& path);
105	void importSharkport(const QString& path);
106	void exportSharkport(const QString& path);
107	void bootBIOS();
108	void closeGame();
109	void setPaused(bool paused);
110	void reset();
111	void frameAdvance();
112	void setRewind(bool enable, int capacity, int interval);
113	void rewind(int states = 0);
114	void startRewinding();
115	void stopRewinding();
116	void keyPressed(int key);
117	void keyReleased(int key);
118	void clearKeys();
119	void setAudioBufferSamples(int samples);
120	void setAudioChannelEnabled(int channel, bool enable = true);
121	void setVideoLayerEnabled(int layer, bool enable = true);
122	void setFPSTarget(float fps);
123	void loadState(int slot = 0);
124	void saveState(int slot = 0);
125	void loadBackupState();
126	void saveBackupState();
127	void setVideoSync(bool);
128	void setAudioSync(bool);
129	void setFrameskip(int);
130	void setVolume(int);
131	void setMute(bool);
132	void setTurbo(bool, bool forced = true);
133	void setTurboSpeed(float ratio = -1);
134	void setAVStream(GBAAVStream*);
135	void clearAVStream();
136	void reloadAudioDriver();
137
138#ifdef USE_PNG
139	void screenshot();
140#endif
141
142	void setLuminanceValue(uint8_t value);
143	uint8_t luminanceValue() const { return m_luxValue; }
144	void setLuminanceLevel(int level);
145	void increaseLuminanceLevel() { setLuminanceLevel(m_luxLevel + 1); }
146	void decreaseLuminanceLevel() { setLuminanceLevel(m_luxLevel - 1); }
147
148	void setRealTime();
149	void setFixedTime(const QDateTime& time);
150	void setFakeEpoch(const QDateTime& time);
151
152	void setLogLevel(int);
153	void enableLogLevel(int);
154	void disableLogLevel(int);
155
156private slots:
157	void openGame(bool bios = false);
158	void crashGame(const QString& crashMessage);
159
160	void pollEvents();
161
162private:
163	void updateKeys();
164	void redoSamples(int samples);
165	void enableTurbo();
166
167	uint32_t* m_drawContext;
168	GBAThread m_threadContext;
169	GBAVideoSoftwareRenderer* m_renderer;
170	GBACheatDevice m_cheatDevice;
171	int m_activeKeys;
172	int m_activeButtons;
173	int m_inactiveKeys;
174	int m_logLevels;
175
176	bool m_gameOpen;
177	bool m_dirmode;
178
179	QString m_fname;
180	QString m_bios;
181	bool m_useBios;
182	QString m_patch;
183
184	QThread* m_audioThread;
185	AudioProcessor* m_audioProcessor;
186
187	QAtomicInt m_pauseAfterFrame;
188
189	bool m_videoSync;
190	bool m_audioSync;
191	float m_fpsTarget;
192	bool m_turbo;
193	bool m_turboForced;
194	float m_turboSpeed;
195	QTimer m_rewindTimer;
196	bool m_wasPaused;
197
198	bool m_audioChannels[6];
199	bool m_videoLayers[5];
200
201	int m_stateSlot;
202	GBASerializedState* m_backupLoadState;
203	QByteArray m_backupSaveState;
204
205	InputController* m_inputController;
206	MultiplayerController* m_multiplayer;
207
208	struct GameControllerLux : GBALuminanceSource {
209		GameController* p;
210		uint8_t value;
211	} m_lux;
212	uint8_t m_luxValue;
213	int m_luxLevel;
214
215	GBARTCGenericSource m_rtc;
216};
217
218}
219
220#endif