all repos — mgba @ a47bc8455c826a6618089207e96864f78e461c96

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	bool highlight;
 46};
 47
 48enum {
 49#ifdef COLOR_16_BIT
 50#ifdef COLOR_5_6_5
 51	GBA_COLOR_WHITE = 0xFFDF,
 52#else
 53	GBA_COLOR_WHITE = 0x7FFF,
 54#endif
 55#else
 56	GBA_COLOR_WHITE = 0x00F8F8F8,
 57#endif
 58	OFFSET_PRIORITY = 30,
 59	OFFSET_INDEX = 28,
 60};
 61
 62#define FLAG_PRIORITY       0xC0000000
 63#define FLAG_INDEX          0x30000000
 64#define FLAG_IS_BACKGROUND  0x08000000
 65#define FLAG_UNWRITTEN      0xFC000000
 66#define FLAG_REBLEND        0x04000000
 67#define FLAG_TARGET_1       0x02000000
 68#define FLAG_TARGET_2       0x01000000
 69#define FLAG_OBJWIN         0x01000000
 70#define FLAG_ORDER_MASK     0xF8000000
 71
 72#define IS_WRITABLE(PIXEL) ((PIXEL) & 0xFE000000)
 73
 74struct WindowControl {
 75	GBAWindowControl packed;
 76	int8_t priority;
 77};
 78
 79#define MAX_WINDOW 5
 80
 81struct Window {
 82	uint8_t endX;
 83	struct WindowControl control;
 84};
 85
 86struct GBAVideoSoftwareRenderer {
 87	struct GBAVideoRenderer d;
 88
 89	color_t* outputBuffer;
 90	int outputBufferStride;
 91
 92	uint32_t* temporaryBuffer;
 93
 94	GBARegisterDISPCNT dispcnt;
 95
 96	uint32_t row[GBA_VIDEO_HORIZONTAL_PIXELS];
 97	uint32_t spriteLayer[GBA_VIDEO_HORIZONTAL_PIXELS];
 98	int32_t spriteCyclesRemaining;
 99
100	// BLDCNT
101	unsigned target1Obj;
102	unsigned target1Bd;
103	unsigned target2Obj;
104	unsigned target2Bd;
105	bool blendDirty;
106	enum GBAVideoBlendEffect blendEffect;
107	color_t normalPalette[512];
108	color_t variantPalette[512];
109	color_t highlightPalette[512];
110	color_t highlightVariantPalette[512];
111
112	uint16_t blda;
113	uint16_t bldb;
114	uint16_t bldy;
115
116	GBAMosaicControl mosaic;
117
118	struct WindowN {
119		struct GBAVideoWindowRegion h;
120		struct GBAVideoWindowRegion v;
121		struct WindowControl control;
122	} winN[2];
123
124	struct WindowControl winout;
125	struct WindowControl objwin;
126
127	struct WindowControl currentWindow;
128
129	int nWindows;
130	struct Window windows[MAX_WINDOW];
131
132	struct GBAVideoSoftwareBackground bg[4];
133
134	bool forceTarget1;
135	bool oamDirty;
136	int oamMax;
137	struct GBAVideoRendererSprite sprites[128];
138	int16_t objOffsetX;
139	int16_t objOffsetY;
140
141	uint32_t scanlineDirty[5];
142	uint16_t nextIo[REG_SOUND1CNT_LO >> 1];
143	struct ScanlineCache {
144		uint16_t io[REG_SOUND1CNT_LO >> 1];
145		int32_t scale[2][2];
146	} cache[GBA_VIDEO_VERTICAL_PIXELS];
147	int nextY;
148
149	int start;
150	int end;
151
152	uint8_t lastHighlightAmount;
153};
154
155void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer);
156
157CXX_GUARD_START
158
159#endif