From 1fb10f3d9c6ede9601d882ab1064a8576636edca Mon Sep 17 00:00:00 2001 From: Asnivor Date: Mon, 15 Jan 2018 12:50:07 +0000 Subject: [PATCH] Some TapeDevice serialization --- .../BizHawk.Emulation.Cores.csproj | 2 - .../Interfaces/ISupportsTapeBlockPlayback.cs | 6 +- .../SinclairSpectrum/Hardware/Tape.cs | 3 - .../Hardware/TapeBlockSetPlayer.cs | 53 ++++++++++-- .../Hardware/TapeDataBlockPlayer.cs | 81 ++++++++++++++++--- .../Hardware/TapeFilePlayer.cs | 13 ++- .../SinclairSpectrum/Machine/SpectrumBase.cs | 2 +- .../Media/Tape/TAP/TapDataBlock.cs | 17 +++- .../Media/Tape/TAP/TapPlayer.cs | 11 +++ .../Media/Tape/TZX/DataBlocks.cs | 26 +++++- .../Media/Tape/TZX/TzxPlayer.cs | 13 ++- .../SinclairSpectrum/ZXSpectrum.IEmulator.cs | 2 +- .../ZXSpectrum.ISoundProvider.cs | 14 ---- .../ZXSpectrum.IVideoProvider.cs | 13 --- .../Computers/SinclairSpectrum/ZXSpectrum.cs | 15 +--- 15 files changed, 204 insertions(+), 67 deletions(-) delete mode 100644 BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.ISoundProvider.cs delete mode 100644 BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IVideoProvider.cs diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj index 10ba63cfb3..ff25860ed9 100644 --- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj +++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj @@ -312,7 +312,6 @@ - @@ -1393,7 +1392,6 @@ - diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Interfaces/ISupportsTapeBlockPlayback.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Interfaces/ISupportsTapeBlockPlayback.cs index 969944fa92..8d1c47645b 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Interfaces/ISupportsTapeBlockPlayback.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Interfaces/ISupportsTapeBlockPlayback.cs @@ -1,4 +1,5 @@ -using System; +using BizHawk.Common; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -35,5 +36,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// The EAR bit value to play back /// bool GetEarBit(long currentCycle); + + + void SyncState(Serializer ser); } } diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Tape.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Tape.cs index 203fef91b2..fd29eb3855 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Tape.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/Tape.cs @@ -526,9 +526,6 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum ser.SyncEnum("_currentMode", ref _currentMode); ser.SyncEnum("_savePhase", ref _savePhase); ser.SyncEnum("_prevDataPulse", ref _prevDataPulse); - /* - private TapeFilePlayer _tapePlayer; - */ ser.EndSection(); } diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/TapeBlockSetPlayer.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/TapeBlockSetPlayer.cs index c08b488acf..6d5b149f9e 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/TapeBlockSetPlayer.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/TapeBlockSetPlayer.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using BizHawk.Common; +using System.Collections.Generic; namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { @@ -15,27 +16,56 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// /// Signs that the player completed playing back the file /// - public bool Eof { get; private set; } + private bool eof; + public bool Eof + { + get { return eof; } + set { eof = value; } + } + /// /// Gets the currently playing block's index /// - public int CurrentBlockIndex { get; private set; } + private int currentBlockIndex; + public int CurrentBlockIndex + { + get { return currentBlockIndex; } + set { currentBlockIndex = value; } + } /// /// The current playable block /// - public ISupportsTapeBlockPlayback CurrentBlock => DataBlocks[CurrentBlockIndex]; + private ISupportsTapeBlockPlayback currentBlock; + public ISupportsTapeBlockPlayback CurrentBlock + { + get { return DataBlocks[CurrentBlockIndex]; } + //set { currentBlock = value; } + } + /// /// The current playing phase /// - public PlayPhase PlayPhase { get; private set; } + private PlayPhase playPhase; + public PlayPhase PlayPhase + { + get { return playPhase; } + set { playPhase = value; } + } + /// /// The cycle count of the CPU when playing starts /// - public long StartCycle { get; private set; } + private long startCycle; + public long StartCycle + { + get { return startCycle; } + set { startCycle = value; } + } + public TapeBlockSetPlayer(List dataBlocks) { @@ -98,5 +128,16 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum CurrentBlockIndex++; CurrentBlock.InitPlay(currentCycle); } + + public void SyncState(Serializer ser) + { + ser.BeginSection("TapeBlockSetPlayer"); + ser.Sync("eof", ref eof); + ser.Sync("currentBlockIndex", ref currentBlockIndex); + ser.SyncEnum("playPhase", ref playPhase); + ser.Sync("startCycle", ref startCycle); + currentBlock.SyncState(ser); + ser.EndSection(); + } } } diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/TapeDataBlockPlayer.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/TapeDataBlockPlayer.cs index 547d7698b9..0c7dae4f14 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/TapeDataBlockPlayer.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/TapeDataBlockPlayer.cs @@ -1,4 +1,6 @@  +using BizHawk.Common; + namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { /// @@ -9,20 +11,28 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// /// Pause after this block (default: 1000ms) /// - public ushort PauseAfter { get; } + private ushort pauseAfter; + public ushort PauseAfter + { + get { return pauseAfter; } + } /// /// Block Data /// - public byte[] Data { get; } + private byte[] data; + public byte[] Data + { + get { return data; } + } /// /// Initializes a new instance /// - public TapeDataBlockPlayer(byte[] data, ushort pauseAfter) + public TapeDataBlockPlayer(byte[] _data, ushort _pauseAfter) { - PauseAfter = pauseAfter; - Data = data; + pauseAfter = _pauseAfter; + data = _data; } /// @@ -82,27 +92,52 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// /// The index of the currently playing byte /// - public int ByteIndex { get; private set; } + private int byteIndex; + public int ByteIndex + { + get { return byteIndex; } + set { byteIndex = value; } + } /// /// The mask of the currently playing bit in the current byte /// - public byte BitMask { get; private set; } + private byte bitMask; + public byte BitMask + { + get { return bitMask; } + set { bitMask = value; } + } /// /// The current playing phase /// - public PlayPhase PlayPhase { get; private set; } + private PlayPhase playPhase; + public PlayPhase PlayPhase + { + get { return playPhase; } + set { playPhase = value; } + } /// /// The cycle count of the CPU when playing starts /// - public long StartCycle { get; private set; } + private long startCycle; + public long StartCycle + { + get { return startCycle; } + set { startCycle = value; } + } /// /// Last cycle queried /// - public long LastCycle { get; private set; } + private long lastCycle; + public long LastCycle + { + get { return lastCycle; } + set { lastCycle = value; } + } /// /// Initializes the player @@ -214,5 +249,31 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum } return true; } + + + public void SyncState(Serializer ser) + { + ser.BeginSection("TapeDataBlockPlayer"); + + ser.Sync("pauseAfter", ref pauseAfter); + ser.Sync("data", ref data, false); + + ser.Sync("_pilotEnds", ref _pilotEnds); + ser.Sync("_sync1Ends", ref _sync1Ends); + ser.Sync("_sync2Ends", ref _sync2Ends); + ser.Sync("_bitStarts", ref _bitStarts); + ser.Sync("_bitPulseLength", ref _bitPulseLength); + ser.Sync("_currentBit", ref _currentBit); + ser.Sync("_termSyncEnds", ref _termSyncEnds); + ser.Sync("_pauseEnds", ref _pauseEnds); + + ser.Sync("byteIndex", ref byteIndex); + ser.Sync("bitMask", ref bitMask); + ser.SyncEnum("playPhase", ref playPhase); + ser.Sync("startCycle", ref startCycle); + ser.Sync("lastCycle", ref lastCycle); + + ser.EndSection(); + } } } diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/TapeFilePlayer.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/TapeFilePlayer.cs index 25c75df0f8..92c32dbc95 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/TapeFilePlayer.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/TapeFilePlayer.cs @@ -1,4 +1,5 @@ -using System; +using BizHawk.Common; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -13,6 +14,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { private readonly BinaryReader _reader; private TapeBlockSetPlayer _player; + private int _numberOfDataBlocks; /// /// Data blocks to play back @@ -113,5 +115,14 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// /// Tacts time to start the next block public void NextBlock(long currentCycle) => _player.NextBlock(currentCycle); + + public void SyncState(Serializer ser) + { + ser.BeginSection("TapeFilePlayer"); + ReadContent(); + ser.Sync("_numberOfDataBlocks", ref _numberOfDataBlocks); + _player.SyncState(ser); + ser.EndSection(); + } } } diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs index 516b7d4b4d..a67333aa03 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs @@ -142,7 +142,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // paint the buffer if needed if (ULADevice.needsPaint) ULADevice.UpdateScreenBuffer(ULADevice.FrameLength); - + BuzzerDevice.EndFrame(); TapeDevice.CPUFrameCompleted(); diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TAP/TapDataBlock.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TAP/TapDataBlock.cs index 3c4858b533..0682b32752 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TAP/TapDataBlock.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TAP/TapDataBlock.cs @@ -1,4 +1,5 @@  +using BizHawk.Common; using System.IO; namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum @@ -16,7 +17,12 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// /// Block Data /// - public byte[] Data { get; private set; } + private byte[] data; + public byte[] Data + { + get { return data; } + set { data = value; } + } /// /// Pause after this block (given in milliseconds) @@ -86,5 +92,14 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// The EAR bit value to play back /// public bool GetEarBit(long currentTact) => _player.GetEarBit(currentTact); + + public void SyncState(Serializer ser) + { + ser.BeginSection("TapDataBlock"); + + ser.Sync("data", ref data, false); + + ser.EndSection(); + } } } diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TAP/TapPlayer.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TAP/TapPlayer.cs index faa7d23c02..0c24566e37 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TAP/TapPlayer.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TAP/TapPlayer.cs @@ -1,4 +1,5 @@  +using BizHawk.Common; using System.Collections.Generic; using System.IO; using System.Linq; @@ -81,5 +82,15 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// /// Tacts time to start the next block public void NextBlock(long currentCycle) => _player.NextBlock(currentCycle); + + + public void SyncState(Serializer ser) + { + ser.BeginSection("TapePlayer"); + + _player.SyncState(ser); + + ser.EndSection(); + } } } diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TZX/DataBlocks.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TZX/DataBlocks.cs index 18ce828a09..cfd694d544 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TZX/DataBlocks.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TZX/DataBlocks.cs @@ -1,4 +1,5 @@  +using BizHawk.Common; using System.IO; namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum @@ -1144,12 +1145,23 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// /// Lenght of block data /// - public ushort DataLength { get; set; } + private ushort dataLength; + public ushort DataLength + { + get { return dataLength; } + set { dataLength = value; } + } /// /// Block Data /// - public byte[] Data { get; set; } + private byte[] data; + public byte[] Data + { + get { return data; } + set { data = value; } + } + /// /// The ID of the block @@ -1222,6 +1234,16 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// The EAR bit value to play back /// public bool GetEarBit(long currentCycle) => _player.GetEarBit(currentCycle); + + public void SyncState(Serializer ser) + { + ser.BeginSection("TzxStandardSpeedDataBlock"); + + ser.Sync("dataLength", ref dataLength); + ser.Sync("data", ref data, false); + + ser.EndSection(); + } } /// diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TZX/TzxPlayer.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TZX/TzxPlayer.cs index 55797b80df..a9ac846467 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TZX/TzxPlayer.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/TZX/TzxPlayer.cs @@ -1,4 +1,5 @@ -using System.IO; +using BizHawk.Common; +using System.IO; using System.Linq; namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum @@ -79,5 +80,15 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// /// Tacts time to start the next block public void NextBlock(long currentTact) => _player.NextBlock(currentTact); + + + public void SyncState(Serializer ser) + { + ser.BeginSection("TzxPlayer"); + + _player.SyncState(ser); + + ser.EndSection(); + } } } diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IEmulator.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IEmulator.cs index b7a1a07d82..8b10763146 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IEmulator.cs @@ -29,7 +29,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum public string SystemId => "ZXSpectrum"; - public bool DeterministicEmulation => false; + public bool DeterministicEmulation => true; public void ResetCounters() { diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.ISoundProvider.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.ISoundProvider.cs deleted file mode 100644 index 402b7f292d..0000000000 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.ISoundProvider.cs +++ /dev/null @@ -1,14 +0,0 @@ -using BizHawk.Emulation.Cores.Components; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum -{ - public partial class ZXSpectrum - { - private SoundProviderMixer SoundMixer; - } -} diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IVideoProvider.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IVideoProvider.cs deleted file mode 100644 index 073236a69d..0000000000 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IVideoProvider.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum -{ - /// - /// Main IVideoProvider implementation is inside the machine classes - /// This is just some helper functions - /// - public partial class ZXSpectrum - { - - } -} diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.cs index ac8fd29229..6694a7e97d 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.cs @@ -60,9 +60,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum break; default: throw new InvalidOperationException("Machine not yet emulated"); - } - - + } _cpu.MemoryCallbacks = MemoryCallbacks; @@ -84,14 +82,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum if (_machine.AYDevice != null) SoundMixer.AddSource(_machine.AYDevice); - //SoundMixer.DisableSource(_machine.BuzzerDevice); - - dcf = new DCFilter(SoundMixer, 1024); - - - + dcf = new DCFilter(SoundMixer, 256); ser.Register(dcf); - //ser.Register(_machine.AYDevice); @@ -108,11 +100,12 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum public IController _controller; private SpectrumBase _machine; + private SoundProviderMixer SoundMixer; + private DCFilter dcf; private byte[] _file; - public bool DiagRom = false; private byte[] GetFirmware(int length, params string[] names)