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