mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2026-10-24 14:05:42 +00:00
Add half-carry tests
This commit is contained in:
1 parent
37ed8b4d11
commit
fc1ad39a8d
3 files changed
+74
No files matched your search
@@ -59,6 +59,32 @@ namespace MC6809.UnitTest
|
||||
Assert.AreEqual(2, this.cpu.Cycles);
|
||||
}
|
||||
|
||||
// 0x08 + 0x08 = 0x10: carry out of low nibble sets H
|
||||
[TestMethod]
|
||||
public void TestImmediateADDA_half_carry_set()
|
||||
{
|
||||
this.board.Poke(0, 0x8b);
|
||||
this.board.Poke(1, 0x08);
|
||||
this.cpu.CC = 0;
|
||||
this.cpu.A = 0x08;
|
||||
this.cpu.Step();
|
||||
Assert.AreEqual(0x10, this.cpu.A);
|
||||
Assert.IsTrue(this.cpu.HalfCarry);
|
||||
}
|
||||
|
||||
// 0x01 + 0x01 = 0x02: no carry out of low nibble, H clear
|
||||
[TestMethod]
|
||||
public void TestImmediateADDA_half_carry_clear()
|
||||
{
|
||||
this.board.Poke(0, 0x8b);
|
||||
this.board.Poke(1, 0x01);
|
||||
this.cpu.CC = 0;
|
||||
this.cpu.A = 0x01;
|
||||
this.cpu.Step();
|
||||
Assert.AreEqual(0x02, this.cpu.A);
|
||||
Assert.IsFalse(this.cpu.HalfCarry);
|
||||
}
|
||||
|
||||
// The overflow (V) bit indicates signed two’s complement overflow, which occurs when the
|
||||
// sign bit differs from the carry bit after an arithmetic operation.
|
||||
// A=0x03 + 0xFF becomes 0x02
|
||||
|
||||
@@ -69,5 +69,29 @@ namespace MC6809.UnitTest
|
||||
Assert.IsTrue(this.cpu.Negative);
|
||||
Assert.AreEqual(2, this.cpu.Cycles);
|
||||
}
|
||||
|
||||
// DEC does not affect H: H=1 before must be H=1 after
|
||||
[TestMethod]
|
||||
public void TestInherentDECA_preserves_half_carry_set()
|
||||
{
|
||||
this.board.Poke(0, 0x4a);
|
||||
this.cpu.CC = (byte)StatusBits.HF;
|
||||
this.cpu.A = 0x10;
|
||||
this.cpu.Step();
|
||||
Assert.AreEqual(0x0f, this.cpu.A);
|
||||
Assert.IsTrue(this.cpu.HalfCarry);
|
||||
}
|
||||
|
||||
// DEC does not affect H: H=0 before must be H=0 after
|
||||
[TestMethod]
|
||||
public void TestInherentDECA_preserves_half_carry_clear()
|
||||
{
|
||||
this.board.Poke(0, 0x4a);
|
||||
this.cpu.CC = 0;
|
||||
this.cpu.A = 0x10;
|
||||
this.cpu.Step();
|
||||
Assert.AreEqual(0x0f, this.cpu.A);
|
||||
Assert.IsFalse(this.cpu.HalfCarry);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,5 +67,29 @@ namespace MC6809.UnitTest
|
||||
Assert.IsFalse(this.cpu.Carry);
|
||||
Assert.AreEqual(2, this.cpu.Cycles);
|
||||
}
|
||||
|
||||
// INC does not affect H: H=1 before must be H=1 after
|
||||
[TestMethod]
|
||||
public void TestInherentINCA_preserves_half_carry_set()
|
||||
{
|
||||
this.board.Poke(0, 0x4c);
|
||||
this.cpu.CC = (byte)StatusBits.HF;
|
||||
this.cpu.A = 0x01;
|
||||
this.cpu.Step();
|
||||
Assert.AreEqual(0x02, this.cpu.A);
|
||||
Assert.IsTrue(this.cpu.HalfCarry);
|
||||
}
|
||||
|
||||
// INC does not affect H: a nibble-crossing increment must not set H=1
|
||||
[TestMethod]
|
||||
public void TestInherentINCA_preserves_half_carry_clear()
|
||||
{
|
||||
this.board.Poke(0, 0x4c);
|
||||
this.cpu.CC = 0;
|
||||
this.cpu.A = 0x0f;
|
||||
this.cpu.Step();
|
||||
Assert.AreEqual(0x10, this.cpu.A);
|
||||
Assert.IsFalse(this.cpu.HalfCarry);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user