all repos — mgba @ 2fe2c80ae5aec5cddfe31d0f804cc5a0c58a521f

mGBA Game Boy Advance Emulator

src/gba/gba-video.h (view raw)

 1#ifndef GBA_VIDEO_H
 2#define GBA_VIDEO_H
 3
 4#include <stdint.h>
 5
 6enum {
 7	VIDEO_CYCLES_PER_PIXEL = 4,
 8
 9	VIDEO_HORIZONTAL_PIXELS = 240,
10	VIDEO_HBLANK_PIXELS = 68,
11	VIDEO_HDRAW_LENGTH = 1006,
12	VIDEO_HBLANK_LENGTH = 226,
13	VIDEO_HORIZONTAL_LENGTH = 1232,
14
15	VIDEO_VERTICAL_PIXELS = 160,
16	VIDEO_VBLANK_PIXELS = 68,
17	VIDEO_VERTICAL_TOTAL_PIXELS = 228,
18
19	VIDEO_TOTAL_LENGTH = 280896,
20
21	REG_DISPSTAT_MASK = 0xFF38
22};
23
24struct GBAVideoRenderer {
25	void (*init)(struct GBAVideoRenderer* renderer);
26	void (*deinit)(struct GBAVideoRenderer* renderer);
27
28	uint16_t (*writeVideoRegister)(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value);
29	void (*drawScanline)(struct GBAVideoRenderer* renderer, int y);
30	void (*finishFrame)(struct GBAVideoRenderer* renderer);
31};
32
33struct GBAVideo {
34	struct GBA* p;
35	struct GBAVideoRenderer* renderer;
36
37	// DISPSTAT
38	int inHblank;
39	int inVblank;
40	int vcounter;
41	int blankIRQ;
42	int vblankIRQ;
43	int hblankIRQ;
44	int vcounterIRQ;
45	int vcountSetting;
46
47	// VCOUNT
48	int vcount;
49
50	int32_t lastHblank;
51	int32_t nextHblank;
52	int32_t nextEvent;
53	int32_t eventDiff;
54
55	int32_t nextHblankIRQ;
56	int32_t nextVblankIRQ;
57	int32_t nextVcounterIRQ;
58};
59
60void GBAVideoInit(struct GBAVideo* video);
61int32_t GBAVideoProcessEvents(struct GBAVideo* video, int32_t cycles);
62
63#endif