Simplify switching processor pin handling

This commit is contained in:
Adrian Conlon
2025-06-22 21:07:02 +01:00
parent 3105930027
commit 3bbf300e05
7 changed files with 500 additions and 122 deletions

View File

@@ -43,9 +43,14 @@ namespace EightBit
public byte Read() public byte Read()
{ {
this.ReadingByte?.Invoke(this, EventArgs.Empty); this.ReadingByte?.Invoke(this, EventArgs.Empty);
var returned = this.Data = this.Reference(); try
{
return this.Data = this.Reference();
}
finally
{
ReadByte?.Invoke(this, EventArgs.Empty); ReadByte?.Invoke(this, EventArgs.Empty);
return returned; }
} }
public byte Read(ushort absolute) public byte Read(ushort absolute)
@@ -68,9 +73,15 @@ namespace EightBit
public void Write() public void Write()
{ {
this.WritingByte?.Invoke(this, EventArgs.Empty); this.WritingByte?.Invoke(this, EventArgs.Empty);
try
{
this.Reference() = this.Data; this.Reference() = this.Data;
}
finally
{
this.WrittenByte?.Invoke(this, EventArgs.Empty); this.WrittenByte?.Invoke(this, EventArgs.Empty);
} }
}
public void Write(byte value) public void Write(byte value)
{ {

View File

@@ -26,19 +26,31 @@ namespace EightBit
if (this.POWER.Lowered()) if (this.POWER.Lowered())
{ {
RaisingPOWER?.Invoke(this, EventArgs.Empty); RaisingPOWER?.Invoke(this, EventArgs.Empty);
try
{
this.POWER.Raise(); this.POWER.Raise();
}
finally
{
RaisedPOWER?.Invoke(this, EventArgs.Empty); RaisedPOWER?.Invoke(this, EventArgs.Empty);
} }
} }
}
public virtual void LowerPOWER() public virtual void LowerPOWER()
{ {
if (this.POWER.Raised()) if (this.POWER.Raised())
{ {
LoweringPOWER?.Invoke(this, EventArgs.Empty); LoweringPOWER?.Invoke(this, EventArgs.Empty);
try
{
this.POWER.Lower(); this.POWER.Lower();
}
finally
{
LoweredPOWER?.Invoke(this, EventArgs.Empty); LoweredPOWER?.Invoke(this, EventArgs.Empty);
} }
} }
} }
}
} }

View File

@@ -28,9 +28,14 @@ namespace EightBit
public byte ReadInputPort(ushort port) public byte ReadInputPort(ushort port)
{ {
ReadingPort?.Invoke(this, new PortEventArgs(port)); ReadingPort?.Invoke(this, new PortEventArgs(port));
var value = this._input[port]; try
{
return this._input[port];
}
finally
{
ReadPort?.Invoke(this, new PortEventArgs(port)); ReadPort?.Invoke(this, new PortEventArgs(port));
return value; }
} }
public void WriteInputPort(ushort port, byte value) => this._input[port] = value; public void WriteInputPort(ushort port, byte value) => this._input[port] = value;
@@ -40,8 +45,14 @@ namespace EightBit
public void WriteOutputPort(ushort port, byte value) public void WriteOutputPort(ushort port, byte value)
{ {
WritingPort?.Invoke(this, new PortEventArgs(port)); WritingPort?.Invoke(this, new PortEventArgs(port));
try
{
this._output[port] = value; this._output[port] = value;
}
finally
{
WrittenPort?.Invoke(this, new PortEventArgs(port)); WrittenPort?.Invoke(this, new PortEventArgs(port));
} }
} }
}
} }

View File

