mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2025-09-27 02:16:55 +00:00
Simplify Z80 port handling
This commit is contained in:
@@ -17,31 +17,32 @@ namespace EightBit
|
|||||||
|
|
||||||
public event EventHandler<PortEventArgs>? WrittenPort;
|
public event EventHandler<PortEventArgs>? WrittenPort;
|
||||||
|
|
||||||
public byte Read(ushort port) => this.ReadInputPort(port);
|
|
||||||
|
|
||||||
public byte Read(Register16 port) => this.Read(port.Word);
|
public byte Read(Register16 port) => this.ReadInputPort(port);
|
||||||
|
|
||||||
public void Write(ushort port, byte value) => this.WriteOutputPort(port, value);
|
public byte ReadInputPort(Register16 port)
|
||||||
|
|
||||||
public void Write(Register16 port, byte value) => this.Write(port.Word, value);
|
|
||||||
|
|
||||||
public byte ReadInputPort(ushort port)
|
|
||||||
{
|
{
|
||||||
ReadingPort?.Invoke(this, new PortEventArgs(port));
|
ReadingPort?.Invoke(this, new PortEventArgs(port));
|
||||||
var value = this._input[port];
|
var value = this._input[port.Word];
|
||||||
ReadPort?.Invoke(this, new PortEventArgs(port));
|
ReadPort?.Invoke(this, new PortEventArgs(port));
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteInputPort(ushort port, byte value) => this._input[port] = value;
|
public void WriteInputPort(ushort port, byte value) => this._input[port] = value;
|
||||||
|
|
||||||
public byte ReadOutputPort(ushort port) => this._output[port];
|
public void WriteInputPort(Register16 port, byte value) => this.WriteInputPort(port.Word, value);
|
||||||
|
|
||||||
public void WriteOutputPort(ushort port, byte value)
|
public void Write(Register16 port, byte value) => this.WriteOutputPort(port, value);
|
||||||
|
|
||||||
|
public void WriteOutputPort(Register16 port, byte value)
|
||||||
{
|
{
|
||||||
WritingPort?.Invoke(this, new PortEventArgs(port));
|
WritingPort?.Invoke(this, new PortEventArgs(port));
|
||||||
this._output[port] = value;
|
this._output[port.Word] = value;
|
||||||
WrittenPort?.Invoke(this, new PortEventArgs(port));
|
WrittenPort?.Invoke(this, new PortEventArgs(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte ReadOutputPort(ushort port) => this._output[port];
|
||||||
|
|
||||||
|
public byte ReadOutputPort(Register16 port) => this.ReadOutputPort(port.Word);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
namespace EightBit
|
namespace EightBit
|
||||||
{
|
{
|
||||||
public sealed class PortEventArgs(ushort value) : EventArgs
|
public sealed class PortEventArgs(Register16 value) : EventArgs
|
||||||
{
|
{
|
||||||
public ushort Port { get; } = value;
|
public Register16 Port { get; } = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -407,14 +407,13 @@
|
|||||||
|
|
||||||
foreach (var port in ports)
|
foreach (var port in ports)
|
||||||
{
|
{
|
||||||
var value = port.Value;
|
|
||||||
if (port.Type == "r")
|
if (port.Type == "r")
|
||||||
{
|
{
|
||||||
cpu.Ports.WriteInputPort(port.Address, value);
|
cpu.Ports.WriteInputPort(port.Address, port.Value);
|
||||||
}
|
}
|
||||||
else if (port.Type == "w")
|
else if (port.Type == "w")
|
||||||
{
|
{
|
||||||
cpu.Ports.WriteOutputPort(port.Address, value);
|
cpu.Ports.WriteOutputPort(new Register16(port.Address), port.Value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user