all repos — mgba @ 1a0e44c014ad34bea30d237d27015d82d02cda4b

mGBA Game Boy Advance Emulator

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