all repos — mgba @ 73425e80b51ffbb7f0553a7fa59455ad38890c7d

mGBA Game Boy Advance Emulator

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

  1#ifndef GBA_THREAD_H
  2#define GBA_THREAD_H
  3
  4#include "common.h"
  5
  6#include "gba.h"
  7
  8#include "util/threading.h"
  9#include "platform/commandline.h"
 10
 11struct GBAThread;
 12typedef void (*ThreadCallback)(struct GBAThread* threadContext);
 13
 14enum ThreadState {
 15	THREAD_INITIALIZED = -1,
 16	THREAD_RUNNING = 0,
 17	THREAD_INTERRUPTED,
 18	THREAD_INTERRUPTING,
 19	THREAD_PAUSED,
 20	THREAD_PAUSING,
 21	THREAD_RESETING,
 22	THREAD_EXITING,
 23	THREAD_SHUTDOWN
 24};
 25
 26struct GBASync {
 27	int videoFramePending;
 28	int videoFrameWait;
 29	int videoFrameSkip;
 30	bool videoFrameOn;
 31	Mutex videoFrameMutex;
 32	Condition videoFrameAvailableCond;
 33	Condition videoFrameRequiredCond;
 34
 35	int audioWait;
 36	Condition audioRequiredCond;
 37	Mutex audioBufferMutex;
 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 VFile* rom;
 51	struct VFile* save;
 52	struct VFile* bios;
 53	struct VFile* patch;
 54	const char* fname;
 55	int activeKeys;
 56	int frameskip;
 57
 58	// Threading state
 59	Thread thread;
 60
 61	Mutex stateMutex;
 62	Condition stateCond;
 63	enum ThreadState savedState;
 64
 65	GBALogHandler logHandler;
 66	int logLevel;
 67	ThreadCallback startCallback;
 68	ThreadCallback cleanCallback;
 69	ThreadCallback frameCallback;
 70	void* userData;
 71
 72	struct GBASync sync;
 73
 74	int rewindBufferSize;
 75	int rewindBufferCapacity;
 76	int rewindBufferInterval;
 77	int rewindBufferNext;
 78	struct GBASerializedState** rewindBuffer;
 79	int rewindBufferWriteOffset;
 80};
 81
 82void GBAMapOptionsToContext(struct StartupOptions*, struct GBAThread*);
 83
 84bool GBAThreadStart(struct GBAThread* threadContext);
 85bool GBAThreadHasStarted(struct GBAThread* threadContext);
 86void GBAThreadEnd(struct GBAThread* threadContext);
 87void GBAThreadReset(struct GBAThread* threadContext);
 88void GBAThreadJoin(struct GBAThread* threadContext);
 89
 90void GBAThreadInterrupt(struct GBAThread* threadContext);
 91void GBAThreadContinue(struct GBAThread* threadContext);
 92
 93void GBAThreadPause(struct GBAThread* threadContext);
 94void GBAThreadUnpause(struct GBAThread* threadContext);
 95bool GBAThreadIsPaused(struct GBAThread* threadContext);
 96void GBAThreadTogglePause(struct GBAThread* threadContext);
 97struct GBAThread* GBAThreadGetContext(void);
 98
 99void GBASyncPostFrame(struct GBASync* sync);
100bool GBASyncWaitFrameStart(struct GBASync* sync, int frameskip);
101void GBASyncWaitFrameEnd(struct GBASync* sync);
102bool GBASyncDrawingFrame(struct GBASync* sync);
103
104void GBASyncProduceAudio(struct GBASync* sync, int wait);
105void GBASyncLockAudio(struct GBASync* sync);
106void GBASyncConsumeAudio(struct GBASync* sync);
107
108#endif