mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2025-07-25 13:24:08 +00:00
Share instruction fetch and halt implementations
This commit is contained in:
@@ -96,6 +96,13 @@ namespace EightBit
|
||||
}
|
||||
}
|
||||
|
||||
protected override byte FetchInstruction()
|
||||
{
|
||||
var read = this.FetchByte();
|
||||
return this.HALT.Lowered() ? (byte)0 : read;
|
||||
}
|
||||
|
||||
|
||||
protected void ResetWorkingRegisters()
|
||||
{
|
||||
this.AF.Word = this.BC.Word = this.DE.Word = this.HL.Word = (ushort)Mask.Sixteen;
|
||||
|
@@ -92,6 +92,11 @@ namespace EightBit
|
||||
return current;
|
||||
}
|
||||
|
||||
protected virtual byte FetchInstruction()
|
||||
{
|
||||
return this.FetchByte();
|
||||
}
|
||||
|
||||
public void Execute(byte value)
|
||||
{
|
||||
this.OpCode = value;
|
||||
|
@@ -54,14 +54,9 @@ namespace Intel8080
|
||||
{
|
||||
this.HandleINT();
|
||||
}
|
||||
else if (this.HALT.Lowered())
|
||||
{
|
||||
_ = this.FetchByte();
|
||||
this.Execute(0); // NOP
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Execute(this.FetchByte());
|
||||
this.Execute(this.FetchInstruction());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -224,14 +224,9 @@ namespace LR35902
|
||||
{
|
||||
this.HandleINT();
|
||||
}
|
||||
else if (this.HALT.Lowered())
|
||||
{
|
||||
_ = this.FetchByte();
|
||||
this.Execute(0); // NOP
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Execute(this.FetchByte());
|
||||
this.Execute(this.FetchInstruction());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -516,7 +516,7 @@ namespace M6502
|
||||
|
||||
if (this.RDY.Raised())
|
||||
{
|
||||
this.FetchInstruction();
|
||||
this.OpCode = this.FetchInstruction();
|
||||
if (this.RESET.Lowered())
|
||||
{
|
||||
this.HandleRESET();
|
||||
@@ -536,17 +536,19 @@ namespace M6502
|
||||
}
|
||||
}
|
||||
|
||||
private void FetchInstruction()
|
||||
protected override byte FetchInstruction()
|
||||
{
|
||||
this.LowerSYNC();
|
||||
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();
|
||||
this.OpCode = this.ReadFromBus();
|
||||
var returned = this.ReadFromBus();
|
||||
|
||||
System.Diagnostics.Debug.Assert(this.Cycles == 1, "BUS read has introduced stray cycles");
|
||||
this.RaiseSYNC();
|
||||
|
||||
return returned;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
24
Z80/Z80.cs
24
Z80/Z80.cs
@@ -142,7 +142,8 @@ namespace Z80
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
else if (this.HALT.Lowered())
|
||||
|
||||
if (!handled)
|
||||
{
|
||||
// ** From the Z80 CPU User Manual
|
||||
// When a software HALT instruction is executed, the CPU executes NOPs until an interrupt
|
||||
@@ -158,14 +159,7 @@ namespace Z80
|
||||
// received from the memory is ignored and an NOP instruction is forced internally to the
|
||||
// CPU.The HALT acknowledge signal is active during this time indicating that the processor
|
||||
// is in the HALT state.
|
||||
_ = this.FetchInitialOpCode();
|
||||
this.Execute(0); // NOP
|
||||
handled = true;
|
||||
}
|
||||
|
||||
if (!handled)
|
||||
{
|
||||
this.Execute(this.FetchInitialOpCode());
|
||||
this.Execute(this.FetchInstruction());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1535,7 +1529,7 @@ namespace Z80
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Execute(this.FetchInitialOpCode());
|
||||
this.Execute(this.FetchInstruction());
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -1585,15 +1579,15 @@ namespace Z80
|
||||
break;
|
||||
case 1: // DD prefix
|
||||
this._displaced = this._prefixDD = true;
|
||||
this.Execute(this.FetchInitialOpCode());
|
||||
this.Execute(this.FetchInstruction());
|
||||
break;
|
||||
case 2: // ED prefix
|
||||
this._prefixED = true;
|
||||
this.Execute(this.FetchInitialOpCode());
|
||||
this.Execute(this.FetchInstruction());
|
||||
break;
|
||||
case 3: // FD prefix
|
||||
this._displaced = this._prefixFD = true;
|
||||
this.Execute(this.FetchInitialOpCode());
|
||||
this.Execute(this.FetchInstruction());
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException("Invalid operation mode");
|
||||
@@ -1680,10 +1674,10 @@ namespace Z80
|
||||
// before the RD signal becomes inactive. Clock states T3 and T4 of a fetch cycle are used to
|
||||
// _refresh dynamic memories. The CPU uses this time to decode and execute the fetched
|
||||
// instruction so that no other concurrent operation can be performed.
|
||||
private byte FetchInitialOpCode()
|
||||
protected override byte FetchInstruction()
|
||||
{
|
||||
this.LowerM1();
|
||||
var returned = this.FetchByte();
|
||||
var returned = base.FetchInstruction();
|
||||
this.RaiseM1();
|
||||
return returned;
|
||||
}
|
||||
|
Reference in New Issue
Block a user