all repos — mgba @ 5b40951c05baa28ac43c84ffacfec6bd99692ed3

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