From 91008590cfb01a76f71ef500445b98dc450378f1 Mon Sep 17 00:00:00 2001 From: Asnivor Date: Sun, 29 Dec 2019 22:23:20 +0000 Subject: [PATCH] ZXHawk: Implement more faithful AY port decoding (fixes #1767) --- .../Hardware/SoundOuput/AY38912.cs | 57 ++++++++++++------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/SoundOuput/AY38912.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/SoundOuput/AY38912.cs index c15be8d2a3..f95b3c0aa8 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/SoundOuput/AY38912.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/SoundOuput/AY38912.cs @@ -1,4 +1,5 @@ using BizHawk.Common; +using BizHawk.Common.NumberExtensions; using BizHawk.Emulation.Common; using System; using System.Collections.Generic; @@ -57,38 +58,54 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum #region IPortIODevice + /// + /// |11-- ---- ---- --0-| - IN - Read value of currently selected register + /// + /// public bool ReadPort(ushort port, ref int value) { - if (port != 0xfffd) + if (!port.Bit(1)) { - // port read is not addressing this device - return false; + if ((port >> 14) == 3) + { + // port read is addressing this device + value = PortRead(); + return true; + } } - value = PortRead(); - - return true; + // port read is not addressing this device + return false; } + /// + /// |11-- ---- ---- --0-| - OUT - Register Select + /// |10-- ---- ---- --0-| - OUT - Write value to currently selected register + /// + /// public bool WritePort(ushort port, int value) { - if (port == 0xfffd) + if (!port.Bit(1)) { - // register select - SelectedRegister = value & 0x0f; - return true; - } - else if (port == 0xbffd) - { - // Update the audiobuffer based on the current CPU cycle - // (this process the previous data BEFORE writing to the currently selected register) - int d = (int)(_machine.CurrentFrameCycle); - BufferUpdate(d); + if ((port >> 14) == 3) + { + // register select + SelectedRegister = value & 0x0f; + return true; + } + else if ((port >> 14) == 2) + { + // Update the audiobuffer based on the current CPU cycle + // (this process the previous data BEFORE writing to the currently selected register) + int d = (int)(_machine.CurrentFrameCycle); + BufferUpdate(d); - // write to register - PortWrite(value); - return true; + // write to register + PortWrite(value); + return true; + } } + return false; }