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)(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 (*setAVStream)(struct mCore*, struct mAVStream*);
68
69 bool (*isROM)(struct VFile* vf);
70 bool (*loadROM)(struct mCore*, struct VFile* vf);
71 bool (*loadSave)(struct mCore*, struct VFile* vf);
72 bool (*loadTemporarySave)(struct mCore*, struct VFile* vf);
73 void (*unloadROM)(struct mCore*);
74
75 bool (*loadBIOS)(struct mCore*, struct VFile* vf, int biosID);
76 bool (*selectBIOS)(struct mCore*, int biosID);
77
78 bool (*loadPatch)(struct mCore*, struct VFile* vf);
79
80 void (*reset)(struct mCore*);
81 void (*runFrame)(struct mCore*);
82 void (*runLoop)(struct mCore*);
83 void (*step)(struct mCore*);
84
85 size_t (*stateSize)(struct mCore*);
86 bool (*loadState)(struct mCore*, const void* state);
87 bool (*saveState)(struct mCore*, void* state);
88
89 void (*setKeys)(struct mCore*, uint32_t keys);
90 void (*addKeys)(struct mCore*, uint32_t keys);
91 void (*clearKeys)(struct mCore*, uint32_t keys);
92
93 int32_t (*frameCounter)(struct mCore*);
94 int32_t (*frameCycles)(struct mCore*);
95 int32_t (*frequency)(struct mCore*);
96
97 void (*getGameTitle)(struct mCore*, char* title);
98 void (*getGameCode)(struct mCore*, char* title);
99
100 void (*setRTC)(struct mCore*, struct mRTCSource*);
101 void (*setRotation)(struct mCore*, struct mRotationSource*);
102 void (*setRumble)(struct mCore*, struct mRumble*);
103
104 uint32_t (*busRead8)(struct mCore*, uint32_t address);
105 uint32_t (*busRead16)(struct mCore*, uint32_t address);
106 uint32_t (*busRead32)(struct mCore*, uint32_t address);
107
108 void (*busWrite8)(struct mCore*, uint32_t address, uint8_t);
109void (*busWrite16)(struct mCore*, uint32_t address, uint16_t);
110 void (*busWrite32)(struct mCore*, uint32_t address, uint32_t);
111
112 uint32_t (*rawRead8)(struct mCore*, uint32_t address, int segment);
113 uint32_t (*rawRead16)(struct mCore*, uint32_t address, int segment);
114 uint32_t (*rawRead32)(struct mCore*, uint32_t address, int segment);
115
116 void (*rawWrite8)(struct mCore*, uint32_t address, int segment, uint8_t);
117 void (*rawWrite16)(struct mCore*, uint32_t address, int segment, uint16_t);
118 void (*rawWrite32)(struct mCore*, uint32_t address, int segment, uint32_t);
119
120 bool (*supportsDebuggerType)(struct mCore*, enum mDebuggerType);
121 struct mDebuggerPlatform* (*debuggerPlatform)(struct mCore*);
122 struct CLIDebuggerSystem* (*cliDebuggerSystem)(struct mCore*);
123 void (*attachDebugger)(struct mCore*, struct mDebugger*);
124 void (*detachDebugger)(struct mCore*);
125
126 struct mCheatDevice* (*cheatDevice)(struct mCore*);
127
128 size_t (*savedataClone)(struct mCore*, void** sram);
129 bool (*savedataLoad)(struct mCore*, const void* sram, size_t size);
130};
131
132#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
133struct mCore* mCoreFind(const char* path);
134bool mCoreLoadFile(struct mCore* core, const char* path);
135
136bool mCoreAutoloadSave(struct mCore* core);
137bool mCoreAutoloadPatch(struct mCore* core);
138
139bool mCoreSaveState(struct mCore* core, int slot, int flags);
140bool mCoreLoadState(struct mCore* core, int slot, int flags);
141struct VFile* mCoreGetState(struct mCore* core, int slot, bool write);
142void mCoreDeleteState(struct mCore* core, int slot);
143
144void mCoreTakeScreenshot(struct mCore* core);
145#endif
146
147struct mCore* mCoreFindVF(struct VFile* vf);
148enum mPlatform mCoreIsCompatible(struct VFile* vf);
149
150bool mCoreSaveStateNamed(struct mCore* core, struct VFile* vf, int flags);
151bool mCoreLoadStateNamed(struct mCore* core, struct VFile* vf, int flags);
152
153void mCoreInitConfig(struct mCore* core, const char* port);
154void mCoreLoadConfig(struct mCore* core);
155void mCoreLoadForeignConfig(struct mCore* core, const struct mCoreConfig* config);
156
157#endif