include/mgba/internal/gba/renderers/video-software.h (view raw)
1/* Copyright (c) 2013-2015 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef VIDEO_SOFTWARE_H
7#define VIDEO_SOFTWARE_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba/core/core.h>
14#include <mgba/internal/gba/video.h>
15
16struct GBAVideoSoftwareSprite {
17 struct GBAObj obj;
18 int y;
19 int endY;
20};
21
22struct GBAVideoSoftwareBackground {
23 unsigned index;
24 int enabled;
25 unsigned priority;
26 uint32_t charBase;
27 uint16_t control;
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 color_t* extPalette;
46 color_t* variantPalette;
47};
48
49enum BlendEffect {
50 BLEND_NONE = 0,
51 BLEND_ALPHA = 1,
52 BLEND_BRIGHTEN = 2,
53 BLEND_DARKEN = 3
54};
55
56enum {
57#ifdef COLOR_16_BIT
58#ifdef COLOR_5_6_5
59 GBA_COLOR_WHITE = 0xFFDF,
60#else
61 GBA_COLOR_WHITE = 0x7FFF,
62#endif
63#else
64 GBA_COLOR_WHITE = 0x00F8F8F8,
65#endif
66 OFFSET_PRIORITY = 30,
67 OFFSET_INDEX = 28,
68};
69
70#define FLAG_PRIORITY 0xC0000000
71#define FLAG_INDEX 0x30000000
72#define FLAG_IS_BACKGROUND 0x08000000
73#define FLAG_UNWRITTEN 0xFC000000
74#define FLAG_REBLEND 0x04000000
75#define FLAG_TARGET_1 0x02000000
76#define FLAG_TARGET_2 0x01000000
77#define FLAG_OBJWIN 0x01000000
78#define FLAG_ORDER_MASK 0xF8000000
79
80#define IS_WRITABLE(PIXEL) ((PIXEL) & 0xFE000000)
81
82struct WindowRegion {
83 int end;
84 int start;
85};
86
87DECL_BITFIELD(GBAWindowControl, uint8_t);
88DECL_BIT(GBAWindowControl, Bg0Enable, 0);
89DECL_BIT(GBAWindowControl, Bg1Enable, 1);
90DECL_BIT(GBAWindowControl, Bg2Enable, 2);
91DECL_BIT(GBAWindowControl, Bg3Enable, 3);
92DECL_BIT(GBAWindowControl, ObjEnable, 4);
93DECL_BIT(GBAWindowControl, BlendEnable, 5);
94
95DECL_BITFIELD(GBAMosaicControl, uint16_t);
96DECL_BITS(GBAMosaicControl, BgH, 0, 4);
97DECL_BITS(GBAMosaicControl, BgV, 4, 4);
98DECL_BITS(GBAMosaicControl, ObjH, 8, 4);
99DECL_BITS(GBAMosaicControl, ObjV, 12, 4);
100
101struct WindowControl {
102 GBAWindowControl packed;
103 int8_t priority;
104};
105
106#define MAX_WINDOW 5
107
108struct Window {
109 uint16_t endX;
110 struct WindowControl control;
111};
112
113struct GBAVideoSoftwareRenderer {
114 struct GBAVideoRenderer d;
115
116 color_t* outputBuffer;
117 int outputBufferStride;
118
119 uint32_t* temporaryBuffer;
120
121 uint32_t dispcnt;
122
123 uint32_t row[256];
124 uint32_t spriteLayer[256];
125 uint8_t alphaA[256];
126 uint8_t alphaB[256];
127 int32_t spriteCyclesRemaining;
128
129 // BLDCNT
130 unsigned target1Obj;
131 unsigned target1Bd;
132 unsigned target2Obj;
133 unsigned target2Bd;
134 bool blendDirty;
135 enum BlendEffect blendEffect;
136 color_t normalPalette[512];
137 color_t variantPalette[512];
138 color_t* objExtPalette;
139 color_t* objExtVariantPalette;
140
141 uint16_t blda;
142 uint16_t bldb;
143 uint16_t bldy;
144
145 GBAMosaicControl mosaic;
146
147 struct WindowN {
148 struct WindowRegion h;
149 struct WindowRegion v;
150 struct WindowControl control;
151 } winN[2];
152
153 struct WindowControl winout;
154 struct WindowControl objwin;
155
156 struct WindowControl currentWindow;
157
158 int nWindows;
159 struct Window windows[MAX_WINDOW];
160
161 struct GBAVideoSoftwareBackground bg[4];
162
163 int oamDirty;
164 int oamMax;
165 struct GBAVideoSoftwareSprite sprites[128];
166 int tileStride;
167 int bitmapStride;
168 bool combinedObjSort;
169
170 int start;
171 int end;
172 int masterEnd;
173 int masterHeight;
174 int masterScanlines;
175
176 int masterBright;
177 int masterBrightY;
178};
179
180void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
181
182CXX_GUARD_START
183
184#endif