2 * DOS interrupt 16h handler
14 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(int);
22 /**********************************************************************
25 * Handler for int 16h (keyboard)
29 * KEYB.COM (DOS >3.2) adds functions to this interrupt, they are
30 * not currently listed here.
33 void WINAPI DOSVM_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 DOSVM_Int16ReadChar(&AL_reg(context), &AH_reg(context), FALSE);
44 case 0x01: /* Check for Keystroke */
45 /* Returns: ZF set if no keystroke */
47 /* AL = ASCII character */
48 TRACE("Check for Keystroke\n");
49 if (!DOSVM_Int16ReadChar(&AL_reg(context), &AH_reg(context), TRUE))
59 case 0x02: /* Get Shift Flags */
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 TRACE("Get Shift Flags: returning 0x%02x\n", AL_reg(context));
81 case 0x03: /* Set Typematic Rate and Delay */
82 FIXME("Set Typematic Rate and Delay - Not Supported\n");
85 case 0x09: /* Get Keyboard Functionality */
86 FIXME("Get Keyboard Functionality - Not Supported\n");
87 /* As a temporary measure, say that "nothing" is supported... */
91 case 0x0a: /* Get Keyboard ID */
92 FIXME("Get Keyboard ID - Not Supported\n");
95 case 0x10: /* Get Enhanced Keystroke */
96 TRACE("Get Enhanced Keystroke - Partially supported\n");
97 /* Returns: AH = Scan code
98 AL = ASCII character */
99 DOSVM_Int16ReadChar(&AL_reg(context), &AH_reg(context), FALSE);
103 case 0x11: /* Check for Enhanced Keystroke */
104 /* Returns: ZF set if no keystroke */
106 /* AL = ASCII character */
107 TRACE("Check for Enhanced Keystroke - Partially supported\n");
108 if (!DOSVM_Int16ReadChar(&AL_reg(context), &AH_reg(context), TRUE))
114 RESET_ZFLAG(context);
118 case 0x12: /* Get Extended Shift States */
119 FIXME("Get Extended Shift States - Not Supported\n");
123 FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context));
129 int WINAPI DOSVM_Int16ReadChar(BYTE*ascii,BYTE*scan,BOOL peek)
131 BIOSDATA *data = DOSMEM_BiosData();
132 WORD CurOfs = data->NextKbdCharPtr;
134 /* check if there's data in buffer */
136 if (CurOfs == data->FirstKbdCharPtr)
139 while (CurOfs == data->FirstKbdCharPtr) {
140 /* no input available yet, so wait... */
144 /* read from keyboard queue */
145 TRACE("(%p,%p,%d) -> %02x %02x\n",ascii,scan,peek,((BYTE*)data)[CurOfs],((BYTE*)data)[CurOfs+1]);
146 if (ascii) *ascii = ((BYTE*)data)[CurOfs];
147 if (scan) *scan = ((BYTE*)data)[CurOfs+1];
150 if (CurOfs >= data->KbdBufferEnd) CurOfs = data->KbdBufferStart;
151 data->NextKbdCharPtr = CurOfs;
156 int WINAPI DOSVM_Int16AddChar(BYTE ascii,BYTE scan)
158 BIOSDATA *data = DOSMEM_BiosData();
159 WORD CurOfs = data->FirstKbdCharPtr;
160 WORD NextOfs = CurOfs + 2;
162 TRACE("(%02x,%02x)\n",ascii,scan);
163 if (NextOfs >= data->KbdBufferEnd) NextOfs = data->KbdBufferStart;
164 /* check if buffer is full */
165 if (NextOfs == data->NextKbdCharPtr) return 0;
167 /* okay, insert character in ring buffer */
168 ((BYTE*)data)[CurOfs] = ascii;
169 ((BYTE*)data)[CurOfs+1] = scan;
171 data->FirstKbdCharPtr = NextOfs;