using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
///
/// The abstract class that all emulated models will inherit from
/// * Port Access *
///
public abstract partial class SpectrumBase
{
///
/// The last OUT data that was sent to the ULA
///
protected byte LastULAOutByte;
///
/// Reads a byte of data from a specified port address
///
///
///
public abstract byte ReadPort(ushort port);
///
/// Writes a byte of data to a specified port address
///
///
///
public abstract void WritePort(ushort port, byte value);
///
/// Apply I/O contention if necessary
///
///
public virtual void ContendPort(ushort port)
{
var lowBit = (port & 0x0001) != 0;
var ulaHigh = (port & 0xc000) == 0x4000;
var cfc = CurrentFrameCycle;
if (cfc < 1)
cfc = 1;
if (ulaHigh)
{
CPU.TotalExecutedCycles += GetContentionValue(cfc - 1);
}
else
{
if (!lowBit)
CPU.TotalExecutedCycles += GetContentionValue(cfc);
}
}
}
}