diff --git a/CPU_emu/CPU/CPU_CMD_Methods.cs b/CPU_emu/CPU/CPU_CMD_Methods.cs index 706adea..c556f8d 100644 --- a/CPU_emu/CPU/CPU_CMD_Methods.cs +++ b/CPU_emu/CPU/CPU_CMD_Methods.cs @@ -66,7 +66,7 @@ public void Cmd_BD() // Load Accumulator absolute X BD // LDA $nnnn,Y [Opcode(4)] - public void Cmd_B9() + public void Cmd_B9() // Load Accumulator absolute Y B9 { ushort addr = AddrAbsoluteY(); byte value = ReadByteFromMemory(addr); @@ -76,7 +76,7 @@ public void Cmd_B9() // LDA ($zz,X) – Indirect,X [Opcode(6)] - public void Cmd_A1() + public void Cmd_A1() // Load Accumulator indirect X A1 { ushort addr = AddrIndirectX(); byte value = ReadByteFromMemory(addr); @@ -86,7 +86,7 @@ public void Cmd_A1() // LDA ($zz),Y – Indirect,Y [Opcode(5)] - public void Cmd_B1() + public void Cmd_B1() // Load Accumulator indirect y B1 { ushort addr = AddrIndirectY(); byte value = ReadByteFromMemory(addr); diff --git a/CPU_emuTests/CPU_Tests.cs b/CPU_emuTests/CPU_Tests.cs index d15da71..f0c334c 100644 --- a/CPU_emuTests/CPU_Tests.cs +++ b/CPU_emuTests/CPU_Tests.cs @@ -462,7 +462,78 @@ public void Cmd_AD_Test(byte value, bool expectedZ, bool expectedN, byte expecte } - #endregion + // Load Accumulator absolute X BD + [TestCase(0xff, false, true, 0xff, 6)] + [TestCase(0x00, true, false, 0x00, 6)] + public void Cmd_BD_Test(byte value, bool expectedZ, bool expectedN, byte expectedA, int expectedCycles) + { + cpu.Reset(); + cpu.WriteByteToMemory(value, 0xFFEF); + cpu.WriteByteToMemory(0xEE, 0x200); + cpu.WriteByteToMemory(0xFF, 0x201); + cpu.SetRegister("X", 0x01); + cpu.SetPC(0x200); + + TestHelper.GetPrivateMethod("CallInstruction", cpu).Invoke(cpu, new object[] { cpu.GetType(), (byte)0xBD }); + + Assert.Multiple(() => + { + Assert.That(cpu.flags["Z"], Is.EqualTo(expectedZ), "Zero Flag"); + Assert.That(cpu.flags["N"], Is.EqualTo(expectedN), "Negative Flag"); + Assert.That(cpu.A, Is.EqualTo(expectedA), "Register A"); + Assert.That(cpu.CpuCycle, Is.EqualTo(expectedCycles), "CPU Cycles"); + }); + + } + + // Load Accumulator absolute Y B9 + [TestCase(0xff, false, true, 0xff, 6)] + [TestCase(0x00, true, false, 0x00, 6)] + public void Cmd_B9_Test(byte value, bool expectedZ, bool expectedN, byte expectedA, int expectedCycles) + { + cpu.Reset(); + cpu.WriteByteToMemory(value, 0xFFEF); + cpu.WriteByteToMemory(0xEE, 0x200); + cpu.WriteByteToMemory(0xFF, 0x201); + cpu.SetRegister("Y", 0x01); + cpu.SetPC(0x200); + + TestHelper.GetPrivateMethod("CallInstruction", cpu).Invoke(cpu, new object[] { cpu.GetType(), (byte)0xB9 }); + + Assert.Multiple(() => + { + Assert.That(cpu.flags["Z"], Is.EqualTo(expectedZ), "Zero Flag"); + Assert.That(cpu.flags["N"], Is.EqualTo(expectedN), "Negative Flag"); + Assert.That(cpu.A, Is.EqualTo(expectedA), "Register A"); + Assert.That(cpu.CpuCycle, Is.EqualTo(expectedCycles), "CPU Cycles"); + }); + + } + + // Load Accumulator indirect X A1 + [TestCase(0xff, false, true, 0xff, 7)] + [TestCase(0x00, true, false, 0x00, 7)] + public void Cmd_A1_Test(byte value, bool expectedZ, bool expectedN, byte expectedA, int expectedCycles) + { + cpu.Reset(); + cpu.WriteByteToMemory(value, 0xFFEF); + cpu.WriteByteToMemory(0xEF, 0x01); + cpu.WriteByteToMemory(0xFF, 0x02); + cpu.SetRegister("X", 0x01); + cpu.SetPC(0x200); + + TestHelper.GetPrivateMethod("CallInstruction", cpu).Invoke(cpu, new object[] { cpu.GetType(), (byte)0xA1 }); + + Assert.Multiple(() => + { + Assert.That(cpu.flags["Z"], Is.EqualTo(expectedZ), "Zero Flag"); + Assert.That(cpu.flags["N"], Is.EqualTo(expectedN), "Negative Flag"); + Assert.That(cpu.A, Is.EqualTo(expectedA), "Register A"); + Assert.That(cpu.CpuCycle, Is.EqualTo(expectedCycles), "CPU Cycles"); + }); + + } + #endregion #region LDX