src/gba/renderers/video-software.h (view raw)
1#ifndef VIDEO_SOFTWARE_H
2#define VIDEO_SOFTWARE_H
3
4#include "gba-video.h"
5
6#include <pthread.h>
7
8#ifdef COLOR_16_BIT
9typedef uint16_t color_t;
10#else
11typedef uint32_t color_t;
12#endif
13
14struct GBAVideoSoftwareBackground {
15 int index;
16 int enabled;
17 int priority;
18 uint32_t charBase;
19 int mosaic;
20 int multipalette;
21 uint32_t screenBase;
22 int overflow;
23 int size;
24 int target1;
25 int target2;
26 uint16_t x;
27 uint16_t y;
28 int32_t refx;
29 int32_t refy;
30 int16_t dx;
31 int16_t dmx;
32 int16_t dy;
33 int16_t dmy;
34 int32_t sx;
35 int32_t sy;
36};
37
38enum BlendEffect {
39 BLEND_NONE = 0,
40 BLEND_ALPHA = 1,
41 BLEND_BRIGHTEN = 2,
42 BLEND_DARKEN = 3
43};
44
45enum {
46#ifdef COLOR_16_BIT
47#ifdef COLOR_5_6_5
48 GBA_COLOR_WHITE = 0xFFDF,
49#else
50 GBA_COLOR_WHITE = 0x7FFF,
51#endif
52#else
53 GBA_COLOR_WHITE = 0x00F8F8F8,
54#endif
55 OFFSET_PRIORITY = 29
56};
57
58enum PixelFlags {
59 FLAG_FINALIZED = 0x80000000,
60 FLAG_PRIORITY = 0x60000000,
61 FLAG_IS_BACKGROUND = 0x10000000,
62 FLAG_UNWRITTEN = 0x08000000,
63 FLAG_TARGET_1 = 0x04000000,
64 FLAG_TARGET_2 = 0x02000000,
65 FLAG_OBJWIN = 0x01000000,
66
67 FLAG_ORDER_MASK = 0xF8000000
68};
69
70union WindowRegion {
71 struct {
72 uint8_t end;
73 uint8_t start;
74 };
75 uint16_t packed;
76};
77
78union WindowControl {
79 struct {
80 unsigned bg0Enable : 1;
81 unsigned bg1Enable : 1;
82 unsigned bg2Enable : 1;
83 unsigned bg3Enable : 1;
84 unsigned objEnable : 1;
85 unsigned blendEnable : 1;
86 unsigned : 2;
87 };
88 uint8_t packed;
89 int8_t priority;
90};
91
92#define MAX_WINDOW 5
93
94struct Window {
95 uint8_t endX;
96 union WindowControl control;
97};
98
99struct GBAVideoSoftwareRenderer {
100 struct GBAVideoRenderer d;
101
102 color_t* outputBuffer;
103 unsigned outputBufferStride;
104
105 union GBARegisterDISPCNT dispcnt;
106
107 uint32_t row[VIDEO_HORIZONTAL_PIXELS];
108 uint32_t spriteLayer[VIDEO_HORIZONTAL_PIXELS];
109
110 // BLDCNT
111 unsigned target1Obj;
112 unsigned target1Bd;
113 unsigned target2Obj;
114 unsigned target2Bd;
115 enum BlendEffect blendEffect;
116 color_t normalPalette[512];
117 color_t variantPalette[512];
118
119 uint16_t blda;
120 uint16_t bldb;
121 uint16_t bldy;
122
123 union {
124 struct {
125 unsigned bgH : 4;
126 unsigned bgV : 4;
127 unsigned objH : 4;
128 unsigned objV : 4;
129 };
130 uint16_t packed;
131 } mosaic;
132
133 struct WindowN {
134 union WindowRegion h;
135 union WindowRegion v;
136 union WindowControl control;
137 } winN[2];
138
139 union WindowControl winout;
140 union WindowControl objwin;
141
142 union WindowControl currentWindow;
143
144 int nWindows;
145 struct Window windows[MAX_WINDOW];
146
147 struct GBAVideoSoftwareBackground bg[4];
148
149 int start;
150 int end;
151};
152
153void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
154
155#endif