all repos — mgba @ bed6ba1fc48a7432c8b45ebb38ea7e403c45bfb0

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// TODO: Fix layering violation
 23#include <mgba/internal/debugger/debugger.h>
 24#endif
 25
 26enum mPlatform {
 27	PLATFORM_NONE = -1,
 28#ifdef M_CORE_GBA
 29	PLATFORM_GBA,
 30#endif
 31#ifdef M_CORE_GB
 32	PLATFORM_GB,
 33#endif
 34};
 35
 36enum mCoreChecksumType {
 37	CHECKSUM_CRC32,
 38};
 39
 40struct mCoreConfig;
 41struct mCoreSync;
 42struct mStateExtdata;
 43struct mCore {
 44	void* cpu;
 45	void* board;
 46	struct mDebugger* debugger;
 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
 64	void (*setSync)(struct mCore*, struct mCoreSync*);
 65	void (*loadConfig)(struct mCore*, const struct mCoreConfig*);
 66
 67	void (*desiredVideoDimensions)(struct mCore*, unsigned* width, unsigned* height);
 68	void (*setVideoBuffer)(struct mCore*, color_t* buffer, size_t stride);
 69
 70	void (*getPixels)(struct mCore*, const void** buffer, size_t* stride);
 71	void (*putPixels)(struct mCore*, const void* buffer, size_t stride);
 72
 73	struct blip_t* (*getAudioChannel)(struct mCore*, int ch);
 74	void (*setAudioBufferSize)(struct mCore*, size_t samples);
 75	size_t (*getAudioBufferSize)(struct mCore*);
 76
 77	void (*addCoreCallbacks)(struct mCore*, struct mCoreCallbacks*);
 78	void (*clearCoreCallbacks)(struct mCore*);
 79	void (*setAVStream)(struct mCore*, struct mAVStream*);
 80
 81	bool (*isROM)(struct VFile* vf);
 82	bool (*loadROM)(struct mCore*, struct VFile* vf);
 83	bool (*loadSave)(struct mCore*, struct VFile* vf);
 84	bool (*loadTemporarySave)(struct mCore*, struct VFile* vf);
 85	void (*unloadROM)(struct mCore*);
 86	void (*checksum)(const struct mCore*, void* data, enum mCoreChecksumType type);
 87
 88	bool (*loadBIOS)(struct mCore*, struct VFile* vf, int biosID);
 89	bool (*selectBIOS)(struct mCore*, int biosID);
 90
 91	bool (*loadPatch)(struct mCore*, struct VFile* vf);
 92
 93	void (*reset)(struct mCore*);
 94	void (*runFrame)(struct mCore*);
 95	void (*runLoop)(struct mCore*);
 96	void (*step)(struct mCore*);
 97
 98	size_t (*stateSize)(struct mCore*);
 99	bool (*loadState)(struct mCore*, const void* state);
100	bool (*saveState)(struct mCore*, void* state);
101
102	void (*setKeys)(struct mCore*, uint32_t keys);
103	void (*addKeys)(struct mCore*, uint32_t keys);
104	void (*clearKeys)(struct mCore*, uint32_t keys);
105
106	int32_t (*frameCounter)(const struct mCore*);
107	int32_t (*frameCycles)(const struct mCore*);
108	int32_t (*frequency)(const struct mCore*);
109
110	void (*getGameTitle)(const struct mCore*, char* title);
111	void (*getGameCode)(const struct mCore*, char* title);
112
113	void (*setPeripheral)(struct mCore*, int type, void*);
114
115	uint32_t (*busRead8)(struct mCore*, uint32_t address);
116	uint32_t (*busRead16)(struct mCore*, uint32_t address);
117	uint32_t (*busRead32)(struct mCore*, uint32_t address);
118
119	void (*busWrite8)(struct mCore*, uint32_t address, uint8_t);
120	void (*busWrite16)(struct mCore*, uint32_t address, uint16_t);
121	void (*busWrite32)(struct mCore*, uint32_t address, uint32_t);
122
123	uint32_t (*rawRead8)(struct mCore*, uint32_t address, int segment);
124	uint32_t (*rawRead16)(struct mCore*, uint32_t address, int segment);
125	uint32_t (*rawRead32)(struct mCore*, uint32_t address, int segment);
126
127	void (*rawWrite8)(struct mCore*, uint32_t address, int segment, uint8_t);
128	void (*rawWrite16)(struct mCore*, uint32_t address, int segment, uint16_t);
129	void (*rawWrite32)(struct mCore*, uint32_t address, int segment, uint32_t);
130
131#ifdef USE_DEBUGGERS
132	bool (*supportsDebuggerType)(struct mCore*, enum mDebuggerType);
133	struct mDebuggerPlatform* (*debuggerPlatform)(struct mCore*);
134	struct CLIDebuggerSystem* (*cliDebuggerSystem)(struct mCore*);
135	void (*attachDebugger)(struct mCore*, struct mDebugger*);
136	void (*detachDebugger)(struct mCore*);
137#endif
138
139	struct mCheatDevice* (*cheatDevice)(struct mCore*);
140
141	size_t (*savedataClone)(struct mCore*, void** sram);
142	bool (*savedataRestore)(struct mCore*, const void* sram, size_t size, bool writeback);
143
144	size_t (*listVideoLayers)(const struct mCore*, const struct mCoreChannelInfo**);
145	size_t (*listAudioChannels)(const struct mCore*, const struct mCoreChannelInfo**);
146	void (*enableVideoLayer)(struct mCore*, size_t id, bool enable);
147	void (*enableAudioChannel)(struct mCore*, size_t id, bool enable);
148};
149
150#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
151struct mCore* mCoreFind(const char* path);
152bool mCoreLoadFile(struct mCore* core, const char* path);
153
154bool mCorePreloadVF(struct mCore* core, struct VFile* vf);
155bool mCorePreloadFile(struct mCore* core, const char* path);
156
157bool mCoreAutoloadSave(struct mCore* core);
158bool mCoreAutoloadPatch(struct mCore* core);
159
160bool mCoreSaveState(struct mCore* core, int slot, int flags);
161bool mCoreLoadState(struct mCore* core, int slot, int flags);
162struct VFile* mCoreGetState(struct mCore* core, int slot, bool write);
163void mCoreDeleteState(struct mCore* core, int slot);
164
165void mCoreTakeScreenshot(struct mCore* core);
166#endif
167
168struct mCore* mCoreFindVF(struct VFile* vf);
169enum mPlatform mCoreIsCompatible(struct VFile* vf);
170
171bool mCoreSaveStateNamed(struct mCore* core, struct VFile* vf, int flags);
172bool mCoreLoadStateNamed(struct mCore* core, struct VFile* vf, int flags);
173
174void mCoreInitConfig(struct mCore* core, const char* port);
175void mCoreLoadConfig(struct mCore* core);
176void mCoreLoadForeignConfig(struct mCore* core, const struct mCoreConfig* config);
177
178void mCoreSetRTC(struct mCore* core, struct mRTCSource* rtc);
179
180CXX_GUARD_END
181
182#endif