From 1994e4fdb4225e09d202c988fe0eaba7ba213e5b Mon Sep 17 00:00:00 2001 From: Jared Young Date: Mon, 4 Nov 2019 03:09:57 +0000 Subject: [PATCH] input working, double chars for now(next thing to figure out), can now quite with ctrl-D --- mp-s7-src/main.cc | 1 + mp-s7-src/retro/Console.cc | 21 +++++++++++++++++++++ mp-s7-src/retro/Console.h | 1 + 3 files changed, 23 insertions(+) diff --git a/mp-s7-src/main.cc b/mp-s7-src/main.cc index 50f0c9b..9e071f0 100644 --- a/mp-s7-src/main.cc +++ b/mp-s7-src/main.cc @@ -98,6 +98,7 @@ extern "C" void gc_collect(void) { // Receive single character int mp_hal_stdin_rx_chr(void) { unsigned char c = 0; + c = retro::Console::currentInstance->ReadChar(); return c; } diff --git a/mp-s7-src/retro/Console.cc b/mp-s7-src/retro/Console.cc index bc10bf5..47d4b79 100644 --- a/mp-s7-src/retro/Console.cc +++ b/mp-s7-src/retro/Console.cc @@ -326,6 +326,27 @@ std::string Console::ReadLine() return buffer; } +char Console::ReadChar() +{ + if(!consolePort) + return 0; + + char c; + + c = WaitNextChar(); + if(!c) + { + eof = true; + return 0; + } + + if(c == '\r') + c = '\n'; + + putch(c); + return c; +} + void Console::InvalidateCursor() { if(cursorDrawn) diff --git a/mp-s7-src/retro/Console.h b/mp-s7-src/retro/Console.h index d94417c..7792e6c 100644 --- a/mp-s7-src/retro/Console.h +++ b/mp-s7-src/retro/Console.h @@ -40,6 +40,7 @@ namespace retro void write(const char *s, int n); std::string ReadLine(); + char ReadChar(); static Console *currentInstance;