aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hw/pckbd.c1
-rw-r--r--hw/ps2.c34
-rw-r--r--vl.h1
3 files changed, 35 insertions, 1 deletions
diff --git a/hw/pckbd.c b/hw/pckbd.c
index 61f8a63a82..7d0f49b762 100644
--- a/hw/pckbd.c
+++ b/hw/pckbd.c
@@ -295,6 +295,7 @@ void kbd_write_data(void *opaque, uint32_t addr, uint32_t val)
break;
case KBD_CCMD_WRITE_MODE:
s->mode = val;
+ ps2_keyboard_set_translation(s->kbd, (s->mode & KBD_MODE_KCC) != 0);
/* ??? */
kbd_update_irq(s);
break;
diff --git a/hw/ps2.c b/hw/ps2.c
index e7c66f648f..be6b31ce7c 100644
--- a/hw/ps2.c
+++ b/hw/ps2.c
@@ -83,6 +83,10 @@ typedef struct {
typedef struct {
PS2State common;
int scan_enabled;
+ /* Qemu uses translated PC scancodes internally. To avoid multiple
+ conversions we do the translation (if any) in the PS/2 emulation
+ not the keyboard controller. */
+ int translate;
} PS2KbdState;
typedef struct {
@@ -99,6 +103,18 @@ typedef struct {
uint8_t mouse_buttons;
} PS2MouseState;
+/* Table to convert from PC scancodes to raw scancodes. */
+static const unsigned char ps2_raw_keycode[128] = {
+ 0,118, 22, 30, 38, 37, 46, 54, 61, 62, 70, 69, 78, 85,102, 13,
+ 21, 29, 36, 45, 44, 53, 60, 67, 68, 77, 84, 91, 90, 20, 28, 27,
+ 35, 43, 52, 51, 59, 66, 75, 76, 82, 14, 18, 93, 26, 34, 33, 42,
+ 50, 49, 58, 65, 73, 74, 89,124, 17, 41, 88, 5, 6, 4, 12, 3,
+ 11, 2, 10, 1, 9,119,126,108,117,125,123,107,115,116,121,105,
+ 114,122,112,113,127, 96, 97,120, 7, 15, 23, 31, 39, 47, 55, 63,
+ 71, 79, 86, 94, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 87,111,
+ 19, 25, 57, 81, 83, 92, 95, 98, 99,100,101,103,104,106,109,110
+};
+
void ps2_queue(void *opaque, int b)
{
PS2State *s = (PS2State *)opaque;
@@ -115,7 +131,13 @@ void ps2_queue(void *opaque, int b)
static void ps2_put_keycode(void *opaque, int keycode)
{
- PS2MouseState *s = opaque;
+ PS2KbdState *s = opaque;
+ if (!s->translate && keycode < 0xe0)
+ {
+ if (keycode & 0x80)
+ ps2_queue(&s->common, 0xf0);
+ keycode = ps2_raw_keycode[keycode & 0x7f];
+ }
ps2_queue(&s->common, keycode);
}
@@ -214,6 +236,16 @@ void ps2_write_keyboard(void *opaque, int val)
}
}
+/* Set the scancode translation mode.
+ 0 = raw scancodes.
+ 1 = translated scancodes (used by qemu internally). */
+
+void ps2_keyboard_set_translation(void *opaque, int mode)
+{
+ PS2KbdState *s = (PS2KbdState *)opaque;
+ s->translate = mode;
+}
+
static void ps2_mouse_send_packet(PS2MouseState *s)
{
unsigned int b;
diff --git a/vl.h b/vl.h
index 5e56ee4225..4d215e7dd6 100644
--- a/vl.h
+++ b/vl.h
@@ -969,6 +969,7 @@ void ps2_write_mouse(void *, int val);
void ps2_write_keyboard(void *, int val);
uint32_t ps2_read_data(void *);
void ps2_queue(void *, int b);
+void ps2_keyboard_set_translation(void *opaque, int mode);
/* smc91c111.c */
void smc91c111_init(NICInfo *, uint32_t, void *, int);