all repos — mgba @ 9c07698068ec289786178c36a273d0de588dcab0

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