From 9498206980b0ab6c3092947e4c395bade5291d7b Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Mon, 23 Oct 2017 17:15:08 -0400 Subject: [PATCH] NESHawk: FDS Timer IRQ's --- .../Consoles/Nintendo/NES/FDS/FDS.cs | 38 +++++++++---------- .../Consoles/Nintendo/NES/FDS/RamAdapter.cs | 7 +++- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/FDS/FDS.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/FDS/FDS.cs index 9f46fdf560..e649c730e5 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/FDS/FDS.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/FDS/FDS.cs @@ -255,19 +255,29 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES case 0x0020: timerlatch &= 0xff00; timerlatch |= value; - //timerirq = false; break; case 0x0021: timerlatch &= 0x00ff; timerlatch |= value << 8; - //timerirq = false; break; case 0x0022: - timerreg = (byte)(value & 3); - timervalue = timerlatch; + if (diskenable) + { + timerreg = (byte)(value & 3); + if ((value & 0x02) == 0x02) + { + timervalue = timerlatch; + } + else + { + _timerirq = false; + } + } + break; case 0x0023: diskenable = (value & 1) != 0; + if (!diskenable) { _timerirq = false; } soundenable = (value & 2) != 0; break; case 0x0024: @@ -344,7 +354,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public override void ClockCPU() { - if ((timerreg & 2) != 0)// && timervalue > 0) + if ((timerreg & 2) != 0 && diskenable) { if (timervalue!=0) { @@ -352,22 +362,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES } if (timervalue == 0) { - - /* - if ((timerreg & 1) != 0) - { - timervalue = timerlatch; - //timervalue = 0xFFFF; - } - else - { - timerreg &= unchecked((byte)~2); - timervalue = 0; - timerlatch = 0; - } - */ timervalue = timerlatch; timerirq = true; + if ((timerreg & 1) == 0) + { + timerreg -= 2; + } } } audio.Clock(); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/FDS/RamAdapter.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/FDS/RamAdapter.cs index 4861d49708..9c86f953e7 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/FDS/RamAdapter.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/FDS/RamAdapter.cs @@ -67,14 +67,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES byte[] fileheader = br.ReadBytes(16); if (fileheader[0] != 0x03) { - throw new Exception("Corrupt FDS block 3"); + // Instead of exceptions, display strong warnings + Console.WriteLine("WARNING: INVALID FILE, BLOCK 3 ERROR"); + //throw new Exception("Corrupt FDS block 3"); } int filesize = fileheader[13] + fileheader[14] * 256; byte[] file = br.ReadBytes(filesize + 1); if (file[0] != 0x04) { - throw new Exception("Corrupt FDS block 4"); + Console.WriteLine("WARNING: INVALID FILE, BLOCK 4 ERROR"); + //throw new Exception("Corrupt FDS block 4"); } WriteBlock(ret, fileheader, 122);