ZXHawk: 48k Interrupt, ULA tables and contention tweaked

This commit is contained in:
Asnivor 2018-06-08 11:07:16 +01:00
parent f33863126c
commit 403a1032d8
4 changed files with 22 additions and 55 deletions

View File

@ -98,6 +98,16 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
public int PortContentionOffset;
/// <summary>
/// Arbitrary offset for render table generation
/// </summary>
public int RenderTableOffset;
/// <summary>
/// The offset when return floating bus bytes
/// </summary>
public int FloatingBusOffset;
/// <summary>
/// The time in T-States for one scanline to complete
/// </summary>
@ -317,17 +327,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <param name="machineType"></param>
private void InitRenderer(MachineType machineType)
{
switch (machineType)
{
case MachineType.ZXSpectrum16:
case MachineType.ZXSpectrum48:
Offset = 0;
break;
}
for (var t = 0; t < _ula.FrameCycleLength; t++)
{
var tStateScreen = t + 1 + _ula.InterruptStartTime;
var tStateScreen = t + _ula.RenderTableOffset + _ula.InterruptStartTime;
if (tStateScreen < 0)
tStateScreen += _ula.FrameCycleLength;
@ -458,7 +460,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// calculate contention values
for (int t = 0; t < _ula.FrameCycleLength; t++)
{
int shifted = (t + 1) + _ula.InterruptStartTime + Offset;
int shifted = t + _ula.RenderTableOffset + _ula.InterruptStartTime;
if (shifted < 0)
shifted += _ula.FrameCycleLength;
shifted %= _ula.FrameCycleLength;
@ -482,46 +484,6 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
Renderer[t].ContentionValue = conPattern[pixByte];
}
// calculate floating bus values
for (int t = 0; t < _ula.FrameCycleLength; t++)
{
int shifted = (t + 10) + _ula.InterruptStartTime;
if (shifted < 0)
shifted += _ula.FrameCycleLength;
shifted %= _ula.FrameCycleLength;
Renderer[t].FloatingBusAddress = 0;
int line = shifted / _ula.ScanlineTime;
int pix = shifted % _ula.ScanlineTime;
if (line < _ula.FirstPaperLine || line >= (_ula.FirstPaperLine + 192))
{
Renderer[t].FloatingBusAddress = 0;
continue;
}
int scrPix = pix - _ula.FirstPaperTState;
if (scrPix < 0 || scrPix >= 128)
{
Renderer[t].FloatingBusAddress = 0;
continue;
}
int pixByte = scrPix % 8;
int chunk = scrPix % 16;
switch (chunk)
{
case 0:
case 2:
Renderer[t].FloatingBusAddress = CalculateByteAddress(scrPix, line);
break;
case 1:
case 3:
Renderer[t].FloatingBusAddress = CalculateAttributeAddress(scrPix, line);
break;
}
}
}
private ushort CalculateByteAddress(int x, int y)
@ -719,8 +681,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <returns></returns>
public void ReadFloatingBus(int tstate, ref int result)
{
int off = 0;
tstate += off;
tstate += FloatingBusOffset;
if (tstate >= RenderingTable.Renderer.Length)
tstate -= RenderingTable.Renderer.Length;
if (tstate < 0)

View File

@ -22,6 +22,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
MemoryContentionOffset = 5;
PortContentionOffset = 5;
RenderTableOffset = 1;
FloatingBusOffset = 1;
BorderLeftTime = 24;
BorderRightTime = 24;

View File

@ -22,6 +22,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
MemoryContentionOffset = 7;
PortContentionOffset = 7;
RenderTableOffset = 1;
FloatingBusOffset = 1;
BorderLeftTime = 24;
BorderRightTime = 24;

View File

@ -16,12 +16,14 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// timing
ClockSpeed = 3500000;
FrameCycleLength = 69888;
InterruptStartTime = 31;
InterruptStartTime = 30;
InterruptLength = 32;
ScanlineTime = 224;
MemoryContentionOffset = 5;
PortContentionOffset = 5;
MemoryContentionOffset = 6;
PortContentionOffset = 6;
RenderTableOffset = 2;
FloatingBusOffset = 1;
BorderLeftTime = 24;
BorderRightTime = 24;