Some TapeDevice serialization

This commit is contained in:
Asnivor 2018-01-15 12:50:07 +00:00
parent 3d508455ec
commit 1fb10f3d9c
15 changed files with 204 additions and 67 deletions

View File

@ -312,7 +312,6 @@
<Compile Include="Computers\SinclairSpectrum\ZXSpectrum.IInputPollable.cs" /> <Compile Include="Computers\SinclairSpectrum\ZXSpectrum.IInputPollable.cs" />
<Compile Include="Computers\SinclairSpectrum\ZXSpectrum.IMemoryDomains.cs" /> <Compile Include="Computers\SinclairSpectrum\ZXSpectrum.IMemoryDomains.cs" />
<Compile Include="Computers\SinclairSpectrum\ZXSpectrum.ISettable.cs" /> <Compile Include="Computers\SinclairSpectrum\ZXSpectrum.ISettable.cs" />
<Compile Include="Computers\SinclairSpectrum\ZXSpectrum.ISoundProvider.cs" />
<Compile Include="Computers\SinclairSpectrum\ZXSpectrum.IStatable.cs" /> <Compile Include="Computers\SinclairSpectrum\ZXSpectrum.IStatable.cs" />
<Compile Include="Computers\SinclairSpectrum\ZXSpectrum.Util.cs" /> <Compile Include="Computers\SinclairSpectrum\ZXSpectrum.Util.cs" />
<Compile Include="Consoles\Atari\2600\Atari2600.cs" /> <Compile Include="Consoles\Atari\2600\Atari2600.cs" />
@ -1393,7 +1392,6 @@
<Compile Include="Computers\SinclairSpectrum\Machine\ZXSpectrum48K\ZX48.Keyboard.cs" /> <Compile Include="Computers\SinclairSpectrum\Machine\ZXSpectrum48K\ZX48.Keyboard.cs" />
<Compile Include="Computers\SinclairSpectrum\Machine\ZXSpectrum48K\ZX48.Port.cs" /> <Compile Include="Computers\SinclairSpectrum\Machine\ZXSpectrum48K\ZX48.Port.cs" />
<None Include="Computers\SinclairSpectrum\readme.md" /> <None Include="Computers\SinclairSpectrum\readme.md" />
<Compile Include="Computers\SinclairSpectrum\ZXSpectrum.IVideoProvider.cs" />
<None Include="Consoles\Atari\docs\stella.pdf" /> <None Include="Consoles\Atari\docs\stella.pdf" />
<None Include="Consoles\Coleco\docs\colecovision tech1.pdf" /> <None Include="Consoles\Coleco\docs\colecovision tech1.pdf" />
<None Include="Consoles\Coleco\docs\colecovision tech2.pdf" /> <None Include="Consoles\Coleco\docs\colecovision tech2.pdf" />

View File

@ -1,4 +1,5 @@
using System; using BizHawk.Common;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -35,5 +36,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// The EAR bit value to play back /// The EAR bit value to play back
/// </returns> /// </returns>
bool GetEarBit(long currentCycle); bool GetEarBit(long currentCycle);
void SyncState(Serializer ser);
} }
} }

View File

@ -526,9 +526,6 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
ser.SyncEnum<TapeOperationMode>("_currentMode", ref _currentMode); ser.SyncEnum<TapeOperationMode>("_currentMode", ref _currentMode);
ser.SyncEnum<SavePhase>("_savePhase", ref _savePhase); ser.SyncEnum<SavePhase>("_savePhase", ref _savePhase);
ser.SyncEnum<MicPulseType>("_prevDataPulse", ref _prevDataPulse); ser.SyncEnum<MicPulseType>("_prevDataPulse", ref _prevDataPulse);
/*
private TapeFilePlayer _tapePlayer;
*/
ser.EndSection(); ser.EndSection();
} }

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using BizHawk.Common;
using System.Collections.Generic;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
@ -15,27 +16,56 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <summary> /// <summary>
/// Signs that the player completed playing back the file /// Signs that the player completed playing back the file
/// </summary> /// </summary>
public bool Eof { get; private set; } private bool eof;
public bool Eof
{
get { return eof; }
set { eof = value; }
}
/// <summary> /// <summary>
/// Gets the currently playing block's index /// Gets the currently playing block's index
/// </summary> /// </summary>
public int CurrentBlockIndex { get; private set; } private int currentBlockIndex;
public int CurrentBlockIndex
{
get { return currentBlockIndex; }
set { currentBlockIndex = value; }
}
/// <summary> /// <summary>
/// The current playable block /// The current playable block
/// </summary> /// </summary>
public ISupportsTapeBlockPlayback CurrentBlock => DataBlocks[CurrentBlockIndex]; private ISupportsTapeBlockPlayback currentBlock;
public ISupportsTapeBlockPlayback CurrentBlock
{
get { return DataBlocks[CurrentBlockIndex]; }
//set { currentBlock = value; }
}
/// <summary> /// <summary>
/// The current playing phase /// The current playing phase
/// </summary> /// </summary>
public PlayPhase PlayPhase { get; private set; } private PlayPhase playPhase;
public PlayPhase PlayPhase
{
get { return playPhase; }
set { playPhase = value; }
}
/// <summary> /// <summary>
/// The cycle count of the CPU when playing starts /// The cycle count of the CPU when playing starts
/// </summary> /// </summary>
public long StartCycle { get; private set; } private long startCycle;
public long StartCycle
{
get { return startCycle; }
set { startCycle = value; }
}
public TapeBlockSetPlayer(List<ISupportsTapeBlockPlayback> dataBlocks) public TapeBlockSetPlayer(List<ISupportsTapeBlockPlayback> dataBlocks)
{ {
@ -98,5 +128,16 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
CurrentBlockIndex++; CurrentBlockIndex++;
CurrentBlock.InitPlay(currentCycle); CurrentBlock.InitPlay(currentCycle);
} }
public void SyncState(Serializer ser)
{
ser.BeginSection("TapeBlockSetPlayer");
ser.Sync("eof", ref eof);
ser.Sync("currentBlockIndex", ref currentBlockIndex);
ser.SyncEnum<PlayPhase>("playPhase", ref playPhase);
ser.Sync("startCycle", ref startCycle);
currentBlock.SyncState(ser);
ser.EndSection();
}
} }
} }

