all repos — mgba @ d6e24b20515510fab670f40b8d657cc43adc17fe

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