all repos — mgba @ 783b2a3e09c0d98807239e23128573a913a072f3

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 vblankIRQ;
42	int hblankIRQ;
43	int vcounterIRQ;
44	int vcountSetting;
45
46	// VCOUNT
47	int vcount;
48
49	int32_t lastHblank;
50	int32_t nextHblank;
51	int32_t nextEvent;
52	int32_t eventDiff;
53
54	int32_t nextHblankIRQ;
55	int32_t nextVblankIRQ;
56	int32_t nextVcounterIRQ;
57};
58
59void GBAVideoInit(struct GBAVideo* video);
60int32_t GBAVideoProcessEvents(struct GBAVideo* video, int32_t cycles);
61
62void GBAVideoWriteDISPSTAT(struct GBAVideo* video, uint16_t value);
63uint16_t GBAVideoReadDISPSTAT(struct GBAVideo* video);
64
65#endif