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
34struct blip_t;
35
36struct mCoreCallbacks {
37 void* context;
38 void (*videoFrameStarted)(void* context);
39 void (*videoFrameEnded)(void* context);
40 void (*coreCrashed)(void* context);
41 void (*sleep)(void* context);
42};
43
44DECLARE_VECTOR(mCoreCallbacksList, struct mCoreCallbacks);
45
46struct mAVStream {
47 void (*videoDimensionsChanged)(struct mAVStream*, unsigned width, unsigned height);
48 void (*postVideoFrame)(struct mAVStream*, const color_t* buffer, size_t stride);
49 void (*postAudioFrame)(struct mAVStream*, int16_t left, int16_t right);
50 void (*postAudioBuffer)(struct mAVStream*, struct blip_t* left, struct blip_t* right);
51 void (*videoFrameRateChanged)(struct mAVStream*, unsigned numerator, unsigned denominator);
52};
53
54struct mKeyCallback {
55 uint16_t (*readKeys)(struct mKeyCallback*);
56};
57
58enum mPeripheral {
59 mPERIPH_ROTATION = 1,
60 mPERIPH_RUMBLE,
61 mPERIPH_CUSTOM = 0x1000
62};
63
64struct mRotationSource {
65 void (*sample)(struct mRotationSource*);
66
67 int32_t (*readTiltX)(struct mRotationSource*);
68 int32_t (*readTiltY)(struct mRotationSource*);
69
70 int32_t (*readGyroZ)(struct mRotationSource*);
71};
72
73struct mRTCSource {
74 void (*sample)(struct mRTCSource*);
75
76 time_t (*unixTime)(struct mRTCSource*);
77
78 void (*serialize)(struct mRTCSource*, struct mStateExtdataItem*);
79 bool (*deserialize)(struct mRTCSource*, const struct mStateExtdataItem*);
80};
81
82enum mRTCGenericType {
83 RTC_NO_OVERRIDE,
84 RTC_FIXED,
85 RTC_FAKE_EPOCH,
86 RTC_CUSTOM_START = 0x1000
87};
88
89struct mRTCGenericSource {
90 struct mRTCSource d;
91 struct mCore* p;
92 enum mRTCGenericType override;
93 int64_t value;
94 struct mRTCSource* custom;
95};
96
97struct mRTCGenericState {
98 int32_t type;
99 int32_t padding;
100 int64_t value;
101};
102
103void mRTCGenericSourceInit(struct mRTCGenericSource* rtc, struct mCore* core);
104
105struct mRumble {
106 void (*setRumble)(struct mRumble*, int enable);
107};
108
109struct mCoreChannelInfo {
110 size_t id;
111 const char* internalName;
112 const char* visibleName;
113 const char* visibleType;
114};
115
116CXX_GUARD_END
117
118#endif