2 * DOS interrupt 09h handler (IRQ1 - KEYBOARD)
11 #include "debugtools.h"
14 DEFAULT_DEBUG_CHANNEL(int);
19 BYTE queuelen
,queue
[QUEUELEN
],ascii
[QUEUELEN
];
22 /**********************************************************************
25 * Handler for int 09h.
27 void WINAPI
INT_Int09Handler( CONTEXT86
*context
)
29 BYTE ascii
, scan
= INT_Int09ReadScan(&ascii
);
33 TRACE("scan=%02x\n",scan
);
36 /* we already have an ASCII code, no translation necessary */
40 #if 0 /* FIXME: cannot call USER functions here */
41 UINT vkey
= MapVirtualKeyA(scan
&0x7f, 1);
42 /* as in TranslateMessage, windows/input.c */
43 cnt
= ToAscii(vkey
, scan
, QueueKeyStateTable
, (LPWORD
)ch
, 0);
49 for (c2
=0; c2
<cnt
; c2
++)
50 INT_Int16AddChar(ch
[c2
], scan
);
53 /* FIXME: need to handle things like shift-F-keys,
54 * 0xE0 extended keys, etc */
55 INT_Int16AddChar(0, scan
);
58 DOSVM_PIC_ioport_out(0x20, 0x20); /* send EOI */
61 static void KbdRelay( LPDOSTASK lpDosTask
, CONTEXT86
*context
, void *data
)
63 KBDSYSTEM
*sys
= (KBDSYSTEM
*)DOSVM_GetSystemData(0x09);
65 if (sys
&& sys
->queuelen
) {
66 /* cleanup operation, called from DOSVM_PIC_ioport_out:
67 * we'll remove current scancode from keyboard buffer here,
68 * rather than in ReadScan, because some DOS apps depend on
69 * the scancode being available for reading multiple times... */
70 if (--sys
->queuelen
) {
71 memmove(sys
->queue
,sys
->queue
+1,sys
->queuelen
);
72 memmove(sys
->ascii
,sys
->ascii
+1,sys
->queuelen
);
77 void WINAPI
INT_Int09SendScan( BYTE scan
, BYTE ascii
)
79 KBDSYSTEM
*sys
= (KBDSYSTEM
*)DOSVM_GetSystemData(0x09);
81 sys
= calloc(1,sizeof(KBDSYSTEM
));
82 DOSVM_SetSystemData(0x09,sys
);
84 if (sys
->queuelen
== QUEUELEN
) {
85 ERR("keyboard queue overflow\n");
88 /* add scancode to queue */
89 sys
->queue
[sys
->queuelen
] = scan
;
90 sys
->ascii
[sys
->queuelen
++] = ascii
;
91 /* tell app to read it by triggering IRQ 1 (int 09) */
92 DOSVM_QueueEvent(1,DOS_PRIORITY_KEYBOARD
,KbdRelay
,NULL
);
95 BYTE WINAPI
INT_Int09ReadScan( BYTE
*ascii
)
97 KBDSYSTEM
*sys
= (KBDSYSTEM
*)DOSVM_GetSystemData(0x09);
99 if (ascii
) *ascii
= sys
->ascii
[0];
100 return sys
->queue
[0];
102 if (ascii
) *ascii
= 0;