From 0341dd12b2e39586a82ddf81b670aa1d6aaff69d Mon Sep 17 00:00:00 2001 From: Sour Date: Sat, 13 Jul 2019 14:16:50 -0400 Subject: [PATCH] PPU: Fixed mode7 regressions (horizontal mirroring and sprite priority) --- Core/Ppu.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Core/Ppu.cpp b/Core/Ppu.cpp index 450ca39..af2d04f 100644 --- a/Core/Ppu.cpp +++ b/Core/Ppu.cpp @@ -1101,18 +1101,26 @@ void Ppu::RenderTilemapMode7() (centerY << 8) ); - xValue += _mode7.Matrix[0] * _drawStartX; - yValue += _mode7.Matrix[2] * _drawStartX; + int16_t xStep = _mode7.Matrix[0]; + int16_t yStep = _mode7.Matrix[2]; + if(_mode7.HorizontalMirroring) { + //Calculate the value at the end of the scanline, and then start going backwards + xValue += xStep * _drawEndX; + yValue += yStep * _drawEndX; + xStep = -xStep; + yStep = -yStep; + } + + xValue += xStep * _drawStartX; + yValue += yStep * _drawStartX; uint8_t pixelFlags = PixelFlags::Filled | (((_colorMathEnabled >> layerIndex) & 0x01) ? PixelFlags::AllowColorMath : 0); for(int x = _drawStartX; x <= _drawEndX; x++) { - uint16_t realX = _mode7.HorizontalMirroring ? (255 - x) : x; - int32_t xOffset = xValue >> 8; int32_t yOffset = yValue >> 8; - xValue += _mode7.Matrix[0]; - yValue += _mode7.Matrix[2]; + xValue += xStep; + yValue += yStep; if(_rowPixelFlags[x] && _subScreenFilled[x]) { continue; @@ -1156,11 +1164,11 @@ void Ppu::RenderTilemapMode7() paletteColor = _cgram[colorIndex]; } - if(drawMain && !ProcessMaskWindow(mainWindowCount, x)) { + if(drawMain && !_rowPixelFlags[x] && !ProcessMaskWindow(mainWindowCount, x)) { DrawMainPixel(x, paletteColor, pixelFlags); } - if(drawSub && !ProcessMaskWindow(subWindowCount, x)) { + if(drawSub && !_subScreenFilled[x] && !ProcessMaskWindow(subWindowCount, x)) { DrawSubPixel(x, paletteColor); } }