From 3c8a6a4e19211004e4c545f9e1635294442798fa Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Sat, 4 Feb 2017 09:14:55 -0500 Subject: [PATCH] NES: Fix PPU timing and Race condition --- .../Consoles/Nintendo/NES/PPU.regs.cs | 4 ++++ .../Consoles/Nintendo/NES/PPU.run.cs | 20 ++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.regs.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.regs.cs index 155690b2c7..c89ed19a33 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.regs.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.regs.cs @@ -479,6 +479,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES //VRAM address register (write) void write_2006(byte value) { + if (ppur.status.cycle==256) + { + conflict_2006 = true; + } if (!vtoggle) { ppur._vt &= 0x07; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs index 70345b5b38..1a6006f135 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs @@ -39,6 +39,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public int spriteHeight; public byte[] soam = new byte[512]; // in a real nes, this would only be 32, but we wish to allow more then 8 sprites per scanline public bool reg_2001_color_disable_latch; // the value used here is taken + public bool conflict_2006; struct TempOAM { @@ -124,19 +125,20 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES bgdata.pt_1 = ppubus_read(ppu_addr_temp, true, true); runppu(1); - //horizontal scroll clocked at cycle 3 and then - //vertical scroll at 255 - if (reg_2001.PPUON) - { - ppur.increment_hsc(); - if (ppur.status.cycle == 255) - ppur.increment_vs(); - } + break; case 7: runppu(1); - + //horizontal scroll clocked at cycle 3 and then + //vertical scroll at 256 + if (reg_2001.PPUON) + { + ppur.increment_hsc(); + if (ppur.status.cycle == 256 && !conflict_2006) + ppur.increment_vs(); + } + conflict_2006 = false; break; } //switch(cycle) }