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