Moved all Win16 definitions out of the standard Windows headers.
[wine.git] / msdos / int16.c
blobf86be1352d0aa3466dbb265b8fb1e30d99996ac2
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 "dosexe.h"
12 #include "wincon.h"
13 #include "debugtools.h"
14 #include "windef.h"
15 #include "wingdi.h"
16 #include "winuser.h"
17 #include "miscemu.h"
19 DEFAULT_DEBUG_CHANNEL(int16)
21 /**********************************************************************
22 * INT_Int16Handler
24 * Handler for int 16h (keyboard)
26 * NOTE:
28 * KEYB.COM (DOS >3.2) adds functions to this interrupt, they are
29 * not currently listed here.
32 void WINAPI INT_Int16Handler( CONTEXT86 *context )
34 switch AH_reg(context) {
36 case 0x00: /* Get Keystroke */
37 /* Returns: AH = Scan code
38 AL = ASCII character */
39 TRACE("Get Keystroke\n");
40 INT_Int16ReadChar(&AL_reg(context), &AH_reg(context), FALSE);
41 break;
43 case 0x01: /* Check for Keystroke */
44 /* Returns: ZF set if no keystroke */
45 /* AH = Scan code */
46 /* AL = ASCII character */
47 TRACE("Check for Keystroke\n");
48 if (!INT_Int16ReadChar(&AL_reg(context), &AH_reg(context), TRUE))
50 SET_ZFLAG(context);
52 else
54 RESET_ZFLAG(context);
56 break;
58 case 0x02: /* Get Shift Flags */
59 AL_reg(context) = 0;
61 #if 0 /* FIXME: cannot call USER functions here */
62 if (GetAsyncKeyState(VK_RSHIFT))
63 AL_reg(context) |= 0x01;
64 if (GetAsyncKeyState(VK_LSHIFT))
65 AL_reg(context) |= 0x02;
66 if (GetAsyncKeyState(VK_LCONTROL) || GetAsyncKeyState(VK_RCONTROL))
67 AL_reg(context) |= 0x04;
68 if (GetAsyncKeyState(VK_LMENU) || GetAsyncKeyState(VK_RMENU))
69 AL_reg(context) |= 0x08;
70 if (GetAsyncKeyState(VK_SCROLL))
71 AL_reg(context) |= 0x10;
72 if (GetAsyncKeyState(VK_NUMLOCK))
73 AL_reg(context) |= 0x20;
74 if (GetAsyncKeyState(VK_CAPITAL))
75 AL_reg(context) |= 0x40;
76 if (GetAsyncKeyState(VK_INSERT))
77 AL_reg(context) |= 0x80;
78 #endif
79 TRACE("Get Shift Flags: returning 0x%02x\n", AL_reg(context));
80 break;
82 case 0x03: /* Set Typematic Rate and Delay */
83 FIXME("Set Typematic Rate and Delay - Not Supported\n");
84 break;
86 case 0x09: /* Get Keyboard Functionality */
87 FIXME("Get Keyboard Functionality - Not Supported\n");
88 /* As a temporary measure, say that "nothing" is supported... */
89 AL_reg(context) = 0;
90 break;
92 case 0x0a: /* Get Keyboard ID */
93 FIXME("Get Keyboard ID - Not Supported\n");
94 break;
96 case 0x10: /* Get Enhanced Keystroke */
97 TRACE("Get Enhanced Keystroke - Partially supported\n");
98 /* Returns: AH = Scan code
99 AL = ASCII character */
100 INT_Int16ReadChar(&AL_reg(context), &AH_reg(context), FALSE);
101 break;
104 case 0x11: /* Check for Enhanced Keystroke */
105 /* Returns: ZF set if no keystroke */
106 /* AH = Scan code */
107 /* AL = ASCII character */
108 TRACE("Check for Enhanced Keystroke - Partially supported\n");
109 if (!INT_Int16ReadChar(&AL_reg(context), &AH_reg(context), TRUE))
111 SET_ZFLAG(context);
113 else
115 RESET_ZFLAG(context);
117 break;
119 case 0x12: /* Get Extended Shift States */
120 FIXME("Get Extended Shift States - Not Supported\n");
121 break;
123 default:
124 FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context));
125 break;
130 int WINAPI INT_Int16ReadChar(BYTE*ascii,BYTE*scan,BOOL peek)
132 BIOSDATA *data = DOSMEM_BiosData();
133 WORD CurOfs = data->NextKbdCharPtr;
135 /* check if there's data in buffer */
136 if (peek) {
137 if (CurOfs == data->FirstKbdCharPtr)
138 return 0;
139 } else {
140 while (CurOfs == data->FirstKbdCharPtr) {
141 /* no input available yet, so wait... */
142 DOSVM_Wait( -1, 0 );
145 /* read from keyboard queue */
146 TRACE("(%p,%p,%d) -> %02x %02x\n",ascii,scan,peek,((BYTE*)data)[CurOfs],((BYTE*)data)[CurOfs+1]);
147 if (ascii) *ascii = ((BYTE*)data)[CurOfs];
148 if (scan) *scan = ((BYTE*)data)[CurOfs+1];
149 if (!peek) {
150 CurOfs += 2;
151 if (CurOfs >= data->KbdBufferEnd) CurOfs = data->KbdBufferStart;
152 data->NextKbdCharPtr = CurOfs;
154 return 1;
157 int WINAPI INT_Int16AddChar(BYTE ascii,BYTE scan)
159 BIOSDATA *data = DOSMEM_BiosData();
160 WORD CurOfs = data->FirstKbdCharPtr;
161 WORD NextOfs = CurOfs + 2;
163 TRACE("(%02x,%02x)\n",ascii,scan);
164 if (NextOfs >= data->KbdBufferEnd) NextOfs = data->KbdBufferStart;
165 /* check if buffer is full */
166 if (NextOfs == data->NextKbdCharPtr) return 0;
168 /* okay, insert character in ring buffer */
169 ((BYTE*)data)[CurOfs] = ascii;
170 ((BYTE*)data)[CurOfs+1] = scan;
172 data->FirstKbdCharPtr = NextOfs;
173 return 1;