all repos — mgba @ e7be40e80ccb6dbeee0b79c97f349859b1b4afb8

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 height = GBAVideoObjSizes[GBAObjAttributesAGetShape(obj.a) * 4 + GBAObjAttributesBGetSize(obj.b)][1];
29				if (GBAObjAttributesAIsTransformed(obj.a)) {
30					height <<= GBAObjAttributesAGetDoubleSize(obj.a);
31				}
32				if (GBAObjAttributesAGetY(obj.a) < masterHeight || GBAObjAttributesAGetY(obj.a) + height >= 256) {
33					int y = GBAObjAttributesAGetY(obj.a) + offsetY;
34					sprites[oamMax].y = y;
35					sprites[oamMax].endY = y + height;
36					sprites[oamMax].obj = obj;
37					++oamMax;
38				}
39			}
40		}
41	}
42	return oamMax;
43}