all repos — mgba @ 0216557477ad2606a4e094ad53cefaae3185dd96

mGBA Game Boy Advance Emulator

GBA Video: Simplify sprite cycle counting (fixes #1279)
Vicki Pfau vi@endrift.com
Wed, 10 Jun 2020 01:28:39 -0700
commit

0216557477ad2606a4e094ad53cefaae3185dd96

parent

f11cb1c16bcd036227c970ee1ee3f2794a63509e

3 files changed, 8 insertions(+), 13 deletions(-)

jump to
M CHANGESCHANGES

@@ -13,6 +13,7 @@ - GBA Video: Fix mosaic objects drawing past the end (fixes mgba.io/i/1702)

- GBA Video: Fix disabling OBJWIN in GL renderer (fixes mgba.io/i/1759) - GBA Video: Add missing parts of 256-color mode 0 mosaic (fixes mgba.io/i/1701) - GBA Video: Fix double-size OBJ wrapping in GL renderer (fixes mgba.io/i/1712) + - GBA Video: Simplify sprite cycle counting (fixes mgba.io/i/1279) Other fixes: - ARM: Fix disassembling of several S-type instructions (fixes mgba.io/i/1778) - ARM Debugger: Clear low bit on breakpoint addresses (fixes mgba.io/i/1764)
M src/gba/renderers/software-obj.csrc/gba/renderers/software-obj.c

@@ -9,7 +9,6 @@ #define SPRITE_NORMAL_LOOP(DEPTH, TYPE) \

SPRITE_YBASE_ ## DEPTH(inY); \ unsigned tileData; \ for (; outX < condition; ++outX, inX += xOffset) { \ - renderer->spriteCyclesRemaining -= 1; \ SPRITE_XBASE_ ## DEPTH(inX); \ SPRITE_DRAW_PIXEL_ ## DEPTH ## _ ## TYPE(inX); \ }

@@ -33,7 +32,6 @@ unsigned tileData; \

unsigned widthMask = ~(width - 1); \ unsigned heightMask = ~(height - 1); \ for (; outX < condition; ++outX, ++inX) { \ - renderer->spriteCyclesRemaining -= 2; \ xAccum += mat.a; \ yAccum += mat.c; \ int localX = xAccum >> 8; \

@@ -55,7 +53,6 @@ unsigned heightMask = ~(height - 1); \

int localX = xAccum >> 8; \ int localY = yAccum >> 8; \ for (; outX < condition; ++outX, ++inX) { \ - renderer->spriteCyclesRemaining -= 2; \ xAccum += mat.a; \ yAccum += mat.c; \ \

@@ -272,7 +269,6 @@

if (outX < start || outX >= condition) { return 0; } - renderer->spriteCyclesRemaining -= 10; if (!GBAObjAttributesAIs256Color(sprite->a)) { palette = &palette[GBAObjAttributesCGetPalette(sprite->c) << 4];

@@ -305,9 +301,6 @@ SPRITE_TRANSFORMED_LOOP(256, NORMAL_OBJWIN);

} else { SPRITE_TRANSFORMED_LOOP(256, NORMAL); } - } - if (end == GBA_VIDEO_HORIZONTAL_PIXELS && x + totalWidth > GBA_VIDEO_HORIZONTAL_PIXELS) { - renderer->spriteCyclesRemaining -= (x + totalWidth - GBA_VIDEO_HORIZONTAL_PIXELS) * 2; } } else { int outX = x >= start ? x : start;

@@ -365,9 +358,6 @@ SPRITE_NORMAL_LOOP(256, NORMAL_OBJWIN);

} else { SPRITE_NORMAL_LOOP(256, NORMAL); } - } - if (end == GBA_VIDEO_HORIZONTAL_PIXELS && x + width > GBA_VIDEO_HORIZONTAL_PIXELS) { - renderer->spriteCyclesRemaining -= x + width - GBA_VIDEO_HORIZONTAL_PIXELS; } } return 1;
M src/gba/renderers/video-software.csrc/gba/renderers/video-software.c

@@ -845,12 +845,10 @@ localY = sprite->endY - 1;

} } for (w = 0; w < renderer->nWindows; ++w) { - if (renderer->spriteCyclesRemaining <= 0) { - break; - } renderer->currentWindow = renderer->windows[w].control; renderer->start = renderer->end; renderer->end = renderer->windows[w].endX; + // TODO: partial sprite drawing if (!GBAWindowControlIsObjEnable(renderer->currentWindow.packed) && !GBARegisterDISPCNTIsObjwinEnable(renderer->dispcnt)) { continue; }

@@ -858,6 +856,12 @@

int drawn = GBAVideoSoftwareRendererPreprocessSprite(renderer, &sprite->obj, sprite->index, localY); spriteLayers |= drawn << GBAObjAttributesCGetPriority(sprite->obj.c); } + int cycles = GBAVideoObjSizes[GBAObjAttributesAGetShape(sprite->obj.a) * 4 + GBAObjAttributesBGetSize(sprite->obj.b)][0]; + if (GBAObjAttributesAIsTransformed(sprite->obj.a)) { + cycles <<= GBAObjAttributesAGetDoubleSize(sprite->obj.a) + 1; + cycles += 10; + } + renderer->spriteCyclesRemaining -= cycles; if (renderer->spriteCyclesRemaining <= 0) { break; }