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