all repos — mgba @ bb37a60765fafdce9db1aeb0f70f951c29522777

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/video.h>
 17
 18struct GBAVideoSoftwareSprite {
 19	struct GBAObj obj;
 20	int y;
 21	int endY;
 22};
 23
 24struct GBAVideoSoftwareBackground {
 25	unsigned index;
 26	int enabled;
 27	unsigned priority;
 28	uint32_t charBase;
 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	int32_t offsetX;
 49	int32_t offsetY;
 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	uint8_t end;
 87	uint8_t 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	uint8_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	GBARegisterDISPCNT dispcnt;
125
126	uint32_t row[GBA_VIDEO_HORIZONTAL_PIXELS];
127	uint32_t spriteLayer[GBA_VIDEO_HORIZONTAL_PIXELS];
128	int32_t spriteCyclesRemaining;
129
130	// BLDCNT
131	unsigned target1Obj;
132	unsigned target1Bd;
133	unsigned target2Obj;
134	unsigned target2Bd;
135	bool blendDirty;
136	enum BlendEffect blendEffect;
137	color_t normalPalette[512];
138	color_t variantPalette[512];
139
140	uint16_t blda;
141	uint16_t bldb;
142	uint16_t bldy;
143
144	GBAMosaicControl mosaic;
145
146	struct WindowN {
147		struct WindowRegion h;
148		struct WindowRegion v;
149		struct WindowControl control;
150	} winN[2];
151
152	struct WindowControl winout;
153	struct WindowControl objwin;
154
155	struct WindowControl currentWindow;
156
157	int nWindows;
158	struct Window windows[MAX_WINDOW];
159
160	struct GBAVideoSoftwareBackground bg[4];
161
162	int oamDirty;
163	int oamMax;
164	struct GBAVideoSoftwareSprite sprites[128];
165	int16_t objOffsetX;
166	int16_t objOffsetY;
167
168	uint32_t scanlineDirty[5];
169	uint16_t nextIo[REG_SOUND1CNT_LO];
170	struct ScanlineCache {
171		uint16_t io[REG_SOUND1CNT_LO];
172		int32_t scale[2][2];
173	} cache[GBA_VIDEO_VERTICAL_PIXELS];
174	int nextY;
175
176	int start;
177	int end;
178};
179
180void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
181
182CXX_GUARD_START
183
184#endif