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 void (*videoFrameRateChanged)(struct mAVStream*, unsigned numerator, unsigned denominator);
56};
57
58struct mKeyCallback {
59 uint16_t (*readKeys)(struct mKeyCallback*);
60};
61
62enum mPeripheral {
63 mPERIPH_ROTATION = 1,
64 mPERIPH_RUMBLE,
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
86enum mRTCGenericType {
87 RTC_NO_OVERRIDE,
88 RTC_FIXED,
89 RTC_FAKE_EPOCH,
90 RTC_CUSTOM_START = 0x1000
91};
92
93struct mRTCGenericSource {
94 struct mRTCSource d;
95 struct mCore* p;
96 enum mRTCGenericType override;
97 int64_t value;
98 struct mRTCSource* custom;
99};
100
101struct mRTCGenericState {
102 int32_t type;
103 int32_t padding;
104 int64_t value;
105};
106
107void mRTCGenericSourceInit(struct mRTCGenericSource* rtc, struct mCore* core);
108
109struct mRumble {
110 void (*setRumble)(struct mRumble*, int enable);
111};
112
113struct mCoreChannelInfo {
114 size_t id;
115 const char* internalName;
116 const char* visibleName;
117 const char* visibleType;
118};
119
120enum mCoreMemoryBlockFlags {
121 mCORE_MEMORY_READ = 0x01,
122 mCORE_MEMORY_WRITE = 0x02,
123 mCORE_MEMORY_RW = 0x03,
124 mCORE_MEMORY_MAPPED = 0x10,
125 mCORE_MEMORY_VIRTUAL = 0x20,
126};
127
128struct mCoreMemoryBlock {
129 size_t id;
130 const char* internalName;
131 const char* shortName;
132 const char* longName;
133 uint32_t start;
134 uint32_t end;
135 uint32_t size;
136 uint32_t flags;
137 uint16_t maxSegment;
138 uint32_t segmentStart;
139};
140
141CXX_GUARD_END
142
143#endif