src/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 "util/common.h"
10
11#include "gba/video.h"
12
13#ifdef COLOR_16_BIT
14typedef uint16_t color_t;
15#else
16typedef uint32_t color_t;
17#endif
18
19struct GBAVideoSoftwareSprite {
20 struct GBAObj obj;
21 int y;
22 int endY;
23};
24
25struct GBAVideoSoftwareBackground {
26 int index;
27 int enabled;
28 int priority;
29 uint32_t charBase;
30 int mosaic;
31 int multipalette;
32 uint32_t screenBase;
33 int overflow;
34 int size;
35 int target1;
36 int target2;
37 uint16_t x;
38 uint16_t y;
39 int32_t refx;
40 int32_t refy;
41 int16_t dx;
42 int16_t dmx;
43 int16_t dy;
44 int16_t dmy;
45 int32_t sx;
46 int32_t sy;
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_TARGET_1 0x02000000
75#define FLAG_TARGET_2 0x01000000
76#define FLAG_OBJWIN 0x01000000
77#define FLAG_ORDER_MASK 0xF8000000
78
79#define IS_WRITABLE(PIXEL) ((PIXEL) & 0xFE000000)
80
81struct WindowRegion {
82 uint8_t end;
83 uint8_t start;
84};
85
86DECL_BITFIELD(GBAWindowControl, uint8_t);
87DECL_BIT(GBAWindowControl, Bg0Enable, 0);
88DECL_BIT(GBAWindowControl, Bg1Enable, 1);
89DECL_BIT(GBAWindowControl, Bg2Enable, 2);
90DECL_BIT(GBAWindowControl, Bg3Enable, 3);
91DECL_BIT(GBAWindowControl, ObjEnable, 4);
92DECL_BIT(GBAWindowControl, BlendEnable, 5);
93
94DECL_BITFIELD(GBAMosaicControl, uint16_t);
95DECL_BITS(GBAMosaicControl, BgH, 0, 4);
96DECL_BITS(GBAMosaicControl, BgV, 4, 4);
97DECL_BITS(GBAMosaicControl, ObjH, 8, 4);
98DECL_BITS(GBAMosaicControl, ObjV, 12, 4);
99
100struct WindowControl {
101 GBAWindowControl packed;
102 int8_t priority;
103};
104
105#define MAX_WINDOW 5
106
107struct Window {
108 uint8_t endX;
109 struct WindowControl control;
110};
111
112struct GBAVideoSoftwareRenderer {
113 struct GBAVideoRenderer d;
114
115 color_t* outputBuffer;
116 int outputBufferStride;
117
118 uint32_t* temporaryBuffer;
119
120 GBARegisterDISPCNT dispcnt;
121
122 uint32_t row[VIDEO_HORIZONTAL_PIXELS];
123 uint32_t spriteLayer[VIDEO_HORIZONTAL_PIXELS];
124
125 // BLDCNT
126 unsigned target1Obj;
127 unsigned target1Bd;
128 unsigned target2Obj;
129 unsigned target2Bd;
130 enum BlendEffect blendEffect;
131 color_t normalPalette[512];
132 color_t variantPalette[512];
133 int anyTarget2;
134
135 uint16_t blda;
136 uint16_t bldb;
137 uint16_t bldy;
138
139 GBAMosaicControl mosaic;
140
141 struct WindowN {
142 struct WindowRegion h;
143 struct WindowRegion v;
144 struct WindowControl control;
145 } winN[2];
146
147 struct WindowControl winout;
148 struct WindowControl objwin;
149
150 struct WindowControl currentWindow;
151
152 int nWindows;
153 struct Window windows[MAX_WINDOW];
154
155 struct GBAVideoSoftwareBackground bg[4];
156
157 int oamDirty;
158 int oamMax;
159 struct GBAVideoSoftwareSprite sprites[128];
160
161 int start;
162 int end;
163};
164
165void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
166
167#endif