all repos — mgba @ 1882b155677ce11c4fd6e02bb5285fe78a2cc3f4

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