From b3b10187033565000e62436c000042b09e2cb158 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 28 Mar 2015 16:09:49 +0200 Subject: [PATCH] Seriallogging key input support. --- include/sysdeps.h | 1 + od-win32/serial_win32.cpp | 14 ++++++++++++- od-win32/writelog.cpp | 42 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/include/sysdeps.h b/include/sysdeps.h index 394c59c0..68f4ffba 100644 --- a/include/sysdeps.h +++ b/include/sysdeps.h @@ -450,6 +450,7 @@ extern void write_log (const TCHAR *, ...); extern void write_log (const char *, ...); #endif extern void write_dlog (const TCHAR *, ...); +extern int read_log(void); extern void flush_log (void); extern TCHAR *setconsolemode (TCHAR *buffer, int maxlen); diff --git a/od-win32/serial_win32.cpp b/od-win32/serial_win32.cpp index 3a64cafe..09ae885f 100644 --- a/od-win32/serial_win32.cpp +++ b/od-win32/serial_win32.cpp @@ -165,6 +165,7 @@ static int dtr; static int serial_period_hsyncs, serial_period_hsync_counter; static int ninebit; static int lastbitcycle_active_hsyncs; +static bool gotlogwrite; static unsigned int lastbitcycle; int serdev; int seriallog = 0, log_sercon = 0; @@ -370,8 +371,10 @@ static void serdatcopy(void) serial_check_irq(); checksend(); - if (seriallog) + if (seriallog) { + gotlogwrite = true; write_log(_T("%c"), dochar(serdatshift)); + } if (serper == 372) { if (enforcermode & 2) { @@ -414,6 +417,15 @@ void serial_hsynchandler (void) extern void hsyncstuff(void); hsyncstuff(); #endif + if (seriallog && !data_in_serdatr && gotlogwrite) { + int ch = read_log(); + if (ch > 0) { + serdatr = ch | 0x100; + data_in_serdatr = 1; + serial_check_irq (); + } + } + if (lastbitcycle_active_hsyncs > 0) lastbitcycle_active_hsyncs--; if (sermap2 && sermap_enabled && !data_in_serdatr) { diff --git a/od-win32/writelog.cpp b/od-win32/writelog.cpp index a10e7bbc..b3b2b415 100644 --- a/od-win32/writelog.cpp +++ b/od-win32/writelog.cpp @@ -68,6 +68,7 @@ int console_logging = 0; static int debugger_type = -1; extern BOOL debuggerinitializing; extern int lof_store; +static int console_input_linemode = -1; int always_flush_log = 1; #define WRITE_LOG_BUF_SIZE 4096 @@ -79,6 +80,16 @@ static HWND myGetConsoleWindow (void) return GetConsoleWindow (); } +static void set_console_input_mode(int line) +{ + if (console_input_linemode < 0) + return; + if (line == console_input_linemode) + return; + SetConsoleMode (stdinput, ENABLE_PROCESSED_INPUT | ENABLE_PROCESSED_OUTPUT | (line ? (ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT) : 0)); + console_input_linemode = line; +} + static void getconsole (void) { CONSOLE_SCREEN_BUFFER_INFO csbi; @@ -86,6 +97,7 @@ static void getconsole (void) stdinput = GetStdHandle (STD_INPUT_HANDLE); stdoutput = GetStdHandle (STD_OUTPUT_HANDLE); SetConsoleMode (stdinput, ENABLE_PROCESSED_INPUT|ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT|ENABLE_PROCESSED_OUTPUT); + console_input_linemode = 1; SetConsoleCP (65001); SetConsoleOutputCP (65001); if (GetConsoleScreenBufferInfo (stdoutput, &csbi)) { @@ -218,6 +230,35 @@ void close_console (void) consoleopen = 0; } +int read_log(void) +{ +#if 0 + return -1; +#else + if (consoleopen >= 0) + return -1; + set_console_input_mode(0); + INPUT_RECORD irbuf; + DWORD numread; + for (;;) { + if (!PeekConsoleInput(stdinput, &irbuf, 1, &numread)) + return -1; + if (!numread) + return -1; + if (!ReadConsoleInput(stdinput, &irbuf, 1, &numread)) + return -1; + if (irbuf.EventType != KEY_EVENT) + continue; + if (!irbuf.Event.KeyEvent.bKeyDown) + continue; + int ch = irbuf.Event.KeyEvent.uChar.AsciiChar; + if (ch == 0) + continue; + return ch; + } +#endif +} + static void writeconsole_2 (const TCHAR *buffer) { DWORD temp; @@ -345,6 +386,7 @@ int console_get (TCHAR *out, int maxlen) { *out = 0; + set_console_input_mode(1); if (consoleopen > 0) { return console_get_gui (out, maxlen); } else if (realconsole) { -- 2.47.3