include/mgba/core/core.h (view raw)
1/* Copyright (c) 2013-2016 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 M_CORE_H
7#define M_CORE_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba/core/config.h>
14#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
15#include <mgba/core/directories.h>
16#endif
17#ifndef MINIMAL_CORE
18#include <mgba/core/input.h>
19#endif
20#include <mgba/core/interface.h>
21#ifdef USE_DEBUGGERS
22#include <mgba/debugger/debugger.h>
23#endif
24
25enum mPlatform {
26 PLATFORM_NONE = -1,
27#ifdef M_CORE_GBA
28 PLATFORM_GBA = 0,
29#endif
30#ifdef M_CORE_GB
31 PLATFORM_GB = 1,
32#endif
33};
34
35enum mCoreChecksumType {
36 CHECKSUM_CRC32,
37};
38
39struct mCoreConfig;
40struct mCoreSync;
41struct mDebuggerSymbols;
42struct mStateExtdata;
43struct mVideoLogContext;
44struct mCore {
45 void* cpu;
46 void* board;
47 struct mTiming* timing;
48 struct mDebugger* debugger;
49 struct mDebuggerSymbols* symbolTable;
50 struct mVideoLogger* videoLogger;
51
52#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
53 struct mDirectorySet dirs;
54#endif
55#ifndef MINIMAL_CORE
56 struct mInputMap inputMap;
57#endif
58 struct mCoreConfig config;
59 struct mCoreOptions opts;
60
61 struct mRTCGenericSource rtc;
62
63 bool (*init)(struct mCore*);
64 void (*deinit)(struct mCore*);
65
66 enum mPlatform (*platform)(const struct mCore*);
67
68 void (*setSync)(struct mCore*, struct mCoreSync*);
69 void (*loadConfig)(struct mCore*, const struct mCoreConfig*);
70
71 void (*desiredVideoDimensions)(struct mCore*, unsigned* width, unsigned* height);
72 void (*setVideoBuffer)(struct mCore*, color_t* buffer, size_t stride);
73 void (*setVideoGLTex)(struct mCore*, unsigned texid);
74
75 void (*getPixels)(struct mCore*, const void** buffer, size_t* stride);
76 void (*putPixels)(struct mCore*, const void* buffer, size_t stride);
77
78 struct blip_t* (*getAudioChannel)(struct mCore*, int ch);
79 void (*setAudioBufferSize)(struct mCore*, size_t samples);
80 size_t (*getAudioBufferSize)(struct mCore*);
81
82 void (*addCoreCallbacks)(struct mCore*, struct mCoreCallbacks*);
83 void (*clearCoreCallbacks)(struct mCore*);
84 void (*setAVStream)(struct mCore*, struct mAVStream*);
85
86 bool (*isROM)(struct VFile* vf);
87 bool (*loadROM)(struct mCore*, struct VFile* vf);
88 bool (*loadSave)(struct mCore*, struct VFile* vf);
89 bool (*loadTemporarySave)(struct mCore*, struct VFile* vf);
90 void (*unloadROM)(struct mCore*);
91 void (*checksum)(const struct mCore*, void* data, enum mCoreChecksumType type);
92
93 bool (*loadBIOS)(struct mCore*, struct VFile* vf, int biosID);
94 bool (*selectBIOS)(struct mCore*, int biosID);
95
96 bool (*loadPatch)(struct mCore*, struct VFile* vf);
97
98 void (*reset)(struct mCore*);
99 void (*runFrame)(struct mCore*);
100 void (*runLoop)(struct mCore*);
101 void (*step)(struct mCore*);
102
103 size_t (*stateSize)(struct mCore*);
104 bool (*loadState)(struct mCore*, const void* state);
105 bool (*saveState)(struct mCore*, void* state);
106
107 void (*setKeys)(struct mCore*, uint32_t keys);
108 void (*addKeys)(struct mCore*, uint32_t keys);
109 void (*clearKeys)(struct mCore*, uint32_t keys);
110
111 int32_t (*frameCounter)(const struct mCore*);
112 int32_t (*frameCycles)(const struct mCore*);
113 int32_t (*frequency)(const struct mCore*);
114
115 void (*getGameTitle)(const struct mCore*, char* title);
116 void (*getGameCode)(const struct mCore*, char* title);
117
118 void (*setPeripheral)(struct mCore*, int type, void*);
119
120 uint32_t (*busRead8)(struct mCore*, uint32_t address);
121 uint32_t (*busRead16)(struct mCore*, uint32_t address);
122 uint32_t (*busRead32)(struct mCore*, uint32_t address);
123
124 void (*busWrite8)(struct mCore*, uint32_t address, uint8_t);
125 void (*busWrite16)(struct mCore*, uint32_t address, uint16_t);
126 void (*busWrite32)(struct mCore*, uint32_t address, uint32_t);
127
128 uint32_t (*rawRead8)(struct mCore*, uint32_t address, int segment);
129 uint32_t (*rawRead16)(struct mCore*, uint32_t address, int segment);
130 uint32_t (*rawRead32)(struct mCore*, uint32_t address, int segment);
131
132 void (*rawWrite8)(struct mCore*, uint32_t address, int segment, uint8_t);
133 void (*rawWrite16)(struct mCore*, uint32_t address, int segment, uint16_t);
134 void (*rawWrite32)(struct mCore*, uint32_t address, int segment, uint32_t);
135
136 size_t (*listMemoryBlocks)(const struct mCore*, const struct mCoreMemoryBlock**);
137 void* (*getMemoryBlock)(struct mCore*, size_t id, size_t* sizeOut);
138
139#ifdef USE_DEBUGGERS
140 bool (*supportsDebuggerType)(struct mCore*, enum mDebuggerType);
141 struct mDebuggerPlatform* (*debuggerPlatform)(struct mCore*);
142 struct CLIDebuggerSystem* (*cliDebuggerSystem)(struct mCore*);
143 void (*attachDebugger)(struct mCore*, struct mDebugger*);
144 void (*detachDebugger)(struct mCore*);
145
146 void (*loadSymbols)(struct mCore*, struct VFile*);
147 bool (*lookupIdentifier)(struct mCore*, const char* name, int32_t* value, int* segment);
148#endif
149
150 struct mCheatDevice* (*cheatDevice)(struct mCore*);
151
152 size_t (*savedataClone)(struct mCore*, void** sram);
153 bool (*savedataRestore)(struct mCore*, const void* sram, size_t size, bool writeback);
154
155 size_t (*listVideoLayers)(const struct mCore*, const struct mCoreChannelInfo**);
156 size_t (*listAudioChannels)(const struct mCore*, const struct mCoreChannelInfo**);
157 void (*enableVideoLayer)(struct mCore*, size_t id, bool enable);
158 void (*enableAudioChannel)(struct mCore*, size_t id, bool enable);
159 void (*adjustVideoLayer)(struct mCore*, size_t id, int32_t x, int32_t y);
160
161#ifndef MINIMAL_CORE
162 void (*startVideoLog)(struct mCore*, struct mVideoLogContext*);
163 void (*endVideoLog)(struct mCore*);
164#endif
165};
166
167#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
168struct mCore* mCoreFind(const char* path);
169bool mCoreLoadFile(struct mCore* core, const char* path);
170
171bool mCorePreloadVF(struct mCore* core, struct VFile* vf);
172bool mCorePreloadFile(struct mCore* core, const char* path);
173
174bool mCoreAutoloadSave(struct mCore* core);
175bool mCoreAutoloadPatch(struct mCore* core);
176bool mCoreAutoloadCheats(struct mCore* core);
177
178bool mCoreSaveState(struct mCore* core, int slot, int flags);
179bool mCoreLoadState(struct mCore* core, int slot, int flags);
180struct VFile* mCoreGetState(struct mCore* core, int slot, bool write);
181void mCoreDeleteState(struct mCore* core, int slot);
182
183void mCoreTakeScreenshot(struct mCore* core);
184#endif
185
186struct mCore* mCoreFindVF(struct VFile* vf);
187enum mPlatform mCoreIsCompatible(struct VFile* vf);
188
189bool mCoreSaveStateNamed(struct mCore* core, struct VFile* vf, int flags);
190bool mCoreLoadStateNamed(struct mCore* core, struct VFile* vf, int flags);
191
192void mCoreInitConfig(struct mCore* core, const char* port);
193void mCoreLoadConfig(struct mCore* core);
194void mCoreLoadForeignConfig(struct mCore* core, const struct mCoreConfig* config);
195
196void mCoreSetRTC(struct mCore* core, struct mRTCSource* rtc);
197
198void* mCoreGetMemoryBlock(struct mCore* core, uint32_t start, size_t* size);
199
200#ifdef USE_ELF
201struct ELF;
202bool mCoreLoadELF(struct mCore* core, struct ELF* elf);
203#ifdef USE_DEBUGGERS
204void mCoreLoadELFSymbols(struct mDebuggerSymbols* symbols, struct ELF*);
205#endif
206#endif
207
208CXX_GUARD_END
209
210#endif