all repos — mgba @ a6c8089601ba6669b6664d8117e8b6d6bf8830fa

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 = 1,
 18	THREAD_PAUSED = 2,
 19	THREAD_EXITING = 3,
 20	THREAD_SHUTDOWN = 4
 21};
 22
 23struct GBASync {
 24	int videoFramePending;
 25	int videoFrameWait;
 26	int videoFrameSkip;
 27	int videoFrameOn;
 28	Mutex videoFrameMutex;
 29	Condition videoFrameAvailableCond;
 30	Condition videoFrameRequiredCond;
 31
 32	int audioWait;
 33	Condition audioRequiredCond;
 34	Mutex audioBufferMutex;
 35};
 36
 37struct GBAThread {
 38	// Output
 39	enum ThreadState state;
 40	struct GBA* gba;
 41	struct ARMCore* cpu;
 42
 43	// Input
 44	struct GBAVideoRenderer* renderer;
 45	struct GBASIODriverSet sioDrivers;
 46	struct ARMDebugger* debugger;
 47	int fd;
 48	int biosFd;
 49	const char* fname;
 50	int activeKeys;
 51	int frameskip;
 52
 53	// Threading state
 54	Thread thread;
 55
 56	Mutex stateMutex;
 57	Condition stateCond;
 58	enum ThreadState savedState;
 59
 60	GBALogHandler logHandler;
 61	int logLevel;
 62	ThreadCallback startCallback;
 63	ThreadCallback cleanCallback;
 64	ThreadCallback frameCallback;
 65	void* userData;
 66
 67	struct GBASync sync;
 68
 69	int rewindBufferSize;
 70	int rewindBufferCapacity;
 71	int rewindBufferInterval;
 72	int rewindBufferNext;
 73	struct GBASerializedState** rewindBuffer;
 74	int rewindBufferWriteOffset;
 75};
 76
 77void GBAMapOptionsToContext(struct StartupOptions*, struct GBAThread*);
 78
 79int GBAThreadStart(struct GBAThread* threadContext);
 80int GBAThreadHasStarted(struct GBAThread* threadContext);
 81void GBAThreadEnd(struct GBAThread* threadContext);
 82void GBAThreadJoin(struct GBAThread* threadContext);
 83
 84void GBAThreadInterrupt(struct GBAThread* threadContext);
 85void GBAThreadContinue(struct GBAThread* threadContext);
 86
 87void GBAThreadPause(struct GBAThread* threadContext);
 88void GBAThreadUnpause(struct GBAThread* threadContext);
 89int GBAThreadIsPaused(struct GBAThread* threadContext);
 90void GBAThreadTogglePause(struct GBAThread* threadContext);
 91struct GBAThread* GBAThreadGetContext(void);
 92
 93void GBASyncPostFrame(struct GBASync* sync);
 94int GBASyncWaitFrameStart(struct GBASync* sync, int frameskip);
 95void GBASyncWaitFrameEnd(struct GBASync* sync);
 96int GBASyncDrawingFrame(struct GBASync* sync);
 97
 98void GBASyncProduceAudio(struct GBASync* sync, int wait);
 99void GBASyncLockAudio(struct GBASync* sync);
100void GBASyncConsumeAudio(struct GBASync* sync);
101
102#endif