all repos — mgba @ e2e48a1c5830562c876b7959698bdefec91a8468

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