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.IMemoryDomains.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.Util.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.Port.cs" />
<None Include="Computers\SinclairSpectrum\readme.md" />
<Compile Include="Computers\SinclairSpectrum\ZXSpectrum.IVideoProvider.cs" />
<None Include="Consoles\Atari\docs\stella.pdf" />
<None Include="Consoles\Coleco\docs\colecovision tech1.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.Linq;
using System.Text;
@ -35,5 +36,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// The EAR bit value to play back
/// </returns>
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<SavePhase>("_savePhase", ref _savePhase);
ser.SyncEnum<MicPulseType>("_prevDataPulse", ref _prevDataPulse);
/*
private TapeFilePlayer _tapePlayer;
*/
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
{
@ -15,27 +16,56 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <summary>
/// Signs that the player completed playing back the file
/// </summary>
public bool Eof { get; private set; }
private bool eof;
public bool Eof
{
get { return eof; }
set { eof = value; }
}
/// <summary>
/// Gets the currently playing block's index
/// </summary>
public int CurrentBlockIndex { get; private set; }
private int currentBlockIndex;
public int CurrentBlockIndex
{
get { return currentBlockIndex; }
set { currentBlockIndex = value; }
}
/// <summary>
/// The current playable block
/// </summary>
public ISupportsTapeBlockPlayback CurrentBlock => DataBlocks[CurrentBlockIndex];
private ISupportsTapeBlockPlayback currentBlock;
public ISupportsTapeBlockPlayback CurrentBlock
{
get { return DataBlocks[CurrentBlockIndex]; }
//set { currentBlock = value; }
}
/// <summary>
/// The current playing phase
/// </summary>
public PlayPhase PlayPhase { get; private set; }
private PlayPhase playPhase;
public PlayPhase PlayPhase
{
get { return playPhase; }
set { playPhase = value; }
}
/// <summary>
/// The cycle count of the CPU when playing starts
/// </summary>
public long StartCycle { get; private set; }
private long startCycle;
public long StartCycle
{
get { return startCycle; }
set { startCycle = value; }
}
public TapeBlockSetPlayer(List<ISupportsTapeBlockPlayback> 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>("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
{
/// <summary>
@ -9,20 +11,28 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <summary>
/// Pause after this block (default: 1000ms)
/// </summary>
public ushort PauseAfter { get; }
private ushort pauseAfter;
public ushort PauseAfter
{
get { return pauseAfter; }
}
/// <summary>
/// Block Data
/// </summary>
public byte[] Data { get; }
private byte[] data;
public byte[] Data
{
get { return data; }
}
/// <summary>
/// Initializes a new instance
/// </summary>
public TapeDataBlockPlayer(byte[] data, ushort pauseAfter)
public TapeDataBlockPlayer(byte[] _data, ushort _pauseAfter)
{
PauseAfter = pauseAfter;
Data = data;
pauseAfter = _pauseAfter;
data = _data;
}
/// <summary>
@ -82,27 +92,52 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <summary>
/// The index of the currently playing byte
/// </summary>
public int ByteIndex { get; private set; }
private int byteIndex;
public int ByteIndex
{
get { return byteIndex; }
set { byteIndex = value; }
}
/// <summary>
/// The mask of the currently playing bit in the current byte
/// </summary>
public byte BitMask { get; private set; }
private byte bitMask;
public byte BitMask
{
get { return bitMask; }
set { bitMask = value; }
}
/// <summary>
/// The current playing phase
/// </summary>
public PlayPhase PlayPhase { get; private set; }
private PlayPhase playPhase;
public PlayPhase PlayPhase
{
get { return playPhase; }
set { playPhase = value; }
}
/// <summary>
/// The cycle count of the CPU when playing starts
/// </summary>
public long StartCycle { get; private set; }
private long startCycle;
public long StartCycle
{
get { return startCycle; }
set { startCycle = value; }
}
/// <summary>
/// Last cycle queried
/// </summary>
public long LastCycle { get; private set; }
private long lastCycle;
public long LastCycle
{
get { return lastCycle; }
set { lastCycle = value; }
}
/// <summary>
/// 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>("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.IO;
using System.Linq;
@ -13,6 +14,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
private readonly BinaryReader _reader;
private TapeBlockSetPlayer _player;
private int _numberOfDataBlocks;
/// <summary>
/// Data blocks to play back
@ -113,5 +115,14 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
/// <param name="currentTact">Tacts time to start the next block</param>
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
if (ULADevice.needsPaint)
ULADevice.UpdateScreenBuffer(ULADevice.FrameLength);
BuzzerDevice.EndFrame();
TapeDevice.CPUFrameCompleted();

View File

@ -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
/// <summary>
/// Block Data
/// </summary>
public byte[] Data { get; private set; }
private byte[] data;
public byte[] Data
{
get { return data; }
set { data = value; }
}
/// <summary>
/// Pause after this block (given in milliseconds)
@ -86,5 +92,14 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// The EAR bit value to play back
/// </returns>
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.IO;
using System.Linq;
@ -81,5 +82,15 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
/// <param name="currentCycle">Tacts time to start the next block</param>
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;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
@ -1144,12 +1145,23 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <summary>
/// Lenght of block data
/// </summary>
public ushort DataLength { get; set; }
private ushort dataLength;
public ushort DataLength
{
get { return dataLength; }
set { dataLength = value; }
}
/// <summary>
/// Block Data
/// </summary>
public byte[] Data { get; set; }
private byte[] data;
public byte[] Data
{
get { return data; }
set { data = value; }
}
/// <summary>
/// The ID of the block
@ -1222,6 +1234,16 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// The EAR bit value to play back
/// </returns>
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>

View File

@ -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
/// </summary>
/// <param name="currentTact">Tacts time to start the next block</param>
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 bool DeterministicEmulation => false;
public bool DeterministicEmulation => true;
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;
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<ISoundProvider>(dcf);
//ser.Register<ISoundProvider>(_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)