all repos — mgba @ 75d9085eefa51c7d5a6a5436e4692e6daf0cc4e4

mGBA Game Boy Advance Emulator

src/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 "util/common.h"
 10
 11CXX_GUARD_START
 12
 13#include "core/config.h"
 14#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
 15#include "core/directories.h"
 16#endif
 17#ifndef MINIMAL_CORE
 18#include "core/input.h"
 19#endif
 20#include "core/interface.h"
 21#ifdef USE_DEBUGGERS
 22#include "debugger/debugger.h"
 23#endif
 24
 25enum mPlatform {
 26	PLATFORM_NONE = -1,
 27#ifdef M_CORE_GBA
 28	PLATFORM_GBA,
 29#endif
 30#ifdef M_CORE_GB
 31	PLATFORM_GB,
 32#endif
 33};
 34
 35struct mRTCSource;
 36struct mCoreConfig;
 37struct mCoreSync;
 38struct mStateExtdata;
 39struct mCore {
 40	void* cpu;
 41	void* board;
 42	struct mDebugger* debugger;
 43
 44#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
 45	struct mDirectorySet dirs;
 46#endif
 47#ifndef MINIMAL_CORE
 48	struct mInputMap inputMap;
 49#endif
 50	struct mCoreConfig config;
 51	struct mCoreOptions opts;
 52
 53	bool (*init)(struct mCore*);
 54	void (*deinit)(struct mCore*);
 55
 56	enum mPlatform (*platform)(const struct mCore*);
 57
 58	void (*setSync)(struct mCore*, struct mCoreSync*);
 59	void (*loadConfig)(struct mCore*, const struct mCoreConfig*);
 60
 61	void (*desiredVideoDimensions)(struct mCore*, unsigned* width, unsigned* height);
 62	void (*setVideoBuffer)(struct mCore*, color_t* buffer, size_t stride);
 63
 64	void (*getPixels)(struct mCore*, const void** buffer, size_t* stride);
 65	void (*putPixels)(struct mCore*, const void* buffer, size_t stride);
 66
 67	struct blip_t* (*getAudioChannel)(struct mCore*, int ch);
 68	void (*setAudioBufferSize)(struct mCore*, size_t samples);
 69	size_t (*getAudioBufferSize)(struct mCore*);
 70
 71	void (*setCoreCallbacks)(struct mCore*, struct mCoreCallbacks*);
 72	void (*setAVStream)(struct mCore*, struct mAVStream*);
 73
 74	bool (*isROM)(struct VFile* vf);
 75	bool (*loadROM)(struct mCore*, struct VFile* vf);
 76	bool (*loadSave)(struct mCore*, struct VFile* vf);
 77	bool (*loadTemporarySave)(struct mCore*, struct VFile* vf);
 78	void (*unloadROM)(struct mCore*);
 79
 80	bool (*loadBIOS)(struct mCore*, struct VFile* vf, int biosID);
 81	bool (*selectBIOS)(struct mCore*, int biosID);
 82
 83	bool (*loadPatch)(struct mCore*, struct VFile* vf);
 84
 85	void (*reset)(struct mCore*);
 86	void (*runFrame)(struct mCore*);
 87	void (*runLoop)(struct mCore*);
 88	void (*step)(struct mCore*);
 89
 90	size_t (*stateSize)(struct mCore*);
 91	bool (*loadState)(struct mCore*, const void* state);
 92	bool (*saveState)(struct mCore*, void* state);
 93
 94	void (*setKeys)(struct mCore*, uint32_t keys);
 95	void (*addKeys)(struct mCore*, uint32_t keys);
 96	void (*clearKeys)(struct mCore*, uint32_t keys);
 97
 98	int32_t (*frameCounter)(const struct mCore*);
 99	int32_t (*frameCycles)(const struct mCore*);
100	int32_t (*frequency)(const struct mCore*);
101
102	void (*getGameTitle)(const struct mCore*, char* title);
103	void (*getGameCode)(const struct mCore*, char* title);
104
105	void (*setRTC)(struct mCore*, struct mRTCSource*);
106	void (*setRotation)(struct mCore*, struct mRotationSource*);
107	void (*setRumble)(struct mCore*, struct mRumble*);
108
109	uint32_t (*busRead8)(struct mCore*, uint32_t address);
110	uint32_t (*busRead16)(struct mCore*, uint32_t address);
111	uint32_t (*busRead32)(struct mCore*, uint32_t address);
112
113	void (*busWrite8)(struct mCore*, uint32_t address, uint8_t);
114	void (*busWrite16)(struct mCore*, uint32_t address, uint16_t);
115	void (*busWrite32)(struct mCore*, uint32_t address, uint32_t);
116
117	uint32_t (*rawRead8)(struct mCore*, uint32_t address, int segment);
118	uint32_t (*rawRead16)(struct mCore*, uint32_t address, int segment);
119	uint32_t (*rawRead32)(struct mCore*, uint32_t address, int segment);
120
121	void (*rawWrite8)(struct mCore*, uint32_t address, int segment, uint8_t);
122	void (*rawWrite16)(struct mCore*, uint32_t address, int segment, uint16_t);
123	void (*rawWrite32)(struct mCore*, uint32_t address, int segment, uint32_t);
124
125#ifdef USE_DEBUGGERS
126	bool (*supportsDebuggerType)(struct mCore*, enum mDebuggerType);
127	struct mDebuggerPlatform* (*debuggerPlatform)(struct mCore*);
128	struct CLIDebuggerSystem* (*cliDebuggerSystem)(struct mCore*);
129	void (*attachDebugger)(struct mCore*, struct mDebugger*);
130	void (*detachDebugger)(struct mCore*);
131#endif
132
133	struct mCheatDevice* (*cheatDevice)(struct mCore*);
134
135	size_t (*savedataClone)(struct mCore*, void** sram);
136	bool (*savedataRestore)(struct mCore*, const void* sram, size_t size, bool writeback);
137};
138
139#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
140struct mCore* mCoreFind(const char* path);
141bool mCoreLoadFile(struct mCore* core, const char* path);
142
143bool mCoreAutoloadSave(struct mCore* core);
144bool mCoreAutoloadPatch(struct mCore* core);
145
146bool mCoreSaveState(struct mCore* core, int slot, int flags);
147bool mCoreLoadState(struct mCore* core, int slot, int flags);
148struct VFile* mCoreGetState(struct mCore* core, int slot, bool write);
149void mCoreDeleteState(struct mCore* core, int slot);
150
151void mCoreTakeScreenshot(struct mCore* core);
152#endif
153
154struct mCore* mCoreFindVF(struct VFile* vf);
155enum mPlatform mCoreIsCompatible(struct VFile* vf);
156
157bool mCoreSaveStateNamed(struct mCore* core, struct VFile* vf, int flags);
158bool mCoreLoadStateNamed(struct mCore* core, struct VFile* vf, int flags);
159
160void mCoreInitConfig(struct mCore* core, const char* port);
161void mCoreLoadConfig(struct mCore* core);
162void mCoreLoadForeignConfig(struct mCore* core, const struct mCoreConfig* config);
163
164CXX_GUARD_END
165
166#endif