diff --git a/CHANGES b/CHANGES index c4d250e29..4453790e7 100644 --- a/CHANGES +++ b/CHANGES @@ -20,6 +20,7 @@ Bugfixes: - Debugger: Fix watchpoints triggering too late - GBA Video: Fix sprite mis-ordering behavior in some cases (fixes #168) - GBA Video: Fix window interactions with 16-color mode 0 mosaic + - GBA Video: Fix sprite boundary conditions with mosaic Misc: - Qt: Disable sync to video by default - GBA: Exit cleanly on FATAL if the port supports it diff --git a/src/gba/renderers/video-software.c b/src/gba/renderers/video-software.c index 55e2dc10f..8f0d8cb4a 100644 --- a/src/gba/renderers/video-software.c +++ b/src/gba/renderers/video-software.c @@ -1578,14 +1578,22 @@ static void _drawBackgroundMode5(struct GBAVideoSoftwareRenderer* renderer, stru SPRITE_YBASE_ ## DEPTH(inY); \ unsigned tileData; \ if (outX % mosaicH) { \ - inX += (mosaicH - (outX % mosaicH)) * xOffset; \ - outX += mosaicH - (outX % mosaicH); \ + if (!inX && xOffset > 0) { \ + inX = mosaicH - (outX % mosaicH); \ + outX += mosaicH - (outX % mosaicH); \ + } else if (inX == width - xOffset) { \ + inX = mosaicH + (outX % mosaicH); \ + outX += mosaicH - (outX % mosaicH); \ + } \ } \ for (; outX < condition; ++outX, inX += xOffset) { \ if (!(renderer->row[outX] & FLAG_UNWRITTEN)) { \ continue; \ } \ int localX = inX - xOffset * (outX % mosaicH); \ + if (localX < 0 || localX > width - 1) { \ + continue; \ + } \ SPRITE_XBASE_ ## DEPTH(localX); \ SPRITE_DRAW_PIXEL_ ## DEPTH ## _ ## TYPE(localX); \ }