all repos — mgba @ daaa2fa5236df5e8976e7e0ba7ac39e0d9233422

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 "core/core.h"
 12#include "gba/video.h"
 13
 14struct GBAVideoSoftwareSprite {
 15	struct GBAObj obj;
 16	int y;
 17	int endY;
 18};
 19
 20struct GBAVideoSoftwareBackground {
 21	unsigned index;
 22	int enabled;
 23	unsigned 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_REBLEND        0x04000000
 70#define FLAG_TARGET_1       0x02000000
 71#define FLAG_TARGET_2       0x01000000
 72#define FLAG_OBJWIN         0x01000000
 73#define FLAG_ORDER_MASK     0xF8000000
 74
 75#define IS_WRITABLE(PIXEL) ((PIXEL) & 0xFE000000)
 76
 77struct WindowRegion {
 78	uint8_t end;
 79	uint8_t start;
 80};
 81
 82DECL_BITFIELD(GBAWindowControl, uint8_t);
 83DECL_BIT(GBAWindowControl, Bg0Enable, 0);
 84DECL_BIT(GBAWindowControl, Bg1Enable, 1);
 85DECL_BIT(GBAWindowControl, Bg2Enable, 2);
 86DECL_BIT(GBAWindowControl, Bg3Enable, 3);
 87DECL_BIT(GBAWindowControl, ObjEnable, 4);
 88DECL_BIT(GBAWindowControl, BlendEnable, 5);
 89
 90DECL_BITFIELD(GBAMosaicControl, uint16_t);
 91DECL_BITS(GBAMosaicControl, BgH, 0, 4);
 92DECL_BITS(GBAMosaicControl, BgV, 4, 4);
 93DECL_BITS(GBAMosaicControl, ObjH, 8, 4);
 94DECL_BITS(GBAMosaicControl, ObjV, 12, 4);
 95
 96struct WindowControl {
 97	GBAWindowControl packed;
 98	int8_t priority;
 99};
100
101#define MAX_WINDOW 5
102
103struct Window {
104	uint8_t endX;
105	struct WindowControl control;
106};
107
108struct GBAVideoSoftwareRenderer {
109	struct GBAVideoRenderer d;
110
111	color_t* outputBuffer;
112	int outputBufferStride;
113
114	uint32_t* temporaryBuffer;
115
116	GBARegisterDISPCNT dispcnt;
117
118	uint32_t row[VIDEO_HORIZONTAL_PIXELS];
119	uint32_t spriteLayer[VIDEO_HORIZONTAL_PIXELS];
120	int32_t spriteCyclesRemaining;
121
122	// BLDCNT
123	unsigned target1Obj;
124	unsigned target1Bd;
125	unsigned target2Obj;
126	unsigned target2Bd;
127	enum BlendEffect blendEffect;
128	color_t normalPalette[512];
129	color_t variantPalette[512];
130
131	uint16_t blda;
132	uint16_t bldb;
133	uint16_t bldy;
134
135	GBAMosaicControl mosaic;
136
137	struct WindowN {
138		struct WindowRegion h;
139		struct WindowRegion v;
140		struct WindowControl control;
141	} winN[2];
142
143	struct WindowControl winout;
144	struct WindowControl objwin;
145
146	struct WindowControl currentWindow;
147
148	int nWindows;
149	struct Window windows[MAX_WINDOW];
150
151	struct GBAVideoSoftwareBackground bg[4];
152
153	int oamDirty;
154	int oamMax;
155	int objwinMax;
156	struct GBAVideoSoftwareSprite sprites[128];
157	struct GBAVideoSoftwareSprite objwinSprites[128];
158
159	int start;
160	int end;
161};
162
163void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
164
165#endif