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
60
61struct DSVideoRenderer {
62 void (*init)(struct DSVideoRenderer* renderer);
63 void (*reset)(struct DSVideoRenderer* renderer);
64 void (*deinit)(struct DSVideoRenderer* renderer);
65
66 uint16_t (*writeVideoRegister)(struct DSVideoRenderer* renderer, uint32_t address, uint16_t value);
67 void (*writePalette)(struct DSVideoRenderer* renderer, uint32_t address, uint16_t value);
68 void (*writeOAM)(struct DSVideoRenderer* renderer, uint32_t oam);
69 void (*drawScanline)(struct DSVideoRenderer* renderer, int y);
70 void (*finishFrame)(struct DSVideoRenderer* renderer);
71
72 void (*getPixels)(struct DSVideoRenderer* renderer, size_t* stride, const void** pixels);
73 void (*putPixels)(struct DSVideoRenderer* renderer, size_t stride, const void* pixels);
74
75 uint16_t* palette;
76 uint16_t* vram;
77 uint16_t* vramABG[32];
78 uint16_t* vramAOBJ[32];
79 uint16_t* vramBBG[32];
80 uint16_t* vramBOBJ[32];
81 union DSOAM* oam;
82};
83
84struct DS;
85struct DSVideo {
86 struct DS* p;
87 struct DSVideoRenderer* renderer;
88 struct mTimingEvent event7;
89 struct mTimingEvent event9;
90
91 // VCOUNT
92 int vcount;
93
94 uint16_t palette[1024];
95 uint16_t* vram;
96 uint16_t* vramABG[32];
97 uint16_t* vramAOBJ[32];
98 uint16_t* vramBBG[32];
99 uint16_t* vramBOBJ[32];
100 union DSOAM oam;
101
102 int32_t frameCounter;
103 int frameskip;
104 int frameskipCounter;
105};
106
107void DSVideoInit(struct DSVideo* video);
108void DSVideoReset(struct DSVideo* video);
109void DSVideoDeinit(struct DSVideo* video);
110void DSVideoAssociateRenderer(struct DSVideo* video, struct DSVideoRenderer* renderer);
111
112struct DSCommon;
113void DSVideoWriteDISPSTAT(struct DSCommon* dscore, uint16_t value);
114
115struct DSMemory;
116void DSVideoConfigureVRAM(struct DS* ds, int index, uint8_t value);
117
118CXX_GUARD_START
119
120#endif