From 90af933fb7b2c7ed66c5db13f89f83f86483eb71 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Fri, 26 Apr 2024 15:29:49 +0200 Subject: [PATCH 1/4] code clean-up & compile fix for ESP32 --- ESP32/disk_device.h | 1 + ESP32/main.ino | 7 +-- debugger.cpp | 150 -------------------------------------------- debugger.h | 4 -- 4 files changed, 2 insertions(+), 160 deletions(-) create mode 120000 ESP32/disk_device.h diff --git a/ESP32/disk_device.h b/ESP32/disk_device.h new file mode 120000 index 0000000..dbcee94 --- /dev/null +++ b/ESP32/disk_device.h @@ -0,0 +1 @@ +../disk_device.h \ No newline at end of file diff --git a/ESP32/main.ino b/ESP32/main.ino index 1609ba9..618845e 100644 --- a/ESP32/main.ino +++ b/ESP32/main.ino @@ -193,12 +193,7 @@ void recall_configuration(console *const cnsl) cnsl->put_string_lf("Starting network..."); start_network(cnsl); - auto disk_configuration = load_disk_configuration(cnsl); - - if (disk_configuration.has_value()) { - cnsl->put_string_lf("Starting disk..."); - set_disk_configuration(b, cnsl, disk_configuration.value()); - } + // TODO } #endif diff --git a/debugger.cpp b/debugger.cpp index 4d696ec..c48241b 100644 --- a/debugger.cpp +++ b/debugger.cpp @@ -10,7 +10,6 @@ #include #else #include -#include #include #endif @@ -47,155 +46,12 @@ void check_network(console *const c); void start_network(console *const c); void set_tty_serial_speed(console *const c, const uint32_t bps); - -void recall_configuration(console *const c); #endif -#define NET_DISK_CFG_FILE "net-disk.json" - #if !defined(BUILD_FOR_RP2040) && !defined(linux) extern SdFs SD; #endif -#ifndef linux -#define MAX_CFG_SIZE 1024 -StaticJsonDocument json_doc; -#endif - -typedef enum { BE_NETWORK, BE_SD } disk_backend_t; - -#if !defined(BUILD_FOR_RP2040) -std::optional, std::vector, std::string> > load_disk_configuration(console *const c) -{ -#if IS_POSIX - json_error_t error; - json_t *json = json_load_file("." NET_DISK_CFG_FILE, JSON_REJECT_DUPLICATES, &error); - if (!json) { - c->put_string_lf(format("Cannot load ." NET_DISK_CFG_FILE ": %s", error.text)); - - return { }; - } - - std::string nbd_host = json_string_value (json_object_get(json, "NBD-host")); - int nbd_port = json_integer_value(json_object_get(json, "NBD-port")); - - std::string disk_type_temp = json_string_value (json_object_get(json, "disk-type")); - - std::string tape_file = json_string_value (json_object_get(json, "tape-file")); - - json_decref(json); -#else - File dataFile = LittleFS.open("/" NET_DISK_CFG_FILE, "r"); - if (!dataFile) - return { }; - - size_t size = dataFile.size(); - - char buffer[MAX_CFG_SIZE]; - - if (size > sizeof buffer) { // this should not happen - dataFile.close(); - - return { }; - } - - dataFile.read(reinterpret_cast(buffer), size); - buffer[(sizeof buffer) - 1] = 0x00; - - dataFile.close(); - - auto error = deserializeJson(json_doc, buffer); - if (error) // this should not happen - return { }; - - String nbd_host = json_doc["NBD-host"]; - int nbd_port = json_doc["NBD-port"]; - - String disk_type_temp = json_doc["disk-type"]; - - String tape_file = json_doc["tape-file"]; -#endif - - disk_type_t disk_type = DT_RK05; - - if (disk_type_temp == "rl02") - disk_type = DT_RL02; - else if (disk_type_temp == "tape") - disk_type = DT_TAPE; - - disk_backend *d = new disk_backend_nbd(nbd_host.c_str(), nbd_port); - - if (d->begin(false) == false) { - c->put_string_lf("Cannot initialize NBD client from configuration file"); - delete d; - return { }; - } - - c->put_string_lf(format("Connection to NBD server at %s:%d success", nbd_host.c_str(), nbd_port)); - - if (disk_type == DT_RK05) - return { { { d }, { }, "" } }; - - if (disk_type == DT_RL02) - return { { { }, { d }, "" } }; - - if (disk_type == DT_TAPE) - return { { { }, { }, tape_file.c_str() } }; - - return { }; -} - -bool save_disk_configuration(const std::string & nbd_host, const int nbd_port, const std::optional & tape_file, const disk_type_t dt, console *const cnsl) -{ -#if IS_POSIX - json_t *json = json_object(); - - json_object_set(json, "NBD-host", json_string(nbd_host.c_str())); - json_object_set(json, "NBD-port", json_integer(nbd_port)); - - if (dt == DT_RK05) - json_object_set(json, "disk-type", json_string("rk05")); - else if (dt == DT_RL02) - json_object_set(json, "disk-type", json_string("rl02")); - else - json_object_set(json, "disk-type", json_string("tape")); - - json_object_set(json, "tape-file", json_string(tape_file.has_value() ? tape_file.value().c_str() : "")); - - bool succeeded = json_dump_file(json, "." NET_DISK_CFG_FILE, 0) == 0; - json_decref(json); - - if (succeeded == false) { - cnsl->put_string_lf(format("Cannot write ." NET_DISK_CFG_FILE)); - - return false; - } -#else - json_doc["NBD-host"] = nbd_host; - json_doc["NBD-port"] = nbd_port; - - if (dt == DT_RK05) - json_doc["disk-type"] = "rk05"; - else if (dt == DT_RL02) - json_doc["disk-type"] = "rl02"; - else - json_doc["disk-type"] = "tape"; - - json_doc["tape-file"] = tape_file.has_value() ? tape_file.value() : ""; - - File dataFile = LittleFS.open("/" NET_DISK_CFG_FILE, "w"); - if (!dataFile) - return false; - - serializeJson(json_doc, dataFile); - - dataFile.close(); -#endif - - return true; -} -#endif - #if !defined(BUILD_FOR_RP2040) std::optional select_nbd_server(console *const cnsl) { @@ -995,11 +851,6 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto cnsl->put_string_lf("serspd requires an (decimal) parameter"); } - continue; - } - else if (cmd == "init") { - recall_configuration(cnsl); - continue; } #endif @@ -1160,7 +1011,6 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto "startnet - start network", "chknet - check network status", "serspd - set serial speed in bps (8N1 are default)", - "init - reload (disk-)configuration from flash", #endif "cfgdisk - configure disk", nullptr diff --git a/debugger.h b/debugger.h index 6a39e46..083f0a1 100644 --- a/debugger.h +++ b/debugger.h @@ -6,10 +6,6 @@ #include "gen.h" -std::optional, std::vector, std::string> > load_disk_configuration(console *const c); -bool save_disk_configuration(const std::string & nbd_host, const int nbd_port, const disk_type_t dt); -void set_disk_configuration(bus *const b, console *const cnsl, std::tuple, std::vector, std::string> & disk_files); - int disassemble(cpu *const c, console *const cnsl, const uint16_t pc, const bool instruction_only); void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const stop_event, const bool tracing); From 7cc3dab687ef13cf136c48be5992f7267e36ca38 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Fri, 26 Apr 2024 16:01:31 +0200 Subject: [PATCH 2/4] casing --- loaders.cpp | 16 ++++++++-------- loaders.h | 4 ++-- main.cpp | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/loaders.cpp b/loaders.cpp index 8f71e3d..8752141 100644 --- a/loaders.cpp +++ b/loaders.cpp @@ -23,14 +23,14 @@ void loadbin(bus *const b, uint16_t base, const char *const file) FILE *fh = fopen(file, "rb"); while(!feof(fh)) - b -> writeByte(base++, fgetc(fh)); + b->writeByte(base++, fgetc(fh)); fclose(fh); } void set_boot_loader(bus *const b, const bootloader_t which) { - cpu *const c = b -> getCpu(); + cpu *const c = b->getCpu(); uint16_t offset = 0; uint16_t start = 0; @@ -139,12 +139,12 @@ void set_boot_loader(bus *const b, const bootloader_t which) } for(int i=0; i writeWord(offset + i * 2, bl[i]); + b->writeWord(offset + i * 2, bl[i]); - c -> setRegister(7, start); + c->setRegister(7, start); } -std::optional loadTape(bus *const b, const std::string & file) +std::optional load_tape(bus *const b, const std::string & file) { #if defined(ESP32) File32 fh; @@ -211,7 +211,7 @@ std::optional loadTape(bus *const b, const std::string & file) #endif csum += c; - b -> writeByte(p++, c); + b->writeByte(p++, c); } #if defined(ESP32) @@ -271,6 +271,6 @@ void load_p11_x11(bus *const b, const std::string & file) fclose(fh); - cpu *const c = b -> getCpu(); - c -> setRegister(7, 0); + cpu *const c = b->getCpu(); + c->setRegister(7, 0); } diff --git a/loaders.h b/loaders.h index 704535a..4b6846f 100644 --- a/loaders.h +++ b/loaders.h @@ -1,4 +1,4 @@ -// (C) 2018-2023 by Folkert van Heusden +// (C) 2018-2024 by Folkert van Heusden // Released under MIT license #include @@ -12,5 +12,5 @@ typedef enum { BL_NONE, BL_RK05, BL_RL02 } bootloader_t; void loadbin(bus *const b, uint16_t base, const char *const file); void set_boot_loader(bus *const b, const bootloader_t which); -std::optional loadTape(bus *const b, const std::string & file); +std::optional load_tape(bus *const b, const std::string & file); void load_p11_x11(bus *const b, const std::string & file); diff --git a/main.cpp b/main.cpp index 56f7c72..7426408 100644 --- a/main.cpp +++ b/main.cpp @@ -574,7 +574,7 @@ int main(int argc, char *argv[]) std::optional bic_start; if (tape.empty() == false) { - bic_start = loadTape(b, tape); + bic_start = load_tape(b, tape); if (bic_start.has_value() == false) return 1; // fail From 6be8f2c970ed4a12d109f1c24a9364e0cccb9318 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Fri, 26 Apr 2024 16:05:29 +0200 Subject: [PATCH 3/4] ESP32: allocate memory & init disks --- ESP32/main.ino | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ESP32/main.ino b/ESP32/main.ino index 618845e..8748cd1 100644 --- a/ESP32/main.ino +++ b/ESP32/main.ino @@ -70,6 +70,9 @@ std::atomic_bool *running { nullptr }; bool trace_output { false }; +std::vector rk05_files; +std::vector rl02_files; + void console_thread_wrapper_panel(void *const c) { console *const cnsl = reinterpret_cast(c); @@ -258,12 +261,20 @@ void setup() { Serial.println(F("Init bus")); b = new bus(); + Serial.println(F("Allocate memory")); + b->set_memory_size(DEFAULT_N_PAGES); + Serial.println(F("Init CPU")); c = new cpu(b, &stop_event); Serial.println(F("Connect CPU to BUS")); b->add_cpu(c); + Serial.println(F("Connect RK05 and RL02 to BUS")); + 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())); + constexpr uint32_t hwSerialConfig = SERIAL_8N1; uint32_t bitrate = load_serial_speed_configuration(); From 723edfd0f975c03718605a6763600ec6086338b4 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Fri, 26 Apr 2024 16:13:38 +0200 Subject: [PATCH 4/4] instantiate rk05/rl02 after console has been setup --- ESP32/main.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ESP32/main.ino b/ESP32/main.ino index 8748cd1..bb29dd8 100644 --- a/ESP32/main.ino +++ b/ESP32/main.ino @@ -270,11 +270,6 @@ void setup() { Serial.println(F("Connect CPU to BUS")); b->add_cpu(c); - Serial.println(F("Connect RK05 and RL02 to BUS")); - 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())); - constexpr uint32_t hwSerialConfig = SERIAL_8N1; uint32_t bitrate = load_serial_speed_configuration(); @@ -299,6 +294,11 @@ void setup() { running = cnsl->get_running_flag(); + Serial.println(F("Connect RK05 and RL02 to BUS")); + 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())); + Serial.println(F("Init TTY")); tty_ = new tty(cnsl, b); Serial.println(F("Connect TTY to bus"));