Delay import of user32 to allow debugging crashes in user init code.
[wine/multimedia.git] / msdos / int16.c
blobfeba5d93bf18beacc7e90716ef41a0d14e0d04b7
1 /*
2 * DOS interrupt 16h handler
3 */
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
9 #include "config.h"
10 #include "module.h"
11 #include "callback.h"
12 #include "dosexe.h"
13 #include "wincon.h"
14 #include "debugtools.h"
15 #include "windef.h"
16 #include "wingdi.h"
17 #include "winuser.h"
18 #include "miscemu.h"
20 DEFAULT_DEBUG_CHANNEL(int16);
22 /**********************************************************************
23 * INT_Int16Handler
25 * Handler for int 16h (keyboard)
27 * NOTE:
29 * KEYB.COM (DOS >3.2) adds functions to this interrupt, they are
30 * not currently listed here.
33 void WINAPI INT_Int16Handler( CONTEXT86 *context )
35 switch AH_reg(context) {
37 case 0x00: /* Get Keystroke */
38 /* Returns: AH = Scan code
39 AL = ASCII character */
40 TRACE("Get Keystroke\n");
41 INT_Int16ReadChar(&AL_reg(context), &AH_reg(context), FALSE);
42 break;
44 case 0x01: /* Check for Keystroke */
45 /* Returns: ZF set if no keystroke */
46 /* AH = Scan code */
47 /* AL = ASCII character */
48 TRACE("Check for Keystroke\n");
49 if (!INT_Int16ReadChar(&AL_reg(context), &AH_reg(context), TRUE))
51 SET_ZFLAG(context);
53 else
55 RESET_ZFLAG(context);
57 break;
59 case 0x02: /* Get Shift Flags */
60 AL_reg(context) = 0;
62 #if 0 /* FIXME: cannot call USER functions here */
63 if (GetAsyncKeyState(VK_RSHIFT))
64 AL_reg(context) |= 0x01;
65 if (GetAsyncKeyState(VK_LSHIFT))
66 AL_reg(context) |= 0x02;
67 if (GetAsyncKeyState(VK_LCONTROL) || GetAsyncKeyState(VK_RCONTROL))
68 AL_reg(context) |= 0x04;
69 if (GetAsyncKeyState(VK_LMENU) || GetAsyncKeyState(VK_RMENU))
70 AL_reg(context) |= 0x08;
71 if (GetAsyncKeyState(VK_SCROLL))
72 AL_reg(context) |= 0x10;
73 if (GetAsyncKeyState(VK_NUMLOCK))
74 AL_reg(context) |= 0x20;
75 if (GetAsyncKeyState(VK_CAPITAL))
76 AL_reg(context) |= 0x40;
77 if (GetAsyncKeyState(VK_INSERT))
78 AL_reg(context) |= 0x80;
79 #endif
80 TRACE("Get Shift Flags: returning 0x%02x\n", AL_reg(context));
81 break;
83 case 0x03: /* Set Typematic Rate and Delay */
84 FIXME("Set Typematic Rate and Delay - Not Supported\n");
85 break;
87 case 0x09: /* Get Keyboard Functionality */
88 FIXME("Get Keyboard Functionality - Not Supported\n");
89 /* As a temporary measure, say that "nothing" is supported... */
90 AL_reg(context) = 0;
91 break;
93 case 0x0a: /* Get Keyboard ID */
94 FIXME("Get Keyboard ID - Not Supported\n");
95 break;
97 case 0x10: /* Get Enhanced Keystroke */
98 TRACE("Get Enhanced Keystroke - Partially supported\n");
99 /* Returns: AH = Scan code
100 AL = ASCII character */
101 INT_Int16ReadChar(&AL_reg(context), &AH_reg(context), FALSE);
102 break;
105 case 0x11: /* Check for Enhanced Keystroke */
106 /* Returns: ZF set if no keystroke */
107 /* AH = Scan code */
108 /* AL = ASCII character */
109 TRACE("Check for Enhanced Keystroke - Partially supported\n");
110 if (!INT_Int16ReadChar(&AL_reg(context), &AH_reg(context), TRUE))
112 SET_ZFLAG(context);
114 else
116 RESET_ZFLAG(context);
118 break;
120 case 0x12: /* Get Extended Shift States */
121 FIXME("Get Extended Shift States - Not Supported\n");
122 break;
124 default:
125 FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context));
126 break;
131 int WINAPI INT_Int16ReadChar(BYTE*ascii,BYTE*scan,BOOL peek)
133 BIOSDATA *data = DOSMEM_BiosData();
134 WORD CurOfs = data->NextKbdCharPtr;
136 /* check if there's data in buffer */
137 if (peek) {
138 if (CurOfs == data->FirstKbdCharPtr)
139 return 0;
140 } else {
141 while (CurOfs == data->FirstKbdCharPtr) {
142 /* no input available yet, so wait... */
143 Dosvm.Wait( -1, 0 );
146 /* read from keyboard queue */
147 TRACE("(%p,%p,%d) -> %02x %02x\n",ascii,scan,peek,((BYTE*)data)[CurOfs],((BYTE*)data)[CurOfs+1]);
148 if (ascii) *ascii = ((BYTE*)data)[CurOfs];
149 if (scan) *scan = ((BYTE*)data)[CurOfs+1];
150 if (!peek) {
151 CurOfs += 2;
152 if (CurOfs >= data->KbdBufferEnd) CurOfs = data->KbdBufferStart;
153 data->NextKbdCharPtr = CurOfs;
155 return 1;
158 int WINAPI INT_Int16AddChar(BYTE ascii,BYTE scan)
160 BIOSDATA *data = DOSMEM_BiosData();
161 WORD CurOfs = data->FirstKbdCharPtr;
162 WORD NextOfs = CurOfs + 2;
164 TRACE("(%02x,%02x)\n",ascii,scan);
165 if (NextOfs >= data->KbdBufferEnd) NextOfs = data->KbdBufferStart;
166 /* check if buffer is full */
167 if (NextOfs == data->NextKbdCharPtr) return 0;
169 /* okay, insert character in ring buffer */
170 ((BYTE*)data)[CurOfs] = ascii;
171 ((BYTE*)data)[CurOfs+1] = scan;
173 data->FirstKbdCharPtr = NextOfs;
174 return 1;