1998-10-17 11:55:07 +00:00
|
|
|
/*
|
|
|
|
* DOS interrupt 16h handler
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* Copyright 1998 Joseph Pranevich
|
2008-10-18 17:21:31 +00:00
|
|
|
* Copyright 1999 Ove Kåven
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* 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
|
1998-10-17 11:55:07 +00:00
|
|
|
*/
|
|
|
|
|
2001-10-14 16:18:52 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
1998-10-17 11:55:07 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-08-17 00:43:16 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
1998-10-17 11:55:07 +00:00
|
|
|
|
2000-07-25 12:24:53 +00:00
|
|
|
#include "dosexe.h"
|
1999-02-24 13:05:13 +00:00
|
|
|
#include "wincon.h"
|
2002-03-09 23:29:33 +00:00
|
|
|
#include "wine/debug.h"
|
2000-02-10 19:03:02 +00:00
|
|
|
#include "windef.h"
|
|
|
|
#include "wingdi.h"
|
1999-03-25 16:41:35 +00:00
|
|
|
#include "winuser.h"
|
1998-10-17 11:55:07 +00:00
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(int);
|
1999-04-19 14:56:29 +00:00
|
|
|
|
1998-10-17 11:55:07 +00:00
|
|
|
/**********************************************************************
|
2010-01-04 15:29:19 +00:00
|
|
|
* DOSVM_Int16Handler
|
1998-10-17 11:55:07 +00:00
|
|
|
*
|
|
|
|
* Handler for int 16h (keyboard)
|
|
|
|
*
|
|
|
|
* NOTE:
|
2002-05-31 23:06:46 +00:00
|
|
|
*
|
1998-10-17 11:55:07 +00:00
|
|
|
* KEYB.COM (DOS >3.2) adds functions to this interrupt, they are
|
|
|
|
* not currently listed here.
|
|
|
|
*/
|
|
|
|
|
2010-10-20 13:48:31 +00:00
|
|
|
void WINAPI DOSVM_Int16Handler( CONTEXT *context )
|
1998-10-17 11:55:07 +00:00
|
|
|
{
|
2002-10-28 23:51:27 +00:00
|
|
|
BIOSDATA *data = NULL;
|
|
|
|
BYTE ascii, scan;
|
|
|
|
|
2013-02-06 22:08:42 +00:00
|
|
|
switch (AH_reg(context)) {
|
1998-10-17 11:55:07 +00:00
|
|
|
|
|
|
|
case 0x00: /* Get Keystroke */
|
1998-12-03 16:29:56 +00:00
|
|
|
/* Returns: AH = Scan code
|
2001-12-04 19:54:44 +00:00
|
|
|
AL = ASCII character */
|
1999-06-26 19:09:08 +00:00
|
|
|
TRACE("Get Keystroke\n");
|
2003-05-02 20:12:52 +00:00
|
|
|
DOSVM_Int16ReadChar(&ascii, &scan, context);
|
2002-08-31 18:47:00 +00:00
|
|
|
SET_AL( context, ascii );
|
|
|
|
SET_AH( context, scan );
|
1998-10-17 11:55:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x01: /* Check for Keystroke */
|
1998-12-03 16:29:56 +00:00
|
|
|
/* Returns: ZF set if no keystroke */
|
|
|
|
/* AH = Scan code */
|
|
|
|
/* AL = ASCII character */
|
1999-06-26 19:09:08 +00:00
|
|
|
TRACE("Check for Keystroke\n");
|
2003-05-02 20:12:52 +00:00
|
|
|
if (!DOSVM_Int16ReadChar(&ascii, &scan, NULL))
|
1998-12-03 16:29:56 +00:00
|
|
|
{
|
|
|
|
SET_ZFLAG(context);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-08-31 18:47:00 +00:00
|
|
|
SET_AL( context, ascii );
|
|
|
|
SET_AH( context, scan );
|
1998-12-03 16:29:56 +00:00
|
|
|
RESET_ZFLAG(context);
|
|
|
|
}
|
2002-07-03 01:13:34 +00:00
|
|
|
/* don't miss the opportunity to break some tight timing loop in DOS
|
|
|
|
* programs causing 100% CPU usage (by doing a Sleep here) */
|
|
|
|
Sleep(5);
|
1998-10-17 11:55:07 +00:00
|
|
|
break;
|
|
|
|
|
2001-12-04 19:54:44 +00:00
|
|
|
case 0x02: /* Get Shift Flags */
|
1999-03-25 16:41:35 +00:00
|
|
|
|
2002-10-28 23:51:27 +00:00
|
|
|
/* read value from BIOS data segment's keyboard status flags field */
|
2003-09-30 00:22:12 +00:00
|
|
|
data = DOSVM_BiosData();
|
2002-10-28 23:51:27 +00:00
|
|
|
SET_AL( context, data->KbdFlags1 );
|
|
|
|
|
1999-06-26 19:09:08 +00:00
|
|
|
TRACE("Get Shift Flags: returning 0x%02x\n", AL_reg(context));
|
1998-10-17 11:55:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x03: /* Set Typematic Rate and Delay */
|
1999-06-26 19:09:08 +00:00
|
|
|
FIXME("Set Typematic Rate and Delay - Not Supported\n");
|
1998-10-17 11:55:07 +00:00
|
|
|
break;
|
2004-03-30 20:43:00 +00:00
|
|
|
|
|
|
|
case 0x05:/*simulate Keystroke*/
|
|
|
|
FIXME("Simulating a keystroke is not supported yet\n");
|
|
|
|
break;
|
1998-10-17 11:55:07 +00:00
|
|
|
|
|
|
|
case 0x09: /* Get Keyboard Functionality */
|
1999-06-26 19:09:08 +00:00
|
|
|
FIXME("Get Keyboard Functionality - Not Supported\n");
|
1998-10-17 11:55:07 +00:00
|
|
|
/* As a temporary measure, say that "nothing" is supported... */
|
2002-08-31 18:47:00 +00:00
|
|
|
SET_AL( context, 0 );
|
1998-10-17 11:55:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0a: /* Get Keyboard ID */
|
1999-06-26 19:09:08 +00:00
|
|
|
FIXME("Get Keyboard ID - Not Supported\n");
|
1998-10-17 11:55:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x10: /* Get Enhanced Keystroke */
|
1999-06-26 19:09:08 +00:00
|
|
|
TRACE("Get Enhanced Keystroke - Partially supported\n");
|
1999-03-17 15:29:06 +00:00
|
|
|
/* Returns: AH = Scan code
|
2001-12-04 19:54:44 +00:00
|
|
|
AL = ASCII character */
|
2003-05-02 20:12:52 +00:00
|
|
|
DOSVM_Int16ReadChar(&ascii, &scan, context);
|
2002-08-31 18:47:00 +00:00
|
|
|
SET_AL( context, ascii );
|
|
|
|
SET_AH( context, scan );
|
1998-10-17 11:55:07 +00:00
|
|
|
break;
|
2001-12-04 19:54:44 +00:00
|
|
|
|
1998-10-17 11:55:07 +00:00
|
|
|
|
|
|
|
case 0x11: /* Check for Enhanced Keystroke */
|
1999-03-17 15:29:06 +00:00
|
|
|
/* Returns: ZF set if no keystroke */
|
|
|
|
/* AH = Scan code */
|
|
|
|
/* AL = ASCII character */
|
1999-06-26 19:09:08 +00:00
|
|
|
TRACE("Check for Enhanced Keystroke - Partially supported\n");
|
2003-05-02 20:12:52 +00:00
|
|
|
if (!DOSVM_Int16ReadChar(&ascii, &scan, NULL))
|
1999-03-17 15:29:06 +00:00
|
|
|
{
|
|
|
|
SET_ZFLAG(context);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-08-31 18:47:00 +00:00
|
|
|
SET_AL( context, ascii );
|
|
|
|
SET_AH( context, scan );
|
1999-03-17 15:29:06 +00:00
|
|
|
RESET_ZFLAG(context);
|
|
|
|
}
|
1998-10-17 11:55:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x12: /* Get Extended Shift States */
|
1999-06-26 19:09:08 +00:00
|
|
|
FIXME("Get Extended Shift States - Not Supported\n");
|
1998-10-17 11:55:07 +00:00
|
|
|
break;
|
2001-12-04 19:54:44 +00:00
|
|
|
|
1998-10-17 11:55:07 +00:00
|
|
|
default:
|
2001-12-04 19:54:44 +00:00
|
|
|
FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context));
|
1998-10-17 11:55:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-02 20:12:52 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* DOSVM_Int16ReadChar
|
|
|
|
*
|
|
|
|
* Either peek into keyboard buffer or wait for next keystroke.
|
|
|
|
*
|
|
|
|
* If waitctx is NULL, return TRUE if buffer had keystrokes and
|
|
|
|
* FALSE if buffer is empty. Returned keystroke will be left into buffer.
|
|
|
|
*
|
|
|
|
* If waitctx is non-NULL, wait until keystrokes are available.
|
|
|
|
* Return value will always be TRUE and returned keystroke will be
|
|
|
|
* removed from buffer.
|
|
|
|
*/
|
2010-10-20 13:48:31 +00:00
|
|
|
int DOSVM_Int16ReadChar(BYTE *ascii, BYTE *scan, CONTEXT *waitctx)
|
2000-02-03 00:47:01 +00:00
|
|
|
{
|
2003-09-30 00:22:12 +00:00
|
|
|
BIOSDATA *data = DOSVM_BiosData();
|
2003-05-02 20:12:52 +00:00
|
|
|
WORD CurOfs = data->NextKbdCharPtr;
|
|
|
|
|
|
|
|
/* check if there's data in buffer */
|
|
|
|
if (waitctx)
|
|
|
|
{
|
|
|
|
/* wait until input is available... */
|
|
|
|
while (CurOfs == data->FirstKbdCharPtr)
|
|
|
|
DOSVM_Wait( waitctx );
|
2000-02-03 00:47:01 +00:00
|
|
|
}
|
2003-05-02 20:12:52 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (CurOfs == data->FirstKbdCharPtr)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read from keyboard queue */
|
|
|
|
TRACE( "(%p,%p,%p) -> %02x %02x\n", ascii, scan, waitctx,
|
|
|
|
((BYTE*)data)[CurOfs], ((BYTE*)data)[CurOfs+1] );
|
|
|
|
|
|
|
|
if (ascii) *ascii = ((BYTE*)data)[CurOfs];
|
|
|
|
if (scan) *scan = ((BYTE*)data)[CurOfs+1];
|
|
|
|
|
|
|
|
if (waitctx)
|
|
|
|
{
|
|
|
|
CurOfs += 2;
|
|
|
|
if (CurOfs >= data->KbdBufferEnd) CurOfs = data->KbdBufferStart;
|
|
|
|
data->NextKbdCharPtr = CurOfs;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2000-02-03 00:47:01 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 12:44:22 +00:00
|
|
|
int DOSVM_Int16AddChar(BYTE ascii,BYTE scan)
|
1999-05-22 11:27:40 +00:00
|
|
|
{
|
2003-09-30 00:22:12 +00:00
|
|
|
BIOSDATA *data = DOSVM_BiosData();
|
1999-05-22 11:27:40 +00:00
|
|
|
WORD CurOfs = data->FirstKbdCharPtr;
|
|
|
|
WORD NextOfs = CurOfs + 2;
|
|
|
|
|
2000-02-03 00:47:01 +00:00
|
|
|
TRACE("(%02x,%02x)\n",ascii,scan);
|
1999-05-22 11:27:40 +00:00
|
|
|
if (NextOfs >= data->KbdBufferEnd) NextOfs = data->KbdBufferStart;
|
|
|
|
/* check if buffer is full */
|
|
|
|
if (NextOfs == data->NextKbdCharPtr) return 0;
|
|
|
|
|
|
|
|
/* okay, insert character in ring buffer */
|
|
|
|
((BYTE*)data)[CurOfs] = ascii;
|
|
|
|
((BYTE*)data)[CurOfs+1] = scan;
|
|
|
|
|
|
|
|
data->FirstKbdCharPtr = NextOfs;
|
|
|
|
return 1;
|
|
|
|
}
|