all repos — mgba @ c825c57281734bddefa16c05ec9d61a387029cf5

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