From bb7f0de707c131f9a4cf0bcf431cd0338d748149 Mon Sep 17 00:00:00 2001 From: Ove Kaaven Date: Thu, 25 Mar 1999 10:50:32 +0000 Subject: [PATCH] Implemented a int 0x09 handler, and a scancode queue that simulates IRQ 1 in the dos box. --- msdos/int09.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 msdos/int09.c diff --git a/msdos/int09.c b/msdos/int09.c new file mode 100644 index 00000000000..26a77a12ce8 --- /dev/null +++ b/msdos/int09.c @@ -0,0 +1,72 @@ +/* + * DOS interrupt 09h handler (IRQ1 - KEYBOARD) + */ + +#include +#include "winuser.h" +#include "miscemu.h" +#include "input.h" +#include "debug.h" +#include "dosexe.h" + +typedef struct { + BYTE queuelen,queue[15]; +} KBDSYSTEM; + +/********************************************************************** + * INT_Int09Handler + * + * Handler for int 09h. + */ +void WINAPI INT_Int09Handler( CONTEXT *context ) +{ + BYTE scan = INT_Int09ReadScan(); + UINT vkey = MapVirtualKeyA(scan&0x7f, 1); + BYTE ch[2]; + int cnt; + + if (!(scan & 0x80)) { + /* as in TranslateMessage, windows/input.c */ + cnt = ToAscii(vkey, scan&0x7f, QueueKeyStateTable, (LPWORD)ch, 0); + if (cnt==1) { + FIXME(int,"enter character %c into console input, not implemented\n",ch[0]); + } + } + DOSVM_PIC_ioport_out(0x20, 0x20); /* send EOI */ +} + +static void KbdRelay( LPDOSTASK lpDosTask, PCONTEXT context, void *data ) +{ + KBDSYSTEM *sys = (KBDSYSTEM *)DOSVM_GetSystemData(0x09); + + if (sys && sys->queuelen) { + /* cleanup operation, called from DOSVM_PIC_ioport_out: + * we'll remove current scancode from keyboard buffer here, + * rather than in ReadScan, because some DOS apps depend on + * the scancode being available for reading multiple times... */ + if (--sys->queuelen) + memmove(sys->queue,sys->queue+1,sys->queuelen); + } +} + +void WINAPI INT_Int09SendScan( BYTE scan ) +{ + KBDSYSTEM *sys = (KBDSYSTEM *)DOSVM_GetSystemData(0x09); + if (!sys) { + sys = calloc(1,sizeof(KBDSYSTEM)); + DOSVM_SetSystemData(0x09,sys); + } + /* add scancode to queue */ + sys->queue[sys->queuelen++] = scan; + /* tell app to read it by triggering IRQ 1 (int 09) */ + DOSVM_QueueEvent(1,DOS_PRIORITY_KEYBOARD,KbdRelay,NULL); +} + +BYTE WINAPI INT_Int09ReadScan( void ) +{ + KBDSYSTEM *sys = (KBDSYSTEM *)DOSVM_GetSystemData(0x09); + if (sys) + return sys->queue[0]; + else + return 0; +}