From 7dfd19de2b6b1e50ebe770aa907895f7c3c46672 Mon Sep 17 00:00:00 2001 From: Asnivor Date: Mon, 4 Jun 2018 17:11:12 +0100 Subject: [PATCH] ZXHawk: Fix memory contention lookup overflow --- .../Computers/SinclairSpectrum/Machine/CPUMonitor.cs | 2 +- .../Computers/SinclairSpectrum/Machine/ULA.cs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/CPUMonitor.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/CPUMonitor.cs index e345c44c4f..8cfd43c657 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/CPUMonitor.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/CPUMonitor.cs @@ -109,7 +109,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum } if (_machine.IsContended(addr)) - _cpu.TotalExecutedCycles += _machine.ULADevice.GetContentionValue(); + _cpu.TotalExecutedCycles += _machine.ULADevice.GetContentionValue((int)(_machine.CurrentFrameCycle + 1)); } } diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ULA.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ULA.cs index 72bd3bc3ba..59abd58290 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ULA.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ULA.cs @@ -752,7 +752,11 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public int GetContentionValue() { - return RenderingTable.Renderer[_machine.CurrentFrameCycle].ContentionValue; + var f = _machine.CurrentFrameCycle; + if (f >= FrameCycleLength) + f -= FrameCycleLength; + + return RenderingTable.Renderer[f].ContentionValue; } ///