View File

@ -1,4 +1,6 @@
 
using BizHawk.Common;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
/// <summary> /// <summary>
@ -9,20 +11,28 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <summary> /// <summary>
/// Pause after this block (default: 1000ms) /// Pause after this block (default: 1000ms)
/// </summary> /// </summary>
public ushort PauseAfter { get; } private ushort pauseAfter;
public ushort PauseAfter
{
get { return pauseAfter; }
}
/// <summary> /// <summary>
/// Block Data /// Block Data
/// </summary> /// </summary>
public byte[] Data { get; } private byte[] data;
public byte[] Data
{
get { return data; }
}
/// <summary> /// <summary>
/// Initializes a new instance /// Initializes a new instance
/// </summary> /// </summary>
public TapeDataBlockPlayer(byte[] data, ushort pauseAfter) public TapeDataBlockPlayer(byte[] _data, ushort _pauseAfter)
{ {
PauseAfter = pauseAfter; pauseAfter = _pauseAfter;
Data = data; data = _data;
} }
/// <summary> /// <summary>
@ -82,27 +92,52 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <summary> /// <summary>
/// The index of the currently playing byte /// The index of the currently playing byte
/// </summary> /// </summary>
public int ByteIndex { get; private set; } private int byteIndex;
public int ByteIndex
{
get { return byteIndex; }
set { byteIndex = value; }
}
/// <summary> /// <summary>
/// The mask of the currently playing bit in the current byte /// The mask of the currently playing bit in the current byte
/// </summary> /// </summary>
public byte BitMask { get; private set; } private byte bitMask;
public byte BitMask
{
get { return bitMask; }
set { bitMask = value; }
}
/// <summary> /// <summary>
/// The current playing phase /// The current playing phase
/// </summary> /// </summary>
public PlayPhase PlayPhase { get; private set; } private PlayPhase playPhase;
public PlayPhase PlayPhase
{
get { return playPhase; }
set { playPhase = value; }
}
/// <summary> /// <summary>
/// The cycle count of the CPU when playing starts /// The cycle count of the CPU when playing starts
/// </summary> /// </summary>
public long StartCycle { get; private set; } private long startCycle;
public long StartCycle
{
get { return startCycle; }
set { startCycle = value; }
}
/// <summary> /// <summary>
/// Last cycle queried /// Last cycle queried
/// </summary> /// </summary>
public long LastCycle { get; private set; } private long lastCycle;
public long LastCycle
{
get { return lastCycle; }
set { lastCycle = value; }
}
/// <summary> /// <summary>
/// Initializes the player /// Initializes the player
@ -214,5 +249,31 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
} }
return true; 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>("playPhase", ref playPhase);
ser.Sync("startCycle", ref startCycle);
ser.Sync("lastCycle", ref lastCycle);
ser.EndSection();
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; using BizHawk.Common;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -13,6 +14,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
private readonly BinaryReader _reader; private readonly BinaryReader _reader;
private TapeBlockSetPlayer _player; private TapeBlockSetPlayer _player;
private int _numberOfDataBlocks;
/// <summary> /// <summary>
/// Data blocks to play back /// Data blocks to play back
@ -113,5 +115,14 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary> /// </summary>
/// <param name="currentTact">Tacts time to start the next block</param> /// <param name="currentTact">Tacts time to start the next block</param>
public void NextBlock(long currentCycle) => _player.NextBlock(currentCycle); 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();
}
} }
} }

View File

@ -142,7 +142,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// paint the buffer if needed // paint the buffer if needed
if (ULADevice.needsPaint) if (ULADevice.needsPaint)
ULADevice.UpdateScreenBuffer(ULADevice.FrameLength); ULADevice.UpdateScreenBuffer(ULADevice.FrameLength);
BuzzerDevice.EndFrame(); BuzzerDevice.EndFrame();
TapeDevice.CPUFrameCompleted(); TapeDevice.CPUFrameCompleted();

