Merge branch 'master' into psram
This commit is contained in:
commit
b9f8418ea0
45 changed files with 1253 additions and 441 deletions
|
@ -1,4 +1,4 @@
|
||||||
// (C) 2018-2023 by Folkert van Heusden
|
// (C) 2018-2024 by Folkert van Heusden
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
#include <Adafruit_NeoPixel.h>
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
@ -13,8 +13,8 @@
|
||||||
|
|
||||||
#define NEOPIXELS_PIN 25
|
#define NEOPIXELS_PIN 25
|
||||||
|
|
||||||
console_esp32::console_esp32(std::atomic_uint32_t *const stop_event, bus *const b, std::vector<Stream *> & io_ports, const int t_width, const int t_height) :
|
console_esp32::console_esp32(std::atomic_uint32_t *const stop_event, std::vector<Stream *> & io_ports, const int t_width, const int t_height) :
|
||||||
console(stop_event, b, t_width, t_height),
|
console(stop_event, t_width, t_height),
|
||||||
io_ports(io_ports)
|
io_ports(io_ports)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// (C) 2018-2023 by Folkert van Heusden
|
// (C) 2018-2024 by Folkert van Heusden
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
@ -18,7 +18,7 @@ protected:
|
||||||
void put_char_ll(const char c) override;
|
void put_char_ll(const char c) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
console_esp32(std::atomic_uint32_t *const stop_event, bus *const b, std::vector<Stream *> & io_ports, const int t_width, const int t_height);
|
console_esp32(std::atomic_uint32_t *const stop_event, std::vector<Stream *> & io_ports, const int t_width, const int t_height);
|
||||||
virtual ~console_esp32();
|
virtual ~console_esp32();
|
||||||
|
|
||||||
void put_string_lf(const std::string & what) override;
|
void put_string_lf(const std::string & what) override;
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
#define COLORED 0
|
#define COLORED 0
|
||||||
#define UNCOLORED 1
|
#define UNCOLORED 1
|
||||||
|
|
||||||
console_shabadge::console_shabadge(std::atomic_uint32_t *const stop_event, bus *const b, std::vector<Stream *> & io_ports) :
|
console_shabadge::console_shabadge(std::atomic_uint32_t *const stop_event, std::vector<Stream *> & io_ports) :
|
||||||
console_esp32(stop_event, b, io_ports, 296 / 8, 128 / 8)
|
console_esp32(stop_event, io_ports, 296 / 8, 128 / 8)
|
||||||
{
|
{
|
||||||
if (epd.Init() != 0)
|
if (epd.Init() != 0)
|
||||||
Serial.println("Init of DEPG0290B01 failed");
|
Serial.println("Init of DEPG0290B01 failed");
|
||||||
|
|
|
@ -22,7 +22,7 @@ private:
|
||||||
void put_char_ll(const char c) override;
|
void put_char_ll(const char c) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
console_shabadge(std::atomic_uint32_t *const stop_event, bus *const b, std::vector<Stream *> & io_ports);
|
console_shabadge(std::atomic_uint32_t *const stop_event, std::vector<Stream *> & io_ports);
|
||||||
virtual ~console_shabadge();
|
virtual ~console_shabadge();
|
||||||
|
|
||||||
void panel_update_thread() override;
|
void panel_update_thread() override;
|
||||||
|
|
|
@ -29,7 +29,7 @@ void disk_backend_esp32::emit_error()
|
||||||
DOLOG(ll_error, true, "SdFat error: %d/%d", sd.sdErrorCode(), sd.sdErrorData());
|
DOLOG(ll_error, true, "SdFat error: %d/%d", sd.sdErrorCode(), sd.sdErrorData());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_backend_esp32::begin()
|
bool disk_backend_esp32::begin(const bool dummy)
|
||||||
{
|
{
|
||||||
if (!fh->open(filename.c_str(), O_RDWR)) {
|
if (!fh->open(filename.c_str(), O_RDWR)) {
|
||||||
DOLOG(ll_error, true, "rk05: cannot open \"%s\"", filename.c_str());
|
DOLOG(ll_error, true, "rk05: cannot open \"%s\"", filename.c_str());
|
||||||
|
@ -41,7 +41,7 @@ bool disk_backend_esp32::begin()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_backend_esp32::read(const off_t offset, const size_t n, uint8_t *const target)
|
bool disk_backend_esp32::read(const off_t offset, const size_t n, uint8_t *const target, const size_t sector_size)
|
||||||
{
|
{
|
||||||
DOLOG(debug, false, "disk_backend_esp32::read: read %zu bytes from offset %zu", n, offset);
|
DOLOG(debug, false, "disk_backend_esp32::read: read %zu bytes from offset %zu", n, offset);
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ bool disk_backend_esp32::read(const off_t offset, const size_t n, uint8_t *const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_backend_esp32::write(const off_t offset, const size_t n, const uint8_t *const from)
|
bool disk_backend_esp32::write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size)
|
||||||
{
|
{
|
||||||
DOLOG(debug, false, "disk_backend_esp32::write: write %zu bytes to offset %zu", n, offset);
|
DOLOG(debug, false, "disk_backend_esp32::write: write %zu bytes to offset %zu", n, offset);
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,11 @@ public:
|
||||||
disk_backend_esp32(const std::string & filename);
|
disk_backend_esp32(const std::string & filename);
|
||||||
virtual ~disk_backend_esp32();
|
virtual ~disk_backend_esp32();
|
||||||
|
|
||||||
bool begin() override;
|
std::string get_identifier() const { return filename; }
|
||||||
|
|
||||||
bool read(const off_t offset, const size_t n, uint8_t *const target) override;
|
bool begin(const bool dummy) override;
|
||||||
|
|
||||||
bool write(const off_t offset, const size_t n, const uint8_t *const from) override;
|
bool read(const off_t offset, const size_t n, uint8_t *const target, const size_t sector_size) override;
|
||||||
|
|
||||||
|
bool write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
#include "esp32.h"
|
#include "esp32.h"
|
||||||
#endif
|
#endif
|
||||||
#include "gen.h"
|
#include "gen.h"
|
||||||
#include "kw11-l.h"
|
|
||||||
#include "loaders.h"
|
#include "loaders.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "tty.h"
|
#include "tty.h"
|
||||||
|
@ -217,7 +216,7 @@ void setup() {
|
||||||
while(!Serial)
|
while(!Serial)
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
Serial.println(F("This PDP-11 emulator is called \"kek\" (reason for that is forgotten) and was written by Folkert van Heusden."));
|
Serial.println(F("PDP11 emulator, by Folkert van Heusden"));
|
||||||
Serial.print(F("GIT hash: "));
|
Serial.print(F("GIT hash: "));
|
||||||
Serial.println(version_str);
|
Serial.println(version_str);
|
||||||
Serial.println(F("Build on: " __DATE__ " " __TIME__));
|
Serial.println(F("Build on: " __DATE__ " " __TIME__));
|
||||||
|
@ -291,13 +290,11 @@ void setup() {
|
||||||
|
|
||||||
std::vector<Stream *> serial_ports { &Serial_RS232, &Serial };
|
std::vector<Stream *> serial_ports { &Serial_RS232, &Serial };
|
||||||
#if defined(SHA2017)
|
#if defined(SHA2017)
|
||||||
cnsl = new console_shabadge(&stop_event, b, serial_ports);
|
cnsl = new console_shabadge(&stop_event, serial_ports);
|
||||||
#elif defined(ESP32) || defined(BUILD_FOR_RP2040)
|
#elif defined(ESP32) || defined(BUILD_FOR_RP2040)
|
||||||
cnsl = new console_esp32(&stop_event, b, serial_ports, 80, 25);
|
cnsl = new console_esp32(&stop_event, serial_ports, 80, 25);
|
||||||
#endif
|
#endif
|
||||||
|
cnsl->set_bus(b);
|
||||||
Serial.println(F("Start line-frequency interrupt"));
|
|
||||||
kw11_l *lf = new kw11_l(b, cnsl);
|
|
||||||
|
|
||||||
running = cnsl->get_running_flag();
|
running = cnsl->get_running_flag();
|
||||||
|
|
||||||
|
|
1
ESP32/mmu.cpp
Symbolic link
1
ESP32/mmu.cpp
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../mmu.cpp
|
1
ESP32/mmu.h
Symbolic link
1
ESP32/mmu.h
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../mmu.h
|
|
@ -1,4 +1,4 @@
|
||||||
# (C) 2018-2023 by Folkert van Heusden
|
# (C) 2018-2024 by Folkert van Heusden
|
||||||
# Released under MIT license
|
# Released under MIT license
|
||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
|
|
173
bus.cpp
173
bus.cpp
|
@ -8,6 +8,7 @@
|
||||||
#include "bus.h"
|
#include "bus.h"
|
||||||
#include "gen.h"
|
#include "gen.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
|
#include "kw11-l.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "mmu.h"
|
#include "mmu.h"
|
||||||
|
@ -22,19 +23,16 @@
|
||||||
|
|
||||||
bus::bus()
|
bus::bus()
|
||||||
{
|
{
|
||||||
m = new memory(n_pages * 8192l);
|
|
||||||
|
|
||||||
mmu_ = new mmu();
|
mmu_ = new mmu();
|
||||||
|
|
||||||
reset();
|
kw11_l_ = new kw11_l(this);
|
||||||
|
|
||||||
#if defined(BUILD_FOR_RP2040)
|
reset();
|
||||||
xSemaphoreGive(lf_csr_lock); // initialize
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bus::~bus()
|
bus::~bus()
|
||||||
{
|
{
|
||||||
|
delete kw11_l_;
|
||||||
delete c;
|
delete c;
|
||||||
delete tm11;
|
delete tm11;
|
||||||
delete rk05_;
|
delete rk05_;
|
||||||
|
@ -44,6 +42,82 @@ bus::~bus()
|
||||||
delete m;
|
delete m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
|
json_t *bus::serialize() const
|
||||||
|
{
|
||||||
|
json_t *j_out = json_object();
|
||||||
|
|
||||||
|
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());
|
||||||
|
|
||||||
|
if (mmu_)
|
||||||
|
json_object_set(j_out, "mmu", mmu_->serialize());
|
||||||
|
|
||||||
|
if (c)
|
||||||
|
json_object_set(j_out, "cpu", c->serialize());
|
||||||
|
|
||||||
|
if (rl02_)
|
||||||
|
json_object_set(j_out, "rl02", rl02_->serialize());
|
||||||
|
|
||||||
|
// TODO: rk05, tm11
|
||||||
|
|
||||||
|
return j_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
bus *bus::deserialize(const json_t *const j, console *const cnsl, std::atomic_uint32_t *const event)
|
||||||
|
{
|
||||||
|
bus *b = new bus();
|
||||||
|
|
||||||
|
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_);
|
||||||
|
}
|
||||||
|
|
||||||
|
temp = json_object_get(j, "mmu");
|
||||||
|
if (temp) {
|
||||||
|
mmu *mmu_ = mmu::deserialize(temp);
|
||||||
|
b->add_mmu(mmu_);
|
||||||
|
}
|
||||||
|
|
||||||
|
temp = json_object_get(j, "cpu");
|
||||||
|
if (temp) {
|
||||||
|
cpu *cpu_ = cpu::deserialize(temp, b, event);
|
||||||
|
b->add_cpu(cpu_);
|
||||||
|
}
|
||||||
|
|
||||||
|
temp = json_object_get(j, "rl02");
|
||||||
|
if (temp) {
|
||||||
|
rl02 *rl02_ = rl02::deserialize(temp, b);
|
||||||
|
b->add_rl02(rl02_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: rk05, tm11
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void bus::set_memory_size(const int n_pages)
|
void bus::set_memory_size(const int n_pages)
|
||||||
{
|
{
|
||||||
this->n_pages = n_pages;
|
this->n_pages = n_pages;
|
||||||
|
@ -58,10 +132,10 @@ void bus::set_memory_size(const int n_pages)
|
||||||
|
|
||||||
void bus::reset()
|
void bus::reset()
|
||||||
{
|
{
|
||||||
|
if (m)
|
||||||
m->reset();
|
m->reset();
|
||||||
|
if (mmu_)
|
||||||
mmu_->reset();
|
mmu_->reset();
|
||||||
|
|
||||||
if (c)
|
if (c)
|
||||||
c->reset();
|
c->reset();
|
||||||
if (tm11)
|
if (tm11)
|
||||||
|
@ -72,6 +146,26 @@ void bus::reset()
|
||||||
rl02_->reset();
|
rl02_->reset();
|
||||||
if (tty_)
|
if (tty_)
|
||||||
tty_->reset();
|
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)
|
||||||
|
{
|
||||||
|
delete this->m;
|
||||||
|
this->m = m;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bus::add_mmu(mmu *const mmu_)
|
||||||
|
{
|
||||||
|
delete this->mmu_;
|
||||||
|
this->mmu_ = mmu_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bus::add_cpu(cpu *const c)
|
void bus::add_cpu(cpu *const c)
|
||||||
|
@ -83,7 +177,7 @@ void bus::add_cpu(cpu *const c)
|
||||||
void bus::add_tm11(tm_11 *const tm11)
|
void bus::add_tm11(tm_11 *const tm11)
|
||||||
{
|
{
|
||||||
delete this->tm11;
|
delete this->tm11;
|
||||||
this->tm11 = tm11;
|
this->tm11= tm11;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bus::add_rk05(rk05 *const rk05_)
|
void bus::add_rk05(rk05 *const rk05_)
|
||||||
|
@ -220,22 +314,8 @@ uint16_t bus::read(const uint16_t addr_in, const word_mode_t word_mode, const rm
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a == ADDR_LFC) { // line frequency clock and status register
|
if (a == ADDR_LFC) // line frequency clock and status register
|
||||||
#if defined(BUILD_FOR_RP2040)
|
return kw11_l_->readWord(a);
|
||||||
xSemaphoreTake(lf_csr_lock, portMAX_DELAY);
|
|
||||||
#else
|
|
||||||
std::unique_lock<std::mutex> lck(lf_csr_lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
uint16_t temp = lf_csr;
|
|
||||||
if (!peek_only) DOLOG(debug, false, "READ-I/O line frequency clock: %o", temp);
|
|
||||||
|
|
||||||
#if defined(BUILD_FOR_RP2040)
|
|
||||||
xSemaphoreGive(lf_csr_lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a == ADDR_LP11CSR) { // printer, CSR register, LP11
|
if (a == ADDR_LP11CSR) { // printer, CSR register, LP11
|
||||||
uint16_t temp = 0x80;
|
uint16_t temp = 0x80;
|
||||||
|
@ -848,17 +928,8 @@ write_rc_t bus::write(const uint16_t addr_in, const word_mode_t word_mode, uint1
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a == ADDR_LFC) { // line frequency clock and status register
|
if (a == ADDR_LFC) { // line frequency clock and status register
|
||||||
#if defined(BUILD_FOR_RP2040)
|
kw11_l_->writeWord(a, value);
|
||||||
xSemaphoreTake(lf_csr_lock, portMAX_DELAY);
|
|
||||||
#else
|
|
||||||
std::unique_lock<std::mutex> lck(lf_csr_lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DOLOG(debug, false, "WRITE-I/O set line frequency clock/status register: %06o", value);
|
|
||||||
lf_csr = value;
|
|
||||||
#if defined(BUILD_FOR_RP2040)
|
|
||||||
xSemaphoreGive(lf_csr_lock);
|
|
||||||
#endif
|
|
||||||
return { false };
|
return { false };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1023,35 +1094,3 @@ void bus::writeUnibusByte(const uint32_t a, const uint8_t v)
|
||||||
DOLOG(debug, false, "writeUnibusByte[%08o]=%03o", a, v);
|
DOLOG(debug, false, "writeUnibusByte[%08o]=%03o", a, v);
|
||||||
m->writeByte(a, v);
|
m->writeByte(a, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bus::set_lf_crs_b7()
|
|
||||||
{
|
|
||||||
#if defined(BUILD_FOR_RP2040)
|
|
||||||
xSemaphoreTake(lf_csr_lock, portMAX_DELAY);
|
|
||||||
#else
|
|
||||||
std::unique_lock<std::mutex> lck(lf_csr_lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lf_csr |= 128;
|
|
||||||
|
|
||||||
#if defined(BUILD_FOR_RP2040)
|
|
||||||
xSemaphoreGive(lf_csr_lock);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t bus::get_lf_crs()
|
|
||||||
{
|
|
||||||
#if defined(BUILD_FOR_RP2040)
|
|
||||||
xSemaphoreTake(lf_csr_lock, portMAX_DELAY);
|
|
||||||
#else
|
|
||||||
std::unique_lock<std::mutex> lck(lf_csr_lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
uint8_t rc = lf_csr;
|
|
||||||
|
|
||||||
#if defined(BUILD_FOR_RP2040)
|
|
||||||
xSemaphoreGive(lf_csr_lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
51
bus.h
51
bus.h
|
@ -18,14 +18,6 @@
|
||||||
#include "rp2040.h"
|
#include "rp2040.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ESP32) || defined(BUILD_FOR_RP2040)
|
|
||||||
// ESP32 goes in a crash-loop when allocating 128kB
|
|
||||||
// see also https://github.com/espressif/esp-idf/issues/1934
|
|
||||||
#define DEFAULT_N_PAGES 12
|
|
||||||
#else
|
|
||||||
#define DEFAULT_N_PAGES 31
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ADDR_MMR0 0177572
|
#define ADDR_MMR0 0177572
|
||||||
#define ADDR_MMR1 0177574
|
#define ADDR_MMR1 0177574
|
||||||
#define ADDR_MMR2 0177576
|
#define ADDR_MMR2 0177576
|
||||||
|
@ -53,7 +45,9 @@
|
||||||
#define ADDR_CCR 0177746
|
#define ADDR_CCR 0177746
|
||||||
#define ADDR_SYSTEM_ID 0177764
|
#define ADDR_SYSTEM_ID 0177764
|
||||||
|
|
||||||
|
class console;
|
||||||
class cpu;
|
class cpu;
|
||||||
|
class kw11_l;
|
||||||
class memory;
|
class memory;
|
||||||
class tty;
|
class tty;
|
||||||
|
|
||||||
|
@ -80,19 +74,13 @@ private:
|
||||||
rk05 *rk05_ { nullptr };
|
rk05 *rk05_ { nullptr };
|
||||||
rl02 *rl02_ { nullptr };
|
rl02 *rl02_ { nullptr };
|
||||||
tty *tty_ { nullptr };
|
tty *tty_ { nullptr };
|
||||||
|
kw11_l *kw11_l_ { nullptr };
|
||||||
|
|
||||||
mmu *mmu_ { nullptr };
|
mmu *mmu_ { nullptr };
|
||||||
|
|
||||||
int n_pages { DEFAULT_N_PAGES };
|
int n_pages { DEFAULT_N_PAGES };
|
||||||
memory *m { nullptr };
|
memory *m { nullptr };
|
||||||
|
|
||||||
#if defined(BUILD_FOR_RP2040)
|
|
||||||
SemaphoreHandle_t lf_csr_lock { xSemaphoreCreateBinary() };
|
|
||||||
#else
|
|
||||||
std::mutex lf_csr_lock;
|
|
||||||
#endif
|
|
||||||
uint16_t lf_csr { 0 };
|
|
||||||
|
|
||||||
uint16_t microprogram_break_register { 0 };
|
uint16_t microprogram_break_register { 0 };
|
||||||
|
|
||||||
uint16_t console_switches { 0 };
|
uint16_t console_switches { 0 };
|
||||||
|
@ -102,36 +90,41 @@ public:
|
||||||
bus();
|
bus();
|
||||||
~bus();
|
~bus();
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
|
json_t *serialize() const;
|
||||||
|
static bus *deserialize(const json_t *const j, console *const cnsl, std::atomic_uint32_t *const event);
|
||||||
|
#endif
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
void init(); // invoked by 'RESET' command
|
||||||
|
|
||||||
void set_console_switches(const uint16_t new_state) { console_switches = new_state; }
|
void set_console_switches(const uint16_t new_state) { console_switches = new_state; }
|
||||||
void set_console_switch(const int bit, const bool state) { console_switches &= ~(1 << bit); console_switches |= state << bit; }
|
void set_console_switch(const int bit, const bool state) { console_switches &= ~(1 << bit); console_switches |= state << bit; }
|
||||||
uint16_t get_console_switches() { return console_switches; }
|
uint16_t get_console_switches() { return console_switches; }
|
||||||
void set_debug_mode() { console_switches |= 128; }
|
void set_debug_mode() { console_switches |= 128; }
|
||||||
|
uint16_t get_console_leds() { return console_leds; }
|
||||||
|
|
||||||
int get_memory_size() const { return n_pages; }
|
int get_memory_size() const { return n_pages; }
|
||||||
void set_memory_size(const int n_pages);
|
void set_memory_size(const int n_pages);
|
||||||
|
|
||||||
void mmudebug(const uint16_t a);
|
void mmudebug(const uint16_t a);
|
||||||
|
|
||||||
uint16_t get_console_leds() { return console_leds; }
|
void add_ram (memory *const m );
|
||||||
|
void add_cpu (cpu *const c );
|
||||||
void add_cpu (cpu *const c);
|
void add_mmu (mmu *const mmu_ );
|
||||||
void add_tm11(tm_11 *const tm11);
|
void add_tm11 (tm_11 *const tm11 );
|
||||||
void add_rk05(rk05 *const rk05_);
|
void add_rk05 (rk05 *const rk05_ );
|
||||||
void add_rl02(rl02 *const rl02_);
|
void add_rl02 (rl02 *const rl02_ );
|
||||||
void add_tty (tty *const tty_);
|
void add_tty (tty *const tty_ );
|
||||||
|
void add_KW11_L(kw11_l *const kw11_l_);
|
||||||
|
|
||||||
|
memory *getRAM() { return m; }
|
||||||
cpu *getCpu() { return c; }
|
cpu *getCpu() { return c; }
|
||||||
|
kw11_l *getKW11_L() { return kw11_l_; }
|
||||||
tty *getTty() { return tty_; }
|
tty *getTty() { return tty_; }
|
||||||
|
|
||||||
mmu *getMMU() { return mmu_; }
|
mmu *getMMU() { return mmu_; }
|
||||||
|
rk05 *getRK05() { return rk05_; }
|
||||||
void init(); // invoked by 'RESET' command
|
rl02 *getRL02() { return rl02_; }
|
||||||
|
|
||||||
void set_lf_crs_b7();
|
|
||||||
uint8_t get_lf_crs();
|
|
||||||
|
|
||||||
uint16_t read (const uint16_t a, const word_mode_t word_mode, const rm_selection_t mode_selection, const bool peek_only=false, const d_i_space_t s = i_space);
|
uint16_t read (const uint16_t a, const word_mode_t word_mode, const rm_selection_t mode_selection, const bool peek_only=false, const d_i_space_t s = i_space);
|
||||||
uint16_t readByte(const uint16_t a) { return read(a, wm_byte, rm_cur); }
|
uint16_t readByte(const uint16_t a) { return read(a, wm_byte, rm_cur); }
|
||||||
|
|
|
@ -25,9 +25,8 @@ void thread_wrapper_console(void *p)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
console::console(std::atomic_uint32_t *const stop_event, bus *const b, const int t_width, const int t_height) :
|
console::console(std::atomic_uint32_t *const stop_event, const int t_width, const int t_height) :
|
||||||
stop_event(stop_event),
|
stop_event(stop_event),
|
||||||
b(b),
|
|
||||||
t_width(t_width),
|
t_width(t_width),
|
||||||
t_height(t_height)
|
t_height(t_height)
|
||||||
{
|
{
|
||||||
|
@ -49,6 +48,8 @@ console::~console()
|
||||||
|
|
||||||
void console::start_thread()
|
void console::start_thread()
|
||||||
{
|
{
|
||||||
|
assert(b);
|
||||||
|
|
||||||
stop_thread_flag = false;
|
stop_thread_flag = false;
|
||||||
|
|
||||||
#if defined(BUILD_FOR_RP2040)
|
#if defined(BUILD_FOR_RP2040)
|
||||||
|
|
|
@ -31,7 +31,7 @@ private:
|
||||||
protected:
|
protected:
|
||||||
std::atomic_uint32_t *const stop_event { nullptr };
|
std::atomic_uint32_t *const stop_event { nullptr };
|
||||||
|
|
||||||
bus *const b { nullptr };
|
bus *b { nullptr };
|
||||||
#if !defined(BUILD_FOR_RP2040)
|
#if !defined(BUILD_FOR_RP2040)
|
||||||
std::thread *th { nullptr };
|
std::thread *th { nullptr };
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,9 +57,11 @@ protected:
|
||||||
virtual void put_char_ll(const char c) = 0;
|
virtual void put_char_ll(const char c) = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
console(std::atomic_uint32_t *const stop_event, bus *const b, const int t_width = 80, const int t_height = 25);
|
console(std::atomic_uint32_t *const stop_event, const int t_width = 80, const int t_height = 25);
|
||||||
virtual ~console();
|
virtual ~console();
|
||||||
|
|
||||||
|
void set_bus(bus *const b) { this->b = b; }
|
||||||
|
|
||||||
void start_thread();
|
void start_thread();
|
||||||
void stop_thread();
|
void stop_thread();
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,7 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
|
||||||
console_ncurses::console_ncurses(std::atomic_uint32_t *const stop_event, bus *const b) :
|
console_ncurses::console_ncurses(std::atomic_uint32_t *const stop_event): console(stop_event)
|
||||||
console(stop_event, b)
|
|
||||||
{
|
{
|
||||||
init_ncurses(true);
|
init_ncurses(true);
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ protected:
|
||||||
void put_char_ll(const char c) override;
|
void put_char_ll(const char c) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
console_ncurses(std::atomic_uint32_t *const stop_event, bus *const b);
|
console_ncurses(std::atomic_uint32_t *const stop_event);
|
||||||
virtual ~console_ncurses();
|
virtual ~console_ncurses();
|
||||||
|
|
||||||
void put_string_lf(const std::string & what) override;
|
void put_string_lf(const std::string & what) override;
|
||||||
|
|
|
@ -16,8 +16,7 @@
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
|
||||||
|
|
||||||
console_posix::console_posix(std::atomic_uint32_t *const stop_event, bus *const b) :
|
console_posix::console_posix(std::atomic_uint32_t *const stop_event): console(stop_event)
|
||||||
console(stop_event, b)
|
|
||||||
{
|
{
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
if (tcgetattr(STDIN_FILENO, &org_tty_opts) == -1)
|
if (tcgetattr(STDIN_FILENO, &org_tty_opts) == -1)
|
||||||
|
|
|
@ -21,7 +21,7 @@ protected:
|
||||||
void put_char_ll(const char c) override;
|
void put_char_ll(const char c) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
console_posix(std::atomic_uint32_t *const stop_event, bus *const b);
|
console_posix(std::atomic_uint32_t *const stop_event);
|
||||||
virtual ~console_posix();
|
virtual ~console_posix();
|
||||||
|
|
||||||
void resize_terminal() override;
|
void resize_terminal() override;
|
||||||
|
|
87
cpu.cpp
87
cpu.cpp
|
@ -2395,3 +2395,90 @@ void cpu::step()
|
||||||
DOLOG(debug, false, "bus-trap during execution of command (%d)", exception_nr);
|
DOLOG(debug, false, "bus-trap during execution of command (%d)", exception_nr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
|
json_t *cpu::serialize()
|
||||||
|
{
|
||||||
|
json_t *j = json_object();
|
||||||
|
|
||||||
|
for(int set=0; set<2; set++) {
|
||||||
|
for(int regnr=0; regnr<6; regnr++)
|
||||||
|
json_object_set(j, format("register-%d-%d", set, regnr).c_str(), json_integer(regs0_5[set][regnr]));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int spnr=0; spnr<4; spnr++)
|
||||||
|
json_object_set(j, format("sp-%d", spnr).c_str(), json_integer(sp[spnr]));
|
||||||
|
|
||||||
|
json_object_set(j, "pc", json_integer(pc));
|
||||||
|
json_object_set(j, "instruction_start", json_integer(instruction_start));
|
||||||
|
json_object_set(j, "psw", json_integer(psw));
|
||||||
|
json_object_set(j, "fpsr", json_integer(fpsr));
|
||||||
|
json_object_set(j, "stackLimitRegister", json_integer(stackLimitRegister));
|
||||||
|
json_object_set(j, "processing_trap_depth", json_integer(processing_trap_depth));
|
||||||
|
json_object_set(j, "instruction_count", json_integer(instruction_count));
|
||||||
|
json_object_set(j, "running_since", json_integer(running_since));
|
||||||
|
json_object_set(j, "wait_time", json_integer(wait_time));
|
||||||
|
json_object_set(j, "it_is_a_trap", json_boolean(it_is_a_trap));
|
||||||
|
json_object_set(j, "debug_mode", json_boolean(debug_mode));
|
||||||
|
if (trap_delay.has_value())
|
||||||
|
json_object_set(j, "trap_delay", json_integer(trap_delay.value()));
|
||||||
|
|
||||||
|
json_t *j_queued_interrupts = json_object();
|
||||||
|
for(auto & il: queued_interrupts) {
|
||||||
|
json_t *ja_qi_level = json_array();
|
||||||
|
for(auto & v: il.second)
|
||||||
|
json_array_append(ja_qi_level, json_integer(v));
|
||||||
|
|
||||||
|
json_object_set(j_queued_interrupts, format("%d", il.first).c_str(), ja_qi_level);
|
||||||
|
}
|
||||||
|
json_object_set(j, "queued_interrupts", j_queued_interrupts);
|
||||||
|
|
||||||
|
json_object_set(j, "any_queued_interrupts", json_boolean(any_queued_interrupts));
|
||||||
|
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu *cpu::deserialize(const json_t *const j, bus *const b, std::atomic_uint32_t *const event)
|
||||||
|
{
|
||||||
|
cpu *c = new cpu(b, event);
|
||||||
|
|
||||||
|
for(int set=0; set<2; set++) {
|
||||||
|
for(int regnr=0; regnr<6; regnr++)
|
||||||
|
c->regs0_5[set][regnr] = json_integer_value(json_object_get(j, format("register-%d-%d", set, regnr).c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int spnr=0; spnr<4; spnr++)
|
||||||
|
c->sp[spnr] = json_integer_value(json_object_get(j, format("sp-%d", spnr).c_str()));
|
||||||
|
|
||||||
|
c->pc = json_integer_value(json_object_get(j, "pc"));
|
||||||
|
c->instruction_start = json_integer_value(json_object_get(j, "instruction_start"));
|
||||||
|
c->psw = json_integer_value(json_object_get(j, "psw"));
|
||||||
|
c->fpsr = json_integer_value(json_object_get(j, "fpsr"));
|
||||||
|
c->stackLimitRegister = json_integer_value(json_object_get(j, "stackLimitRegister"));
|
||||||
|
c->processing_trap_depth = json_integer_value(json_object_get(j, "processing_trap_depth"));
|
||||||
|
c->instruction_count = json_integer_value(json_object_get(j, "instruction_count"));
|
||||||
|
c->running_since = get_us();
|
||||||
|
c->wait_time = 0;
|
||||||
|
c->it_is_a_trap = json_boolean_value(json_object_get(j, "it_is_a_trap"));
|
||||||
|
c->debug_mode = json_boolean_value(json_object_get(j, "debug_mode"));
|
||||||
|
json_t *temp = json_object_get(j, "trap_delay");
|
||||||
|
if (temp)
|
||||||
|
c->trap_delay = json_integer_value(temp);
|
||||||
|
else
|
||||||
|
c->trap_delay.reset();
|
||||||
|
c->any_queued_interrupts = json_boolean_value(json_object_get(j, "any_queued_interrupts"));
|
||||||
|
|
||||||
|
c->init_interrupt_queue();
|
||||||
|
json_t *j_queued_interrupts = json_object_get(j, "queued_interrupts");
|
||||||
|
for(int level=0; level<8; level++) {
|
||||||
|
auto it = c->queued_interrupts.find(level);
|
||||||
|
|
||||||
|
json_t *ja_qi_level = json_object_get(j_queued_interrupts, format("%d", level).c_str());
|
||||||
|
|
||||||
|
for(size_t i=0; i<json_array_size(ja_qi_level); i++)
|
||||||
|
it->second.insert(json_integer_value(json_array_get(ja_qi_level, i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
8
cpu.h
8
cpu.h
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include "breakpoint.h"
|
#include "breakpoint.h"
|
||||||
#include "bus.h"
|
#include "bus.h"
|
||||||
|
#include "gen.h"
|
||||||
|
|
||||||
|
|
||||||
constexpr const int initial_trap_delay = 8;
|
constexpr const int initial_trap_delay = 8;
|
||||||
|
@ -61,6 +62,7 @@ private:
|
||||||
|
|
||||||
// level, vector
|
// level, vector
|
||||||
std::map<uint8_t, std::set<uint8_t> > queued_interrupts;
|
std::map<uint8_t, std::set<uint8_t> > queued_interrupts;
|
||||||
|
std::atomic_bool any_queued_interrupts { false };
|
||||||
#if defined(BUILD_FOR_RP2040)
|
#if defined(BUILD_FOR_RP2040)
|
||||||
SemaphoreHandle_t qi_lock { xSemaphoreCreateBinary() };
|
SemaphoreHandle_t qi_lock { xSemaphoreCreateBinary() };
|
||||||
QueueHandle_t qi_q { xQueueCreate(16, 1) };
|
QueueHandle_t qi_q { xQueueCreate(16, 1) };
|
||||||
|
@ -68,7 +70,6 @@ private:
|
||||||
std::mutex qi_lock;
|
std::mutex qi_lock;
|
||||||
std::condition_variable qi_cv;
|
std::condition_variable qi_cv;
|
||||||
#endif
|
#endif
|
||||||
std::atomic_bool any_queued_interrupts { false };
|
|
||||||
|
|
||||||
std::map<int, breakpoint *> breakpoints;
|
std::map<int, breakpoint *> breakpoints;
|
||||||
int bp_nr { 0 };
|
int bp_nr { 0 };
|
||||||
|
@ -111,6 +112,11 @@ public:
|
||||||
explicit cpu(bus *const b, std::atomic_uint32_t *const event);
|
explicit cpu(bus *const b, std::atomic_uint32_t *const event);
|
||||||
~cpu();
|
~cpu();
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
|
json_t *serialize();
|
||||||
|
static cpu *deserialize(const json_t *const j, bus *const b, std::atomic_uint32_t *const event);
|
||||||
|
#endif
|
||||||
|
|
||||||
std::optional<std::string> check_breakpoint();
|
std::optional<std::string> check_breakpoint();
|
||||||
int set_breakpoint(breakpoint *const bp);
|
int set_breakpoint(breakpoint *const bp);
|
||||||
bool remove_breakpoint(const int bp_id);
|
bool remove_breakpoint(const int bp_id);
|
||||||
|
|
287
debugger.cpp
287
debugger.cpp
|
@ -2,7 +2,8 @@
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#ifdef linux
|
#include "gen.h"
|
||||||
|
#if IS_POSIX
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -18,13 +19,12 @@
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "disk_backend.h"
|
#include "disk_backend.h"
|
||||||
#ifdef linux
|
#if IS_POSIX
|
||||||
#include "disk_backend_file.h"
|
#include "disk_backend_file.h"
|
||||||
#else
|
#else
|
||||||
#include "disk_backend_esp32.h"
|
#include "disk_backend_esp32.h"
|
||||||
#endif
|
#endif
|
||||||
#include "disk_backend_nbd.h"
|
#include "disk_backend_nbd.h"
|
||||||
#include "gen.h"
|
|
||||||
#include "loaders.h"
|
#include "loaders.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "tty.h"
|
#include "tty.h"
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
#include "rp2040.h"
|
#include "rp2040.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void setBootLoader(bus *const b);
|
void set_boot_loader(bus *const b);
|
||||||
|
|
||||||
void configure_disk(console *const c);
|
void configure_disk(console *const c);
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ typedef enum { BE_NETWORK, BE_SD } disk_backend_t;
|
||||||
#if !defined(BUILD_FOR_RP2040)
|
#if !defined(BUILD_FOR_RP2040)
|
||||||
std::optional<std::tuple<std::vector<disk_backend *>, std::vector<disk_backend *>, std::string> > load_disk_configuration(console *const c)
|
std::optional<std::tuple<std::vector<disk_backend *>, std::vector<disk_backend *>, std::string> > load_disk_configuration(console *const c)
|
||||||
{
|
{
|
||||||
#ifdef linux
|
#if IS_POSIX
|
||||||
json_error_t error;
|
json_error_t error;
|
||||||
json_t *json = json_load_file("." NET_DISK_CFG_FILE, JSON_REJECT_DUPLICATES, &error);
|
json_t *json = json_load_file("." NET_DISK_CFG_FILE, JSON_REJECT_DUPLICATES, &error);
|
||||||
if (!json) {
|
if (!json) {
|
||||||
|
@ -125,7 +125,7 @@ std::optional<std::tuple<std::vector<disk_backend *>, std::vector<disk_backend *
|
||||||
|
|
||||||
disk_backend *d = new disk_backend_nbd(nbd_host.c_str(), nbd_port);
|
disk_backend *d = new disk_backend_nbd(nbd_host.c_str(), nbd_port);
|
||||||
|
|
||||||
if (d->begin() == false) {
|
if (d->begin(false) == false) {
|
||||||
c->put_string_lf("Cannot initialize NBD client from configuration file");
|
c->put_string_lf("Cannot initialize NBD client from configuration file");
|
||||||
delete d;
|
delete d;
|
||||||
return { };
|
return { };
|
||||||
|
@ -147,7 +147,7 @@ std::optional<std::tuple<std::vector<disk_backend *>, std::vector<disk_backend *
|
||||||
|
|
||||||
bool save_disk_configuration(const std::string & nbd_host, const int nbd_port, const std::optional<std::string> & tape_file, const disk_type_t dt, console *const cnsl)
|
bool save_disk_configuration(const std::string & nbd_host, const int nbd_port, const std::optional<std::string> & tape_file, const disk_type_t dt, console *const cnsl)
|
||||||
{
|
{
|
||||||
#ifdef linux
|
#if IS_POSIX
|
||||||
json_t *json = json_object();
|
json_t *json = json_object();
|
||||||
|
|
||||||
json_object_set(json, "NBD-host", json_string(nbd_host.c_str()));
|
json_object_set(json, "NBD-host", json_string(nbd_host.c_str()));
|
||||||
|
@ -196,108 +196,37 @@ bool save_disk_configuration(const std::string & nbd_host, const int nbd_port, c
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::optional<disk_backend_t> select_disk_backend(console *const c)
|
|
||||||
{
|
|
||||||
#if defined(BUILD_FOR_RP2040)
|
|
||||||
return BE_SD;
|
|
||||||
#elif linux
|
|
||||||
c->put_string("1. network (NBD), 2. local filesystem, 9. abort");
|
|
||||||
#else
|
|
||||||
c->put_string("1. network (NBD), 2. local SD card, 9. abort");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int ch = -1;
|
|
||||||
while(ch == -1 && ch != '1' && ch != '2' && ch != '9') {
|
|
||||||
auto temp = c->wait_char(500);
|
|
||||||
|
|
||||||
if (temp.has_value())
|
|
||||||
ch = temp.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
c->put_string_lf(format("%c", ch));
|
|
||||||
|
|
||||||
if (ch == '1')
|
|
||||||
return BE_NETWORK;
|
|
||||||
|
|
||||||
if (ch == '2')
|
|
||||||
return BE_SD;
|
|
||||||
|
|
||||||
return { };
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<disk_type_t> select_disk_type(console *const c)
|
|
||||||
{
|
|
||||||
c->put_string("1. RK05, 2. RL02, 3. tape/BIC, 9. abort");
|
|
||||||
|
|
||||||
int ch = -1;
|
|
||||||
while(ch == -1 && ch != '1' && ch != '2' && ch != '3' && ch != '9') {
|
|
||||||
auto temp = c->wait_char(500);
|
|
||||||
|
|
||||||
if (temp.has_value())
|
|
||||||
ch = temp.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
c->put_string_lf(format("%c", ch));
|
|
||||||
|
|
||||||
if (ch == '1')
|
|
||||||
return DT_RK05;
|
|
||||||
|
|
||||||
if (ch == '2')
|
|
||||||
return DT_RL02;
|
|
||||||
|
|
||||||
if (ch == '3')
|
|
||||||
return DT_TAPE;
|
|
||||||
|
|
||||||
return { };
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !defined(BUILD_FOR_RP2040)
|
#if !defined(BUILD_FOR_RP2040)
|
||||||
std::optional<std::tuple<std::vector<disk_backend *>, std::vector<disk_backend *>, std::string> > select_nbd_server(console *const c)
|
std::optional<disk_backend *> select_nbd_server(console *const cnsl)
|
||||||
{
|
{
|
||||||
c->flush_input();
|
cnsl->flush_input();
|
||||||
|
|
||||||
std::string hostname = c->read_line("Enter hostname (or empty to abort): ");
|
std::string hostname = cnsl->read_line("Enter hostname (or empty to abort): ");
|
||||||
|
|
||||||
if (hostname.empty())
|
if (hostname.empty())
|
||||||
return { };
|
return { };
|
||||||
|
|
||||||
std::string port_str = c->read_line("Enter port number (or empty to abort): ");
|
std::string port_str = cnsl->read_line("Enter port number (or empty to abort): ");
|
||||||
|
|
||||||
if (port_str.empty())
|
if (port_str.empty())
|
||||||
return { };
|
return { };
|
||||||
|
|
||||||
auto disk_type = select_disk_type(c);
|
|
||||||
|
|
||||||
if (disk_type.has_value() == false)
|
|
||||||
return { };
|
|
||||||
|
|
||||||
disk_backend *d = new disk_backend_nbd(hostname, atoi(port_str.c_str()));
|
disk_backend *d = new disk_backend_nbd(hostname, atoi(port_str.c_str()));
|
||||||
|
|
||||||
if (d->begin() == false) {
|
if (d->begin(false) == false) {
|
||||||
c->put_string_lf("Cannot initialize NBD client");
|
cnsl->put_string_lf("Cannot initialize NBD client");
|
||||||
delete d;
|
delete d;
|
||||||
return { };
|
return { };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (save_disk_configuration(hostname, atoi(port_str.c_str()), { }, disk_type.value(), c))
|
return d;
|
||||||
c->put_string_lf("NBD disk configuration saved");
|
|
||||||
else
|
|
||||||
c->put_string_lf("NBD disk configuration NOT saved");
|
|
||||||
|
|
||||||
if (disk_type.value() == DT_RK05)
|
|
||||||
return { { { d }, { }, "" } };
|
|
||||||
|
|
||||||
if (disk_type.value() == DT_RL02)
|
|
||||||
return { { { }, { d }, "" } };
|
|
||||||
|
|
||||||
return { };
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// RK05, RL02 files
|
// disk image files
|
||||||
std::optional<std::tuple<std::vector<disk_backend *>, std::vector<disk_backend *>, std::string> > select_disk_files(console *const c)
|
std::optional<disk_backend *> select_disk_file(console *const c)
|
||||||
{
|
{
|
||||||
#ifdef linux
|
#if IS_POSIX
|
||||||
c->put_string_lf("Files in current directory: ");
|
c->put_string_lf("Files in current directory: ");
|
||||||
#else
|
#else
|
||||||
c->debug("MISO: %d", int(MISO));
|
c->debug("MISO: %d", int(MISO));
|
||||||
|
@ -367,17 +296,12 @@ std::optional<std::tuple<std::vector<disk_backend *>, std::vector<disk_backend *
|
||||||
if (selected_file.empty())
|
if (selected_file.empty())
|
||||||
return { };
|
return { };
|
||||||
|
|
||||||
auto disk_type = select_disk_type(c);
|
|
||||||
|
|
||||||
if (disk_type.has_value() == false)
|
|
||||||
return { };
|
|
||||||
|
|
||||||
c->put_string("Opening file: ");
|
c->put_string("Opening file: ");
|
||||||
c->put_string_lf(selected_file.c_str());
|
c->put_string_lf(selected_file.c_str());
|
||||||
|
|
||||||
bool can_open_file = false;
|
bool can_open_file = false;
|
||||||
|
|
||||||
#ifdef linux
|
#if IS_POSIX
|
||||||
struct stat st { };
|
struct stat st { };
|
||||||
can_open_file = stat(selected_file.c_str(), &st) == 0;
|
can_open_file = stat(selected_file.c_str(), &st) == 0;
|
||||||
#else
|
#else
|
||||||
|
@ -388,16 +312,13 @@ std::optional<std::tuple<std::vector<disk_backend *>, std::vector<disk_backend *
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (can_open_file) {
|
if (can_open_file) {
|
||||||
if (disk_type.value() == DT_TAPE)
|
#if IS_POSIX
|
||||||
return { { { }, { }, selected_file } };
|
|
||||||
|
|
||||||
#ifdef linux
|
|
||||||
disk_backend *temp = new disk_backend_file(selected_file);
|
disk_backend *temp = new disk_backend_file(selected_file);
|
||||||
#else
|
#else
|
||||||
disk_backend *temp = new disk_backend_esp32(selected_file);
|
disk_backend *temp = new disk_backend_esp32(selected_file);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!temp->begin()) {
|
if (!temp->begin(false)) {
|
||||||
c->put_string("Cannot use: ");
|
c->put_string("Cannot use: ");
|
||||||
c->put_string_lf(selected_file.c_str());
|
c->put_string_lf(selected_file.c_str());
|
||||||
|
|
||||||
|
@ -406,63 +327,136 @@ std::optional<std::tuple<std::vector<disk_backend *>, std::vector<disk_backend *
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disk_type.value() == DT_RK05)
|
return { temp };
|
||||||
return { { { temp }, { }, "" } };
|
|
||||||
|
|
||||||
if (disk_type.value() == DT_RL02)
|
|
||||||
return { { { }, { temp }, "" } };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c->put_string_lf("open failed");
|
c->put_string_lf("open failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { };
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_disk_configuration(bus *const b, console *const cnsl, std::tuple<std::vector<disk_backend *>, std::vector<disk_backend *>, std::string> & disk_files)
|
int wait_for_key(const std::string & title, console *const cnsl, const std::vector<char> & allowed)
|
||||||
{
|
{
|
||||||
if (std::get<0>(disk_files).empty() == false)
|
cnsl->put_string_lf(title);
|
||||||
b->add_rk05(new rk05(std::get<0>(disk_files), b, cnsl->get_disk_read_activity_flag(), cnsl->get_disk_write_activity_flag()));
|
|
||||||
|
|
||||||
if (std::get<1>(disk_files).empty() == false)
|
cnsl->put_string("> ");
|
||||||
b->add_rl02(new rl02(std::get<1>(disk_files), b, cnsl->get_disk_read_activity_flag(), cnsl->get_disk_write_activity_flag()));
|
|
||||||
|
|
||||||
if (std::get<2>(disk_files).empty() == false) {
|
int ch = -1;
|
||||||
auto addr = loadTape(b, std::get<2>(disk_files));
|
while(ch == -1) {
|
||||||
|
auto temp = cnsl->wait_char(500);
|
||||||
|
|
||||||
if (addr.has_value())
|
if (temp.has_value()) {
|
||||||
b->getCpu()->setPC(addr.value());
|
for(auto & a: allowed) {
|
||||||
|
if (a == temp.value()) {
|
||||||
|
ch = temp.value();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (std::get<0>(disk_files).empty() == false)
|
cnsl->put_string_lf(format("%c", ch));
|
||||||
setBootLoader(b, BL_RK05);
|
|
||||||
else if (std::get<1>(disk_files).empty() == false)
|
return ch;
|
||||||
setBootLoader(b, BL_RL02);
|
}
|
||||||
|
|
||||||
|
std::optional<disk_backend *> select_disk_backend(console *const cnsl)
|
||||||
|
{
|
||||||
|
#if defined(BUILD_FOR_RP2040)
|
||||||
|
return select_disk_file(cnsl);
|
||||||
|
#else
|
||||||
|
int ch = wait_for_key("1. local disk, 2. network disk (NBD), 9. abort", cnsl, { '1', '2', '9' });
|
||||||
|
if (ch == '9')
|
||||||
|
return { };
|
||||||
|
|
||||||
|
if (ch == '1')
|
||||||
|
return select_disk_file(cnsl);
|
||||||
|
|
||||||
|
if (ch == '2')
|
||||||
|
return select_nbd_server(cnsl);
|
||||||
|
|
||||||
|
return { };
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void configure_disk(bus *const b, console *const cnsl)
|
void configure_disk(bus *const b, console *const cnsl)
|
||||||
{
|
{
|
||||||
|
// TODO tape
|
||||||
|
int ch = wait_for_key("1. RK05, 2. RL02, 9. abort", cnsl, { '1', '2', '3', '9' });
|
||||||
|
|
||||||
|
bootloader_t bl = BL_NONE;
|
||||||
|
disk_device *dd = nullptr;
|
||||||
|
|
||||||
|
if (ch == '1') {
|
||||||
|
dd = b->getRK05();
|
||||||
|
bl = BL_RK05;
|
||||||
|
}
|
||||||
|
else if (ch == '2') {
|
||||||
|
dd = b->getRL02();
|
||||||
|
bl = BL_RL02;
|
||||||
|
}
|
||||||
|
else if (ch == '9') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
cnsl->put_string_lf("Load disk");
|
std::vector<char> keys_allowed { '1', '2', '9' };
|
||||||
|
|
||||||
auto backend = select_disk_backend(cnsl);
|
auto cartridge_slots = dd->access_disk_backends();
|
||||||
|
int slot_key = 'A';
|
||||||
|
for(auto & slot: *cartridge_slots) {
|
||||||
|
cnsl->put_string_lf(format(" %c. %s", slot_key, slot ? slot->get_identifier().c_str() : "-"));
|
||||||
|
keys_allowed.push_back(slot_key);
|
||||||
|
slot_key++;
|
||||||
|
}
|
||||||
|
|
||||||
if (backend.has_value() == false)
|
int ch = wait_for_key("Select cartridge to setup, 1. to add a cartridge, 2. to load a bootloader or 9. to exit", cnsl, keys_allowed);
|
||||||
|
if (ch == '9')
|
||||||
break;
|
break;
|
||||||
|
|
||||||
std::optional<std::tuple<std::vector<disk_backend *>, std::vector<disk_backend *>, std::string> > files;
|
if (ch == '1') {
|
||||||
|
auto image_file = select_disk_backend(cnsl);
|
||||||
|
|
||||||
#if !defined(BUILD_FOR_RP2040)
|
if (image_file.has_value()) {
|
||||||
if (backend == BE_NETWORK)
|
cartridge_slots->push_back(image_file.value());
|
||||||
files = select_nbd_server(cnsl);
|
|
||||||
else // if (backend == BE_SD)
|
|
||||||
#endif
|
|
||||||
files = select_disk_files(cnsl);
|
|
||||||
|
|
||||||
if (files.has_value() == false)
|
cnsl->put_string_lf("Cartridge loaded");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ch == '2') {
|
||||||
|
set_boot_loader(b, bl);
|
||||||
|
|
||||||
|
cnsl->put_string_lf("Bootloader loaded");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int slot = ch - 'A';
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
|
int ch = wait_for_key("Select cartridge action: 1. load, 2. unload, 9. exit", cnsl, { '1', '2', '9' });
|
||||||
|
if (ch == '9')
|
||||||
break;
|
break;
|
||||||
|
|
||||||
set_disk_configuration(b, cnsl, files.value());
|
if (ch == '1') {
|
||||||
|
auto image_file = select_disk_backend(cnsl);
|
||||||
|
|
||||||
break;
|
if (image_file.has_value()) {
|
||||||
|
delete cartridge_slots->at(slot);
|
||||||
|
cartridge_slots->at(slot) = image_file.value();
|
||||||
|
|
||||||
|
cnsl->put_string_lf("Cartridge loaded");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ch == '2') {
|
||||||
|
if (cartridge_slots->at(slot)) {
|
||||||
|
delete cartridge_slots->at(slot);
|
||||||
|
cartridge_slots->at(slot) = nullptr;
|
||||||
|
|
||||||
|
cnsl->put_string_lf("Cartridge unloaded");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -722,6 +716,27 @@ void show_queued_interrupts(console *const cnsl, cpu *const c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
|
void serialize_state(console *const cnsl, const bus *const b, const std::string & filename)
|
||||||
|
{
|
||||||
|
json_t *j = b->serialize();
|
||||||
|
|
||||||
|
bool ok = false;
|
||||||
|
|
||||||
|
FILE *fh = fopen(filename.c_str(), "w");
|
||||||
|
if (fh) {
|
||||||
|
if (json_dumpf(j, fh, JSON_INDENT(4)) == 0)
|
||||||
|
ok = true;
|
||||||
|
|
||||||
|
fclose(fh);
|
||||||
|
}
|
||||||
|
|
||||||
|
json_decref(j);
|
||||||
|
|
||||||
|
cnsl->put_string_lf(format("Serialize to %s: %s", filename.c_str(), ok ? "OK" : "failed"));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const stop_event, const bool tracing_in)
|
void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const stop_event, const bool tracing_in)
|
||||||
{
|
{
|
||||||
int32_t trace_start_addr = -1;
|
int32_t trace_start_addr = -1;
|
||||||
|
@ -1005,7 +1020,7 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (parts[0] == "bl" && parts.size() == 2) {
|
else if (parts[0] == "bl" && parts.size() == 2) {
|
||||||
setBootLoader(b, parts.at(1) == "rk05" ? BL_RK05 : BL_RL02);
|
set_boot_loader(b, parts.at(1) == "rk05" ? BL_RK05 : BL_RL02);
|
||||||
cnsl->put_string_lf("Bootloader set");
|
cnsl->put_string_lf("Bootloader set");
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
@ -1069,6 +1084,12 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
#if IS_POSIX
|
||||||
|
else if (parts[0] == "ser" && parts.size() == 2) {
|
||||||
|
serialize_state(cnsl, b, parts.at(1));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
else if (parts[0] == "setsl" && parts.size() == 3) {
|
else if (parts[0] == "setsl" && parts.size() == 3) {
|
||||||
setloghost(parts.at(1).c_str(), parse_ll(parts[2]));
|
setloghost(parts.at(1).c_str(), parse_ll(parts[2]));
|
||||||
|
|
||||||
|
@ -1130,6 +1151,10 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
|
||||||
"stats - show run statistics",
|
"stats - show run statistics",
|
||||||
"ramsize - set ram size (page count (8 kB))",
|
"ramsize - set ram size (page count (8 kB))",
|
||||||
"bl - set bootload (rl02 or rk05)",
|
"bl - set bootload (rl02 or rk05)",
|
||||||
|
#if IS_POSIX
|
||||||
|
"ser - serialize state to a file",
|
||||||
|
// "dser - deserialize state from a file",
|
||||||
|
#endif
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
"cfgnet - configure network (e.g. WiFi)",
|
"cfgnet - configure network (e.g. WiFi)",
|
||||||
"startnet - start network",
|
"startnet - start network",
|
||||||
|
|
108
disk_backend.cpp
108
disk_backend.cpp
|
@ -1,7 +1,14 @@
|
||||||
// (C) 2018-2023 by Folkert van Heusden
|
// (C) 2018-2024 by Folkert van Heusden
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include "disk_backend.h"
|
#include "disk_backend.h"
|
||||||
|
#if IS_POSIX
|
||||||
|
#include "disk_backend_file.h"
|
||||||
|
#include "disk_backend_nbd.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
disk_backend::disk_backend()
|
disk_backend::disk_backend()
|
||||||
{
|
{
|
||||||
|
@ -10,3 +17,102 @@ disk_backend::disk_backend()
|
||||||
disk_backend::~disk_backend()
|
disk_backend::~disk_backend()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
|
void disk_backend::store_object_in_overlay(const off_t id, const std::vector<uint8_t> & data)
|
||||||
|
{
|
||||||
|
overlay.insert_or_assign(id, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::vector<uint8_t> > disk_backend::get_object_from_overlay(const off_t id)
|
||||||
|
{
|
||||||
|
auto it = overlay.find(id);
|
||||||
|
if (it != overlay.end())
|
||||||
|
return it->second;
|
||||||
|
|
||||||
|
return { };
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::vector<uint8_t> > disk_backend::get_from_overlay(const off_t offset, const size_t sector_size)
|
||||||
|
{
|
||||||
|
assert((offset % sector_size) == 0);
|
||||||
|
|
||||||
|
if (use_overlay)
|
||||||
|
return get_object_from_overlay(offset / sector_size);
|
||||||
|
|
||||||
|
return { };
|
||||||
|
}
|
||||||
|
|
||||||
|
bool disk_backend::store_mem_range_in_overlay(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size)
|
||||||
|
{
|
||||||
|
assert((offset % sector_size) == 0);
|
||||||
|
assert((n % sector_size) == 0);
|
||||||
|
|
||||||
|
if (use_overlay) {
|
||||||
|
for(size_t o=0; o<n; o += sector_size)
|
||||||
|
store_object_in_overlay((offset + o) / sector_size, std::vector<uint8_t>(from + o, from + o + sector_size));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
json_t *disk_backend::serialize_overlay() const
|
||||||
|
{
|
||||||
|
json_t *out = json_object();
|
||||||
|
|
||||||
|
for(auto & id: overlay) {
|
||||||
|
json_t *j_data = json_array();
|
||||||
|
|
||||||
|
for(size_t i=0; i<id.second.size(); i++)
|
||||||
|
json_array_append(j_data, json_integer(id.second.at(i)));
|
||||||
|
|
||||||
|
json_object_set(out, format("%u", id.first).c_str(), j_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void disk_backend::deserialize_overlay(const json_t *const j)
|
||||||
|
{
|
||||||
|
json_t *input = json_object_get(j, "overlay");
|
||||||
|
if (!input) // we can have state-dumps without overlay
|
||||||
|
return;
|
||||||
|
|
||||||
|
const char *key = nullptr;
|
||||||
|
json_t *value = nullptr;
|
||||||
|
json_object_foreach(input, key, value) {
|
||||||
|
uint32_t id = std::atoi(key);
|
||||||
|
|
||||||
|
std::vector<uint8_t> data;
|
||||||
|
for(size_t i=0; i<json_array_size(value); i++)
|
||||||
|
data.push_back(json_integer_value(json_array_get(value, i)));
|
||||||
|
|
||||||
|
store_object_in_overlay(id, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
disk_backend *disk_backend::deserialize(const json_t *const j)
|
||||||
|
{
|
||||||
|
std::string type = json_string_value(json_object_get(j, "disk-backend-type"));
|
||||||
|
|
||||||
|
disk_backend *d = nullptr;
|
||||||
|
|
||||||
|
if (type == "file")
|
||||||
|
d = disk_backend_file::deserialize(j);
|
||||||
|
|
||||||
|
else if (type == "nbd")
|
||||||
|
d = disk_backend_nbd::deserialize(j);
|
||||||
|
|
||||||
|
// should not be reached
|
||||||
|
assert(d);
|
||||||
|
|
||||||
|
d->deserialize_overlay(j);
|
||||||
|
|
||||||
|
// assume we want snapshots (again?)
|
||||||
|
d->begin(true);
|
||||||
|
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,21 +1,48 @@
|
||||||
// (C) 2018-2023 by Folkert van Heusden
|
// (C) 2018-2024 by Folkert van Heusden
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <optional>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "gen.h"
|
||||||
|
|
||||||
|
|
||||||
class disk_backend
|
class disk_backend
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
|
#if IS_POSIX
|
||||||
|
bool use_overlay { false };
|
||||||
|
std::map<off_t, std::vector<uint8_t> > overlay;
|
||||||
|
|
||||||
|
void store_object_in_overlay(const off_t id, const std::vector<uint8_t> & data);
|
||||||
|
bool store_mem_range_in_overlay(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size);
|
||||||
|
std::optional<std::vector<uint8_t> > get_object_from_overlay(const off_t id);
|
||||||
|
std::optional<std::vector<uint8_t> > get_from_overlay(const off_t offset, const size_t sector_size);
|
||||||
|
|
||||||
|
json_t *serialize_overlay() const;
|
||||||
|
void deserialize_overlay(const json_t *const j);
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
disk_backend();
|
disk_backend();
|
||||||
virtual ~disk_backend();
|
virtual ~disk_backend();
|
||||||
|
|
||||||
virtual bool begin() = 0;
|
#if IS_POSIX
|
||||||
|
virtual json_t *serialize() const = 0;
|
||||||
|
static disk_backend *deserialize(const json_t *const j);
|
||||||
|
#endif
|
||||||
|
|
||||||
virtual bool read(const off_t offset, const size_t n, uint8_t *const target) = 0;
|
virtual std::string get_identifier() const = 0;
|
||||||
|
|
||||||
virtual bool write(const off_t offset, const size_t n, const uint8_t *const from) = 0;
|
virtual bool begin(const bool disk_snapshots) = 0;
|
||||||
|
|
||||||
|
virtual bool read(const off_t offset, const size_t n, uint8_t *const target, const size_t sector_size) = 0;
|
||||||
|
|
||||||
|
virtual bool write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size) = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
// (C) 2018-2024 by Folkert van Heusden
|
// (C) 2018-2024 by Folkert van Heusden
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "disk_backend_file.h"
|
#include "disk_backend_file.h"
|
||||||
|
#include "gen.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,8 +21,32 @@ disk_backend_file::~disk_backend_file()
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_backend_file::begin()
|
#if IS_POSIX
|
||||||
|
json_t *disk_backend_file::serialize() const
|
||||||
{
|
{
|
||||||
|
json_t *j = json_object();
|
||||||
|
|
||||||
|
json_object_set(j, "disk-backend-type", json_string("file"));
|
||||||
|
|
||||||
|
json_object_set(j, "overlay", serialize_overlay());
|
||||||
|
|
||||||
|
// TODO store checksum of backend
|
||||||
|
json_object_set(j, "filename", json_string(filename.c_str()));
|
||||||
|
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
|
disk_backend_file *disk_backend_file::deserialize(const json_t *const j)
|
||||||
|
{
|
||||||
|
// TODO verify checksum of backend
|
||||||
|
return new disk_backend_file(json_string_value(json_object_get(j, "filename")));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool disk_backend_file::begin(const bool snapshots)
|
||||||
|
{
|
||||||
|
use_overlay = snapshots;
|
||||||
|
|
||||||
fd = open(filename.c_str(), O_RDWR);
|
fd = open(filename.c_str(), O_RDWR);
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
|
@ -32,30 +58,48 @@ bool disk_backend_file::begin()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_backend_file::read(const off_t offset, const size_t n, uint8_t *const target)
|
bool disk_backend_file::read(const off_t offset_in, const size_t n, uint8_t *const target, const size_t sector_size)
|
||||||
{
|
{
|
||||||
DOLOG(debug, false, "disk_backend_file::read: read %zu bytes from offset %zu", n, offset);
|
DOLOG(debug, false, "disk_backend_file::read: read %zu bytes from offset %zu", n, offset_in);
|
||||||
|
|
||||||
|
assert((offset % sector_size) == 0);
|
||||||
|
assert((n % sector_size) == 0);
|
||||||
|
|
||||||
|
for(off_t o=0; o<off_t(n); o+=sector_size) {
|
||||||
|
off_t offset = offset_in + o;
|
||||||
|
#if IS_POSIX
|
||||||
|
auto o_rc = get_from_overlay(offset, sector_size);
|
||||||
|
if (o_rc.has_value()) {
|
||||||
|
memcpy(&target[o], o_rc.value().data(), sector_size);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32) // hope for the best
|
#if defined(_WIN32) // hope for the best
|
||||||
if (lseek(fd, offset, SEEK_SET) == -1)
|
if (lseek(fd, offset, SEEK_SET) == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return ::read(fd, target, n) == ssize_t(n);
|
if (::read(fd, target, n) != ssize_t(n))
|
||||||
|
return false;
|
||||||
#else
|
#else
|
||||||
ssize_t rc = pread(fd, target, n, offset);
|
ssize_t rc = pread(fd, target, n, offset);
|
||||||
if (rc != ssize_t(n)) {
|
if (rc != ssize_t(n)) {
|
||||||
DOLOG(warning, false, "disk_backend_file::read: read failure. expected %zu bytes, got %zd", n, rc);
|
DOLOG(warning, false, "disk_backend_file::read: read failure. expected %zu bytes, got %zd", n, rc);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_backend_file::write(const off_t offset, const size_t n, const uint8_t *const from)
|
bool disk_backend_file::write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size)
|
||||||
{
|
{
|
||||||
DOLOG(debug, false, "disk_backend_file::write: write %zu bytes to offset %zu", n, offset);
|
DOLOG(debug, false, "disk_backend_file::write: write %zu bytes to offset %zu", n, offset);
|
||||||
|
|
||||||
|
if (store_mem_range_in_overlay(offset, n, from, sector_size))
|
||||||
|
return true;
|
||||||
|
|
||||||
#if defined(_WIN32) // hope for the best
|
#if defined(_WIN32) // hope for the best
|
||||||
if (lseek(fd, offset, SEEK_SET) == -1)
|
if (lseek(fd, offset, SEEK_SET) == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// (C) 2018-2023 by Folkert van Heusden
|
// (C) 2018-2024 by Folkert van Heusden
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -17,9 +17,16 @@ public:
|
||||||
disk_backend_file(const std::string & filename);
|
disk_backend_file(const std::string & filename);
|
||||||
virtual ~disk_backend_file();
|
virtual ~disk_backend_file();
|
||||||
|
|
||||||
bool begin() override;
|
#if IS_POSIX
|
||||||
|
json_t *serialize() const override;
|
||||||
|
static disk_backend_file *deserialize(const json_t *const j);
|
||||||
|
#endif
|
||||||
|
|
||||||
bool read(const off_t offset, const size_t n, uint8_t *const target) override;
|
std::string get_identifier() const override { return filename; }
|
||||||
|
|
||||||
bool write(const off_t offset, const size_t n, const uint8_t *const from) override;
|
bool begin(const bool snapshots) override;
|
||||||
|
|
||||||
|
bool read(const off_t offset, const size_t n, uint8_t *const target, const size_t sector_size) override;
|
||||||
|
|
||||||
|
bool write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// (C) 2018-2024 by Folkert van Heusden
|
// (C) 2018-2024 by Folkert van Heusden
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -47,8 +48,35 @@ disk_backend_nbd::~disk_backend_nbd()
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_backend_nbd::begin()
|
#if IS_POSIX
|
||||||
|
json_t *disk_backend_nbd::serialize() const
|
||||||
{
|
{
|
||||||
|
json_t *j = json_object();
|
||||||
|
|
||||||
|
json_object_set(j, "disk-backend-type", json_string("nbd"));
|
||||||
|
|
||||||
|
json_object_set(j, "overlay", serialize_overlay());
|
||||||
|
|
||||||
|
// TODO store checksum of backend
|
||||||
|
json_object_set(j, "host", json_string(host.c_str()));
|
||||||
|
json_object_set(j, "port", json_integer(port));
|
||||||
|
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
|
disk_backend_nbd *disk_backend_nbd::deserialize(const json_t *const j)
|
||||||
|
{
|
||||||
|
// TODO verify checksum of backend
|
||||||
|
return new disk_backend_nbd(json_string_value(json_object_get(j, "host")), json_integer_value(json_object_get(j, "port")));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool disk_backend_nbd::begin(const bool snapshots)
|
||||||
|
{
|
||||||
|
#if IS_POSIX
|
||||||
|
use_overlay = snapshots;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!connect(false)) {
|
if (!connect(false)) {
|
||||||
DOLOG(ll_error, true, "disk_backend_nbd: cannot connect to NBD server");
|
DOLOG(ll_error, true, "disk_backend_nbd: cannot connect to NBD server");
|
||||||
return false;
|
return false;
|
||||||
|
@ -133,14 +161,27 @@ bool disk_backend_nbd::connect(const bool retry)
|
||||||
return fd != -1;
|
return fd != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_backend_nbd::read(const off_t offset, const size_t n, uint8_t *const target)
|
bool disk_backend_nbd::read(const off_t offset_in, const size_t n, uint8_t *const target, const size_t sector_size)
|
||||||
{
|
{
|
||||||
DOLOG(debug, false, "disk_backend_nbd::read: read %zu bytes from offset %zu", n, offset);
|
DOLOG(debug, false, "disk_backend_nbd::read: read %zu bytes from offset %zu", n, offset_in);
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
do {
|
size_t o = 0;
|
||||||
|
off_t offset = offset_in;
|
||||||
|
|
||||||
|
while(offset < offset_in + off_t(n)) {
|
||||||
|
#if IS_POSIX
|
||||||
|
auto o_rc = get_from_overlay(offset, sector_size);
|
||||||
|
if (o_rc.has_value()) {
|
||||||
|
memcpy(&target[o], o_rc.value().data(), sector_size);
|
||||||
|
offset += sector_size;
|
||||||
|
o += sector_size;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (fd == -1 && !connect(true)) {
|
if (fd == -1 && !connect(true)) {
|
||||||
DOLOG(warning, true, "disk_backend_nbd::read: (re-)connect");
|
DOLOG(warning, true, "disk_backend_nbd::read: (re-)connect");
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
@ -158,7 +199,7 @@ bool disk_backend_nbd::read(const off_t offset, const size_t n, uint8_t *const t
|
||||||
nbd_request.magic = ntohl(0x25609513);
|
nbd_request.magic = ntohl(0x25609513);
|
||||||
nbd_request.type = 0; // READ
|
nbd_request.type = 0; // READ
|
||||||
nbd_request.offset = HTONLL(uint64_t(offset));
|
nbd_request.offset = HTONLL(uint64_t(offset));
|
||||||
nbd_request.length = htonl(n);
|
nbd_request.length = htonl(sector_size);
|
||||||
|
|
||||||
if (WRITE(fd, reinterpret_cast<const char *>(&nbd_request), sizeof nbd_request) != sizeof nbd_request) {
|
if (WRITE(fd, reinterpret_cast<const char *>(&nbd_request), sizeof nbd_request) != sizeof nbd_request) {
|
||||||
DOLOG(warning, true, "disk_backend_nbd::read: problem sending request");
|
DOLOG(warning, true, "disk_backend_nbd::read: problem sending request");
|
||||||
|
@ -196,26 +237,33 @@ bool disk_backend_nbd::read(const off_t offset, const size_t n, uint8_t *const t
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (READ(fd, reinterpret_cast<char *>(target), n) != ssize_t(n)) {
|
if (READ(fd, reinterpret_cast<char *>(target), sector_size) != ssize_t(sector_size)) {
|
||||||
DOLOG(warning, true, "disk_backend_nbd::read: problem receiving payload");
|
DOLOG(warning, true, "disk_backend_nbd::read: problem receiving payload");
|
||||||
close(fd);
|
close(fd);
|
||||||
fd = -1;
|
fd = -1;
|
||||||
sleep(1);
|
sleep(1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
offset += sector_size;
|
||||||
|
o += sector_size;
|
||||||
}
|
}
|
||||||
while(fd == -1);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_backend_nbd::write(const off_t offset, const size_t n, const uint8_t *const from)
|
bool disk_backend_nbd::write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size)
|
||||||
{
|
{
|
||||||
DOLOG(debug, false, "disk_backend_nbd::write: write %zu bytes to offset %zu", n, offset);
|
DOLOG(debug, false, "disk_backend_nbd::write: write %zu bytes to offset %zu", n, offset);
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
|
if (store_mem_range_in_overlay(offset, n, from, sector_size))
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (!connect(true)) {
|
if (!connect(true)) {
|
||||||
DOLOG(warning, true, "disk_backend_nbd::write: (re-)connect");
|
DOLOG(warning, true, "disk_backend_nbd::write: (re-)connect");
|
||||||
|
@ -229,7 +277,7 @@ bool disk_backend_nbd::write(const off_t offset, const size_t n, const uint8_t *
|
||||||
uint64_t handle;
|
uint64_t handle;
|
||||||
uint64_t offset;
|
uint64_t offset;
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
} nbd_request { 0 };
|
} nbd_request { };
|
||||||
|
|
||||||
nbd_request.magic = ntohl(0x25609513);
|
nbd_request.magic = ntohl(0x25609513);
|
||||||
nbd_request.type = 1; // WRITE
|
nbd_request.type = 1; // WRITE
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
// (C) 2018-2023 by Folkert van Heusden
|
// (C) 2018-2024 by Folkert van Heusden
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "disk_backend.h"
|
#include "disk_backend.h"
|
||||||
|
#include "gen.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
|
||||||
class disk_backend_nbd : public disk_backend
|
class disk_backend_nbd : public disk_backend
|
||||||
|
@ -20,9 +22,16 @@ public:
|
||||||
disk_backend_nbd(const std::string & host, const unsigned port);
|
disk_backend_nbd(const std::string & host, const unsigned port);
|
||||||
virtual ~disk_backend_nbd();
|
virtual ~disk_backend_nbd();
|
||||||
|
|
||||||
bool begin() override;
|
#if IS_POSIX
|
||||||
|
json_t *serialize() const override;
|
||||||
|
static disk_backend_nbd *deserialize(const json_t *const j);
|
||||||
|
#endif
|
||||||
|
|
||||||
bool read(const off_t offset, const size_t n, uint8_t *const target) override;
|
std::string get_identifier() const override { return format("%s:%d", host.c_str(), port); }
|
||||||
|
|
||||||
bool write(const off_t offset, const size_t n, const uint8_t *const from) override;
|
bool begin(const bool snapshots) override;
|
||||||
|
|
||||||
|
bool read(const off_t offset, const size_t n, uint8_t *const target, const size_t sector_size) override;
|
||||||
|
|
||||||
|
bool write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size) override;
|
||||||
};
|
};
|
||||||
|
|
22
disk_device.h
Normal file
22
disk_device.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "device.h"
|
||||||
|
#include "disk_backend.h"
|
||||||
|
|
||||||
|
|
||||||
|
class disk_device: public device
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
std::vector<disk_backend *> fhs;
|
||||||
|
|
||||||
|
public:
|
||||||
|
disk_device() {
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~disk_device() {
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<disk_backend *> * access_disk_backends() { return &fhs; }
|
||||||
|
};
|
18
gen.h
18
gen.h
|
@ -12,3 +12,21 @@ typedef enum { d_space, i_space } d_i_space_t;
|
||||||
typedef enum { wm_word = 0, wm_byte = 1 } word_mode_t;
|
typedef enum { wm_word = 0, wm_byte = 1 } word_mode_t;
|
||||||
|
|
||||||
typedef enum { rm_prev, rm_cur } rm_selection_t;
|
typedef enum { rm_prev, rm_cur } rm_selection_t;
|
||||||
|
|
||||||
|
#if (defined(linux) || defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)))
|
||||||
|
#define IS_POSIX 1
|
||||||
|
#else
|
||||||
|
#define IS_POSIX 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
|
#include <jansson.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ESP32) || defined(BUILD_FOR_RP2040)
|
||||||
|
// ESP32 goes in a crash-loop when allocating 128kB
|
||||||
|
// see also https://github.com/espressif/esp-idf/issues/1934
|
||||||
|
#define DEFAULT_N_PAGES 12
|
||||||
|
#else
|
||||||
|
#define DEFAULT_N_PAGES 31
|
||||||
|
#endif
|
||||||
|
|
129
kw11-l.cpp
129
kw11-l.cpp
|
@ -25,13 +25,8 @@ void thread_wrapper_kw11(void *p)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
kw11_l::kw11_l(bus *const b, console *const cnsl) : b(b), cnsl(cnsl)
|
kw11_l::kw11_l(bus *const b): b(b)
|
||||||
{
|
{
|
||||||
#if defined(ESP32) || defined(BUILD_FOR_RP2040)
|
|
||||||
xTaskCreate(&thread_wrapper_kw11, "kw11-l", 2048, this, 1, nullptr);
|
|
||||||
#else
|
|
||||||
th = new std::thread(std::ref(*this));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kw11_l::~kw11_l()
|
kw11_l::~kw11_l()
|
||||||
|
@ -39,12 +34,34 @@ kw11_l::~kw11_l()
|
||||||
stop_flag = true;
|
stop_flag = true;
|
||||||
|
|
||||||
#if !defined(ESP32) && !defined(BUILD_FOR_RP2040)
|
#if !defined(ESP32) && !defined(BUILD_FOR_RP2040)
|
||||||
|
if (th) {
|
||||||
th->join();
|
th->join();
|
||||||
|
|
||||||
delete th;
|
delete th;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void kw11_l::begin(console *const cnsl)
|
||||||
|
{
|
||||||
|
this->cnsl = cnsl;
|
||||||
|
|
||||||
|
#if defined(ESP32) || defined(BUILD_FOR_RP2040)
|
||||||
|
xTaskCreate(&thread_wrapper_kw11, "kw11-l", 2048, this, 1, nullptr);
|
||||||
|
|
||||||
|
#if defined(BUILD_FOR_RP2040)
|
||||||
|
xSemaphoreGive(lf_csr_lock); // initialize
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
th = new std::thread(std::ref(*this));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void kw11_l::reset()
|
||||||
|
{
|
||||||
|
lf_csr = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void kw11_l::operator()()
|
void kw11_l::operator()()
|
||||||
{
|
{
|
||||||
set_thread_name("kek:kw-11l");
|
set_thread_name("kek:kw-11l");
|
||||||
|
@ -53,9 +70,9 @@ void kw11_l::operator()()
|
||||||
|
|
||||||
while(!stop_flag) {
|
while(!stop_flag) {
|
||||||
if (*cnsl->get_running_flag()) {
|
if (*cnsl->get_running_flag()) {
|
||||||
b->set_lf_crs_b7();
|
set_lf_crs_b7();
|
||||||
|
|
||||||
if (b->get_lf_crs() & 64)
|
if (get_lf_crs() & 64)
|
||||||
b->getCpu()->queue_interrupt(6, 0100);
|
b->getCpu()->queue_interrupt(6, 0100);
|
||||||
|
|
||||||
// TODO: dependant on cpu cycles processed
|
// TODO: dependant on cpu cycles processed
|
||||||
|
@ -68,3 +85,99 @@ void kw11_l::operator()()
|
||||||
|
|
||||||
DOLOG(debug, true, "KW11-L thread terminating");
|
DOLOG(debug, true, "KW11-L thread terminating");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t kw11_l::readWord(const uint16_t a)
|
||||||
|
{
|
||||||
|
if (a != ADDR_LFC) {
|
||||||
|
DOLOG(debug, true, "KW11-L readWord not for us (%06o)", a);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(BUILD_FOR_RP2040)
|
||||||
|
xSemaphoreTake(lf_csr_lock, portMAX_DELAY);
|
||||||
|
#else
|
||||||
|
std::unique_lock<std::mutex> lck(lf_csr_lock);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uint16_t temp = lf_csr;
|
||||||
|
|
||||||
|
#if defined(BUILD_FOR_RP2040)
|
||||||
|
xSemaphoreGive(lf_csr_lock);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void kw11_l::writeWord(const uint16_t a, const uint16_t value)
|
||||||
|
{
|
||||||
|
if (a != ADDR_LFC) {
|
||||||
|
DOLOG(debug, true, "KW11-L writeWord not for us (%06o to %06o)", value, a);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(BUILD_FOR_RP2040)
|
||||||
|
xSemaphoreTake(lf_csr_lock, portMAX_DELAY);
|
||||||
|
#else
|
||||||
|
std::unique_lock<std::mutex> lck(lf_csr_lock);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
DOLOG(debug, false, "WRITE-I/O set line frequency clock/status register: %06o", value);
|
||||||
|
lf_csr = value;
|
||||||
|
#if defined(BUILD_FOR_RP2040)
|
||||||
|
xSemaphoreGive(lf_csr_lock);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void kw11_l::set_lf_crs_b7()
|
||||||
|
{
|
||||||
|
#if defined(BUILD_FOR_RP2040)
|
||||||
|
xSemaphoreTake(lf_csr_lock, portMAX_DELAY);
|
||||||
|
#else
|
||||||
|
std::unique_lock<std::mutex> lck(lf_csr_lock);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
lf_csr |= 128;
|
||||||
|
|
||||||
|
#if defined(BUILD_FOR_RP2040)
|
||||||
|
xSemaphoreGive(lf_csr_lock);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t kw11_l::get_lf_crs()
|
||||||
|
{
|
||||||
|
#if defined(BUILD_FOR_RP2040)
|
||||||
|
xSemaphoreTake(lf_csr_lock, portMAX_DELAY);
|
||||||
|
#else
|
||||||
|
std::unique_lock<std::mutex> lck(lf_csr_lock);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uint8_t rc = lf_csr;
|
||||||
|
|
||||||
|
#if defined(BUILD_FOR_RP2040)
|
||||||
|
xSemaphoreGive(lf_csr_lock);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
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
|
||||||
|
|
31
kw11-l.h
31
kw11-l.h
|
@ -1,26 +1,47 @@
|
||||||
// (C) 2018-2023 by Folkert van Heusden
|
// (C) 2018-2024 by Folkert van Heusden
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "bus.h"
|
#include "bus.h"
|
||||||
|
#include "console.h"
|
||||||
|
#include "gen.h"
|
||||||
|
|
||||||
|
|
||||||
class kw11_l
|
class kw11_l
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bus *const b { nullptr };
|
bus *const b { nullptr };
|
||||||
console *const cnsl { nullptr };
|
console *cnsl { nullptr };
|
||||||
|
|
||||||
#if !defined(BUILD_FOR_RP2040)
|
#if defined(BUILD_FOR_RP2040)
|
||||||
std::thread * th { nullptr };
|
SemaphoreHandle_t lf_csr_lock { xSemaphoreCreateBinary() };
|
||||||
|
#else
|
||||||
|
std::thread *th { nullptr };
|
||||||
|
std::mutex lf_csr_lock;
|
||||||
#endif
|
#endif
|
||||||
|
uint16_t lf_csr { 0 };
|
||||||
|
|
||||||
std::atomic_bool stop_flag { false };
|
std::atomic_bool stop_flag { false };
|
||||||
|
|
||||||
|
uint8_t get_lf_crs();
|
||||||
|
void set_lf_crs_b7();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
kw11_l(bus *const b, console *const cnsl);
|
kw11_l(bus *const b);
|
||||||
virtual ~kw11_l();
|
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()();
|
void operator()();
|
||||||
|
|
||||||
|
uint16_t readWord (const uint16_t a);
|
||||||
|
void writeWord(const uint16_t a, const uint16_t v);
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,7 +28,7 @@ void loadbin(bus *const b, uint16_t base, const char *const file)
|
||||||
fclose(fh);
|
fclose(fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBootLoader(bus *const b, const bootloader_t which)
|
void set_boot_loader(bus *const b, const bootloader_t which)
|
||||||
{
|
{
|
||||||
cpu *const c = b -> getCpu();
|
cpu *const c = b -> getCpu();
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,6 @@
|
||||||
typedef enum { BL_NONE, BL_RK05, BL_RL02 } bootloader_t;
|
typedef enum { BL_NONE, BL_RK05, BL_RL02 } bootloader_t;
|
||||||
|
|
||||||
void loadbin(bus *const b, uint16_t base, const char *const file);
|
void loadbin(bus *const b, uint16_t base, const char *const file);
|
||||||
void setBootLoader(bus *const b, const bootloader_t which);
|
void set_boot_loader(bus *const b, const bootloader_t which);
|
||||||
std::optional<uint16_t> loadTape(bus *const b, const std::string & file);
|
std::optional<uint16_t> loadTape(bus *const b, const std::string & file);
|
||||||
void load_p11_x11(bus *const b, const std::string & file);
|
void load_p11_x11(bus *const b, const std::string & file);
|
||||||
|
|
185
main.cpp
185
main.cpp
|
@ -295,9 +295,19 @@ void get_metrics(cpu *const c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void start_disk_devices(const std::vector<disk_backend *> & backends, const bool enable_snapshots)
|
||||||
|
{
|
||||||
|
for(auto & backend: backends) {
|
||||||
|
if (backend->begin(enable_snapshots) == false)
|
||||||
|
error_exit(false, "Failed to initialize disk backend \"%s\"", backend->get_identifier().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void help()
|
void help()
|
||||||
{
|
{
|
||||||
printf("-h this help\n");
|
printf("-h this help\n");
|
||||||
|
printf("-D x deserialize state from file\n");
|
||||||
|
printf("-P when serializing state to file (in the debugger), include an overlay: changes to disk-files are then non-persistent, they only exist in the state-dump\n");
|
||||||
printf("-T t.bin load file as a binary tape file (like simh \"load\" command), also for .BIC files\n");
|
printf("-T t.bin load file as a binary tape file (like simh \"load\" command), also for .BIC files\n");
|
||||||
printf("-B run tape file as a unit test (for .BIC files)\n");
|
printf("-B run tape file as a unit test (for .BIC files)\n");
|
||||||
printf("-R d.rk load file as a RK05 disk device\n");
|
printf("-R d.rk load file as a RK05 disk device\n");
|
||||||
|
@ -317,27 +327,8 @@ void help()
|
||||||
printf("-M log metrics\n");
|
printf("-M log metrics\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "breakpoint_parser.h"
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
{
|
|
||||||
bus *b = new bus();
|
|
||||||
cpu *c = new cpu(b, &event);
|
|
||||||
b->add_cpu(c);
|
|
||||||
|
|
||||||
std::pair<breakpoint *, std::optional<std::string> > rc = parse_breakpoint(b, "(pc=0123 and (r0=01456 or r2=1) and memWV[0444]=0222)");
|
|
||||||
printf("%p\n", rc.first);
|
|
||||||
|
|
||||||
if (rc.second.has_value())
|
|
||||||
printf("%s\n", rc.second.value().c_str());
|
|
||||||
delete rc.first;
|
|
||||||
delete b;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//setlocale(LC_ALL, "");
|
//setlocale(LC_ALL, "");
|
||||||
|
|
||||||
std::vector<disk_backend *> rk05_files;
|
std::vector<disk_backend *> rk05_files;
|
||||||
|
@ -364,7 +355,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
std::string test;
|
std::string test;
|
||||||
|
|
||||||
disk_backend *temp_d = nullptr;
|
bool disk_snapshots = false;
|
||||||
|
|
||||||
std::optional<int> set_ram_size;
|
std::optional<int> set_ram_size;
|
||||||
|
|
||||||
|
@ -372,14 +363,20 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
bool metrics = false;
|
bool metrics = false;
|
||||||
|
|
||||||
|
std::string deserialize;
|
||||||
|
|
||||||
int opt = -1;
|
int opt = -1;
|
||||||
while((opt = getopt(argc, argv, "hMT:Br:R:p:ndtL:bl:s:Q:N:J:XS:")) != -1)
|
while((opt = getopt(argc, argv, "hD:MT:Br:R:p:ndtL:bl:s:Q:N:J:XS:P")) != -1)
|
||||||
{
|
{
|
||||||
switch(opt) {
|
switch(opt) {
|
||||||
case 'h':
|
case 'h':
|
||||||
help();
|
help();
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
case 'D':
|
||||||
|
deserialize = optarg;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'M':
|
case 'M':
|
||||||
metrics = true;
|
metrics = true;
|
||||||
break;
|
break;
|
||||||
|
@ -434,17 +431,11 @@ int main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'R':
|
case 'R':
|
||||||
temp_d = new disk_backend_file(optarg);
|
rk05_files.push_back(new disk_backend_file(optarg));
|
||||||
if (!temp_d->begin())
|
|
||||||
error_exit(false, "Cannot use file \"%s\" for RK05", optarg);
|
|
||||||
rk05_files.push_back(temp_d);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
temp_d = new disk_backend_file(optarg);
|
rl02_files.push_back(new disk_backend_file(optarg));
|
||||||
if (!temp_d->begin())
|
|
||||||
error_exit(false, "Cannot use file \"%s\" for RL02", optarg);
|
|
||||||
rl02_files.push_back(temp_d);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'N': {
|
case 'N': {
|
||||||
|
@ -452,7 +443,7 @@ int main(int argc, char *argv[])
|
||||||
if (parts.size() != 3)
|
if (parts.size() != 3)
|
||||||
error_exit(false, "-N: parameter missing");
|
error_exit(false, "-N: parameter missing");
|
||||||
|
|
||||||
temp_d = new disk_backend_nbd(parts.at(0), atoi(parts.at(1).c_str()));
|
disk_backend *temp_d = new disk_backend_nbd(parts.at(0), atoi(parts.at(1).c_str()));
|
||||||
|
|
||||||
if (parts.at(2) == "rk05")
|
if (parts.at(2) == "rk05")
|
||||||
rk05_files.push_back(temp_d);
|
rk05_files.push_back(temp_d);
|
||||||
|
@ -487,6 +478,10 @@ int main(int argc, char *argv[])
|
||||||
set_ram_size = std::stoi(optarg);
|
set_ram_size = std::stoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'P':
|
||||||
|
disk_snapshots = true;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "-%c is not understood\n", opt);
|
fprintf(stderr, "-%c is not understood\n", opt);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -500,16 +495,80 @@ int main(int argc, char *argv[])
|
||||||
if (validate_json.empty() == false)
|
if (validate_json.empty() == false)
|
||||||
return run_cpu_validation(validate_json);
|
return run_cpu_validation(validate_json);
|
||||||
|
|
||||||
bus *b = new bus();
|
DOLOG(info, true, "PDP11 emulator, by Folkert van Heusden");
|
||||||
|
|
||||||
|
DOLOG(info, true, "Built on: " __DATE__ " " __TIME__);
|
||||||
|
|
||||||
|
start_disk_devices(rk05_files, disk_snapshots);
|
||||||
|
|
||||||
|
start_disk_devices(rl02_files, disk_snapshots);
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
if (withUI)
|
||||||
|
cnsl = new console_ncurses(&event);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
cnsl = new console_posix(&event);
|
||||||
|
|
||||||
|
bus *b = nullptr;
|
||||||
|
|
||||||
|
if (deserialize.empty()) {
|
||||||
|
b = new bus();
|
||||||
|
|
||||||
if (set_ram_size.has_value())
|
if (set_ram_size.has_value())
|
||||||
b->set_memory_size(set_ram_size.value());
|
b->set_memory_size(set_ram_size.value());
|
||||||
|
else
|
||||||
|
b->set_memory_size(DEFAULT_N_PAGES * 8192l);
|
||||||
|
|
||||||
b->set_console_switches(console_switches);
|
b->set_console_switches(console_switches);
|
||||||
|
|
||||||
cpu *c = new cpu(b, &event);
|
cpu *c = new cpu(b, &event);
|
||||||
b->add_cpu(c);
|
b->add_cpu(c);
|
||||||
|
|
||||||
|
if (rk05_files.empty() == false)
|
||||||
|
bootloader = BL_RK05;
|
||||||
|
|
||||||
|
if (rl02_files.empty() == false)
|
||||||
|
bootloader = BL_RL02;
|
||||||
|
|
||||||
|
if (enable_bootloader)
|
||||||
|
set_boot_loader(b, bootloader);
|
||||||
|
|
||||||
|
b->add_rk05(new rk05(rk05_files, b, cnsl->get_disk_read_activity_flag(), cnsl->get_disk_write_activity_flag()));
|
||||||
|
|
||||||
|
b->add_rl02(new rl02(rl02_files, b, cnsl->get_disk_read_activity_flag(), cnsl->get_disk_write_activity_flag()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
FILE *fh = fopen(deserialize.c_str(), "r");
|
||||||
|
if (!fh)
|
||||||
|
error_exit(true, "Failed to open %s", deserialize.c_str());
|
||||||
|
|
||||||
|
json_error_t je { };
|
||||||
|
json_t *j = json_loadf(fh, 0, &je);
|
||||||
|
|
||||||
|
fclose(fh);
|
||||||
|
|
||||||
|
if (!j)
|
||||||
|
error_exit(true, "State file %s is corrupt: %s", deserialize.c_str(), je.text);
|
||||||
|
|
||||||
|
b = bus::deserialize(j, cnsl, &event);
|
||||||
|
|
||||||
|
json_decref(j);
|
||||||
|
|
||||||
|
DOLOG(warning, true, "DO NOT FORGET TO DELETE AND NOT TO RE-USE THE STATE FILE (\"%s\")! (unless updated)", deserialize.c_str());
|
||||||
|
myusleep(251000);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b->getTty() == nullptr) {
|
||||||
|
tty *tty_ = new tty(cnsl, b);
|
||||||
|
|
||||||
|
b->add_tty(tty_);
|
||||||
|
}
|
||||||
|
|
||||||
|
cnsl->set_bus(b);
|
||||||
|
|
||||||
|
running = cnsl->get_running_flag();
|
||||||
|
|
||||||
std::atomic_bool interrupt_emulation { false };
|
std::atomic_bool interrupt_emulation { false };
|
||||||
|
|
||||||
std::optional<uint16_t> bic_start;
|
std::optional<uint16_t> bic_start;
|
||||||
|
@ -520,53 +579,13 @@ int main(int argc, char *argv[])
|
||||||
if (bic_start.has_value() == false)
|
if (bic_start.has_value() == false)
|
||||||
return 1; // fail
|
return 1; // fail
|
||||||
|
|
||||||
c->setRegister(7, bic_start.value());
|
b->getCpu()->setRegister(7, bic_start.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa_set)
|
if (sa_set)
|
||||||
c->setRegister(7, start_addr);
|
b->getCpu()->setRegister(7, start_addr);
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
DOLOG(info, true, "Start running at %06o", b->getCpu()->getRegister(7));
|
||||||
if (withUI)
|
|
||||||
cnsl = new console_ncurses(&event, b);
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
DOLOG(info, true, "This PDP-11 emulator is called \"kek\" (reason for that is forgotten) and was written by Folkert van Heusden.");
|
|
||||||
|
|
||||||
DOLOG(info, true, "Built on: " __DATE__ " " __TIME__);
|
|
||||||
|
|
||||||
cnsl = new console_posix(&event, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rk05_files.empty() == false) {
|
|
||||||
if (enable_bootloader == false)
|
|
||||||
DOLOG(warning, true, "Note: loading RK05 with no (RK05-) bootloader selected");
|
|
||||||
else
|
|
||||||
bootloader = BL_RK05;
|
|
||||||
|
|
||||||
b->add_rk05(new rk05(rk05_files, b, cnsl->get_disk_read_activity_flag(), cnsl->get_disk_write_activity_flag()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rl02_files.empty() == false) {
|
|
||||||
if (enable_bootloader == false)
|
|
||||||
DOLOG(warning, true, "Note: loading RL02 with no (RL02-) bootloader selected");
|
|
||||||
else
|
|
||||||
bootloader = BL_RL02;
|
|
||||||
|
|
||||||
b->add_rl02(new rl02(rl02_files, b, cnsl->get_disk_read_activity_flag(), cnsl->get_disk_write_activity_flag()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enable_bootloader)
|
|
||||||
setBootLoader(b, bootloader);
|
|
||||||
|
|
||||||
running = cnsl->get_running_flag();
|
|
||||||
|
|
||||||
tty *tty_ = new tty(cnsl, b);
|
|
||||||
|
|
||||||
b->add_tty(tty_);
|
|
||||||
|
|
||||||
DOLOG(info, true, "Start running at %06o", c->getRegister(7));
|
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
struct sigaction sa { };
|
struct sigaction sa { };
|
||||||
|
@ -584,26 +603,26 @@ int main(int argc, char *argv[])
|
||||||
if (test.empty() == false)
|
if (test.empty() == false)
|
||||||
load_p11_x11(b, test);
|
load_p11_x11(b, test);
|
||||||
|
|
||||||
kw11_l *lf = new kw11_l(b, cnsl);
|
|
||||||
|
|
||||||
std::thread *metrics_thread = nullptr;
|
std::thread *metrics_thread = nullptr;
|
||||||
if (metrics)
|
if (metrics)
|
||||||
metrics_thread = new std::thread(get_metrics, c);
|
metrics_thread = new std::thread(get_metrics, b->getCpu());
|
||||||
|
|
||||||
cnsl->start_thread();
|
cnsl->start_thread();
|
||||||
|
|
||||||
|
b->getKW11_L()->begin(cnsl);
|
||||||
|
|
||||||
if (is_bic)
|
if (is_bic)
|
||||||
run_bic(cnsl, b, &event, tracing, bic_start.value());
|
run_bic(cnsl, b, &event, tracing, bic_start.value());
|
||||||
else if (run_debugger || (bootloader == BL_NONE && test.empty() && tape.empty()))
|
else if (run_debugger || (bootloader == BL_NONE && test.empty() && tape.empty()))
|
||||||
debugger(cnsl, b, &event, tracing);
|
debugger(cnsl, b, &event, tracing);
|
||||||
else {
|
else {
|
||||||
c->emulation_start(); // for statistics
|
b->getCpu()->emulation_start(); // for statistics
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
*running = true;
|
*running = true;
|
||||||
|
|
||||||
while(event == EVENT_NONE)
|
while(event == EVENT_NONE)
|
||||||
c->step();
|
b->getCpu()->step();
|
||||||
|
|
||||||
*running = false;
|
*running = false;
|
||||||
|
|
||||||
|
@ -613,7 +632,7 @@ int main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto stats = c->get_mips_rel_speed({ }, { });
|
auto stats = b->getCpu()->get_mips_rel_speed({ }, { });
|
||||||
cnsl->put_string_lf(format("MIPS: %.2f, relative speed: %.2f%%, instructions executed: %" PRIu64 " in %.2f seconds", std::get<0>(stats), std::get<1>(stats), std::get<2>(stats), std::get<3>(stats) / 1000000.));
|
cnsl->put_string_lf(format("MIPS: %.2f, relative speed: %.2f%%, instructions executed: %" PRIu64 " in %.2f seconds", std::get<0>(stats), std::get<1>(stats), std::get<2>(stats), std::get<3>(stats) / 1000000.));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -624,11 +643,11 @@ int main(int argc, char *argv[])
|
||||||
delete metrics_thread;
|
delete metrics_thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete lf;
|
cnsl->stop_thread();
|
||||||
|
|
||||||
delete cnsl;
|
|
||||||
|
|
||||||
delete b;
|
delete b;
|
||||||
|
|
||||||
|
delete cnsl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
28
memory.cpp
28
memory.cpp
|
@ -46,3 +46,31 @@ void memory::reset()
|
||||||
{
|
{
|
||||||
memset(m, 0x00, size);
|
memset(m, 0x00, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
|
json_t *memory::serialize() const
|
||||||
|
{
|
||||||
|
json_t *j = json_object();
|
||||||
|
|
||||||
|
json_object_set(j, "size", json_integer(size));
|
||||||
|
|
||||||
|
json_t *ja = json_array();
|
||||||
|
for(size_t i=0; i<size; i++)
|
||||||
|
json_array_append(ja, json_integer(m[i]));
|
||||||
|
json_object_set(j, "contents", ja);
|
||||||
|
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
|
memory *memory::deserialize(const json_t *const j)
|
||||||
|
{
|
||||||
|
size_t size = json_integer_value(json_object_get(j, "size"));
|
||||||
|
memory *m = new memory(size);
|
||||||
|
|
||||||
|
json_t *ja = json_object_get(j, "contents");
|
||||||
|
for(size_t i=0; i<size; i++)
|
||||||
|
m->m[i] = json_integer_value(json_array_get(ja, i));
|
||||||
|
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
8
memory.h
8
memory.h
|
@ -2,10 +2,12 @@
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "gen.h"
|
||||||
|
|
||||||
|
|
||||||
class memory
|
class memory
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -20,6 +22,10 @@ public:
|
||||||
~memory();
|
~memory();
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
#if IS_POSIX
|
||||||
|
json_t *serialize() const;
|
||||||
|
static memory *deserialize(const json_t *const j);
|
||||||
|
#endif
|
||||||
|
|
||||||
uint16_t readByte(const uint32_t a) const { return m[a]; }
|
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; }
|
void writeByte(const uint32_t a, const uint16_t v) { assert(a < size); m[a] = v; }
|
||||||
|
|
77
mmu.cpp
77
mmu.cpp
|
@ -220,3 +220,80 @@ void mmu::writeByte(const uint16_t a, const uint8_t value)
|
||||||
else if (a >= ADDR_PAR_U_START && a < ADDR_PAR_U_END)
|
else if (a >= ADDR_PAR_U_START && a < ADDR_PAR_U_END)
|
||||||
write_par(a, 3, value, wm_byte);
|
write_par(a, 3, value, wm_byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
|
void mmu::add_par_pdr(json_t *const target, const int run_mode, const bool is_d, const std::string & name) const
|
||||||
|
{
|
||||||
|
json_t *j = json_object();
|
||||||
|
|
||||||
|
json_t *ja_par = json_array();
|
||||||
|
for(int i=0; i<8; i++)
|
||||||
|
json_array_append(ja_par, json_integer(pages[run_mode][is_d][i].par));
|
||||||
|
json_object_set(j, "par", ja_par);
|
||||||
|
|
||||||
|
json_t *ja_pdr = json_array();
|
||||||
|
for(int i=0; i<8; i++)
|
||||||
|
json_array_append(ja_pdr, json_integer(pages[run_mode][is_d][i].pdr));
|
||||||
|
json_object_set(j, "pdr", ja_pdr);
|
||||||
|
|
||||||
|
json_object_set(target, name.c_str(), j);
|
||||||
|
}
|
||||||
|
|
||||||
|
json_t *mmu::serialize() const
|
||||||
|
{
|
||||||
|
json_t *j = json_object();
|
||||||
|
|
||||||
|
for(int run_mode=0; run_mode<4; run_mode++) {
|
||||||
|
if (run_mode == 2)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for(int is_d=0; is_d<2; is_d++)
|
||||||
|
add_par_pdr(j, run_mode, is_d, format("runmode_%d_d_%d", run_mode, is_d));
|
||||||
|
}
|
||||||
|
|
||||||
|
json_object_set(j, "MMR0", json_integer(MMR0));
|
||||||
|
json_object_set(j, "MMR1", json_integer(MMR1));
|
||||||
|
json_object_set(j, "MMR2", json_integer(MMR2));
|
||||||
|
json_object_set(j, "MMR3", json_integer(MMR3));
|
||||||
|
json_object_set(j, "CPUERR", json_integer(CPUERR));
|
||||||
|
json_object_set(j, "PIR", json_integer(PIR));
|
||||||
|
json_object_set(j, "CSR", json_integer(CSR));
|
||||||
|
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mmu::set_par_pdr(const json_t *const j_in, const int run_mode, const bool is_d, const std::string & name)
|
||||||
|
{
|
||||||
|
json_t *j = json_object_get(j_in, name.c_str());
|
||||||
|
|
||||||
|
json_t *j_par = json_object_get(j, "par");
|
||||||
|
for(int i=0; i<8; i++)
|
||||||
|
pages[run_mode][is_d][i].par = json_integer_value(json_array_get(j_par, i));
|
||||||
|
json_t *j_pdr = json_object_get(j, "pdr");
|
||||||
|
for(int i=0; i<8; i++)
|
||||||
|
pages[run_mode][is_d][i].pdr = json_integer_value(json_array_get(j_pdr, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
mmu *mmu::deserialize(const json_t *const j)
|
||||||
|
{
|
||||||
|
mmu *m = new mmu();
|
||||||
|
|
||||||
|
for(int run_mode=0; run_mode<4; run_mode++) {
|
||||||
|
if (run_mode == 2)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for(int is_d=0; is_d<2; is_d++)
|
||||||
|
m->set_par_pdr(j, run_mode, is_d, format("runmode_%d_d_%d", run_mode, is_d));
|
||||||
|
}
|
||||||
|
|
||||||
|
m->MMR0 = json_integer_value(json_object_get(j, "MMR0"));
|
||||||
|
m->MMR1 = json_integer_value(json_object_get(j, "MMR1"));
|
||||||
|
m->MMR2 = json_integer_value(json_object_get(j, "MMR2"));
|
||||||
|
m->MMR3 = json_integer_value(json_object_get(j, "MMR3"));
|
||||||
|
m->CPUERR = json_integer_value(json_object_get(j, "CPUERR"));
|
||||||
|
m->PIR = json_integer_value(json_object_get(j, "PIR"));
|
||||||
|
m->CSR = json_integer_value(json_object_get(j, "CSR"));
|
||||||
|
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
12
mmu.h
12
mmu.h
|
@ -1,8 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
#include "gen.h"
|
||||||
|
|
||||||
#define ADDR_PDR_SV_START 0172200
|
#define ADDR_PDR_SV_START 0172200
|
||||||
#define ADDR_PDR_SV_END 0172240
|
#define ADDR_PDR_SV_END 0172240
|
||||||
|
@ -39,10 +41,20 @@ private:
|
||||||
uint16_t PIR { 0 };
|
uint16_t PIR { 0 };
|
||||||
uint16_t CSR { 0 };
|
uint16_t CSR { 0 };
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
|
void add_par_pdr(json_t *const target, const int run_mode, const bool is_d, const std::string & name) const;
|
||||||
|
void set_par_pdr(const json_t *const j_in, const int run_mode, const bool is_d, const std::string & name);
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
mmu();
|
mmu();
|
||||||
virtual ~mmu();
|
virtual ~mmu();
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
|
json_t *serialize() const;
|
||||||
|
static mmu *deserialize(const json_t *const j);
|
||||||
|
#endif
|
||||||
|
|
||||||
void reset() override;
|
void reset() override;
|
||||||
|
|
||||||
bool is_enabled() const { return MMR0 & 1; }
|
bool is_enabled() const { return MMR0 & 1; }
|
||||||
|
|
4
rk05.cpp
4
rk05.cpp
|
@ -156,7 +156,7 @@ void rk05::writeWord(const uint16_t addr, const uint16_t v)
|
||||||
for(size_t i=0; i<cur; i++)
|
for(size_t i=0; i<cur; i++)
|
||||||
xfer_buffer[i] = b->readUnibusByte(work_memoff++);
|
xfer_buffer[i] = b->readUnibusByte(work_memoff++);
|
||||||
|
|
||||||
if (!fhs.at(device)->write(work_diskoffb, cur, xfer_buffer))
|
if (!fhs.at(device)->write(work_diskoffb, cur, xfer_buffer, 512))
|
||||||
DOLOG(ll_error, true, "RK05(%d) write error %s to %u len %u", device, strerror(errno), work_diskoffb, cur);
|
DOLOG(ll_error, true, "RK05(%d) write error %s to %u len %u", device, strerror(errno), work_diskoffb, cur);
|
||||||
|
|
||||||
work_diskoffb += cur;
|
work_diskoffb += cur;
|
||||||
|
@ -191,7 +191,7 @@ void rk05::writeWord(const uint16_t addr, const uint16_t v)
|
||||||
while(temp > 0) {
|
while(temp > 0) {
|
||||||
uint32_t cur = std::min(uint32_t(sizeof xfer_buffer), temp);
|
uint32_t cur = std::min(uint32_t(sizeof xfer_buffer), temp);
|
||||||
|
|
||||||
if (!fhs.at(device)->read(temp_diskoffb, cur, xfer_buffer)) {
|
if (!fhs.at(device)->read(temp_diskoffb, cur, xfer_buffer, 512)) {
|
||||||
DOLOG(ll_error, true, "RK05 read error %s from %u len %u", strerror(errno), temp_diskoffb, cur);
|
DOLOG(ll_error, true, "RK05 read error %s from %u len %u", strerror(errno), temp_diskoffb, cur);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
5
rk05.h
5
rk05.h
|
@ -9,7 +9,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "device.h"
|
#include "disk_device.h"
|
||||||
#include "disk_backend.h"
|
#include "disk_backend.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,12 +25,11 @@
|
||||||
|
|
||||||
class bus;
|
class bus;
|
||||||
|
|
||||||
class rk05 : public device
|
class rk05: public disk_device
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bus *const b { nullptr };
|
bus *const b { nullptr };
|
||||||
uint16_t registers [7] { 0 };
|
uint16_t registers [7] { 0 };
|
||||||
std::vector<disk_backend *> fhs;
|
|
||||||
uint8_t xfer_buffer[512] { 0 };
|
uint8_t xfer_buffer[512] { 0 };
|
||||||
|
|
||||||
std::atomic_bool *const disk_read_acitivity { nullptr };
|
std::atomic_bool *const disk_read_acitivity { nullptr };
|
||||||
|
|
74
rl02.cpp
74
rl02.cpp
|
@ -31,10 +31,10 @@ static const char * const commands[] = {
|
||||||
"read data w/o header check"
|
"read data w/o header check"
|
||||||
};
|
};
|
||||||
|
|
||||||
rl02::rl02(const std::vector<disk_backend *> & files, bus *const b, std::atomic_bool *const disk_read_acitivity, std::atomic_bool *const disk_write_acitivity) :
|
rl02::rl02(const std::vector<disk_backend *> & files, bus *const b, std::atomic_bool *const disk_read_activity, std::atomic_bool *const disk_write_activity) :
|
||||||
b(b),
|
b(b),
|
||||||
disk_read_acitivity(disk_read_acitivity),
|
disk_read_activity (disk_read_activity ),
|
||||||
disk_write_acitivity(disk_write_acitivity)
|
disk_write_activity(disk_write_activity)
|
||||||
{
|
{
|
||||||
fhs = files;
|
fhs = files;
|
||||||
|
|
||||||
|
@ -58,6 +58,54 @@ void rl02::reset()
|
||||||
sector = 0;
|
sector = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
|
json_t *rl02::serialize() const
|
||||||
|
{
|
||||||
|
json_t *j = json_object();
|
||||||
|
|
||||||
|
json_t *j_backends = json_array();
|
||||||
|
for(auto & dbe: fhs)
|
||||||
|
json_array_append(j_backends, dbe->serialize());
|
||||||
|
|
||||||
|
json_object_set(j, "backends", j_backends);
|
||||||
|
|
||||||
|
for(int regnr=0; regnr<4; regnr++)
|
||||||
|
json_object_set(j, format("register-%d", regnr).c_str(), json_integer(registers[regnr]));
|
||||||
|
|
||||||
|
for(int mprnr=0; mprnr<3; mprnr++)
|
||||||
|
json_object_set(j, format("mpr-%d", mprnr).c_str(), json_integer(mpr[mprnr]));
|
||||||
|
|
||||||
|
json_object_set(j, "track", json_integer(track));
|
||||||
|
json_object_set(j, "head", json_integer(head));
|
||||||
|
json_object_set(j, "sector", json_integer(sector));
|
||||||
|
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
|
rl02 *rl02::deserialize(const json_t *const j, bus *const b)
|
||||||
|
{
|
||||||
|
std::vector<disk_backend *> backends;
|
||||||
|
|
||||||
|
json_t *j_backends = json_object_get(j, "backends");
|
||||||
|
for(size_t i=0; i<json_array_size(j_backends); i++)
|
||||||
|
backends.push_back(disk_backend::deserialize(json_array_get(j_backends, i)));
|
||||||
|
|
||||||
|
rl02 *r = new rl02(backends, b, nullptr, nullptr);
|
||||||
|
|
||||||
|
for(int regnr=0; regnr<4; regnr++)
|
||||||
|
r->registers[regnr] = json_integer_value(json_object_get(j, format("register-%d", regnr).c_str()));
|
||||||
|
|
||||||
|
for(int mprnr=0; mprnr<3; mprnr++)
|
||||||
|
r->mpr[mprnr] = json_integer_value(json_object_get(j, format("mpr-%d", mprnr).c_str()));
|
||||||
|
|
||||||
|
r->track = json_integer_value(json_object_get(j, "track" ));
|
||||||
|
r->head = json_integer_value(json_object_get(j, "head" ));
|
||||||
|
r->sector = json_integer_value(json_object_get(j, "sector"));
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
uint8_t rl02::readByte(const uint16_t addr)
|
uint8_t rl02::readByte(const uint16_t addr)
|
||||||
{
|
{
|
||||||
uint16_t v = readWord(addr & ~1);
|
uint16_t v = readWord(addr & ~1);
|
||||||
|
@ -152,8 +200,6 @@ void rl02::writeWord(const uint16_t addr, uint16_t v)
|
||||||
|
|
||||||
bool do_int = false;
|
bool do_int = false;
|
||||||
|
|
||||||
*disk_read_acitivity = true;
|
|
||||||
|
|
||||||
if (size_t(device) >= fhs.size()) {
|
if (size_t(device) >= fhs.size()) {
|
||||||
DOLOG(info, false, "RL02: PDP11/70 is accessing a not-attached virtual disk %d", device);
|
DOLOG(info, false, "RL02: PDP11/70 is accessing a not-attached virtual disk %d", device);
|
||||||
|
|
||||||
|
@ -194,6 +240,9 @@ void rl02::writeWord(const uint16_t addr, uint16_t v)
|
||||||
do_int = true;
|
do_int = true;
|
||||||
}
|
}
|
||||||
else if (command == 5) { // write data
|
else if (command == 5) { // write data
|
||||||
|
if (disk_write_activity)
|
||||||
|
*disk_write_activity = true;
|
||||||
|
|
||||||
uint32_t memory_address = get_bus_address();
|
uint32_t memory_address = get_bus_address();
|
||||||
|
|
||||||
uint32_t count = (65536l - registers[(RL02_MPR - RL02_BASE) / 2]) * 2;
|
uint32_t count = (65536l - registers[(RL02_MPR - RL02_BASE) / 2]) * 2;
|
||||||
|
@ -222,7 +271,7 @@ void rl02::writeWord(const uint16_t addr, uint16_t v)
|
||||||
mpr[0]++;
|
mpr[0]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fhs.at(device)->write(temp_disk_offset, cur, xfer_buffer)) {
|
if (fhs.at(device) == nullptr || fhs.at(device)->write(temp_disk_offset, cur, xfer_buffer, 256) == false) {
|
||||||
DOLOG(ll_error, true, "RL02: write error, device %d, disk offset %u, read size %u, cylinder %d, head %d, sector %d", device, temp_disk_offset, cur, track, head, sector);
|
DOLOG(ll_error, true, "RL02: write error, device %d, disk offset %u, read size %u, cylinder %d, head %d, sector %d", device, temp_disk_offset, cur, track, head, sector);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -247,8 +296,14 @@ void rl02::writeWord(const uint16_t addr, uint16_t v)
|
||||||
}
|
}
|
||||||
|
|
||||||
do_int = true;
|
do_int = true;
|
||||||
|
|
||||||
|
if (disk_write_activity)
|
||||||
|
*disk_write_activity = false;
|
||||||
}
|
}
|
||||||
else if (command == 6 || command == 7) { // read data / read data without header check
|
else if (command == 6 || command == 7) { // read data / read data without header check
|
||||||
|
if (disk_read_activity)
|
||||||
|
*disk_read_activity = true;
|
||||||
|
|
||||||
uint32_t memory_address = get_bus_address();
|
uint32_t memory_address = get_bus_address();
|
||||||
|
|
||||||
uint32_t count = (65536l - registers[(RL02_MPR - RL02_BASE) / 2]) * 2;
|
uint32_t count = (65536l - registers[(RL02_MPR - RL02_BASE) / 2]) * 2;
|
||||||
|
@ -270,7 +325,7 @@ void rl02::writeWord(const uint16_t addr, uint16_t v)
|
||||||
while(count > 0) {
|
while(count > 0) {
|
||||||
uint32_t cur = std::min(uint32_t(sizeof xfer_buffer), count);
|
uint32_t cur = std::min(uint32_t(sizeof xfer_buffer), count);
|
||||||
|
|
||||||
if (!fhs.at(device)->read(temp_disk_offset, cur, xfer_buffer)) {
|
if (fhs.at(device) == nullptr || fhs.at(device)->read(temp_disk_offset, cur, xfer_buffer, 256) == false) {
|
||||||
DOLOG(ll_error, true, "RL02: read error, device %d, disk offset %u, read size %u, cylinder %d, head %d, sector %d", device, temp_disk_offset, cur, track, head, sector);
|
DOLOG(ll_error, true, "RL02: read error, device %d, disk offset %u, read size %u, cylinder %d, head %d, sector %d", device, temp_disk_offset, cur, track, head, sector);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -305,6 +360,9 @@ void rl02::writeWord(const uint16_t addr, uint16_t v)
|
||||||
}
|
}
|
||||||
|
|
||||||
do_int = true;
|
do_int = true;
|
||||||
|
|
||||||
|
if (disk_read_activity)
|
||||||
|
*disk_read_activity = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DOLOG(warning, false, "RL02: command %d not implemented", command);
|
DOLOG(warning, false, "RL02: command %d not implemented", command);
|
||||||
|
@ -317,7 +375,5 @@ void rl02::writeWord(const uint16_t addr, uint16_t v)
|
||||||
b->getCpu()->queue_interrupt(5, 0160);
|
b->getCpu()->queue_interrupt(5, 0160);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*disk_read_acitivity = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
rl02.h
17
rl02.h
|
@ -9,8 +9,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "device.h"
|
#include "disk_device.h"
|
||||||
#include "disk_backend.h"
|
#include "disk_backend.h"
|
||||||
|
#include "gen.h"
|
||||||
|
|
||||||
|
|
||||||
#define RL02_CSR 0174400 // control status register
|
#define RL02_CSR 0174400 // control status register
|
||||||
|
@ -26,7 +27,7 @@ constexpr const int rl02_bytes_per_sector = 256;
|
||||||
|
|
||||||
class bus;
|
class bus;
|
||||||
|
|
||||||
class rl02 : public device
|
class rl02: public disk_device
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bus *const b;
|
bus *const b;
|
||||||
|
@ -36,10 +37,9 @@ private:
|
||||||
uint8_t head { 0 };
|
uint8_t head { 0 };
|
||||||
uint8_t sector { 0 };
|
uint8_t sector { 0 };
|
||||||
uint16_t mpr[3];
|
uint16_t mpr[3];
|
||||||
std::vector<disk_backend *> fhs;
|
|
||||||
|
|
||||||
std::atomic_bool *const disk_read_acitivity { nullptr };
|
std::atomic_bool *const disk_read_activity { nullptr };
|
||||||
std::atomic_bool *const disk_write_acitivity { nullptr };
|
std::atomic_bool *const disk_write_activity { nullptr };
|
||||||
|
|
||||||
uint32_t get_bus_address() const;
|
uint32_t get_bus_address() const;
|
||||||
void update_bus_address(const uint32_t a);
|
void update_bus_address(const uint32_t a);
|
||||||
|
@ -47,11 +47,16 @@ private:
|
||||||
uint32_t calc_offset() const;
|
uint32_t calc_offset() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
rl02(const std::vector<disk_backend *> & files, bus *const b, std::atomic_bool *const disk_read_acitivity, std::atomic_bool *const disk_write_acitivity);
|
rl02(const std::vector<disk_backend *> & files, bus *const b, std::atomic_bool *const disk_read_activity, std::atomic_bool *const disk_write_activity);
|
||||||
virtual ~rl02();
|
virtual ~rl02();
|
||||||
|
|
||||||
void reset() override;
|
void reset() override;
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
|
json_t *serialize() const;
|
||||||
|
static rl02 *deserialize(const json_t *const j, bus *const b);
|
||||||
|
#endif
|
||||||
|
|
||||||
uint8_t readByte(const uint16_t addr) override;
|
uint8_t readByte(const uint16_t addr) override;
|
||||||
uint16_t readWord(const uint16_t addr) override;
|
uint16_t readWord(const uint16_t addr) override;
|
||||||
|
|
||||||
|
|
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
|
// Released under MIT license
|
||||||
|
|
||||||
#include <errno.h>
|
#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);
|
DOLOG(debug, false, "set register %o to %o", addr, v);
|
||||||
registers[(addr - PDP11TTY_BASE) / 2] = 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
|
// Released under MIT license
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include "bus.h"
|
#include "bus.h"
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
|
#include "gen.h"
|
||||||
|
|
||||||
|
|
||||||
#define PDP11TTY_TKS 0177560 // reader status
|
#define PDP11TTY_TKS 0177560 // reader status
|
||||||
|
@ -50,6 +51,11 @@ public:
|
||||||
tty(console *const c, bus *const b);
|
tty(console *const c, bus *const b);
|
||||||
virtual ~tty();
|
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();
|
void reset();
|
||||||
|
|
||||||
uint8_t readByte(const uint16_t addr);
|
uint8_t readByte(const uint16_t addr);
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// (C) 2018-2023 by Folkert van Heusden
|
// (C) 2018-2024 by Folkert van Heusden
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
|
#include "gen.h"
|
||||||
|
|
||||||
#if defined(ESP32) || defined(BUILD_FOR_RP2040)
|
#if defined(ESP32) || defined(BUILD_FOR_RP2040)
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "rp2040.h"
|
#include "rp2040.h"
|
||||||
|
@ -165,7 +167,7 @@ void set_thread_name(std::string name)
|
||||||
|
|
||||||
std::string get_thread_name()
|
std::string get_thread_name()
|
||||||
{
|
{
|
||||||
#ifdef linux
|
#if IS_POSIX
|
||||||
char buffer[16 + 1] { };
|
char buffer[16 + 1] { };
|
||||||
pthread_getname_np(pthread_self(), buffer, sizeof buffer);
|
pthread_getname_np(pthread_self(), buffer, sizeof buffer);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue