all repos — mgba @ 8ca80d4a94ccbd06ecfffaabd89822071e3244d5

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