all repos — mgba @ 5e82d97b5b41609b29c67aa1aa0da5b3849fdb4a

mGBA Game Boy Advance Emulator

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

  1/* Copyright (c) 2013-2017 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#pragma once
  7
  8#include <QByteArray>
  9#include <QList>
 10#include <QMutex>
 11#include <QObject>
 12#include <QSize>
 13
 14#include "VFileDevice.h"
 15
 16#include <functional>
 17#include <memory>
 18
 19#include <mgba/core/core.h>
 20#include <mgba/core/interface.h>
 21#include <mgba/core/thread.h>
 22#include <mgba/core/cache-set.h>
 23
 24#ifdef M_CORE_GB
 25#include <mgba/internal/gb/sio/printer.h>
 26#endif
 27
 28struct mCore;
 29
 30namespace QGBA {
 31
 32class ConfigController;
 33class InputController;
 34class LogController;
 35class MultiplayerController;
 36class Override;
 37
 38class CoreController : public QObject {
 39Q_OBJECT
 40
 41public:
 42	static const bool VIDEO_SYNC = false;
 43	static const bool AUDIO_SYNC = true;
 44
 45	class Interrupter {
 46	public:
 47		Interrupter(CoreController*, bool fromThread = false);
 48		Interrupter(std::shared_ptr<CoreController>, bool fromThread = false);
 49		Interrupter(const Interrupter&);
 50		~Interrupter();
 51
 52	private:
 53		CoreController* m_parent;
 54	};
 55
 56	CoreController(mCore* core, QObject* parent = nullptr);
 57	~CoreController();
 58
 59	mCoreThread* thread() { return &m_threadContext; }
 60
 61	color_t* drawContext();
 62
 63	bool isPaused();
 64	bool hasStarted();
 65
 66	mPlatform platform() const;
 67	QSize screenDimensions() const;
 68	QPair<unsigned, unsigned> frameRate() const;
 69
 70	void loadConfig(ConfigController*);
 71
 72	mCheatDevice* cheatDevice() { return m_threadContext.core->cheatDevice(m_threadContext.core); }
 73
 74#ifdef USE_DEBUGGERS
 75	mDebugger* debugger() { return m_threadContext.core->debugger; }
 76	void setDebugger(mDebugger*);
 77#endif
 78
 79	void setMultiplayerController(MultiplayerController*);
 80	void clearMultiplayerController();
 81	MultiplayerController* multiplayerController() { return m_multiplayer; }
 82
 83	mCacheSet* graphicCaches();
 84	int stateSlot() const { return m_stateSlot; }
 85
 86	void setOverride(std::unique_ptr<Override> override);
 87	Override* override() { return m_override.get(); }
 88
 89	void setInputController(InputController*);
 90	void setLogger(LogController*);
 91
 92public slots:
 93	void start();
 94	void stop();
 95	void reset();
 96	void setPaused(bool paused);
 97	void frameAdvance();
 98	void setSync(bool enable);
 99
100	void setRewinding(bool);
101	void rewind(int count = 0);
102
103	void setFastForward(bool);
104	void forceFastForward(bool);
105
106	void loadState(int slot = 0);
107	void loadState(const QString& path);
108	void saveState(int slot = 0);
109	void saveState(const QString& path);
110	void loadBackupState();
111	void saveBackupState();
112
113	void loadSave(const QString&, bool temporary);
114	void loadPatch(const QString&);
115	void replaceGame(const QString&);
116	void yankPak();
117
118#ifdef USE_PNG
119	void screenshot();
120#endif
121
122	void setRealTime();
123	void setFixedTime(const QDateTime& time);
124	void setFakeEpoch(const QDateTime& time);
125
126	void importSharkport(const QString& path);
127	void exportSharkport(const QString& path);
128
129	void attachPrinter();
130	void detachPrinter();
131	void endPrint();
132
133	void setAVStream(mAVStream*);
134	void clearAVStream();
135
136	void clearOverride();
137
138	void startVideoLog(const QString& path);
139	void endVideoLog();
140
141signals:
142	void started();
143	void paused();
144	void unpaused();
145	void stopping();
146	void crashed(const QString& errorMessage);
147	void failed();
148	void frameAvailable();
149	void stateLoaded();
150	void rewound();
151
152	void rewindChanged(bool);
153	void fastForwardChanged(bool);
154
155	void unimplementedBiosCall(int);
156	void statusPosted(const QString& message);
157	void logPosted(int level, int category, const QString& log);
158
159	void imagePrinted(const QImage&);
160
161private:
162	void updateKeys();
163	void finishFrame();
164
165	void updateFastForward();
166
167	mCoreThread m_threadContext{};
168
169	bool m_patched = false;
170
171	QByteArray m_buffers[2];
172	QByteArray* m_activeBuffer;
173	QByteArray* m_completeBuffer = nullptr;
174
175	std::unique_ptr<mCacheSet> m_cacheSet;
176	std::unique_ptr<Override> m_override;
177
178	QList<std::function<void()>> m_resetActions;
179	QList<std::function<void()>> m_frameActions;
180	QMutex m_mutex;
181
182	int m_activeKeys = 0;
183	bool m_autofire[32] = {};
184	int m_autofireStatus[32] = {};
185	int m_autofireThreshold = 1;
186
187	VFileDevice m_backupLoadState;
188	QByteArray m_backupSaveState{nullptr};
189	int m_stateSlot = 1;
190	QString m_statePath;
191	int m_loadStateFlags;
192	int m_saveStateFlags;
193
194	bool m_audioSync = AUDIO_SYNC;
195	bool m_videoSync = VIDEO_SYNC;
196
197	bool m_autosave;
198	bool m_autoload;
199	int m_autosaveCounter;
200
201	int m_fastForward = false;
202	int m_fastForwardForced = false;
203	float m_fastForwardRatio = -1.f;
204	float m_fpsTarget;
205
206	InputController* m_inputController = nullptr;
207	LogController* m_log = nullptr;
208	MultiplayerController* m_multiplayer = nullptr;
209
210	mVideoLogContext* m_vl = nullptr;
211	VFile* m_vlVf = nullptr;
212
213#ifdef M_CORE_GB
214	struct QGBPrinter {
215		GBPrinter d;
216		CoreController* parent;
217	} m_printer;
218#endif
219};
220
221}