Removed some unnecessary #includes and dll dependencies.
[wine/multimedia.git] / msdos / int09.c
blobf232b8d47091a87a1b870c26538bc1110e63e183
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 "debugtools.h"
12 #include "dosexe.h"
14 DEFAULT_DEBUG_CHANNEL(int);
16 #define QUEUELEN 31
18 typedef struct {
19 BYTE queuelen,queue[QUEUELEN],ascii[QUEUELEN];
20 } KBDSYSTEM;
22 /**********************************************************************
23 * INT_Int09Handler
25 * Handler for int 09h.
27 void WINAPI INT_Int09Handler( CONTEXT86 *context )
29 BYTE ascii, scan = INT_Int09ReadScan(&ascii);
30 BYTE ch[2];
31 int cnt, c2;
33 TRACE("scan=%02x\n",scan);
34 if (!(scan & 0x80)) {
35 if (ascii) {
36 /* we already have an ASCII code, no translation necessary */
37 ch[0] = ascii;
38 cnt = 1;
39 } else {
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);
44 #else
45 cnt = 0;
46 #endif
48 if (cnt>0) {
49 for (c2=0; c2<cnt; c2++)
50 INT_Int16AddChar(ch[c2], scan);
51 } else
52 if (cnt==0) {
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);
80 if (!sys) {
81 sys = calloc(1,sizeof(KBDSYSTEM));
82 DOSVM_SetSystemData(0x09,sys);
84 if (sys->queuelen == QUEUELEN) {
85 ERR("keyboard queue overflow\n");
86 return;
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);
98 if (sys) {
99 if (ascii) *ascii = sys->ascii[0];
100 return sys->queue[0];
101 } else {
102 if (ascii) *ascii = 0;
103 return 0;