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