all repos — mgba @ 4fd170ac38a9c312f3dd1d0dd912d2c761f60fdb

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