ZXHawk: Fixed auto-tape traps (now working properly for all games tested so far)

This commit is contained in:
Asnivor 2018-03-21 14:23:41 +00:00
parent 752bd0e35b
commit c2d3a42a69
6 changed files with 91 additions and 23 deletions

View File

@ -691,7 +691,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
_monitorCount++;
if (_monitorCount >= 16 && _cpu.RegPC == 1523 && _machine.Spectrum.Settings.AutoLoadTape)
if (_monitorCount >= 16 && _machine.Spectrum.Settings.AutoLoadTape)
{
if (!_tapeIsPlaying)
{
@ -714,7 +714,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
public void AutoStopTape()
{
if (_tapeIsPlaying)
if (!_tapeIsPlaying)
return;
if (!_machine.Spectrum.Settings.AutoLoadTape)
@ -749,6 +749,29 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
//Stop();
//_machine.Spectrum.OSD_TapeStoppedAuto();
}
// number of t-states since last IN operation
long diff = _machine.CPU.TotalExecutedCycles - _lastINCycle;
// pause in ms at the end of the current block
int blockPause = DataBlocks[_currentDataBlockIndex].PauseInMS;
// timeout in t-states (equiv. to blockpause)
int timeout = ((_machine.ULADevice.FrameLength * 50) / 1000) * blockPause;
// dont use autostop detection if block has no pause at the end
if (timeout == 0)
return;
if (diff >= timeout * 2)
{
// There have been no attempted tape reads by the CPU within the double timeout period
// Autostop the tape
AutoStopTape();
_lastCycle = _cpu.TotalExecutedCycles;
MonitorReset();
}
}
}

View File

@ -188,21 +188,21 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// THE 'ERROR' RESTART
if (addr == 8)
{
TapeDevice?.AutoStopTape();
//TapeDevice?.AutoStopTape();
return;
}
// THE 'ED-ERROR' SUBROUTINE
if (addr == 4223)
{
TapeDevice?.AutoStopTape();
//TapeDevice?.AutoStopTape();
return;
}
// THE 'ERROR-2' ROUTINE
if (addr == 83)
{
TapeDevice?.AutoStopTape();
//TapeDevice?.AutoStopTape();
return;
}
@ -218,14 +218,14 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// THE 'LD-BYTES' SUBROUTINE
if (addr == 1366)
{
TapeDevice?.AutoStartTape();
//TapeDevice?.AutoStartTape();
return;
}
// THE 'LD-EDGE-2' AND 'LD-EDGE-1' SUBROUTINES
if (addr == 1507)
{
TapeDevice?.AutoStartTape();
//TapeDevice?.AutoStartTape();
return;
}
}

View File

@ -154,22 +154,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
ULADevice.CheckForInterrupt(CurrentFrameCycle);
// run a single CPU instruction
CPU.ExecuteOne();
// update AY
int ayCnt = 0;
if (_renderSound)
{
if (AYDevice != null)
{
//AYDevice.UpdateSound(CurrentFrameCycle);
if (ayCnt > 10)
{
//AYDevice.UpdateSound(CurrentFrameCycle);
ayCnt = 0;
}
}
}
CPU.ExecuteOne();
}
// we have reached the end of a frame

View File

@ -288,6 +288,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
int actualPause = PAUSE_MS * 1000;
dataPeriods.Add(actualPause);
// default pause for tap files
tdb.PauseInMS = 1000;
// add to the tapedatablock object
tdb.DataPeriods = dataPeriods;

View File

@ -126,6 +126,17 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
set { _command = value; }
}
/// <summary>
/// The defined post-block pause
/// </summary>
private int _pauseInMS;
public int PauseInMS
{
get { return _pauseInMS; }
set { _pauseInMS = value; }
}
/// <summary>
/// Returns the data periods as an array
/// (primarily to aid in bizhawk state serialization)

View File

