all repos — mgba @ 68e70b61f19b1e2b34e39be0c4dff35a84f2d313

mGBA Game Boy Advance Emulator

src/gba/supervisor/thread.h (view raw)

  1/* Copyright (c) 2013-2015 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 GBA_THREAD_H
  7#define GBA_THREAD_H
  8
  9#include "util/common.h"
 10
 11#include "gba/gba.h"
 12#include "gba/input.h"
 13#include "gba/supervisor/overrides.h"
 14#include "gba/supervisor/sync.h"
 15
 16#include "util/threading.h"
 17
 18struct GBAThread;
 19struct GBAArguments;
 20struct GBACheatSet;
 21struct GBAOptions;
 22
 23typedef void (*ThreadCallback)(struct GBAThread* threadContext);
 24typedef bool (*ThreadStopCallback)(struct GBAThread* threadContext);
 25
 26enum ThreadState {
 27	THREAD_INITIALIZED = -1,
 28	THREAD_RUNNING = 0,
 29	THREAD_INTERRUPTED,
 30	THREAD_INTERRUPTING,
 31	THREAD_PAUSED,
 32	THREAD_PAUSING,
 33	THREAD_RUN_ON,
 34	THREAD_RESETING,
 35	THREAD_EXITING,
 36	THREAD_SHUTDOWN,
 37	THREAD_CRASHED
 38};
 39
 40struct GBAThread {
 41	// Output
 42	enum ThreadState state;
 43	struct GBA* gba;
 44	struct ARMCore* cpu;
 45
 46	// Input
 47	struct GBAVideoRenderer* renderer;
 48	struct GBASIODriverSet sioDrivers;
 49	struct ARMDebugger* debugger;
 50	struct VDir* gameDir;
 51	struct VDir* stateDir;
 52	struct VFile* rom;
 53	struct VFile* save;
 54	struct VFile* bios;
 55	struct VFile* patch;
 56	struct VFile* cheatsFile;
 57	const char* fname;
 58	const char* movie;
 59	int activeKeys;
 60	struct GBAAVStream* stream;
 61	struct Configuration* overrides;
 62	enum GBAIdleLoopOptimization idleOptimization;
 63	bool bootBios;
 64
 65	bool hasOverride;
 66	struct GBACartridgeOverride override;
 67
 68	// Run-time options
 69	int frameskip;
 70	float fpsTarget;
 71	size_t audioBuffers;
 72	bool skipBios;
 73	int volume;
 74	bool mute;
 75
 76	// Threading state
 77	Thread thread;
 78
 79	Mutex stateMutex;
 80	Condition stateCond;
 81	enum ThreadState savedState;
 82	int interruptDepth;
 83	bool frameWasOn;
 84
 85	GBALogHandler logHandler;
 86	int logLevel;
 87	ThreadCallback startCallback;
 88	ThreadCallback cleanCallback;
 89	ThreadCallback frameCallback;
 90	ThreadStopCallback stopCallback;
 91	void* userData;
 92	void (*run)(struct GBAThread*);
 93
 94	struct GBASync sync;
 95
 96	int rewindBufferSize;
 97	int rewindBufferCapacity;
 98	int rewindBufferInterval;
 99	int rewindBufferNext;
100	struct GBASerializedState** rewindBuffer;
101	int rewindBufferWriteOffset;
102	uint8_t* rewindScreenBuffer;
103
104	struct GBACheatDevice* cheats;
105};
106
107void GBAMapOptionsToContext(const struct GBAOptions*, struct GBAThread*);
108void GBAMapArgumentsToContext(const struct GBAArguments*, struct GBAThread*);
109
110bool GBAThreadStart(struct GBAThread* threadContext);
111bool GBAThreadHasStarted(struct GBAThread* threadContext);
112bool GBAThreadHasExited(struct GBAThread* threadContext);
113bool GBAThreadHasCrashed(struct GBAThread* threadContext);
114void GBAThreadEnd(struct GBAThread* threadContext);
115void GBAThreadReset(struct GBAThread* threadContext);
116void GBAThreadJoin(struct GBAThread* threadContext);
117
118bool GBAThreadIsActive(struct GBAThread* threadContext);
119void GBAThreadInterrupt(struct GBAThread* threadContext);
120void GBAThreadContinue(struct GBAThread* threadContext);
121
122void GBARunOnThread(struct GBAThread* threadContext, void (*run)(struct GBAThread*));
123
124void GBAThreadPause(struct GBAThread* threadContext);
125void GBAThreadUnpause(struct GBAThread* threadContext);
126bool GBAThreadIsPaused(struct GBAThread* threadContext);
127void GBAThreadTogglePause(struct GBAThread* threadContext);
128void GBAThreadPauseFromThread(struct GBAThread* threadContext);
129struct GBAThread* GBAThreadGetContext(void);
130
131void GBAThreadLoadROM(struct GBAThread* threadContext, const char* fname);
132void GBAThreadReplaceROM(struct GBAThread* threadContext, const char* fname);
133
134#ifdef USE_PNG
135void GBAThreadTakeScreenshot(struct GBAThread* threadContext);
136#endif
137
138#endif