mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-08-18 00:28:57 +00:00
67 lines
1.7 KiB
C++
67 lines
1.7 KiB
C++
|
#include "stdafx.h"
|
||
|
#include "ram_t.h"
|
||
|
|
||
|
#ifdef USE_SIMDJSON_JSON
|
||
|
|
||
|
ram_t::ram_t(simdjson::dom::array input) {
|
||
|
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);
|
||
|
const auto address = (uint16_t)(uint64_t)byte.at(0);
|
||
|
const auto value = (uint8_t)(uint64_t)byte.at(1);
|
||
|
m_bytes.push_back({ address, value });
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|
||
|
|
||
|
#ifdef USE_BOOST_JSON
|
||
|
|
||
|
ram_t::ram_t(const boost::json::array& input) {
|
||
|
m_bytes.reserve(input.size());
|
||
|
for (const auto& byte : input) {
|
||
|
const auto& ram_entry_array = byte.as_array();
|
||
|
assert(ram_entry_array.size() == 2);
|
||
|
const auto address = (uint16_t)ram_entry_array.at(0).as_int64();
|
||
|
const auto value = (uint8_t)ram_entry_array.at(1).as_int64();
|
||
|
m_bytes.push_back({ address, value });
|
||
|
}
|
||
|
}
|
||
|
|
||
|
ram_t::ram_t(const boost::json::value& input)
|
||
|
: ram_t(input.as_array()) {}
|
||
|
|
||
|
#endif
|
||
|
|
||
|
#ifdef USE_NLOHMANN_JSON
|
||
|
|
||
|
ram_t::ram_t(const nlohmann::json& input) {
|
||
|
assert(input.is_array());
|
||
|
for (const auto& byte : input) {
|
||
|
assert(byte.is_array());
|
||
|
assert(byte.size() == 2);
|
||
|
const auto address = byte[0].get<uint16_t>();
|
||
|
const auto value = byte[1].get<uint8_t>();
|
||
|
m_bytes.push_back({ address, value });
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|
||
|
|
||
|
#ifdef USE_JSONCPP_JSON
|
||
|
|
||
|
ram_t::ram_t(const Json::Value& input) {
|
||
|
assert(input.isArray());
|
||
|
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 });
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|