all repos — mgba @ 2d02719fa57d4e4a33168955a8e0c34dfabc301a

mGBA Game Boy Advance Emulator

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