all repos — mgba @ b677d41469cb4fc0cced47c69729ecf3681e927b

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