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