@@ -69,20 +69,32 @@ namespace EightBit
if (this.HALT.Lowered()) if (this.HALT.Lowered())
{ {
RaisingHALT?.Invoke(this, EventArgs.Empty); RaisingHALT?.Invoke(this, EventArgs.Empty);
try
{
this.HALT.Raise(); this.HALT.Raise();
}
finally
{
RaisedHALT?.Invoke(this, EventArgs.Empty); RaisedHALT?.Invoke(this, EventArgs.Empty);
} }
} }
}
public virtual void LowerHALT() public virtual void LowerHALT()
{ {
if (this.HALT.Raised()) if (this.HALT.Raised())
{ {
LoweringHALT?.Invoke(this, EventArgs.Empty); LoweringHALT?.Invoke(this, EventArgs.Empty);
try
{
this.HALT.Lower(); this.HALT.Lower();
}
finally
{
LoweredHALT?.Invoke(this, EventArgs.Empty); LoweredHALT?.Invoke(this, EventArgs.Empty);
} }
} }
}
protected abstract void DisableInterrupts(); protected abstract void DisableInterrupts();

View File

@@ -69,11 +69,17 @@ namespace EightBit
{ {
this.ResetCycles(); this.ResetCycles();
ExecutingInstruction?.Invoke(this, EventArgs.Empty); ExecutingInstruction?.Invoke(this, EventArgs.Empty);
try
{
if (this.Powered) if (this.Powered)
{ {
this.PoweredStep(); this.PoweredStep();
} }
}
finally
{
ExecutedInstruction?.Invoke(this, EventArgs.Empty); ExecutedInstruction?.Invoke(this, EventArgs.Empty);
}
return this.Cycles; return this.Cycles;
} }
@@ -115,20 +121,32 @@ namespace EightBit
if (this.RESET.Lowered()) if (this.RESET.Lowered())
{ {
RaisingRESET?.Invoke(this, EventArgs.Empty); RaisingRESET?.Invoke(this, EventArgs.Empty);
try
{
this.RESET.Raise(); this.RESET.Raise();
}
finally
{
RaisedRESET?.Invoke(this, EventArgs.Empty); RaisedRESET?.Invoke(this, EventArgs.Empty);
} }
} }
}
public virtual void LowerRESET() public virtual void LowerRESET()
{ {
if (this.RESET.Raised()) if (this.RESET.Raised())
{ {
LoweringRESET?.Invoke(this, EventArgs.Empty); LoweringRESET?.Invoke(this, EventArgs.Empty);
try
{
this.RESET.Lower(); this.RESET.Lower();
}
finally
{
LoweredRESET?.Invoke(this, EventArgs.Empty); LoweredRESET?.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 RaiseINT() public virtual void RaiseINT()
@@ -136,20 +154,32 @@ namespace EightBit
if (this.INT.Lowered()) if (this.INT.Lowered())
{ {
RaisingINT?.Invoke(this, EventArgs.Empty); RaisingINT?.Invoke(this, EventArgs.Empty);
try
{
this.INT.Raise(); this.INT.Raise();
}
finally
{
RaisedINT?.Invoke(this, EventArgs.Empty); RaisedINT?.Invoke(this, EventArgs.Empty);
} }
} }
}
public virtual void LowerINT() public virtual void LowerINT()
{ {
if (this.INT.Raised()) if (this.INT.Raised())
{ {
LoweringINT?.Invoke(this, EventArgs.Empty); LoweringINT?.Invoke(this, EventArgs.Empty);
try
{
this.INT.Lower(); this.INT.Lower();
}
finally
{
LoweredINT?.Invoke(this, EventArgs.Empty); LoweredINT?.Invoke(this, EventArgs.Empty);
} }
} }
}
protected virtual void HandleRESET() => this.RaiseRESET(); protected virtual void HandleRESET() => this.RaiseRESET();

View File

@@ -33,20 +33,32 @@ namespace M6502
if (this.NMI.Lowered()) if (this.NMI.Lowered())
{ {
RaisingNMI?.Invoke(this, EventArgs.Empty); RaisingNMI?.Invoke(this, EventArgs.Empty);
try
{
this.NMI.Raise(); this.NMI.Raise();
}
finally
{
RaisedNMI?.Invoke(this, EventArgs.Empty); RaisedNMI?.Invoke(this, EventArgs.Empty);
} }
} }
}
public virtual void LowerNMI() public virtual void LowerNMI()
{ {
if (this.NMI.Raised()) if (this.NMI.Raised())
{ {
LoweringNMI?.Invoke(this, EventArgs.Empty); LoweringNMI?.Invoke(this, EventArgs.Empty);
try
{
this.NMI.Lower(); this.NMI.Lower();
}
finally
{
LoweredNMI?.Invoke(this, EventArgs.Empty); LoweredNMI?.Invoke(this, EventArgs.Empty);
} }
} }
}
#endregion #endregion
@@ -65,20 +77,32 @@ namespace M6502
if (this.SO.Lowered()) if (this.SO.Lowered())
{ {
RaisingSO?.Invoke(this, EventArgs.Empty); RaisingSO?.Invoke(this, EventArgs.Empty);
try
{
this.SO.Raise(); this.SO.Raise();
}
finally
{
RaisedSO?.Invoke(this, EventArgs.Empty); RaisedSO?.Invoke(this, EventArgs.Empty);
} }
} }
}
public virtual void LowerSO() public virtual void LowerSO()
{ {
if (this.SO.Raised()) if (this.SO.Raised())
{ {
LoweringSO?.Invoke(this, EventArgs.Empty); LoweringSO?.Invoke(this, EventArgs.Empty);
try
{
this.SO.Lower(); this.SO.Lower();
}
finally
{
LoweredSO?.Invoke(this, EventArgs.Empty); LoweredSO?.Invoke(this, EventArgs.Empty);
} }
} }
}
#endregion #endregion
@@ -97,20 +121,32 @@ namespace M6502
if (this.SYNC.Lowered()) if (this.SYNC.Lowered())
{ {
RaisingSYNC?.Invoke(this, EventArgs.Empty); RaisingSYNC?.Invoke(this, EventArgs.Empty);
try
{
this.SYNC.Raise(); this.SYNC.Raise();
}
finally
{
RaisedSYNC?.Invoke(this, EventArgs.Empty); RaisedSYNC?.Invoke(this, EventArgs.Empty);
} }
} }
}
protected virtual void LowerSYNC() protected virtual void LowerSYNC()
{ {
if (this.SYNC.Raised()) if (this.SYNC.Raised())
{ {
LoweringSYNC?.Invoke(this, EventArgs.Empty); LoweringSYNC?.Invoke(this, EventArgs.Empty);
try
{
this.SYNC.Lower(); this.SYNC.Lower();
}
finally
{
LoweredSYNC?.Invoke(this, EventArgs.Empty); LoweredSYNC?.Invoke(this, EventArgs.Empty);
} }
} }
}
#endregion #endregion
@@ -129,20 +165,32 @@ namespace M6502
if (this.RDY.Lowered()) if (this.RDY.Lowered())
{ {
RaisingRDY?.Invoke(this, EventArgs.Empty); RaisingRDY?.Invoke(this, EventArgs.Empty);
try
{
this.RDY.Raise(); this.RDY.Raise();
}
finally
{
RaisedRDY?.Invoke(this, EventArgs.Empty); RaisedRDY?.Invoke(this, EventArgs.Empty);
} }
} }
}
public virtual void LowerRDY() public virtual void LowerRDY()
{ {
if (this.RDY.Raised()) if (this.RDY.Raised())
{ {
LoweringRDY?.Invoke(this, EventArgs.Empty); LoweringRDY?.Invoke(this, EventArgs.Empty);
try
{
this.RDY.Lower(); this.RDY.Lower();
}
finally
{
LoweredRDY?.Invoke(this, EventArgs.Empty); LoweredRDY?.Invoke(this, EventArgs.Empty);
} }
} }
}
#endregion #endregion
@@ -161,20 +209,32 @@ namespace M6502
if (this.RW.Lowered()) if (this.RW.Lowered())
{ {
RaisingRW?.Invoke(this, EventArgs.Empty); RaisingRW?.Invoke(this, EventArgs.Empty);
try
{
this.RW.Raise(); this.RW.Raise();
}
finally
{
RaisedRW?.Invoke(this, EventArgs.Empty); RaisedRW?.Invoke(this, EventArgs.Empty);
} }
} }
}
public virtual void LowerRW() public virtual void LowerRW()
{ {
if (this.RW.Raised()) if (this.RW.Raised())
{ {
LoweringRW?.Invoke(this, EventArgs.Empty); LoweringRW?.Invoke(this, EventArgs.Empty);
try
{
this.RW.Lower(); this.RW.Lower();
}
finally
{
LoweredRW?.Invoke(this, EventArgs.Empty); LoweredRW?.Invoke(this, EventArgs.Empty);
} }
} }
}
#endregion #endregion

