all repos — mgba @ 0209381d112a9e0a0b6e65764efd50c9a9790ca9

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