all repos — mgba @ 289e9b0cf12c5458afecfccdabf59f83f161214f

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