all repos — mgba @ c62d913e233e7ea3bb23a3f52fcb7b481f2faed5

mGBA Game Boy Advance Emulator

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