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