Fix ASR implementation. Unify ANDCC / ORCC cycle waste

This commit is contained in:
Adrian Conlon committed 2026-05-09 17:31:05 +01:00
1 parent 1c485bca22
commit da7f362754
3 files changed
+32 -9

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@ namespace EightBit
var configuration = new Configuration();
#if DEBUG
configuration.DebugMode = true;
//configuration.DebugMode = true;
#endif
var harness = new TestHarness(configuration);
+26
View File
@@ -39,5 +39,31 @@ namespace MC6809.UnitTest
Assert.AreNotEqual(0, this.cpu.Negative);
Assert.AreEqual(2, this.cpu.Cycles);
}
// ASR of positive value 0x40: sign bit (0) must be preserved, not forced to 1
[TestMethod]
public void TestInherentPositive()
{
this.cpu.A = 0x40;
this.cpu.Step();
Assert.AreEqual(0x20, this.cpu.A);
Assert.AreEqual(0, this.cpu.Carry);
Assert.AreEqual(0, this.cpu.Zero);
Assert.AreEqual(0, this.cpu.Negative);
Assert.AreEqual(2, this.cpu.Cycles);
}
// ASR of 0x01: carry set, result zero
[TestMethod]
public void TestInherentOne()
{
this.cpu.A = 0x01;
this.cpu.Step();
Assert.AreEqual(0x00, this.cpu.A);
Assert.AreNotEqual(0, this.cpu.Carry);
Assert.AreNotEqual(0, this.cpu.Zero);
Assert.AreEqual(0, this.cpu.Negative);
Assert.AreEqual(2, this.cpu.Cycles);
}
}
}
+5 -8
View File
@@ -1176,8 +1176,6 @@ namespace MC6809
}
}
private void SwallowFetch() => _ = this.FetchByte();
private void SwallowCurrent(int ticks = 1)
{
for (int i = 0; i < ticks; i++)
@@ -1219,8 +1217,7 @@ namespace MC6809
}
else
{
this.FetchByte();
this.Execute(this.Bus.Data);
this.Execute(this.FetchByte());
}
}
@@ -1799,7 +1796,7 @@ namespace MC6809
private byte ArithmeticShiftRight(byte operand)
{
this.CC = SetBit(this.CC, StatusBits.CF, operand & (byte)Bits.Bit0);
var result = (byte)(operand >> 1 | (int)Bits.Bit7);
var result = (byte)(operand >> 1 | (operand & (byte)Bits.Bit7));
this.CC = this.AdjustNZ(result);
return result;
}
@@ -2049,8 +2046,8 @@ namespace MC6809
private void ORCC()
{
this.SwallowCurrent();
this.CC |= this.Bus.Data;
this.SwallowRead();
}
private void ORA() => this.A = this.Or(this.A);
@@ -2170,8 +2167,8 @@ namespace MC6809
private void SWI()
{
SwallowCurrent();
SwallowRead();
this.SwallowCurrent();
this.SwallowRead();
this.SaveEntireRegisterState();
this.CC = SetBit(this.CC, StatusBits.IF); // Disable IRQ
this.CC = SetBit(this.CC, StatusBits.FF); // Disable FIRQ