all repos — mgba @ df8cddb289bece5bd4ed0db9355048ecd006d12c

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