all repos — mgba @ 50402c830729f2ba5a6fc3e6facfd8b258f7f97d

mGBA Game Boy Advance Emulator

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

  1/* Copyright (c) 2013-2015 Jeffrey Pfau
  2 *
  3 * This Source Code Form is subject to the terms of the Mozilla Public
  4 * License, v. 2.0. If a copy of the MPL was not distributed with this
  5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6#ifndef VIDEO_SOFTWARE_H
  7#define VIDEO_SOFTWARE_H
  8
  9#include "util/common.h"
 10
 11#include "gba/video.h"
 12
 13#ifdef COLOR_16_BIT
 14typedef uint16_t color_t;
 15#else
 16typedef uint32_t color_t;
 17#endif
 18
 19struct GBAVideoSoftwareSprite {
 20	struct GBAObj obj;
 21	int y;
 22	int endY;
 23};
 24
 25struct GBAVideoSoftwareBackground {
 26	int index;
 27	int enabled;
 28	int priority;
 29	uint32_t charBase;
 30	int mosaic;
 31	int multipalette;
 32	uint32_t screenBase;
 33	int overflow;
 34	int size;
 35	int target1;
 36	int target2;
 37	uint16_t x;
 38	uint16_t y;
 39	int32_t refx;
 40	int32_t refy;
 41	int16_t dx;
 42	int16_t dmx;
 43	int16_t dy;
 44	int16_t dmy;
 45	int32_t sx;
 46	int32_t sy;
 47};
 48
 49enum BlendEffect {
 50	BLEND_NONE = 0,
 51	BLEND_ALPHA = 1,
 52	BLEND_BRIGHTEN = 2,
 53	BLEND_DARKEN = 3
 54};
 55
 56enum {
 57#ifdef COLOR_16_BIT
 58#ifdef COLOR_5_6_5
 59	GBA_COLOR_WHITE = 0xFFDF,
 60#else
 61	GBA_COLOR_WHITE = 0x7FFF,
 62#endif
 63#else
 64	GBA_COLOR_WHITE = 0x00F8F8F8,
 65#endif
 66	OFFSET_PRIORITY = 30,
 67	OFFSET_INDEX = 28,
 68};
 69
 70#define FLAG_PRIORITY       0xC0000000
 71#define FLAG_INDEX          0x30000000
 72#define FLAG_IS_BACKGROUND  0x08000000
 73#define FLAG_UNWRITTEN      0xFC000000
 74#define FLAG_REBLEND        0x04000000
 75#define FLAG_TARGET_1       0x02000000
 76#define FLAG_TARGET_2       0x01000000
 77#define FLAG_OBJWIN         0x01000000
 78#define FLAG_ORDER_MASK     0xF8000000
 79
 80#define IS_WRITABLE(PIXEL) ((PIXEL) & 0xFE000000)
 81
 82struct WindowRegion {
 83	uint8_t end;
 84	uint8_t start;
 85};
 86
 87DECL_BITFIELD(GBAWindowControl, uint8_t);
 88DECL_BIT(GBAWindowControl, Bg0Enable, 0);
 89DECL_BIT(GBAWindowControl, Bg1Enable, 1);
 90DECL_BIT(GBAWindowControl, Bg2Enable, 2);
 91DECL_BIT(GBAWindowControl, Bg3Enable, 3);
 92DECL_BIT(GBAWindowControl, ObjEnable, 4);
 93DECL_BIT(GBAWindowControl, BlendEnable, 5);
 94
 95DECL_BITFIELD(GBAMosaicControl, uint16_t);
 96DECL_BITS(GBAMosaicControl, BgH, 0, 4);
 97DECL_BITS(GBAMosaicControl, BgV, 4, 4);
 98DECL_BITS(GBAMosaicControl, ObjH, 8, 4);
 99DECL_BITS(GBAMosaicControl, ObjV, 12, 4);
100
101struct WindowControl {
102	GBAWindowControl packed;
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	int outputBufferStride;
118
119	uint32_t* temporaryBuffer;
120
121	GBARegisterDISPCNT dispcnt;
122
123	uint32_t row[VIDEO_HORIZONTAL_PIXELS];
124	uint32_t spriteLayer[VIDEO_HORIZONTAL_PIXELS];
125
126	// BLDCNT
127	unsigned target1Obj;
128	unsigned target1Bd;
129	unsigned target2Obj;
130	unsigned target2Bd;
131	enum BlendEffect blendEffect;
132	color_t normalPalette[512];
133	color_t variantPalette[512];
134	int anyTarget2;
135
136	uint16_t blda;
137	uint16_t bldb;
138	uint16_t bldy;
139
140	GBAMosaicControl mosaic;
141
142	struct WindowN {
143		struct WindowRegion h;
144		struct 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