Use correct linear pointer when accessing BIOS data area.
[wine/multimedia.git] / dlls / winedos / int16.c
blobd68384299ae2685f6f050aee362f946e6e0703cc
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"
36 #include "miscemu.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(int);
40 /**********************************************************************
41 * DOSVM_Int16Handler (WINEDOS16.122)
43 * Handler for int 16h (keyboard)
45 * NOTE:
47 * KEYB.COM (DOS >3.2) adds functions to this interrupt, they are
48 * not currently listed here.
51 void WINAPI DOSVM_Int16Handler( CONTEXT86 *context )
53 BIOSDATA *data = NULL;
54 BYTE ascii, scan;
56 switch AH_reg(context) {
58 case 0x00: /* Get Keystroke */
59 /* Returns: AH = Scan code
60 AL = ASCII character */
61 TRACE("Get Keystroke\n");
62 DOSVM_Int16ReadChar(&ascii, &scan, context);
63 SET_AL( context, ascii );
64 SET_AH( context, scan );
65 break;
67 case 0x01: /* Check for Keystroke */
68 /* Returns: ZF set if no keystroke */
69 /* AH = Scan code */
70 /* AL = ASCII character */
71 TRACE("Check for Keystroke\n");
72 if (!DOSVM_Int16ReadChar(&ascii, &scan, NULL))
74 SET_ZFLAG(context);
76 else
78 SET_AL( context, ascii );
79 SET_AH( context, scan );
80 RESET_ZFLAG(context);
82 /* don't miss the opportunity to break some tight timing loop in DOS
83 * programs causing 100% CPU usage (by doing a Sleep here) */
84 Sleep(5);
85 break;
87 case 0x02: /* Get Shift Flags */
89 /* read value from BIOS data segment's keyboard status flags field */
90 data = DOSVM_BiosData();
91 SET_AL( context, data->KbdFlags1 );
93 TRACE("Get Shift Flags: returning 0x%02x\n", AL_reg(context));
94 break;
96 case 0x03: /* Set Typematic Rate and Delay */
97 FIXME("Set Typematic Rate and Delay - Not Supported\n");
98 break;
100 case 0x09: /* Get Keyboard Functionality */
101 FIXME("Get Keyboard Functionality - Not Supported\n");
102 /* As a temporary measure, say that "nothing" is supported... */
103 SET_AL( context, 0 );
104 break;
106 case 0x0a: /* Get Keyboard ID */
107 FIXME("Get Keyboard ID - Not Supported\n");
108 break;
110 case 0x10: /* Get Enhanced Keystroke */
111 TRACE("Get Enhanced Keystroke - Partially supported\n");
112 /* Returns: AH = Scan code
113 AL = ASCII character */
114 DOSVM_Int16ReadChar(&ascii, &scan, context);
115 SET_AL( context, ascii );
116 SET_AH( context, scan );
117 break;
120 case 0x11: /* Check for Enhanced Keystroke */
121 /* Returns: ZF set if no keystroke */
122 /* AH = Scan code */
123 /* AL = ASCII character */
124 TRACE("Check for Enhanced Keystroke - Partially supported\n");
125 if (!DOSVM_Int16ReadChar(&ascii, &scan, NULL))
127 SET_ZFLAG(context);
129 else
131 SET_AL( context, ascii );
132 SET_AH( context, scan );
133 RESET_ZFLAG(context);
135 break;
137 case 0x12: /* Get Extended Shift States */
138 FIXME("Get Extended Shift States - Not Supported\n");
139 break;
141 default:
142 FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context));
143 break;
148 /**********************************************************************
149 * DOSVM_Int16ReadChar
151 * Either peek into keyboard buffer or wait for next keystroke.
153 * If waitctx is NULL, return TRUE if buffer had keystrokes and
154 * FALSE if buffer is empty. Returned keystroke will be left into buffer.
156 * If waitctx is non-NULL, wait until keystrokes are available.
157 * Return value will always be TRUE and returned keystroke will be
158 * removed from buffer.
160 int WINAPI DOSVM_Int16ReadChar(BYTE *ascii, BYTE *scan, CONTEXT86 *waitctx)
162 BIOSDATA *data = DOSVM_BiosData();
163 WORD CurOfs = data->NextKbdCharPtr;
165 /* check if there's data in buffer */
166 if (waitctx)
168 /* wait until input is available... */
169 while (CurOfs == data->FirstKbdCharPtr)
170 DOSVM_Wait( waitctx );
172 else
174 if (CurOfs == data->FirstKbdCharPtr)
175 return FALSE;
178 /* read from keyboard queue */
179 TRACE( "(%p,%p,%p) -> %02x %02x\n", ascii, scan, waitctx,
180 ((BYTE*)data)[CurOfs], ((BYTE*)data)[CurOfs+1] );
182 if (ascii) *ascii = ((BYTE*)data)[CurOfs];
183 if (scan) *scan = ((BYTE*)data)[CurOfs+1];
185 if (waitctx)
187 CurOfs += 2;
188 if (CurOfs >= data->KbdBufferEnd) CurOfs = data->KbdBufferStart;
189 data->NextKbdCharPtr = CurOfs;
192 return TRUE;
195 int WINAPI DOSVM_Int16AddChar(BYTE ascii,BYTE scan)
197 BIOSDATA *data = DOSVM_BiosData();
198 WORD CurOfs = data->FirstKbdCharPtr;
199 WORD NextOfs = CurOfs + 2;
201 TRACE("(%02x,%02x)\n",ascii,scan);
202 if (NextOfs >= data->KbdBufferEnd) NextOfs = data->KbdBufferStart;
203 /* check if buffer is full */
204 if (NextOfs == data->NextKbdCharPtr) return 0;
206 /* okay, insert character in ring buffer */
207 ((BYTE*)data)[CurOfs] = ascii;
208 ((BYTE*)data)[CurOfs+1] = scan;
210 data->FirstKbdCharPtr = NextOfs;
211 return 1;