2 * DOS interrupt 16h handler
4 * Copyright 1998 Joseph Pranevich
5 * Copyright 1999 Ove Kåven
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(int);
39 /**********************************************************************
42 * Handler for int 16h (keyboard)
46 * KEYB.COM (DOS >3.2) adds functions to this interrupt, they are
47 * not currently listed here.
50 void WINAPI
DOSVM_Int16Handler( CONTEXT86
*context
)
52 switch AH_reg(context
) {
54 case 0x00: /* Get Keystroke */
55 /* Returns: AH = Scan code
56 AL = ASCII character */
57 TRACE("Get Keystroke\n");
58 DOSVM_Int16ReadChar(&AL_reg(context
), &AH_reg(context
), FALSE
);
61 case 0x01: /* Check for Keystroke */
62 /* Returns: ZF set if no keystroke */
64 /* AL = ASCII character */
65 TRACE("Check for Keystroke\n");
66 if (!DOSVM_Int16ReadChar(&AL_reg(context
), &AH_reg(context
), TRUE
))
76 case 0x02: /* Get Shift Flags */
79 if (GetAsyncKeyState(VK_RSHIFT
))
80 AL_reg(context
) |= 0x01;
81 if (GetAsyncKeyState(VK_LSHIFT
))
82 AL_reg(context
) |= 0x02;
83 if (GetAsyncKeyState(VK_LCONTROL
) || GetAsyncKeyState(VK_RCONTROL
))
84 AL_reg(context
) |= 0x04;
85 if (GetAsyncKeyState(VK_LMENU
) || GetAsyncKeyState(VK_RMENU
))
86 AL_reg(context
) |= 0x08;
87 if (GetAsyncKeyState(VK_SCROLL
))
88 AL_reg(context
) |= 0x10;
89 if (GetAsyncKeyState(VK_NUMLOCK
))
90 AL_reg(context
) |= 0x20;
91 if (GetAsyncKeyState(VK_CAPITAL
))
92 AL_reg(context
) |= 0x40;
93 if (GetAsyncKeyState(VK_INSERT
))
94 AL_reg(context
) |= 0x80;
95 TRACE("Get Shift Flags: returning 0x%02x\n", AL_reg(context
));
98 case 0x03: /* Set Typematic Rate and Delay */
99 FIXME("Set Typematic Rate and Delay - Not Supported\n");
102 case 0x09: /* Get Keyboard Functionality */
103 FIXME("Get Keyboard Functionality - Not Supported\n");
104 /* As a temporary measure, say that "nothing" is supported... */
108 case 0x0a: /* Get Keyboard ID */
109 FIXME("Get Keyboard ID - Not Supported\n");
112 case 0x10: /* Get Enhanced Keystroke */
113 TRACE("Get Enhanced Keystroke - Partially supported\n");
114 /* Returns: AH = Scan code
115 AL = ASCII character */
116 DOSVM_Int16ReadChar(&AL_reg(context
), &AH_reg(context
), FALSE
);
120 case 0x11: /* Check for Enhanced Keystroke */
121 /* Returns: ZF set if no keystroke */
123 /* AL = ASCII character */
124 TRACE("Check for Enhanced Keystroke - Partially supported\n");
125 if (!DOSVM_Int16ReadChar(&AL_reg(context
), &AH_reg(context
), TRUE
))
131 RESET_ZFLAG(context
);
135 case 0x12: /* Get Extended Shift States */
136 FIXME("Get Extended Shift States - Not Supported\n");
140 FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context
));
146 int WINAPI
DOSVM_Int16ReadChar(BYTE
*ascii
,BYTE
*scan
,BOOL peek
)
148 BIOSDATA
*data
= DOSMEM_BiosData();
149 WORD CurOfs
= data
->NextKbdCharPtr
;
151 /* check if there's data in buffer */
153 if (CurOfs
== data
->FirstKbdCharPtr
)
156 while (CurOfs
== data
->FirstKbdCharPtr
) {
157 /* no input available yet, so wait... */
161 /* read from keyboard queue */
162 TRACE("(%p,%p,%d) -> %02x %02x\n",ascii
,scan
,peek
,((BYTE
*)data
)[CurOfs
],((BYTE
*)data
)[CurOfs
+1]);
163 if (ascii
) *ascii
= ((BYTE
*)data
)[CurOfs
];
164 if (scan
) *scan
= ((BYTE
*)data
)[CurOfs
+1];
167 if (CurOfs
>= data
->KbdBufferEnd
) CurOfs
= data
->KbdBufferStart
;
168 data
->NextKbdCharPtr
= CurOfs
;
173 int WINAPI
DOSVM_Int16AddChar(BYTE ascii
,BYTE scan
)
175 BIOSDATA
*data
= DOSMEM_BiosData();
176 WORD CurOfs
= data
->FirstKbdCharPtr
;
177 WORD NextOfs
= CurOfs
+ 2;
179 TRACE("(%02x,%02x)\n",ascii
,scan
);
180 if (NextOfs
>= data
->KbdBufferEnd
) NextOfs
= data
->KbdBufferStart
;
181 /* check if buffer is full */
182 if (NextOfs
== data
->NextKbdCharPtr
) return 0;
184 /* okay, insert character in ring buffer */
185 ((BYTE
*)data
)[CurOfs
] = ascii
;
186 ((BYTE
*)data
)[CurOfs
+1] = scan
;
188 data
->FirstKbdCharPtr
= NextOfs
;