qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Ring <stefanrin@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Fix for DOS keyboard problems
Date: Tue, 18 Aug 2009 14:02:18 +0200	[thread overview]
Message-ID: <53e878390908180502n36f1bb97kb8868a647d514d08@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1538 bytes --]

Scratching an itch for myself, I have created a patch that allows me
to use Turbo Pascal and other Turbo Vision-based programs from DOS. I
post it here in the hope that someone take a good look, and maybe,
there's even a chance of this going into mainline. I verified that it
doesn't break keyboard or mouse functionality in Win 3.11, Win 2000
and Linux X11 (from systemrescuecd 1.1.4) as well as some DOS games.
Couldn't get win98 to run, unfortunately, so no testing there.
However, there is always the chance that it might break some random
obscure stuff, and clearly I cannot test everything.

The patch basically exploits the fact that the BIOS IRQ 1 handler
always does <disable keyboard> - <read 60h> - <enable keyboard> in
this order. We just remember the last value read from port 60h outside
this disable/enable block and play it back inside. The keyboard is
still very unreliable when a keyboard driver is loaded inside DOS (I
assume that the keyboard driver completely disables the BIOS handler).
This behavior is also present without my patch, and I personally don't
care about it, so this should not be an obstacle.

I also didn't know what to do about kbd_save and kbd_load just because
I didn't dig into them to find out what they are used for. The new
member should probably be serialized there.

My ultimate hope would be to get this into VirtualBox (see ticket #58
[1]). It should be easy enough to adapt the patch to VirtualBox; I
will try to do that within the next few days.

[1] http://www.virtualbox.org/ticket/58

[-- Attachment #2: qemu-patch --]
[-- Type: application/octet-stream, Size: 1545 bytes --]

--- qemu-0.10.5.orig/hw/pckbd.c	2009-05-20 22:46:59.000000000 +0200
+++ qemu-0.10.5/hw/pckbd.c	2009-08-18 11:26:59.896195620 +0200
@@ -120,6 +120,7 @@
     uint8_t mode;
     /* Bitmask of devices with data available.  */
     uint8_t pending;
+    uint32_t held_kbd_val;
     void *kbd;
     void *mouse;
 
@@ -161,9 +162,10 @@
 {
     KBDState *s = (KBDState *)opaque;
 
-    if (level)
+    if (level) {
         s->pending |= KBD_PENDING_KBD;
-    else
+        s->held_kbd_val = (uint32_t) -1;
+    } else
         s->pending &= ~KBD_PENDING_KBD;
     kbd_update_irq(s);
 }
@@ -238,6 +240,7 @@
         break;
     case KBD_CCMD_KBD_ENABLE:
         s->mode &= ~KBD_MODE_DISABLE_KBD;
+        s->held_kbd_val = (uint32_t) -1;
         kbd_update_irq(s);
         break;
     case KBD_CCMD_READ_INPORT:
@@ -283,8 +286,15 @@
 
     if (s->pending == KBD_PENDING_AUX)
         val = ps2_read_data(s->mouse);
-    else
-        val = ps2_read_data(s->kbd);
+    else {
+        if (s->mode & KBD_MODE_DISABLE_KBD && s->held_kbd_val != (uint32_t) -1)
+            val = s->held_kbd_val;
+        else {
+            val = ps2_read_data(s->kbd);
+            if (!(s->mode & KBD_MODE_DISABLE_KBD))
+                s->held_kbd_val = val;
+        }
+    }
 
 #if defined(DEBUG_KBD)
     printf("kbd: read data=0x%02x\n", val);
@@ -339,6 +349,7 @@
 
     s->mode = KBD_MODE_KBD_INT | KBD_MODE_MOUSE_INT;
     s->status = KBD_STAT_CMD | KBD_STAT_UNLOCKED;
+    s->held_kbd_val = (uint32_t) -1;
 }
 
 static void kbd_save(QEMUFile* f, void* opaque)

                 reply	other threads:[~2009-08-18 12:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53e878390908180502n36f1bb97kb8868a647d514d08@mail.gmail.com \
    --to=stefanrin@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).