From 02cd2f47f30997b895426fa8b89fd8d59ff0df1e Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Fri, 18 Jun 2021 23:08:04 -0400 Subject: [PATCH] NESHawk: update lag definition and add sprite address glitch --- .../Consoles/Nintendo/NES/NES.Core.cs | 6 +++++- .../Consoles/Nintendo/NES/PPU.cs | 4 +++- .../Consoles/Nintendo/NES/PPU.regs.cs | 6 +++--- .../Consoles/Nintendo/NES/PPU.run.cs | 19 ++++++++++++++++--- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs index 24a2988f1f..73fee421c1 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs @@ -744,6 +744,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES private void write_joyport(byte value) { + //Console.WriteLine("cont " + value + " frame " + Frame); + var si = new StrobeInfo(latched4016, value); ControllerDeck.Strobe(si, _controller); latched4016 = value; @@ -752,13 +754,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { controller_was_latched = true; alt_lag = false; + lagged = false; } + current_strobe = new_strobe; } private byte read_joyport(int addr) { InputCallbacks.Call(); - lagged = false; + byte ret; if (_isVS) { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.cs index ef96f42cd3..d4cd8c6d9f 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.cs @@ -3,7 +3,7 @@ using BizHawk.Common; namespace BizHawk.Emulation.Cores.Nintendo.NES { - public sealed partial class PPU + public partial class PPU { public int cpu_step, cpu_stepcounter; @@ -260,6 +260,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES ser.Sync(nameof(yp), ref yp); ser.Sync(nameof(target), ref target); ser.Sync(nameof(ppu_was_on), ref ppu_was_on); + ser.Sync(nameof(ppu_was_on_spr), ref ppu_was_on_spr); ser.Sync(nameof(spriteHeight), ref spriteHeight); ser.Sync(nameof(install_2006), ref install_2006); ser.Sync(nameof(race_2006), ref race_2006); @@ -356,6 +357,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES ppu_open_bus = 0; ppu_open_bus_decay_timer = new int[8]; double_2007_read = 0; + start_up_offset = 2; } private void runppu() diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.regs.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.regs.cs index 67b1d02ef2..ea5102cb26 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.regs.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.regs.cs @@ -12,7 +12,7 @@ using BizHawk.Common; namespace BizHawk.Emulation.Cores.Nintendo.NES { - sealed partial class PPU + public partial class PPU { public sealed class Reg_2001 { @@ -294,7 +294,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public PPUREGS ppur; public Reg_2000 reg_2000; public Reg_2001 reg_2001; - private byte reg_2003; + public byte reg_2003; public byte reg_2006_2; private void regs_reset() @@ -436,7 +436,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { OAM[reg_2003] = value; reg_2003++; - } + } } else { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs index decb671de3..606f014f6c 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs @@ -2,11 +2,12 @@ using BizHawk.Common; using BizHawk.Common.NumberExtensions; +using System; using System.Runtime.CompilerServices; namespace BizHawk.Emulation.Cores.Nintendo.NES { - sealed partial class PPU + public partial class PPU { private struct BGDataRecord { @@ -36,6 +37,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public int spriteHeight; public byte[] soam = new byte[256]; // in a real nes, this would only be 32, but we wish to allow more then 8 sprites per scanline public bool ppu_was_on; + public bool ppu_was_on_spr; public byte[] sl_sprites = new byte[3 * 256]; // installing vram address is delayed after second write to 2006, set this up here @@ -131,7 +133,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES private bool nmi_destiny; private bool evenOddDestiny; - private static readonly int start_up_offset = 2; + private int start_up_offset; private int NMI_offset; private int yp_shift; private int sprite_eval_cycle; @@ -524,7 +526,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES //check all the conditions that can cause things to render in these 8px renderspritenow = show_obj_new && (xt > 0 || reg_2001.show_obj_leftmost); - } + } + + if (ppur.status.cycle > 63) + { + if (ppu_was_on_spr && !PPUON) + { + Console.WriteLine("oam addr glitch " + ppur.status.sl + " " + ppur.status.cycle); + reg_2003++; + } + } + + ppu_was_on_spr = PPUON; } else {