More event handling simplification

This commit is contained in:
Adrian Conlon
2025-03-29 13:18:54 +00:00
parent b461eb97d6
commit 1b1b92ac2c
6 changed files with 54 additions and 59 deletions

View File

@@ -23,9 +23,9 @@ namespace EightBit
public byte ReadInputPort(byte port)
{
this.OnReadingPort(port);
ReadingPort?.Invoke(this, new PortEventArgs(port));
var value = this._input[port];
this.OnReadPort(port);
ReadPort?.Invoke(this, new PortEventArgs(port));
return value;
}
@@ -35,17 +35,9 @@ namespace EightBit
public void WriteOutputPort(byte port, byte value)
{
this.OnWritingPort(port);
WritingPort?.Invoke(this, new PortEventArgs(port));
this._output[port] = value;
this.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));
WrittenPort?.Invoke(this, new PortEventArgs(port));
}
}
}

View File

@@ -70,7 +70,6 @@ namespace EightBit
{
RaisingHALT?.Invoke(this, EventArgs.Empty);
this.HALT.Raise();
++this.PC.Word; // Release the PC from HALT instruction
RaisedHALT?.Invoke(this, EventArgs.Empty);
}
}
@@ -81,7 +80,6 @@ namespace EightBit
{
LoweringHALT?.Invoke(this, EventArgs.Empty);
this.HALT.Lower();
--this.PC.Word; // Keep the PC on the HALT instruction (i.e. executing NOP)
LoweredHALT?.Invoke(this, EventArgs.Empty);
}
}

View File

@@ -7,11 +7,19 @@ namespace Intel8080
{
using EightBit;
public class Intel8080(Bus bus, InputOutput ports) : IntelProcessor(bus)
public class Intel8080 : IntelProcessor
{
public Intel8080(Bus bus, InputOutput ports)
: base(bus)
{
this.ports = ports;
this.LoweredHALT += this.Intel8080_LoweredHALT;
this.RaisedHALT += this.Intel8080_RaisedHALT;
}
private readonly Register16 af = new();
private readonly InputOutput ports = ports;
private readonly InputOutput ports;
private bool interruptEnable;
@@ -83,6 +91,16 @@ namespace Intel8080
}
}
private void Intel8080_RaisedHALT(object? sender, EventArgs e)
{
++this.PC.Word; // Release the PC from HALT instruction
}
private void Intel8080_LoweredHALT(object? sender, EventArgs e)
{
--this.PC.Word; // Keep the PC on the HALT instruction (i.e. executing NOP)
}
private static byte SetBit(byte f, StatusBits flag) => SetBit(f, (byte)flag);
private static byte SetBit(byte f, StatusBits flag, int condition) => SetBit(f, (byte)flag, condition);

View File

