all repos — mgba @ a2c1ef2fcc0d3aab083962eb1efa09feee819c54

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_RGB8(X) ((M_R5(X) << 3) | (M_G5(X) << 11) | (M_B5(X) << 19))
 35#define M_RGB8_TO_RGB5(X) ((((X) & 0xF8) >> 3) | (((X) & 0xF800) >> 6) | (((X) & 0xF80000) >> 9))
 36
 37struct blip_t;
 38
 39struct mCoreCallbacks {
 40	void* context;
 41	void (*videoFrameStarted)(void* context);
 42	void (*videoFrameEnded)(void* context);
 43	void (*coreCrashed)(void* context);
 44	void (*sleep)(void* context);
 45};
 46
 47DECLARE_VECTOR(mCoreCallbacksList, struct mCoreCallbacks);
 48
 49struct mAVStream {
 50	void (*videoDimensionsChanged)(struct mAVStream*, unsigned width, unsigned height);
 51	void (*postVideoFrame)(struct mAVStream*, const color_t* buffer, size_t stride);
 52	void (*postAudioFrame)(struct mAVStream*, int16_t left, int16_t right);
 53	void (*postAudioBuffer)(struct mAVStream*, struct blip_t* left, struct blip_t* right);
 54};
 55
 56struct mKeyCallback {
 57	uint16_t (*readKeys)(struct mKeyCallback*);
 58};
 59
 60enum mPeripheral {
 61	mPERIPH_ROTATION = 1,
 62	mPERIPH_RUMBLE,
 63	mPERIPH_CUSTOM = 0x1000
 64};
 65
 66struct mRotationSource {
 67	void (*sample)(struct mRotationSource*);
 68
 69	int32_t (*readTiltX)(struct mRotationSource*);
 70	int32_t (*readTiltY)(struct mRotationSource*);
 71
 72	int32_t (*readGyroZ)(struct mRotationSource*);
 73};
 74
 75struct mRTCSource {
 76	void (*sample)(struct mRTCSource*);
 77
 78	time_t (*unixTime)(struct mRTCSource*);
 79
 80	void (*serialize)(struct mRTCSource*, struct mStateExtdataItem*);
 81	bool (*deserialize)(struct mRTCSource*, const struct mStateExtdataItem*);
 82};
 83
 84enum mRTCGenericType {
 85	RTC_NO_OVERRIDE,
 86	RTC_FIXED,
 87	RTC_FAKE_EPOCH,
 88	RTC_CUSTOM_START = 0x1000
 89};
 90
 91struct mRTCGenericSource {
 92	struct mRTCSource d;
 93	struct mCore* p;
 94	enum mRTCGenericType override;
 95	int64_t value;
 96	struct mRTCSource* custom;
 97};
 98
 99struct mRTCGenericState {
100	int32_t type;
101	int32_t padding;
102	int64_t value;
103};
104
105void mRTCGenericSourceInit(struct mRTCGenericSource* rtc, struct mCore* core);
106
107struct mRumble {
108	void (*setRumble)(struct mRumble*, int enable);
109};
110
111struct mCoreChannelInfo {
112	size_t id;
113	const char* internalName;
114	const char* visibleName;
115	const char* visibleType;
116};
117
118enum mCoreMemoryBlockFlags {
119	mCORE_MEMORY_READ = 0x01,
120	mCORE_MEMORY_WRITE = 0x02,
121	mCORE_MEMORY_RW = 0x03,
122	mCORE_MEMORY_MAPPED = 0x10,
123	mCORE_MEMORY_VIRTUAL = 0x20,
124};
125
126struct mCoreMemoryBlock {
127	size_t id;
128	const char* internalName;
129	const char* shortName;
130	const char* longName;
131	uint32_t start;
132	uint32_t end;
133	uint32_t size;
134	uint32_t flags;
135	uint16_t maxSegment;
136	uint32_t segmentStart;
137};
138
139CXX_GUARD_END
140
141#endif