diff --git a/ESP32/main.ino b/ESP32/main.ino index b399d65..3b833cc 100644 --- a/ESP32/main.ino +++ b/ESP32/main.ino @@ -100,20 +100,20 @@ void delete_first_line() { void telnet_terminal(void *p) { bus *const b = reinterpret_cast(p); + tty *const tty_ = b->getTty(); Serial.println(F("telnet_terminal task started")); + if (!tty_) + Serial.println(F(" *** NO TTY ***")); + for(;;) { char c { 0 }; - xQueueReceive(b->getTerminalQueue(), &c, portMAX_DELAY); - - Serial.println(F("queue recv")); + xQueueReceive(tty_->getTerminalQueue(), &c, portMAX_DELAY); xSemaphoreTake(terminal_mutex, portMAX_DELAY); - Serial.println(F("got mutex")); - if (c == 13 || c == 10) { tx = 0; @@ -141,8 +141,6 @@ void telnet_terminal(void *p) { xSemaphoreGive(terminal_mutex); - Serial.println(F("notify task")); - xTaskNotify(wifi_task, 0, eNoAction); } } @@ -181,14 +179,17 @@ void wifi(void *p) { if (xTaskNotifyWait(0, 0, &ulNotifiedValue, 100 / portMAX_DELAY) != pdTRUE) continue; - Serial.println(F("got notification")); - xSemaphoreTake(terminal_mutex, portMAX_DELAY); - Serial.println(F("send to clients")); + std::string out = "\033[2J"; + + for(int y=0; y<25; y++) + out += format("\033[%dH", y + 1) + std::string(&terminal[y][0], 80); + + xSemaphoreGive(terminal_mutex); for(size_t i=0; i -#endif #include #include @@ -31,10 +28,6 @@ bus::bus() : c(nullptr), tm11(nullptr), rk05_(nullptr), rx02_(nullptr), tty_(nul } CPUERR = MMR2 = MMR3 = PIR = CSR = 0; - -#if defined(ESP32) - queue = xQueueCreate(10, sizeof(char)); -#endif } bus::~bus() @@ -437,25 +430,6 @@ uint16_t bus::write(const uint16_t a, const bool word_mode, uint16_t value, cons return 128; } - if (a == 0177566) { // console tty buffer register - D(fprintf(stderr, "bus::write TTY buffer %d / %c\n", value, value);) - - if (value) { -#if defined(ESP32) - char c = value & 127; - - Serial.print(c); - - if (xQueueSend(queue, &c, portMAX_DELAY) != pdTRUE) - Serial.println(F("queue fail")); -#else - printf("%c", value & 127); -#endif - } - - return 128; - } - if (a & 1) D(fprintf(stderr, "bus::writeWord: odd address UNHANDLED\n");) D(fprintf(stderr, "UNHANDLED write %o(%c): %o\n", a, word_mode ? 'B' : ' ', value);) diff --git a/bus.h b/bus.h index bd05c5e..93ffe0e 100644 --- a/bus.h +++ b/bus.h @@ -33,10 +33,6 @@ private: uint16_t MMR2 { 0 }, MMR3 { 0 }, CPUERR { 0 }, PIR { 0 }, CSR { 0 }; -#if defined(ESP32) - QueueHandle_t queue { nullptr }; -#endif - public: bus(); ~bus(); @@ -49,11 +45,9 @@ public: void add_rx02(rx02 *rx02_) { this -> rx02_ = rx02_; } void add_tty(tty *tty_) { this -> tty_ = tty_; } - cpu *getCpu() { return this -> c; } + cpu *getCpu() { return this->c; } -#if defined(ESP32) - QueueHandle_t & getTerminalQueue() { return queue; } -#endif + tty *getTty() { return this->tty_; } uint16_t read(const uint16_t a, const bool word_mode, const bool use_prev=false); uint16_t readByte(const uint16_t a) { return read(a, true); } diff --git a/tty.cpp b/tty.cpp index 6ddf819..e5c08bc 100644 --- a/tty.cpp +++ b/tty.cpp @@ -29,6 +29,13 @@ const char * const regnames[] = { tty::tty(const bool withUI) : withUI(withUI) { memset(registers, 0x00, sizeof registers); + +#if defined(ESP32) + queue = xQueueCreate(10, sizeof(char)); + + if (queue == nullptr) + Serial.println(F("Problem creating TTY queue")); +#endif } tty::~tty() @@ -103,7 +110,12 @@ void tty::writeWord(const uint16_t addr, uint16_t v) v &= 127; #if defined(ESP32) - Serial.print(char(v)); + char c = v & 127; + + Serial.print(c); + + if (xQueueSend(queue, &c, portMAX_DELAY) != pdTRUE) + Serial.println(F("queue TTY character failed")); #else FILE *tf = fopen("tty.dat", "a+"); if (tf) { diff --git a/tty.dat b/tty.dat new file mode 100644 index 0000000..4366c13 Binary files /dev/null and b/tty.dat differ diff --git a/tty.h b/tty.h index 67b3076..8826d1f 100644 --- a/tty.h +++ b/tty.h @@ -1,4 +1,4 @@ -// (C) 2018 by Folkert van Heusden +// (C) 2018-2022 by Folkert van Heusden // Released under Apache License v2.0 #pragma once @@ -22,12 +22,20 @@ private: bool testMode { false }, withUI { false }; char c { 0 }; +#if defined(ESP32) + QueueHandle_t queue { nullptr }; +#endif + public: tty(const bool withUI); virtual ~tty(); void setTest() { testMode = true; } +#if defined(ESP32) + QueueHandle_t & getTerminalQueue() { return queue; } +#endif + void sendChar(const char v); uint8_t readByte(const uint16_t addr); diff --git a/utils.cpp b/utils.cpp index de75474..8aa0edc 100644 --- a/utils.cpp +++ b/utils.cpp @@ -18,7 +18,6 @@ void setBit(uint16_t & v, const int bit, const bool vb) v |= mask; } -#if !defined(ESP32) std::string format(const char *const fmt, ...) { char *buffer = nullptr; @@ -33,7 +32,6 @@ std::string format(const char *const fmt, ...) return result; } -#endif unsigned long get_ms() { diff --git a/utils.h b/utils.h index a87b52d..8d3652b 100644 --- a/utils.h +++ b/utils.h @@ -8,7 +8,5 @@ int parity(int v); #define sign(a) ( ( (a) < 0 ) ? -1 : ( (a) > 0 ) ) -#if !defined(ESP32) std::string format(const char *const fmt, ...); -#endif unsigned long get_ms();