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