all repos — mgba @ b0726d018582c86a0dbf69a37e494cbce0562f4e

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