all repos — mgba @ 7149dd3102a6bbb7f73cae7da0c01dc784b0f601

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