From 8f2fd3910869936f0b40ec99443b151ae7697f29 Mon Sep 17 00:00:00 2001
From: Ove Kaaven <ovek@arcticnet.no>
Date: Sun, 14 Mar 1999 12:13:43 +0000
Subject: [PATCH] Fully implemented Direct Console Input.

---
 msdos/int21.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/msdos/int21.c b/msdos/int21.c
index d53b1616d4a..71f7c0cfa7e 100644
--- a/msdos/int21.c
+++ b/msdos/int21.c
@@ -1170,13 +1170,34 @@ void WINAPI DOS3Call( CONTEXT *context )
         break;
 
     case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
-        TRACE(int21, "Direct Console Input/Output\n");
         if (DL_reg(context) == 0xff) {
-            FIXME(int21,"Direct Console Input should not block\n");
-            AL_reg(context) = CONSOLE_GetCharacter();
-            FL_reg(context) &= ~0x40; /* clear ZF */
-        } else
+            static char scan = 0;
+            TRACE(int21, "Direct Console Input\n");
+            if (scan) {
+                /* return pending scancode */
+                AL_reg(context) = scan;
+                FL_reg(context) &= ~0x40; /* clear ZF */
+                scan = 0;
+            } else {
+                char ascii;
+                if (CONSOLE_CheckForKeystroke(&scan,&ascii)) {
+                    CONSOLE_GetKeystroke(&scan,&ascii);
+                    /* return ASCII code */
+                    AL_reg(context) = ascii;
+                    FL_reg(context) &= ~0x40; /* clear ZF */
+                    /* return scan code on next call only if ascii==0 */
+                    if (ascii) scan = 0;
+                } else {
+                    /* nothing pending, clear everything */
+                    AL_reg(context) = 0;
+                    FL_reg(context) |= 0x40; /* set ZF */
+                    scan = 0; /* just in case */
+                }
+            }
+        } else {
+            TRACE(int21, "Direct Console Output\n");
     	    CONSOLE_Write(DL_reg(context), 0, 0, 0);
+    	}
         break;
 
     case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
-- 
GitLab