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_RGB8_TO_BGR5(X) ((((X) & 0xF8) >> 3) | (((X) & 0xF800) >> 6) | (((X) & 0xF80000) >> 9))
36#define M_RGB8_TO_RGB5(X) ((((X) & 0xF8) << 7) | (((X) & 0xF800) >> 6) | (((X) & 0xF80000) >> 19))
37
38#ifndef PYCPARSE
39static inline color_t mColorFrom555(uint16_t value) {
40#ifdef COLOR_16_BIT
41#ifdef COLOR_5_6_5
42 color_t color = 0;
43 color |= (value & 0x001F) << 11;
44 color |= (value & 0x03E0) << 1;
45 color |= (value & 0x7C00) >> 10;
46#else
47 color_t color = value;
48#endif
49#else
50 color_t color = M_RGB5_TO_BGR8(value);
51 color |= (color >> 5) & 0x070707;
52#endif
53 return color;
54}
55#endif
56
57struct blip_t;
58
59enum mColorFormat {
60 mCOLOR_XBGR8 = 0x00001,
61 mCOLOR_XRGB8 = 0x00002,
62 mCOLOR_BGRX8 = 0x00004,
63 mCOLOR_RGBX8 = 0x00008,
64 mCOLOR_ABGR8 = 0x00010,
65 mCOLOR_ARGB8 = 0x00020,
66 mCOLOR_BGRA8 = 0x00040,
67 mCOLOR_RGBA8 = 0x00080,
68 mCOLOR_RGB5 = 0x00100,
69 mCOLOR_BGR5 = 0x00200,
70 mCOLOR_RGB565 = 0x00400,
71 mCOLOR_BGR565 = 0x00800,
72 mCOLOR_ARGB5 = 0x01000,
73 mCOLOR_ABGR5 = 0x02000,
74 mCOLOR_RGBA5 = 0x04000,
75 mCOLOR_BGRA5 = 0x08000,
76 mCOLOR_RGB8 = 0x10000,
77 mCOLOR_BGR8 = 0x20000,
78
79 mCOLOR_ANY = -1
80};
81
82struct mCoreCallbacks {
83 void* context;
84 void (*videoFrameStarted)(void* context);
85 void (*videoFrameEnded)(void* context);
86 void (*coreCrashed)(void* context);
87 void (*sleep)(void* context);
88};
89
90DECLARE_VECTOR(mCoreCallbacksList, struct mCoreCallbacks);
91
92struct mAVStream {
93 void (*videoDimensionsChanged)(struct mAVStream*, unsigned width, unsigned height);
94 void (*postVideoFrame)(struct mAVStream*, const color_t* buffer, size_t stride);
95 void (*postAudioFrame)(struct mAVStream*, int16_t left, int16_t right);
96 void (*postAudioBuffer)(struct mAVStream*, struct blip_t* left, struct blip_t* right);
97};
98
99struct mKeyCallback {
100 uint16_t (*readKeys)(struct mKeyCallback*);
101};
102
103enum mPeripheral {
104 mPERIPH_ROTATION = 1,
105 mPERIPH_RUMBLE,
106 mPERIPH_IMAGE_SOURCE,
107 mPERIPH_CUSTOM = 0x1000
108};
109
110struct mRotationSource {
111 void (*sample)(struct mRotationSource*);
112
113 int32_t (*readTiltX)(struct mRotationSource*);
114 int32_t (*readTiltY)(struct mRotationSource*);
115
116 int32_t (*readGyroZ)(struct mRotationSource*);
117};
118
119struct mRTCSource {
120 void (*sample)(struct mRTCSource*);
121
122 time_t (*unixTime)(struct mRTCSource*);
123
124 void (*serialize)(struct mRTCSource*, struct mStateExtdataItem*);
125 bool (*deserialize)(struct mRTCSource*, const struct mStateExtdataItem*);
126};
127
128struct mImageSource {
129 void (*startRequestImage)(struct mImageSource*, unsigned w, unsigned h, int colorFormats);
130 void (*stopRequestImage)(struct mImageSource*);
131 void (*requestImage)(struct mImageSource*, const void** buffer, size_t* stride, enum mColorFormat* colorFormat);
132};
133
134enum mRTCGenericType {
135 RTC_NO_OVERRIDE,
136 RTC_FIXED,
137 RTC_FAKE_EPOCH,
138 RTC_CUSTOM_START = 0x1000
139};
140
141struct mRTCGenericSource {
142 struct mRTCSource d;
143 struct mCore* p;
144 enum mRTCGenericType override;
145 int64_t value;
146 struct mRTCSource* custom;
147};
148
149struct mRTCGenericState {
150 int32_t type;
151 int32_t padding;
152 int64_t value;
153};
154
155void mRTCGenericSourceInit(struct mRTCGenericSource* rtc, struct mCore* core);
156
157struct mRumble {
158 void (*setRumble)(struct mRumble*, int enable);
159};
160
161struct mCoreChannelInfo {
162 size_t id;
163 const char* internalName;
164 const char* visibleName;
165 const char* visibleType;
166};
167
168enum mCoreMemoryBlockFlags {
169 mCORE_MEMORY_READ = 0x01,
170 mCORE_MEMORY_WRITE = 0x02,
171 mCORE_MEMORY_RW = 0x03,
172 mCORE_MEMORY_MAPPED = 0x10,
173 mCORE_MEMORY_VIRTUAL = 0x20,
174};
175
176struct mCoreMemoryBlock {
177 size_t id;
178 const char* internalName;
179 const char* shortName;
180 const char* longName;
181 uint32_t start;
182 uint32_t end;
183 uint32_t size;
184 uint32_t flags;
185 uint16_t maxSegment;
186 uint32_t segmentStart;
187};
188
189CXX_GUARD_END
190
191#endif