all repos — mgba @ 8266f54d7674ec7fdbe263efea163481c8b33571

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