mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2025-11-26 12:17:43 +00:00
More event handling simplification
This commit is contained in:
@@ -23,9 +23,9 @@ namespace EightBit
|
|||||||
|
|
||||||
public byte ReadInputPort(byte port)
|
public byte ReadInputPort(byte port)
|
||||||
{
|
{
|
||||||
this.OnReadingPort(port);
|
ReadingPort?.Invoke(this, new PortEventArgs(port));
|
||||||
var value = this._input[port];
|
var value = this._input[port];
|
||||||
this.OnReadPort(port);
|
ReadPort?.Invoke(this, new PortEventArgs(port));
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,17 +35,9 @@ namespace EightBit
|
|||||||
|
|
||||||
public void WriteOutputPort(byte port, byte value)
|
public void WriteOutputPort(byte port, byte value)
|
||||||
{
|
{
|
||||||
this.OnWritingPort(port);
|
WritingPort?.Invoke(this, new PortEventArgs(port));
|
||||||
this._output[port] = value;
|
this._output[port] = value;
|
||||||
this.OnWrittenPort(port);
|
WrittenPort?.Invoke(this, new PortEventArgs(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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ namespace EightBit
|
|||||||
{
|
{
|
||||||
RaisingHALT?.Invoke(this, EventArgs.Empty);
|
RaisingHALT?.Invoke(this, EventArgs.Empty);
|
||||||
this.HALT.Raise();
|
this.HALT.Raise();
|
||||||
++this.PC.Word; // Release the PC from HALT instruction
|
|
||||||
RaisedHALT?.Invoke(this, EventArgs.Empty);
|
RaisedHALT?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,7 +80,6 @@ namespace EightBit
|
|||||||
{
|
{
|
||||||
LoweringHALT?.Invoke(this, EventArgs.Empty);
|
LoweringHALT?.Invoke(this, EventArgs.Empty);
|
||||||
this.HALT.Lower();
|
this.HALT.Lower();
|
||||||
--this.PC.Word; // Keep the PC on the HALT instruction (i.e. executing NOP)
|
|
||||||
LoweredHALT?.Invoke(this, EventArgs.Empty);
|
LoweredHALT?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,19 @@ namespace Intel8080
|
|||||||
{
|
{
|
||||||
using EightBit;
|
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 Register16 af = new();
|
||||||
|
|
||||||
private readonly InputOutput ports = ports;
|
private readonly InputOutput ports;
|
||||||
|
|
||||||
private bool interruptEnable;
|
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) => SetBit(f, (byte)flag);
|
||||||
|
|
||||||
private static byte SetBit(byte f, StatusBits flag, int condition) => SetBit(f, (byte)flag, condition);
|
private static byte SetBit(byte f, StatusBits flag, int condition) => SetBit(f, (byte)flag, condition);
|
||||||
|
|||||||
@@ -26,20 +26,15 @@ namespace M6502
|
|||||||
public event EventHandler<EventArgs>? RaisedNMI;
|
public event EventHandler<EventArgs>? RaisedNMI;
|
||||||
public event EventHandler<EventArgs>? LoweringNMI;
|
public event EventHandler<EventArgs>? LoweringNMI;
|
||||||
public event EventHandler<EventArgs>? LoweredNMI;
|
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")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1030:Use events where appropriate", Justification = "The word 'raise' is used in an electrical sense")]
|
||||||
public virtual void RaiseNMI()
|
public virtual void RaiseNMI()
|
||||||
{
|
{
|
||||||
if (this.NMI.Lowered())
|
if (this.NMI.Lowered())
|
||||||
{
|
{
|
||||||
this.OnRaisingNMI();
|
RaisingNMI?.Invoke(this, EventArgs.Empty);
|
||||||
this.NMI.Raise();
|
this.NMI.Raise();
|
||||||
this.OnRaisedNMI();
|
RaisedNMI?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,9 +42,9 @@ namespace M6502
|
|||||||
{
|
{
|
||||||
if (this.NMI.Raised())
|
if (this.NMI.Raised())
|
||||||
{
|
{
|
||||||
this.OnLoweringNMI();
|
LoweringNMI?.Invoke(this, EventArgs.Empty);
|
||||||
this.NMI.Lower();
|
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>? LoweringSO;
|
||||||
public event EventHandler<EventArgs>? LoweredSO;
|
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")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1030:Use events where appropriate", Justification = "The word 'raise' is used in an electrical sense")]
|
||||||
public virtual void RaiseSO()
|
public virtual void RaiseSO()
|
||||||
{
|
{
|
||||||
if (this.SO.Lowered())
|
if (this.SO.Lowered())
|
||||||
{
|
{
|
||||||
this.OnRaisingSO();
|
RaisingSO?.Invoke(this, EventArgs.Empty);
|
||||||
this.SO.Raise();
|
this.SO.Raise();
|
||||||
this.OnRaisedSO();
|
RaisedSO?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,9 +74,9 @@ namespace M6502
|
|||||||
{
|
{
|
||||||
if (this.SO.Raised())
|
if (this.SO.Raised())
|
||||||
{
|
{
|
||||||
this.OnLoweringSO();
|
LoweringSO?.Invoke(this, EventArgs.Empty);
|
||||||
this.SO.Lower();
|
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>? LoweringSYNC;
|
||||||
public event EventHandler<EventArgs>? LoweredSYNC;
|
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")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1030:Use events where appropriate", Justification = "The word 'raise' is used in an electrical sense")]
|
||||||
protected virtual void RaiseSYNC()
|
protected virtual void RaiseSYNC()
|
||||||
{
|
{
|
||||||
@@ -138,19 +122,15 @@ namespace M6502
|
|||||||
public event EventHandler<EventArgs>? RaisedRDY;
|
public event EventHandler<EventArgs>? RaisedRDY;
|
||||||
public event EventHandler<EventArgs>? LoweringRDY;
|
public event EventHandler<EventArgs>? LoweringRDY;
|
||||||
public event EventHandler<EventArgs>? LoweredRDY;
|
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")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1030:Use events where appropriate", Justification = "The word 'raise' is used in an electrical sense")]
|
||||||
public virtual void RaiseRDY()
|
public virtual void RaiseRDY()
|
||||||
{
|
{
|
||||||
if (this.RDY.Lowered())
|
if (this.RDY.Lowered())
|
||||||
{
|
{
|
||||||
this.OnRaisingRDY();
|
RaisingRDY?.Invoke(this, EventArgs.Empty);
|
||||||
this.RDY.Raise();
|
this.RDY.Raise();
|
||||||
this.OnRaisedRDY();
|
RaisedRDY?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,9 +138,9 @@ namespace M6502
|
|||||||
{
|
{
|
||||||
if (this.RDY.Raised())
|
if (this.RDY.Raised())
|
||||||
{
|
{
|
||||||
this.OnLoweringRDY();
|
LoweringRDY?.Invoke(this, EventArgs.Empty);
|
||||||
this.RDY.Lower();
|
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>? RaisedRW;
|
||||||
public event EventHandler<EventArgs>? LoweringRW;
|
public event EventHandler<EventArgs>? LoweringRW;
|
||||||
public event EventHandler<EventArgs>? LoweredRW;
|
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")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1030:Use events where appropriate", Justification = "The word 'raise' is used in an electrical sense")]
|
||||||
public virtual void RaiseRW()
|
public virtual void RaiseRW()
|
||||||
{
|
{
|
||||||
if (this.RW.Lowered())
|
if (this.RW.Lowered())
|
||||||
{
|
{
|
||||||
this.OnRaisingRW();
|
RaisingRW?.Invoke(this, EventArgs.Empty);
|
||||||
this.RW.Raise();
|
this.RW.Raise();
|
||||||
this.OnRaisedRW();
|
RaisedRW?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,9 +170,9 @@ namespace M6502
|
|||||||
{
|
{
|
||||||
if (this.RW.Raised())
|
if (this.RW.Raised())
|
||||||
{
|
{
|
||||||
this.OnLoweringRW();
|
LoweringRW?.Invoke(this, EventArgs.Empty);
|
||||||
this.RW.Lower();
|
this.RW.Lower();
|
||||||
this.OnLoweredRW();
|
LoweredRW?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ namespace M6502
|
|||||||
{
|
{
|
||||||
this.LoweredRESET += this.WDC65C02_LoweredRESET;
|
this.LoweredRESET += this.WDC65C02_LoweredRESET;
|
||||||
this.LoweredINT += this.WDC65C02_LoweredINT;
|
this.LoweredINT += this.WDC65C02_LoweredINT;
|
||||||
|
this.LoweredNMI += this.WDC65C02_LoweredNMI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private bool _stopped;
|
private bool _stopped;
|
||||||
private bool _waiting;
|
private bool _waiting;
|
||||||
|
|
||||||
@@ -189,9 +189,8 @@ namespace M6502
|
|||||||
this.Waiting = false;
|
this.Waiting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnLoweredNMI()
|
private void WDC65C02_LoweredNMI(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnLoweredNMI();
|
|
||||||
this.Waiting = false;
|
this.Waiting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
Z80/Z80.cs
12
Z80/Z80.cs
@@ -13,6 +13,8 @@ namespace Z80
|
|||||||
{
|
{
|
||||||
this._ports = ports;
|
this._ports = ports;
|
||||||
this.RaisedPOWER += this.Z80_RaisedPOWER;
|
this.RaisedPOWER += this.Z80_RaisedPOWER;
|
||||||
|
this.LoweredHALT += this.Z80_LoweredHALT;
|
||||||
|
this.RaisedHALT += this.Z80_RaisedHALT;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly InputOutput _ports;
|
private readonly InputOutput _ports;
|
||||||
@@ -190,6 +192,16 @@ namespace Z80
|
|||||||
this.ResetPrefixes();
|
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()
|
private void ResetPrefixes()
|
||||||
{
|
{
|
||||||
this._prefixCB = this._prefixDD = this._prefixED = this._prefixFD = false;
|
this._prefixCB = this._prefixDD = this._prefixED = this._prefixFD = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user