all repos — mgba @ f5a1ceb0252ca4c92f19c000b0039bb82f4e62d3

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
 83enum mCoreFeature {
 84	mCORE_FEATURE_OPENGL = 1,
 85};
 86
 87struct mCoreCallbacks {
 88	void* context;
 89	void (*videoFrameStarted)(void* context);
 90	void (*videoFrameEnded)(void* context);
 91	void (*coreCrashed)(void* context);
 92	void (*sleep)(void* context);
 93	void (*keysRead)(void* context);
 94	void (*savedataUpdated)(void* context);
 95};
 96
 97DECLARE_VECTOR(mCoreCallbacksList, struct mCoreCallbacks);
 98
 99struct mAVStream {
100	void (*videoDimensionsChanged)(struct mAVStream*, unsigned width, unsigned height);
101	void (*postVideoFrame)(struct mAVStream*, const color_t* buffer, size_t stride);
102	void (*postAudioFrame)(struct mAVStream*, int16_t left, int16_t right);
103	void (*postAudioBuffer)(struct mAVStream*, struct blip_t* left, struct blip_t* right);
104};
105
106struct mKeyCallback {
107	uint16_t (*readKeys)(struct mKeyCallback*);
108};
109
110enum mPeripheral {
111	mPERIPH_ROTATION = 1,
112	mPERIPH_RUMBLE,
113	mPERIPH_IMAGE_SOURCE,
114	mPERIPH_CUSTOM = 0x1000
115};
116
117struct mRotationSource {
118	void (*sample)(struct mRotationSource*);
119
120	int32_t (*readTiltX)(struct mRotationSource*);
121	int32_t (*readTiltY)(struct mRotationSource*);
122
123	int32_t (*readGyroZ)(struct mRotationSource*);
124};
125
126struct mRTCSource {
127	void (*sample)(struct mRTCSource*);
128
129	time_t (*unixTime)(struct mRTCSource*);
130
131	void (*serialize)(struct mRTCSource*, struct mStateExtdataItem*);
132	bool (*deserialize)(struct mRTCSource*, const struct mStateExtdataItem*);
133};
134
135struct mImageSource {
136	void (*startRequestImage)(struct mImageSource*, unsigned w, unsigned h, int colorFormats);
137	void (*stopRequestImage)(struct mImageSource*);
138	void (*requestImage)(struct mImageSource*, const void** buffer, size_t* stride, enum mColorFormat* colorFormat);
139};
140
141enum mRTCGenericType {
142	RTC_NO_OVERRIDE,
143	RTC_FIXED,
144	RTC_FAKE_EPOCH,
145	RTC_CUSTOM_START = 0x1000
146};
147
148struct mRTCGenericSource {
149	struct mRTCSource d;
150	struct mCore* p;
151	enum mRTCGenericType override;
152	int64_t value;
153	struct mRTCSource* custom;
154};
155
156struct mRTCGenericState {
157	int32_t type;
158	int32_t padding;
159	int64_t value;
160};
161
162void mRTCGenericSourceInit(struct mRTCGenericSource* rtc, struct mCore* core);
163
164struct mRumble {
165	void (*setRumble)(struct mRumble*, int enable);
166};
167
168struct mCoreChannelInfo {
169	size_t id;
170	const char* internalName;
171	const char* visibleName;
172	const char* visibleType;
173};
174
175enum mCoreMemoryBlockFlags {
176	mCORE_MEMORY_READ = 0x01,
177	mCORE_MEMORY_WRITE = 0x02,
178	mCORE_MEMORY_RW = 0x03,
179	mCORE_MEMORY_WORM = 0x04,
180	mCORE_MEMORY_MAPPED = 0x10,
181	mCORE_MEMORY_VIRTUAL = 0x20,
182};
183
184struct mCoreMemoryBlock {
185	size_t id;
186	const char* internalName;
187	const char* shortName;
188	const char* longName;
189	uint32_t start;
190	uint32_t end;
191	uint32_t size;
192	uint32_t flags;
193	uint16_t maxSegment;
194	uint32_t segmentStart;
195};
196
197CXX_GUARD_END
198
199#endif