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