all repos — mgba @ d5241484693fd9d280470c9b0e8c703f068c9024

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