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