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 uint8_t end;
84 uint8_t 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 int32_t spriteCyclesRemaining;
126
127 // BLDCNT
128 unsigned target1Obj;
129 unsigned target1Bd;
130 unsigned target2Obj;
131 unsigned target2Bd;
132 enum BlendEffect blendEffect;
133 color_t normalPalette[512];
134 color_t variantPalette[512];
135
136 uint16_t blda;
137 uint16_t bldb;
138 uint16_t bldy;
139
140 GBAMosaicControl mosaic;
141
142 struct WindowN {
143 struct WindowRegion h;
144 struct WindowRegion v;
145 struct WindowControl control;
146 } winN[2];
147
148 struct WindowControl winout;
149 struct WindowControl objwin;
150
151 struct WindowControl currentWindow;
152
153 int nWindows;
154 struct Window windows[MAX_WINDOW];
155
156 struct GBAVideoSoftwareBackground bg[4];
157
158 int oamDirty;
159 int oamMax;
160 struct GBAVideoSoftwareSprite sprites[128];
161 int tileStride;
162
163 int start;
164 int end;
165 int masterEnd;
166 int masterHeight;
167 int masterScanlines;
168};
169
170void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
171
172CXX_GUARD_START
173
174#endif