18 : xml(*config.getXML())
21 , debuggable(std::in_place,
22 config.getMotherBoard(), name, description, *this)
37 if (
const auto* init = xml.
findChild(
"initialContent")) {
39 auto encoding = init->getAttributeValue(
"encoding");
41 if (encoding ==
"gz-base64") {
42 auto [buf, bufSize] = Base64::decode(init->getData());
44 if (uncompress(
reinterpret_cast<Bytef*
>(ram.
data()), &dstLen,
45 reinterpret_cast<const Bytef*
>(buf.data()), uLong(bufSize))
47 throw MSXException(
"Error while decompressing initialContent.");
50 }
else if (encoding ==
one_of(
"hex",
"base64")) {
51 auto [buf, bufSize] = (encoding ==
"hex")
52 ? HexDump::decode(init->getData())
53 : Base64 ::decode(init->getData());
57 done =
std::min(
size_t(size), bufSize);
58 memcpy(ram.
data(), buf.data(), done);
61 "\" for initialContent");
65 auto left = size - done;
68 memcpy(&ram[done], &ram[0], tmp);
74 memset(ram.
data(), c, size);
81 return debuggable->getName();
85 const std::string& name_,
103 template<
typename Archive>
106 ar.serialize_blob(
"ram", ram.
data(), size);
const T * data() const
Returns pointer to the start of the memory buffer.
byte read(unsigned address) override
void write(unsigned address, byte value) override
RamDebuggable(MSXMotherBoard &motherBoard, const std::string &name, static_string_view description, Ram &ram)
Ram(const DeviceConfig &config, const std::string &name, static_string_view description, unsigned size)
Create Ram object with an associated debuggable.
void serialize(Archive &ar, unsigned version)
const std::string & getName() const
const XMLElement * findChild(std::string_view childName) const
constexpr vecN< N, T > min(const vecN< N, T > &x, const vecN< N, T > &y)
This file implemented 3 utility functions:
size_t size(std::string_view utf8)
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)