View File

@ -1,4 +1,5 @@
 
using BizHawk.Common;
using System.IO; using System.IO;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
@ -16,7 +17,12 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <summary> /// <summary>
/// Block Data /// Block Data
/// </summary> /// </summary>
public byte[] Data { get; private set; } private byte[] data;
public byte[] Data
{
get { return data; }
set { data = value; }
}
/// <summary> /// <summary>
/// Pause after this block (given in milliseconds) /// Pause after this block (given in milliseconds)
@ -86,5 +92,14 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// The EAR bit value to play back /// The EAR bit value to play back
/// </returns> /// </returns>
public bool GetEarBit(long currentTact) => _player.GetEarBit(currentTact); public bool GetEarBit(long currentTact) => _player.GetEarBit(currentTact);
public void SyncState(Serializer ser)
{
ser.BeginSection("TapDataBlock");
ser.Sync("data", ref data, false);
ser.EndSection();
}
} }
} }

View File

@ -1,4 +1,5 @@
 
using BizHawk.Common;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -81,5 +82,15 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary> /// </summary>
/// <param name="currentCycle">Tacts time to start the next block</param> /// <param name="currentCycle">Tacts time to start the next block</param>
public void NextBlock(long currentCycle) => _player.NextBlock(currentCycle); public void NextBlock(long currentCycle) => _player.NextBlock(currentCycle);
public void SyncState(Serializer ser)
{
ser.BeginSection("TapePlayer");
_player.SyncState(ser);
ser.EndSection();
}
} }
} }

View File

@ -1,4 +1,5 @@
 
using BizHawk.Common;
using System.IO; using System.IO;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
@ -1144,12 +1145,23 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <summary> /// <summary>
/// Lenght of block data /// Lenght of block data
/// </summary> /// </summary>
public ushort DataLength { get; set; } private ushort dataLength;
public ushort DataLength
{
get { return dataLength; }
set { dataLength = value; }
}
/// <summary> /// <summary>
/// Block Data /// Block Data
/// </summary> /// </summary>
public byte[] Data { get; set; } private byte[] data;
public byte[] Data
{
get { return data; }
set { data = value; }
}
/// <summary> /// <summary>
/// The ID of the block /// The ID of the block
@ -1222,6 +1234,16 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// The EAR bit value to play back /// The EAR bit value to play back
/// </returns> /// </returns>
public bool GetEarBit(long currentCycle) => _player.GetEarBit(currentCycle); 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();
}
} }
/// <summary> /// <summary>

View File

@ -1,4 +1,5 @@
using System.IO; using BizHawk.Common;
using System.IO;
using System.Linq; using System.Linq;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
@ -79,5 +80,15 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary> /// </summary>
/// <param name="currentTact">Tacts time to start the next block</param> /// <param name="currentTact">Tacts time to start the next block</param>
public void NextBlock(long currentTact) => _player.NextBlock(currentTact); public void NextBlock(long currentTact) => _player.NextBlock(currentTact);
public void SyncState(Serializer ser)
{
ser.BeginSection("TzxPlayer");
_player.SyncState(ser);
ser.EndSection();
}
} }
} }

View File

@ -29,7 +29,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
public string SystemId => "ZXSpectrum"; public string SystemId => "ZXSpectrum";
public bool DeterministicEmulation => false; public bool DeterministicEmulation => true;
public void ResetCounters() public void ResetCounters()
{ {

View File

@ -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;
}
}

View File

@ -1,13 +0,0 @@
using System;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
/// <summary>
/// Main IVideoProvider implementation is inside the machine classes
/// This is just some helper functions
/// </summary>
public partial class ZXSpectrum
{
}
}

View File

@ -60,9 +60,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
break; break;
default: default:
throw new InvalidOperationException("Machine not yet emulated"); throw new InvalidOperationException("Machine not yet emulated");
} }
_cpu.MemoryCallbacks = MemoryCallbacks; _cpu.MemoryCallbacks = MemoryCallbacks;
@ -84,14 +82,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
if (_machine.AYDevice != null) if (_machine.AYDevice != null)
SoundMixer.AddSource(_machine.AYDevice); SoundMixer.AddSource(_machine.AYDevice);
//SoundMixer.DisableSource(_machine.BuzzerDevice); dcf = new DCFilter(SoundMixer, 256);
dcf = new DCFilter(SoundMixer, 1024);
ser.Register<ISoundProvider>(dcf); ser.Register<ISoundProvider>(dcf);
//ser.Register<ISoundProvider>(_machine.AYDevice);
@ -108,11 +100,12 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
public IController _controller; public IController _controller;
private SpectrumBase _machine; private SpectrumBase _machine;
private SoundProviderMixer SoundMixer;
private DCFilter dcf; private DCFilter dcf;
private byte[] _file; private byte[] _file;
public bool DiagRom = false; public bool DiagRom = false;
private byte[] GetFirmware(int length, params string[] names) private byte[] GetFirmware(int length, params string[] names)