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 INT_Int16ReadChar(&AL_reg(context), &AH_reg(context), FALSE);
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 (!INT_Int16ReadChar(&AL_reg(context), &AH_reg(context), TRUE))
58 case 0x02: /* Get Shift Flags */
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;
79 TRACE("Get Shift Flags: returning 0x%02x\n", AL_reg(context));
82 case 0x03: /* Set Typematic Rate and Delay */
83 FIXME("Set Typematic Rate and Delay - Not Supported\n");
86 case 0x09: /* Get Keyboard Functionality */
87 FIXME("Get Keyboard Functionality - Not Supported\n");
88 /* As a temporary measure, say that "nothing" is supported... */
92 case 0x0a: /* Get Keyboard ID */
93 FIXME("Get Keyboard ID - Not Supported\n");
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);
104 case 0x11: /* Check for Enhanced Keystroke */
105 /* Returns: ZF set if no keystroke */
107 /* AL = ASCII character */
108 TRACE("Check for Enhanced Keystroke - Partially supported\n");
109 if (!INT_Int16ReadChar(&AL_reg(context), &AH_reg(context), TRUE))
115 RESET_ZFLAG(context);
119 case 0x12: /* Get Extended Shift States */
120 FIXME("Get Extended Shift States - Not Supported\n");
124 FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context));
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 */
137 if (CurOfs == data->FirstKbdCharPtr)
140 while (CurOfs == data->FirstKbdCharPtr) {
141 /* no input available yet, so wait... */
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];
151 if (CurOfs >= data->KbdBufferEnd) CurOfs = data->KbdBufferStart;
152 data->NextKbdCharPtr = CurOfs;
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;