Tighten up the sequence associated with changing pin levels + fix persistent HALT/PC bug

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon
2019-09-06 22:50:21 +01:00
parent bc491884b0
commit f01e3e0430
7 changed files with 229 additions and 138 deletions
+12 -6
View File
@@ -28,16 +28,22 @@ namespace EightBit
public virtual void RaisePOWER()
{
this.OnRaisingPOWER();
this.POWER.Raise();
this.OnRaisedPOWER();
if (this.POWER.Lowered())
{
this.OnRaisingPOWER();
this.POWER.Raise();
this.OnRaisedPOWER();
}
}
public virtual void LowerPOWER()
{
this.OnLoweringPOWER();
this.POWER.Lower();
this.OnLoweredPOWER();
if (this.POWER.Raised())
{
this.OnLoweringPOWER();
this.POWER.Lower();
this.OnLoweredPOWER();
}
}
protected virtual void OnRaisingPOWER() => this.RaisingPOWER?.Invoke(this, EventArgs.Empty);
+29 -15
View File
@@ -64,25 +64,24 @@ namespace EightBit
public IntelOpCodeDecoded GetDecodedOpCode(byte opCode) => this.decodedOpCodes[opCode];
public override void RaisePOWER()
{
base.RaisePOWER();
this.RaiseHALT();
this.SP.Word = this.AF.Word = this.BC.Word = this.DE.Word = this.HL.Word = (ushort)Mask.Mask16;
}
public virtual void RaiseHALT()
{
this.OnRaisingHALT();
this.HALT.Raise();
this.OnRaisedHALT();
if (this.HALT.Lowered())
{
this.OnRaisingHALT();
this.HALT.Raise();
this.OnRaisedHALT();
}
}
public virtual void LowerHALT()
{
this.OnLoweringHALT();
this.HALT.Lower();
this.OnLoweredHALT();
if (this.HALT.Raised())
{
this.OnLoweringHALT();
this.HALT.Lower();
this.OnLoweredHALT();
}
}
protected static int BuildHalfCarryIndex(byte before, byte value, int calculation) => ((before & 0x88) >> 1) | ((value & 0x88) >> 2) | ((calculation & 0x88) >> 3);
@@ -99,13 +98,28 @@ namespace EightBit
return HalfCarryTableSub[index & (int)Mask.Mask3];
}
protected override void OnRaisedPOWER()
{
this.RaiseHALT();
this.SP.Word = this.AF.Word = this.BC.Word = this.DE.Word = this.HL.Word = (ushort)Mask.Mask16;
base.OnRaisedPOWER();
}
protected virtual void OnRaisingHALT() => this.RaisingHALT?.Invoke(this, EventArgs.Empty);
protected virtual void OnRaisedHALT() => this.RaisedHALT?.Invoke(this, EventArgs.Empty);
protected virtual void OnRaisedHALT()
{
++this.PC.Word; // Release the PC from HALT instruction
this.RaisedHALT?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnLoweringHALT() => this.LoweringHALT?.Invoke(this, EventArgs.Empty);
protected virtual void OnLoweredHALT() => this.LoweredHALT?.Invoke(this, EventArgs.Empty);
protected virtual void OnLoweredHALT()
{
--this.PC.Word; // Keep the PC on the HALT instruction (i.e. executing NOP)
this.LoweredHALT?.Invoke(this, EventArgs.Empty);
}
protected override void HandleRESET()
{
+24 -12
View File
@@ -78,30 +78,42 @@ namespace EightBit
public virtual void RaiseRESET()
{
this.OnRaisingRESET();
this.RESET.Raise();
this.OnRaisedRESET();
if (this.RESET.Lowered())
{
this.OnRaisingRESET();
this.RESET.Raise();
this.OnRaisedRESET();
}
}
public virtual void LowerRESET()
{
this.OnLoweringRESET();
this.RESET.Lower();
this.OnLoweredRESET();
if (this.RESET.Raised())
{
this.OnLoweringRESET();
this.RESET.Lower();
this.OnLoweredRESET();
}
}
public virtual void RaiseINT()
{
this.OnRaisingINT();
this.INT.Raise();
this.OnRaisedINT();
if (this.INT.Lowered())
{
this.OnRaisingINT();
this.INT.Raise();
this.OnRaisedINT();
}
}
public virtual void LowerINT()
{
this.OnLoweringINT();
this.INT.Lower();
this.OnLoweredINT();
if (this.INT.Raised())
{
this.OnLoweringINT();
this.INT.Lower();
this.OnLoweredINT();
}
}
protected virtual void OnRaisingRESET() => this.RaisingRESET?.Invoke(this, EventArgs.Empty);