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};
49
50enum {
51#ifdef COLOR_16_BIT
52#ifdef COLOR_5_6_5
53 GBA_COLOR_WHITE = 0xFFDF,
54#else
55 GBA_COLOR_WHITE = 0x7FFF,
56#endif
57#else
58 GBA_COLOR_WHITE = 0x00F8F8F8,
59#endif
60 OFFSET_PRIORITY = 30,
61 OFFSET_INDEX = 28,
62};
63
64#define FLAG_PRIORITY 0xC0000000
65#define FLAG_INDEX 0x30000000
66#define FLAG_IS_BACKGROUND 0x08000000
67#define FLAG_UNWRITTEN 0xFC000000
68#define FLAG_REBLEND 0x04000000
69#define FLAG_TARGET_1 0x02000000
70#define FLAG_TARGET_2 0x01000000
71#define FLAG_OBJWIN 0x01000000
72#define FLAG_ORDER_MASK 0xF8000000
73
74#define IS_WRITABLE(PIXEL) ((PIXEL) & 0xFE000000)
75
76struct WindowRegion {
77 int end;
78 int start;
79};
80
81struct WindowControl {
82 GBAWindowControl packed;
83 int8_t priority;
84};
85
86#define MAX_WINDOW 5
87
88struct Window {
89 uint16_t endX;
90 struct WindowControl control;
91};
92
93struct GBAVideoSoftwareRenderer {
94 struct GBAVideoRenderer d;
95
96 color_t* outputBuffer;
97 int outputBufferStride;
98
99 uint32_t* temporaryBuffer;
100
101 uint32_t dispcnt;
102
103 uint32_t row[256];
104 uint32_t spriteLayer[256];
105 uint8_t alphaA[256];
106 uint8_t alphaB[256];
107 int32_t spriteCyclesRemaining;
108
109 // BLDCNT
110 unsigned target1Obj;
111 unsigned target1Bd;
112 unsigned target2Obj;
113 unsigned target2Bd;
114 bool blendDirty;
115 enum GBAVideoBlendEffect blendEffect;
116 color_t normalPalette[512];
117 color_t variantPalette[512];
118 color_t* objExtPalette;
119 color_t* objExtVariantPalette;
120
121 uint16_t blda;
122 uint16_t bldb;
123 uint16_t bldy;
124
125 GBAMosaicControl mosaic;
126
127 struct WindowN {
128 struct GBAVideoWindowRegion h;
129 struct GBAVideoWindowRegion v;
130 struct WindowControl control;
131 } winN[2];
132
133 struct WindowControl winout;
134 struct WindowControl objwin;
135
136 struct WindowControl currentWindow;
137
138 int nWindows;
139 struct Window windows[MAX_WINDOW];
140
141 struct GBAVideoSoftwareBackground bg[4];
142
143 int oamDirty;
144 int oamMax;
145 struct GBAVideoRendererSprite sprites[128];
146 int tileStride;
147 int bitmapStride;
148 bool combinedObjSort;
149 int16_t objOffsetX;
150 int16_t objOffsetY;
151
152 uint32_t scanlineDirty[5];
153 uint16_t nextIo[REG_SOUND1CNT_LO];
154 struct ScanlineCache {
155 uint16_t io[REG_SOUND1CNT_LO];
156 int32_t scale[2][2];
157 } cache[GBA_VIDEO_VERTICAL_PIXELS];
158 int nextY;
159
160 int start;
161 int end;
162 int masterEnd;
163 int masterHeight;
164 int masterScanlines;
165
166 int masterBright;
167 int masterBrightY;
168};
169
170void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
171
172CXX_GUARD_START
173
174#endif