all repos — mgba @ 2f00e3d146be22ebc257f98a1396378f1a77faaa

mGBA Game Boy Advance Emulator

src/gba/renderers/video-software.h (view raw)

  1#ifndef VIDEO_SOFTWARE_H
  2#define VIDEO_SOFTWARE_H
  3
  4#include "gba-video.h"
  5
  6#include <pthread.h>
  7
  8#ifdef COLOR_16_BIT
  9typedef uint16_t color_t;
 10#else
 11typedef uint32_t color_t;
 12#endif
 13
 14struct GBAVideoSoftwareBackground {
 15	int index;
 16	int enabled;
 17	int priority;
 18	uint32_t charBase;
 19	int mosaic;
 20	int multipalette;
 21	uint32_t screenBase;
 22	int overflow;
 23	int size;
 24	int target1;
 25	int target2;
 26	uint16_t x;
 27	uint16_t y;
 28	int32_t refx;
 29	int32_t refy;
 30	int16_t dx;
 31	int16_t dmx;
 32	int16_t dy;
 33	int16_t dmy;
 34	int32_t sx;
 35	int32_t sy;
 36};
 37
 38enum BlendEffect {
 39	BLEND_NONE = 0,
 40	BLEND_ALPHA = 1,
 41	BLEND_BRIGHTEN = 2,
 42	BLEND_DARKEN = 3
 43};
 44
 45enum {
 46#ifdef COLOR_16_BIT
 47	GBA_COLOR_WHITE = 0x7FFF,
 48#else
 49	GBA_COLOR_WHITE = 0x00F8F8F8,
 50#endif
 51	OFFSET_PRIORITY = 29
 52};
 53
 54enum PixelFlags {
 55	FLAG_FINALIZED = 0x80000000,
 56	FLAG_PRIORITY = 0x60000000,
 57	FLAG_IS_BACKGROUND = 0x10000000,
 58	FLAG_UNWRITTEN = 0x08000000,
 59	FLAG_TARGET_1 = 0x04000000,
 60	FLAG_TARGET_2 = 0x02000000,
 61	FLAG_OBJWIN = 0x01000000
 62};
 63
 64union WindowRegion {
 65	struct {
 66		uint8_t end;
 67		uint8_t start;
 68	};
 69	uint16_t packed;
 70};
 71
 72union WindowControl {
 73	struct {
 74		unsigned bg0Enable : 1;
 75		unsigned bg1Enable : 1;
 76		unsigned bg2Enable : 1;
 77		unsigned bg3Enable : 1;
 78		unsigned objEnable : 1;
 79		unsigned blendEnable : 1;
 80		unsigned : 2;
 81	};
 82	uint8_t packed;
 83	int8_t priority;
 84};
 85
 86#define MAX_WINDOW 5
 87
 88struct Window {
 89	uint8_t endX;
 90	union WindowControl control;
 91};
 92
 93struct GBAVideoSoftwareRenderer {
 94	struct GBAVideoRenderer d;
 95
 96	color_t* outputBuffer;
 97	unsigned outputBufferStride;
 98
 99	union GBARegisterDISPCNT dispcnt;
100
101	uint32_t row[VIDEO_HORIZONTAL_PIXELS];
102	uint32_t spriteLayer[VIDEO_HORIZONTAL_PIXELS];
103
104	// BLDCNT
105	unsigned target1Obj;
106	unsigned target1Bd;
107	unsigned target2Obj;
108	unsigned target2Bd;
109	enum BlendEffect blendEffect;
110	color_t normalPalette[512];
111	color_t variantPalette[512];
112
113	uint16_t blda;
114	uint16_t bldb;
115	uint16_t bldy;
116
117	union WindowRegion win0H;
118	union WindowRegion win0V;
119	union WindowRegion win1H;
120	union WindowRegion win1V;
121
122	union WindowControl win0;
123	union WindowControl win1;
124	union WindowControl winout;
125	union WindowControl objwin;
126
127	union WindowControl currentWindow;
128
129	int nWindows;
130	struct Window windows[MAX_WINDOW];
131
132	struct GBAVideoSoftwareBackground bg[4];
133
134	int start;
135	int end;
136
137	uint32_t enabledBitmap[4];
138
139	pthread_mutex_t mutex;
140	pthread_cond_t upCond;
141	pthread_cond_t downCond;
142};
143
144void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
145
146#endif