all repos — mgba @ 55977796f35735f606f301b20f4b09ec621cc0c1

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	union {
 16		struct GBAObj obj;
 17		struct GBATransformedObj tobj;
 18	};
 19	int y;
 20	int endY;
 21};
 22
 23struct GBAVideoSoftwareBackground {
 24	int index;
 25	int enabled;
 26	int 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};
 46
 47enum BlendEffect {
 48	BLEND_NONE = 0,
 49	BLEND_ALPHA = 1,
 50	BLEND_BRIGHTEN = 2,
 51	BLEND_DARKEN = 3
 52};
 53
 54enum {
 55#ifdef COLOR_16_BIT
 56#ifdef COLOR_5_6_5
 57	GBA_COLOR_WHITE = 0xFFDF,
 58#else
 59	GBA_COLOR_WHITE = 0x7FFF,
 60#endif
 61#else
 62	GBA_COLOR_WHITE = 0x00F8F8F8,
 63#endif
 64	OFFSET_PRIORITY = 30,
 65	OFFSET_INDEX = 28,
 66};
 67
 68enum PixelFlags {
 69	FLAG_PRIORITY = 0xC0000000,
 70	FLAG_INDEX = 0x30000000,
 71	FLAG_IS_BACKGROUND = 0x08000000,
 72	FLAG_UNWRITTEN = 0xFC000000,
 73	FLAG_TARGET_1 = 0x02000000,
 74	FLAG_TARGET_2 = 0x01000000,
 75	FLAG_OBJWIN = 0x01000000,
 76
 77	FLAG_ORDER_MASK = 0xF8000000
 78};
 79
 80#define IS_WRITABLE(PIXEL) ((PIXEL) & 0xFE000000)
 81
 82union WindowRegion {
 83	struct {
 84		uint8_t end;
 85		uint8_t start;
 86	};
 87	uint16_t packed;
 88};
 89
 90struct WindowControl {
 91	union {
 92		struct {
 93			unsigned bg0Enable : 1;
 94			unsigned bg1Enable : 1;
 95			unsigned bg2Enable : 1;
 96			unsigned bg3Enable : 1;
 97			unsigned objEnable : 1;
 98			unsigned blendEnable : 1;
 99			unsigned : 2;
100		};
101		uint8_t packed;
102	};
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	unsigned outputBufferStride;
118
119	union GBARegisterDISPCNT dispcnt;
120
121	uint32_t row[VIDEO_HORIZONTAL_PIXELS];
122	uint32_t spriteLayer[VIDEO_HORIZONTAL_PIXELS];
123
124	// BLDCNT
125	unsigned target1Obj;
126	unsigned target1Bd;
127	unsigned target2Obj;
128	unsigned target2Bd;
129	enum BlendEffect blendEffect;
130	color_t normalPalette[512];
131	color_t variantPalette[512];
132	int anyTarget2;
133
134	uint16_t blda;
135	uint16_t bldb;
136	uint16_t bldy;
137
138	union {
139		struct {
140			unsigned bgH : 4;
141			unsigned bgV : 4;
142			unsigned objH : 4;
143			unsigned objV : 4;
144		};
145		uint16_t packed;
146	} mosaic;
147
148	struct WindowN {
149		union WindowRegion h;
150		union WindowRegion v;
151		struct WindowControl control;
152	} winN[2];
153
154	struct WindowControl winout;
155	struct WindowControl objwin;
156
157	struct WindowControl currentWindow;
158
159	int nWindows;
160	struct Window windows[MAX_WINDOW];
161
162	struct GBAVideoSoftwareBackground bg[4];
163
164	int oamDirty;
165	int oamMax;
166	struct GBAVideoSoftwareSprite sprites[128];
167
168	int start;
169	int end;
170};
171
172void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
173
174#endif