all repos — mgba @ b51710e92f0d9050666a531c060c0c4343e3e13f

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 setAudioBufferSamples(int samples);
 86	void setFPSTarget(float fps);
 87	void loadState(int slot);
 88	void saveState(int slot);
 89	void setVideoSync(bool);
 90	void setAudioSync(bool);
 91	void setFrameskip(int);
 92	void setTurbo(bool, bool forced = true);
 93	void setAVStream(GBAAVStream*);
 94	void clearAVStream();
 95	void setLuminanceValue(uint8_t value) { m_luxValue = value; }
 96
 97	void setRealTime();
 98	void setFixedTime(const QDateTime& time);
 99	void setFakeEpoch(const QDateTime& time);
100
101	void setLogLevel(int);
102	void enableLogLevel(int);
103	void disableLogLevel(int);
104
105private slots:
106	void crashGame(const QString& crashMessage);
107
108#ifdef BUILD_SDL
109	void testSDLEvents();
110
111private:
112	GBASDLEvents m_sdlEvents;
113	int m_activeButtons;
114#endif
115
116private:
117	void updateKeys();
118	void redoSamples(int samples);
119
120	uint32_t* m_drawContext;
121	GBAThread m_threadContext;
122	GBAVideoSoftwareRenderer* m_renderer;
123	int m_activeKeys;
124	int m_logLevels;
125
126	bool m_gameOpen;
127	bool m_dirmode;
128
129	QString m_fname;
130	QString m_bios;
131	QString m_patch;
132
133	QThread* m_audioThread;
134	AudioProcessor* m_audioProcessor;
135
136	QMutex m_pauseMutex;
137	bool m_pauseAfterFrame;
138
139	bool m_videoSync;
140	bool m_audioSync;
141	bool m_turbo;
142	bool m_turboForced;
143
144	InputController* m_inputController;
145
146	struct GameControllerLux : GBALuminanceSource {
147		GameController* p;
148		uint8_t value;
149	} m_lux;
150	uint8_t m_luxValue;
151
152	struct GameControllerRTC : GBARTCSource {
153		GameController* p;
154		enum {
155			NO_OVERRIDE,
156			FIXED,
157			FAKE_EPOCH
158		} override;
159		int64_t value;
160	} m_rtc;
161};
162
163}
164
165#endif