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
40struct mCoreCallbacks {
41 void* context;
42 void (*videoFrameStarted)(void* context);
43 void (*videoFrameEnded)(void* context);
44 void (*coreCrashed)(void* context);
45 void (*sleep)(void* context);
46};
47
48DECLARE_VECTOR(mCoreCallbacksList, struct mCoreCallbacks);
49
50struct mAVStream {
51 void (*videoDimensionsChanged)(struct mAVStream*, unsigned width, unsigned height);
52 void (*postVideoFrame)(struct mAVStream*, const color_t* buffer, size_t stride);
53 void (*postAudioFrame)(struct mAVStream*, int16_t left, int16_t right);
54 void (*postAudioBuffer)(struct mAVStream*, struct blip_t* left, struct blip_t* right);
55};
56
57struct mKeyCallback {
58 uint16_t (*readKeys)(struct mKeyCallback*);
59};
60
61enum mPeripheral {
62 mPERIPH_ROTATION = 1,
63 mPERIPH_RUMBLE,
64 mPERIPH_IMAGE_SOURCE,
65 mPERIPH_CUSTOM = 0x1000
66};
67
68struct mRotationSource {
69 void (*sample)(struct mRotationSource*);
70
71 int32_t (*readTiltX)(struct mRotationSource*);
72 int32_t (*readTiltY)(struct mRotationSource*);
73
74 int32_t (*readGyroZ)(struct mRotationSource*);
75};
76
77struct mRTCSource {
78 void (*sample)(struct mRTCSource*);
79
80 time_t (*unixTime)(struct mRTCSource*);
81
82 void (*serialize)(struct mRTCSource*, struct mStateExtdataItem*);
83 bool (*deserialize)(struct mRTCSource*, const struct mStateExtdataItem*);
84};
85
86struct mImageSource {
87 void (*startRequestImage)(struct mImageSource*, unsigned w, unsigned h);
88 void (*stopRequestImage)(struct mImageSource*);
89 void (*requestImage)(struct mImageSource*, const uint32_t** buffer, size_t* stride);
90};
91
92enum mRTCGenericType {
93 RTC_NO_OVERRIDE,
94 RTC_FIXED,
95 RTC_FAKE_EPOCH,
96 RTC_CUSTOM_START = 0x1000
97};
98
99struct mRTCGenericSource {
100 struct mRTCSource d;
101 struct mCore* p;
102 enum mRTCGenericType override;
103 int64_t value;
104 struct mRTCSource* custom;
105};
106
107struct mRTCGenericState {
108 int32_t type;
109 int32_t padding;
110 int64_t value;
111};
112
113void mRTCGenericSourceInit(struct mRTCGenericSource* rtc, struct mCore* core);
114
115struct mRumble {
116 void (*setRumble)(struct mRumble*, int enable);
117};
118
119struct mCoreChannelInfo {
120 size_t id;
121 const char* internalName;
122 const char* visibleName;
123 const char* visibleType;
124};
125
126enum mCoreMemoryBlockFlags {
127 mCORE_MEMORY_READ = 0x01,
128 mCORE_MEMORY_WRITE = 0x02,
129 mCORE_MEMORY_RW = 0x03,
130 mCORE_MEMORY_MAPPED = 0x10,
131 mCORE_MEMORY_VIRTUAL = 0x20,
132};
133
134struct mCoreMemoryBlock {
135 size_t id;
136 const char* internalName;
137 const char* shortName;
138 const char* longName;
139 uint32_t start;
140 uint32_t end;
141 uint32_t size;
142 uint32_t flags;
143 uint16_t maxSegment;
144 uint32_t segmentStart;
145};
146
147CXX_GUARD_END
148
149#endif