all repos — mgba @ c7593d7073069caa8b73ebff50d51aec8aafa06e

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#ifdef USE_GDB_STUB
 60	ARMDebugger* debugger();
 61	void setDebugger(ARMDebugger*);
 62#endif
 63
 64signals:
 65	void frameAvailable(const uint32_t*);
 66	void gameStarted(GBAThread*);
 67	void gameStopped(GBAThread*);
 68	void gamePaused(GBAThread*);
 69	void gameUnpaused(GBAThread*);
 70	void gameCrashed(const QString& errorMessage);
 71	void gameFailed();
 72	void stateLoaded(GBAThread*);
 73
 74	void postLog(int level, const QString& log);
 75
 76public slots:
 77	void loadGame(const QString& path, bool dirmode = false);
 78	void loadBIOS(const QString& path);
 79	void setSkipBIOS(bool);
 80	void loadPatch(const QString& path);
 81	void openGame();
 82	void closeGame();
 83	void setPaused(bool paused);
 84	void reset();
 85	void frameAdvance();
 86	void setRewind(bool enable, int capacity, int interval);
 87	void rewind(int states = 0);
 88	void keyPressed(int key);
 89	void keyReleased(int key);
 90	void clearKeys();
 91	void setAudioBufferSamples(int samples);
 92	void setFPSTarget(float fps);
 93	void loadState(int slot);
 94	void saveState(int slot);
 95	void setVideoSync(bool);
 96	void setAudioSync(bool);
 97	void setFrameskip(int);
 98	void setTurbo(bool, bool forced = true);
 99	void setAVStream(GBAAVStream*);
100	void clearAVStream();
101
102	void setLuminanceValue(uint8_t value);
103	void setLuminanceLevel(int level);
104	void increaseLuminanceLevel() { setLuminanceLevel(m_luxLevel + 1); }
105	void decreaseLuminanceLevel() { setLuminanceLevel(m_luxLevel - 1); }
106
107	void setRealTime();
108	void setFixedTime(const QDateTime& time);
109	void setFakeEpoch(const QDateTime& time);
110
111	void setLogLevel(int);
112	void enableLogLevel(int);
113	void disableLogLevel(int);
114
115private slots:
116	void crashGame(const QString& crashMessage);
117
118#ifdef BUILD_SDL
119	void testSDLEvents();
120
121private:
122	GBASDLEvents m_sdlEvents;
123	int m_activeButtons;
124#endif
125
126private:
127	void updateKeys();
128	void redoSamples(int samples);
129
130	uint32_t* m_drawContext;
131	GBAThread m_threadContext;
132	GBAVideoSoftwareRenderer* m_renderer;
133	int m_activeKeys;
134	int m_logLevels;
135
136	bool m_gameOpen;
137	bool m_dirmode;
138
139	QString m_fname;
140	QString m_bios;
141	QString m_patch;
142
143	QThread* m_audioThread;
144	AudioProcessor* m_audioProcessor;
145
146	QMutex m_pauseMutex;
147	bool m_pauseAfterFrame;
148
149	bool m_videoSync;
150	bool m_audioSync;
151	bool m_turbo;
152	bool m_turboForced;
153
154	InputController* m_inputController;
155
156	struct GameControllerLux : GBALuminanceSource {
157		GameController* p;
158		uint8_t value;
159	} m_lux;
160	uint8_t m_luxValue;
161	int m_luxLevel;
162
163	static const int LUX_LEVELS[10];
164
165	struct GameControllerRTC : GBARTCSource {
166		GameController* p;
167		enum {
168			NO_OVERRIDE,
169			FIXED,
170			FAKE_EPOCH
171		} override;
172		int64_t value;
173	} m_rtc;
174};
175
176}
177
178#endif