all repos — mgba @ 32bc6750c1d0df840ed81234c330a33ee0142ba4

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
 76struct WindowRegion {
 77	uint8_t end;
 78	uint8_t start;
 79};
 80
 81DECL_BITFIELD(GBAWindowControl, uint8_t);
 82DECL_BIT(GBAWindowControl, Bg0Enable, 0);
 83DECL_BIT(GBAWindowControl, Bg1Enable, 1);
 84DECL_BIT(GBAWindowControl, Bg2Enable, 2);
 85DECL_BIT(GBAWindowControl, Bg3Enable, 3);
 86DECL_BIT(GBAWindowControl, ObjEnable, 4);
 87DECL_BIT(GBAWindowControl, BlendEnable, 5);
 88
 89DECL_BITFIELD(GBAMosaicControl, uint16_t);
 90DECL_BITS(GBAMosaicControl, BgH, 0, 4);
 91DECL_BITS(GBAMosaicControl, BgV, 4, 4);
 92DECL_BITS(GBAMosaicControl, ObjH, 8, 4);
 93DECL_BITS(GBAMosaicControl, ObjV, 12, 4);
 94
 95struct WindowControl {
 96	GBAWindowControl packed;
 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	GBAMosaicControl mosaic;
133
134	struct WindowN {
135		struct WindowRegion h;
136		struct WindowRegion v;
137		struct WindowControl control;
138	} winN[2];
139
140	struct WindowControl winout;
141	struct WindowControl objwin;
142
143	struct WindowControl currentWindow;
144
145	int nWindows;
146	struct Window windows[MAX_WINDOW];
147
148	struct GBAVideoSoftwareBackground bg[4];
149
150	int oamDirty;
151	int oamMax;
152	struct GBAVideoSoftwareSprite sprites[128];
153
154	int start;
155	int end;
156};
157
158void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
159
160#endif