all repos — mgba @ 338d29f5adb7e4c132dc6b5d6b00a4d20c2bc243

mGBA Game Boy Advance Emulator

include/mgba/internal/ds/video.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_VIDEO_H
  7#define DS_VIDEO_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/internal/gba/video.h>
 16
 17mLOG_DECLARE_CATEGORY(DS_VIDEO);
 18
 19enum {
 20	DS_VIDEO_HORIZONTAL_PIXELS = 256,
 21	DS_VIDEO_HBLANK_PIXELS = 99,
 22	DS7_VIDEO_HBLANK_LENGTH = 1613,
 23	DS9_VIDEO_HBLANK_LENGTH = 1606,
 24	DS_VIDEO_HORIZONTAL_LENGTH = (DS_VIDEO_HORIZONTAL_PIXELS + DS_VIDEO_HBLANK_PIXELS) * 6,
 25
 26	DS_VIDEO_VERTICAL_PIXELS = 192,
 27	DS_VIDEO_VBLANK_PIXELS = 71,
 28	DS_VIDEO_VERTICAL_TOTAL_PIXELS = DS_VIDEO_VERTICAL_PIXELS + DS_VIDEO_VBLANK_PIXELS,
 29
 30	DS_VIDEO_TOTAL_LENGTH = DS_VIDEO_HORIZONTAL_LENGTH * DS_VIDEO_VERTICAL_TOTAL_PIXELS,
 31};
 32
 33union DSOAM {
 34	union GBAOAM oam[2];
 35	uint16_t raw[1024];
 36};
 37
 38DECL_BITFIELD(DSRegisterDISPCNT, uint32_t);
 39DECL_BITS(DSRegisterDISPCNT, Mode, 0, 3);
 40DECL_BIT(DSRegisterDISPCNT, 3D, 3);
 41DECL_BIT(DSRegisterDISPCNT, TileObjMapping, 4);
 42DECL_BIT(DSRegisterDISPCNT, BitmapObj2D, 5);
 43DECL_BIT(DSRegisterDISPCNT, BitmapObjMapping, 6);
 44DECL_BIT(DSRegisterDISPCNT, ForcedBlank, 7);
 45DECL_BIT(DSRegisterDISPCNT, Bg0Enable, 8);
 46DECL_BIT(DSRegisterDISPCNT, Bg1Enable, 9);
 47DECL_BIT(DSRegisterDISPCNT, Bg2Enable, 10);
 48DECL_BIT(DSRegisterDISPCNT, Bg3Enable, 11);
 49DECL_BIT(DSRegisterDISPCNT, ObjEnable, 12);
 50DECL_BIT(DSRegisterDISPCNT, Win0Enable, 13);
 51DECL_BIT(DSRegisterDISPCNT, Win1Enable, 14);
 52DECL_BIT(DSRegisterDISPCNT, ObjwinEnable, 15);
 53DECL_BITS(DSRegisterDISPCNT, DispMode, 16, 2);
 54DECL_BITS(DSRegisterDISPCNT, VRAMBlock, 18, 2);
 55DECL_BITS(DSRegisterDISPCNT, TileBoundary, 20, 2);
 56// TODO
 57DECL_BITS(DSRegisterDISPCNT, CharBase, 24, 3);
 58DECL_BITS(DSRegisterDISPCNT, ScreenBase, 27, 3);
 59// TODO
 60DECL_BIT(DSRegisterDISPCNT, BgExtPalette, 30);
 61DECL_BIT(DSRegisterDISPCNT, ObjExtPalette, 31);
 62
 63DECL_BITFIELD(DSRegisterPOWCNT1, uint16_t);
 64// TODO
 65DECL_BIT(DSRegisterPOWCNT1, Swap, 15);
 66
 67DECL_BIT(GBARegisterBGCNT, ExtPaletteSlot, 13);
 68
 69DECL_BITFIELD(DSRegisterMASTER_BRIGHT, uint16_t);
 70DECL_BITS(DSRegisterMASTER_BRIGHT, Y, 0, 5);
 71DECL_BITS(DSRegisterMASTER_BRIGHT, Mode, 14, 2);
 72
 73struct DSGX;
 74struct DSVideoRenderer {
 75	void (*init)(struct DSVideoRenderer* renderer);
 76	void (*reset)(struct DSVideoRenderer* renderer);
 77	void (*deinit)(struct DSVideoRenderer* renderer);
 78
 79	uint16_t (*writeVideoRegister)(struct DSVideoRenderer* renderer, uint32_t address, uint16_t value);
 80	void (*writePalette)(struct DSVideoRenderer* renderer, uint32_t address, uint16_t value);
 81	void (*writeOAM)(struct DSVideoRenderer* renderer, uint32_t oam);
 82	void (*invalidateExtPal)(struct DSVideoRenderer* renderer, bool obj, bool engB, int slot);
 83	void (*drawScanline)(struct DSVideoRenderer* renderer, int y);
 84	void (*finishFrame)(struct DSVideoRenderer* renderer);
 85
 86	void (*getPixels)(struct DSVideoRenderer* renderer, size_t* stride, const void** pixels);
 87	void (*putPixels)(struct DSVideoRenderer* renderer, size_t stride, const void* pixels);
 88
 89	uint16_t* palette;
 90	uint16_t* vram;
 91	uint16_t* vramABG[32];
 92	uint16_t* vramAOBJ[32];
 93	uint16_t* vramABGExtPal[4];
 94	uint16_t* vramAOBJExtPal;
 95	uint16_t* vramBBG[32];
 96	uint16_t* vramBOBJ[32];
 97	uint16_t* vramBBGExtPal[4];
 98	uint16_t* vramBOBJExtPal;
 99	union DSOAM* oam;
100	struct DSGX* gx;
101};
102
103struct DS;
104struct DSVideo {
105	struct DS* p;
106	struct DSVideoRenderer* renderer;
107	struct mTimingEvent event7;
108	struct mTimingEvent event9;
109
110	// VCOUNT
111	int vcount;
112
113	uint16_t palette[1024];
114	uint16_t* vram;
115	uint16_t* vramABG[32];
116	uint16_t* vramAOBJ[32];
117	uint16_t* vramABGExtPal[4];
118	uint16_t* vramAOBJExtPal;
119	uint16_t* vramBBG[32];
120	uint16_t* vramBOBJ[32];
121	uint16_t* vramBBGExtPal[4];
122	uint16_t* vramBOBJExtPal;
123	union DSOAM oam;
124
125	int32_t frameCounter;
126	int frameskip;
127	int frameskipCounter;
128};
129
130void DSVideoInit(struct DSVideo* video);
131void DSVideoReset(struct DSVideo* video);
132void DSVideoDeinit(struct DSVideo* video);
133void DSVideoAssociateRenderer(struct DSVideo* video, struct DSVideoRenderer* renderer);
134
135struct DSCommon;
136void DSVideoWriteDISPSTAT(struct DSCommon* dscore, uint16_t value);
137
138struct DSMemory;
139void DSVideoConfigureVRAM(struct DS* ds, int index, uint8_t value, uint8_t oldValue);
140
141CXX_GUARD_START
142
143#endif