2 * DOS interrupt 09h handler (IRQ1 - KEYBOARD)
12 #include "debugtools.h"
15 DEFAULT_DEBUG_CHANNEL(int)
20 BYTE queuelen
,queue
[QUEUELEN
],ascii
[QUEUELEN
];
23 /**********************************************************************
26 * Handler for int 09h.
28 void WINAPI
INT_Int09Handler( CONTEXT86
*context
)
30 BYTE ascii
, scan
= INT_Int09ReadScan(&ascii
);
34 TRACE("scan=%02x\n",scan
);
37 /* we already have an ASCII code, no translation necessary */
41 #if 0 /* FIXME: cannot call USER functions here */
42 UINT vkey
= MapVirtualKeyA(scan
&0x7f, 1);
43 /* as in TranslateMessage, windows/input.c */
44 cnt
= ToAscii(vkey
, scan
, QueueKeyStateTable
, (LPWORD
)ch
, 0);
50 for (c2
=0; c2
<cnt
; c2
++)
51 INT_Int16AddChar(ch
[c2
], scan
);
54 /* FIXME: need to handle things like shift-F-keys,
55 * 0xE0 extended keys, etc */
56 INT_Int16AddChar(0, scan
);
59 DOSVM_PIC_ioport_out(0x20, 0x20); /* send EOI */
62 static void KbdRelay( LPDOSTASK lpDosTask
, CONTEXT86
*context
, void *data
)
64 KBDSYSTEM
*sys
= (KBDSYSTEM
*)DOSVM_GetSystemData(0x09);
66 if (sys
&& sys
->queuelen
) {
67 /* cleanup operation, called from DOSVM_PIC_ioport_out:
68 * we'll remove current scancode from keyboard buffer here,
69 * rather than in ReadScan, because some DOS apps depend on
70 * the scancode being available for reading multiple times... */
71 if (--sys
->queuelen
) {
72 memmove(sys
->queue
,sys
->queue
+1,sys
->queuelen
);
73 memmove(sys
->ascii
,sys
->ascii
+1,sys
->queuelen
);
78 void WINAPI
INT_Int09SendScan( BYTE scan
, BYTE ascii
)
80 KBDSYSTEM
*sys
= (KBDSYSTEM
*)DOSVM_GetSystemData(0x09);
82 sys
= calloc(1,sizeof(KBDSYSTEM
));
83 DOSVM_SetSystemData(0x09,sys
);
85 if (sys
->queuelen
== QUEUELEN
) {
86 ERR("keyboard queue overflow\n");
89 /* add scancode to queue */
90 sys
->queue
[sys
->queuelen
] = scan
;
91 sys
->ascii
[sys
->queuelen
++] = ascii
;
92 /* tell app to read it by triggering IRQ 1 (int 09) */
93 DOSVM_QueueEvent(1,DOS_PRIORITY_KEYBOARD
,KbdRelay
,NULL
);
96 BYTE WINAPI
INT_Int09ReadScan( BYTE
*ascii
)
98 KBDSYSTEM
*sys
= (KBDSYSTEM
*)DOSVM_GetSystemData(0x09);
100 if (ascii
) *ascii
= sys
->ascii
[0];
101 return sys
->queue
[0];
103 if (ascii
) *ascii
= 0;