kernel32: Update Italian translation.
[wine/testsucceed.git] / dlls / krnl386.exe16 / int16.c
blob47c94104c93d127cccb4508d29f077e61b287281
1 /*
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
24 #include <stdlib.h>
25 #include <string.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
30 #include "dosexe.h"
31 #include "wincon.h"
32 #include "wine/debug.h"
33 #include "windef.h"
34 #include "wingdi.h"
35 #include "winuser.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(int);
39 /**********************************************************************
40 * DOSVM_Int16Handler
42 * Handler for int 16h (keyboard)
44 * NOTE:
46 * KEYB.COM (DOS >3.2) adds functions to this interrupt, they are
47 * not currently listed here.
50 void WINAPI DOSVM_Int16Handler( CONTEXT86 *context )
52 BIOSDATA *data = NULL;
53 BYTE ascii, scan;
55 switch AH_reg(context) {
57 case 0x00: /* Get Keystroke */
58 /* Returns: AH = Scan code
59 AL = ASCII character */
60 TRACE("Get Keystroke\n");
61 DOSVM_Int16ReadChar(&ascii, &scan, context);
62 SET_AL( context, ascii );
63 SET_AH( context, scan );
64 break;
66 case 0x01: /* Check for Keystroke */
67 /* Returns: ZF set if no keystroke */
68 /* AH = Scan code */
69 /* AL = ASCII character */
70 TRACE("Check for Keystroke\n");
71 if (!DOSVM_Int16ReadChar(&ascii, &scan, NULL))
73 SET_ZFLAG(context);
75 else
77 SET_AL( context, ascii );
78 SET_AH( context, scan );
79 RESET_ZFLAG(context);
81 /* don't miss the opportunity to break some tight timing loop in DOS
82 * programs causing 100% CPU usage (by doing a Sleep here) */
83 Sleep(5);
84 break;
86 case 0x02: /* Get Shift Flags */
88 /* read value from BIOS data segment's keyboard status flags field */
89 data = DOSVM_BiosData();
90 SET_AL( context, data->KbdFlags1 );
92 TRACE("Get Shift Flags: returning 0x%02x\n", AL_reg(context));
93 break;
95 case 0x03: /* Set Typematic Rate and Delay */
96 FIXME("Set Typematic Rate and Delay - Not Supported\n");
97 break;
99 case 0x05:/*simulate Keystroke*/
100 FIXME("Simulating a keystroke is not supported yet\n");
101 break;
103 case 0x09: /* Get Keyboard Functionality */
104 FIXME("Get Keyboard Functionality - Not Supported\n");
105 /* As a temporary measure, say that "nothing" is supported... */
106 SET_AL( context, 0 );
107 break;
109 case 0x0a: /* Get Keyboard ID */
110 FIXME("Get Keyboard ID - Not Supported\n");
111 break;
113 case 0x10: /* Get Enhanced Keystroke */
114 TRACE("Get Enhanced Keystroke - Partially supported\n");
115 /* Returns: AH = Scan code
116 AL = ASCII character */
117 DOSVM_Int16ReadChar(&ascii, &scan, context);
118 SET_AL( context, ascii );
119 SET_AH( context, scan );
120 break;
123 case 0x11: /* Check for Enhanced Keystroke */
124 /* Returns: ZF set if no keystroke */
125 /* AH = Scan code */
126 /* AL = ASCII character */
127 TRACE("Check for Enhanced Keystroke - Partially supported\n");
128 if (!DOSVM_Int16ReadChar(&ascii, &scan, NULL))
130 SET_ZFLAG(context);
132 else
134 SET_AL( context, ascii );
135 SET_AH( context, scan );
136 RESET_ZFLAG(context);
138 break;
140 case 0x12: /* Get Extended Shift States */
141 FIXME("Get Extended Shift States - Not Supported\n");
142 break;
144 default:
145 FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context));
146 break;
151 /**********************************************************************
152 * DOSVM_Int16ReadChar
154 * Either peek into keyboard buffer or wait for next keystroke.
156 * If waitctx is NULL, return TRUE if buffer had keystrokes and
157 * FALSE if buffer is empty. Returned keystroke will be left into buffer.
159 * If waitctx is non-NULL, wait until keystrokes are available.
160 * Return value will always be TRUE and returned keystroke will be
161 * removed from buffer.
163 int DOSVM_Int16ReadChar(BYTE *ascii, BYTE *scan, CONTEXT86 *waitctx)
165 BIOSDATA *data = DOSVM_BiosData();
166 WORD CurOfs = data->NextKbdCharPtr;
168 /* check if there's data in buffer */
169 if (waitctx)
171 /* wait until input is available... */
172 while (CurOfs == data->FirstKbdCharPtr)
173 DOSVM_Wait( waitctx );
175 else
177 if (CurOfs == data->FirstKbdCharPtr)
178 return FALSE;
181 /* read from keyboard queue */
182 TRACE( "(%p,%p,%p) -> %02x %02x\n", ascii, scan, waitctx,
183 ((BYTE*)data)[CurOfs], ((BYTE*)data)[CurOfs+1] );
185 if (ascii) *ascii = ((BYTE*)data)[CurOfs];
186 if (scan) *scan = ((BYTE*)data)[CurOfs+1];
188 if (waitctx)
190 CurOfs += 2;
191 if (CurOfs >= data->KbdBufferEnd) CurOfs = data->KbdBufferStart;
192 data->NextKbdCharPtr = CurOfs;
195 return TRUE;
198 int DOSVM_Int16AddChar(BYTE ascii,BYTE scan)
200 BIOSDATA *data = DOSVM_BiosData();
201 WORD CurOfs = data->FirstKbdCharPtr;
202 WORD NextOfs = CurOfs + 2;
204 TRACE("(%02x,%02x)\n",ascii,scan);
205 if (NextOfs >= data->KbdBufferEnd) NextOfs = data->KbdBufferStart;
206 /* check if buffer is full */
207 if (NextOfs == data->NextKbdCharPtr) return 0;
209 /* okay, insert character in ring buffer */
210 ((BYTE*)data)[CurOfs] = ascii;
211 ((BYTE*)data)[CurOfs+1] = scan;
213 data->FirstKbdCharPtr = NextOfs;
214 return 1;