mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-21 18:29:57 +00:00
More JSON code simplifications.
Signed-off-by: Adrian Conlon <adrian.conlon@gmail.com>
This commit is contained in:
parent
c39178f9d1
commit
0deb37ab19
@ -27,20 +27,20 @@ void TestRunner::addActualCycle(const cycle_t& value) {
|
||||
m_actualCycles.add(value);
|
||||
}
|
||||
|
||||
void TestRunner::addActualCycle(uint16_t address, uint8_t value, cycle_t::action_t action) {
|
||||
void TestRunner::addActualCycle(uint16_t address, uint8_t value, std::string action) {
|
||||
addActualCycle({ address, value, action });
|
||||
}
|
||||
|
||||
void TestRunner::addActualCycle(EightBit::register16_t address, uint8_t value, cycle_t::action_t action) {
|
||||
void TestRunner::addActualCycle(EightBit::register16_t address, uint8_t value, std::string action) {
|
||||
addActualCycle(address.word, value, action);
|
||||
}
|
||||
|
||||
void TestRunner::addActualReadCycle(EightBit::register16_t address, uint8_t value) {
|
||||
addActualCycle(address, value, cycle_t::action_t::read);
|
||||
addActualCycle(address, value, "read");
|
||||
}
|
||||
|
||||
void TestRunner::addActualWriteCycle(EightBit::register16_t address, uint8_t value) {
|
||||
addActualCycle(address, value, cycle_t::action_t::write);
|
||||
addActualCycle(address, value, "write");
|
||||
}
|
||||
|
||||
void TestRunner::dumpCycles(std::string which, const cycles_t& events) {
|
||||
@ -58,7 +58,7 @@ void TestRunner::dumpCycle(const cycle_t& cycle) {
|
||||
os()
|
||||
<< "Address: " << std::setw(4) << cycle.address()
|
||||
<< ", value: " << std::setw(2) << (int)cycle.value()
|
||||
<< ", action: " << cycle_t::to_string(cycle.action());
|
||||
<< ", action: " << cycle.action();
|
||||
m_messages.push_back(os().str());
|
||||
os().str("");
|
||||
}
|
||||
@ -98,11 +98,11 @@ void TestRunner::raise(std::string what, uint8_t expected, uint8_t actual) {
|
||||
os().str("");
|
||||
}
|
||||
|
||||
void TestRunner::raise(std::string what, cycle_t::action_t expected, cycle_t::action_t actual) {
|
||||
void TestRunner::raise(std::string what, std::string expected, std::string actual) {
|
||||
os()
|
||||
<< what
|
||||
<< ": expected: " << cycle_t::to_string(expected)
|
||||
<< ", actual: " << cycle_t::to_string(actual);
|
||||
<< ": expected: " << expected
|
||||
<< ", actual: " << actual;
|
||||
m_messages.push_back(os().str());
|
||||
os().str("");
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ private:
|
||||
|
||||
void raise(std::string what, uint16_t expected, uint16_t actual);
|
||||
void raise(std::string what, uint8_t expected, uint8_t actual);
|
||||
void raise(std::string what, cycle_t::action_t expected, cycle_t::action_t actual);
|
||||
void raise(std::string what, std::string expected, std::string actual);
|
||||
|
||||
template<class T>
|
||||
bool check(std::string what, T expected, T actual) {
|
||||
@ -46,8 +46,8 @@ private:
|
||||
bool check(std::string what, uint16_t address, uint8_t expected, uint8_t actual);
|
||||
|
||||
void addActualCycle(const cycle_t& value);
|
||||
void addActualCycle(uint16_t address, uint8_t value, cycle_t::action_t action);
|
||||
void addActualCycle(EightBit::register16_t address, uint8_t value, cycle_t::action_t action);
|
||||
void addActualCycle(uint16_t address, uint8_t value, std::string action);
|
||||
void addActualCycle(EightBit::register16_t address, uint8_t value, std::string action);
|
||||
|
||||
void addActualReadCycle(EightBit::register16_t address, uint8_t value);
|
||||
void addActualWriteCycle(EightBit::register16_t address, uint8_t value);
|
||||
|
@ -6,12 +6,12 @@
|
||||
|
||||
class byte_t final {
|
||||
private:
|
||||
simdjson::dom::array m_raw;
|
||||
const simdjson::dom::array m_raw;
|
||||
|
||||
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.begin(); }
|
||||
[[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); }
|
||||
};
|
||||
|
@ -1,25 +1,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "cycle_t.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
cycle_t::action_t cycle_t::to_action(std::string value) noexcept {
|
||||
if (value == "read")
|
||||
return action_t::read;
|
||||
if (value == "write")
|
||||
return action_t::write;
|
||||
return action_t::unknown;
|
||||
}
|
||||
|
||||
std::string cycle_t::to_string(action_t value) noexcept {
|
||||
if (value == action_t::read)
|
||||
return "read";
|
||||
if (value == action_t::write)
|
||||
return "write";
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
cycle_t::cycle_t(uint16_t address, uint8_t value, action_t action) noexcept
|
||||
cycle_t::cycle_t(uint16_t address, uint8_t value, std::string action) noexcept
|
||||
: m_address(address),
|
||||
m_value(value),
|
||||
m_action(action) {}
|
||||
@ -27,10 +9,7 @@ cycle_t::cycle_t(uint16_t address, uint8_t value, action_t action) noexcept
|
||||
cycle_t::cycle_t(simdjson::dom::element input) noexcept
|
||||
: cycle_t(input.get_array()) {}
|
||||
|
||||
cycle_t::cycle_t(simdjson::dom::array input) noexcept {
|
||||
assert(input.size() == 3);
|
||||
auto iterator = input.begin();
|
||||
m_address = (uint16_t)(int64_t)*iterator;
|
||||
m_value = (uint8_t)(int64_t)*++iterator;
|
||||
m_action = to_action((std::string)*++iterator);
|
||||
}
|
||||
cycle_t::cycle_t(simdjson::dom::array input) noexcept
|
||||
: m_address((uint16_t)(int64_t)input.at(0)),
|
||||
m_value((uint8_t)(int64_t)input.at(1)),
|
||||
m_action((std::string)input.at(2)) {}
|
||||
|
@ -6,24 +6,18 @@
|
||||
#include "simdjson/simdjson.h"
|
||||
|
||||
class cycle_t final {
|
||||
public:
|
||||
enum class action_t { read, write, unknown };
|
||||
|
||||
private:
|
||||
uint16_t m_address = 0xffff;
|
||||
uint8_t m_value = 0xff;
|
||||
action_t m_action = action_t::unknown;
|
||||
const uint16_t m_address = 0xffff;
|
||||
const uint8_t m_value = 0xff;
|
||||
const std::string m_action;
|
||||
|
||||
public:
|
||||
[[nodiscard]] static std::string to_string(action_t value) noexcept;
|
||||
[[nodiscard]] static action_t to_action(std::string value) noexcept;
|
||||
|
||||
cycle_t(uint16_t address, uint8_t value, action_t action) noexcept;
|
||||
cycle_t(uint16_t address, uint8_t value, std::string action) noexcept;
|
||||
|
||||
cycle_t(simdjson::dom::element input) noexcept;
|
||||
cycle_t(simdjson::dom::array input) noexcept;
|
||||
|
||||
[[nodiscard]] constexpr auto address() const noexcept { return m_address; }
|
||||
[[nodiscard]] constexpr auto value() const noexcept { return m_value; }
|
||||
[[nodiscard]] constexpr auto action() const noexcept { return m_action; }
|
||||
[[nodiscard]] auto action() const noexcept { return m_action; }
|
||||
};
|
||||
|
@ -23,6 +23,5 @@ public:
|
||||
|
||||
void clear() { m_cycles.clear(); }
|
||||
|
||||
[[nodiscard]] auto& operator[](size_t idx) noexcept { return m_cycles[idx]; }
|
||||
[[nodiscard]] const auto& operator[](size_t idx) const noexcept { return m_cycles[idx]; }
|
||||
};
|
||||
|
@ -21,8 +21,6 @@ public:
|
||||
|
||||
[[nodiscard]] auto size() const noexcept { return m_bytes.size(); }
|
||||
|
||||
void clear() noexcept { m_bytes.clear(); }
|
||||
|
||||
[[nodiscard]] auto& operator[](size_t idx) noexcept { return m_bytes[idx]; }
|
||||
[[nodiscard]] auto operator[](size_t idx) const noexcept { return m_bytes[idx]; }
|
||||
};
|
||||
|
@ -1,11 +1,5 @@
|
||||
#include "stdafx.h"
|
||||
#include "state_t.h"
|
||||
|
||||
state_t::state_t(const simdjson::dom::element serialised)
|
||||
: m_pc((uint16_t)(int64_t)serialised["pc"]),
|
||||
m_s((uint8_t)(int64_t)serialised["s"]),
|
||||
m_a((uint8_t)(int64_t)serialised["a"]),
|
||||
m_x((uint8_t)(int64_t)serialised["x"]),
|
||||
m_y((uint8_t)(int64_t)serialised["y"]),
|
||||
m_p((uint8_t)(int64_t)serialised["p"]),
|
||||
m_ram(serialised["ram"].get_array()) {}
|
||||
state_t::state_t(const simdjson::dom::element input)
|
||||
: m_raw(input) {}
|
||||
|
@ -8,22 +8,16 @@
|
||||
|
||||
class state_t final {
|
||||
private:
|
||||
uint16_t m_pc = 0xffff;
|
||||
uint8_t m_s = 0xff;
|
||||
uint8_t m_a = 0xff;
|
||||
uint8_t m_x = 0xff;
|
||||
uint8_t m_y = 0xff;
|
||||
uint8_t m_p = 0xff;
|
||||
ram_t m_ram;
|
||||
const simdjson::dom::element m_raw;
|
||||
|
||||
public:
|
||||
state_t(simdjson::dom::element serialised);
|
||||
state_t(simdjson::dom::element input);
|
||||
|
||||
[[nodiscard]] constexpr auto pc() const noexcept { return m_pc; }
|
||||
[[nodiscard]] constexpr auto s() const noexcept { return m_s; }
|
||||
[[nodiscard]] constexpr auto a() const noexcept { return m_a; }
|
||||
[[nodiscard]] constexpr auto x() const noexcept { return m_x; }
|
||||
[[nodiscard]] constexpr auto y() const noexcept { return m_y; }
|
||||
[[nodiscard]] constexpr auto p() const noexcept { return m_p; }
|
||||
[[nodiscard]] constexpr const auto& ram() const noexcept { return m_ram; }
|
||||
[[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()); }
|
||||
};
|
||||
|
@ -1,9 +1,5 @@
|
||||
#include "stdafx.h"
|
||||
#include "test_t.h"
|
||||
#include <cassert>
|
||||
|
||||
test_t::test_t(const simdjson::dom::element serialised)
|
||||
: m_name(serialised["name"]),
|
||||
m_initial_state(serialised["initial"]),
|
||||
m_final_state(serialised["final"]),
|
||||
m_cycles(serialised["cycles"].get_array()) {}
|
||||
test_t::test_t(const simdjson::dom::element input)
|
||||
: m_raw(input) {}
|
||||
|
@ -9,16 +9,13 @@
|
||||
|
||||
class test_t final {
|
||||
private:
|
||||
std::string m_name;
|
||||
state_t m_initial_state;
|
||||
state_t m_final_state;
|
||||
cycles_t m_cycles;
|
||||
simdjson::dom::element m_raw;
|
||||
|
||||
public:
|
||||
test_t(simdjson::dom::element serialised);
|
||||
test_t(simdjson::dom::element input);
|
||||
|
||||
[[nodiscard]] constexpr const auto& name() const noexcept { return m_name; }
|
||||
[[nodiscard]] constexpr const auto& initial_state() const noexcept { return m_initial_state; }
|
||||
[[nodiscard]] constexpr const auto& final_state() const noexcept { return m_final_state; }
|
||||
[[nodiscard]] constexpr const auto& cycles() const noexcept { return m_cycles; }
|
||||
[[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()); }
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user