diff --git a/memory.cpp b/memory.cpp index e58851c..9761814 100644 --- a/memory.cpp +++ b/memory.cpp @@ -27,3 +27,31 @@ void memory::reset() { memset(m, 0x00, size); } + +#if IS_POSIX +json_t *memory::serialize() +{ + json_t *j = json_object(); + + json_object_set(j, "size", json_integer(size)); + + json_t *ja = json_array(); + for(size_t i=0; iwriteByte(i, json_integer_value(json_array_get(ja, i))); + + return m; +} +#endif diff --git a/memory.h b/memory.h index 5942078..4120cd4 100644 --- a/memory.h +++ b/memory.h @@ -1,11 +1,15 @@ -// (C) 2018-2023 by Folkert van Heusden +// (C) 2018-2024 by Folkert van Heusden // Released under MIT license #pragma once - +#include "gen.h" #include +#if IS_POSIX +#include +#endif #include + class memory { private: @@ -17,6 +21,10 @@ public: ~memory(); void reset(); +#if IS_POSIX + json_t *serialize(); + static memory *deserialize(const json_t *const j); +#endif uint16_t readByte(const uint32_t a) const { return m[a]; } void writeByte(const uint32_t a, const uint16_t v) { assert(a < size); m[a] = v; }