all repos — mgba @ 68f0176ee4fccfc8bb5bf0678b4c7122f1eff0f3

mGBA Game Boy Advance Emulator

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