all repos — mgba @ fd7d883e69cc573c7f1582eceaf1892e7e7a60e2

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
 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};
 56
 57struct mKeyCallback {
 58	uint16_t (*readKeys)(struct mKeyCallback*);
 59};
 60
 61enum mPeripheral {
 62	mPERIPH_ROTATION = 1,
 63	mPERIPH_RUMBLE,
 64	mPERIPH_CUSTOM = 0x1000
 65};
 66
 67struct mRotationSource {
 68	void (*sample)(struct mRotationSource*);
 69
 70	int32_t (*readTiltX)(struct mRotationSource*);
 71	int32_t (*readTiltY)(struct mRotationSource*);
 72
 73	int32_t (*readGyroZ)(struct mRotationSource*);
 74};
 75
 76struct mRTCSource {
 77	void (*sample)(struct mRTCSource*);
 78
 79	time_t (*unixTime)(struct mRTCSource*);
 80
 81	void (*serialize)(struct mRTCSource*, struct mStateExtdataItem*);
 82	bool (*deserialize)(struct mRTCSource*, const struct mStateExtdataItem*);
 83};
 84
 85enum mRTCGenericType {
 86	RTC_NO_OVERRIDE,
 87	RTC_FIXED,
 88	RTC_FAKE_EPOCH,
 89	RTC_CUSTOM_START = 0x1000
 90};
 91
 92struct mRTCGenericSource {
 93	struct mRTCSource d;
 94	struct mCore* p;
 95	enum mRTCGenericType override;
 96	int64_t value;
 97	struct mRTCSource* custom;
 98};
 99
100struct mRTCGenericState {
101	int32_t type;
102	int32_t padding;
103	int64_t value;
104};
105
106void mRTCGenericSourceInit(struct mRTCGenericSource* rtc, struct mCore* core);
107
108struct mRumble {
109	void (*setRumble)(struct mRumble*, int enable);
110};
111
112struct mCoreChannelInfo {
113	size_t id;
114	const char* internalName;
115	const char* visibleName;
116	const char* visibleType;
117};
118
119enum mCoreMemoryBlockFlags {
120	mCORE_MEMORY_READ = 0x01,
121	mCORE_MEMORY_WRITE = 0x02,
122	mCORE_MEMORY_RW = 0x03,
123	mCORE_MEMORY_MAPPED = 0x10,
124	mCORE_MEMORY_VIRTUAL = 0x20,
125};
126
127struct mCoreMemoryBlock {
128	size_t id;
129	const char* internalName;
130	const char* shortName;
131	const char* longName;
132	uint32_t start;
133	uint32_t end;
134	uint32_t size;
135	uint32_t flags;
136	uint16_t maxSegment;
137	uint32_t segmentStart;
138};
139
140CXX_GUARD_END
141
142#endif