all repos — mgba @ dd31a888620ad6e8481a4e688f38dc078e75fc37

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) {
11	int i;
12	int oamMax = 0;
13	for (i = 0; i < 128; ++i) {
14		struct GBAObj obj;
15		LOAD_16LE(obj.a, 0, &oam[i].a);
16		LOAD_16LE(obj.b, 0, &oam[i].b);
17		LOAD_16LE(obj.c, 0, &oam[i].c);
18		if (GBAObjAttributesAIsTransformed(obj.a) || !GBAObjAttributesAIsDisable(obj.a)) {
19			int width = GBAVideoObjSizes[GBAObjAttributesAGetShape(obj.a) * 4 + GBAObjAttributesBGetSize(obj.b)][0];
20			int height = GBAVideoObjSizes[GBAObjAttributesAGetShape(obj.a) * 4 + GBAObjAttributesBGetSize(obj.b)][1];
21			int cycles = width;
22			if (GBAObjAttributesAIsTransformed(obj.a)) {
23				height <<= GBAObjAttributesAGetDoubleSize(obj.a);
24				width <<= GBAObjAttributesAGetDoubleSize(obj.a);
25				cycles = 10 + width * 2;
26			}
27			if (GBAObjAttributesAGetY(obj.a) < GBA_VIDEO_VERTICAL_PIXELS || GBAObjAttributesAGetY(obj.a) + height >= VIDEO_VERTICAL_TOTAL_PIXELS) {
28				int y = GBAObjAttributesAGetY(obj.a) + offsetY;
29				sprites[oamMax].y = y;
30				sprites[oamMax].endY = y + height;
31				sprites[oamMax].cycles = cycles;
32				sprites[oamMax].obj = obj;
33				sprites[oamMax].index = i;
34				++oamMax;
35			}
36		}
37	}
38	return oamMax;
39}