all repos — mgba @ 37a564da4c34ec84f95a1224e5f5fc1161176184

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