@ -270,6 +270,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
int pauseLen = GetWordValue(data, _position);
if (pauseLen == 0)
pauseLen = 1000;
t.PauseInMS = pauseLen;
int blockLen = GetWordValue(data, _position + 2);
_position += 4;
@ -331,6 +334,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
var t2 = DecodeDataBlock(t, tmp, DataBlockType.Turbo, pause, pilotTL, pilotPL, sync1P, sync2P, bit0P, bit1P, bitinbyte);
t.PauseInMS = pause;
// add the block
_datacorder.DataBlocks.Add(t2);
@ -355,6 +360,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
t.BlockID = 0x12;
t.BlockDescription = BlockType.Pure_Tone;
t.DataPeriods = new List<int>();
t.PauseInMS = 0;
// get values
int pulseLength = GetWordValue(data, _position);
@ -392,6 +398,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
t.BlockDescription = BlockType.Pulse_Sequence;
t.DataPeriods = new List<int>();
t.PauseInMS = 0;
// get pulse count
int pulseCount = data[_position];
t.AddMetaData(BlockDescriptorTitle.Pulse_Count, pulseCount.ToString());
@ -449,6 +457,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
var t2 = DecodeDataBlock(t, tmp, DataBlockType.Pure, pause, pilotTL, pilotPL, sync1P, sync2P, bit0P, bit1P, bitinbyte);
t.PauseInMS = pause;
// add the block
_datacorder.DataBlocks.Add(t2);
@ -549,6 +559,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
t.DataPeriods.Add(3500 * pauseAfterBlock);
}
t.PauseInMS = pauseAfterBlock;
// increment position
_position++;
@ -673,6 +685,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
//t.BlockDescription = "[STOP THE TAPE]";
}
t.PauseInMS = pauseDuration;
if (pauseDuration == 0)
{
// issue stop the tape command
@ -722,11 +736,15 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
//t.BlockDescription = "[GROUP: " + name + "]";
t.Command = TapeCommand.BEGIN_GROUP;
t.PauseInMS = 0;
// add to tape
_datacorder.DataBlocks.Add(t);
// advance to next block
_position += nameLength;
;
}
#endregion
@ -742,6 +760,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
t.BlockDescription = BlockType.Group_End;
t.Command = TapeCommand.END_GROUP;
t.PauseInMS = 0;
// add to tape
_datacorder.DataBlocks.Add(t);
}
@ -787,6 +807,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
//t.BlockDescription = "[JUMP BLOCK - " + result +"]";
t.PauseInMS = 0;
// add to tape
_datacorder.DataBlocks.Add(t);
@ -824,6 +846,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// update description
//t.BlockDescription = "[LOOP START - " + numberOfRepetitions + " times]";
t.PauseInMS = 0;
// add to tape
_datacorder.DataBlocks.Add(t);
@ -899,6 +923,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
t.BlockDescription = BlockType.Call_Sequence;
int blockSize = 2 + 2 * GetWordValue(data, _position);
t.PauseInMS = 0;
// add to tape
_datacorder.DataBlocks.Add(t);
@ -921,6 +947,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
t.BlockID = 0x27;
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Return_From_Sequence;
t.PauseInMS = 0;
// add to tape
_datacorder.DataBlocks.Add(t);
@ -956,6 +984,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
int blockSize = 2 + GetWordValue(data, _position);
t.PauseInMS = 0;
// add to tape
_datacorder.DataBlocks.Add(t);
@ -982,6 +1012,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
int blockSize = 4 + GetWordValue(data, _position);
t.PauseInMS = 0;
// add to tape
_datacorder.DataBlocks.Add(t);
@ -1005,6 +1037,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Set_Signal_Level;
t.PauseInMS = 0;
// add to tape
_datacorder.DataBlocks.Add(t);
@ -1037,6 +1071,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
string desc = Encoding.ASCII.GetString(data, _position, textLen);
t.PauseInMS = 0;
//t.BlockDescription = "[" + desc + "]";
// add to tape
@ -1081,6 +1117,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
//t.BlockDescription = "[MESSAGE: " + desc + "]";
t.PauseInMS = 0;
// add to tape
_datacorder.DataBlocks.Add(t);
@ -1186,6 +1224,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
string val = Encoding.ASCII.GetString(data, _position, strLen);
//t.BlockDescription += val + " \n";
t.PauseInMS = 0;
// advance to next string block
_position += strLen;
}
@ -1232,6 +1272,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Hardware_Type;
t.PauseInMS = 0;
_position += 2;
int blockLen = GetWordValue(data, 0);
@ -1259,6 +1301,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Custom_Info_Block;
t.PauseInMS = 0;
string info = Encoding.ASCII.GetString(data, _position, 0x10);
//t.BlockDescription = "[CUSTOM INFO: " + info + "]";
_position += 0x10;
@ -1292,6 +1336,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
t.DataPeriods = new List<int>();
t.BlockDescription = BlockType.Glue_Block;
t.PauseInMS = 0;
// add to tape
_datacorder.DataBlocks.Add(t);