Merge branch 'ZXHawk-new-ULA' of https://github.com/TASVideos/BizHawk into ZXHawk-new-ULA

This commit is contained in:
alyosha-tas 2018-06-01 15:21:14 -04:00
commit 1637ab3953
12 changed files with 224 additions and 14 deletions

View File

@ -263,6 +263,7 @@
<Compile Include="Computers\SinclairSpectrum\Hardware\SoundOuput\Beeper.cs" />
<Compile Include="Computers\SinclairSpectrum\Machine\CPUMonitor.cs" />
<Compile Include="Computers\SinclairSpectrum\Machine\ULA.cs" />
<Compile Include="Computers\SinclairSpectrum\Machine\ZXSpectrum128KPlus2a\ZX128Plus2a.Screen.cs" />
<Compile Include="Computers\SinclairSpectrum\Media\Disk\FloppyDisk.cs" />
<Compile Include="Computers\SinclairSpectrum\Hardware\Abstraction\IJoystick.cs" />
<Compile Include="Computers\SinclairSpectrum\Hardware\Abstraction\IPortIODevice.cs" />
@ -1437,6 +1438,7 @@
<Compile Include="Computers\SinclairSpectrum\Hardware\Input\StandardKeyboard.cs" />
<Compile Include="Computers\SinclairSpectrum\Machine\ZXSpectrum48K\ZX48.Port.cs" />
<Compile Include="Computers\SinclairSpectrum\Machine\ZXSpectrum48K\ZX48.Screen.cs" />
<Compile Include="Computers\SinclairSpectrum\Machine\ZXSpectrum128K\ZX128.Screen.cs" />
<None Include="Computers\SinclairSpectrum\readme.md" />
<Compile Include="Computers\SinclairSpectrum\Machine\SpectrumBase.Media.cs" />
<None Include="Consoles\Atari\docs\stella.pdf" />

View File

@ -39,12 +39,112 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// </summary>
public void Cycle()
{
if (portContending)
{
RunPortContention();
}
/*
else
{
// check for wait state on cycle that has just happened
// next cycle should be a read/write operation
if (cur_instr[instr_pntr] == Z80A.WAIT)
{
ushort addr = 0;
bool abort = false;
// identify the type of operation and get the targetted address
switch (cur_instr[instr_pntr + 1])
{
// op fetch
case Z80A.OP_F:
addr = RegPC;
break;
// read/writes
case Z80A.RD:
case Z80A.RD_INC:
case Z80A.WR:
case Z80A.WR_INC:
addr = (ushort)(_cpu.Regs[cur_instr[instr_pntr + 3]] | _cpu.Regs[cur_instr[instr_pntr + 4]] << 8);
break;
default:
abort = true;
break;
}
if (!abort)
{
// is the address in a potentially contended bank?
if (_machine.IsContended(addr))
{
// will the ULA be contending this address on the next cycle?
var delay = _machine.ULADevice.GetContentionValue((int)_machine.CurrentFrameCycle + 1);
_cpu.TotalExecutedCycles += delay;
}
}
}
}
*/
return;
// check for wait state on next cycle
// the cycle after that should be a read/write operation or op fetch
if (instr_pntr >= cur_instr.Length - 1)
{
// will overflow
return;
}
if (cur_instr[instr_pntr + 1] == Z80A.WAIT)
{
// return;
ushort addr = 0;
// identify the type of operation and get the targetted address
var op = cur_instr[instr_pntr + 2];
switch (op)
{
// op fetch
case Z80A.OP_F:
addr = (ushort)(RegPC);
if (_machine.IsContended(addr))
{
var delay = _machine.ULADevice.GetContentionValue((int)_machine.CurrentFrameCycle);
if (delay > 0)
{
_cpu.TotalExecutedCycles += delay;
_machine.ULADevice.RenderScreen((int)_machine.CurrentFrameCycle);
}
}
break;
// read/writes
case Z80A.RD:
case Z80A.RD_INC:
case Z80A.WR:
case Z80A.WR_INC:
case Z80A.I_RD:
case Z80A.I_WR:
addr = (ushort)(_cpu.Regs[cur_instr[instr_pntr + 4]] | _cpu.Regs[cur_instr[instr_pntr + 5]] << 8);
if (_machine.IsContended(addr))
{
var delay = _machine.ULADevice.GetContentionValue((int)_machine.CurrentFrameCycle);
if (delay > 0)
{
_cpu.TotalExecutedCycles += delay;
_machine.ULADevice.RenderScreen((int)_machine.CurrentFrameCycle);
}
}
break;
case Z80A.FTCH_DB:
break;
default:
break;
}
}
}
#region Port Contention
public int portContCounter = 0;
@ -78,6 +178,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
case MachineType.ZXSpectrum16:
case MachineType.ZXSpectrum48:
case MachineType.ZXSpectrum128:
case MachineType.ZXSpectrum128Plus2:
if ((lastPortAddr & 0xc000) == 0x4000)
highByte407f = true;
@ -160,10 +262,6 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
}
break;
case MachineType.ZXSpectrum128:
case MachineType.ZXSpectrum128Plus2:
break;
case MachineType.ZXSpectrum128Plus2a:
case MachineType.ZXSpectrum128Plus3:
break;

