all repos — mgba @ 5ad70925670fcc5069eb093c264d62f45c6b7131

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
38struct DSVideoRenderer {
39	void (*init)(struct DSVideoRenderer* renderer);
40	void (*reset)(struct DSVideoRenderer* renderer);
41	void (*deinit)(struct DSVideoRenderer* renderer);
42
43	uint16_t (*writeVideoRegister)(struct DSVideoRenderer* renderer, uint32_t address, uint16_t value);
44	void (*drawScanline)(struct DSVideoRenderer* renderer, int y);
45	void (*finishFrame)(struct DSVideoRenderer* renderer);
46
47	void (*getPixels)(struct DSVideoRenderer* renderer, size_t* stride, const void** pixels);
48	void (*putPixels)(struct DSVideoRenderer* renderer, size_t stride, const void* pixels);
49
50	uint16_t* palette;
51	uint16_t* vram;
52	union DSOAM* oam;
53};
54
55struct DS;
56struct DSVideo {
57	struct DS* p;
58	struct DSVideoRenderer* renderer;
59	struct mTimingEvent event7;
60	struct mTimingEvent event9;
61
62	// VCOUNT
63	int vcount;
64
65	uint16_t palette[1024];
66	uint16_t* vram;
67	union DSOAM oam;
68
69	int32_t frameCounter;
70	int frameskip;
71	int frameskipCounter;
72};
73
74void DSVideoInit(struct DSVideo* video);
75void DSVideoReset(struct DSVideo* video);
76void DSVideoDeinit(struct DSVideo* video);
77void DSVideoAssociateRenderer(struct DSVideo* video, struct DSVideoRenderer* renderer);
78
79struct DSCommon;
80void DSVideoWriteDISPSTAT(struct DSCommon* dscore, uint16_t value);
81
82struct DSMemory;
83void DSVideoConfigureVRAM(struct DSMemory* memory, int index, uint8_t value);
84
85CXX_GUARD_START
86
87#endif