2 * DOS interrupt 16h handler
15 #include "debugtools.h"
21 DEFAULT_DEBUG_CHANNEL(int16
);
23 /**********************************************************************
26 * Handler for int 16h (keyboard)
30 * KEYB.COM (DOS >3.2) adds functions to this interrupt, they are
31 * not currently listed here.
34 void WINAPI
INT_Int16Handler( CONTEXT86
*context
)
36 switch AH_reg(context
) {
38 case 0x00: /* Get Keystroke */
39 /* Returns: AH = Scan code
40 AL = ASCII character */
41 TRACE("Get Keystroke\n");
42 INT_Int16ReadChar(&AL_reg(context
), &AH_reg(context
), FALSE
);
45 case 0x01: /* Check for Keystroke */
46 /* Returns: ZF set if no keystroke */
48 /* AL = ASCII character */
49 TRACE("Check for Keystroke\n");
50 if (!INT_Int16ReadChar(&AL_reg(context
), &AH_reg(context
), TRUE
))
60 case 0x02: /* Get Shift Flags */
63 #if 0 /* FIXME: cannot call USER functions here */
64 if (GetAsyncKeyState(VK_RSHIFT
))
65 AL_reg(context
) |= 0x01;
66 if (GetAsyncKeyState(VK_LSHIFT
))
67 AL_reg(context
) |= 0x02;
68 if (GetAsyncKeyState(VK_LCONTROL
) || GetAsyncKeyState(VK_RCONTROL
))
69 AL_reg(context
) |= 0x04;
70 if (GetAsyncKeyState(VK_LMENU
) || GetAsyncKeyState(VK_RMENU
))
71 AL_reg(context
) |= 0x08;
72 if (GetAsyncKeyState(VK_SCROLL
))
73 AL_reg(context
) |= 0x10;
74 if (GetAsyncKeyState(VK_NUMLOCK
))
75 AL_reg(context
) |= 0x20;
76 if (GetAsyncKeyState(VK_CAPITAL
))
77 AL_reg(context
) |= 0x40;
78 if (GetAsyncKeyState(VK_INSERT
))
79 AL_reg(context
) |= 0x80;
81 TRACE("Get Shift Flags: returning 0x%02x\n", AL_reg(context
));
84 case 0x03: /* Set Typematic Rate and Delay */
85 FIXME("Set Typematic Rate and Delay - Not Supported\n");
88 case 0x09: /* Get Keyboard Functionality */
89 FIXME("Get Keyboard Functionality - Not Supported\n");
90 /* As a temporary measure, say that "nothing" is supported... */
94 case 0x0a: /* Get Keyboard ID */
95 FIXME("Get Keyboard ID - Not Supported\n");
98 case 0x10: /* Get Enhanced Keystroke */
99 TRACE("Get Enhanced Keystroke - Partially supported\n");
100 /* Returns: AH = Scan code
101 AL = ASCII character */
102 INT_Int16ReadChar(&AL_reg(context
), &AH_reg(context
), FALSE
);
106 case 0x11: /* Check for Enhanced Keystroke */
107 /* Returns: ZF set if no keystroke */
109 /* AL = ASCII character */
110 TRACE("Check for Enhanced Keystroke - Partially supported\n");
111 if (!INT_Int16ReadChar(&AL_reg(context
), &AH_reg(context
), TRUE
))
117 RESET_ZFLAG(context
);
121 case 0x12: /* Get Extended Shift States */
122 FIXME("Get Extended Shift States - Not Supported\n");
126 FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context
));
132 int WINAPI
INT_Int16ReadChar(BYTE
*ascii
,BYTE
*scan
,BOOL peek
)
134 BIOSDATA
*data
= DOSMEM_BiosData();
135 WORD CurOfs
= data
->NextKbdCharPtr
;
137 /* check if there's data in buffer */
139 if (CurOfs
== data
->FirstKbdCharPtr
)
142 while (CurOfs
== data
->FirstKbdCharPtr
) {
143 /* no input available yet, so wait... */
147 /* read from keyboard queue */
148 TRACE("(%p,%p,%d) -> %02x %02x\n",ascii
,scan
,peek
,((BYTE
*)data
)[CurOfs
],((BYTE
*)data
)[CurOfs
+1]);
149 if (ascii
) *ascii
= ((BYTE
*)data
)[CurOfs
];
150 if (scan
) *scan
= ((BYTE
*)data
)[CurOfs
+1];
153 if (CurOfs
>= data
->KbdBufferEnd
) CurOfs
= data
->KbdBufferStart
;
154 data
->NextKbdCharPtr
= CurOfs
;
159 int WINAPI
INT_Int16AddChar(BYTE ascii
,BYTE scan
)
161 BIOSDATA
*data
= DOSMEM_BiosData();
162 WORD CurOfs
= data
->FirstKbdCharPtr
;
163 WORD NextOfs
= CurOfs
+ 2;
165 TRACE("(%02x,%02x)\n",ascii
,scan
);
166 if (NextOfs
>= data
->KbdBufferEnd
) NextOfs
= data
->KbdBufferStart
;
167 /* check if buffer is full */
168 if (NextOfs
== data
->NextKbdCharPtr
) return 0;
170 /* okay, insert character in ring buffer */
171 ((BYTE
*)data
)[CurOfs
] = ascii
;
172 ((BYTE
*)data
)[CurOfs
+1] = scan
;
174 data
->FirstKbdCharPtr
= NextOfs
;