23 : xml(*config.getXML())
26 , debuggable(
std::in_place,
27 config.getMotherBoard(), name, description, *this)
42 if (
const auto* init = xml.
findChild(
"initialContent")) {
44 auto encoding = init->getAttributeValue(
"encoding");
46 if (encoding ==
"gz-base64") {
47 auto [buf, bufSize] = Base64::decode(init->getData());
48 auto dstLen = narrow<uLongf>(
size());
49 if (uncompress(std::bit_cast<Bytef*>(ram.
data()), &dstLen,
50 std::bit_cast<const Bytef*>(buf.data()), uLong(bufSize))
52 throw MSXException(
"Error while decompressing initialContent.");
55 }
else if (encoding ==
one_of(
"hex",
"base64")) {
56 auto [buf, bufSize] = (encoding ==
"hex")
57 ? HexDump::decode(init->getData())
58 : Base64 ::decode(init->getData());
62 done = std::min(
size(), bufSize);
66 "\" for initialContent");
70 auto left =
size() - done;
72 auto tmp = std::min(done, left);
85 return debuggable->getName();
89 const std::string& name_,
103 ram[address] = value;
107template<
typename Archive>
111 ar.serialize_blob(
"ram", std::span{
begin(),
end()});
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, size_t 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
This file implemented 3 utility functions:
constexpr void fill(ForwardRange &&range, const T &value)
constexpr auto copy(InputRange &&range, OutputIter out)
constexpr To narrow(From from) noexcept
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)