View File

@@ -205,20 +205,54 @@ namespace Z80
if (this.NMI.Lowered()) if (this.NMI.Lowered())
{ {
RaisingNMI?.Invoke(this, EventArgs.Empty); RaisingNMI?.Invoke(this, EventArgs.Empty);
try
{
this.NMI.Raise(); this.NMI.Raise();
}
finally
{
RaisedNMI?.Invoke(this, EventArgs.Empty); RaisedNMI?.Invoke(this, EventArgs.Empty);
} }
} }
}
public virtual void LowerNMI() public virtual void LowerNMI()
{ {
if (this.NMI.Raised()) if (this.NMI.Raised())
{ {
LoweringNMI?.Invoke(this, EventArgs.Empty); LoweringNMI?.Invoke(this, EventArgs.Empty);
try
{
this.NMI.Lower(); this.NMI.Lower();
}
finally
{
LoweredNMI?.Invoke(this, EventArgs.Empty); LoweredNMI?.Invoke(this, EventArgs.Empty);
} }
} }
}
protected sealed class AutoNMI : IDisposable
{
private readonly Z80 _cpu;
private bool _disposed;
public AutoNMI(Z80 cpu)
{
_cpu = cpu;
_cpu.LowerNMI();
}
public void Dispose()
{
if (!_disposed)
{
_cpu.RaiseNMI();
_disposed = true;
}
GC.SuppressFinalize(this);
}
}
#endregion #endregion
@@ -246,20 +280,53 @@ namespace Z80
if (this.M1.Lowered()) if (this.M1.Lowered())
{ {
RaisingM1?.Invoke(this, EventArgs.Empty); RaisingM1?.Invoke(this, EventArgs.Empty);
try
{
this.M1.Raise(); this.M1.Raise();
}
finally
{
RaisedM1?.Invoke(this, EventArgs.Empty); RaisedM1?.Invoke(this, EventArgs.Empty);
} }
} }
}
public virtual void LowerM1() public virtual void LowerM1()
{ {
if (this.M1.Raised()) if (this.M1.Raised())
{ {
LoweringM1?.Invoke(this, EventArgs.Empty); LoweringM1?.Invoke(this, EventArgs.Empty);
try
{
this.M1.Lower(); this.M1.Lower();
}
finally
{
LoweredM1?.Invoke(this, EventArgs.Empty); LoweredM1?.Invoke(this, EventArgs.Empty);
} }
} }
}
protected sealed class AutoM1 : IDisposable
{
private readonly Z80 _cpu;
private bool _disposed;
public AutoM1(Z80 cpu)
{
_cpu = cpu;
_cpu.LowerM1();
}
public void Dispose()
{
if (!_disposed)
{
_cpu.RaiseM1();
_disposed = true;
}
GC.SuppressFinalize(this);
}
}
#endregion #endregion
@@ -288,21 +355,55 @@ namespace Z80
if (this.RFSH.Lowered()) if (this.RFSH.Lowered())
{ {
RaisingRFSH?.Invoke(this, EventArgs.Empty); RaisingRFSH?.Invoke(this, EventArgs.Empty);
try
{
this.RFSH.Raise(); this.RFSH.Raise();
++this.REFRESH; ++this.REFRESH;
}
finally
{
RaisedRFSH?.Invoke(this, EventArgs.Empty); RaisedRFSH?.Invoke(this, EventArgs.Empty);
} }
} }
}
public virtual void LowerRFSH() public virtual void LowerRFSH()
{ {
if (this.RFSH.Raised()) if (this.RFSH.Raised())
{ {
LoweringRFSH?.Invoke(this, EventArgs.Empty); LoweringRFSH?.Invoke(this, EventArgs.Empty);
try
{
this.RFSH.Lower(); this.RFSH.Lower();
}
finally
{
LoweredRFSH?.Invoke(this, EventArgs.Empty); LoweredRFSH?.Invoke(this, EventArgs.Empty);
} }
} }
}
protected sealed class AutoRFSH : IDisposable
{
private readonly Z80 _cpu;
private bool _disposed;
public AutoRFSH(Z80 cpu)
{
_cpu = cpu;
_cpu.LowerRFSH();
}
public void Dispose()
{
if (!_disposed)
{
_cpu.RaiseRFSH();
_disposed = true;
}
GC.SuppressFinalize(this);
}
}
#endregion #endregion
@@ -326,20 +427,54 @@ namespace Z80
if (this.MREQ.Lowered()) if (this.MREQ.Lowered())
{ {
RaisingMREQ?.Invoke(this, EventArgs.Empty); RaisingMREQ?.Invoke(this, EventArgs.Empty);
try
{
this.MREQ.Raise(); this.MREQ.Raise();
}
finally
{
RaisedMREQ?.Invoke(this, EventArgs.Empty); RaisedMREQ?.Invoke(this, EventArgs.Empty);
} }
} }
}
public virtual void LowerMREQ() public virtual void LowerMREQ()
{ {
if (this.MREQ.Raised()) if (this.MREQ.Raised())
{ {
LoweringMREQ?.Invoke(this, EventArgs.Empty); LoweringMREQ?.Invoke(this, EventArgs.Empty);
try
{
this.MREQ.Lower(); this.MREQ.Lower();
}
finally
{
LoweredMREQ?.Invoke(this, EventArgs.Empty); LoweredMREQ?.Invoke(this, EventArgs.Empty);
} }
} }
}
protected sealed class AutoMREQ : IDisposable
{
private readonly Z80 _cpu;
private bool _disposed;
public AutoMREQ(Z80 cpu)
{
_cpu = cpu;
_cpu.LowerMREQ();
}
public void Dispose()
{
if (!_disposed)
{
_cpu.RaiseMREQ();
_disposed = true;
}
GC.SuppressFinalize(this);
}
}
#endregion #endregion
@@ -363,10 +498,16 @@ namespace Z80
if (this.IORQ.Lowered()) if (this.IORQ.Lowered())
{ {
RaisingIORQ?.Invoke(this, EventArgs.Empty); RaisingIORQ?.Invoke(this, EventArgs.Empty);
try
{
this.IORQ.Raise(); this.IORQ.Raise();
}
finally
{
RaisedIORQ?.Invoke(this, EventArgs.Empty); RaisedIORQ?.Invoke(this, EventArgs.Empty);
} }
} }
}
public virtual void LowerIORQ() public virtual void LowerIORQ()
{ {
@@ -378,6 +519,28 @@ namespace Z80
} }
} }
protected sealed class AutoIORQ : IDisposable
{
private readonly Z80 _cpu;
private bool _disposed;
public AutoIORQ(Z80 cpu)
{
_cpu = cpu;
_cpu.LowerIORQ();
}
public void Dispose()
{
if (!_disposed)
{
_cpu.RaiseIORQ();
_disposed = true;
}
GC.SuppressFinalize(this);
}
}
#endregion #endregion
#region RD pin #region RD pin
@@ -400,20 +563,54 @@ namespace Z80
if (this.RD.Lowered()) if (this.RD.Lowered())
{ {
RaisingRD?.Invoke(this, EventArgs.Empty); RaisingRD?.Invoke(this, EventArgs.Empty);
try
{
this.RD.Raise(); this.RD.Raise();
}
finally
{
RaisedRD?.Invoke(this, EventArgs.Empty); RaisedRD?.Invoke(this, EventArgs.Empty);
} }
} }
}
public virtual void LowerRD() public virtual void LowerRD()
{ {
if (this.RD.Raised()) if (this.RD.Raised())
{ {
LoweringRD?.Invoke(this, EventArgs.Empty); LoweringRD?.Invoke(this, EventArgs.Empty);
try
{
this.RD.Lower(); this.RD.Lower();
}
finally
{
LoweredRD?.Invoke(this, EventArgs.Empty); LoweredRD?.Invoke(this, EventArgs.Empty);
} }
} }
}
protected sealed class AutoRD : IDisposable
{
private readonly Z80 _cpu;
private bool _disposed;
public AutoRD(Z80 cpu)
{
_cpu = cpu;
_cpu.LowerRD();
}
public void Dispose()
{
if (!_disposed)
{
_cpu.RaiseRD();
_disposed = true;
}
GC.SuppressFinalize(this);
}
}
#endregion #endregion
@@ -437,20 +634,54 @@ namespace Z80
if (this.WR.Lowered()) if (this.WR.Lowered())
{ {
RaisingWR?.Invoke(this, EventArgs.Empty); RaisingWR?.Invoke(this, EventArgs.Empty);
try
{
this.WR.Raise(); this.WR.Raise();
}
finally
{
RaisedWR?.Invoke(this, EventArgs.Empty); RaisedWR?.Invoke(this, EventArgs.Empty);
} }
} }
}
public virtual void LowerWR() public virtual void LowerWR()
{ {
if (this.WR.Raised()) if (this.WR.Raised())
{ {
LoweringWR?.Invoke(this, EventArgs.Empty); LoweringWR?.Invoke(this, EventArgs.Empty);
try
{
this.WR.Lower(); this.WR.Lower();
}
finally
{
LoweredWR?.Invoke(this, EventArgs.Empty); LoweredWR?.Invoke(this, EventArgs.Empty);
} }
} }
}
protected sealed class AutoWR : IDisposable
{
private readonly Z80 _cpu;
private bool _disposed;
public AutoWR(Z80 cpu)
{
_cpu = cpu;
_cpu.LowerWR();
}
public void Dispose()
{
if (!_disposed)
{
_cpu.RaiseWR();
_disposed = true;
}
GC.SuppressFinalize(this);
}
}
#endregion #endregion
@@ -459,14 +690,18 @@ namespace Z80
protected void MemoryUpdate(int ticks) protected void MemoryUpdate(int ticks)
{ {
this.OnWritingMemory(); this.OnWritingMemory();
this.LowerMREQ(); try
this.LowerWR(); {
using var _ = new AutoMREQ(this);
using var __ = new AutoWR(this);
this.Tick(ticks); this.Tick(ticks);
base.MemoryWrite(); base.MemoryWrite();
this.RaiseWR(); }
this.RaiseMREQ(); finally
{
this.OnWroteMemory(); this.OnWroteMemory();
} }
}
protected override void MemoryWrite() protected override void MemoryWrite()
{ {
@@ -476,25 +711,32 @@ namespace Z80
protected override byte MemoryRead() protected override byte MemoryRead()
{ {
this.OnReadingMemory(); this.OnReadingMemory();
try
{
this.Tick(); this.Tick();
this.LowerMREQ(); try
this.LowerRD(); {
using var __ = new AutoMREQ(this);
using var _ = new AutoRD(this);
this.Tick(); this.Tick();
var returned = base.MemoryRead(); return base.MemoryRead();
this.RaiseRD(); }
this.RaiseMREQ(); finally
{
if (this.M1.Lowered()) if (this.M1.Lowered())
{ {
this.Bus.Address.Assign(this.REFRESH, this.IV); this.Bus.Address.Assign(this.REFRESH, this.IV);
this.LowerRFSH(); using var _ = new AutoRFSH(this);
this.Tick(); this.Tick();
this.LowerMREQ(); using var __ = new AutoMREQ(this);
this.RaiseMREQ();
this.RaiseRFSH();
} }
this.Tick(); this.Tick();
}
}
finally
{
this.OnReadMemory(); this.OnReadMemory();
return returned; }
} }
// From Zilog Z80 manual // From Zilog Z80 manual
@@ -516,15 +758,18 @@ namespace Z80
this.Tick(3); this.Tick(3);
} }
private byte ReadDataUnderInterrupt()
{
using var _ = new AutoM1(this);
using var __ = new AutoIORQ(this);
return this.Bus.Data;
}
protected override void HandleINT() protected override void HandleINT()
{ {
base.HandleINT(); base.HandleINT();
this.LowerM1(); var data = this.ReadDataUnderInterrupt();
this.LowerIORQ();
var data = this.Bus.Data;
this.RaiseIORQ();
this.RaiseM1();
this.DisableInterrupts(); this.DisableInterrupts();
this.Tick(5); this.Tick(5);
@@ -1560,9 +1805,8 @@ namespace Z80
this.RaiseHALT(); this.RaiseHALT();
this.IFF2 = this.IFF1; this.IFF2 = this.IFF1;
this.IFF1 = false; this.IFF1 = false;
this.LowerM1(); using var __ = new AutoM1(this);
_ = this.Bus.Data; _ = this.Bus.Data;
this.RaiseM1();
this.Restart(0x66); this.Restart(0x66);
} }
@@ -1582,10 +1826,8 @@ namespace Z80
// instruction so that no other concurrent operation can be performed. // instruction so that no other concurrent operation can be performed.
protected override byte FetchInstruction() protected override byte FetchInstruction()
{ {
this.LowerM1(); using var _ = new AutoM1(this);
var returned = base.FetchInstruction(); return base.FetchInstruction();
this.RaiseM1();
return returned;
} }
private byte Subtract(byte operand, byte value, int carry = 0) private byte Subtract(byte operand, byte value, int carry = 0)
@@ -2321,12 +2563,12 @@ namespace Z80
{ {
this.MEMPTR.Assign(this.Bus.Address); this.MEMPTR.Assign(this.Bus.Address);
this.Tick(2); this.Tick(2);
this.LowerIORQ(); {
this.LowerWR(); using var _ = new AutoIORQ(this);
using var __ = new AutoWR(this);
this.Ports.Write(this.Bus.Address, this.Bus.Data); this.Ports.Write(this.Bus.Address, this.Bus.Data);
this.Tick(); this.Tick();
this.RaiseWR(); }
this.RaiseIORQ();
this.Tick(); this.Tick();
} }
@@ -2341,12 +2583,12 @@ namespace Z80
{ {
this.MEMPTR.Assign(this.Bus.Address); this.MEMPTR.Assign(this.Bus.Address);
this.Tick(2); this.Tick(2);
this.LowerIORQ(); {
this.LowerRD(); using var _ = new AutoIORQ(this);
using var __ = new AutoRD(this);
this.Bus.Data = this.Ports.Read(this.Bus.Address); this.Bus.Data = this.Ports.Read(this.Bus.Address);
this.Tick(); this.Tick();
this.RaiseRD(); }
this.RaiseIORQ();
this.Tick(); this.Tick();
} }