From 6fe19d8bbe295575c8a5c5d5b15b5be8beb2bc64 Mon Sep 17 00:00:00 2001 From: KallDrexx Date: Wed, 31 Dec 2025 15:24:31 -0500 Subject: [PATCH] Testrunner ignore N and V flags in bcd mode --- .../Compilation/InstructionConverter.cs | 3 +++ .../TestRunner.cs | 22 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Dotnet6502.Common/Compilation/InstructionConverter.cs b/src/Dotnet6502.Common/Compilation/InstructionConverter.cs index 4b8a6dc..be0ed74 100644 --- a/src/Dotnet6502.Common/Compilation/InstructionConverter.cs +++ b/src/Dotnet6502.Common/Compilation/InstructionConverter.cs @@ -210,6 +210,9 @@ public static class InstructionConverter var setAcc = new Ir6502.Copy(result, accumulator); + // Note: I can't find reliable info on what the zero flag should be in decimal mode. 6502 test suite + // claims it should follow non-BCD logic, but other references state it should be zero result from BCD logic. + // For now I'm just going to assume it follows a zero result but will probably revisit. var setZeroFlag = new Ir6502.Binary( Ir6502.BinaryOperator.Equals, result, diff --git a/src/Dotnet6502.ComprehensiveTestRunner/TestRunner.cs b/src/Dotnet6502.ComprehensiveTestRunner/TestRunner.cs index 52f8449..76ca680 100644 --- a/src/Dotnet6502.ComprehensiveTestRunner/TestRunner.cs +++ b/src/Dotnet6502.ComprehensiveTestRunner/TestRunner.cs @@ -1,5 +1,6 @@ using System.Text.Json; using Dotnet6502.Common.Compilation; +using Dotnet6502.Common.Hardware; using NESDecompiler.Core.CPU; using NESDecompiler.Core.Disassembly; @@ -131,10 +132,25 @@ public static class TestRunner errorMessages.Add($"Y: expected {testCase.Final.Y}, actual {jit.TestHal.YRegister}"); } - if (jit.TestHal.ProcessorStatus != testCase.Final.P) + // If we are in decimal mode, we need to ignore the negative and overflow flags, as they are + // undefined behavior. + if (jit.TestHal.GetFlag(CpuStatusFlags.Decimal)) { - hasFailure = true; - errorMessages.Add($"P: expected {testCase.Final.P}, actual {jit.TestHal.ProcessorStatus}"); + var testValue = jit.TestHal.ProcessorStatus & 0b00111111; + var expectedValue = testCase.Final.P & 0b00111111; + if (testValue != expectedValue) + { + hasFailure = true; + errorMessages.Add($"Decimal mode P: expected {expectedValue}, actual {testValue}"); + } + } + else + { + if (jit.TestHal.ProcessorStatus != testCase.Final.P) + { + hasFailure = true; + errorMessages.Add($"P: expected {testCase.Final.P}, actual {jit.TestHal.ProcessorStatus}"); + } } if (jit.TestHal.StackPointer != testCase.Final.S)