Removed unused #include of module.h.
[wine/multimedia.git] / dlls / winedos / int16.c
blob4f52a33551b1dbdb0cc495972cb515a3138dcd62
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, FALSE);
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, TRUE))
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 = BIOS_DATA;
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, FALSE);
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, TRUE))
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 int WINAPI DOSVM_Int16ReadChar(BYTE*ascii,BYTE*scan,BOOL peek)
150 BIOSDATA *data = BIOS_DATA;
151 WORD CurOfs = data->NextKbdCharPtr;
153 /* check if there's data in buffer */
154 if (peek) {
155 if (CurOfs == data->FirstKbdCharPtr)
156 return 0;
157 } else {
158 while (CurOfs == data->FirstKbdCharPtr) {
159 /* no input available yet, so wait... */
160 DOSVM_Wait( -1, 0 );
163 /* read from keyboard queue */
164 TRACE("(%p,%p,%d) -> %02x %02x\n",ascii,scan,peek,((BYTE*)data)[CurOfs],((BYTE*)data)[CurOfs+1]);
165 if (ascii) *ascii = ((BYTE*)data)[CurOfs];
166 if (scan) *scan = ((BYTE*)data)[CurOfs+1];
167 if (!peek) {
168 CurOfs += 2;
169 if (CurOfs >= data->KbdBufferEnd) CurOfs = data->KbdBufferStart;
170 data->NextKbdCharPtr = CurOfs;
172 return 1;
175 int WINAPI DOSVM_Int16AddChar(BYTE ascii,BYTE scan)
177 BIOSDATA *data = BIOS_DATA;
178 WORD CurOfs = data->FirstKbdCharPtr;
179 WORD NextOfs = CurOfs + 2;
181 TRACE("(%02x,%02x)\n",ascii,scan);
182 if (NextOfs >= data->KbdBufferEnd) NextOfs = data->KbdBufferStart;
183 /* check if buffer is full */
184 if (NextOfs == data->NextKbdCharPtr) return 0;
186 /* okay, insert character in ring buffer */
187 ((BYTE*)data)[CurOfs] = ascii;
188 ((BYTE*)data)[CurOfs+1] = scan;
190 data->FirstKbdCharPtr = NextOfs;
191 return 1;