all repos — mgba @ 484618ca4c5f59f62a73018051ca6397472ea35e

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