2019-02-02 15:12:51 +00:00
|
|
|
|
namespace EightBit
|
|
|
|
|
{
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
public sealed class InputOutput
|
|
|
|
|
{
|
2019-02-03 20:29:52 +00:00
|
|
|
|
private byte[] input = new byte[0x100];
|
|
|
|
|
private byte[] output = new byte[0x100];
|
2019-02-02 15:12:51 +00:00
|
|
|
|
|
|
|
|
|
public InputOutput()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event EventHandler<PortEventArgs> ReadingPort;
|
|
|
|
|
public event EventHandler<PortEventArgs> ReadPort;
|
|
|
|
|
|
|
|
|
|
public event EventHandler<PortEventArgs> WritingPort;
|
|
|
|
|
public event EventHandler<PortEventArgs> WrittenPort;
|
|
|
|
|
|
2019-02-03 20:29:52 +00:00
|
|
|
|
byte Read(byte port) => ReadInputPort(port);
|
|
|
|
|
void Write(byte port, byte value) => WriteOutputPort(port, value);
|
2019-02-02 15:12:51 +00:00
|
|
|
|
|
|
|
|
|
byte ReadInputPort(byte port)
|
|
|
|
|
{
|
|
|
|
|
OnReadingPort(port);
|
|
|
|
|
var value = input[port];
|
|
|
|
|
OnReadPort(port);
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WriteInputPort(byte port, byte value) => input[port] = value;
|
|
|
|
|
|
|
|
|
|
byte ReadOutputPort(byte port) => output[port];
|
|
|
|
|
|
|
|
|
|
void WriteOutputPort(byte port, byte value)
|
|
|
|
|
{
|
|
|
|
|
OnWritingPort(port);
|
|
|
|
|
output[port] = value;
|
|
|
|
|
OnWrittenPort(port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnReadingPort(byte port) => ReadingPort?.Invoke(this, new PortEventArgs(port));
|
|
|
|
|
private void OnReadPort(byte port) => ReadPort?.Invoke(this, new PortEventArgs(port));
|
|
|
|
|
|
|
|
|
|
private void OnWritingPort(byte port) => WritingPort?.Invoke(this, new PortEventArgs(port));
|
|
|
|
|
private void OnWrittenPort(byte port) => WrittenPort?.Invoke(this, new PortEventArgs(port));
|
|
|
|
|
}
|
|
|
|
|
}
|