all repos — mgba @ e71baacd2fe3729e3556b73af7b1cafc0345955f

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};
 46
 47enum BlendEffect {
 48	BLEND_NONE = 0,
 49	BLEND_ALPHA = 1,
 50	BLEND_BRIGHTEN = 2,
 51	BLEND_DARKEN = 3
 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 = 0x00F8F8F8,
 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	uint8_t end;
 82	uint8_t start;
 83};
 84
 85DECL_BITFIELD(GBAWindowControl, uint8_t);
 86DECL_BIT(GBAWindowControl, Bg0Enable, 0);
 87DECL_BIT(GBAWindowControl, Bg1Enable, 1);
 88DECL_BIT(GBAWindowControl, Bg2Enable, 2);
 89DECL_BIT(GBAWindowControl, Bg3Enable, 3);
 90DECL_BIT(GBAWindowControl, ObjEnable, 4);
 91DECL_BIT(GBAWindowControl, BlendEnable, 5);
 92
 93DECL_BITFIELD(GBAMosaicControl, uint16_t);
 94DECL_BITS(GBAMosaicControl, BgH, 0, 4);
 95DECL_BITS(GBAMosaicControl, BgV, 4, 4);
 96DECL_BITS(GBAMosaicControl, ObjH, 8, 4);
 97DECL_BITS(GBAMosaicControl, ObjV, 12, 4);
 98
 99struct WindowControl {
100	GBAWindowControl packed;
101	int8_t priority;
102};
103
104#define MAX_WINDOW 5
105
106struct Window {
107	uint8_t endX;
108	struct WindowControl control;
109};
110
111struct GBAVideoSoftwareRenderer {
112	struct GBAVideoRenderer d;
113
114	color_t* outputBuffer;
115	int outputBufferStride;
116
117	uint32_t* temporaryBuffer;
118
119	GBARegisterDISPCNT dispcnt;
120
121	uint32_t row[VIDEO_HORIZONTAL_PIXELS];
122	uint32_t spriteLayer[VIDEO_HORIZONTAL_PIXELS];
123	int32_t spriteCyclesRemaining;
124
125	// BLDCNT
126	unsigned target1Obj;
127	unsigned target1Bd;
128	unsigned target2Obj;
129	unsigned target2Bd;
130	bool blendDirty;
131	enum BlendEffect blendEffect;
132	color_t normalPalette[512];
133	color_t variantPalette[512];
134
135	uint16_t blda;
136	uint16_t bldb;
137	uint16_t bldy;
138
139	GBAMosaicControl mosaic;
140
141	struct WindowN {
142		struct WindowRegion h;
143		struct WindowRegion v;
144		struct WindowControl control;
145	} winN[2];
146
147	struct WindowControl winout;
148	struct WindowControl objwin;
149
150	struct WindowControl currentWindow;
151
152	int nWindows;
153	struct Window windows[MAX_WINDOW];
154
155	struct GBAVideoSoftwareBackground bg[4];
156
157	int oamDirty;
158	int oamMax;
159	struct GBAVideoSoftwareSprite sprites[128];
160
161	uint32_t scanlineDirty[5];
162	uint16_t ioCache[VIDEO_VERTICAL_PIXELS][REG_SOUND1CNT_LO];
163	uint16_t nextIo[REG_SOUND1CNT_LO];
164	int32_t scaleCache[VIDEO_VERTICAL_PIXELS][2][2];
165	int nextY;
166
167	int start;
168	int end;
169};
170
171void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
172
173CXX_GUARD_START
174
175#endif