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 height = GBAVideoObjSizes[GBAObjAttributesAGetShape(obj.a) * 4 + GBAObjAttributesBGetSize(obj.b)][1];
20 if (GBAObjAttributesAIsTransformed(obj.a)) {
21 height <<= GBAObjAttributesAGetDoubleSize(obj.a);
22 }
23 if (GBAObjAttributesAGetY(obj.a) < GBA_VIDEO_VERTICAL_PIXELS || GBAObjAttributesAGetY(obj.a) + height >= VIDEO_VERTICAL_TOTAL_PIXELS) {
24 int y = GBAObjAttributesAGetY(obj.a) + offsetY;
25 sprites[oamMax].y = y;
26 sprites[oamMax].endY = y + height;
27 sprites[oamMax].obj = obj;
28 sprites[oamMax].index = i;
29 ++oamMax;
30 }
31 }
32 }
33 return oamMax;
34}