2 * DOS interrupt 16h handler
14 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(int16
);
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
INT_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 INT_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 (!INT_Int16ReadChar(&AL_reg(context
), &AH_reg(context
), TRUE
))
59 case 0x02: /* Get Shift Flags */
62 #if 0 /* FIXME: cannot call USER functions here */
63 if (GetAsyncKeyState(VK_RSHIFT
))
64 AL_reg(context
) |= 0x01;
65 if (GetAsyncKeyState(VK_LSHIFT
))
66 AL_reg(context
) |= 0x02;
67 if (GetAsyncKeyState(VK_LCONTROL
) || GetAsyncKeyState(VK_RCONTROL
))
68 AL_reg(context
) |= 0x04;
69 if (GetAsyncKeyState(VK_LMENU
) || GetAsyncKeyState(VK_RMENU
))
70 AL_reg(context
) |= 0x08;
71 if (GetAsyncKeyState(VK_SCROLL
))
72 AL_reg(context
) |= 0x10;
73 if (GetAsyncKeyState(VK_NUMLOCK
))
74 AL_reg(context
) |= 0x20;
75 if (GetAsyncKeyState(VK_CAPITAL
))
76 AL_reg(context
) |= 0x40;
77 if (GetAsyncKeyState(VK_INSERT
))
78 AL_reg(context
) |= 0x80;
80 TRACE("Get Shift Flags: returning 0x%02x\n", AL_reg(context
));
83 case 0x03: /* Set Typematic Rate and Delay */
84 FIXME("Set Typematic Rate and Delay - Not Supported\n");
87 case 0x09: /* Get Keyboard Functionality */
88 FIXME("Get Keyboard Functionality - Not Supported\n");
89 /* As a temporary measure, say that "nothing" is supported... */
93 case 0x0a: /* Get Keyboard ID */
94 FIXME("Get Keyboard ID - Not Supported\n");
97 case 0x10: /* Get Enhanced Keystroke */
98 TRACE("Get Enhanced Keystroke - Partially supported\n");
99 /* Returns: AH = Scan code
100 AL = ASCII character */
101 INT_Int16ReadChar(&AL_reg(context
), &AH_reg(context
), FALSE
);
105 case 0x11: /* Check for Enhanced Keystroke */
106 /* Returns: ZF set if no keystroke */
108 /* AL = ASCII character */
109 TRACE("Check for Enhanced Keystroke - Partially supported\n");
110 if (!INT_Int16ReadChar(&AL_reg(context
), &AH_reg(context
), TRUE
))
116 RESET_ZFLAG(context
);
120 case 0x12: /* Get Extended Shift States */
121 FIXME("Get Extended Shift States - Not Supported\n");
125 FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context
));
131 int WINAPI
INT_Int16ReadChar(BYTE
*ascii
,BYTE
*scan
,BOOL peek
)
133 BIOSDATA
*data
= DOSMEM_BiosData();
134 WORD CurOfs
= data
->NextKbdCharPtr
;
136 /* check if there's data in buffer */
138 if (CurOfs
== data
->FirstKbdCharPtr
)
141 while (CurOfs
== data
->FirstKbdCharPtr
) {
142 /* no input available yet, so wait... */
146 /* read from keyboard queue */
147 TRACE("(%p,%p,%d) -> %02x %02x\n",ascii
,scan
,peek
,((BYTE
*)data
)[CurOfs
],((BYTE
*)data
)[CurOfs
+1]);
148 if (ascii
) *ascii
= ((BYTE
*)data
)[CurOfs
];
149 if (scan
) *scan
= ((BYTE
*)data
)[CurOfs
+1];
152 if (CurOfs
>= data
->KbdBufferEnd
) CurOfs
= data
->KbdBufferStart
;
153 data
->NextKbdCharPtr
= CurOfs
;
158 int WINAPI
INT_Int16AddChar(BYTE ascii
,BYTE scan
)
160 BIOSDATA
*data
= DOSMEM_BiosData();
161 WORD CurOfs
= data
->FirstKbdCharPtr
;
162 WORD NextOfs
= CurOfs
+ 2;
164 TRACE("(%02x,%02x)\n",ascii
,scan
);
165 if (NextOfs
>= data
->KbdBufferEnd
) NextOfs
= data
->KbdBufferStart
;
166 /* check if buffer is full */
167 if (NextOfs
== data
->NextKbdCharPtr
) return 0;
169 /* okay, insert character in ring buffer */
170 ((BYTE
*)data
)[CurOfs
] = ascii
;
171 ((BYTE
*)data
)[CurOfs
+1] = scan
;
173 data
->FirstKbdCharPtr
= NextOfs
;