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 int anyTarget2;
119
120 uint16_t blda;
121 uint16_t bldb;
122 uint16_t bldy;
123
124 union {
125 struct {
126 unsigned bgH : 4;
127 unsigned bgV : 4;
128 unsigned objH : 4;
129 unsigned objV : 4;
130 };
131 uint16_t packed;
132 } mosaic;
133
134 struct WindowN {
135 union WindowRegion h;
136 union WindowRegion v;
137 union WindowControl control;
138 } winN[2];
139
140 union WindowControl winout;
141 union WindowControl objwin;
142
143 union WindowControl currentWindow;
144
145 int nWindows;
146 struct Window windows[MAX_WINDOW];
147
148 struct GBAVideoSoftwareBackground bg[4];
149
150 int start;
151 int end;
152};
153
154void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
155
156#endif