all repos — mgba @ 570f2c5f380464ae7f6d468242151d520cb00c15

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