Toolbar customization dialog (take one).
[wine.git] / msdos / int09.c
blobd11245178d416d35dc8ff780cb8f6bb5dfdda112
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 "debug.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( CONTEXT *context )
26 BYTE scan = INT_Int09ReadScan();
27 UINT vkey = MapVirtualKeyA(scan&0x7f, 1);
28 BYTE ch[2];
29 int cnt;
31 if (!(scan & 0x80)) {
32 /* as in TranslateMessage, windows/input.c */
33 cnt = ToAscii(vkey, scan&0x7f, QueueKeyStateTable, (LPWORD)ch, 0);
34 if (cnt==1) {
35 FIXME(int,"enter character %c into console input, not implemented\n",ch[0]);
38 DOSVM_PIC_ioport_out(0x20, 0x20); /* send EOI */
41 static void KbdRelay( LPDOSTASK lpDosTask, PCONTEXT context, void *data )
43 KBDSYSTEM *sys = (KBDSYSTEM *)DOSVM_GetSystemData(0x09);
45 if (sys && sys->queuelen) {
46 /* cleanup operation, called from DOSVM_PIC_ioport_out:
47 * we'll remove current scancode from keyboard buffer here,
48 * rather than in ReadScan, because some DOS apps depend on
49 * the scancode being available for reading multiple times... */
50 if (--sys->queuelen)
51 memmove(sys->queue,sys->queue+1,sys->queuelen);
55 void WINAPI INT_Int09SendScan( BYTE scan )
57 KBDSYSTEM *sys = (KBDSYSTEM *)DOSVM_GetSystemData(0x09);
58 if (!sys) {
59 sys = calloc(1,sizeof(KBDSYSTEM));
60 DOSVM_SetSystemData(0x09,sys);
62 /* add scancode to queue */
63 sys->queue[sys->queuelen++] = scan;
64 /* tell app to read it by triggering IRQ 1 (int 09) */
65 DOSVM_QueueEvent(1,DOS_PRIORITY_KEYBOARD,KbdRelay,NULL);
68 BYTE WINAPI INT_Int09ReadScan( void )
70 KBDSYSTEM *sys = (KBDSYSTEM *)DOSVM_GetSystemData(0x09);
71 if (sys)
72 return sys->queue[0];
73 else
74 return 0;