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 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
68enum PixelFlags {
69 FLAG_PRIORITY = 0xC0000000,
70 FLAG_INDEX = 0x30000000,
71 FLAG_IS_BACKGROUND = 0x08000000,
72 FLAG_UNWRITTEN = 0xFC000000,
73 FLAG_TARGET_1 = 0x02000000,
74 FLAG_TARGET_2 = 0x01000000,
75 FLAG_OBJWIN = 0x01000000,
76
77 FLAG_ORDER_MASK = 0xF8000000
78};
79
80#define IS_WRITABLE(PIXEL) ((PIXEL) & 0xFE000000)
81
82union WindowRegion {
83 struct {
84 uint8_t end;
85 uint8_t start;
86 };
87 uint16_t packed;
88};
89
90union WindowControl {
91 struct {
92 unsigned bg0Enable : 1;
93 unsigned bg1Enable : 1;
94 unsigned bg2Enable : 1;
95 unsigned bg3Enable : 1;
96 unsigned objEnable : 1;
97 unsigned blendEnable : 1;
98 unsigned : 2;
99 };
100 uint8_t packed;
101 int8_t priority;
102};
103
104#define MAX_WINDOW 5
105
106struct Window {
107 uint8_t endX;
108 union WindowControl control;
109};
110
111struct GBAVideoSoftwareRenderer {
112 struct GBAVideoRenderer d;
113
114 color_t* outputBuffer;
115 unsigned outputBufferStride;
116
117 union GBARegisterDISPCNT dispcnt;
118
119 uint32_t row[VIDEO_HORIZONTAL_PIXELS];
120 uint32_t spriteLayer[VIDEO_HORIZONTAL_PIXELS];
121
122 // BLDCNT
123 unsigned target1Obj;
124 unsigned target1Bd;
125 unsigned target2Obj;
126 unsigned target2Bd;
127 enum BlendEffect blendEffect;
128 color_t normalPalette[512];
129 color_t variantPalette[512];
130 int anyTarget2;
131
132 uint16_t blda;
133 uint16_t bldb;
134 uint16_t bldy;
135
136 union {
137 struct {
138 unsigned bgH : 4;
139 unsigned bgV : 4;
140 unsigned objH : 4;
141 unsigned objV : 4;
142 };
143 uint16_t packed;
144 } mosaic;
145
146 struct WindowN {
147 union WindowRegion h;
148 union WindowRegion v;
149 union WindowControl control;
150 } winN[2];
151
152 union WindowControl winout;
153 union WindowControl objwin;
154
155 union WindowControl currentWindow;
156
157 int nWindows;
158 struct Window windows[MAX_WINDOW];
159
160 struct GBAVideoSoftwareBackground bg[4];
161
162 int oamDirty;
163 int oamMax;
164 struct GBAVideoSoftwareSprite sprites[128];
165
166 int start;
167 int end;
168};
169
170void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
171
172#endif