View File

@ -170,6 +170,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
ULADevice.CheckForInterrupt(CurrentFrameCycle);
// run a single CPU instruction
CPU.ExecuteOne();
CPUMon.Cycle();

View File

@ -176,7 +176,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <param name="addr"></param>
public override void ContendPort(ushort addr)
{
throw new NotImplementedException();
CPUMon.ContendPort(addr);
return;
}
}
}

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
class Screen128 : ULA
{
#region Construction
public Screen128(SpectrumBase machine)
: base(machine)
{
// timing
ClockSpeed = 3546900;
FrameCycleLength = 70908;
InterruptStartTime = 33;
InterruptLength = 36;
ScanlineTime = 228;
BorderLeftTime = 24;
BorderRightTime = 24;
FirstPaperLine = 63;
FirstPaperTState = 64;
Border4T = true;
Border4TStage = 2;
// screen layout
ScreenWidth = 256;
ScreenHeight = 192;
BorderTopHeight = 48;
BorderBottomHeight = 56;
BorderLeftWidth = 48;
BorderRightWidth = 48;
ScanLineWidth = BorderLeftWidth + ScreenWidth + BorderRightWidth;
RenderingTable = new RenderTable(this,
MachineType.ZXSpectrum128);
SetupScreenSize();
}
#endregion
}
}

View File

@ -30,7 +30,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
PagingDisabled = false;
//ULADevice = new ULA128(this);
ULADevice = new Screen48(this); // still todo
ULADevice = new Screen128(this); // still todo
BuzzerDevice = new Beeper(this);
BuzzerDevice.Init(44100, ULADevice.FrameLength);

View File

@ -289,7 +289,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <param name="addr"></param>
public override void ContendPort(ushort addr)
{
throw new NotImplementedException();
CPUMon.ContendPort(addr);
return;
}
}
}

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
class Screen128Plus2a : ULA
{
#region Construction
public Screen128Plus2a(SpectrumBase machine)
: base(machine)
{
// timing
ClockSpeed = 3546900;
FrameCycleLength = 70908;
InterruptStartTime = 33;
InterruptLength = 32;
ScanlineTime = 228;
BorderLeftTime = 24;
BorderRightTime = 24;
FirstPaperLine = 63;
FirstPaperTState = 64;
Border4T = true;
Border4TStage = 2;
// screen layout
ScreenWidth = 256;
ScreenHeight = 192;
BorderTopHeight = 48;
BorderBottomHeight = 56;
BorderLeftWidth = 48;
BorderRightWidth = 48;
ScanLineWidth = BorderLeftWidth + ScreenWidth + BorderRightWidth;
RenderingTable = new RenderTable(this,
MachineType.ZXSpectrum128Plus2a);
SetupScreenSize();
}
#endregion
}
}

View File

@ -30,7 +30,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
PagingDisabled = false;
//ULADevice = new ULAPlus2a(this);
ULADevice = new Screen48(this); // still todo
ULADevice = new Screen128Plus2a(this); // still todo
BuzzerDevice = new Beeper(this);
BuzzerDevice.Init(44100, ULADevice.FrameLength);

View File

@ -224,7 +224,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// <param name="addr"></param>
public override void ContendPort(ushort addr)
{
throw new NotImplementedException();
CPUMon.ContendPort(addr);
return;
}
}
}

View File

@ -20,9 +20,10 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
Spectrum = spectrum;
CPU = cpu;
CPUMon.machineType = MachineType.ZXSpectrum128Plus3;
CPUMon = new CPUMonitor(this);
CPUMon.machineType = MachineType.ZXSpectrum128Plus3;
ROMPaged = 0;
SHADOWPaged = false;
@ -30,7 +31,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
PagingDisabled = false;
// ULADevice = new ULAPlus3(this);
ULADevice = new Screen48(this); // still todo
ULADevice = new Screen128Plus2a(this); // still todo
BuzzerDevice = new Beeper(this);
BuzzerDevice.Init(44100, ULADevice.FrameLength);

View File

@ -124,7 +124,14 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
if (IsContended(addr))
{
var delay = ULADevice.GetContentionValue((int)CurrentFrameCycle);
var off = 1;
var offset = CurrentFrameCycle + off;
if (offset < 0)
offset += ULADevice.FrameCycleLength;
if (offset >= ULADevice.FrameCycleLength)
offset -= ULADevice.FrameCycleLength;
var delay = ULADevice.GetContentionValue((int)offset);
if (delay > 0)
{