From ab2b598942124132872ac51b7d0e9da539b375f7 Mon Sep 17 00:00:00 2001 From: Michael Bohn Date: Thu, 24 Jul 2025 17:51:37 +0200 Subject: [PATCH 1/3] Add test for cmd_BD --- CPU_emuTests/CPU_Tests.cs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/CPU_emuTests/CPU_Tests.cs b/CPU_emuTests/CPU_Tests.cs index d15da71..545248a 100644 --- a/CPU_emuTests/CPU_Tests.cs +++ b/CPU_emuTests/CPU_Tests.cs @@ -462,12 +462,35 @@ public void Cmd_AD_Test(byte value, bool expectedZ, bool expectedN, byte expecte } + // 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"); + }); + + } #endregion - #region LDX + #region LDX - // Test Load X immidiate A2 - [TestCase(0xff, ExpectedResult = new object[] { false, true, 0xff })] + // Test Load X immidiate A2 + [TestCase(0xff, ExpectedResult = new object[] { false, true, 0xff })] [TestCase(0x00, ExpectedResult = new object[] { true, false, 0x00 })] public object[] Cmd_A2_Test(byte b) { From 3c3a91498a1f8c5fda2637bd8a7b4330785d2dcc Mon Sep 17 00:00:00 2001 From: Michael Bohn Date: Thu, 24 Jul 2025 22:28:58 +0200 Subject: [PATCH 2/3] add some comments --- CPU_emu/CPU/CPU_CMD_Methods.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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); From c8b49acd6d6606a2488859f0bda0ffd890e36d2c Mon Sep 17 00:00:00 2001 From: Michael Bohn Date: Thu, 24 Jul 2025 22:30:45 +0200 Subject: [PATCH 3/3] add tests cmd_B9 & cmd_A1 --- CPU_emuTests/CPU_Tests.cs | 56 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/CPU_emuTests/CPU_Tests.cs b/CPU_emuTests/CPU_Tests.cs index 545248a..f0c334c 100644 --- a/CPU_emuTests/CPU_Tests.cs +++ b/CPU_emuTests/CPU_Tests.cs @@ -485,12 +485,60 @@ public void Cmd_BD_Test(byte value, bool expectedZ, bool expectedN, byte expecte }); } - #endregion - #region LDX + // 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"); + }); - // Test Load X immidiate A2 - [TestCase(0xff, ExpectedResult = new object[] { false, true, 0xff })] + } + + // 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 + + // Test Load X immidiate A2 + [TestCase(0xff, ExpectedResult = new object[] { false, true, 0xff })] [TestCase(0x00, ExpectedResult = new object[] { true, false, 0x00 })] public object[] Cmd_A2_Test(byte b) {