From 0a2f508e616bc0440dd70cf5088828bd6de71c15 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Thu, 25 Apr 2024 20:30:43 +0200 Subject: [PATCH] several fixes for serialization --- console.cpp | 5 +++-- console.h | 6 ++++-- console_ncurses.cpp | 3 +-- console_ncurses.h | 2 +- console_posix.cpp | 3 +-- console_posix.h | 2 +- disk_backend.cpp | 1 + main.cpp | 36 +++++++++++++++++++----------------- rl02.cpp | 2 +- 9 files changed, 32 insertions(+), 28 deletions(-) diff --git a/console.cpp b/console.cpp index 47beb3d..f656aed 100644 --- a/console.cpp +++ b/console.cpp @@ -25,9 +25,8 @@ void thread_wrapper_console(void *p) } #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), - b(b), t_width(t_width), t_height(t_height) { @@ -49,6 +48,8 @@ console::~console() void console::start_thread() { + assert(b); + stop_thread_flag = false; #if defined(BUILD_FOR_RP2040) diff --git a/console.h b/console.h index 5680350..5cb932f 100644 --- a/console.h +++ b/console.h @@ -31,7 +31,7 @@ private: protected: std::atomic_uint32_t *const stop_event { nullptr }; - bus *const b { nullptr }; + bus *b { nullptr }; #if !defined(BUILD_FOR_RP2040) std::thread *th { nullptr }; #endif @@ -57,9 +57,11 @@ protected: virtual void put_char_ll(const char c) = 0; 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(); + void set_bus(bus *const b) { this->b = b; } + void start_thread(); void stop_thread(); diff --git a/console_ncurses.cpp b/console_ncurses.cpp index 025a2ce..df2e736 100644 --- a/console_ncurses.cpp +++ b/console_ncurses.cpp @@ -13,8 +13,7 @@ #include "utils.h" -console_ncurses::console_ncurses(std::atomic_uint32_t *const stop_event, bus *const b) : - console(stop_event, b) +console_ncurses::console_ncurses(std::atomic_uint32_t *const stop_event): console(stop_event) { init_ncurses(true); diff --git a/console_ncurses.h b/console_ncurses.h index 30eb9ae..99ca686 100644 --- a/console_ncurses.h +++ b/console_ncurses.h @@ -29,7 +29,7 @@ protected: void put_char_ll(const char c) override; 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(); void put_string_lf(const std::string & what) override; diff --git a/console_posix.cpp b/console_posix.cpp index 5d9b9ee..02f7a13 100644 --- a/console_posix.cpp +++ b/console_posix.cpp @@ -16,8 +16,7 @@ #include "error.h" -console_posix::console_posix(std::atomic_uint32_t *const stop_event, bus *const b) : - console(stop_event, b) +console_posix::console_posix(std::atomic_uint32_t *const stop_event): console(stop_event) { #if !defined(_WIN32) if (tcgetattr(STDIN_FILENO, &org_tty_opts) == -1) diff --git a/console_posix.h b/console_posix.h index 661c3d7..aabf323 100644 --- a/console_posix.h +++ b/console_posix.h @@ -21,7 +21,7 @@ protected: void put_char_ll(const char c) override; 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(); void resize_terminal() override; diff --git a/disk_backend.cpp b/disk_backend.cpp index 1b4de50..b1cb17d 100644 --- a/disk_backend.cpp +++ b/disk_backend.cpp @@ -26,6 +26,7 @@ disk_backend *disk_backend::deserialize(const json_t *const j) return disk_backend_nbd::deserialize(j); // should not be reached + assert(false); return nullptr; } diff --git a/main.cpp b/main.cpp index f92a5f8..c9505e4 100644 --- a/main.cpp +++ b/main.cpp @@ -507,6 +507,17 @@ int main(int argc, char *argv[]) if (validate_json.empty() == false) return run_cpu_validation(validate_json); + 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__); + +#if !defined(_WIN32) + if (withUI) + cnsl = new console_ncurses(&event); + else +#endif + cnsl = new console_posix(&event); + bus *b = nullptr; if (deserialize.empty()) { @@ -542,10 +553,6 @@ int main(int argc, char *argv[]) if (enable_bootloader) setBootLoader(b, bootloader); - - tty *tty_ = new tty(cnsl, b); - - b->add_tty(tty_); } else { FILE *fh = fopen(deserialize.c_str(), "r"); @@ -565,6 +572,14 @@ int main(int argc, char *argv[]) json_decref(j); } + 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 }; @@ -583,19 +598,6 @@ int main(int argc, char *argv[]) if (sa_set) b->getCpu()->setRegister(7, start_addr); -#if !defined(_WIN32) - 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); - } - DOLOG(info, true, "Start running at %06o", b->getCpu()->getRegister(7)); #if !defined(_WIN32) diff --git a/rl02.cpp b/rl02.cpp index 25b57af..0256c86 100644 --- a/rl02.cpp +++ b/rl02.cpp @@ -33,7 +33,7 @@ static const char * const commands[] = { rl02::rl02(const std::vector & files, bus *const b, std::atomic_bool *const disk_read_activity, std::atomic_bool *const disk_write_activity) : b(b), - disk_read_activity (disk_read_activity), + disk_read_activity (disk_read_activity ), disk_write_activity(disk_write_activity) { fhs = files;