all repos — mgba @ 4e296c3efc2fb1b753ef1a1085642d691d4b1567

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