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