From f2ac06b9db16621e8e2e5d7913e51d5e949cc291 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Thu, 16 May 2024 09:50:36 +0200 Subject: [PATCH] WIP --- bus.cpp | 24 +++++++++++++++++++----- bus.h | 4 ++-- cpu.cpp | 6 ++---- cpu.h | 5 ++--- debugger.cpp | 2 +- disk_backend.h | 3 +-- disk_backend_file.h | 1 + gen.h | 2 ++ kw11-l.h | 2 +- memory.h | 4 ++-- mmu.h | 3 +-- rk05.h | 2 +- rl02.h | 2 +- tty.h | 2 +- 14 files changed, 37 insertions(+), 25 deletions(-) diff --git a/bus.cpp b/bus.cpp index 78c78b1..952900b 100644 --- a/bus.cpp +++ b/bus.cpp @@ -1,13 +1,13 @@ // (C) 2018-2024 by Folkert van Heusden // Released under MIT license +#include "gen.h" #include #include #include #include #include "bus.h" -#include "gen.h" #include "cpu.h" #include "dc11.h" #include "kw11-l.h" @@ -45,34 +45,48 @@ bus::~bus() delete dc11_; } -JsonVariant bus::serialize() const +void dump(JsonVariantConst j) +{ + std::string temp; + printf("%zu\n", serializeJson(j, temp)); + + printf("%s\r\n", temp.c_str()); +} + +JsonDocument bus::serialize() const { - JsonVariant j_out; + JsonDocument doc; + JsonVariant j_out = doc.to(); if (m) j_out["memory"] = m->serialize(); if (kw11_l_) j_out["kw11-l"] = kw11_l_->serialize(); + dump(kw11_l_->serialize()); if (tty_) j_out["tty"] = tty_->serialize(); + dump(tty_->serialize()); if (mmu_) j_out["mmu"] = mmu_->serialize(); + dump(mmu_->serialize()); if (c) - j_out["cpu"] = c->serialize(); + c->serialize(j_out["cpu"]); if (rl02_) j_out["rl02"] = rl02_->serialize(); + dump(rl02_->serialize()); if (rk05_) j_out["rk05"] = rk05_->serialize(); + dump(rk05_->serialize()); // TODO: tm11, dc11 - return j_out; + return doc; } bus *bus::deserialize(const JsonDocument j, console *const cnsl, std::atomic_uint32_t *const event) diff --git a/bus.h b/bus.h index c198816..2bbb99c 100644 --- a/bus.h +++ b/bus.h @@ -3,13 +3,13 @@ #pragma once +#include "gen.h" #include #include #include #include #include -#include "gen.h" #include "device.h" #include "dc11.h" #include "mmu.h" @@ -80,7 +80,7 @@ class bus: public device bus(); ~bus(); - JsonVariant serialize() const; + JsonDocument serialize() const; static bus *deserialize(const JsonDocument j, console *const cnsl, std::atomic_uint32_t *const event); void reset() override; diff --git a/cpu.cpp b/cpu.cpp index 6485873..ade9285 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -2434,9 +2434,9 @@ void cpu::step() } } -JsonVariant cpu::serialize() +void cpu::serialize(JsonVariant j_in) { - JsonVariant j; + JsonVariant j = j_in["cpu"].to(); for(int set=0; set<2; set++) { for(int regnr=0; regnr<6; regnr++) @@ -2473,8 +2473,6 @@ JsonVariant cpu::serialize() j["queued_interrupts"] = j_queued_interrupts; j["any_queued_interrupts"] = bool(any_queued_interrupts); - - return j; } cpu *cpu::deserialize(const JsonVariantConst j, bus *const b, std::atomic_uint32_t *const event) diff --git a/cpu.h b/cpu.h index 50e2100..ff770df 100644 --- a/cpu.h +++ b/cpu.h @@ -3,6 +3,7 @@ #pragma once +#include "gen.h" #include #include #include @@ -14,8 +15,6 @@ #include #include -#include "gen.h" - class breakpoint; class bus; @@ -115,7 +114,7 @@ class cpu explicit cpu(bus *const b, std::atomic_uint32_t *const event); ~cpu(); - JsonVariant serialize(); + void serialize(JsonVariant j); static cpu *deserialize(const JsonVariantConst j, bus *const b, std::atomic_uint32_t *const event); std::optional check_breakpoint(); diff --git a/debugger.cpp b/debugger.cpp index 288f5a0..04c2c3e 100644 --- a/debugger.cpp +++ b/debugger.cpp @@ -550,7 +550,7 @@ struct state_writer { void serialize_state(console *const cnsl, const bus *const b, const std::string & filename) { - JsonVariant j = b->serialize(); + JsonDocument j = b->serialize(); bool ok = false; diff --git a/disk_backend.h b/disk_backend.h index e1dcd3d..fc8e401 100644 --- a/disk_backend.h +++ b/disk_backend.h @@ -3,6 +3,7 @@ #pragma once +#include "gen.h" #include #include #include @@ -11,8 +12,6 @@ #include #include -#include "gen.h" - class disk_backend { diff --git a/disk_backend_file.h b/disk_backend_file.h index 8b825ac..6c8a4b5 100644 --- a/disk_backend_file.h +++ b/disk_backend_file.h @@ -1,6 +1,7 @@ // (C) 2018-2024 by Folkert van Heusden // Released under MIT license +#include "gen.h" #include #include diff --git a/gen.h b/gen.h index caeaa23..20c26fb 100644 --- a/gen.h +++ b/gen.h @@ -3,6 +3,8 @@ #pragma once +#define ARDUINOJSON_DEBUG 1 + // #define TURBO typedef enum { EVENT_NONE = 0, EVENT_HALT, EVENT_INTERRUPT, EVENT_TERMINATE } stop_event_t; diff --git a/kw11-l.h b/kw11-l.h index 04031a1..5ee0f61 100644 --- a/kw11-l.h +++ b/kw11-l.h @@ -1,6 +1,7 @@ // (C) 2018-2024 by Folkert van Heusden // Released under MIT license +#include "gen.h" #include #include #include @@ -8,7 +9,6 @@ #include "bus.h" #include "console.h" #include "device.h" -#include "gen.h" class kw11_l: public device diff --git a/memory.h b/memory.h index 0fb5670..55deaa9 100644 --- a/memory.h +++ b/memory.h @@ -2,10 +2,10 @@ // Released under MIT license #pragma once -#include -#include #include "gen.h" +#include +#include class memory diff --git a/mmu.h b/mmu.h index b9f2f5e..591e00d 100644 --- a/mmu.h +++ b/mmu.h @@ -1,10 +1,9 @@ #pragma once +#include "gen.h" #include #include #include - -#include "gen.h" #include "cpu.h" #include "device.h" #include "memory.h" diff --git a/rk05.h b/rk05.h index 537d9d9..4c94058 100644 --- a/rk05.h +++ b/rk05.h @@ -3,6 +3,7 @@ #pragma once +#include "gen.h" #include #include #include @@ -12,7 +13,6 @@ #include "disk_device.h" #include "disk_backend.h" -#include "gen.h" #define RK05_DS 0177400 // drive status diff --git a/rl02.h b/rl02.h index 0c36945..1128fe2 100644 --- a/rl02.h +++ b/rl02.h @@ -3,6 +3,7 @@ #pragma once +#include "gen.h" #include #include #include @@ -12,7 +13,6 @@ #include "disk_device.h" #include "disk_backend.h" -#include "gen.h" #define RL02_CSR 0174400 // control status register diff --git a/tty.h b/tty.h index dc26be2..50c1016 100644 --- a/tty.h +++ b/tty.h @@ -3,6 +3,7 @@ #pragma once +#include "gen.h" #include #include #include @@ -14,7 +15,6 @@ #include "bus.h" #include "console.h" -#include "gen.h" #define PDP11TTY_TKS 0177560 // reader status