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

View File

@ -28,16 +28,22 @@ namespace EightBit
public virtual void RaisePOWER() public virtual void RaisePOWER()
{ {
this.OnRaisingPOWER(); if (this.POWER.Lowered())
this.POWER.Raise(); {
this.OnRaisedPOWER(); this.OnRaisingPOWER();
this.POWER.Raise();
this.OnRaisedPOWER();
}
} }
public virtual void LowerPOWER() public virtual void LowerPOWER()
{ {
this.OnLoweringPOWER(); if (this.POWER.Raised())
this.POWER.Lower(); {
this.OnLoweredPOWER(); this.OnLoweringPOWER();
this.POWER.Lower();
this.OnLoweredPOWER();
}
} }
protected virtual void OnRaisingPOWER() => this.RaisingPOWER?.Invoke(this, EventArgs.Empty); protected virtual void OnRaisingPOWER() => this.RaisingPOWER?.Invoke(this, EventArgs.Empty);

View File

@ -64,25 +64,24 @@ namespace EightBit
public IntelOpCodeDecoded GetDecodedOpCode(byte opCode) => this.decodedOpCodes[opCode]; 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() public virtual void RaiseHALT()
{ {
this.OnRaisingHALT(); if (this.HALT.Lowered())
this.HALT.Raise(); {
this.OnRaisedHALT(); this.OnRaisingHALT();
this.HALT.Raise();
this.OnRaisedHALT();
}
} }
public virtual void LowerHALT() public virtual void LowerHALT()
{ {
this.OnLoweringHALT(); if (this.HALT.Raised())
this.HALT.Lower(); {
this.OnLoweredHALT(); 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); 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]; 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 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 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() protected override void HandleRESET()
{ {

View File

@ -78,30 +78,42 @@ namespace EightBit
public virtual void RaiseRESET() public virtual void RaiseRESET()
{ {
this.OnRaisingRESET(); if (this.RESET.Lowered())
this.RESET.Raise(); {
this.OnRaisedRESET(); this.OnRaisingRESET();
this.RESET.Raise();
this.OnRaisedRESET();
}
} }
public virtual void LowerRESET() public virtual void LowerRESET()
{ {
this.OnLoweringRESET(); if (this.RESET.Raised())
this.RESET.Lower(); {
this.OnLoweredRESET(); this.OnLoweringRESET();
this.RESET.Lower();
this.OnLoweredRESET();
}
} }
public virtual void RaiseINT() public virtual void RaiseINT()
{ {
this.OnRaisingINT(); if (this.INT.Lowered())
this.INT.Raise(); {
this.OnRaisedINT(); this.OnRaisingINT();
this.INT.Raise();
this.OnRaisedINT();
}
} }
public virtual void LowerINT() public virtual void LowerINT()
{ {
this.OnLoweringINT(); if (this.INT.Raised())
this.INT.Lower(); {
this.OnLoweredINT(); this.OnLoweringINT();
this.INT.Lower();
this.OnLoweredINT();
}
} }
protected virtual void OnRaisingRESET() => this.RaisingRESET?.Invoke(this, EventArgs.Empty); protected virtual void OnRaisingRESET() => this.RaisingRESET?.Invoke(this, EventArgs.Empty);

View File

@ -95,57 +95,64 @@ namespace EightBit
private int Carry => this.P & (byte)StatusBits.CF; private int Carry => this.P & (byte)StatusBits.CF;
public override void RaisePOWER()
{
base.RaisePOWER();
this.X = (byte)Bits.Bit7;
this.Y = 0;
this.A = 0;
this.P = (byte)StatusBits.RF;
this.S = (byte)Mask.Mask8;
this.LowerSYNC();
}
public virtual void RaiseNMI() public virtual void RaiseNMI()
{ {
this.OnRaisingNMI(); if (this.NMI.Lowered())
this.NMI.Raise(); {
this.OnRaisedNMI(); this.OnRaisingNMI();
this.NMI.Raise();
this.OnRaisedNMI();
}
} }
public virtual void LowerNMI() public virtual void LowerNMI()
{ {
this.OnLoweringNMI(); if (this.NMI.Raised())
this.NMI.Lower(); {
this.OnLoweredNMI(); this.OnLoweringNMI();
this.NMI.Lower();
this.OnLoweredNMI();
}
} }
public virtual void RaiseSO() public virtual void RaiseSO()
{ {
this.OnRaisingSO(); if (this.SO.Lowered())
this.SO.Raise(); {
this.OnRaisedSO(); this.OnRaisingSO();
this.SO.Raise();
this.OnRaisedSO();
}
} }
public virtual void LowerSO() public virtual void LowerSO()
{ {
this.OnLoweringSO(); if (this.SO.Raised())
this.SO.Lower(); {
this.OnLoweredSO(); this.OnLoweringSO();
this.SO.Lower();
this.OnLoweredSO();
}
} }
public virtual void RaiseRDY() public virtual void RaiseRDY()
{ {
this.OnRaisingRDY(); if (this.RDY.Lowered())
this.RDY.Raise(); {
this.OnRaisedRDY(); this.OnRaisingRDY();
this.RDY.Raise();
this.OnRaisedRDY();
}
} }
public virtual void LowerRDY() public virtual void LowerRDY()
{ {
this.OnLoweringRDY(); if (this.RDY.Raised())
this.RDY.Lower(); {
this.OnLoweredRDY(); this.OnLoweringRDY();
this.RDY.Lower();
this.OnLoweredRDY();
}
} }
public override int Execute() public override int Execute()
@ -502,6 +509,17 @@ namespace EightBit
protected virtual void OnLoweredRDY() => this.LoweredRDY?.Invoke(this, EventArgs.Empty); protected virtual void OnLoweredRDY() => this.LoweredRDY?.Invoke(this, EventArgs.Empty);
protected override void OnRaisedPOWER()
{
this.X = (byte)Bits.Bit7;
this.Y = 0;
this.A = 0;
this.P = (byte)StatusBits.RF;
this.S = (byte)Mask.Mask8;
this.LowerSYNC();
base.OnRaisedPOWER();
}
protected override byte Pop() => this.BusRead(++this.S, 1); protected override byte Pop() => this.BusRead(++this.S, 1);
protected override void Push(byte value) => this.BusWrite(this.S--, 1, value); protected override void Push(byte value) => this.BusWrite(this.S--, 1, value);

View File

@ -221,81 +221,111 @@
return this.Cycles; return this.Cycles;
} }
public override void RaisePOWER()
{
base.RaisePOWER();
this.LowerBA();
this.LowerBS();
}
public void RaiseNMI() public void RaiseNMI()
{ {
this.OnRaisingNMI(); if (this.NMI.Lowered())
this.NMI.Raise(); {
this.OnRaisedNMI(); this.OnRaisingNMI();
this.NMI.Raise();
this.OnRaisedNMI();
}
} }
public void LowerNMI() public void LowerNMI()
{ {
this.OnLoweringNMI(); if (this.NMI.Raised())
this.NMI.Lower(); {
this.OnLoweredNMI(); this.OnLoweringNMI();
this.NMI.Lower();
this.OnLoweredNMI();
}
} }
public void RaiseFIRQ() public void RaiseFIRQ()
{ {
this.OnRaisingFIRQ(); if (this.FIRQ.Lowered())
this.FIRQ.Raise(); {
this.OnRaisedFIRQ(); this.OnRaisingFIRQ();
this.FIRQ.Raise();
this.OnRaisedFIRQ();
}
} }
public void LowerFIRQ() public void LowerFIRQ()
{ {
this.OnLoweringFIRQ(); if (this.FIRQ.Raised())
this.FIRQ.Lower(); {
this.OnLoweredFIRQ(); this.OnLoweringFIRQ();
this.FIRQ.Lower();
this.OnLoweredFIRQ();
}
} }
public void RaiseHALT() public void RaiseHALT()
{ {
this.OnRaisingHALT(); if (this.HALT.Lowered())
this.HALT.Raise(); {
this.OnRaisedHALT(); this.OnRaisingHALT();
this.HALT.Raise();
this.OnRaisedHALT();
}
} }
public void LowerHALT() public void LowerHALT()
{ {
this.OnLoweringHALT(); if (this.HALT.Raised())
this.HALT.Lower(); {
this.OnLoweredHALT(); this.OnLoweringHALT();
this.HALT.Lower();
this.OnLoweredHALT();
}
} }
public void RaiseBA() public void RaiseBA()
{ {
this.OnRaisingBA(); if (this.BA.Lowered())
this.BA.Raise(); {
this.OnRaisedBA(); this.OnRaisingBA();
this.BA.Raise();
this.OnRaisedBA();
}
} }
public void LowerBA() public void LowerBA()
{ {
this.OnLoweringBA(); if (this.BA.Raised())
this.BA.Lower(); {
this.OnLoweredBA(); this.OnLoweringBA();
this.BA.Lower();
this.OnLoweredBA();
}
} }
public void RaiseBS() public void RaiseBS()
{ {
this.OnRaisingBS(); if (this.BS.Lowered())
this.BS.Raise(); {
this.OnRaisedBS(); this.OnRaisingBS();
this.BS.Raise();
this.OnRaisedBS();
}
} }
public void LowerBS() public void LowerBS()
{ {
this.OnLoweringBS(); if (this.BS.Raised())
this.BS.Lower(); {
this.OnLoweredBS(); this.OnLoweringBS();
this.BS.Lower();
this.OnLoweredBS();
}
}
protected override void OnRaisedPOWER()
{
this.LowerBA();
this.LowerBS();
base.OnRaisedPOWER();
} }
protected override void HandleRESET() protected override void HandleRESET()

View File

@ -337,12 +337,6 @@ namespace EightBit
} }
} }
public override void RaisePOWER()
{
base.RaisePOWER();
this.startup = StartupCondition.ColdStart;
}
public void MarkTransmitComplete() public void MarkTransmitComplete()
{ {
this.statusTDRE = this.CTS.Lowered(); this.statusTDRE = this.CTS.Lowered();
@ -383,6 +377,12 @@ namespace EightBit
return returned; return returned;
} }
protected override void OnRaisedPOWER()
{
this.startup = StartupCondition.ColdStart;
base.OnRaisedPOWER();
}
protected override void OnTicked() protected override void OnTicked()
{ {
base.OnTicked(); base.OnTicked();

View File

@ -108,53 +108,44 @@ namespace EightBit
public void ExxAF() => this.accumulatorFlagsSet ^= 1; public void ExxAF() => this.accumulatorFlagsSet ^= 1;
public override void RaisePOWER()
{
base.RaisePOWER();
this.RaiseM1();
this.DisableInterrupts();
this.IM = 0;
this.REFRESH = new RefreshRegister(0);
this.IV = (byte)Mask.Mask8;
this.ExxAF();
this.AF.Word = (ushort)Mask.Mask16;
this.Exx();
this.IX.Word = this.IY.Word = this.BC.Word = this.DE.Word = this.HL.Word = (ushort)Mask.Mask16;
this.prefixCB = this.prefixDD = this.prefixED = false;
}
public virtual void RaiseNMI() public virtual void RaiseNMI()
{ {
this.OnRaisingNMI(); if (this.NMI.Lowered())
this.NMI.Raise(); {
this.OnRaisedNMI(); this.OnRaisingNMI();
this.NMI.Raise();
this.OnRaisedNMI();
}
} }
public virtual void LowerNMI() public virtual void LowerNMI()
{ {
this.OnLoweringNMI(); if (this.NMI.Raised())
this.NMI.Lower(); {
this.OnLoweredNMI(); this.OnLoweringNMI();
this.NMI.Lower();
this.OnLoweredNMI();
}
} }
public virtual void RaiseM1() public virtual void RaiseM1()
{ {
this.OnRaisingM1(); if (this.M1.Lowered())
this.M1.Raise(); {
this.OnRaisedM1(); this.OnRaisingM1();
this.M1.Raise();
this.OnRaisedM1();
}
} }
public virtual void LowerM1() public virtual void LowerM1()
{ {
this.OnLoweringM1(); if (this.M1.Raised())
this.M1.Lower(); {
this.OnLoweredM1(); this.OnLoweringM1();
this.M1.Lower();
this.OnLoweredM1();
}
} }
public override int Execute() public override int Execute()
@ -228,6 +219,26 @@ namespace EightBit
return this.Cycles; return this.Cycles;
} }
protected override void OnRaisedPOWER()
{
this.RaiseM1();
this.DisableInterrupts();
this.IM = 0;
this.REFRESH = new RefreshRegister(0);
this.IV = (byte)Mask.Mask8;
this.AF.Word = this.IX.Word = this.IY.Word = this.BC.Word = this.DE.Word = this.HL.Word = (ushort)Mask.Mask16;
this.ExxAF();
this.Exx();
this.prefixCB = this.prefixDD = this.prefixED = false;
base.OnRaisedPOWER();
}
protected virtual void OnExecutingInstruction() => this.ExecutingInstruction?.Invoke(this, EventArgs.Empty); protected virtual void OnExecutingInstruction() => this.ExecutingInstruction?.Invoke(this, EventArgs.Empty);
protected virtual void OnExecutedInstruction() => this.ExecutedInstruction?.Invoke(this, EventArgs.Empty); protected virtual void OnExecutedInstruction() => this.ExecutedInstruction?.Invoke(this, EventArgs.Empty);