all repos — mgba @ 6e1ae2321eab2562bd7db11dd096a9bd1e7cd1a2

mGBA Game Boy Advance Emulator

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