all repos — mgba @ 871c21fb6cf9041b4ac7c7f7074e0b2eb77484fe

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