diff --git a/bsnes/sfc/ppu-fast/background.cpp b/bsnes/sfc/ppu-fast/background.cpp index cb880bd6..ffa6867c 100644 --- a/bsnes/sfc/ppu-fast/background.cpp +++ b/bsnes/sfc/ppu-fast/background.cpp @@ -33,7 +33,7 @@ auto PPU::Line::renderBackground(PPU::IO::Background& self, uint8 source) -> voi hscroll <<= 1; if(io.interlace) { y = y << 1 | field(); - if(self.mosaicEnable) y -= io.mosaic.size - io.mosaic.counter + ppu.field(); + if(self.mosaicEnable) y -= io.mosaic.size - io.mosaic.counter + field(); } } diff --git a/bsnes/sfc/ppu-fast/io.cpp b/bsnes/sfc/ppu-fast/io.cpp index 7447be79..4e445a03 100644 --- a/bsnes/sfc/ppu-fast/io.cpp +++ b/bsnes/sfc/ppu-fast/io.cpp @@ -248,14 +248,13 @@ auto PPU::writeIO(uint address, uint8 data) -> void { } case 0x2106: { //MOSAIC - bool enable = io.bg1.mosaicEnable || io.bg2.mosaicEnable || io.bg3.mosaicEnable || io.bg4.mosaicEnable; + bool mosaicEnable = io.bg1.mosaicEnable || io.bg2.mosaicEnable || io.bg3.mosaicEnable || io.bg4.mosaicEnable; io.bg1.mosaicEnable = data >> 0 & 1; io.bg2.mosaicEnable = data >> 1 & 1; io.bg3.mosaicEnable = data >> 2 & 1; io.bg4.mosaicEnable = data >> 3 & 1; - io.mosaic.enable = data >> 0 & 15; io.mosaic.size = (data >> 4 & 15) + 1; - if(!enable && (data >> 0 & 15)) { + if(!mosaicEnable && (data >> 0 & 15)) { //mosaic vcounter is reloaded when mosaic becomes enabled io.mosaic.counter = io.mosaic.size + 1; } diff --git a/bsnes/sfc/ppu-fast/line.cpp b/bsnes/sfc/ppu-fast/line.cpp index f14a9899..7edf7e18 100644 --- a/bsnes/sfc/ppu-fast/line.cpp +++ b/bsnes/sfc/ppu-fast/line.cpp @@ -27,12 +27,6 @@ auto PPU::Line::flush() -> void { auto PPU::Line::cache() -> void { uint y = ppu.vcounter(); - if(y == 1) { - ppu.io.mosaic.counter = ppu.io.mosaic.enable ? ppu.io.mosaic.size + 1 : 0; - } - if(ppu.io.mosaic.counter && !--ppu.io.mosaic.counter) { - ppu.io.mosaic.counter = ppu.io.mosaic.enable ? ppu.io.mosaic.size + 0 : 0; - } if(ppu.io.displayDisable || y >= ppu.vdisp()) { io.displayDisable = true; } else { diff --git a/bsnes/sfc/ppu-fast/mode7.cpp b/bsnes/sfc/ppu-fast/mode7.cpp index c5251c17..dc44accf 100644 --- a/bsnes/sfc/ppu-fast/mode7.cpp +++ b/bsnes/sfc/ppu-fast/mode7.cpp @@ -1,12 +1,12 @@ auto PPU::Line::renderMode7(PPU::IO::Background& self, uint8 source) -> void { //HD mode 7 support - if(!ppu.hdMosaic() || !self.mosaicEnable || !io.mosaic.size) { + if(!ppu.hdMosaic() || !self.mosaicEnable || io.mosaic.size == 1) { if(ppu.hdScale() > 1) return renderMode7HD(self, source); } int Y = this->y; + if(self.mosaicEnable) Y -= io.mosaic.size - io.mosaic.counter; int y = !io.mode7.vflip ? Y : 255 - Y; - if(self.mosaicEnable) y -= io.mosaic.size - io.mosaic.counter; int a = (int16)io.mode7.a; int b = (int16)io.mode7.b; diff --git a/bsnes/sfc/ppu-fast/ppu.cpp b/bsnes/sfc/ppu-fast/ppu.cpp index 0ebb3450..718a6338 100644 --- a/bsnes/sfc/ppu-fast/ppu.cpp +++ b/bsnes/sfc/ppu-fast/ppu.cpp @@ -85,6 +85,13 @@ auto PPU::main() -> void { uint y = vcounter(); if(y >= 1 && y <= 239) { step(renderCycle()); + bool mosaicEnable = io.bg1.mosaicEnable || io.bg2.mosaicEnable || io.bg3.mosaicEnable || io.bg4.mosaicEnable; + if(y == 1) { + io.mosaic.counter = mosaicEnable ? io.mosaic.size + 1 : 0; + } + if(io.mosaic.counter && !--io.mosaic.counter) { + io.mosaic.counter = mosaicEnable ? io.mosaic.size + 0 : 0; + } lines[y].cache(); } } diff --git a/bsnes/sfc/ppu-fast/ppu.hpp b/bsnes/sfc/ppu-fast/ppu.hpp index 61e8aea5..2ef93c42 100644 --- a/bsnes/sfc/ppu-fast/ppu.hpp +++ b/bsnes/sfc/ppu-fast/ppu.hpp @@ -102,7 +102,6 @@ public: //serialization.cpp auto serialize(serializer&) -> void; - uint8 enable = 0; uint8 size = 1; uint8 counter = 0; } mosaic; diff --git a/bsnes/sfc/ppu-fast/serialization.cpp b/bsnes/sfc/ppu-fast/serialization.cpp index 75248288..ff6b4171 100644 --- a/bsnes/sfc/ppu-fast/serialization.cpp +++ b/bsnes/sfc/ppu-fast/serialization.cpp @@ -69,7 +69,6 @@ auto PPU::IO::serialize(serializer& s) -> void { } auto PPU::IO::Mosaic::serialize(serializer& s) -> void { - s.integer(enable); s.integer(size); s.integer(counter); } diff --git a/bsnes/sfc/ppu/io.cpp b/bsnes/sfc/ppu/io.cpp index fa07c7bd..745b3331 100644 --- a/bsnes/sfc/ppu/io.cpp +++ b/bsnes/sfc/ppu/io.cpp @@ -262,15 +262,16 @@ auto PPU::writeIO(uint addr, uint8 data) -> void { //MOSAIC case 0x2106: { - if(!mosaic.enable() && (data >> 0 & 15)) { - //mosaic vcounter is reloaded when mosaic becomes enabled - mosaic.vcounter = (data >> 4 & 15) + 2; - } + bool mosaicEnable = mosaic.enable(); bg1.mosaic.enable = data >> 0 & 1; bg2.mosaic.enable = data >> 1 & 1; bg3.mosaic.enable = data >> 2 & 1; bg4.mosaic.enable = data >> 3 & 1; mosaic.size = (data >> 4 & 15) + 1; + if(!mosaicEnable && mosaic.enable()) { + //mosaic vcounter is reloaded when mosaic becomes enabled + mosaic.vcounter = mosaic.size + 1; + } return; }