Port access in Intel processors is 16 rather than 8 bit addressed

This commit is contained in:
Adrian Conlon
2025-05-08 13:00:30 +01:00
parent eda9519068
commit 9e0006187e
5 changed files with 20 additions and 17 deletions
+12 -8
View File
@@ -6,8 +6,8 @@ namespace EightBit
{
public sealed class InputOutput
{
private readonly byte[] _input = new byte[0x100];
private readonly byte[] _output = new byte[0x100];
private readonly byte[] _input = new byte[0x10000];
private readonly byte[] _output = new byte[0x10000];
public event EventHandler<PortEventArgs>? ReadingPort;
@@ -17,11 +17,15 @@ namespace EightBit
public event EventHandler<PortEventArgs>? WrittenPort;
public byte Read(byte port) => this.ReadInputPort(port);
public byte Read(ushort port) => this.ReadInputPort(port);
public void Write(byte port, byte value) => this.WriteOutputPort(port, value);
public byte Read(Register16 port) => this.Read(port.Word);
public byte ReadInputPort(byte port)
public void Write(ushort port, byte value) => this.WriteOutputPort(port, value);
public void Write(Register16 port, byte value) => this.Write(port.Word, value);
public byte ReadInputPort(ushort port)
{
ReadingPort?.Invoke(this, new PortEventArgs(port));
var value = this._input[port];
@@ -29,11 +33,11 @@ namespace EightBit
return value;
}
public void WriteInputPort(byte port, byte value) => this._input[port] = value;
public void WriteInputPort(ushort port, byte value) => this._input[port] = value;
public byte ReadOutputPort(byte port) => this._output[port];
public byte ReadOutputPort(ushort port) => this._output[port];
public void WriteOutputPort(byte port, byte value)
public void WriteOutputPort(ushort port, byte value)
{
WritingPort?.Invoke(this, new PortEventArgs(port));
this._output[port] = value;
+2 -2
View File
@@ -4,8 +4,8 @@
namespace EightBit
{
public sealed class PortEventArgs(byte value) : EventArgs
public sealed class PortEventArgs(ushort value) : EventArgs
{
public byte Port { get; } = value;
public ushort Port { get; } = value;
}
}
+2 -2
View File
@@ -773,7 +773,7 @@ namespace Intel8080
this.WritePort();
}
private void WritePort() => this.ports.Write(this.Bus.Address.Low, this.Bus.Data);
private void WritePort() => this.ports.Write(this.Bus.Address, this.Bus.Data);
private byte ReadPort(byte port)
{
@@ -781,6 +781,6 @@ namespace Intel8080
return this.ReadPort();
}
private byte ReadPort() => this.Bus.Data = this.ports.Read(this.Bus.Address.Low);
private byte ReadPort() => this.Bus.Data = this.ports.Read(this.Bus.Address);
}
}
+2 -3
View File
@@ -410,15 +410,14 @@
foreach (var port in ports)
{
var address = new Register16(port.Address).Low;
var value = port.Value;
if (port.Type == "r")
{
cpu.Ports.WriteInputPort(address, value);
cpu.Ports.WriteInputPort(port.Address, value);
}
else if (port.Type == "w")
{
cpu.Ports.WriteOutputPort(address, value);
cpu.Ports.WriteOutputPort(port.Address, value);
}
else
{
+2 -2
View File
@@ -2344,7 +2344,7 @@ namespace Z80
this.Tick(2);
this.LowerIORQ();
this.LowerWR();
this.Ports.Write(this.Bus.Address.Low, this.Bus.Data);
this.Ports.Write(this.Bus.Address, this.Bus.Data);
this.Tick();
this.RaiseWR();
this.RaiseIORQ();
@@ -2364,7 +2364,7 @@ namespace Z80
this.Tick(2);
this.LowerIORQ();
this.LowerRD();
this.Bus.Data = this.Ports.Read(this.Bus.Address.Low);
this.Bus.Data = this.Ports.Read(this.Bus.Address);
this.Tick();
this.RaiseRD();
this.RaiseIORQ();