several fixes for serialization

This commit is contained in:
folkert van heusden 2024-04-25 20:30:43 +02:00
parent 5ded69d437
commit 0a2f508e61
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
9 changed files with 32 additions and 28 deletions

View file

@ -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)

View file

@ -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();

View file

@ -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);

View file

@ -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;

View file

@ -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)

View file

@ -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;

View file

@ -26,6 +26,7 @@ disk_backend *disk_backend::deserialize(const json_t *const j)
return disk_backend_nbd::deserialize(j); return disk_backend_nbd::deserialize(j);
// should not be reached // should not be reached
assert(false);
return nullptr; return nullptr;
} }

View file

@ -507,6 +507,17 @@ 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);
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; bus *b = nullptr;
if (deserialize.empty()) { if (deserialize.empty()) {
@ -542,10 +553,6 @@ int main(int argc, char *argv[])
if (enable_bootloader) if (enable_bootloader)
setBootLoader(b, bootloader); setBootLoader(b, bootloader);
tty *tty_ = new tty(cnsl, b);
b->add_tty(tty_);
} }
else { else {
FILE *fh = fopen(deserialize.c_str(), "r"); FILE *fh = fopen(deserialize.c_str(), "r");
@ -565,6 +572,14 @@ int main(int argc, char *argv[])
json_decref(j); 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(); running = cnsl->get_running_flag();
std::atomic_bool interrupt_emulation { false }; std::atomic_bool interrupt_emulation { false };
@ -583,19 +598,6 @@ int main(int argc, char *argv[])
if (sa_set) if (sa_set)
b->getCpu()->setRegister(7, start_addr); 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)); DOLOG(info, true, "Start running at %06o", b->getCpu()->getRegister(7));
#if !defined(_WIN32) #if !defined(_WIN32)