From d1b1f1a5ac354617aefe8c30c305b71132214bc6 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Mon, 31 Oct 2016 22:09:26 -0400 Subject: [PATCH] Get VS Zapper working Now Duck Hunt and Gumshoe work, and other VS Zapper games hsould as well. Hurray! --- .../Consoles/Nintendo/NES/NESControllers.cs | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NESControllers.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NESControllers.cs index e5bf596802..fc7e3aa9e5 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NESControllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NESControllers.cs @@ -607,6 +607,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES /// PPUCallback { get; set; } + bool resetting = false; + uint latchedvalue = 0; + static ControllerDefinition Definition = new ControllerDefinition { BoolButtons = { "0Fire" }, @@ -614,18 +617,34 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES FloatRanges = { new[] { 0.0f, 128.0f, 255.0f }, new[] { 0.0f, 120.0f, 239.0f } } }; + void Latch(IController c) + { + byte ret = 0; + if (c["0Fire"]) + ret |= 0x80; + if (PPUCallback((int)c.GetFloat("0Zapper X"), (int)c.GetFloat("0Zapper Y"))) + ret |= 0x40; + + ret |= 0x10; // always 1 + latchedvalue = ret; + latchedvalue |= 0xFFFFFF00; + } + public void Strobe(StrobeInfo s, IController c) { + resetting = s.OUT0 != 0; + if (s.OUT0 < s.OUT0old) + Latch(c); } // NES controller port interface public byte Read(IController c) { - byte ret = 0; - if (c["0Fire"]) - ret |= 0x10; - if (!PPUCallback((int)c.GetFloat("0Zapper X"), (int)c.GetFloat("0Zapper Y"))) - ret |= 0x08; + if (resetting) + Latch(c); + byte ret = (byte)(latchedvalue & 1); + if (!resetting) + latchedvalue >>= 1; // ASR not LSR, so endless stream of 1s after data return ret; } @@ -636,6 +655,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public void SyncState(Serializer ser) { + ser.Sync("restting", ref resetting); + ser.Sync("latchedvalue", ref latchedvalue); } // famicom expansion hookups