Initialize 'str' in ICONTITLE_GetTitlePos.
[wine.git] / msdos / int09.c
blob9278d94ca8f37feedf026ac653a0c123ae2c7e03
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 "input.h"
12 #include "debugtools.h"
13 #include "dosexe.h"
15 DEFAULT_DEBUG_CHANNEL(int)
17 #define QUEUELEN 31
19 typedef struct {
20 BYTE queuelen,queue[QUEUELEN],ascii[QUEUELEN];
21 } KBDSYSTEM;
23 /**********************************************************************
24 * INT_Int09Handler
26 * Handler for int 09h.
28 void WINAPI INT_Int09Handler( CONTEXT86 *context )
30 BYTE ascii, scan = INT_Int09ReadScan(&ascii);
31 BYTE ch[2];
32 int cnt, c2;
34 TRACE("scan=%02x\n",scan);
35 if (!(scan & 0x80)) {
36 if (ascii) {
37 /* we already have an ASCII code, no translation necessary */
38 ch[0] = ascii;
39 cnt = 1;
40 } else {
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);
45 #else
46 cnt = 0;
47 #endif
49 if (cnt>0) {
50 for (c2=0; c2<cnt; c2++)
51 INT_Int16AddChar(ch[c2], scan);
52 } else
53 if (cnt==0) {
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);
81 if (!sys) {
82 sys = calloc(1,sizeof(KBDSYSTEM));
83 DOSVM_SetSystemData(0x09,sys);
85 if (sys->queuelen == QUEUELEN) {
86 ERR("keyboard queue overflow\n");
87 return;
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);
99 if (sys) {
100 if (ascii) *ascii = sys->ascii[0];
101 return sys->queue[0];
102 } else {
103 if (ascii) *ascii = 0;
104 return 0;