diff --git a/M6502/HarteTest_6502/HarteTest_6502.vcxproj b/M6502/HarteTest_6502/HarteTest_6502.vcxproj index 7f2dab7..37447ee 100644 --- a/M6502/HarteTest_6502/HarteTest_6502.vcxproj +++ b/M6502/HarteTest_6502/HarteTest_6502.vcxproj @@ -161,6 +161,7 @@ + @@ -183,6 +184,7 @@ + @@ -225,7 +227,6 @@ - diff --git a/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters b/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters index c7e38bc..2b1cec4 100644 --- a/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters +++ b/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters @@ -50,6 +50,9 @@ Source Files + + Source Files + @@ -145,11 +148,11 @@ Header Files\rapidjson + + Header Files + - - Header Files\rapidjson - \ No newline at end of file diff --git a/M6502/HarteTest_6502/TestRunner.cpp b/M6502/HarteTest_6502/TestRunner.cpp index e961781..c13c72f 100644 --- a/M6502/HarteTest_6502/TestRunner.cpp +++ b/M6502/HarteTest_6502/TestRunner.cpp @@ -130,10 +130,8 @@ void TestRunner::initialiseState() { CPU().Y() = starting.y(); CPU().P() = starting.p(); const auto& ram = starting.ram(); - for (const auto& entry : ram) { - const auto [address, value] = entry; - RAM().poke(address, value); - } + for (const auto& entry : ram) + RAM().poke(entry.address(), entry.value()); m_actualCycles.clear(); } @@ -166,8 +164,7 @@ bool TestRunner::checkState() { const auto& ram = finished.ram(); bool ram_problem = false; for (const auto& entry : ram) { - const auto [address, value] = entry; - const auto ram_good = check("RAM", address, value, RAM().peek(address)); + const auto ram_good = check("RAM", entry.address(), entry.value(), RAM().peek(entry.address())); if (!ram_good && !ram_problem) ram_problem = true; } diff --git a/M6502/HarteTest_6502/byte_t.cpp b/M6502/HarteTest_6502/byte_t.cpp new file mode 100644 index 0000000..1a7f937 --- /dev/null +++ b/M6502/HarteTest_6502/byte_t.cpp @@ -0,0 +1,66 @@ +#include "stdafx.h" +#include "byte_t.h" + +#include +#include + +byte_t::byte_t(uint16_t address, uint8_t value) noexcept +: m_address(address), + m_value(value) {} + +#ifdef USE_SIMDJSON_JSON + +byte_t::byte_t(simdjson::dom::element input) noexcept +: byte_t(input.get_array()) {} + +byte_t::byte_t(simdjson::dom::array input) noexcept +: m_iterator(input.begin()), + m_address((uint16_t)(uint64_t)*m_iterator), + m_value((uint8_t)(uint64_t)* ++m_iterator) { + assert(input.size() == 2); +} + +#endif + +#ifdef USE_RAPIDJSON_JSON + +byte_t::byte_t(const rapidjson::Value& input) +: m_address((uint8_t)input[0].GetInt64()), + m_value((uint8_t)input[1].GetInt64()) { + assert(input.Size() == 2); +} + +#endif + +#ifdef USE_BOOST_JSON + +byte_t::byte_t(const boost::json::value& input) noexcept +: byte_t(input.get_array()) {} + +byte_t::byte_t(const boost::json::array& input) noexcept +: m_address((uint16_t)input[0].get_int64()), + m_value((uint8_t)input[1].get_int64()) { + assert(input.size() == 2); +}; + +#endif + +#ifdef USE_NLOHMANN_JSON + +byte_t::byte_t(const nlohmann::json& input) noexcept +: m_address(input[0].get()), + m_value(input[1].get()) { + assert(input.size() == 2); +} + +#endif + +#ifdef USE_JSONCPP_JSON + +byte_t::byte_t(const Json::Value& input) +: m_address(input[0].asUInt()), + m_value(input[1].asUInt()) { + assert(input.size() == 2); +} + +#endif diff --git a/M6502/HarteTest_6502/byte_t.h b/M6502/HarteTest_6502/byte_t.h new file mode 100644 index 0000000..4c176f5 --- /dev/null +++ b/M6502/HarteTest_6502/byte_t.h @@ -0,0 +1,61 @@ +#pragma once + +#include + +#ifdef USE_SIMDJSON_JSON +# include "simdjson/simdjson.h" +#endif + +#ifdef USE_RAPIDJSON_JSON +# include "rapidjson/document.h" +#endif + +#ifdef USE_BOOST_JSON +# include +#endif + +#ifdef USE_NLOHMANN_JSON +# include "nlohmann/json.hpp" +#endif + +#ifdef USE_JSONCPP_JSON +# include +#endif + +class byte_t final { +private: +#ifdef USE_SIMDJSON_JSON + simdjson::dom::array::iterator m_iterator; +#endif + uint16_t m_address = 0xffff; + uint8_t m_value = 0xff; + +public: + byte_t(uint16_t address, uint8_t value) noexcept; + +#ifdef USE_SIMDJSON_JSON + byte_t(simdjson::dom::element input) noexcept; + byte_t(simdjson::dom::array input) noexcept; +#endif + +#ifdef USE_RAPIDJSON_JSON + byte_t(const rapidjson::Value& input); +#endif + +#ifdef USE_BOOST_JSON + byte_t(const boost::json::value& input) noexcept; + byte_t(const boost::json::array& input) noexcept; +#endif + +#ifdef USE_NLOHMANN_JSON + byte_t(const nlohmann::json& input) noexcept; +#endif + +#ifdef USE_JSONCPP_JSON + byte_t(const Json::Value& input); +#endif + + [[nodiscard]] constexpr auto address() const noexcept { return m_address; } + [[nodiscard]] constexpr auto value() const noexcept { return m_value; } +}; + diff --git a/M6502/HarteTest_6502/cycle_t.h b/M6502/HarteTest_6502/cycle_t.h index 079c845..91d1805 100644 --- a/M6502/HarteTest_6502/cycle_t.h +++ b/M6502/HarteTest_6502/cycle_t.h @@ -8,7 +8,7 @@ #endif #ifdef USE_RAPIDJSON_JSON -# include "rapidjson/rapidjson.h" +# include "rapidjson/document.h" #endif #ifdef USE_BOOST_JSON diff --git a/M6502/HarteTest_6502/cycles_t.h b/M6502/HarteTest_6502/cycles_t.h index 5368102..882f47f 100644 --- a/M6502/HarteTest_6502/cycles_t.h +++ b/M6502/HarteTest_6502/cycles_t.h @@ -7,7 +7,7 @@ #endif #ifdef USE_RAPIDJSON_JSON -# include "rapidjson/rapidjson.h" +# include "rapidjson/document.h" #endif #ifdef USE_BOOST_JSON diff --git a/M6502/HarteTest_6502/opcode_test_suite_t.h b/M6502/HarteTest_6502/opcode_test_suite_t.h index 7cb58b5..c239941 100644 --- a/M6502/HarteTest_6502/opcode_test_suite_t.h +++ b/M6502/HarteTest_6502/opcode_test_suite_t.h @@ -7,7 +7,6 @@ #endif #ifdef USE_RAPIDJSON_JSON -# include "rapidjson/rapidjson.h" # include "rapidjson/document.h" #endif diff --git a/M6502/HarteTest_6502/ram_t.cpp b/M6502/HarteTest_6502/ram_t.cpp index 478a76f..bdbab50 100644 --- a/M6502/HarteTest_6502/ram_t.cpp +++ b/M6502/HarteTest_6502/ram_t.cpp @@ -1,19 +1,18 @@ #include "stdafx.h" #include "ram_t.h" +void ram_t::add(const byte_t& byte) { + assert(m_bytes.capacity() >= (m_bytes.size() + 1)); + m_bytes.push_back(byte); +} + #ifdef USE_SIMDJSON_JSON ram_t::ram_t(simdjson::dom::array input) { + assert(m_bytes.empty()); m_bytes.reserve(input.size()); - for (const auto byte : input) { - assert(byte.is_array()); - const auto ram_entry_array = byte.get_array(); - assert(byte.size() == 2); - auto iterator = byte.begin(); - const auto address = (uint16_t)(uint64_t)*iterator; - const auto value = (uint8_t)(uint64_t)*++iterator; - m_bytes.push_back({ address, value }); - } + for (const auto& entry : input) + add(entry); } #endif @@ -21,27 +20,21 @@ ram_t::ram_t(simdjson::dom::array input) { #ifdef USE_RAPIDJSON_JSON ram_t::ram_t(const rapidjson::Value& input) { + assert(m_bytes.empty()); m_bytes.reserve(input.Size()); - for (const auto& byte : input.GetArray()) { - assert(byte.Size() == 2); - const auto address = (uint16_t)byte[0].GetInt64(); - const auto value = (uint8_t)byte[1].GetInt64(); - m_bytes.push_back({ address, value }); - } + for (const auto& entry : input.GetArray()) + add(entry); } + #endif #ifdef USE_BOOST_JSON ram_t::ram_t(const boost::json::array& input) { + assert(m_bytes.empty()); m_bytes.reserve(input.size()); - for (const auto& byte : input) { - const auto& ram_entry_array = byte.get_array(); - assert(ram_entry_array.size() == 2); - const auto address = (uint16_t)ram_entry_array[0].get_int64(); - const auto value = (uint8_t)ram_entry_array[1].get_int64(); - m_bytes.push_back({ address, value }); - } + for (const auto& entry : input) + add(entry); } ram_t::ram_t(const boost::json::value& input) @@ -52,15 +45,10 @@ ram_t::ram_t(const boost::json::value& input) #ifdef USE_NLOHMANN_JSON ram_t::ram_t(const nlohmann::json& input) { - assert(input.is_array()); + assert(m_bytes.empty()); m_bytes.reserve(input.size()); - for (const auto& byte : input) { - assert(byte.is_array()); - assert(byte.size() == 2); - const auto address = byte[0].get(); - const auto value = byte[1].get(); - m_bytes.push_back({ address, value }); - } + for (const auto& entry : input) + add(entry); } #endif @@ -68,15 +56,10 @@ ram_t::ram_t(const nlohmann::json& input) { #ifdef USE_JSONCPP_JSON ram_t::ram_t(const Json::Value& input) { - assert(input.isArray()); + assert(m_bytes.empty()); m_bytes.reserve(input.size()); - for (const auto& byte : input) { - assert(byte.isArray()); - assert(byte.size() == 2); - const auto address = byte[0].asUInt(); - const auto value = byte[1].asUInt(); - m_bytes.push_back({ address, value }); - } + for (const auto& entry : input) + add(entry); } #endif diff --git a/M6502/HarteTest_6502/ram_t.h b/M6502/HarteTest_6502/ram_t.h index f507d41..6ae91f9 100644 --- a/M6502/HarteTest_6502/ram_t.h +++ b/M6502/HarteTest_6502/ram_t.h @@ -9,7 +9,7 @@ #endif #ifdef USE_RAPIDJSON_JSON -# include "rapidjson/rapidjson.h" +# include "rapidjson/document.h" #endif #ifdef USE_BOOST_JSON @@ -24,9 +24,11 @@ # include #endif -class ram_t { +#include "byte_t.h" + +class ram_t final { private: - std::vector> m_bytes; + std::vector m_bytes; public: #ifdef USE_SIMDJSON_JSON @@ -50,6 +52,8 @@ public: ram_t(const Json::Value& input); #endif + void add(const byte_t& byte); + [[nodiscard]] auto begin() const noexcept { return m_bytes.begin(); } [[nodiscard]] auto end() const noexcept { return m_bytes.end(); } diff --git a/M6502/HarteTest_6502/state_t.h b/M6502/HarteTest_6502/state_t.h index 1406289..dc6f055 100644 --- a/M6502/HarteTest_6502/state_t.h +++ b/M6502/HarteTest_6502/state_t.h @@ -7,7 +7,7 @@ #endif #ifdef USE_RAPIDJSON_JSON -# include "rapidjson/rapidjson.h" +# include "rapidjson/document.h" #endif #ifdef USE_BOOST_JSON diff --git a/M6502/HarteTest_6502/stdafx.h b/M6502/HarteTest_6502/stdafx.h index 298476a..cc84e43 100644 --- a/M6502/HarteTest_6502/stdafx.h +++ b/M6502/HarteTest_6502/stdafx.h @@ -26,7 +26,8 @@ #endif #ifdef USE_RAPIDJSON_JSON -# include "rapidjson/rapidjson.h" +# define RAPIDJSON_HAS_STDSTRING 1 +# define RAPIDJSON_SSE42 # include "rapidjson/document.h" #endif diff --git a/M6502/HarteTest_6502/test_t.h b/M6502/HarteTest_6502/test_t.h index 486daaa..88877ba 100644 --- a/M6502/HarteTest_6502/test_t.h +++ b/M6502/HarteTest_6502/test_t.h @@ -10,7 +10,6 @@ #endif #ifdef USE_RAPIDJSON_JSON -# include "rapidjson/rapidjson.h" # include "rapidjson/document.h" #endif