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};
52
53struct mKeyCallback {
54 uint16_t (*readKeys)(struct mKeyCallback*);
55};
56
57enum mPeripheral {
58 mPERIPH_ROTATION = 1,
59 mPERIPH_RUMBLE,
60 mPERIPH_CUSTOM = 0x1000
61};
62
63struct mRotationSource {
64 void (*sample)(struct mRotationSource*);
65
66 int32_t (*readTiltX)(struct mRotationSource*);
67 int32_t (*readTiltY)(struct mRotationSource*);
68
69 int32_t (*readGyroZ)(struct mRotationSource*);
70};
71
72struct mRTCSource {
73 void (*sample)(struct mRTCSource*);
74
75 time_t (*unixTime)(struct mRTCSource*);
76
77 void (*serialize)(struct mRTCSource*, struct mStateExtdataItem*);
78 bool (*deserialize)(struct mRTCSource*, const struct mStateExtdataItem*);
79};
80
81enum mRTCGenericType {
82 RTC_NO_OVERRIDE,
83 RTC_FIXED,
84 RTC_FAKE_EPOCH,
85 RTC_CUSTOM_START = 0x1000
86};
87
88struct mRTCGenericSource {
89 struct mRTCSource d;
90 struct mCore* p;
91 enum mRTCGenericType override;
92 int64_t value;
93 struct mRTCSource* custom;
94};
95
96struct mRTCGenericState {
97 int32_t type;
98 int32_t padding;
99 int64_t value;
100};
101
102void mRTCGenericSourceInit(struct mRTCGenericSource* rtc, struct mCore* core);
103
104struct mRumble {
105 void (*setRumble)(struct mRumble*, int enable);
106};
107
108CXX_GUARD_END
109
110#endif