all repos — mgba @ 5f1011d4744195d40685b94f78df0ad0e2158974

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