all repos — mgba @ 1a0e44c014ad34bea30d237d27015d82d02cda4b

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 saveState(int slot = 0);
108	void loadBackupState();
109	void saveBackupState();
110
111	void loadSave(const QString&, bool temporary);
112	void loadPatch(const QString&);
113	void replaceGame(const QString&);
114	void yankPak();
115
116#ifdef USE_PNG
117	void screenshot();
118#endif
119
120	void setRealTime();
121	void setFixedTime(const QDateTime& time);
122	void setFakeEpoch(const QDateTime& time);
123
124	void importSharkport(const QString& path);
125	void exportSharkport(const QString& path);
126
127	void attachPrinter();
128	void detachPrinter();
129	void endPrint();
130
131	void setAVStream(mAVStream*);
132	void clearAVStream();
133
134	void clearOverride();
135
136	void startVideoLog(const QString& path);
137	void endVideoLog();
138
139signals:
140	void started();
141	void paused();
142	void unpaused();
143	void stopping();
144	void crashed(const QString& errorMessage);
145	void failed();
146	void frameAvailable();
147	void stateLoaded();
148	void rewound();
149
150	void rewindChanged(bool);
151	void fastForwardChanged(bool);
152
153	void unimplementedBiosCall(int);
154	void statusPosted(const QString& message);
155	void logPosted(int level, int category, const QString& log);
156
157	void imagePrinted(const QImage&);
158
159private:
160	void updateKeys();
161	void finishFrame();
162
163	void updateFastForward();
164
165	mCoreThread m_threadContext{};
166
167	bool m_patched = false;
168
169	QByteArray m_buffers[2];
170	QByteArray* m_activeBuffer;
171	QByteArray* m_completeBuffer = nullptr;
172
173	std::unique_ptr<mCacheSet> m_cacheSet;
174	std::unique_ptr<Override> m_override;
175
176	QList<std::function<void()>> m_resetActions;
177	QList<std::function<void()>> m_frameActions;
178	QMutex m_mutex;
179
180	int m_activeKeys = 0;
181	bool m_autofire[32] = {};
182	int m_autofireStatus[32] = {};
183	int m_autofireThreshold = 1;
184
185	VFileDevice m_backupLoadState;
186	QByteArray m_backupSaveState{nullptr};
187	int m_stateSlot = 1;
188	int m_loadStateFlags;
189	int m_saveStateFlags;
190
191	bool m_audioSync = AUDIO_SYNC;
192	bool m_videoSync = VIDEO_SYNC;
193
194	bool m_autosave;
195	bool m_autoload;
196	int m_autosaveCounter;
197
198	int m_fastForward = false;
199	int m_fastForwardForced = false;
200	float m_fastForwardRatio = -1.f;
201	float m_fpsTarget;
202
203	InputController* m_inputController = nullptr;
204	LogController* m_log = nullptr;
205	MultiplayerController* m_multiplayer = nullptr;
206
207	mVideoLogContext* m_vl = nullptr;
208	VFile* m_vlVf = nullptr;
209
210#ifdef M_CORE_GB
211	struct QGBPrinter {
212		GBPrinter d;
213		CoreController* parent;
214	} m_printer;
215#endif
216};
217
218}