mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2026-04-19 15:16:41 +00:00
Explicitly state order of operations in code, rather than relying upon RAII etc. (for speed. Much faster)
This commit is contained in:
+5
-16
@@ -43,14 +43,9 @@ namespace EightBit
|
||||
public byte Read()
|
||||
{
|
||||
this.ReadingByte?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
return this.Data = this.Reference();
|
||||
}
|
||||
finally
|
||||
{
|
||||
ReadByte?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.Data = this.Reference();
|
||||
ReadByte?.Invoke(this, EventArgs.Empty);
|
||||
return this.Data;
|
||||
}
|
||||
|
||||
public byte Read(ushort absolute)
|
||||
@@ -74,14 +69,8 @@ namespace EightBit
|
||||
public void Write()
|
||||
{
|
||||
this.WritingByte?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.Reference() = this.Data;
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.WrittenByte?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.Reference() = this.Data;
|
||||
this.WrittenByte?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public void Write(byte value)
|
||||
|
||||
+4
-16
@@ -26,14 +26,8 @@ namespace EightBit
|
||||
if (this.POWER.Lowered())
|
||||
{
|
||||
RaisingPOWER?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.POWER.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedPOWER?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.POWER.Raise();
|
||||
RaisedPOWER?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,14 +36,8 @@ namespace EightBit
|
||||
if (this.POWER.Raised())
|
||||
{
|
||||
LoweringPOWER?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.POWER.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredPOWER?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.POWER.Lower();
|
||||
LoweredPOWER?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-16
@@ -28,14 +28,9 @@ namespace EightBit
|
||||
public byte ReadInputPort(ushort port)
|
||||
{
|
||||
ReadingPort?.Invoke(this, new PortEventArgs(port));
|
||||
try
|
||||
{
|
||||
return this._input[port];
|
||||
}
|
||||
finally
|
||||
{
|
||||
ReadPort?.Invoke(this, new PortEventArgs(port));
|
||||
}
|
||||
var value = this._input[port];
|
||||
ReadPort?.Invoke(this, new PortEventArgs(port));
|
||||
return value;
|
||||
}
|
||||
|
||||
public void WriteInputPort(ushort port, byte value) => this._input[port] = value;
|
||||
@@ -45,14 +40,8 @@ namespace EightBit
|
||||
public void WriteOutputPort(ushort port, byte value)
|
||||
{
|
||||
WritingPort?.Invoke(this, new PortEventArgs(port));
|
||||
try
|
||||
{
|
||||
this._output[port] = value;
|
||||
}
|
||||
finally
|
||||
{
|
||||
WrittenPort?.Invoke(this, new PortEventArgs(port));
|
||||
}
|
||||
this._output[port] = value;
|
||||
WrittenPort?.Invoke(this, new PortEventArgs(port));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,14 +69,8 @@ namespace EightBit
|
||||
if (this.HALT.Lowered())
|
||||
{
|
||||
RaisingHALT?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.HALT.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedHALT?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.HALT.Raise();
|
||||
RaisedHALT?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,14 +79,8 @@ namespace EightBit
|
||||
if (this.HALT.Raised())
|
||||
{
|
||||
LoweringHALT?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.HALT.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredHALT?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.HALT.Lower();
|
||||
LoweredHALT?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-41
@@ -69,17 +69,11 @@ namespace EightBit
|
||||
{
|
||||
this.ResetCycles();
|
||||
ExecutingInstruction?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
if (this.Powered)
|
||||
{
|
||||
if (this.Powered)
|
||||
{
|
||||
this.PoweredStep();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
ExecutedInstruction?.Invoke(this, EventArgs.Empty);
|
||||
this.PoweredStep();
|
||||
}
|
||||
ExecutedInstruction?.Invoke(this, EventArgs.Empty);
|
||||
return this.Cycles;
|
||||
}
|
||||
|
||||
@@ -121,14 +115,8 @@ namespace EightBit
|
||||
if (this.RESET.Lowered())
|
||||
{
|
||||
RaisingRESET?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.RESET.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedRESET?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.RESET.Raise();
|
||||
RaisedRESET?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,14 +125,8 @@ namespace EightBit
|
||||
if (this.RESET.Raised())
|
||||
{
|
||||
LoweringRESET?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.RESET.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredRESET?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.RESET.Lower();
|
||||
LoweredRESET?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,14 +136,8 @@ namespace EightBit
|
||||
if (this.INT.Lowered())
|
||||
{
|
||||
RaisingINT?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.INT.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedINT?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.INT.Raise();
|
||||
RaisedINT?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,14 +146,8 @@ namespace EightBit
|
||||
if (this.INT.Raised())
|
||||
{
|
||||
LoweringINT?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.INT.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredINT?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.INT.Lower();
|
||||
LoweredINT?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-126
@@ -76,14 +76,8 @@ namespace LR35902
|
||||
if (this.MWR.Lowered())
|
||||
{
|
||||
RaisingMWR?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.MWR.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedMWR?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.MWR.Raise();
|
||||
RaisedMWR?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,36 +86,8 @@ namespace LR35902
|
||||
if (this.MWR.Raised())
|
||||
{
|
||||
LoweringMWR?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.MWR.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredMWR?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class AutoMWR : IDisposable
|
||||
{
|
||||
private readonly LR35902 _cpu;
|
||||
private bool _disposed;
|
||||
|
||||
public AutoMWR(LR35902 cpu)
|
||||
{
|
||||
_cpu = cpu;
|
||||
_cpu.LowerMWR();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
_cpu.RaiseMWR();
|
||||
_disposed = true;
|
||||
}
|
||||
GC.SuppressFinalize(this);
|
||||
this.MWR.Lower();
|
||||
LoweredMWR?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,14 +113,8 @@ namespace LR35902
|
||||
if (this.RD.Lowered())
|
||||
{
|
||||
RaisingRD?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.RD.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedRD?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.RD.Raise();
|
||||
RaisedRD?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,36 +123,8 @@ namespace LR35902
|
||||
if (this.RD.Raised())
|
||||
{
|
||||
LoweringRD?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.RD.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredRD?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class AutoRD : IDisposable
|
||||
{
|
||||
private readonly LR35902 _cpu;
|
||||
private bool _disposed;
|
||||
|
||||
public AutoRD(LR35902 cpu)
|
||||
{
|
||||
_cpu = cpu;
|
||||
_cpu.LowerRD();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
_cpu.RaiseRD();
|
||||
_disposed = true;
|
||||
}
|
||||
GC.SuppressFinalize(this);
|
||||
this.RD.Lower();
|
||||
LoweredRD?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,14 +150,8 @@ namespace LR35902
|
||||
if (this.WR.Lowered())
|
||||
{
|
||||
RaisingWR?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.WR.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedWR?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.WR.Raise();
|
||||
RaisedWR?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,36 +160,8 @@ namespace LR35902
|
||||
if (this.WR.Raised())
|
||||
{
|
||||
LoweringWR?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.WR.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredWR?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class AutoWR : IDisposable
|
||||
{
|
||||
private readonly LR35902 _cpu;
|
||||
private bool _disposed;
|
||||
|
||||
public AutoWR(LR35902 cpu)
|
||||
{
|
||||
_cpu = cpu;
|
||||
_cpu.LowerWR();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
_cpu.RaiseWR();
|
||||
_disposed = true;
|
||||
}
|
||||
GC.SuppressFinalize(this);
|
||||
this.WR.Lower();
|
||||
LoweredWR?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -426,24 +324,23 @@ namespace LR35902
|
||||
|
||||
protected override void MemoryWrite()
|
||||
{
|
||||
using var _ = new AutoMWR(this);
|
||||
using var __ = new AutoWR(this);
|
||||
this.LowerMWR();
|
||||
this.LowerWR();
|
||||
base.MemoryWrite();
|
||||
this.TickMachine();
|
||||
this.RaiseWR();
|
||||
this.RaiseMWR();
|
||||
}
|
||||
|
||||
protected override byte MemoryRead()
|
||||
{
|
||||
using var _ = new AutoMWR(this);
|
||||
using var __ = new AutoRD(this);
|
||||
try
|
||||
{
|
||||
return base.MemoryRead();
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.TickMachine();
|
||||
}
|
||||
this.LowerMWR();
|
||||
this.LowerRD();
|
||||
_ = base.MemoryRead();
|
||||
this.TickMachine();
|
||||
this.RaiseRD();
|
||||
this.RaiseMWR();
|
||||
return this.Bus.Data;
|
||||
}
|
||||
|
||||
protected override void PushWord(Register16 value)
|
||||
|
||||
+29
-92
@@ -33,14 +33,8 @@ namespace M6502
|
||||
if (this.NMI.Lowered())
|
||||
{
|
||||
RaisingNMI?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.NMI.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedNMI?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.NMI.Raise();
|
||||
RaisedNMI?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,14 +43,8 @@ namespace M6502
|
||||
if (this.NMI.Raised())
|
||||
{
|
||||
LoweringNMI?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.NMI.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredNMI?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.NMI.Lower();
|
||||
LoweredNMI?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,14 +65,8 @@ namespace M6502
|
||||
if (this.SO.Lowered())
|
||||
{
|
||||
RaisingSO?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.SO.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedSO?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.SO.Raise();
|
||||
RaisedSO?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,14 +75,8 @@ namespace M6502
|
||||
if (this.SO.Raised())
|
||||
{
|
||||
LoweringSO?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.SO.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredSO?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.SO.Lower();
|
||||
LoweredSO?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,14 +97,8 @@ namespace M6502
|
||||
if (this.SYNC.Lowered())
|
||||
{
|
||||
RaisingSYNC?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.SYNC.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedSYNC?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.SYNC.Raise();
|
||||
RaisedSYNC?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,14 +107,8 @@ namespace M6502
|
||||
if (this.SYNC.Raised())
|
||||
{
|
||||
LoweringSYNC?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.SYNC.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredSYNC?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.SYNC.Lower();
|
||||
LoweredSYNC?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,14 +129,8 @@ namespace M6502
|
||||
if (this.RDY.Lowered())
|
||||
{
|
||||
RaisingRDY?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.RDY.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedRDY?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.RDY.Raise();
|
||||
RaisedRDY?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,14 +139,8 @@ namespace M6502
|
||||
if (this.RDY.Raised())
|
||||
{
|
||||
LoweringRDY?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.RDY.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredRDY?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.RDY.Lower();
|
||||
LoweredRDY?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,14 +161,8 @@ namespace M6502
|
||||
if (this.RW.Lowered())
|
||||
{
|
||||
RaisingRW?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.RW.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedRW?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.RW.Raise();
|
||||
RaisedRW?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,14 +171,8 @@ namespace M6502
|
||||
if (this.RW.Raised())
|
||||
{
|
||||
LoweringRW?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.RW.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredRW?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.RW.Lower();
|
||||
LoweredRW?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -599,19 +539,16 @@ namespace M6502
|
||||
protected override byte FetchInstruction()
|
||||
{
|
||||
this.LowerSYNC();
|
||||
try
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(this.Cycles == 1, "An extra cycle has occurred");
|
||||
System.Diagnostics.Debug.Assert(this.Cycles == 1, "An extra cycle has occurred");
|
||||
|
||||
// Can't use "FetchByte", since that would add an extra tick.
|
||||
this.ImmediateAddress();
|
||||
return this.ReadFromBus();
|
||||
}
|
||||
finally
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(this.Cycles == 1, "BUS read has introduced stray cycles");
|
||||
this.RaiseSYNC();
|
||||
}
|
||||
// Can't use "FetchByte", since that would add an extra tick.
|
||||
this.ImmediateAddress();
|
||||
_ = this.ReadFromBus();
|
||||
|
||||
System.Diagnostics.Debug.Assert(this.Cycles == 1, "BUS read has introduced stray cycles");
|
||||
this.RaiseSYNC();
|
||||
|
||||
return this.Bus.Data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
+75
-312
@@ -206,14 +206,8 @@ namespace Z80
|
||||
if (this.NMI.Lowered())
|
||||
{
|
||||
RaisingNMI?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.NMI.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedNMI?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.NMI.Raise();
|
||||
RaisedNMI?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,36 +216,8 @@ namespace Z80
|
||||
if (this.NMI.Raised())
|
||||
{
|
||||
LoweringNMI?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.NMI.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredNMI?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private 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);
|
||||
this.NMI.Lower();
|
||||
LoweredNMI?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,14 +243,8 @@ namespace Z80
|
||||
if (this.M1.Lowered())
|
||||
{
|
||||
RaisingM1?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.M1.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedM1?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.M1.Raise();
|
||||
RaisedM1?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,35 +253,8 @@ namespace Z80
|
||||
if (this.M1.Raised())
|
||||
{
|
||||
LoweringM1?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.M1.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredM1?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
private 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);
|
||||
this.M1.Lower();
|
||||
LoweredM1?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,15 +285,9 @@ namespace Z80
|
||||
if (this.RFSH.Lowered())
|
||||
{
|
||||
RaisingRFSH?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.RFSH.Raise();
|
||||
++this.REFRESH;
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedRFSH?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.RFSH.Raise();
|
||||
++this.REFRESH;
|
||||
RaisedRFSH?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,36 +296,8 @@ namespace Z80
|
||||
if (this.RFSH.Raised())
|
||||
{
|
||||
LoweringRFSH?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.RFSH.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredRFSH?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private 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);
|
||||
this.RFSH.Lower();
|
||||
LoweredRFSH?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,14 +323,8 @@ namespace Z80
|
||||
if (this.MREQ.Lowered())
|
||||
{
|
||||
RaisingMREQ?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.MREQ.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedMREQ?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.MREQ.Raise();
|
||||
RaisedMREQ?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,36 +333,8 @@ namespace Z80
|
||||
if (this.MREQ.Raised())
|
||||
{
|
||||
LoweringMREQ?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.MREQ.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredMREQ?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private 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);
|
||||
this.MREQ.Lower();
|
||||
LoweredMREQ?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -495,14 +360,8 @@ namespace Z80
|
||||
if (this.IORQ.Lowered())
|
||||
{
|
||||
RaisingIORQ?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.IORQ.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedIORQ?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.IORQ.Raise();
|
||||
RaisedIORQ?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -516,28 +375,6 @@ namespace Z80
|
||||
}
|
||||
}
|
||||
|
||||
private 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
|
||||
|
||||
#region RD pin
|
||||
@@ -560,14 +397,8 @@ namespace Z80
|
||||
if (this.RD.Lowered())
|
||||
{
|
||||
RaisingRD?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.RD.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedRD?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.RD.Raise();
|
||||
RaisedRD?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -576,36 +407,8 @@ namespace Z80
|
||||
if (this.RD.Raised())
|
||||
{
|
||||
LoweringRD?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.RD.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredRD?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private 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);
|
||||
this.RD.Lower();
|
||||
LoweredRD?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -631,14 +434,8 @@ namespace Z80
|
||||
if (this.WR.Lowered())
|
||||
{
|
||||
RaisingWR?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.WR.Raise();
|
||||
}
|
||||
finally
|
||||
{
|
||||
RaisedWR?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
this.WR.Raise();
|
||||
RaisedWR?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -647,36 +444,8 @@ namespace Z80
|
||||
if (this.WR.Raised())
|
||||
{
|
||||
LoweringWR?.Invoke(this, EventArgs.Empty);
|
||||
try
|
||||
{
|
||||
this.WR.Lower();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LoweredWR?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private 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);
|
||||
this.WR.Lower();
|
||||
LoweredWR?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -687,19 +456,15 @@ namespace Z80
|
||||
private void MemoryUpdate(int ticks)
|
||||
{
|
||||
this.OnWritingMemory();
|
||||
try
|
||||
{
|
||||
this.Tick(ticks);
|
||||
using var _ = new AutoMREQ(this);
|
||||
using var __ = new AutoWR(this);
|
||||
this.Tick();
|
||||
base.MemoryWrite();
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.Tick();
|
||||
this.OnWrittenMemory();
|
||||
}
|
||||
this.Tick(ticks);
|
||||
this.LowerMREQ();
|
||||
this.LowerWR();
|
||||
this.Tick();
|
||||
base.MemoryWrite();
|
||||
this.RaiseWR();
|
||||
this.RaiseMREQ();
|
||||
this.Tick();
|
||||
this.OnWrittenMemory();
|
||||
}
|
||||
|
||||
protected override void MemoryWrite()
|
||||
@@ -710,32 +475,25 @@ namespace Z80
|
||||
protected override byte MemoryRead()
|
||||
{
|
||||
this.OnReadingMemory();
|
||||
try
|
||||
this.Tick();
|
||||
this.LowerMREQ();
|
||||
this.LowerRD();
|
||||
this.Tick();
|
||||
_ = base.MemoryRead();
|
||||
this.RaiseRD();
|
||||
this.RaiseMREQ();
|
||||
if (this.M1.Lowered())
|
||||
{
|
||||
try
|
||||
{
|
||||
this.Tick();
|
||||
using var __ = new AutoMREQ(this);
|
||||
using var _ = new AutoRD(this);
|
||||
this.Tick();
|
||||
return base.MemoryRead();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (this.M1.Lowered())
|
||||
{
|
||||
this.Bus.Address.Assign(this.REFRESH, this.IV);
|
||||
using var _ = new AutoRFSH(this);
|
||||
this.Tick();
|
||||
using var __ = new AutoMREQ(this);
|
||||
}
|
||||
this.Tick();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.OnReadMemory();
|
||||
this.Bus.Address.Assign(this.REFRESH, this.IV);
|
||||
this.LowerRFSH();
|
||||
this.Tick();
|
||||
this.LowerMREQ();
|
||||
this.RaiseMREQ();
|
||||
this.RaiseRFSH();
|
||||
}
|
||||
this.Tick();
|
||||
this.OnReadMemory();
|
||||
return this.Bus.Data;
|
||||
}
|
||||
|
||||
// From Zilog Z80 manual
|
||||
@@ -759,8 +517,10 @@ namespace Z80
|
||||
|
||||
private byte ReadDataUnderInterrupt()
|
||||
{
|
||||
using var _ = new AutoM1(this);
|
||||
using var __ = new AutoIORQ(this);
|
||||
this.LowerM1();
|
||||
this.LowerIORQ();
|
||||
this.RaiseIORQ();
|
||||
this.RaiseM1();
|
||||
return this.Bus.Data;
|
||||
}
|
||||
|
||||
@@ -1785,8 +1545,9 @@ namespace Z80
|
||||
this.RaiseHALT();
|
||||
this.IFF2 = this.IFF1;
|
||||
this.IFF1 = false;
|
||||
using var __ = new AutoM1(this);
|
||||
this.LowerM1();
|
||||
_ = this.Bus.Data;
|
||||
this.RaiseM1();
|
||||
this.Restart(0x66);
|
||||
}
|
||||
|
||||
@@ -1806,8 +1567,10 @@ namespace Z80
|
||||
// instruction so that no other concurrent operation can be performed.
|
||||
protected override byte FetchInstruction()
|
||||
{
|
||||
using var _ = new AutoM1(this);
|
||||
return base.FetchInstruction();
|
||||
this.LowerM1();
|
||||
_ = base.FetchInstruction();
|
||||
this.RaiseM1();
|
||||
return this.Bus.Data;
|
||||
}
|
||||
|
||||
private byte Subtract(byte operand, byte value, int carry = 0)
|
||||
@@ -2530,12 +2293,12 @@ namespace Z80
|
||||
{
|
||||
this.MEMPTR.Assign(this.Bus.Address);
|
||||
this.Tick(2);
|
||||
{
|
||||
using var _ = new AutoIORQ(this);
|
||||
using var __ = new AutoWR(this);
|
||||
this.Tick();
|
||||
this.Ports.Write(this.Bus.Address, this.Bus.Data);
|
||||
}
|
||||
this.LowerIORQ();
|
||||
this.LowerWR();
|
||||
this.Tick();
|
||||
this.Ports.Write(this.Bus.Address, this.Bus.Data);
|
||||
this.RaiseWR();
|
||||
this.RaiseIORQ();
|
||||
this.Tick();
|
||||
}
|
||||
|
||||
@@ -2550,12 +2313,12 @@ namespace Z80
|
||||
{
|
||||
this.MEMPTR.Assign(this.Bus.Address);
|
||||
this.Tick(2);
|
||||
{
|
||||
using var _ = new AutoIORQ(this);
|
||||
using var __ = new AutoRD(this);
|
||||
this.Bus.Data = this.Ports.Read(this.Bus.Address);
|
||||
this.Tick();
|
||||
}
|
||||
this.LowerIORQ();
|
||||
this.LowerRD();
|
||||
this.Bus.Data = this.Ports.Read(this.Bus.Address);
|
||||
this.Tick();
|
||||
this.RaiseRD();
|
||||
this.RaiseIORQ();
|
||||
this.Tick();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user