all repos — mgba @ 6e467a0332446b2ac4c81f6cb63dc22e07792454

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