all repos — mgba @ c80cc1e307397b0eacc97c40009be58aaa56a4ec

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