mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-09-01 00:28:55 +00:00
Further simplifications and speedups to the json code.
Signed-off-by: Adrian Conlon <adrian.conlon@gmail.com>
This commit is contained in:
parent
0adb60a0f4
commit
393fab2bbc
@ -1,6 +1,9 @@
|
||||
#include "stdafx.h"
|
||||
#include "TestRunner.h"
|
||||
|
||||
std::set<uint8_t> 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;
|
||||
}
|
@ -16,6 +16,9 @@
|
||||
|
||||
class TestRunner final : public EightBit::Bus {
|
||||
private:
|
||||
static std::set<uint8_t> 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<uint8_t> m_undocumented_opcodes;
|
||||
|
||||
void seedUndocumentedOpcodes();
|
||||
void initialiseState();
|
||||
[[nodiscard]] bool checkState();
|
||||
|
@ -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) {}
|
||||
|
@ -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); }
|
||||
};
|
||||
|
@ -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]; }
|
||||
};
|
||||
|
@ -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) {}
|
||||
|
@ -1,25 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "simdjson/simdjson.h"
|
||||
|
||||
#include "byte_t.h"
|
||||
|
||||
class ram_t final {
|
||||
private:
|
||||
std::vector<byte_t> 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(); }
|
||||
};
|
||||
|
@ -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")); }
|
||||
};
|
||||
|
@ -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")); }
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user