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