all repos — mgba @ fbda6d8a1cd76de2385c894bf9182f41af08b71d

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
 34struct blip_t;
 35
 36struct mCoreCallbacks {
 37	void* context;
 38	void (*videoFrameStarted)(void* context);
 39	void (*videoFrameEnded)(void* context);
 40	void (*coreCrashed)(void* context);
 41};
 42
 43DECLARE_VECTOR(mCoreCallbacksList, struct mCoreCallbacks);
 44
 45struct mAVStream {
 46	void (*videoDimensionsChanged)(struct mAVStream*, unsigned width, unsigned height);
 47	void (*postVideoFrame)(struct mAVStream*, const color_t* buffer, size_t stride);
 48	void (*postAudioFrame)(struct mAVStream*, int16_t left, int16_t right);
 49	void (*postAudioBuffer)(struct mAVStream*, struct blip_t* left, struct blip_t* right);
 50};
 51
 52struct mKeyCallback {
 53	uint16_t (*readKeys)(struct mKeyCallback*);
 54};
 55
 56struct mStopCallback {
 57	void (*stop)(struct mStopCallback*);
 58};
 59
 60struct mRotationSource {
 61	void (*sample)(struct mRotationSource*);
 62
 63	int32_t (*readTiltX)(struct mRotationSource*);
 64	int32_t (*readTiltY)(struct mRotationSource*);
 65
 66	int32_t (*readGyroZ)(struct mRotationSource*);
 67};
 68
 69struct mRTCSource {
 70	void (*sample)(struct mRTCSource*);
 71
 72	time_t (*unixTime)(struct mRTCSource*);
 73
 74	void (*serialize)(struct mRTCSource*, struct mStateExtdataItem*);
 75	bool (*deserialize)(struct mRTCSource*, const struct mStateExtdataItem*);
 76};
 77
 78enum mRTCGenericType {
 79	RTC_NO_OVERRIDE,
 80	RTC_FIXED,
 81	RTC_FAKE_EPOCH,
 82	RTC_CUSTOM_START = 0x1000
 83};
 84
 85struct mRTCGenericSource {
 86	struct mRTCSource d;
 87	struct mCore* p;
 88	enum mRTCGenericType override;
 89	int64_t value;
 90	struct mRTCSource* custom;
 91};
 92
 93struct mRTCGenericState {
 94	int32_t type;
 95	int32_t padding;
 96	int64_t value;
 97};
 98
 99void mRTCGenericSourceInit(struct mRTCGenericSource* rtc, struct mCore* core);
100
101struct mRumble {
102	void (*setRumble)(struct mRumble*, int enable);
103};
104
105CXX_GUARD_END
106
107#endif