1999-03-25 11:50:32 +01:00
|
|
|
/*
|
|
|
|
* DOS interrupt 09h handler (IRQ1 - KEYBOARD)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
1999-04-01 12:01:20 +02:00
|
|
|
#include <string.h>
|
2000-02-10 20:03:02 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "wingdi.h"
|
1999-03-25 11:50:32 +01:00
|
|
|
#include "winuser.h"
|
|
|
|
#include "miscemu.h"
|
1999-06-26 21:09:08 +02:00
|
|
|
#include "debugtools.h"
|
1999-03-25 11:50:32 +01:00
|
|
|
#include "dosexe.h"
|
|
|
|
|
2000-08-10 00:35:05 +02:00
|
|
|
DEFAULT_DEBUG_CHANNEL(int);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
2000-07-31 22:58:31 +02:00
|
|
|
#define QUEUELEN 31
|
|
|
|
|
2000-09-24 22:47:50 +02:00
|
|
|
static struct
|
|
|
|
{
|
2000-07-31 22:58:31 +02:00
|
|
|
BYTE queuelen,queue[QUEUELEN],ascii[QUEUELEN];
|
2000-09-24 22:47:50 +02:00
|
|
|
} kbdinfo;
|
|
|
|
|
1999-03-25 11:50:32 +01:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* INT_Int09Handler
|
|
|
|
*
|
|
|
|
* Handler for int 09h.
|
|
|
|
*/
|
1999-06-26 20:40:24 +02:00
|
|
|
void WINAPI INT_Int09Handler( CONTEXT86 *context )
|
1999-03-25 11:50:32 +01:00
|
|
|
{
|
2000-07-29 13:30:28 +02:00
|
|
|
BYTE ascii, scan = INT_Int09ReadScan(&ascii);
|
1999-03-25 11:50:32 +01:00
|
|
|
BYTE ch[2];
|
2000-01-30 03:54:14 +01:00
|
|
|
int cnt, c2;
|
1999-03-25 11:50:32 +01:00
|
|
|
|
2000-02-03 01:47:01 +01:00
|
|
|
TRACE("scan=%02x\n",scan);
|
1999-03-25 11:50:32 +01:00
|
|
|
if (!(scan & 0x80)) {
|
2000-07-29 13:30:28 +02:00
|
|
|
if (ascii) {
|
|
|
|
/* we already have an ASCII code, no translation necessary */
|
|
|
|
ch[0] = ascii;
|
|
|
|
cnt = 1;
|
|
|
|
} else {
|
2000-08-04 00:22:42 +02:00
|
|
|
#if 0 /* FIXME: cannot call USER functions here */
|
|
|
|
UINT vkey = MapVirtualKeyA(scan&0x7f, 1);
|
2000-07-29 13:30:28 +02:00
|
|
|
/* as in TranslateMessage, windows/input.c */
|
|
|
|
cnt = ToAscii(vkey, scan, QueueKeyStateTable, (LPWORD)ch, 0);
|
2000-08-04 00:22:42 +02:00
|
|
|
#else
|
|
|
|
cnt = 0;
|
|
|
|
#endif
|
2000-07-29 13:30:28 +02:00
|
|
|
}
|
2000-01-30 03:54:14 +01:00
|
|
|
if (cnt>0) {
|
|
|
|
for (c2=0; c2<cnt; c2++)
|
|
|
|
INT_Int16AddChar(ch[c2], scan);
|
|
|
|
} else
|
|
|
|
if (cnt==0) {
|
2000-02-03 01:47:01 +01:00
|
|
|
/* FIXME: need to handle things like shift-F-keys,
|
|
|
|
* 0xE0 extended keys, etc */
|
|
|
|
INT_Int16AddChar(0, scan);
|
1999-03-25 11:50:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
DOSVM_PIC_ioport_out(0x20, 0x20); /* send EOI */
|
|
|
|
}
|
|
|
|
|
2000-09-24 22:47:50 +02:00
|
|
|
static void KbdRelay( CONTEXT86 *context, void *data )
|
1999-03-25 11:50:32 +01:00
|
|
|
{
|
2000-09-24 22:47:50 +02:00
|
|
|
if (kbdinfo.queuelen) {
|
1999-03-25 11:50:32 +01:00
|
|
|
/* 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... */
|
2000-09-24 22:47:50 +02:00
|
|
|
if (--kbdinfo.queuelen) {
|
|
|
|
memmove(kbdinfo.queue,kbdinfo.queue+1,kbdinfo.queuelen);
|
|
|
|
memmove(kbdinfo.ascii,kbdinfo.ascii+1,kbdinfo.queuelen);
|
2000-07-29 13:30:28 +02:00
|
|
|
}
|
1999-03-25 11:50:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-29 13:30:28 +02:00
|
|
|
void WINAPI INT_Int09SendScan( BYTE scan, BYTE ascii )
|
1999-03-25 11:50:32 +01:00
|
|
|
{
|
2000-09-24 22:47:50 +02:00
|
|
|
if (kbdinfo.queuelen == QUEUELEN) {
|
2000-07-31 22:58:31 +02:00
|
|
|
ERR("keyboard queue overflow\n");
|
|
|
|
return;
|
|
|
|
}
|
1999-03-25 11:50:32 +01:00
|
|
|
/* add scancode to queue */
|
2000-09-24 22:47:50 +02:00
|
|
|
kbdinfo.queue[kbdinfo.queuelen] = scan;
|
|
|
|
kbdinfo.ascii[kbdinfo.queuelen++] = ascii;
|
1999-03-25 11:50:32 +01:00
|
|
|
/* tell app to read it by triggering IRQ 1 (int 09) */
|
|
|
|
DOSVM_QueueEvent(1,DOS_PRIORITY_KEYBOARD,KbdRelay,NULL);
|
|
|
|
}
|
|
|
|
|
2000-07-29 13:30:28 +02:00
|
|
|
BYTE WINAPI INT_Int09ReadScan( BYTE*ascii )
|
1999-03-25 11:50:32 +01:00
|
|
|
{
|
2000-09-24 22:47:50 +02:00
|
|
|
if (ascii) *ascii = kbdinfo.ascii[0];
|
|
|
|
return kbdinfo.queue[0];
|
1999-03-25 11:50:32 +01:00
|
|
|
}
|