diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ULA.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ULA.cs index 398c0c958f..0124f6721e 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ULA.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ULA.cs @@ -98,6 +98,16 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public int PortContentionOffset; + /// + /// Arbitrary offset for render table generation + /// + public int RenderTableOffset; + + /// + /// The offset when return floating bus bytes + /// + public int FloatingBusOffset; + /// /// The time in T-States for one scanline to complete /// @@ -317,17 +327,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// private void InitRenderer(MachineType machineType) { - switch (machineType) - { - case MachineType.ZXSpectrum16: - case MachineType.ZXSpectrum48: - Offset = 0; - break; - } - for (var t = 0; t < _ula.FrameCycleLength; t++) { - var tStateScreen = t + 1 + _ula.InterruptStartTime; + var tStateScreen = t + _ula.RenderTableOffset + _ula.InterruptStartTime; if (tStateScreen < 0) tStateScreen += _ula.FrameCycleLength; @@ -458,7 +460,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // calculate contention values for (int t = 0; t < _ula.FrameCycleLength; t++) { - int shifted = (t + 1) + _ula.InterruptStartTime + Offset; + int shifted = t + _ula.RenderTableOffset + _ula.InterruptStartTime; if (shifted < 0) shifted += _ula.FrameCycleLength; shifted %= _ula.FrameCycleLength; @@ -482,46 +484,6 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum Renderer[t].ContentionValue = conPattern[pixByte]; } - - // calculate floating bus values - for (int t = 0; t < _ula.FrameCycleLength; t++) - { - int shifted = (t + 10) + _ula.InterruptStartTime; - if (shifted < 0) - shifted += _ula.FrameCycleLength; - shifted %= _ula.FrameCycleLength; - - Renderer[t].FloatingBusAddress = 0; - - int line = shifted / _ula.ScanlineTime; - int pix = shifted % _ula.ScanlineTime; - if (line < _ula.FirstPaperLine || line >= (_ula.FirstPaperLine + 192)) - { - Renderer[t].FloatingBusAddress = 0; - continue; - } - int scrPix = pix - _ula.FirstPaperTState; - if (scrPix < 0 || scrPix >= 128) - { - Renderer[t].FloatingBusAddress = 0; - continue; - } - - int pixByte = scrPix % 8; - int chunk = scrPix % 16; - - switch (chunk) - { - case 0: - case 2: - Renderer[t].FloatingBusAddress = CalculateByteAddress(scrPix, line); - break; - case 1: - case 3: - Renderer[t].FloatingBusAddress = CalculateAttributeAddress(scrPix, line); - break; - } - } } private ushort CalculateByteAddress(int x, int y) @@ -719,8 +681,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public void ReadFloatingBus(int tstate, ref int result) { - int off = 0; - tstate += off; + tstate += FloatingBusOffset; if (tstate >= RenderingTable.Renderer.Length) tstate -= RenderingTable.Renderer.Length; if (tstate < 0) diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128K/ZX128.Screen.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128K/ZX128.Screen.cs index 3e1aed6e24..92472c0e3b 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128K/ZX128.Screen.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128K/ZX128.Screen.cs @@ -22,6 +22,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum MemoryContentionOffset = 5; PortContentionOffset = 5; + RenderTableOffset = 1; + FloatingBusOffset = 1; BorderLeftTime = 24; BorderRightTime = 24; diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128KPlus2a/ZX128Plus2a.Screen.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128KPlus2a/ZX128Plus2a.Screen.cs index 90f505d1f2..2cd69dcaa7 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128KPlus2a/ZX128Plus2a.Screen.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum128KPlus2a/ZX128Plus2a.Screen.cs @@ -22,6 +22,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum MemoryContentionOffset = 7; PortContentionOffset = 7; + RenderTableOffset = 1; + FloatingBusOffset = 1; BorderLeftTime = 24; BorderRightTime = 24; diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum48K/ZX48.Screen.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum48K/ZX48.Screen.cs index 5af98f944a..96624fe1d5 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum48K/ZX48.Screen.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum48K/ZX48.Screen.cs @@ -16,12 +16,14 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // timing ClockSpeed = 3500000; FrameCycleLength = 69888; - InterruptStartTime = 31; + InterruptStartTime = 30; InterruptLength = 32; ScanlineTime = 224; - MemoryContentionOffset = 5; - PortContentionOffset = 5; + MemoryContentionOffset = 6; + PortContentionOffset = 6; + RenderTableOffset = 2; + FloatingBusOffset = 1; BorderLeftTime = 24; BorderRightTime = 24;