all repos — mgba @ c62d913e233e7ea3bb23a3f52fcb7b481f2faed5

mGBA Game Boy Advance Emulator

src/gba/renderers/common.c (view raw)

 1/* Copyright (c) 2013-2019 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#include <mgba/internal/gba/renderers/common.h>
 7
 8#include <mgba/gba/interface.h>
 9
10int GBAVideoRendererCleanOAM(struct GBAObj* oam, struct GBAVideoRendererSprite* sprites, int offsetY, int masterHeight, bool combinedObjSort) {
11	int i;
12	int p;
13	int oamMax = 0;
14	int maxP = 1;
15	if (combinedObjSort) {
16		maxP = 4;
17	}
18	for (p = 0; p < maxP; ++p) {
19		for (i = 0; i < 128; ++i) {
20			struct GBAObj obj;
21			LOAD_16LE(obj.a, 0, &oam[i].a);
22			LOAD_16LE(obj.b, 0, &oam[i].b);
23			LOAD_16LE(obj.c, 0, &oam[i].c);
24			if (combinedObjSort && GBAObjAttributesCGetPriority(obj.c) != p) {
25				continue;
26			}
27			if (GBAObjAttributesAIsTransformed(obj.a) || !GBAObjAttributesAIsDisable(obj.a)) {
28				int width = GBAVideoObjSizes[GBAObjAttributesAGetShape(obj.a) * 4 + GBAObjAttributesBGetSize(obj.b)][0];
29				int height = GBAVideoObjSizes[GBAObjAttributesAGetShape(obj.a) * 4 + GBAObjAttributesBGetSize(obj.b)][1];
30				int cycles = width;
31				if (GBAObjAttributesAIsTransformed(obj.a)) {
32					height <<= GBAObjAttributesAGetDoubleSize(obj.a);
33					width <<= GBAObjAttributesAGetDoubleSize(obj.a);
34					cycles = 10 + width * 2;
35				}
36				if (GBAObjAttributesAGetY(obj.a) < masterHeight || GBAObjAttributesAGetY(obj.a) + height >= 256) {
37					int y = GBAObjAttributesAGetY(obj.a) + offsetY;
38					sprites[oamMax].y = y;
39					sprites[oamMax].endY = y + height;
40					sprites[oamMax].cycles = cycles;
41					sprites[oamMax].obj = obj;
42					sprites[oamMax].index = i;
43					++oamMax;
44				}
45			}
46		}
47	}
48	return oamMax;
49}