2 * DOS interrupt 16h handler
13 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(int16)
21 /**********************************************************************
24 * Handler for int 16h (keyboard)
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 CONSOLE_GetKeystroke(&AH_reg(context), &AL_reg(context));
43 case 0x01: /* Check for Keystroke */
44 /* Returns: ZF set if no keystroke */
46 /* AL = ASCII character */
47 TRACE("Check for Keystroke\n");
48 if (!CONSOLE_CheckForKeystroke(&AH_reg(context), &AL_reg(context)))
58 case 0x02: /* Get Shift Flags */
61 if (GetAsyncKeyState(VK_RSHIFT))
62 AL_reg(context) |= 0x01;
63 if (GetAsyncKeyState(VK_LSHIFT))
64 AL_reg(context) |= 0x02;
65 if (GetAsyncKeyState(VK_LCONTROL) || GetAsyncKeyState(VK_RCONTROL))
66 AL_reg(context) |= 0x04;
67 if (GetAsyncKeyState(VK_LMENU) || GetAsyncKeyState(VK_RMENU))
68 AL_reg(context) |= 0x08;
69 if (GetAsyncKeyState(VK_SCROLL))
70 AL_reg(context) |= 0x10;
71 if (GetAsyncKeyState(VK_NUMLOCK))
72 AL_reg(context) |= 0x20;
73 if (GetAsyncKeyState(VK_CAPITAL))
74 AL_reg(context) |= 0x40;
75 if (GetAsyncKeyState(VK_INSERT))
76 AL_reg(context) |= 0x80;
77 TRACE("Get Shift Flags: returning 0x%02x\n", AL_reg(context));
80 case 0x03: /* Set Typematic Rate and Delay */
81 FIXME("Set Typematic Rate and Delay - Not Supported\n");
84 case 0x09: /* Get Keyboard Functionality */
85 FIXME("Get Keyboard Functionality - Not Supported\n");
86 /* As a temporary measure, say that "nothing" is supported... */
90 case 0x0a: /* Get Keyboard ID */
91 FIXME("Get Keyboard ID - Not Supported\n");
94 case 0x10: /* Get Enhanced Keystroke */
95 TRACE("Get Enhanced Keystroke - Partially supported\n");
96 /* Returns: AH = Scan code
97 AL = ASCII character */
98 CONSOLE_GetKeystroke(&AH_reg(context), &AL_reg(context));
102 case 0x11: /* Check for Enhanced Keystroke */
103 /* Returns: ZF set if no keystroke */
105 /* AL = ASCII character */
106 TRACE("Check for Enhanced Keystroke - Partially supported\n");
107 if (!CONSOLE_CheckForKeystroke(&AH_reg(context), &AL_reg(context)))
113 RESET_ZFLAG(context);
117 case 0x12: /* Get Extended Shift States */
118 FIXME("Get Extended Shift States - Not Supported\n");
122 FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context));
128 int WINAPI INT_Int16ReadChar(BYTE*ascii,BYTE*scan,BOOL peek)
130 BIOSDATA *data = DOSMEM_BiosData();
131 WORD CurOfs = data->NextKbdCharPtr;
133 /* check if there's data in buffer */
135 if (CurOfs == data->FirstKbdCharPtr)
138 while (CurOfs == data->FirstKbdCharPtr) {
139 /* no input available yet, so wait... */
143 /* read from keyboard queue */
144 TRACE("(%p,%p,%d) -> %02x %02x\n",ascii,scan,peek,((BYTE*)data)[CurOfs],((BYTE*)data)[CurOfs+1]);
145 if (ascii) *ascii = ((BYTE*)data)[CurOfs];
146 if (scan) *scan = ((BYTE*)data)[CurOfs+1];
149 if (CurOfs >= data->KbdBufferEnd) CurOfs = data->KbdBufferStart;
150 data->NextKbdCharPtr = CurOfs;
155 int WINAPI INT_Int16AddChar(BYTE ascii,BYTE scan)
157 BIOSDATA *data = DOSMEM_BiosData();
158 WORD CurOfs = data->FirstKbdCharPtr;
159 WORD NextOfs = CurOfs + 2;
161 TRACE("(%02x,%02x)\n",ascii,scan);
162 if (NextOfs >= data->KbdBufferEnd) NextOfs = data->KbdBufferStart;
163 /* check if buffer is full */
164 if (NextOfs == data->NextKbdCharPtr) return 0;
166 /* okay, insert character in ring buffer */
167 ((BYTE*)data)[CurOfs] = ascii;
168 ((BYTE*)data)[CurOfs+1] = scan;
170 data->FirstKbdCharPtr = NextOfs;