LagFrame implementation

This commit is contained in:
Asnivor 2018-03-06 17:57:13 +00:00
parent 36485bba8a
commit 198008a573
7 changed files with 80 additions and 2 deletions

View File

@ -204,6 +204,11 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
return JoystickCollection.Where(a => a.JoyType == type).FirstOrDefault(); return JoystickCollection.Where(a => a.JoyType == type).FirstOrDefault();
} }
/// <summary>
/// Signs whether input read has been requested
/// </summary>
protected bool InputRead { get; set; }
} }
} }

View File

@ -140,6 +140,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary> /// </summary>
public virtual void ExecuteFrame() public virtual void ExecuteFrame()
{ {
InputRead = false;
FrameCompleted = false; FrameCompleted = false;
BuzzerDevice.StartFrame(); BuzzerDevice.StartFrame();
if (AYDevice != null) if (AYDevice != null)
@ -179,6 +181,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
TapeDevice.EndFrame(); TapeDevice.EndFrame();
FrameCompleted = true; FrameCompleted = true;
// is this a lag frame?
Spectrum.IsLagFrame = !InputRead;
} }
/// <summary> /// <summary>

View File

@ -15,6 +15,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <returns></returns> /// <returns></returns>
public override byte ReadPort(ushort port) public override byte ReadPort(ushort port)
{ {
InputRead = true;
int result = 0xFF; int result = 0xFF;
// Check whether the low bit is reset // Check whether the low bit is reset
@ -29,6 +31,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
if (LocateUniqueJoystick(JoystickType.Kempston) != null) if (LocateUniqueJoystick(JoystickType.Kempston) != null)
return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston) as KempstonJoystick).JoyLine; return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston) as KempstonJoystick).JoyLine;
InputRead = true;
} }
else if (lowBitReset) else if (lowBitReset)
{ {
@ -43,28 +47,45 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
*/ */
if ((port & 0x8000) == 0) if ((port & 0x8000) == 0)
{
result &= KeyboardDevice.KeyLine[7]; result &= KeyboardDevice.KeyLine[7];
}
if ((port & 0x4000) == 0) if ((port & 0x4000) == 0)
{
result &= KeyboardDevice.KeyLine[6]; result &= KeyboardDevice.KeyLine[6];
}
if ((port & 0x2000) == 0) if ((port & 0x2000) == 0)
{
result &= KeyboardDevice.KeyLine[5]; result &= KeyboardDevice.KeyLine[5];
}
if ((port & 0x1000) == 0) if ((port & 0x1000) == 0)
{
result &= KeyboardDevice.KeyLine[4]; result &= KeyboardDevice.KeyLine[4];
}
if ((port & 0x800) == 0) if ((port & 0x800) == 0)
{
result &= KeyboardDevice.KeyLine[3]; result &= KeyboardDevice.KeyLine[3];
}
if ((port & 0x400) == 0) if ((port & 0x400) == 0)
{
result &= KeyboardDevice.KeyLine[2]; result &= KeyboardDevice.KeyLine[2];
}
if ((port & 0x200) == 0) if ((port & 0x200) == 0)
{
result &= KeyboardDevice.KeyLine[1]; result &= KeyboardDevice.KeyLine[1];
}
if ((port & 0x100) == 0) if ((port & 0x100) == 0)
{
result &= KeyboardDevice.KeyLine[0]; result &= KeyboardDevice.KeyLine[0];
}
result = result & 0x1f; //mask out lower 4 bits result = result & 0x1f; //mask out lower 4 bits
result = result | 0xa0; //set bit 5 & 7 to 1 result = result | 0xa0; //set bit 5 & 7 to 1

View File

@ -15,6 +15,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <returns></returns> /// <returns></returns>
public override byte ReadPort(ushort port) public override byte ReadPort(ushort port)
{ {
InputRead = true;
int result = 0xFF; int result = 0xFF;
// Check whether the low bit is reset // Check whether the low bit is reset
@ -28,6 +30,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
if (LocateUniqueJoystick(JoystickType.Kempston) != null) if (LocateUniqueJoystick(JoystickType.Kempston) != null)
return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston) as KempstonJoystick).JoyLine; return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston) as KempstonJoystick).JoyLine;
InputRead = true;
} }
else if (lowBitReset) else if (lowBitReset)
{ {
@ -42,28 +46,44 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
*/ */
if ((port & 0x8000) == 0) if ((port & 0x8000) == 0)
{
result &= KeyboardDevice.KeyLine[7]; result &= KeyboardDevice.KeyLine[7];
}
if ((port & 0x4000) == 0) if ((port & 0x4000) == 0)
{
result &= KeyboardDevice.KeyLine[6]; result &= KeyboardDevice.KeyLine[6];
}
if ((port & 0x2000) == 0) if ((port & 0x2000) == 0)
{
result &= KeyboardDevice.KeyLine[5]; result &= KeyboardDevice.KeyLine[5];
}
if ((port & 0x1000) == 0) if ((port & 0x1000) == 0)
{
result &= KeyboardDevice.KeyLine[4]; result &= KeyboardDevice.KeyLine[4];
}
if ((port & 0x800) == 0) if ((port & 0x800) == 0)
{
result &= KeyboardDevice.KeyLine[3]; result &= KeyboardDevice.KeyLine[3];
}
if ((port & 0x400) == 0) if ((port & 0x400) == 0)
{
result &= KeyboardDevice.KeyLine[2]; result &= KeyboardDevice.KeyLine[2];
}
if ((port & 0x200) == 0) if ((port & 0x200) == 0)
{
result &= KeyboardDevice.KeyLine[1]; result &= KeyboardDevice.KeyLine[1];
}
if ((port & 0x100) == 0) if ((port & 0x100) == 0)
{
result &= KeyboardDevice.KeyLine[0]; result &= KeyboardDevice.KeyLine[0];
}
result = result & 0x1f; //mask out lower 4 bits result = result & 0x1f; //mask out lower 4 bits
result = result | 0xa0; //set bit 5 & 7 to 1 result = result | 0xa0; //set bit 5 & 7 to 1

View File

@ -15,6 +15,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <returns></returns> /// <returns></returns>
public override byte ReadPort(ushort port) public override byte ReadPort(ushort port)
{ {
InputRead = true;
int result = 0xFF; int result = 0xFF;
// Check whether the low bit is reset // Check whether the low bit is reset
@ -28,6 +30,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
if (LocateUniqueJoystick(JoystickType.Kempston) != null) if (LocateUniqueJoystick(JoystickType.Kempston) != null)
return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston) as KempstonJoystick).JoyLine; return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston) as KempstonJoystick).JoyLine;
InputRead = true;
} }
else if (lowBitReset) else if (lowBitReset)
{ {
@ -44,28 +48,44 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
*/ */
if ((port & 0x8000) == 0) if ((port & 0x8000) == 0)
{
result &= KeyboardDevice.KeyLine[7]; result &= KeyboardDevice.KeyLine[7];
}
if ((port & 0x4000) == 0) if ((port & 0x4000) == 0)
{
result &= KeyboardDevice.KeyLine[6]; result &= KeyboardDevice.KeyLine[6];
}
if ((port & 0x2000) == 0) if ((port & 0x2000) == 0)
{
result &= KeyboardDevice.KeyLine[5]; result &= KeyboardDevice.KeyLine[5];
}
if ((port & 0x1000) == 0) if ((port & 0x1000) == 0)
{
result &= KeyboardDevice.KeyLine[4]; result &= KeyboardDevice.KeyLine[4];
}
if ((port & 0x800) == 0) if ((port & 0x800) == 0)
{
result &= KeyboardDevice.KeyLine[3]; result &= KeyboardDevice.KeyLine[3];
}
if ((port & 0x400) == 0) if ((port & 0x400) == 0)
{
result &= KeyboardDevice.KeyLine[2]; result &= KeyboardDevice.KeyLine[2];
}
if ((port & 0x200) == 0) if ((port & 0x200) == 0)
{
result &= KeyboardDevice.KeyLine[1]; result &= KeyboardDevice.KeyLine[1];
}
if ((port & 0x100) == 0) if ((port & 0x100) == 0)
{
result &= KeyboardDevice.KeyLine[0]; result &= KeyboardDevice.KeyLine[0];
}
result = result & 0x1f; //mask out lower 4 bits result = result & 0x1f; //mask out lower 4 bits
result = result | 0xa0; //set bit 5 & 7 to 1 result = result | 0xa0; //set bit 5 & 7 to 1

View File

@ -13,6 +13,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
_controller = controller; _controller = controller;
_isLag = true;
if (_tracer.Enabled) if (_tracer.Enabled)
{ {
_cpu.TraceCallback = s => _tracer.Put(s); _cpu.TraceCallback = s => _tracer.Put(s);
@ -23,6 +25,11 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
} }
_machine.ExecuteFrame(); _machine.ExecuteFrame();
if (_isLag)
{
_lagCount++;
}
} }
public int Frame => _machine.FrameCount; public int Frame => _machine.FrameCount;

View File

@ -21,6 +21,6 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
public IInputCallbackSystem InputCallbacks { get; } public IInputCallbackSystem InputCallbacks { get; }
private int _lagCount = 0; private int _lagCount = 0;
private bool _isLag = true; private bool _isLag = false;
} }
} }