all repos — mgba @ 756474ac569989ed2cd6c940e70ce14d1e65a500

mGBA Game Boy Advance Emulator

include/mgba/internal/ds/gx.h (view raw)

  1/* Copyright (c) 2013-2017 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 DS_GX_H
  7#define DS_GX_H
  8
  9#include <mgba-util/common.h>
 10
 11CXX_GUARD_START
 12
 13#include <mgba/core/log.h>
 14#include <mgba/core/timing.h>
 15#include <mgba-util/circle-buffer.h>
 16
 17mLOG_DECLARE_CATEGORY(DS_GX);
 18
 19DECL_BITFIELD(DSRegGXSTAT, uint32_t);
 20DECL_BIT(DSRegGXSTAT, TestBusy, 0);
 21DECL_BIT(DSRegGXSTAT, BoxTestResult, 1);
 22DECL_BITS(DSRegGXSTAT, PVMatrixStackLevel, 8, 5);
 23DECL_BIT(DSRegGXSTAT, ProjMatrixStackLevel, 13);
 24DECL_BIT(DSRegGXSTAT, MatrixStackBusy, 14);
 25DECL_BIT(DSRegGXSTAT, MatrixStackError, 15);
 26DECL_BITS(DSRegGXSTAT, FIFOEntries, 16, 9);
 27DECL_BIT(DSRegGXSTAT, FIFOFull, 24);
 28DECL_BIT(DSRegGXSTAT, FIFOLtHalf, 25);
 29DECL_BIT(DSRegGXSTAT, FIFOEmpty, 26);
 30DECL_BIT(DSRegGXSTAT, Busy, 27);
 31DECL_BITS(DSRegGXSTAT, DoIRQ, 30, 2);
 32
 33enum DSGXCommand {
 34	DS_GX_CMD_NOP = 0,
 35	DS_GX_CMD_MTX_MODE = 0x10,
 36	DS_GX_CMD_MTX_PUSH = 0x11,
 37	DS_GX_CMD_MTX_POP = 0x12,
 38	DS_GX_CMD_MTX_STORE = 0x13,
 39	DS_GX_CMD_MTX_RESTORE = 0x14,
 40	DS_GX_CMD_MTX_IDENTITY = 0x15,
 41	DS_GX_CMD_MTX_LOAD_4x4 = 0x16,
 42	DS_GX_CMD_MTX_LOAD_4x3 = 0x17,
 43	DS_GX_CMD_MTX_MULT_4x4 = 0x18,
 44	DS_GX_CMD_MTX_MULT_4x3 = 0x19,
 45	DS_GX_CMD_MTX_MULT_3x3 = 0x1A,
 46	DS_GX_CMD_MTX_SCALE = 0x1B,
 47	DS_GX_CMD_MTX_TRANS = 0x1C,
 48	DS_GX_CMD_COLOR = 0x20,
 49	DS_GX_CMD_NORMAL = 0x21,
 50	DS_GX_CMD_TEXCOORD = 0x22,
 51	DS_GX_CMD_VTX_16 = 0x23,
 52	DS_GX_CMD_VTX_10 = 0x24,
 53	DS_GX_CMD_VTX_XY = 0x25,
 54	DS_GX_CMD_VTX_XZ = 0x26,
 55	DS_GX_CMD_VTX_YZ = 0x27,
 56	DS_GX_CMD_VTX_DIFF = 0x28,
 57	DS_GX_CMD_POLYGON_ATTR = 0x29,
 58	DS_GX_CMD_TEXIMAGE_PARAM = 0x2A,
 59	DS_GX_CMD_PLTT_BASE = 0x2B,
 60	DS_GX_CMD_DIF_AMB = 0x30,
 61	DS_GX_CMD_SPE_EMI = 0x31,
 62	DS_GX_CMD_LIGHT_VECTOR = 0x32,
 63	DS_GX_CMD_LIGHT_COLOR = 0x33,
 64	DS_GX_CMD_SHININESS = 0x34,
 65	DS_GX_CMD_BEGIN_VTXS = 0x40,
 66	DS_GX_CMD_END_VTXS = 0x41,
 67	DS_GX_CMD_SWAP_BUFFERS = 0x50,
 68	DS_GX_CMD_VIEWPORT = 0x60,
 69	DS_GX_CMD_BOX_TEST = 0x70,
 70	DS_GX_CMD_POS_TEST = 0x71,
 71	DS_GX_CMD_VEC_TEST = 0x72,
 72
 73	DS_GX_CMD_MAX
 74};
 75
 76#pragma pack(push, 1)
 77struct DSGXEntry {
 78	uint8_t command;
 79	uint8_t params[4];
 80};
 81#pragma pack(pop)
 82
 83struct DS;
 84struct DSGX {
 85	struct DS* p;
 86	struct DSGXEntry pipe[4];
 87	struct CircleBuffer fifo;
 88
 89	struct mTimingEvent fifoEvent;
 90
 91	bool swapBuffers;
 92};
 93
 94void DSGXInit(struct DSGX*);
 95void DSGXDeinit(struct DSGX*);
 96void DSGXReset(struct DSGX*);
 97
 98uint16_t DSGXWriteRegister(struct DSGX*, uint32_t address, uint16_t value);
 99uint32_t DSGXWriteRegister32(struct DSGX*, uint32_t address, uint32_t value);
100
101void DSGXSwapBuffers(struct DSGX*);
102void DSGXUpdateGXSTAT(struct DSGX*);
103
104CXX_GUARD_END
105
106#endif