diff --git a/MC6809/MC6809.Test/Program.cs b/MC6809/MC6809.Test/Program.cs index c9d10fd..ee4847a 100644 --- a/MC6809/MC6809.Test/Program.cs +++ b/MC6809/MC6809.Test/Program.cs @@ -11,7 +11,7 @@ namespace EightBit var configuration = new Configuration(); #if DEBUG - configuration.DebugMode = true; + //configuration.DebugMode = true; #endif var harness = new TestHarness(configuration); diff --git a/MC6809/MC6809.UnitTest/AsrTests.cs b/MC6809/MC6809.UnitTest/AsrTests.cs index 8e9c042..692ce21 100644 --- a/MC6809/MC6809.UnitTest/AsrTests.cs +++ b/MC6809/MC6809.UnitTest/AsrTests.cs @@ -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); + } } } diff --git a/MC6809/MC6809.cs b/MC6809/MC6809.cs index 6a28912..736826c 100644 --- a/MC6809/MC6809.cs +++ b/MC6809/MC6809.cs @@ -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