diff --git a/M6502/HarteTest_6502/TestRunner.cpp b/M6502/HarteTest_6502/TestRunner.cpp index be6e4f6..9ee733f 100644 --- a/M6502/HarteTest_6502/TestRunner.cpp +++ b/M6502/HarteTest_6502/TestRunner.cpp @@ -1,6 +1,9 @@ #include "stdafx.h" #include "TestRunner.h" +std::set TestRunner::m_undocumented_opcodes; +bool TestRunner::m_undocumented_opcodes_initialised = false; + TestRunner::TestRunner(const test_t& test) : m_test(test) {} @@ -128,10 +131,10 @@ void TestRunner::initialiseState() { CPU().Y() = starting.y(); CPU().P() = starting.p(); const auto& ram = starting.ram(); - for (auto entry : ram) - RAM().poke(entry.address(), entry.value()); - - m_actualCycles.clear(); + for (auto entry : ram) { + const byte_t byte(entry); + RAM().poke(byte.address(), byte.value()); + } } bool TestRunner::checkState() { @@ -162,7 +165,8 @@ bool TestRunner::checkState() { const auto& ram = finished.ram(); bool ram_problem = false; for (auto entry : ram) { - const auto ram_good = check("RAM", entry.address(), entry.value(), RAM().peek(entry.address())); + const byte_t byte(entry); + const auto ram_good = check("RAM", byte.address(), byte.value(), RAM().peek(byte.address())); if (!ram_good && !ram_problem) ram_problem = true; } @@ -231,6 +235,7 @@ void TestRunner::check() { } void TestRunner::seedUndocumentedOpcodes() { + if (m_undocumented_opcodes_initialised) return; m_undocumented_opcodes = { 0x02, 0x03, 0x04, 0x07, 0x0b, 0x0c, 0x0f, 0x12, 0x13, 0x14, 0x17, 0x1a, 0x1b, 0x1c, 0x1f, @@ -249,4 +254,5 @@ void TestRunner::seedUndocumentedOpcodes() { 0xe2, 0xe3, 0xe7, 0xeb, 0xef, 0xf1, 0xf2, 0xf3, 0xf4, 0xf7, 0xfa, 0xfb, 0xfc, 0xff, }; + m_undocumented_opcodes_initialised = true; } \ No newline at end of file diff --git a/M6502/HarteTest_6502/TestRunner.h b/M6502/HarteTest_6502/TestRunner.h index 1efeec3..5809932 100644 --- a/M6502/HarteTest_6502/TestRunner.h +++ b/M6502/HarteTest_6502/TestRunner.h @@ -16,6 +16,9 @@ class TestRunner final : public EightBit::Bus { private: + static std::set m_undocumented_opcodes; + static bool m_undocumented_opcodes_initialised; + EightBit::Ram m_ram = 0x10000; EightBit::MOS6502 m_cpu = { *this }; EightBit::Symbols m_symbols; @@ -33,8 +36,6 @@ private: bool m_valid = true; bool m_undocumented = false; - std::set m_undocumented_opcodes; - void seedUndocumentedOpcodes(); void initialiseState(); [[nodiscard]] bool checkState(); diff --git a/M6502/HarteTest_6502/byte_t.cpp b/M6502/HarteTest_6502/byte_t.cpp index e47a2d8..ae616f9 100644 --- a/M6502/HarteTest_6502/byte_t.cpp +++ b/M6502/HarteTest_6502/byte_t.cpp @@ -1,8 +1,5 @@ #include "stdafx.h" #include "byte_t.h" -byte_t::byte_t(simdjson::dom::element input) noexcept -: byte_t(input.get_array()) {} - byte_t::byte_t(simdjson::dom::array input) noexcept : m_raw(input) {} diff --git a/M6502/HarteTest_6502/byte_t.h b/M6502/HarteTest_6502/byte_t.h index 2e8a0d2..a148f90 100644 --- a/M6502/HarteTest_6502/byte_t.h +++ b/M6502/HarteTest_6502/byte_t.h @@ -8,10 +8,14 @@ class byte_t final { private: const simdjson::dom::array m_raw; + [[nodiscard]] auto at(size_t idx) const noexcept { return m_raw.at(idx); } + [[nodiscard]] auto integer_at(size_t idx) const noexcept { return (int64_t)at(idx); } + [[nodiscard]] auto address_at(size_t idx) const noexcept { return (uint16_t)integer_at(idx); } + [[nodiscard]] auto byte_at(size_t idx) const noexcept { return (uint8_t)integer_at(idx); } + public: - byte_t(simdjson::dom::element input) noexcept; byte_t(simdjson::dom::array input) noexcept; - [[nodiscard]] auto address() const noexcept { return (uint16_t)(int64_t)m_raw.at(0); } - [[nodiscard]] auto value() const noexcept { return (uint8_t)(int64_t)m_raw.at(1); } + [[nodiscard]] auto address() const noexcept { return address_at(0); } + [[nodiscard]] auto value() const noexcept { return byte_at(1); } }; diff --git a/M6502/HarteTest_6502/cycles_t.h b/M6502/HarteTest_6502/cycles_t.h index 6d09bd6..267fa24 100644 --- a/M6502/HarteTest_6502/cycles_t.h +++ b/M6502/HarteTest_6502/cycles_t.h @@ -21,7 +21,5 @@ public: [[nodiscard]] auto size() const noexcept { return m_cycles.size(); } - void clear() { m_cycles.clear(); } - [[nodiscard]] const auto& operator[](size_t idx) const noexcept { return m_cycles[idx]; } }; diff --git a/M6502/HarteTest_6502/ram_t.cpp b/M6502/HarteTest_6502/ram_t.cpp index 0e89763..e223e87 100644 --- a/M6502/HarteTest_6502/ram_t.cpp +++ b/M6502/HarteTest_6502/ram_t.cpp @@ -1,14 +1,5 @@ #include "stdafx.h" #include "ram_t.h" -void ram_t::add(byte_t byte) { - assert(m_bytes.capacity() >= (m_bytes.size() + 1)); - m_bytes.push_back(byte); -} - -ram_t::ram_t(simdjson::dom::array input) { - assert(m_bytes.empty()); - m_bytes.reserve(input.size()); - for (auto entry : input) - add(entry); -} +ram_t::ram_t(simdjson::dom::array input) +: m_raw(input) {} diff --git a/M6502/HarteTest_6502/ram_t.h b/M6502/HarteTest_6502/ram_t.h index 217a082..ec37480 100644 --- a/M6502/HarteTest_6502/ram_t.h +++ b/M6502/HarteTest_6502/ram_t.h @@ -1,25 +1,16 @@ #pragma once -#include -#include - #include "simdjson/simdjson.h" #include "byte_t.h" class ram_t final { private: - std::vector m_bytes; + simdjson::dom::array m_raw;; public: ram_t(simdjson::dom::array input); - void add(byte_t byte); - - [[nodiscard]] auto begin() const noexcept { return m_bytes.begin(); } - [[nodiscard]] auto end() const noexcept { return m_bytes.end(); } - - [[nodiscard]] auto size() const noexcept { return m_bytes.size(); } - - [[nodiscard]] auto operator[](size_t idx) const noexcept { return m_bytes[idx]; } + [[nodiscard]] auto begin() const noexcept { return m_raw.begin(); } + [[nodiscard]] auto end() const noexcept { return m_raw.end(); } }; diff --git a/M6502/HarteTest_6502/state_t.h b/M6502/HarteTest_6502/state_t.h index 0863c3f..3dc38bf 100644 --- a/M6502/HarteTest_6502/state_t.h +++ b/M6502/HarteTest_6502/state_t.h @@ -10,14 +10,20 @@ class state_t final { private: const simdjson::dom::element m_raw; + [[nodiscard]] auto at(std::string key) const noexcept { return m_raw[key]; } + [[nodiscard]] auto integer_at(std::string key) const noexcept { return (int64_t)at(key); } + [[nodiscard]] auto address_at(std::string key) const noexcept { return (uint16_t)integer_at(key); } + [[nodiscard]] auto byte_at(std::string key) const noexcept { return (uint8_t)integer_at(key); } + [[nodiscard]] auto array_at(std::string key) const noexcept { return at(key).get_array(); } + public: state_t(simdjson::dom::element input); - [[nodiscard]] auto pc() const noexcept { return (uint16_t)(int64_t)m_raw["pc"]; } - [[nodiscard]] auto s() const noexcept { return (uint8_t)(int64_t)m_raw["s"]; } - [[nodiscard]] auto a() const noexcept { return (uint8_t)(int64_t)m_raw["a"]; } - [[nodiscard]] auto x() const noexcept { return (uint8_t)(int64_t)m_raw["x"]; } - [[nodiscard]] auto y() const noexcept { return (uint8_t)(int64_t)m_raw["y"]; } - [[nodiscard]] auto p() const noexcept { return (uint8_t)(int64_t)m_raw["p"]; } - [[nodiscard]] const auto ram() const noexcept { return ram_t(m_raw["ram"].get_array()); } + [[nodiscard]] auto pc() const noexcept { return address_at("pc"); } + [[nodiscard]] auto s() const noexcept { return byte_at("s"); } + [[nodiscard]] auto a() const noexcept { return byte_at("a"); } + [[nodiscard]] auto x() const noexcept { return byte_at("x"); } + [[nodiscard]] auto y() const noexcept { return byte_at("y"); } + [[nodiscard]] auto p() const noexcept { return byte_at("p"); } + [[nodiscard]] auto ram() const noexcept { return ram_t(array_at("ram")); } }; diff --git a/M6502/HarteTest_6502/test_t.h b/M6502/HarteTest_6502/test_t.h index 3539b93..1b9efef 100644 --- a/M6502/HarteTest_6502/test_t.h +++ b/M6502/HarteTest_6502/test_t.h @@ -11,11 +11,14 @@ class test_t final { private: simdjson::dom::element m_raw; + [[nodiscard]] auto at(std::string key) const noexcept { return m_raw[key]; } + [[nodiscard]] auto array_at(std::string key) const noexcept { return at(key).get_array(); } + public: test_t(simdjson::dom::element input); - [[nodiscard]] const auto name() const noexcept { return m_raw["name"]; } - [[nodiscard]] const auto initial_state() const noexcept { return state_t(m_raw["initial"]); } - [[nodiscard]] const auto final_state() const noexcept { return state_t(m_raw["final"]); } - [[nodiscard]] const auto cycles() const noexcept { return cycles_t(m_raw["cycles"].get_array()); } + [[nodiscard]] auto name() const noexcept { return at("name"); } + [[nodiscard]] auto initial_state() const noexcept { return state_t(at("initial")); } + [[nodiscard]] auto final_state() const noexcept { return state_t(at("final")); } + [[nodiscard]] auto cycles() const noexcept { return cycles_t(array_at("cycles")); } };