From 98fe9a85d658dbb3d9dd1aa43b3639cf7efc4713 Mon Sep 17 00:00:00 2001 From: Sour Date: Sun, 5 Jul 2020 16:21:26 -0400 Subject: [PATCH] PPU: Fixed mosaic display when reading/writing to PPU registers in the middle of a scanline --- Core/Ppu.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Core/Ppu.cpp b/Core/Ppu.cpp index af496c8..d6fb066 100644 --- a/Core/Ppu.cpp +++ b/Core/Ppu.cpp @@ -949,7 +949,7 @@ void Ppu::RenderTilemap() TileData* tileData = _layerData[layerIndex].Tiles; - uint8_t mosaicCounter = applyMosaic ? _state.MosaicSize - (_drawStartX % _state.MosaicSize) : 0; + uint8_t mosaicCounter = applyMosaic ? (_drawStartX % _state.MosaicSize) : 0; uint8_t lookupIndex; uint8_t chrDataOffset; @@ -988,7 +988,7 @@ void Ppu::RenderTilemap() uint8_t priority = (tilemapData & 0x2000) ? highPriority : normalPriority; if(applyMosaic) { - if(mosaicCounter == _state.MosaicSize) { + if(mosaicCounter == 0) { mosaicCounter = 1; if(hiResMode) { color = hiresSubColor; @@ -997,6 +997,9 @@ void Ppu::RenderTilemap() _mosaicPriority[layerIndex] = priority; } else { mosaicCounter++; + if(mosaicCounter == _state.MosaicSize) { + mosaicCounter = 0; + } color = _mosaicColor[layerIndex] & 0xFF; paletteIndex = _mosaicColor[layerIndex] >> 8; priority = _mosaicPriority[layerIndex]; @@ -1108,7 +1111,7 @@ void Ppu::RenderTilemapMode7() //Keep the "scanline" to what it was at the start of this mosaic block realY -= _state.MosaicSize - _mosaicScanlineCounter; } - uint8_t mosaicCounter = applyMosaic ? _state.MosaicSize - (_drawStartX % _state.MosaicSize) : 0; + uint8_t mosaicCounter = applyMosaic ? (_drawStartX % _state.MosaicSize) : 0; int32_t xValue = ( ((_state.Mode7.Matrix[0] * clip(hScroll - centerX)) & ~63) + @@ -1175,12 +1178,15 @@ void Ppu::RenderTilemapMode7() } if(applyMosaic) { - if(mosaicCounter == _state.MosaicSize) { + if(mosaicCounter == 0) { mosaicCounter = 1; _mosaicColor[layerIndex] = colorIndex; _mosaicPriority[layerIndex] = priority; } else { mosaicCounter++; + if(mosaicCounter == _state.MosaicSize) { + mosaicCounter = 0; + } colorIndex = _mosaicColor[layerIndex]; priority = _mosaicPriority[layerIndex]; }