all repos — mgba @ d620a8c38c9f49fb4b40a26c0954f0cff2147ab5

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
 39struct mRTCSource;
 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	bool (*init)(struct mCore*);
 58	void (*deinit)(struct mCore*);
 59
 60	enum mPlatform (*platform)(const struct mCore*);
 61
 62	void (*setSync)(struct mCore*, struct mCoreSync*);
 63	void (*loadConfig)(struct mCore*, const struct mCoreConfig*);
 64
 65	void (*desiredVideoDimensions)(struct mCore*, unsigned* width, unsigned* height);
 66	void (*setVideoBuffer)(struct mCore*, color_t* buffer, size_t stride);
 67
 68	void (*getPixels)(struct mCore*, const void** buffer, size_t* stride);
 69	void (*putPixels)(struct mCore*, const void* buffer, size_t stride);
 70
 71	struct blip_t* (*getAudioChannel)(struct mCore*, int ch);
 72	void (*setAudioBufferSize)(struct mCore*, size_t samples);
 73	size_t (*getAudioBufferSize)(struct mCore*);
 74
 75	void (*setCoreCallbacks)(struct mCore*, struct mCoreCallbacks*);
 76	void (*setAVStream)(struct mCore*, struct mAVStream*);
 77
 78	bool (*isROM)(struct VFile* vf);
 79	bool (*loadROM)(struct mCore*, struct VFile* vf);
 80	bool (*loadSave)(struct mCore*, struct VFile* vf);
 81	bool (*loadTemporarySave)(struct mCore*, struct VFile* vf);
 82	void (*unloadROM)(struct mCore*);
 83
 84	bool (*loadBIOS)(struct mCore*, struct VFile* vf, int biosID);
 85	bool (*selectBIOS)(struct mCore*, int biosID);
 86
 87	bool (*loadPatch)(struct mCore*, struct VFile* vf);
 88
 89	void (*reset)(struct mCore*);
 90	void (*runFrame)(struct mCore*);
 91	void (*runLoop)(struct mCore*);
 92	void (*step)(struct mCore*);
 93
 94	size_t (*stateSize)(struct mCore*);
 95	bool (*loadState)(struct mCore*, const void* state);
 96	bool (*saveState)(struct mCore*, void* state);
 97
 98	void (*setKeys)(struct mCore*, uint32_t keys);
 99	void (*addKeys)(struct mCore*, uint32_t keys);
100	void (*clearKeys)(struct mCore*, uint32_t keys);
101
102	int32_t (*frameCounter)(const struct mCore*);
103	int32_t (*frameCycles)(const struct mCore*);
104	int32_t (*frequency)(const struct mCore*);
105
106	void (*getGameTitle)(const struct mCore*, char* title);
107	void (*getGameCode)(const struct mCore*, char* title);
108
109	void (*setRTC)(struct mCore*, struct mRTCSource*);
110	void (*setRotation)(struct mCore*, struct mRotationSource*);
111	void (*setRumble)(struct mCore*, struct mRumble*);
112
113	uint32_t (*busRead8)(struct mCore*, uint32_t address);
114	uint32_t (*busRead16)(struct mCore*, uint32_t address);
115	uint32_t (*busRead32)(struct mCore*, uint32_t address);
116
117	void (*busWrite8)(struct mCore*, uint32_t address, uint8_t);
118	void (*busWrite16)(struct mCore*, uint32_t address, uint16_t);
119	void (*busWrite32)(struct mCore*, uint32_t address, uint32_t);
120
121	uint32_t (*rawRead8)(struct mCore*, uint32_t address, int segment);
122	uint32_t (*rawRead16)(struct mCore*, uint32_t address, int segment);
123	uint32_t (*rawRead32)(struct mCore*, uint32_t address, int segment);
124
125	void (*rawWrite8)(struct mCore*, uint32_t address, int segment, uint8_t);
126	void (*rawWrite16)(struct mCore*, uint32_t address, int segment, uint16_t);
127	void (*rawWrite32)(struct mCore*, uint32_t address, int segment, uint32_t);
128
129#ifdef USE_DEBUGGERS
130	bool (*supportsDebuggerType)(struct mCore*, enum mDebuggerType);
131	struct mDebuggerPlatform* (*debuggerPlatform)(struct mCore*);
132	struct CLIDebuggerSystem* (*cliDebuggerSystem)(struct mCore*);
133	void (*attachDebugger)(struct mCore*, struct mDebugger*);
134	void (*detachDebugger)(struct mCore*);
135#endif
136
137	struct mCheatDevice* (*cheatDevice)(struct mCore*);
138
139	size_t (*savedataClone)(struct mCore*, void** sram);
140	bool (*savedataRestore)(struct mCore*, const void* sram, size_t size, bool writeback);
141};
142
143#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
144struct mCore* mCoreFind(const char* path);
145bool mCoreLoadFile(struct mCore* core, const char* path);
146
147bool mCoreAutoloadSave(struct mCore* core);
148bool mCoreAutoloadPatch(struct mCore* core);
149
150bool mCoreSaveState(struct mCore* core, int slot, int flags);
151bool mCoreLoadState(struct mCore* core, int slot, int flags);
152struct VFile* mCoreGetState(struct mCore* core, int slot, bool write);
153void mCoreDeleteState(struct mCore* core, int slot);
154
155void mCoreTakeScreenshot(struct mCore* core);
156#endif
157
158struct mCore* mCoreFindVF(struct VFile* vf);
159enum mPlatform mCoreIsCompatible(struct VFile* vf);
160
161bool mCoreSaveStateNamed(struct mCore* core, struct VFile* vf, int flags);
162bool mCoreLoadStateNamed(struct mCore* core, struct VFile* vf, int flags);
163
164void mCoreInitConfig(struct mCore* core, const char* port);
165void mCoreLoadConfig(struct mCore* core);
166void mCoreLoadForeignConfig(struct mCore* core, const struct mCoreConfig* config);
167
168CXX_GUARD_END
169
170#endif