1999-03-25 10:50:32 +00:00
|
|
|
|
/*
|
|
|
|
|
* DOS interrupt 09h handler (IRQ1 - KEYBOARD)
|
2002-03-09 23:29:33 +00:00
|
|
|
|
*
|
|
|
|
|
* Copyright 1999 Ove K<EFBFBD>ven
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-03-25 10:50:32 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
|
#include <stdarg.h>
|
1999-03-25 10:50:32 +00:00
|
|
|
|
#include <stdlib.h>
|
1999-04-01 10:01:20 +00:00
|
|
|
|
#include <string.h>
|
2000-12-19 04:53:20 +00:00
|
|
|
|
|
2000-02-10 19:03:02 +00:00
|
|
|
|
#include "windef.h"
|
2000-12-19 04:53:20 +00:00
|
|
|
|
#include "winbase.h"
|
2000-02-10 19:03:02 +00:00
|
|
|
|
#include "wingdi.h"
|
1999-03-25 10:50:32 +00:00
|
|
|
|
#include "winuser.h"
|
2002-03-09 23:29:33 +00:00
|
|
|
|
#include "wine/debug.h"
|
1999-03-25 10:50:32 +00:00
|
|
|
|
#include "dosexe.h"
|
|
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(int);
|
1999-04-19 14:56:29 +00:00
|
|
|
|
|
2000-07-31 20:58:31 +00:00
|
|
|
|
#define QUEUELEN 31
|
|
|
|
|
|
2000-09-24 20:47:50 +00:00
|
|
|
|
static struct
|
|
|
|
|
{
|
2000-07-31 20:58:31 +00:00
|
|
|
|
BYTE queuelen,queue[QUEUELEN],ascii[QUEUELEN];
|
2000-09-24 20:47:50 +00:00
|
|
|
|
} kbdinfo;
|
|
|
|
|
|
1999-03-25 10:50:32 +00:00
|
|
|
|
|
2002-10-28 23:51:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* Update the BIOS data segment's keyboard status flags (mem 0x40:0x17/0x18)
|
|
|
|
|
* if modifier/special keys have been pressed.
|
|
|
|
|
* FIXME: we merely toggle key status and don't actively set it instead,
|
|
|
|
|
* so we might be out of sync with the real current system status of these keys.
|
|
|
|
|
* Probably doesn't matter too much, though.
|
|
|
|
|
*/
|
2007-02-02 14:38:45 +00:00
|
|
|
|
static void DOSVM_Int09UpdateKbdStatusFlags(BYTE scan, BOOL extended, BIOSDATA *data, BOOL *modifier)
|
2002-10-28 23:51:27 +00:00
|
|
|
|
{
|
|
|
|
|
BYTE realscan = scan & 0x7f; /* remove 0x80 make/break flag */
|
|
|
|
|
BYTE bit1 = 255, bit2 = 255;
|
|
|
|
|
INPUT_RECORD msg;
|
|
|
|
|
DWORD res;
|
|
|
|
|
|
|
|
|
|
*modifier = TRUE;
|
|
|
|
|
|
|
|
|
|
switch (realscan)
|
|
|
|
|
{
|
|
|
|
|
case 0x36: /* r shift */
|
|
|
|
|
bit1 = 0;
|
|
|
|
|
break;
|
|
|
|
|
case 0x2a: /* l shift */
|
|
|
|
|
bit1 = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 0x1d: /* l/r control */
|
|
|
|
|
bit1 = 2;
|
|
|
|
|
if (!extended) /* left control only */
|
|
|
|
|
bit2 = 0;
|
|
|
|
|
break;
|
|
|
|
|
case 0x37: /* SysRq inner parts */
|
|
|
|
|
/* SysRq scan code sequence: 38, e0, 37, e0, b7, b8 */
|
|
|
|
|
FIXME("SysRq not handled yet.\n");
|
|
|
|
|
break;
|
|
|
|
|
case 0x38: /* l/r menu/alt, SysRq outer parts */
|
|
|
|
|
bit1 = 3;
|
|
|
|
|
if (!extended) /* left alt only */
|
|
|
|
|
bit2 = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 0x46: /* scroll lock */
|
|
|
|
|
bit1 = 4;
|
|
|
|
|
if (!extended) /* left ctrl only */
|
|
|
|
|
bit2 = 4;
|
|
|
|
|
break;
|
|
|
|
|
case 0x45: /* num lock, pause */
|
|
|
|
|
if (extended) /* distinguish from non-extended Pause key */
|
|
|
|
|
{ /* num lock */
|
|
|
|
|
bit1 = 5;
|
|
|
|
|
bit2 = 5;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ /* pause */
|
|
|
|
|
if (!(scan & 0x80)) /* "make" code */
|
|
|
|
|
bit2 = 3;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 0x3a: /* caps lock */
|
|
|
|
|
bit1 = 6;
|
|
|
|
|
bit2 = 6;
|
|
|
|
|
break;
|
|
|
|
|
case 0x52: /* insert */
|
|
|
|
|
bit1 = 7;
|
|
|
|
|
bit2 = 7;
|
|
|
|
|
*modifier = FALSE; /* insert is no modifier: thus pass to int16 */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
/* now that we know which bits to set, update them */
|
|
|
|
|
if (!(scan & 0x80)) /* "make" code (keypress) */
|
|
|
|
|
{
|
|
|
|
|
if (bit2 != 255)
|
|
|
|
|
{
|
|
|
|
|
if (bit2 == 3)
|
|
|
|
|
{
|
|
|
|
|
data->KbdFlags2 |= 1 << bit2; /* set "Pause" flag */
|
|
|
|
|
TRACE("PAUSE key, sleeping !\n");
|
|
|
|
|
/* wait for keypress to unlock pause */
|
|
|
|
|
do {
|
|
|
|
|
Sleep(55);
|
|
|
|
|
} while (!(ReadConsoleInputA(GetStdHandle(STD_INPUT_HANDLE),&msg,1,&res) && (msg.EventType == KEY_EVENT)));
|
|
|
|
|
data->KbdFlags2 &= ~(1 << bit2); /* release "Pause" flag */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
data->KbdFlags2 |= 1 << bit2;
|
|
|
|
|
}
|
|
|
|
|
if (bit1 != 255)
|
|
|
|
|
{
|
|
|
|
|
if (bit1 < 4) /* key "pressed" flag */
|
|
|
|
|
data->KbdFlags1 |= 1 << bit1;
|
|
|
|
|
else /* key "active" flag */
|
|
|
|
|
data->KbdFlags1 ^= 1 << bit1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else /* "break" / release */
|
|
|
|
|
{
|
|
|
|
|
if (bit2 != 255)
|
|
|
|
|
data->KbdFlags2 &= ~(1 << bit2);
|
|
|
|
|
if (bit1 < 4) /* is it a key "pressed" bit ? */
|
|
|
|
|
data->KbdFlags1 &= ~(1 << bit1);
|
|
|
|
|
}
|
|
|
|
|
TRACE("ext. %d, bits %d/%d, KbdFlags %02x/%02x\n", extended, bit1, bit2, data->KbdFlags1, data->KbdFlags2);
|
|
|
|
|
}
|
|
|
|
|
|
1999-03-25 10:50:32 +00:00
|
|
|
|
/**********************************************************************
|
2002-11-06 19:57:49 +00:00
|
|
|
|
* DOSVM_Int09Handler (WINEDOS16.109)
|
1999-03-25 10:50:32 +00:00
|
|
|
|
*
|
|
|
|
|
* Handler for int 09h.
|
2002-10-28 23:51:27 +00:00
|
|
|
|
* See http://www.execpc.com/~geezer/osd/kbd/ for a very good description
|
|
|
|
|
* of keyboard mapping modes.
|
1999-03-25 10:50:32 +00:00
|
|
|
|
*/
|
2001-12-04 19:54:44 +00:00
|
|
|
|
void WINAPI DOSVM_Int09Handler( CONTEXT86 *context )
|
1999-03-25 10:50:32 +00:00
|
|
|
|
{
|
2003-09-30 00:22:12 +00:00
|
|
|
|
BIOSDATA *data = DOSVM_BiosData();
|
2001-12-04 19:54:44 +00:00
|
|
|
|
BYTE ascii, scan = DOSVM_Int09ReadScan(&ascii);
|
2002-10-28 23:51:27 +00:00
|
|
|
|
BYTE realscan = scan & 0x7f; /* remove 0x80 make/break flag */
|
|
|
|
|
BOOL modifier = FALSE;
|
|
|
|
|
static BOOL extended = FALSE; /* indicates start of extended key sequence */
|
1999-03-25 10:50:32 +00:00
|
|
|
|
BYTE ch[2];
|
2000-01-30 02:54:14 +00:00
|
|
|
|
int cnt, c2;
|
1999-03-25 10:50:32 +00:00
|
|
|
|
|
2002-10-28 23:51:27 +00:00
|
|
|
|
TRACE("scan=%02x, ascii=%02x[%c]\n",scan, ascii, ascii ? ascii : ' ');
|
|
|
|
|
|
|
|
|
|
if (scan == 0xe0) /* extended keycode */
|
|
|
|
|
extended = TRUE;
|
|
|
|
|
|
|
|
|
|
/* check for keys concerning keyboard status flags */
|
|
|
|
|
if ((realscan == 0x52 /* insert */)
|
|
|
|
|
|| (realscan == 0x3a /* caps lock */)
|
|
|
|
|
|| (realscan == 0x45 /* num lock (extended) or pause/break */)
|
|
|
|
|
|| (realscan == 0x46 /* scroll lock */)
|
|
|
|
|
|| (realscan == 0x2a /* l shift */)
|
|
|
|
|
|| (realscan == 0x36 /* r shift */)
|
|
|
|
|
|| (realscan == 0x37 /* SysRq */)
|
|
|
|
|
|| (realscan == 0x38 /* l/r menu/alt, SysRq */)
|
|
|
|
|
|| (realscan == 0x1d /* l/r control */))
|
|
|
|
|
DOSVM_Int09UpdateKbdStatusFlags(scan, extended, data, &modifier);
|
|
|
|
|
|
|
|
|
|
if (scan != 0xe0)
|
|
|
|
|
extended = FALSE; /* reset extended flag now */
|
|
|
|
|
|
|
|
|
|
/* only interested in "make" (press) codes, not "break" (release),
|
|
|
|
|
* and also not in "modifier key only" (w/o ascii) notifications */
|
|
|
|
|
if (!(scan & 0x80) && !(modifier && !ascii))
|
|
|
|
|
{
|
2000-07-29 11:30:28 +00:00
|
|
|
|
if (ascii) {
|
|
|
|
|
/* we already have an ASCII code, no translation necessary */
|
2002-10-28 23:51:27 +00:00
|
|
|
|
if (data->KbdFlags1 & 8) /* Alt key ? */
|
|
|
|
|
ch[0] = 0; /* ASCII code needs to be 0 if Alt also pressed */
|
|
|
|
|
else
|
|
|
|
|
ch[0] = ascii;
|
|
|
|
|
/* FIXME: need to handle things such as Shift-F1 etc. */
|
2000-07-29 11:30:28 +00:00
|
|
|
|
cnt = 1;
|
|
|
|
|
} else {
|
2002-10-28 23:51:27 +00:00
|
|
|
|
/* translate */
|
2000-08-03 22:22:42 +00:00
|
|
|
|
UINT vkey = MapVirtualKeyA(scan&0x7f, 1);
|
2001-11-08 17:06:40 +00:00
|
|
|
|
BYTE keystate[256];
|
|
|
|
|
GetKeyboardState(keystate);
|
|
|
|
|
cnt = ToAscii(vkey, scan, keystate, (LPWORD)ch, 0);
|
2000-07-29 11:30:28 +00:00
|
|
|
|
}
|
2000-01-30 02:54:14 +00:00
|
|
|
|
if (cnt>0) {
|
|
|
|
|
for (c2=0; c2<cnt; c2++)
|
2001-12-04 19:54:44 +00:00
|
|
|
|
DOSVM_Int16AddChar(ch[c2], scan);
|
2000-01-30 02:54:14 +00:00
|
|
|
|
} else
|
|
|
|
|
if (cnt==0) {
|
2000-02-03 00:47:01 +00:00
|
|
|
|
/* FIXME: need to handle things like shift-F-keys,
|
|
|
|
|
* 0xE0 extended keys, etc */
|
2001-12-04 19:54:44 +00:00
|
|
|
|
DOSVM_Int16AddChar(0, scan);
|
1999-03-25 10:50:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-06-23 03:35:51 +00:00
|
|
|
|
|
|
|
|
|
DOSVM_AcknowledgeIRQ( context );
|
1999-03-25 10:50:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-09-24 20:47:50 +00:00
|
|
|
|
static void KbdRelay( CONTEXT86 *context, void *data )
|
1999-03-25 10:50:32 +00:00
|
|
|
|
{
|
2000-09-24 20:47:50 +00:00
|
|
|
|
if (kbdinfo.queuelen) {
|
2001-12-04 19:54:44 +00:00
|
|
|
|
/* cleanup operation, called from DOSVM_PIC_ioport_out:
|
1999-03-25 10:50:32 +00:00
|
|
|
|
* 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 20:47:50 +00:00
|
|
|
|
if (--kbdinfo.queuelen) {
|
|
|
|
|
memmove(kbdinfo.queue,kbdinfo.queue+1,kbdinfo.queuelen);
|
|
|
|
|
memmove(kbdinfo.ascii,kbdinfo.ascii+1,kbdinfo.queuelen);
|
2000-07-29 11:30:28 +00:00
|
|
|
|
}
|
1999-03-25 10:50:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-04 19:54:44 +00:00
|
|
|
|
void WINAPI DOSVM_Int09SendScan( BYTE scan, BYTE ascii )
|
1999-03-25 10:50:32 +00:00
|
|
|
|
{
|
2000-09-24 20:47:50 +00:00
|
|
|
|
if (kbdinfo.queuelen == QUEUELEN) {
|
2000-07-31 20:58:31 +00:00
|
|
|
|
ERR("keyboard queue overflow\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
1999-03-25 10:50:32 +00:00
|
|
|
|
/* add scancode to queue */
|
2000-09-24 20:47:50 +00:00
|
|
|
|
kbdinfo.queue[kbdinfo.queuelen] = scan;
|
|
|
|
|
kbdinfo.ascii[kbdinfo.queuelen++] = ascii;
|
1999-03-25 10:50:32 +00:00
|
|
|
|
/* tell app to read it by triggering IRQ 1 (int 09) */
|
2001-12-04 19:54:44 +00:00
|
|
|
|
DOSVM_QueueEvent(1,DOS_PRIORITY_KEYBOARD,KbdRelay,NULL);
|
1999-03-25 10:50:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-20 18:55:39 +00:00
|
|
|
|
/**********************************************************************
|
|
|
|
|
* KbdReadScan (WINEDOS.@)
|
|
|
|
|
*/
|
2001-12-04 19:54:44 +00:00
|
|
|
|
BYTE WINAPI DOSVM_Int09ReadScan( BYTE*ascii )
|
1999-03-25 10:50:32 +00:00
|
|
|
|
{
|
2000-09-24 20:47:50 +00:00
|
|
|
|
if (ascii) *ascii = kbdinfo.ascii[0];
|
|
|
|
|
return kbdinfo.queue[0];
|
1999-03-25 10:50:32 +00:00
|
|
|
|
}
|