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 GBA_COLOR_WHITE = 0x7FFF,
48#else
49 GBA_COLOR_WHITE = 0x00F8F8F8,
50#endif
51 OFFSET_PRIORITY = 29
52};
53
54enum PixelFlags {
55 FLAG_FINALIZED = 0x80000000,
56 FLAG_PRIORITY = 0x60000000,
57 FLAG_IS_BACKGROUND = 0x10000000,
58 FLAG_UNWRITTEN = 0x08000000,
59 FLAG_TARGET_1 = 0x04000000,
60 FLAG_TARGET_2 = 0x02000000,
61 FLAG_OBJWIN = 0x01000000,
62
63 FLAG_ORDER_MASK = 0xF8000000
64};
65
66union WindowRegion {
67 struct {
68 uint8_t end;
69 uint8_t start;
70 };
71 uint16_t packed;
72};
73
74union WindowControl {
75 struct {
76 unsigned bg0Enable : 1;
77 unsigned bg1Enable : 1;
78 unsigned bg2Enable : 1;
79 unsigned bg3Enable : 1;
80 unsigned objEnable : 1;
81 unsigned blendEnable : 1;
82 unsigned : 2;
83 };
84 uint8_t packed;
85 int8_t priority;
86};
87
88#define MAX_WINDOW 5
89
90struct Window {
91 uint8_t endX;
92 union WindowControl control;
93};
94
95struct GBAVideoSoftwareRenderer {
96 struct GBAVideoRenderer d;
97
98 color_t* outputBuffer;
99 unsigned outputBufferStride;
100
101 union GBARegisterDISPCNT dispcnt;
102
103 uint32_t row[VIDEO_HORIZONTAL_PIXELS];
104 uint32_t spriteLayer[VIDEO_HORIZONTAL_PIXELS];
105
106 // BLDCNT
107 unsigned target1Obj;
108 unsigned target1Bd;
109 unsigned target2Obj;
110 unsigned target2Bd;
111 enum BlendEffect blendEffect;
112 color_t normalPalette[512];
113 color_t variantPalette[512];
114
115 uint16_t blda;
116 uint16_t bldb;
117 uint16_t bldy;
118
119 struct WindowN {
120 union WindowRegion h;
121 union WindowRegion v;
122 union WindowControl control;
123 } winN[2];
124
125 union WindowControl winout;
126 union WindowControl objwin;
127
128 union WindowControl currentWindow;
129
130 int nWindows;
131 struct Window windows[MAX_WINDOW];
132
133 struct GBAVideoSoftwareBackground bg[4];
134
135 int start;
136 int end;
137
138 uint32_t enabledBitmap[4];
139};
140
141void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
142
143#endif