<malloc.h> is not ISO C, <stdlib.h> is.
[wine.git] / msdos / int09.c
blob16ca67acbda7dafac8aa591dfb168ed2978f05f7
1 /*
2 * DOS interrupt 09h handler (IRQ1 - KEYBOARD)
3 */
5 #include <stdlib.h>
6 #include <string.h>
8 #include "windef.h"
9 #include "winbase.h"
10 #include "wingdi.h"
11 #include "winuser.h"
12 #include "miscemu.h"
13 #include "debugtools.h"
14 #include "dosexe.h"
16 DEFAULT_DEBUG_CHANNEL(int);
18 #define QUEUELEN 31
20 static struct
22 BYTE queuelen,queue[QUEUELEN],ascii[QUEUELEN];
23 } kbdinfo;
26 /**********************************************************************
27 * INT_Int09Handler
29 * Handler for int 09h.
31 void WINAPI INT_Int09Handler( CONTEXT86 *context )
33 BYTE ascii, scan = INT_Int09ReadScan(&ascii);
34 BYTE ch[2];
35 int cnt, c2;
37 TRACE("scan=%02x\n",scan);
38 if (!(scan & 0x80)) {
39 if (ascii) {
40 /* we already have an ASCII code, no translation necessary */
41 ch[0] = ascii;
42 cnt = 1;
43 } else {
44 #if 0 /* FIXME: cannot call USER functions here */
45 UINT vkey = MapVirtualKeyA(scan&0x7f, 1);
46 /* as in TranslateMessage, windows/input.c */
47 cnt = ToAscii(vkey, scan, QueueKeyStateTable, (LPWORD)ch, 0);
48 #else
49 cnt = 0;
50 #endif
52 if (cnt>0) {
53 for (c2=0; c2<cnt; c2++)
54 INT_Int16AddChar(ch[c2], scan);
55 } else
56 if (cnt==0) {
57 /* FIXME: need to handle things like shift-F-keys,
58 * 0xE0 extended keys, etc */
59 INT_Int16AddChar(0, scan);
62 DOSVM_PIC_ioport_out(0x20, 0x20); /* send EOI */
65 static void KbdRelay( CONTEXT86 *context, void *data )
67 if (kbdinfo.queuelen) {
68 /* cleanup operation, called from DOSVM_PIC_ioport_out:
69 * we'll remove current scancode from keyboard buffer here,
70 * rather than in ReadScan, because some DOS apps depend on
71 * the scancode being available for reading multiple times... */
72 if (--kbdinfo.queuelen) {
73 memmove(kbdinfo.queue,kbdinfo.queue+1,kbdinfo.queuelen);
74 memmove(kbdinfo.ascii,kbdinfo.ascii+1,kbdinfo.queuelen);
79 void WINAPI INT_Int09SendScan( BYTE scan, BYTE ascii )
81 if (kbdinfo.queuelen == QUEUELEN) {
82 ERR("keyboard queue overflow\n");
83 return;
85 /* add scancode to queue */
86 kbdinfo.queue[kbdinfo.queuelen] = scan;
87 kbdinfo.ascii[kbdinfo.queuelen++] = ascii;
88 /* tell app to read it by triggering IRQ 1 (int 09) */
89 DOSVM_QueueEvent(1,DOS_PRIORITY_KEYBOARD,KbdRelay,NULL);
92 BYTE WINAPI INT_Int09ReadScan( BYTE*ascii )
94 if (ascii) *ascii = kbdinfo.ascii[0];
95 return kbdinfo.queue[0];