Added configure check for sys/reg.h.
[wine/multimedia.git] / msdos / int09.c
blob380564ce89335e447992b01823578aa820fc3d86
1 /*
2 * DOS interrupt 09h handler (IRQ1 - KEYBOARD)
3 */
5 #include <stdlib.h>
6 #include <string.h>
7 #include "winuser.h"
8 #include "miscemu.h"
9 #include "input.h"
10 #include "debugtools.h"
11 #include "dosexe.h"
13 DEFAULT_DEBUG_CHANNEL(int)
15 typedef struct {
16 BYTE queuelen,queue[15];
17 } KBDSYSTEM;
19 /**********************************************************************
20 * INT_Int09Handler
22 * Handler for int 09h.
24 void WINAPI INT_Int09Handler( CONTEXT86 *context )
26 BYTE scan = INT_Int09ReadScan();
27 UINT vkey = MapVirtualKeyA(scan&0x7f, 1);
28 BYTE ch[2];
29 int cnt, c2;
31 if (!(scan & 0x80)) {
32 /* as in TranslateMessage, windows/input.c */
33 cnt = ToAscii(vkey, scan, QueueKeyStateTable, (LPWORD)ch, 0);
34 if (cnt>0) {
35 for (c2=0; c2<cnt; c2++)
36 INT_Int16AddChar(ch[c2], scan);
37 } else
38 if (cnt==0) {
39 /* need to handle things like shift-F-keys etc */
40 FIXME("DOS special key translation not implemented\n");
43 DOSVM_PIC_ioport_out(0x20, 0x20); /* send EOI */
46 static void KbdRelay( LPDOSTASK lpDosTask, CONTEXT86 *context, void *data )
48 KBDSYSTEM *sys = (KBDSYSTEM *)DOSVM_GetSystemData(0x09);
50 if (sys && sys->queuelen) {
51 /* cleanup operation, called from DOSVM_PIC_ioport_out:
52 * we'll remove current scancode from keyboard buffer here,
53 * rather than in ReadScan, because some DOS apps depend on
54 * the scancode being available for reading multiple times... */
55 if (--sys->queuelen)
56 memmove(sys->queue,sys->queue+1,sys->queuelen);
60 void WINAPI INT_Int09SendScan( BYTE scan )
62 KBDSYSTEM *sys = (KBDSYSTEM *)DOSVM_GetSystemData(0x09);
63 if (!sys) {
64 sys = calloc(1,sizeof(KBDSYSTEM));
65 DOSVM_SetSystemData(0x09,sys);
67 /* add scancode to queue */
68 sys->queue[sys->queuelen++] = scan;
69 /* tell app to read it by triggering IRQ 1 (int 09) */
70 DOSVM_QueueEvent(1,DOS_PRIORITY_KEYBOARD,KbdRelay,NULL);
73 BYTE WINAPI INT_Int09ReadScan( void )
75 KBDSYSTEM *sys = (KBDSYSTEM *)DOSVM_GetSystemData(0x09);
76 if (sys)
77 return sys->queue[0];
78 else
79 return 0;