all repos — mgba @ f33e9c060f89e68d9501d0c2c548e571bdafc5f1

mGBA Game Boy Advance Emulator

src/platform/qt/GameController.h (view raw)

  1/* Copyright (c) 2013-2014 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-sensors.h"
 17#include "gba-thread.h"
 18#ifdef BUILD_SDL
 19#include "sdl-events.h"
 20#endif
 21}
 22
 23struct GBAAudio;
 24struct GBAVideoSoftwareRenderer;
 25struct Configuration;
 26
 27class QThread;
 28
 29namespace QGBA {
 30
 31class AudioProcessor;
 32class InputController;
 33
 34class GameController : public QObject {
 35Q_OBJECT
 36
 37public:
 38	static const bool VIDEO_SYNC = false;
 39	static const bool AUDIO_SYNC = true;
 40
 41	GameController(QObject* parent = nullptr);
 42	~GameController();
 43
 44	const uint32_t* drawContext() const { return m_drawContext; }
 45	GBAThread* thread() { return &m_threadContext; }
 46
 47	void threadInterrupt();
 48	void threadContinue();
 49
 50	bool isPaused();
 51	bool isLoaded() { return m_gameOpen; }
 52
 53	bool audioSync() const { return m_audioSync; }
 54	bool videoSync() const { return m_videoSync; }
 55
 56	void setInputController(InputController* controller) { m_inputController = controller; }
 57	void setOverrides(Configuration* overrides) { m_threadContext.overrides = overrides; }
 58
 59	void setOverride(const GBACartridgeOverride& override);
 60	void clearOverride() { m_threadContext.hasOverride = false; }
 61
 62#ifdef USE_GDB_STUB
 63	ARMDebugger* debugger();
 64	void setDebugger(ARMDebugger*);
 65#endif
 66
 67signals:
 68	void frameAvailable(const uint32_t*);
 69	void gameStarted(GBAThread*);
 70	void gameStopped(GBAThread*);
 71	void gamePaused(GBAThread*);
 72	void gameUnpaused(GBAThread*);
 73	void gameCrashed(const QString& errorMessage);
 74	void gameFailed();
 75	void stateLoaded(GBAThread*);
 76
 77	void postLog(int level, const QString& log);
 78
 79public slots:
 80	void loadGame(const QString& path, bool dirmode = false);
 81	void loadBIOS(const QString& path);
 82	void setSkipBIOS(bool);
 83	void loadPatch(const QString& path);
 84	void openGame();
 85	void closeGame();
 86	void setPaused(bool paused);
 87	void reset();
 88	void frameAdvance();
 89	void setRewind(bool enable, int capacity, int interval);
 90	void rewind(int states = 0);
 91	void keyPressed(int key);
 92	void keyReleased(int key);
 93	void clearKeys();
 94	void setAudioBufferSamples(int samples);
 95	void setFPSTarget(float fps);
 96	void loadState(int slot);
 97	void saveState(int slot);
 98	void setVideoSync(bool);
 99	void setAudioSync(bool);
100	void setFrameskip(int);
101	void setTurbo(bool, bool forced = true);
102	void setAVStream(GBAAVStream*);
103	void clearAVStream();
104
105	void setLuminanceValue(uint8_t value);
106	void setLuminanceLevel(int level);
107	void increaseLuminanceLevel() { setLuminanceLevel(m_luxLevel + 1); }
108	void decreaseLuminanceLevel() { setLuminanceLevel(m_luxLevel - 1); }
109
110	void setRealTime();
111	void setFixedTime(const QDateTime& time);
112	void setFakeEpoch(const QDateTime& time);
113
114	void setLogLevel(int);
115	void enableLogLevel(int);
116	void disableLogLevel(int);
117
118private slots:
119	void crashGame(const QString& crashMessage);
120
121#ifdef BUILD_SDL
122	void testSDLEvents();
123
124private:
125	GBASDLEvents m_sdlEvents;
126	int m_activeButtons;
127#endif
128
129private:
130	void updateKeys();
131	void redoSamples(int samples);
132
133	uint32_t* m_drawContext;
134	GBAThread m_threadContext;
135	GBAVideoSoftwareRenderer* m_renderer;
136	int m_activeKeys;
137	int m_logLevels;
138
139	bool m_gameOpen;
140	bool m_dirmode;
141
142	QString m_fname;
143	QString m_bios;
144	QString m_patch;
145
146	QThread* m_audioThread;
147	AudioProcessor* m_audioProcessor;
148
149	QMutex m_pauseMutex;
150	bool m_pauseAfterFrame;
151
152	bool m_videoSync;
153	bool m_audioSync;
154	bool m_turbo;
155	bool m_turboForced;
156
157	InputController* m_inputController;
158
159	struct GameControllerLux : GBALuminanceSource {
160		GameController* p;
161		uint8_t value;
162	} m_lux;
163	uint8_t m_luxValue;
164	int m_luxLevel;
165
166	static const int LUX_LEVELS[10];
167
168	struct GameControllerRTC : GBARTCSource {
169		GameController* p;
170		enum {
171			NO_OVERRIDE,
172			FIXED,
173			FAKE_EPOCH
174		} override;
175		int64_t value;
176	} m_rtc;
177};
178
179}
180
181#endif