2 * DOS interrupt 09h handler (IRQ1 - KEYBOARD)
4 * Copyright 1999 Ove Kåven
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(int);
38 BYTE queuelen
,queue
[QUEUELEN
],ascii
[QUEUELEN
];
42 /**********************************************************************
45 * Handler for int 09h.
47 void WINAPI
DOSVM_Int09Handler( CONTEXT86
*context
)
49 BYTE ascii
, scan
= DOSVM_Int09ReadScan(&ascii
);
53 TRACE("scan=%02x\n",scan
);
56 /* we already have an ASCII code, no translation necessary */
60 UINT vkey
= MapVirtualKeyA(scan
&0x7f, 1);
62 GetKeyboardState(keystate
);
63 cnt
= ToAscii(vkey
, scan
, keystate
, (LPWORD
)ch
, 0);
66 for (c2
=0; c2
<cnt
; c2
++)
67 DOSVM_Int16AddChar(ch
[c2
], scan
);
70 /* FIXME: need to handle things like shift-F-keys,
71 * 0xE0 extended keys, etc */
72 DOSVM_Int16AddChar(0, scan
);
75 DOSVM_PIC_ioport_out( 0x20, 0x20 ); /* send EOI */
78 static void KbdRelay( CONTEXT86
*context
, void *data
)
80 if (kbdinfo
.queuelen
) {
81 /* cleanup operation, called from DOSVM_PIC_ioport_out:
82 * we'll remove current scancode from keyboard buffer here,
83 * rather than in ReadScan, because some DOS apps depend on
84 * the scancode being available for reading multiple times... */
85 if (--kbdinfo
.queuelen
) {
86 memmove(kbdinfo
.queue
,kbdinfo
.queue
+1,kbdinfo
.queuelen
);
87 memmove(kbdinfo
.ascii
,kbdinfo
.ascii
+1,kbdinfo
.queuelen
);
92 void WINAPI
DOSVM_Int09SendScan( BYTE scan
, BYTE ascii
)
94 if (kbdinfo
.queuelen
== QUEUELEN
) {
95 ERR("keyboard queue overflow\n");
98 /* add scancode to queue */
99 kbdinfo
.queue
[kbdinfo
.queuelen
] = scan
;
100 kbdinfo
.ascii
[kbdinfo
.queuelen
++] = ascii
;
101 /* tell app to read it by triggering IRQ 1 (int 09) */
102 DOSVM_QueueEvent(1,DOS_PRIORITY_KEYBOARD
,KbdRelay
,NULL
);
105 /**********************************************************************
106 * KbdReadScan (WINEDOS.@)
108 BYTE WINAPI
DOSVM_Int09ReadScan( BYTE
*ascii
)
110 if (ascii
) *ascii
= kbdinfo
.ascii
[0];
111 return kbdinfo
.queue
[0];