@@ -26,20 +26,15 @@ namespace M6502
public event EventHandler<EventArgs>? RaisedNMI;
public event EventHandler<EventArgs>? LoweringNMI;
public event EventHandler<EventArgs>? LoweredNMI;
protected virtual void OnRaisingNMI() => RaisingNMI?.Invoke(this, EventArgs.Empty);
protected virtual void OnRaisedNMI() => RaisedNMI?.Invoke(this, EventArgs.Empty);
protected virtual void OnLoweringNMI() => LoweringNMI?.Invoke(this, EventArgs.Empty);
protected virtual void OnLoweredNMI() => LoweredNMI?.Invoke(this, EventArgs.Empty);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1030:Use events where appropriate", Justification = "The word 'raise' is used in an electrical sense")]
public virtual void RaiseNMI()
{
if (this.NMI.Lowered())
{
this.OnRaisingNMI();
RaisingNMI?.Invoke(this, EventArgs.Empty);
this.NMI.Raise();
this.OnRaisedNMI();
RaisedNMI?.Invoke(this, EventArgs.Empty);
}
}
@@ -47,9 +42,9 @@ namespace M6502
{
if (this.NMI.Raised())
{
this.OnLoweringNMI();
LoweringNMI?.Invoke(this, EventArgs.Empty);
this.NMI.Lower();
this.OnLoweredNMI();
LoweredNMI?.Invoke(this, EventArgs.Empty);
}
}
@@ -64,20 +59,14 @@ namespace M6502
public event EventHandler<EventArgs>? LoweringSO;
public event EventHandler<EventArgs>? LoweredSO;
protected virtual void OnRaisingSO() => RaisingSO?.Invoke(this, EventArgs.Empty);
protected virtual void OnRaisedSO() => RaisedSO?.Invoke(this, EventArgs.Empty);
protected virtual void OnLoweringSO() => LoweringSO?.Invoke(this, EventArgs.Empty);
protected virtual void OnLoweredSO() => LoweredSO?.Invoke(this, EventArgs.Empty);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1030:Use events where appropriate", Justification = "The word 'raise' is used in an electrical sense")]
public virtual void RaiseSO()
{
if (this.SO.Lowered())
{
this.OnRaisingSO();
RaisingSO?.Invoke(this, EventArgs.Empty);
this.SO.Raise();
this.OnRaisedSO();
RaisedSO?.Invoke(this, EventArgs.Empty);
}
}
@@ -85,9 +74,9 @@ namespace M6502
{
if (this.SO.Raised())
{
this.OnLoweringSO();
LoweringSO?.Invoke(this, EventArgs.Empty);
this.SO.Lower();
this.OnLoweredSO();
LoweredSO?.Invoke(this, EventArgs.Empty);
}
}
@@ -102,11 +91,6 @@ namespace M6502
public event EventHandler<EventArgs>? LoweringSYNC;
public event EventHandler<EventArgs>? LoweredSYNC;
protected virtual void OnRaisingSYNC() => RaisingSYNC?.Invoke(this, EventArgs.Empty);
protected virtual void OnRaisedSYNC() => RaisedSYNC?.Invoke(this, EventArgs.Empty);
protected virtual void OnLoweringSYNC() => LoweringSYNC?.Invoke(this, EventArgs.Empty);
protected virtual void OnLoweredSYNC() => LoweredSYNC?.Invoke(this, EventArgs.Empty);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1030:Use events where appropriate", Justification = "The word 'raise' is used in an electrical sense")]
protected virtual void RaiseSYNC()
{
@@ -138,19 +122,15 @@ namespace M6502
public event EventHandler<EventArgs>? RaisedRDY;
public event EventHandler<EventArgs>? LoweringRDY;
public event EventHandler<EventArgs>? LoweredRDY;
protected virtual void OnRaisingRDY() => RaisingRDY?.Invoke(this, EventArgs.Empty);
protected virtual void OnRaisedRDY() => RaisedRDY?.Invoke(this, EventArgs.Empty);
protected virtual void OnLoweringRDY() => LoweringRDY?.Invoke(this, EventArgs.Empty);
protected virtual void OnLoweredRDY() => LoweredRDY?.Invoke(this, EventArgs.Empty);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1030:Use events where appropriate", Justification = "The word 'raise' is used in an electrical sense")]
public virtual void RaiseRDY()
{
if (this.RDY.Lowered())
{
this.OnRaisingRDY();
RaisingRDY?.Invoke(this, EventArgs.Empty);
this.RDY.Raise();
this.OnRaisedRDY();
RaisedRDY?.Invoke(this, EventArgs.Empty);
}
}
@@ -158,9 +138,9 @@ namespace M6502
{
if (this.RDY.Raised())
{
this.OnLoweringRDY();
LoweringRDY?.Invoke(this, EventArgs.Empty);
this.RDY.Lower();
this.OnLoweredRDY();
LoweredRDY?.Invoke(this, EventArgs.Empty);
}
}
@@ -174,19 +154,15 @@ namespace M6502
public event EventHandler<EventArgs>? RaisedRW;
public event EventHandler<EventArgs>? LoweringRW;
public event EventHandler<EventArgs>? LoweredRW;
protected virtual void OnRaisingRW() => RaisingRW?.Invoke(this, EventArgs.Empty);
protected virtual void OnRaisedRW() => RaisedRW?.Invoke(this, EventArgs.Empty);
protected virtual void OnLoweringRW() => LoweringRW?.Invoke(this, EventArgs.Empty);
protected virtual void OnLoweredRW() => LoweredRW?.Invoke(this, EventArgs.Empty);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1030:Use events where appropriate", Justification = "The word 'raise' is used in an electrical sense")]
public virtual void RaiseRW()
{
if (this.RW.Lowered())
{
this.OnRaisingRW();
RaisingRW?.Invoke(this, EventArgs.Empty);
this.RW.Raise();
this.OnRaisedRW();
RaisedRW?.Invoke(this, EventArgs.Empty);
}
}
@@ -194,9 +170,9 @@ namespace M6502
{
if (this.RW.Raised())
{
this.OnLoweringRW();
LoweringRW?.Invoke(this, EventArgs.Empty);
this.RW.Lower();
this.OnLoweredRW();
LoweredRW?.Invoke(this, EventArgs.Empty);
}
}

View File

@@ -13,9 +13,9 @@ namespace M6502
{
this.LoweredRESET += this.WDC65C02_LoweredRESET;
this.LoweredINT += this.WDC65C02_LoweredINT;
this.LoweredNMI += this.WDC65C02_LoweredNMI;
}
private bool _stopped;
private bool _waiting;
@@ -189,9 +189,8 @@ namespace M6502
this.Waiting = false;
}
protected override void OnLoweredNMI()
private void WDC65C02_LoweredNMI(object? sender, EventArgs e)
{
base.OnLoweredNMI();
this.Waiting = false;
}

View File

@@ -13,6 +13,8 @@ namespace Z80
{
this._ports = ports;
this.RaisedPOWER += this.Z80_RaisedPOWER;
this.LoweredHALT += this.Z80_LoweredHALT;
this.RaisedHALT += this.Z80_RaisedHALT;
}
private readonly InputOutput _ports;
@@ -190,6 +192,16 @@ namespace Z80
this.ResetPrefixes();
}
private void Z80_RaisedHALT(object? sender, EventArgs e)
{
++this.PC.Word; // Release the PC from HALT instruction
}
private void Z80_LoweredHALT(object? sender, EventArgs e)
{
--this.PC.Word; // Keep the PC on the HALT instruction (i.e. executing NOP)
}
private void ResetPrefixes()
{
this._prefixCB = this._prefixDD = this._prefixED = this._prefixFD = false;