diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/APU.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/APU.cs index eb049b0c8b..ce8ad965c3 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/APU.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/APU.cs @@ -861,7 +861,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES /* if ((timer <= 3) && (out_bits_remaining == 0) && (sample_length != 0)) { - //Console.WriteLine("glitch 2"); + Console.WriteLine("glitch 2 " + timer); //fill_glitch_2 = true; } */ 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 79be2fb0c4..cf2438dd0b 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs @@ -448,12 +448,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public bool dmc_dma_exec = false; public bool dmc_realign; public bool IRQ_delay; - public bool special_case_delay; // very ugly but the only option public bool reread_trigger; public int do_the_reread_2002, do_the_reread_2007, do_the_reread_cont_1, do_the_reread_cont_2; public int reread_opp_4016, reread_opp_4017; public byte DB; //old data bus values from previous reads + // DMA's delay IRQ's by one cycle after finished, but allow them on the same cycle if just started public bool DMC_just_started; + public bool OAM_just_started; + public bool ppu_nmi; internal void RunCpuOne() { @@ -591,11 +593,23 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES if (cpu.RDY && !IRQ_delay) { cpu.IRQ = _irq_apu || Board.IrqSignal; + if (ppu_nmi) + { + cpu.NMI = ppu_nmi; + ppu_nmi = false; + } + } - else if (special_case_delay || DMC_just_started) + else if (OAM_just_started || DMC_just_started) { cpu.IRQ = _irq_apu || Board.IrqSignal; - special_case_delay = false; + if (ppu_nmi) + { + cpu.NMI = ppu_nmi; + ppu_nmi = false; + } + + OAM_just_started = false; DMC_just_started = false; } @@ -823,7 +837,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES oam_dma_exec = true; cpu.RDY = false; oam_dma_index = 0; - special_case_delay = true; + OAM_just_started = true; } } break; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.IStatable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.IStatable.cs index b141ccd7f6..7c2b8ed10e 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.IStatable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.IStatable.cs @@ -23,14 +23,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES ser.Sync(nameof(old_s), ref old_s); // OAM related - ser.Sync("Oam_Dma_Index", ref oam_dma_index); - ser.Sync("Oam_Dma_Exec", ref oam_dma_exec); - ser.Sync("Oam_Dma_Addr", ref oam_dma_addr); - ser.Sync("Oam_Dma_Byte", ref oam_dma_byte); - ser.Sync("Dmc_Dma_Exec", ref dmc_dma_exec); + ser.Sync(nameof(oam_dma_index), ref oam_dma_index); + ser.Sync(nameof(oam_dma_exec), ref oam_dma_exec); + ser.Sync(nameof(oam_dma_addr), ref oam_dma_addr); + ser.Sync(nameof(oam_dma_byte), ref oam_dma_byte); + ser.Sync(nameof(dmc_dma_exec), ref dmc_dma_exec); ser.Sync(nameof(dmc_realign), ref dmc_realign); ser.Sync(nameof(IRQ_delay), ref IRQ_delay); - ser.Sync(nameof(special_case_delay), ref special_case_delay); ser.Sync(nameof(reread_trigger), ref reread_trigger); ser.Sync(nameof(do_the_reread_2002), ref do_the_reread_2002); ser.Sync(nameof(do_the_reread_2007), ref do_the_reread_2007); @@ -38,7 +37,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES ser.Sync(nameof(do_the_reread_cont_2), ref do_the_reread_cont_2); ser.Sync(nameof(reread_opp_4016), ref reread_opp_4016); ser.Sync(nameof(reread_opp_4017), ref reread_opp_4017); + ser.Sync(nameof(OAM_just_started), ref OAM_just_started); ser.Sync(nameof(DMC_just_started), ref DMC_just_started); + ser.Sync(nameof(ppu_nmi), ref ppu_nmi); // VS related ser.Sync("VS", ref _isVS); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.cs index aa405a8dad..20476c7428 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.cs @@ -423,7 +423,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES NMI_PendingInstructions--; if (NMI_PendingInstructions <= 0) { - nes.cpu.NMI = true; + nes.ppu_nmi = true; } } } 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 e80233da8c..19e3fc1ed8 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs @@ -175,7 +175,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES } else if (ppur.status.cycle == (3 + NMI_offset) && ppur.status.sl == 241 + preNMIlines) { - if (nmi_destiny) { nes.cpu.NMI = true; } + if (nmi_destiny) { nes.ppu_nmi = true; } nes.Board.AtVsyncNmi(); }