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