Removed the Release in case of error as we do not AddRef anymore.
[wine/multimedia.git] / msdos / int09.c
blob34e440d57cd0a28768dfcf55bb15db4744397b52
1 /*
2 * DOS interrupt 09h handler (IRQ1 - KEYBOARD)
3 */
5 #include <stdlib.h>
6 #include <string.h>
7 #include "windef.h"
8 #include "wingdi.h"
9 #include "winuser.h"
10 #include "miscemu.h"
11 #include "input.h"
12 #include "debugtools.h"
13 #include "dosexe.h"
15 DEFAULT_DEBUG_CHANNEL(int)
17 typedef struct {
18 BYTE queuelen,queue[15];
19 } KBDSYSTEM;
21 /**********************************************************************
22 * INT_Int09Handler
24 * Handler for int 09h.
26 void WINAPI INT_Int09Handler( CONTEXT86 *context )
28 BYTE scan = INT_Int09ReadScan();
29 UINT vkey = MapVirtualKeyA(scan&0x7f, 1);
30 BYTE ch[2];
31 int cnt, c2;
33 TRACE("scan=%02x\n",scan);
34 if (!(scan & 0x80)) {
35 /* as in TranslateMessage, windows/input.c */
36 cnt = ToAscii(vkey, scan, QueueKeyStateTable, (LPWORD)ch, 0);
37 if (cnt>0) {
38 for (c2=0; c2<cnt; c2++)
39 INT_Int16AddChar(ch[c2], scan);
40 } else
41 if (cnt==0) {
42 /* FIXME: need to handle things like shift-F-keys,
43 * 0xE0 extended keys, etc */
44 INT_Int16AddChar(0, scan);
47 DOSVM_PIC_ioport_out(0x20, 0x20); /* send EOI */
50 static void KbdRelay( LPDOSTASK lpDosTask, CONTEXT86 *context, void *data )
52 KBDSYSTEM *sys = (KBDSYSTEM *)DOSVM_GetSystemData(0x09);
54 if (sys && sys->queuelen) {
55 /* cleanup operation, called from DOSVM_PIC_ioport_out:
56 * we'll remove current scancode from keyboard buffer here,
57 * rather than in ReadScan, because some DOS apps depend on
58 * the scancode being available for reading multiple times... */
59 if (--sys->queuelen)
60 memmove(sys->queue,sys->queue+1,sys->queuelen);
64 void WINAPI INT_Int09SendScan( BYTE scan )
66 KBDSYSTEM *sys = (KBDSYSTEM *)DOSVM_GetSystemData(0x09);
67 if (!sys) {
68 sys = calloc(1,sizeof(KBDSYSTEM));
69 DOSVM_SetSystemData(0x09,sys);
71 /* add scancode to queue */
72 sys->queue[sys->queuelen++] = scan;
73 /* tell app to read it by triggering IRQ 1 (int 09) */
74 DOSVM_QueueEvent(1,DOS_PRIORITY_KEYBOARD,KbdRelay,NULL);
77 BYTE WINAPI INT_Int09ReadScan( void )
79 KBDSYSTEM *sys = (KBDSYSTEM *)DOSVM_GetSystemData(0x09);
80 if (sys)
81 return sys->queue[0];
82 else
83 return 0;