all repos — mgba @ 2553b96e9b4ba154b845492a9fec275d6db26fa1

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#ifdef COLOR_5_6_5
 48	GBA_COLOR_WHITE = 0xFFDF,
 49#else
 50	GBA_COLOR_WHITE = 0x7FFF,
 51#endif
 52#else
 53	GBA_COLOR_WHITE = 0x00F8F8F8,
 54#endif
 55	OFFSET_PRIORITY = 30,
 56	OFFSET_INDEX = 28,
 57};
 58
 59enum PixelFlags {
 60	FLAG_PRIORITY = 0xC0000000,
 61	FLAG_INDEX = 0x30000000,
 62	FLAG_IS_BACKGROUND = 0x08000000,
 63	FLAG_UNWRITTEN = 0xFC000000,
 64	FLAG_TARGET_1 = 0x02000000,
 65	FLAG_TARGET_2 = 0x01000000,
 66	FLAG_OBJWIN = 0x01000000,
 67
 68	FLAG_ORDER_MASK = 0xF8000000
 69};
 70
 71#define IS_WRITABLE(PIXEL) ((PIXEL) & 0xFE000000)
 72
 73union WindowRegion {
 74	struct {
 75		uint8_t end;
 76		uint8_t start;
 77	};
 78	uint16_t packed;
 79};
 80
 81union WindowControl {
 82	struct {
 83		unsigned bg0Enable : 1;
 84		unsigned bg1Enable : 1;
 85		unsigned bg2Enable : 1;
 86		unsigned bg3Enable : 1;
 87		unsigned objEnable : 1;
 88		unsigned blendEnable : 1;
 89		unsigned : 2;
 90	};
 91	uint8_t packed;
 92	int8_t priority;
 93};
 94
 95#define MAX_WINDOW 5
 96
 97struct Window {
 98	uint8_t endX;
 99	union WindowControl control;
100};
101
102struct GBAVideoSoftwareRenderer {
103	struct GBAVideoRenderer d;
104
105	color_t* outputBuffer;
106	unsigned outputBufferStride;
107
108	union GBARegisterDISPCNT dispcnt;
109
110	uint32_t row[VIDEO_HORIZONTAL_PIXELS];
111	uint32_t spriteLayer[VIDEO_HORIZONTAL_PIXELS];
112
113	// BLDCNT
114	unsigned target1Obj;
115	unsigned target1Bd;
116	unsigned target2Obj;
117	unsigned target2Bd;
118	enum BlendEffect blendEffect;
119	color_t normalPalette[512];
120	color_t variantPalette[512];
121	int anyTarget2;
122
123	uint16_t blda;
124	uint16_t bldb;
125	uint16_t bldy;
126
127	union {
128		struct {
129			unsigned bgH : 4;
130			unsigned bgV : 4;
131			unsigned objH : 4;
132			unsigned objV : 4;
133		};
134		uint16_t packed;
135	} mosaic;
136
137	struct WindowN {
138		union WindowRegion h;
139		union WindowRegion v;
140		union WindowControl control;
141	} winN[2];
142
143	union WindowControl winout;
144	union WindowControl objwin;
145
146	union WindowControl currentWindow;
147
148	int nWindows;
149	struct Window windows[MAX_WINDOW];
150
151	struct GBAVideoSoftwareBackground bg[4];
152
153	int start;
154	int end;
155};
156
157void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
158
159#endif