diff --git a/M6502/HarteTest_6502/HarteTest_6502.vcxproj b/M6502/HarteTest_6502/HarteTest_6502.vcxproj index 29ecc21..80389c8 100644 --- a/M6502/HarteTest_6502/HarteTest_6502.vcxproj +++ b/M6502/HarteTest_6502/HarteTest_6502.vcxproj @@ -169,6 +169,7 @@ + diff --git a/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters b/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters index 9cf163c..7fd3cd4 100644 --- a/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters +++ b/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters @@ -52,5 +52,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/M6502/HarteTest_6502/TestRunner.cpp b/M6502/HarteTest_6502/TestRunner.cpp index 9fb00db..2d3a006 100644 --- a/M6502/HarteTest_6502/TestRunner.cpp +++ b/M6502/HarteTest_6502/TestRunner.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" #include "TestRunner.h" -#include #include TestRunner::TestRunner(const test_t& test) diff --git a/M6502/HarteTest_6502/TestRunner.h b/M6502/HarteTest_6502/TestRunner.h index ff1c8d7..ee3cdf5 100644 --- a/M6502/HarteTest_6502/TestRunner.h +++ b/M6502/HarteTest_6502/TestRunner.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include diff --git a/M6502/HarteTest_6502/json_t.cpp b/M6502/HarteTest_6502/json_t.cpp index cf6c135..eb87aba 100644 --- a/M6502/HarteTest_6502/json_t.cpp +++ b/M6502/HarteTest_6502/json_t.cpp @@ -1,5 +1,8 @@ #include "stdafx.h" #include "json_t.h" + +#ifdef USE_BOOST_JSON + #include const boost::json::value& json_t::get_value(const boost::json::object& object, std::string key) { @@ -51,3 +54,5 @@ const boost::json::string& json_t::get_string(const boost::json::value& value) { const boost::json::string& json_t::get_string(const boost::json::object& object, std::string key) { return get_string(get_value(object, key)); } + +#endif \ No newline at end of file diff --git a/M6502/HarteTest_6502/json_t.h b/M6502/HarteTest_6502/json_t.h index b3d158f..1f03a85 100644 --- a/M6502/HarteTest_6502/json_t.h +++ b/M6502/HarteTest_6502/json_t.h @@ -1,11 +1,13 @@ #pragma once -#include -#include - -#include +#ifdef USE_BOOST_JSON +# include +# include +# include +#endif class json_t { +#ifdef USE_BOOST_JSON protected: [[nodiscard]] static const boost::json::value& get_value(const boost::json::object& object, std::string key); @@ -22,4 +24,5 @@ protected: [[nodiscard]] static const boost::json::string& get_string(const boost::json::value& value); [[nodiscard]] static const boost::json::string& get_string(const boost::json::object& object, std::string key); +#endif }; diff --git a/M6502/HarteTest_6502/opcode_test_suite_t.cpp b/M6502/HarteTest_6502/opcode_test_suite_t.cpp index b7fb336..db5739e 100644 --- a/M6502/HarteTest_6502/opcode_test_suite_t.cpp +++ b/M6502/HarteTest_6502/opcode_test_suite_t.cpp @@ -16,6 +16,8 @@ std::string opcode_test_suite_t::read(std::string path) { opcode_test_suite_t::opcode_test_suite_t(std::string path) : m_path(path) {} +#ifdef USE_BOOST_JSON + const boost::json::array& opcode_test_suite_t::get_array() const noexcept { assert(raw().is_array()); return raw().get_array(); @@ -25,3 +27,14 @@ void opcode_test_suite_t::load() { const auto contents = read(path()); m_raw = boost::json::parse(contents); } + +#endif + +#ifdef USE_NLOHMANN_JSON + +void opcode_test_suite_t::load() { + const auto contents = read(path()); + m_raw = nlohmann::json::parse(contents); +} + +#endif \ No newline at end of file diff --git a/M6502/HarteTest_6502/opcode_test_suite_t.h b/M6502/HarteTest_6502/opcode_test_suite_t.h index aabac89..63dbafb 100644 --- a/M6502/HarteTest_6502/opcode_test_suite_t.h +++ b/M6502/HarteTest_6502/opcode_test_suite_t.h @@ -1,21 +1,36 @@ #pragma once #include -#include + +#ifdef USE_BOOST_JSON +# include +#endif + +#ifdef USE_NLOHMANN_JSON +# include "nlohmann/json.hpp" +#endif class opcode_test_suite_t final { private: [[nodiscard]] static std::string read(std::string path); std::string m_path; +#ifdef USE_BOOST_JSON boost::json::value m_raw; +#endif +#ifdef USE_NLOHMANN_JSON + nlohmann::json m_raw; +#endif public: opcode_test_suite_t(std::string path); [[nodiscard]] constexpr const auto& path() const noexcept { return m_path; } [[nodiscard]] constexpr const auto& raw() const noexcept { return m_raw; } + +#ifdef USE_BOOST_JSON [[nodiscard]] const boost::json::array& get_array() const noexcept; +#endif void load(); }; diff --git a/M6502/HarteTest_6502/state_t.cpp b/M6502/HarteTest_6502/state_t.cpp index 70e538b..99adee9 100644 --- a/M6502/HarteTest_6502/state_t.cpp +++ b/M6502/HarteTest_6502/state_t.cpp @@ -2,6 +2,21 @@ #include "state_t.h" #include +state_t::state_t() {} + +#ifdef USE_BOOST_JSON + +state_t::state_t(const boost::json::object& serialised) { + initialise(serialised); + assert(initialised()); +} + +state_t::state_t(const boost::json::value& serialised) { + assert(serialised.is_object()); + initialise(serialised.get_object()); + assert(initialised()); +} + void state_t::initialise(const boost::json::object& serialised) { assert(!initialised()); @@ -26,15 +41,38 @@ void state_t::initialise(const boost::json::object& serialised) { m_initialised = true; } -state_t::state_t() {} +#endif -state_t::state_t(const boost::json::object& serialised) { +#ifdef USE_NLOHMANN_JSON + +state_t::state_t(const nlohmann::json& serialised) { + assert(serialised.is_object()); initialise(serialised); assert(initialised()); } -state_t::state_t(const boost::json::value& serialised) { - assert(serialised.is_object()); - initialise(serialised.get_object()); - assert(initialised()); +void state_t::initialise(const nlohmann::json& serialised) { + + assert(!initialised()); + + m_pc = serialised["pc"].get(); + m_s = serialised["s"].get(); + m_a = serialised["a"].get(); + m_x = serialised["x"].get(); + m_y = serialised["y"].get(); + m_p = serialised["p"].get(); + + const auto& ram_entries = serialised["ram"]; + assert(ram_entries.is_array()); + for (const auto& ram_entry : ram_entries) { + assert(ram_entry.is_array()); + assert(ram_entry.size() == 2); + const auto address = ram_entry[0].get(); + const auto value = ram_entry[1].get(); + m_ram[address] = value; + } + + m_initialised = true; } + +#endif diff --git a/M6502/HarteTest_6502/state_t.h b/M6502/HarteTest_6502/state_t.h index be2d8f2..70bc2d1 100644 --- a/M6502/HarteTest_6502/state_t.h +++ b/M6502/HarteTest_6502/state_t.h @@ -2,7 +2,14 @@ #include #include -#include + +#ifdef USE_BOOST_JSON +# include +#endif + +#ifdef USE_NLOHMANN_JSON +# include "nlohmann/json.hpp" +#endif #include "json_t.h" @@ -20,12 +27,25 @@ private: [[nodiscard]] constexpr auto initialised() const noexcept { return m_initialised; } +#ifdef USE_BOOST_JSON void initialise(const boost::json::object& serialised); +#endif + +#ifdef USE_NLOHMANN_JSON + void initialise(const nlohmann::json& serialised); +#endif public: state_t(); + +#ifdef USE_BOOST_JSON state_t(const boost::json::object& serialised); state_t(const boost::json::value& serialised); +#endif + +#ifdef USE_NLOHMANN_JSON + state_t(const nlohmann::json& serialised); +#endif [[nodiscard]] constexpr auto pc() const noexcept { return m_pc; } [[nodiscard]] constexpr auto s() const noexcept { return m_s; } diff --git a/M6502/HarteTest_6502/stdafx.h b/M6502/HarteTest_6502/stdafx.h index 4cfb9a1..6edae2f 100644 --- a/M6502/HarteTest_6502/stdafx.h +++ b/M6502/HarteTest_6502/stdafx.h @@ -11,4 +11,13 @@ #include #include -#include +//#define USE_BOOST_JSON +#define USE_NLOHMANN_JSON + +#ifdef USE_BOOST_JSON +# include +#endif + +#ifdef USE_NLOHMANN_JSON +# include "nlohmann/json.hpp" +#endif \ No newline at end of file diff --git a/M6502/HarteTest_6502/test_t.cpp b/M6502/HarteTest_6502/test_t.cpp index 5816f3a..51c2bff 100644 --- a/M6502/HarteTest_6502/test_t.cpp +++ b/M6502/HarteTest_6502/test_t.cpp @@ -19,6 +19,17 @@ std::string test_t::to_string(action value) { throw new std::out_of_range("Unknown action"); } +#ifdef USE_BOOST_JSON + +test_t::test_t(const boost::json::object& serialised) { + initialise(serialised); +} + +test_t::test_t(const boost::json::value& serialised) { + assert(serialised.is_object()); + initialise(serialised.get_object()); +} + void test_t::initialise(const boost::json::object& serialised) { m_name = get_string(serialised, "name"); @@ -34,15 +45,35 @@ void test_t::initialise(const boost::json::object& serialised) { const auto address = get_uint16(cycle_array[0]); const auto contents = get_uint8(cycle_array[1]); const auto action = to_action((std::string)get_string(cycle_array[2])); - m_cycles.push_back( { address, contents, action } ); + m_cycles.push_back({ address, contents, action }); } } -test_t::test_t(const boost::json::object& serialised) { +#endif + +#ifdef USE_NLOHMANN_JSON + +test_t::test_t(const nlohmann::json& serialised) { + assert(serialised.is_object()); initialise(serialised); } -test_t::test_t(const boost::json::value& serialised) { - assert(serialised.is_object()); - initialise(serialised.get_object()); +void test_t::initialise(const nlohmann::json& serialised) { + + m_name = serialised["name"].get(); + m_initial_state = state_t(serialised["initial"]); + m_final_state = state_t(serialised["final"]); + + const auto& cycles_array = serialised["cycles"]; + m_cycles.reserve(cycles_array.size()); + + for (const auto& cycles_entry : cycles_array) { + assert(cycles_entry.size() == 3); + const auto address = cycles_entry[0].get(); + const auto contents = cycles_entry[1].get(); + const auto action = to_action(cycles_entry[2].get()); + m_cycles.push_back({ address, contents, action }); + } } + +#endif diff --git a/M6502/HarteTest_6502/test_t.h b/M6502/HarteTest_6502/test_t.h index fafd366..8d0e4e6 100644 --- a/M6502/HarteTest_6502/test_t.h +++ b/M6502/HarteTest_6502/test_t.h @@ -4,7 +4,14 @@ #include #include #include -#include + +#ifdef USE_BOOST_JSON +# include +#endif + +#ifdef USE_NLOHMANN_JSON +# include "nlohmann/json.hpp" +#endif #include "state_t.h" #include "json_t.h" @@ -25,11 +32,24 @@ private: state_t m_final_state; events_t m_cycles; +#ifdef USE_BOOST_JSON void initialise(const boost::json::object& serialised); +#endif + +#ifdef USE_NLOHMANN_JSON + void initialise(const nlohmann::json& serialised); +#endif public: + +#ifdef USE_BOOST_JSON test_t(const boost::json::object& serialised); test_t(const boost::json::value& serialised); +#endif + +#ifdef USE_NLOHMANN_JSON + test_t(const nlohmann::json& serialised); +#endif [[nodiscard]] constexpr const auto& name() const noexcept { return m_name; } [[nodiscard]] constexpr const auto& initial_state() const noexcept { return m_initial_state; } diff --git a/M6502/HarteTest_6502/tests.cpp b/M6502/HarteTest_6502/tests.cpp index 7de0e6a..7ecae50 100644 --- a/M6502/HarteTest_6502/tests.cpp +++ b/M6502/HarteTest_6502/tests.cpp @@ -1,5 +1,6 @@ #include "stdafx.h" +#include #include #include @@ -11,6 +12,8 @@ int main() { std::filesystem::path location = "C:\\github\\spectrum\\libraries\\EightBit\\modules\\ProcessorTests\\6502\\v1"; + const auto start_time = std::chrono::steady_clock::now(); + for (const auto& entry : std::filesystem::directory_iterator{ location }) { const auto path = entry.path(); @@ -20,7 +23,13 @@ int main() { opcode_test_suite_t opcode(path.string()); opcode.load(); + +#ifdef USE_BOOST_JSON const auto& opcode_test_array = opcode.get_array(); +#endif +#ifdef USE_NLOHMANN_JSON + const auto& opcode_test_array = opcode.raw(); +#endif bool opcode_bad = false; for (const auto& opcode_test_element : opcode_test_array) { @@ -39,4 +48,12 @@ int main() { } } } + + const auto finish_time = std::chrono::steady_clock::now(); + + const auto elapsed_time = finish_time - start_time; + + const auto seconds = std::chrono::duration_cast>(elapsed_time).count(); + + std::cout << "Elapsed time: " << seconds << " seconds" << std::endl; } \ No newline at end of file