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
16mLOG_DECLARE_CATEGORY(DS_VIDEO);
17
18enum {
19 DS_VIDEO_HORIZONTAL_PIXELS = 256,
20 DS_VIDEO_HBLANK_PIXELS = 99,
21 DS7_VIDEO_HBLANK_LENGTH = 1613,
22 DS9_VIDEO_HBLANK_LENGTH = 1606,
23 DS_VIDEO_HORIZONTAL_LENGTH = (DS_VIDEO_HORIZONTAL_PIXELS + DS_VIDEO_HBLANK_PIXELS) * 6,
24
25 DS_VIDEO_VERTICAL_PIXELS = 192,
26 DS_VIDEO_VBLANK_PIXELS = 71,
27 DS_VIDEO_VERTICAL_TOTAL_PIXELS = DS_VIDEO_VERTICAL_PIXELS + DS_VIDEO_VBLANK_PIXELS,
28
29 DS_VIDEO_TOTAL_LENGTH = DS_VIDEO_HORIZONTAL_LENGTH * DS_VIDEO_VERTICAL_TOTAL_PIXELS,
30};
31
32struct DSVideoRenderer {
33 void (*init)(struct DSVideoRenderer* renderer);
34 void (*reset)(struct DSVideoRenderer* renderer);
35 void (*deinit)(struct DSVideoRenderer* renderer);
36
37 uint16_t (*writeVideoRegister)(struct DSVideoRenderer* renderer, uint32_t address, uint16_t value);
38 void (*drawScanline)(struct DSVideoRenderer* renderer, int y);
39 void (*finishFrame)(struct DSVideoRenderer* renderer);
40
41 void (*getPixels)(struct DSVideoRenderer* renderer, size_t* stride, const void** pixels);
42 void (*putPixels)(struct DSVideoRenderer* renderer, size_t stride, const void* pixels);
43
44 uint16_t* vram;
45};
46
47struct DS;
48struct DSVideo {
49 struct DS* p;
50 struct DSVideoRenderer* renderer;
51 struct mTimingEvent event7;
52 struct mTimingEvent event9;
53
54 // VCOUNT
55 int vcount;
56
57 uint16_t* vram;
58
59 int32_t frameCounter;
60 int frameskip;
61 int frameskipCounter;
62};
63
64void DSVideoInit(struct DSVideo* video);
65void DSVideoReset(struct DSVideo* video);
66void DSVideoDeinit(struct DSVideo* video);
67void DSVideoAssociateRenderer(struct DSVideo* video, struct DSVideoRenderer* renderer);
68
69struct DSCommon;
70void DSVideoWriteDISPSTAT(struct DSCommon* dscore, uint16_t value);
71
72struct DSMemory;
73void DSVideoConfigureVRAM(struct DSMemory* memory, int index, uint8_t value);
74
75CXX_GUARD_START
76
77#endif