]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Seriallogging key input support.
authorToni Wilen <twilen@winuae.net>
Sat, 28 Mar 2015 14:09:49 +0000 (16:09 +0200)
committerToni Wilen <twilen@winuae.net>
Sat, 28 Mar 2015 14:09:49 +0000 (16:09 +0200)
include/sysdeps.h
od-win32/serial_win32.cpp
od-win32/writelog.cpp

index 394c59c04bd2b8f0b8b67806431a5a84e9bac210..68f4ffbad106dc926cc7954420762c1aa3960f82 100644 (file)
@@ -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);
index 3a64cafe81764e084cdf3d5495e9a8a47b76b714..09ae885f9db200da3ff25066ec867d240b46ca6c 100644 (file)
@@ -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) {
index a10e7bbc8e841a7e5b9d38031fc199094d1b433a..b3b2b41572373e3a31622e7a3fe13c58e6989987 100644 (file)
@@ -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) {