more serialize code
This commit is contained in:
parent
6ab59835e7
commit
10193fbf59
6 changed files with 127 additions and 13 deletions
44
bus.cpp
44
bus.cpp
|
@ -47,17 +47,45 @@ json_t *bus::serialize()
|
|||
{
|
||||
json_t *j_out = json_object();
|
||||
|
||||
json_object_set(j_out, "memory", m->serialize());
|
||||
if (m)
|
||||
json_object_set(j_out, "memory", m->serialize());
|
||||
|
||||
if (kw11_l_)
|
||||
json_object_set(j_out, "kw11-l", kw11_l_->serialize());
|
||||
|
||||
if (tty_)
|
||||
json_object_set(j_out, "tty", tty_->serialize());
|
||||
|
||||
// TODO: mmu, cpu, rl02, rk05, tm11
|
||||
|
||||
return j_out;
|
||||
}
|
||||
|
||||
bus *bus::deserialize(const json_t *const j)
|
||||
bus *bus::deserialize(const json_t *const j, console *const cnsl)
|
||||
{
|
||||
bus *b = new bus();
|
||||
|
||||
memory *m = memory::deserialize(json_object_get(j, "memory"));
|
||||
b->add_ram(m);
|
||||
json_t *temp = nullptr;
|
||||
|
||||
temp = json_object_get(j, "memory");
|
||||
if (temp) {
|
||||
memory *m = memory::deserialize(temp);
|
||||
b->add_ram(m);
|
||||
}
|
||||
|
||||
temp = json_object_get(j, "kw11-l");
|
||||
if (temp) {
|
||||
kw11_l *kw11_l_ = kw11_l::deserialize(temp, b, cnsl);
|
||||
b->add_KW11_L(kw11_l_);
|
||||
}
|
||||
|
||||
temp = json_object_get(j, "tty");
|
||||
if (temp) {
|
||||
tty *tty_ = tty::deserialize(temp, b, cnsl);
|
||||
b->add_tty(tty_);
|
||||
}
|
||||
|
||||
// TODO: mmu, cpu, rl02, rk05, tm11
|
||||
|
||||
return b;
|
||||
}
|
||||
|
@ -91,6 +119,14 @@ void bus::reset()
|
|||
rl02_->reset();
|
||||
if (tty_)
|
||||
tty_->reset();
|
||||
if (kw11_l_)
|
||||
kw11_l_->reset();
|
||||
}
|
||||
|
||||
void bus::add_KW11_L(kw11_l *const kw11_l_)
|
||||
{
|
||||
delete this->kw11_l_;
|
||||
this->kw11_l_ = kw11_l_;
|
||||
}
|
||||
|
||||
void bus::add_ram(memory *const m)
|
||||
|
|
16
bus.h
16
bus.h
|
@ -45,6 +45,7 @@
|
|||
#define ADDR_CCR 0177746
|
||||
#define ADDR_SYSTEM_ID 0177764
|
||||
|
||||
class console;
|
||||
class cpu;
|
||||
class kw11_l;
|
||||
class memory;
|
||||
|
@ -91,7 +92,7 @@ public:
|
|||
|
||||
#if IS_POSIX
|
||||
json_t *serialize();
|
||||
static bus *deserialize(const json_t *const j);
|
||||
static bus *deserialize(const json_t *const j, console *const cnsl);
|
||||
#endif
|
||||
|
||||
void reset();
|
||||
|
@ -108,12 +109,13 @@ public:
|
|||
|
||||
void mmudebug(const uint16_t a);
|
||||
|
||||
void add_ram (memory *const m );
|
||||
void add_cpu (cpu *const c );
|
||||
void add_tm11(tm_11 *const tm11 );
|
||||
void add_rk05(rk05 *const rk05_);
|
||||
void add_rl02(rl02 *const rl02_);
|
||||
void add_tty (tty *const tty_ );
|
||||
void add_ram (memory *const m );
|
||||
void add_cpu (cpu *const c );
|
||||
void add_tm11 (tm_11 *const tm11 );
|
||||
void add_rk05 (rk05 *const rk05_ );
|
||||
void add_rl02 (rl02 *const rl02_ );
|
||||
void add_tty (tty *const tty_ );
|
||||
void add_KW11_L(kw11_l *const kw11_l_);
|
||||
|
||||
memory *getRAM() { return m; }
|
||||
cpu *getCpu() { return c; }
|
||||
|
|
27
kw11-l.cpp
27
kw11-l.cpp
|
@ -57,6 +57,11 @@ void kw11_l::begin(console *const cnsl)
|
|||
#endif
|
||||
}
|
||||
|
||||
void kw11_l::reset()
|
||||
{
|
||||
lf_csr = 0;
|
||||
}
|
||||
|
||||
void kw11_l::operator()()
|
||||
{
|
||||
set_thread_name("kek:kw-11l");
|
||||
|
@ -154,3 +159,25 @@ uint8_t kw11_l::get_lf_crs()
|
|||
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if IS_POSIX
|
||||
json_t *kw11_l::serialize()
|
||||
{
|
||||
json_t *j = json_object();
|
||||
|
||||
json_object_set(j, "CSR", json_integer(lf_csr));
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
kw11_l *kw11_l::deserialize(const json_t *const j, bus *const b, console *const cnsl)
|
||||
{
|
||||
uint16_t CSR = json_integer_value(json_object_get(j, "CSR"));
|
||||
|
||||
kw11_l *out = new kw11_l(b);
|
||||
out->lf_csr = CSR;
|
||||
out->begin(cnsl);
|
||||
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
|
8
kw11-l.h
8
kw11-l.h
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "bus.h"
|
||||
#include "console.h"
|
||||
#include "gen.h"
|
||||
|
||||
|
||||
class kw11_l
|
||||
|
@ -31,6 +32,13 @@ public:
|
|||
kw11_l(bus *const b);
|
||||
virtual ~kw11_l();
|
||||
|
||||
void reset();
|
||||
|
||||
#if IS_POSIX
|
||||
json_t *serialize();
|
||||
static kw11_l *deserialize(const json_t *const j, bus *const b, console *const cnsl);
|
||||
#endif
|
||||
|
||||
void begin(console *const cnsl);
|
||||
void operator()();
|
||||
|
||||
|
|
37
tty.cpp
37
tty.cpp
|
@ -1,4 +1,4 @@
|
|||
// (C) 2018-2023 by Folkert van Heusden
|
||||
// (C) 2018-2024 by Folkert van Heusden
|
||||
// Released under MIT license
|
||||
|
||||
#include <errno.h>
|
||||
|
@ -193,3 +193,38 @@ void tty::writeWord(const uint16_t addr, uint16_t v)
|
|||
DOLOG(debug, false, "set register %o to %o", addr, v);
|
||||
registers[(addr - PDP11TTY_BASE) / 2] = v;
|
||||
}
|
||||
|
||||
#if IS_POSIX
|
||||
json_t *tty::serialize()
|
||||
{
|
||||
json_t *j = json_object();
|
||||
|
||||
json_t *ja_reg = json_array();
|
||||
for(size_t i=0; i<4; i++)
|
||||
json_array_append(ja_reg, json_integer(registers[i]));
|
||||
json_object_set(j, "registers", ja_reg);
|
||||
|
||||
json_t *ja_buf = json_array();
|
||||
for(auto & c: chars)
|
||||
json_array_append(ja_buf, json_integer(c));
|
||||
json_object_set(j, "input-buffer", ja_buf);
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
tty *tty::deserialize(const json_t *const j, bus *const b, console *const cnsl)
|
||||
{
|
||||
tty *out = new tty(cnsl, b);
|
||||
|
||||
json_t *ja_reg = json_object_get(j, "registers");
|
||||
for(size_t i=0; i<4; i++)
|
||||
out->registers[i] = json_integer_value(json_array_get(ja_reg, i));
|
||||
|
||||
json_t *ja_buf = json_object_get(j, "input-buffer");
|
||||
size_t buf_size = json_array_size(ja_buf);
|
||||
for(size_t i=0; i<buf_size; i++)
|
||||
out->chars.push_back(json_integer_value(json_array_get(ja_buf, i)));
|
||||
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
|
8
tty.h
8
tty.h
|
@ -1,4 +1,4 @@
|
|||
// (C) 2018-2023 by Folkert van Heusden
|
||||
// (C) 2018-2024 by Folkert van Heusden
|
||||
// Released under MIT license
|
||||
|
||||
#pragma once
|
||||
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include "bus.h"
|
||||
#include "console.h"
|
||||
#include "gen.h"
|
||||
|
||||
|
||||
#define PDP11TTY_TKS 0177560 // reader status
|
||||
|
@ -50,6 +51,11 @@ public:
|
|||
tty(console *const c, bus *const b);
|
||||
virtual ~tty();
|
||||
|
||||
#if IS_POSIX
|
||||
json_t *serialize();
|
||||
static tty *deserialize(const json_t *const j, bus *const b, console *const cnsl);
|
||||
#endif
|
||||
|
||||
void reset();
|
||||
|
||||
uint8_t readByte(const uint16_t addr);
|
||||
|
|
Loading…
Add table
Reference in a new issue