all repos — mgba @ 73947766defe48d122796c602b553af507cdb6d5

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