From 143a683602c4561fc36d67f32e0a3db0fd4125b7 Mon Sep 17 00:00:00 2001 From: ogamespec Date: Wed, 8 Mar 2023 20:17:07 +0300 Subject: [PATCH] UnitTest::DumpDecoder --- UnitTest/CoreUnitTest.cpp | 73 +++++++++++++++++++++++++++++++++++++++ UnitTest/CoreUnitTest.h | 6 ++++ UnitTest/UnitTest.cpp | 6 ++++ 3 files changed, 85 insertions(+) diff --git a/UnitTest/CoreUnitTest.cpp b/UnitTest/CoreUnitTest.cpp index ccf8f5e4..2d80879c 100644 --- a/UnitTest/CoreUnitTest.cpp +++ b/UnitTest/CoreUnitTest.cpp @@ -406,5 +406,78 @@ namespace M6502CoreUnitTest return true; } + bool UnitTest::DumpDecoder() + { + auto decoder = new M6502Core::Decoder; + + TriState* outputs; + + FILE* f; + fopen_s(&f, "decoder_sim.csv", "wt"); + fprintf(f, "inputs,outputs\n"); + + for (size_t inputs=0; inputs<(size_t)(1 << 14); inputs++) + { + DecoderInput decoder_in{}; + + // The lower six bits represent the Tx. The remaining high bits are IR. + + TriState IR[8]{}; + + for (int n = 0; n < 8; n++) + { + IR[n] = FromByte((inputs >> (6 + n)) & 1); + } + + decoder_in.n_IR0 = NOT(IR[0]); + decoder_in.n_IR1 = NOT(IR[1]); + decoder_in.IR01 = OR(IR[0], IR[1]); + decoder_in.n_IR2 = NOT(IR[2]); + decoder_in.IR2 = IR[2]; + decoder_in.n_IR3 = NOT(IR[3]); + decoder_in.IR3 = IR[3]; + decoder_in.n_IR4 = NOT(IR[4]); + decoder_in.IR4 = IR[4]; + decoder_in.n_IR5 = NOT(IR[5]); + decoder_in.IR5 = IR[5]; + decoder_in.n_IR6 = NOT(IR[6]); + decoder_in.IR6 = IR[6]; + decoder_in.n_IR7 = NOT(IR[7]); + decoder_in.IR7 = IR[7]; + + decoder_in.n_T0 = NOT(FromByte((inputs >> 0) & 1)); + decoder_in.n_T1X = NOT(FromByte((inputs >> 1) & 1)); + decoder_in.n_T2 = NOT(FromByte((inputs >> 2) & 1)); + decoder_in.n_T3 = NOT(FromByte((inputs >> 3) & 1)); + decoder_in.n_T4 = NOT(FromByte((inputs >> 4) & 1)); + decoder_in.n_T5 = NOT(FromByte((inputs >> 5) & 1)); + + decoder->sim(decoder_in.packed_bits, &outputs); + + // inputs, msb first + + for (int n = 13; n >= 0; n--) + { + size_t bit_val = (inputs >> n) & 1; + fprintf(f, "%d", bit_val); + } + fprintf(f, ","); + + // outputs, msb first + + for (int n = 129; n >= 0; n--) + { + uint8_t bit_val = ToByte(outputs[n]); + fprintf(f, "%d", bit_val); + } + + fprintf(f, "\n"); + } + + delete decoder; + fclose(f); + + return true; + } } diff --git a/UnitTest/CoreUnitTest.h b/UnitTest/CoreUnitTest.h index 1fb66366..7dcc3d52 100644 --- a/UnitTest/CoreUnitTest.h +++ b/UnitTest/CoreUnitTest.h @@ -37,5 +37,11 @@ namespace M6502CoreUnitTest /// /// bool ALU_UnitTest(); + + /// + /// Go through all 6502 decoder values and output them to CSV. + /// + /// + bool DumpDecoder(); }; } diff --git a/UnitTest/UnitTest.cpp b/UnitTest/UnitTest.cpp index 23ce1e06..1d08ad4c 100644 --- a/UnitTest/UnitTest.cpp +++ b/UnitTest/UnitTest.cpp @@ -76,6 +76,12 @@ namespace UnitTest M6502CoreUnitTest::UnitTest ut; Assert::IsTrue(ut.ALU_UnitTest()); } + + TEST_METHOD(DumpDecoder) + { + M6502CoreUnitTest::UnitTest ut; + Assert::IsTrue(ut.DumpDecoder()); + } }; TEST_CLASS(ApuUnitTest)