From 8236d7b6452f1de7b839ebe8e11ed7d76d498025 Mon Sep 17 00:00:00 2001 From: Asnivor Date: Thu, 21 Jun 2018 13:39:23 +0100 Subject: [PATCH] ZXHawk: Some PZX changes --- .../Hardware/Datacorder/DatacorderDevice.cs | 38 ++++++++++++++----- .../Media/Tape/PZX/PzxConverter.cs | 20 ++++------ .../Media/Tape/TapeDataBlock.cs | 2 +- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Datacorder/DatacorderDevice.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Datacorder/DatacorderDevice.cs index ff80df1982..7623daae23 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Datacorder/DatacorderDevice.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Datacorder/DatacorderDevice.cs @@ -408,7 +408,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { counter++; - if (counter > 30) + if (counter > 20) { counter = 0; bool state = GetEarBit(_machine.CPU.TotalExecutedCycles); @@ -451,15 +451,27 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // decrement cycles cycles -= _waitEdge; - // flip the current state - currentState = !currentState; - if (_position == 0 && _tapeIsPlaying) { - // start of block - - //if (!_dataBlocks[_currentDataBlockIndex].InitialPulseLevel[_position]) - //currentState = !currentState; + // start of block - take care of initial pulse level for PZX + switch (_dataBlocks[_currentDataBlockIndex].BlockDescription) + { + case BlockType.PULS: + // initial pulse level is always low + if (currentState) + FlipTapeState(); + break; + case BlockType.DATA: + // initial pulse level is stored in block + if (currentState != _dataBlocks[_currentDataBlockIndex].InitialPulseLevel) + FlipTapeState(); + break; + case BlockType.PAUS: + // initial pulse level is stored in block + if (currentState != _dataBlocks[_currentDataBlockIndex].InitialPulseLevel) + FlipTapeState(); + break; + } // notify about the current block var bl = _dataBlocks[_currentDataBlockIndex]; @@ -569,7 +581,10 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum } // update waitEdge with current position within the current block - _waitEdge = _dataBlocks[_currentDataBlockIndex].DataPeriods[_position]; + _waitEdge = _dataBlocks[_currentDataBlockIndex].DataPeriods[_position]; + + // flip the current state + FlipTapeState(); } @@ -582,6 +597,11 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum return currentState; } + private void FlipTapeState() + { + currentState = !currentState; + } + /// /// Flash loading implementation /// (Deterministic Emulation must be FALSE) diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/PZX/PzxConverter.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/PZX/PzxConverter.cs index 1d913aef8c..44d0c7b8c9 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/PZX/PzxConverter.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/PZX/PzxConverter.cs @@ -174,6 +174,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum t.BlockID = GetInt32(b, 0); t.DataPeriods = new List(); + t.InitialPulseLevel = false; + List pulses = new List(); while (pos < blockSize + 8) @@ -210,7 +212,6 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum for (int i = 0; i < x[0]; i++) { t.DataPeriods.Add(x[1]); - t.InitialPulseLevel.Add(true); } } @@ -248,6 +249,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum dCount = GetInt32(b, pos); initPulseLevel = (uint)((dCount & 0x80000000) == 0 ? 0 : 1); + t.InitialPulseLevel = initPulseLevel == 1 ? true : false; + dCount = (int)(dCount & 0x7FFFFFFF); pos += 4; @@ -277,8 +280,6 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum dData.Add(buff); } - bool initPulse = initPulseLevel == 1 ? true : false; - foreach (var by in dData) { for (int i = 7; i >= 0; i--) @@ -288,7 +289,6 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum foreach (var pu in s1) { t.DataPeriods.Add((int)pu); - t.InitialPulseLevel.Add(initPulse); } } @@ -297,13 +297,13 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum foreach (var pu in s0) { t.DataPeriods.Add((int)pu); - t.InitialPulseLevel.Add(initPulse); } } } } - + if (tail > 0) + t.DataPeriods.Add(tail); dData.Clear(); } @@ -312,7 +312,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum t.PauseInMS = 0; // tail - t.DataPeriods.Add(tail); + //t.DataPeriods.Add(tail); _datacorder.DataBlocks.Add(t); @@ -334,17 +334,13 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum var d = GetInt32(b, pos); iniPulseLevel = ((d & 0x80000000) == 0 ? 0 : 1); + t.InitialPulseLevel = iniPulseLevel == 1 ? true : false; pCount = (d & 0x7FFFFFFF); // convert to tape block t.BlockDescription = BlockType.PAUS; t.DataPeriods.Add(pCount); - if (iniPulseLevel == 1) - t.InitialPulseLevel.Add(true); - else - t.InitialPulseLevel.Add(false); - _datacorder.DataBlocks.Add(t); break; diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TapeDataBlock.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TapeDataBlock.cs index ed3c046fdc..c2b595f240 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TapeDataBlock.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TapeDataBlock.cs @@ -113,7 +113,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// public List DataPeriods = new List(); - public List InitialPulseLevel = new List(); + public bool InitialPulseLevel; /// /// Command that is raised by this data block