2 * DOS interrupt 16h handler
4 * Copyright 1998 Joseph Pranevich
5 * Copyright 1999 Ove Kåven
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(int);
41 /**********************************************************************
44 * Handler for int 16h (keyboard)
48 * KEYB.COM (DOS >3.2) adds functions to this interrupt, they are
49 * not currently listed here.
52 void WINAPI DOSVM_Int16Handler( CONTEXT86 *context )
54 switch AH_reg(context) {
56 case 0x00: /* Get Keystroke */
57 /* Returns: AH = Scan code
58 AL = ASCII character */
59 TRACE("Get Keystroke\n");
60 DOSVM_Int16ReadChar(&AL_reg(context), &AH_reg(context), FALSE);
63 case 0x01: /* Check for Keystroke */
64 /* Returns: ZF set if no keystroke */
66 /* AL = ASCII character */
67 TRACE("Check for Keystroke\n");
68 if (!DOSVM_Int16ReadChar(&AL_reg(context), &AH_reg(context), TRUE))
76 /* don't miss the opportunity to break some tight timing loop in DOS
77 * programs causing 100% CPU usage (by doing a Sleep here) */
81 case 0x02: /* Get Shift Flags */
84 if (GetAsyncKeyState(VK_RSHIFT))
85 AL_reg(context) |= 0x01;
86 if (GetAsyncKeyState(VK_LSHIFT))
87 AL_reg(context) |= 0x02;
88 if (GetAsyncKeyState(VK_LCONTROL) || GetAsyncKeyState(VK_RCONTROL))
89 AL_reg(context) |= 0x04;
90 if (GetAsyncKeyState(VK_LMENU) || GetAsyncKeyState(VK_RMENU))
91 AL_reg(context) |= 0x08;
92 if (GetAsyncKeyState(VK_SCROLL))
93 AL_reg(context) |= 0x10;
94 if (GetAsyncKeyState(VK_NUMLOCK))
95 AL_reg(context) |= 0x20;
96 if (GetAsyncKeyState(VK_CAPITAL))
97 AL_reg(context) |= 0x40;
98 if (GetAsyncKeyState(VK_INSERT))
99 AL_reg(context) |= 0x80;
100 TRACE("Get Shift Flags: returning 0x%02x\n", AL_reg(context));
103 case 0x03: /* Set Typematic Rate and Delay */
104 FIXME("Set Typematic Rate and Delay - Not Supported\n");
107 case 0x09: /* Get Keyboard Functionality */
108 FIXME("Get Keyboard Functionality - Not Supported\n");
109 /* As a temporary measure, say that "nothing" is supported... */
113 case 0x0a: /* Get Keyboard ID */
114 FIXME("Get Keyboard ID - Not Supported\n");
117 case 0x10: /* Get Enhanced Keystroke */
118 TRACE("Get Enhanced Keystroke - Partially supported\n");
119 /* Returns: AH = Scan code
120 AL = ASCII character */
121 DOSVM_Int16ReadChar(&AL_reg(context), &AH_reg(context), FALSE);
125 case 0x11: /* Check for Enhanced Keystroke */
126 /* Returns: ZF set if no keystroke */
128 /* AL = ASCII character */
129 TRACE("Check for Enhanced Keystroke - Partially supported\n");
130 if (!DOSVM_Int16ReadChar(&AL_reg(context), &AH_reg(context), TRUE))
136 RESET_ZFLAG(context);
140 case 0x12: /* Get Extended Shift States */
141 FIXME("Get Extended Shift States - Not Supported\n");
145 FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context));
151 int WINAPI DOSVM_Int16ReadChar(BYTE*ascii,BYTE*scan,BOOL peek)
153 BIOSDATA *data = BIOS_DATA;
154 WORD CurOfs = data->NextKbdCharPtr;
156 /* check if there's data in buffer */
158 if (CurOfs == data->FirstKbdCharPtr)
161 while (CurOfs == data->FirstKbdCharPtr) {
162 /* no input available yet, so wait... */
166 /* read from keyboard queue */
167 TRACE("(%p,%p,%d) -> %02x %02x\n",ascii,scan,peek,((BYTE*)data)[CurOfs],((BYTE*)data)[CurOfs+1]);
168 if (ascii) *ascii = ((BYTE*)data)[CurOfs];
169 if (scan) *scan = ((BYTE*)data)[CurOfs+1];
172 if (CurOfs >= data->KbdBufferEnd) CurOfs = data->KbdBufferStart;
173 data->NextKbdCharPtr = CurOfs;
178 int WINAPI DOSVM_Int16AddChar(BYTE ascii,BYTE scan)
180 BIOSDATA *data = BIOS_DATA;
181 WORD CurOfs = data->FirstKbdCharPtr;
182 WORD NextOfs = CurOfs + 2;
184 TRACE("(%02x,%02x)\n",ascii,scan);
185 if (NextOfs >= data->KbdBufferEnd) NextOfs = data->KbdBufferStart;
186 /* check if buffer is full */
187 if (NextOfs == data->NextKbdCharPtr) return 0;
189 /* okay, insert character in ring buffer */
190 ((BYTE*)data)[CurOfs] = ascii;
191 ((BYTE*)data)[CurOfs+1] = scan;
193 data->FirstKbdCharPtr = NextOfs;