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/gba/interface.h>
15#include <mgba/internal/gba/io.h>
16#include <mgba/internal/gba/renderers/common.h>
17#include <mgba/internal/gba/video.h>
18
19struct GBAVideoSoftwareBackground {
20 unsigned index;
21 int enabled;
22 unsigned priority;
23 uint32_t charBase;
24 uint16_t control;
25 int mosaic;
26 int multipalette;
27 uint32_t screenBase;
28 int overflow;
29 int size;
30 int target1;
31 int target2;
32 uint16_t x;
33 uint16_t y;
34 int32_t refx;
35 int32_t refy;
36 int16_t dx;
37 int16_t dmx;
38 int16_t dy;
39 int16_t dmy;
40 int32_t sx;
41 int32_t sy;
42 int yCache;
43 uint16_t mapCache[64];
44 color_t* extPalette;
45 color_t* variantPalette;
46 int32_t offsetX;
47 int32_t offsetY;
48 bool highlight;
49};
50
51enum {
52#ifdef COLOR_16_BIT
53#ifdef COLOR_5_6_5
54 GBA_COLOR_WHITE = 0xFFDF,
55#else
56 GBA_COLOR_WHITE = 0x7FFF,
57#endif
58#else
59 GBA_COLOR_WHITE = 0x00F8F8F8,
60#endif
61 OFFSET_PRIORITY = 30,
62 OFFSET_INDEX = 28,
63};
64
65#define FLAG_PRIORITY 0xC0000000
66#define FLAG_INDEX 0x30000000
67#define FLAG_IS_BACKGROUND 0x08000000
68#define FLAG_UNWRITTEN 0xFC000000
69#define FLAG_REBLEND 0x04000000
70#define FLAG_TARGET_1 0x02000000
71#define FLAG_TARGET_2 0x01000000
72#define FLAG_OBJWIN 0x01000000
73#define FLAG_ORDER_MASK 0xF8000000
74
75#define IS_WRITABLE(PIXEL) ((PIXEL) & 0xFE000000)
76
77struct WindowRegion {
78 int end;
79 int start;
80};
81
82struct WindowControl {
83 GBAWindowControl packed;
84 int8_t priority;
85};
86
87#define MAX_WINDOW 5
88
89struct Window {
90 uint16_t endX;
91 struct WindowControl control;
92};
93
94struct GBAVideoSoftwareRenderer {
95 struct GBAVideoRenderer d;
96
97 color_t* outputBuffer;
98 int outputBufferStride;
99
100 uint32_t* temporaryBuffer;
101
102 uint32_t dispcnt;
103
104 uint32_t row[256];
105 uint32_t spriteLayer[256];
106 uint8_t alphaA[256];
107 uint8_t alphaB[256];
108 int32_t spriteCyclesRemaining;
109
110 // BLDCNT
111 unsigned target1Obj;
112 unsigned target1Bd;
113 unsigned target2Obj;
114 unsigned target2Bd;
115 bool blendDirty;
116 enum GBAVideoBlendEffect blendEffect;
117 color_t normalPalette[512];
118 color_t variantPalette[512];
119 color_t* objExtPalette;
120 color_t* objExtVariantPalette;
121 color_t highlightPalette[512];
122 color_t highlightVariantPalette[512];
123
124 uint16_t blda;
125 uint16_t bldb;
126 uint16_t bldy;
127
128 GBAMosaicControl mosaic;
129
130 struct WindowN {
131 struct GBAVideoWindowRegion h;
132 struct GBAVideoWindowRegion v;
133 struct WindowControl control;
134 } winN[2];
135
136 struct WindowControl winout;
137 struct WindowControl objwin;
138
139 struct WindowControl currentWindow;
140
141 int nWindows;
142 struct Window windows[MAX_WINDOW];
143
144 struct GBAVideoSoftwareBackground bg[4];
145
146 bool forceTarget1;
147 bool oamDirty;
148 int oamMax;
149 struct GBAVideoRendererSprite sprites[128];
150 int tileStride;
151 int bitmapStride;
152 bool combinedObjSort;
153 int16_t objOffsetX;
154 int16_t objOffsetY;
155
156 uint32_t scanlineDirty[5];
157 uint16_t nextIo[REG_SOUND1CNT_LO];
158 struct ScanlineCache {
159 uint16_t io[REG_SOUND1CNT_LO];
160 int32_t scale[2][2];
161 } cache[GBA_VIDEO_VERTICAL_PIXELS];
162 int nextY;
163
164 int start;
165 int end;
166 int masterEnd;
167 int masterHeight;
168 int masterScanlines;
169
170 int masterBright;
171 int masterBrightY;
172
173 uint8_t lastHighlightAmount;
174};
175
176void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
177
178CXX_GUARD_START
179
180#endif