include/mgba/core/interface.h (view raw)
1/* Copyright (c) 2013-2015 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 CORE_INTERFACE_H
7#define CORE_INTERFACE_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba-util/vector.h>
14
15struct mCore;
16struct mStateExtdataItem;
17
18#ifdef COLOR_16_BIT
19typedef uint16_t color_t;
20#define BYTES_PER_PIXEL 2
21#else
22typedef uint32_t color_t;
23#define BYTES_PER_PIXEL 4
24#endif
25
26#define M_R5(X) ((X) & 0x1F)
27#define M_G5(X) (((X) >> 5) & 0x1F)
28#define M_B5(X) (((X) >> 10) & 0x1F)
29
30#define M_R8(X) (((((X) << 3) & 0xF8) * 0x21) >> 5)
31#define M_G8(X) (((((X) >> 2) & 0xF8) * 0x21) >> 5)
32#define M_B8(X) (((((X) >> 7) & 0xF8) * 0x21) >> 5)
33
34#define M_RGB5_TO_BGR8(X) ((M_R5(X) << 3) | (M_G5(X) << 11) | (M_B5(X) << 19))
35#define M_RGB5_TO_RGB8(X) ((M_R5(X) << 19) | (M_G5(X) << 11) | (M_B5(X) << 3))
36#define M_RGB8_TO_BGR5(X) ((((X) & 0xF8) >> 3) | (((X) & 0xF800) >> 6) | (((X) & 0xF80000) >> 9))
37#define M_RGB8_TO_RGB5(X) ((((X) & 0xF8) << 7) | (((X) & 0xF800) >> 6) | (((X) & 0xF80000) >> 19))
38
39#ifndef COLOR_16_BIT
40#define M_COLOR_RED 0x000000FF
41#define M_COLOR_GREEN 0x0000FF00
42#define M_COLOR_BLUE 0x00FF0000
43#define M_COLOR_ALPHA 0xFF000000
44#define M_COLOR_WHITE 0x00FFFFFF
45#elif defined(COLOR_5_6_5)
46#define M_COLOR_RED 0x001F
47#define M_COLOR_GREEN 0x07E0
48#define M_COLOR_BLUE 0xF800
49#define M_COLOR_ALPHA 0x0000
50#define M_COLOR_WHITE 0xFFDF
51#else
52#define M_COLOR_RED 0x001F
53#define M_COLOR_GREEN 0x03E0
54#define M_COLOR_BLUE 0x7C00
55#define M_COLOR_ALPHA 0x1000
56#define M_COLOR_WHITE 0x7FFF
57#endif
58
59#ifndef PYCPARSE
60static inline color_t mColorFrom555(uint16_t value) {
61#ifdef COLOR_16_BIT
62#ifdef COLOR_5_6_5
63 color_t color = 0;
64 color |= (value & 0x001F) << 11;
65 color |= (value & 0x03E0) << 1;
66 color |= (value & 0x7C00) >> 10;
67#else
68 color_t color = value;
69#endif
70#else
71 color_t color = M_RGB5_TO_BGR8(value);
72 color |= (color >> 5) & 0x070707;
73#endif
74 return color;
75}
76#endif
77
78struct blip_t;
79
80enum mColorFormat {
81 mCOLOR_XBGR8 = 0x00001,
82 mCOLOR_XRGB8 = 0x00002,
83 mCOLOR_BGRX8 = 0x00004,
84 mCOLOR_RGBX8 = 0x00008,
85 mCOLOR_ABGR8 = 0x00010,
86 mCOLOR_ARGB8 = 0x00020,
87 mCOLOR_BGRA8 = 0x00040,
88 mCOLOR_RGBA8 = 0x00080,
89 mCOLOR_RGB5 = 0x00100,
90 mCOLOR_BGR5 = 0x00200,
91 mCOLOR_RGB565 = 0x00400,
92 mCOLOR_BGR565 = 0x00800,
93 mCOLOR_ARGB5 = 0x01000,
94 mCOLOR_ABGR5 = 0x02000,
95 mCOLOR_RGBA5 = 0x04000,
96 mCOLOR_BGRA5 = 0x08000,
97 mCOLOR_RGB8 = 0x10000,
98 mCOLOR_BGR8 = 0x20000,
99
100 mCOLOR_ANY = -1
101};
102
103enum mCoreFeature {
104 mCORE_FEATURE_OPENGL = 1,
105};
106
107struct mCoreCallbacks {
108 void* context;
109 void (*videoFrameStarted)(void* context);
110 void (*videoFrameEnded)(void* context);
111 void (*coreCrashed)(void* context);
112 void (*sleep)(void* context);
113 void (*shutdown)(void* context);
114 void (*keysRead)(void* context);
115 void (*savedataUpdated)(void* context);
116};
117
118DECLARE_VECTOR(mCoreCallbacksList, struct mCoreCallbacks);
119
120struct mAVStream {
121 void (*videoDimensionsChanged)(struct mAVStream*, unsigned width, unsigned height);
122 void (*postVideoFrame)(struct mAVStream*, const color_t* buffer, size_t stride);
123 void (*postAudioFrame)(struct mAVStream*, int16_t left, int16_t right);
124 void (*postAudioBuffer)(struct mAVStream*, struct blip_t* left, struct blip_t* right);
125};
126
127struct mKeyCallback {
128 uint16_t (*readKeys)(struct mKeyCallback*);
129};
130
131enum mPeripheral {
132 mPERIPH_ROTATION = 1,
133 mPERIPH_RUMBLE,
134 mPERIPH_IMAGE_SOURCE,
135 mPERIPH_CUSTOM = 0x1000
136};
137
138struct mRotationSource {
139 void (*sample)(struct mRotationSource*);
140
141 int32_t (*readTiltX)(struct mRotationSource*);
142 int32_t (*readTiltY)(struct mRotationSource*);
143
144 int32_t (*readGyroZ)(struct mRotationSource*);
145};
146
147struct mRTCSource {
148 void (*sample)(struct mRTCSource*);
149
150 time_t (*unixTime)(struct mRTCSource*);
151
152 void (*serialize)(struct mRTCSource*, struct mStateExtdataItem*);
153 bool (*deserialize)(struct mRTCSource*, const struct mStateExtdataItem*);
154};
155
156struct mImageSource {
157 void (*startRequestImage)(struct mImageSource*, unsigned w, unsigned h, int colorFormats);
158 void (*stopRequestImage)(struct mImageSource*);
159 void (*requestImage)(struct mImageSource*, const void** buffer, size_t* stride, enum mColorFormat* colorFormat);
160};
161
162enum mRTCGenericType {
163 RTC_NO_OVERRIDE,
164 RTC_FIXED,
165 RTC_FAKE_EPOCH,
166 RTC_CUSTOM_START = 0x1000
167};
168
169struct mRTCGenericSource {
170 struct mRTCSource d;
171 struct mCore* p;
172 enum mRTCGenericType override;
173 int64_t value;
174 struct mRTCSource* custom;
175};
176
177struct mRTCGenericState {
178 int32_t type;
179 int32_t padding;
180 int64_t value;
181};
182
183void mRTCGenericSourceInit(struct mRTCGenericSource* rtc, struct mCore* core);
184
185struct mRumble {
186 void (*setRumble)(struct mRumble*, int enable);
187};
188
189struct mCoreChannelInfo {
190 size_t id;
191 const char* internalName;
192 const char* visibleName;
193 const char* visibleType;
194};
195
196enum mCoreMemoryBlockFlags {
197 mCORE_MEMORY_READ = 0x01,
198 mCORE_MEMORY_WRITE = 0x02,
199 mCORE_MEMORY_RW = 0x03,
200 mCORE_MEMORY_WORM = 0x04,
201 mCORE_MEMORY_MAPPED = 0x10,
202 mCORE_MEMORY_VIRTUAL = 0x20,
203};
204
205struct mCoreMemoryBlock {
206 size_t id;
207 const char* internalName;
208 const char* shortName;
209 const char* longName;
210 uint32_t start;
211 uint32_t end;
212 uint32_t size;
213 uint32_t flags;
214 uint16_t maxSegment;
215 uint32_t segmentStart;
216};
217
218CXX_GUARD_END
219
220#endif