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
8struct GBAVideoSoftwareBackground {
9 int index;
10 int enabled;
11 int priority;
12 uint32_t charBase;
13 int mosaic;
14 int multipalette;
15 uint32_t screenBase;
16 int overflow;
17 int size;
18 int target1;
19 int target2;
20 uint16_t x;
21 uint16_t y;
22 int32_t refx;
23 int32_t refy;
24 int16_t dx;
25 int16_t dmx;
26 int16_t dy;
27 int16_t dmy;
28 int32_t sx;
29 int32_t sy;
30};
31
32enum BlendEffect {
33 BLEND_NONE = 0,
34 BLEND_ALPHA = 1,
35 BLEND_BRIGHTEN = 2,
36 BLEND_DARKEN = 3
37};
38
39enum {
40 GBA_COLOR_WHITE = 0x00F8F8F8,
41 OFFSET_PRIORITY = 29
42};
43
44enum PixelFlags {
45 FLAG_FINALIZED = 0x80000000,
46 FLAG_PRIORITY = 0x60000000,
47 FLAG_IS_BACKGROUND = 0x10000000,
48 FLAG_UNWRITTEN = 0x08000000,
49 FLAG_TARGET_1 = 0x04000000,
50 FLAG_TARGET_2 = 0x02000000,
51 FLAG_OBJWIN = 0x01000000
52};
53
54union WindowRegion {
55 struct {
56 uint8_t end;
57 uint8_t start;
58 };
59 uint16_t packed;
60};
61
62union WindowControl {
63 struct {
64 unsigned bg0Enable : 1;
65 unsigned bg1Enable : 1;
66 unsigned bg2Enable : 1;
67 unsigned bg3Enable : 1;
68 unsigned objEnable : 1;
69 unsigned blendEnable : 1;
70 unsigned : 2;
71 };
72 uint8_t packed;
73 int8_t priority;
74};
75
76#define MAX_WINDOW 5
77
78struct Window {
79 uint8_t endX;
80 union WindowControl control;
81};
82
83struct GBAVideoSoftwareRenderer {
84 struct GBAVideoRenderer d;
85
86 uint32_t* outputBuffer;
87 unsigned outputBufferStride;
88
89 union GBARegisterDISPCNT dispcnt;
90
91 uint32_t row[VIDEO_HORIZONTAL_PIXELS];
92 uint32_t spriteLayer[VIDEO_HORIZONTAL_PIXELS];
93
94 // BLDCNT
95 unsigned target1Obj;
96 unsigned target1Bd;
97 unsigned target2Obj;
98 unsigned target2Bd;
99 enum BlendEffect blendEffect;
100 uint32_t normalPalette[512];
101 uint32_t variantPalette[512];
102
103 uint16_t blda;
104 uint16_t bldb;
105 uint16_t bldy;
106
107 union WindowRegion win0H;
108 union WindowRegion win0V;
109 union WindowRegion win1H;
110 union WindowRegion win1V;
111
112 union WindowControl win0;
113 union WindowControl win1;
114 union WindowControl winout;
115 union WindowControl objwin;
116
117 union WindowControl currentWindow;
118
119 int nWindows;
120 struct Window windows[MAX_WINDOW];
121
122 struct GBAVideoSoftwareBackground bg[4];
123
124 int start;
125 int end;
126
127 uint32_t enabledBitmap[4];
128
129 pthread_mutex_t mutex;
130 pthread_cond_t upCond;
131 pthread_cond_t downCond;
132};
133
134void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
135
136#endif