all repos — mgba @ ca3050d76be99f4d635f4c45d790a199befc2f6c

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