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
32 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(int);
40 /**********************************************************************
41 * DOSVM_Int16Handler (WINEDOS16.122)
43 * Handler for int 16h (keyboard)
47 * KEYB.COM (DOS >3.2) adds functions to this interrupt, they are
48 * not currently listed here.
51 void WINAPI
DOSVM_Int16Handler( CONTEXT86
*context
)
53 BIOSDATA
*data
= NULL
;
56 switch AH_reg(context
) {
58 case 0x00: /* Get Keystroke */
59 /* Returns: AH = Scan code
60 AL = ASCII character */
61 TRACE("Get Keystroke\n");
62 DOSVM_Int16ReadChar(&ascii
, &scan
, FALSE
);
63 SET_AL( context
, ascii
);
64 SET_AH( context
, scan
);
67 case 0x01: /* Check for Keystroke */
68 /* Returns: ZF set if no keystroke */
70 /* AL = ASCII character */
71 TRACE("Check for Keystroke\n");
72 if (!DOSVM_Int16ReadChar(&ascii
, &scan
, TRUE
))
78 SET_AL( context
, ascii
);
79 SET_AH( context
, scan
);
82 /* don't miss the opportunity to break some tight timing loop in DOS
83 * programs causing 100% CPU usage (by doing a Sleep here) */
87 case 0x02: /* Get Shift Flags */
89 /* read value from BIOS data segment's keyboard status flags field */
91 SET_AL( context
, data
->KbdFlags1
);
93 TRACE("Get Shift Flags: returning 0x%02x\n", AL_reg(context
));
96 case 0x03: /* Set Typematic Rate and Delay */
97 FIXME("Set Typematic Rate and Delay - Not Supported\n");
100 case 0x09: /* Get Keyboard Functionality */
101 FIXME("Get Keyboard Functionality - Not Supported\n");
102 /* As a temporary measure, say that "nothing" is supported... */
103 SET_AL( context
, 0 );
106 case 0x0a: /* Get Keyboard ID */
107 FIXME("Get Keyboard ID - Not Supported\n");
110 case 0x10: /* Get Enhanced Keystroke */
111 TRACE("Get Enhanced Keystroke - Partially supported\n");
112 /* Returns: AH = Scan code
113 AL = ASCII character */
114 DOSVM_Int16ReadChar(&ascii
, &scan
, FALSE
);
115 SET_AL( context
, ascii
);
116 SET_AH( context
, scan
);
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(&ascii
, &scan
, TRUE
))
131 SET_AL( context
, ascii
);
132 SET_AH( context
, scan
);
133 RESET_ZFLAG(context
);
137 case 0x12: /* Get Extended Shift States */
138 FIXME("Get Extended Shift States - Not Supported\n");
142 FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context
));
148 int WINAPI
DOSVM_Int16ReadChar(BYTE
*ascii
,BYTE
*scan
,BOOL peek
)
150 BIOSDATA
*data
= BIOS_DATA
;
151 WORD CurOfs
= data
->NextKbdCharPtr
;
153 /* check if there's data in buffer */
155 if (CurOfs
== data
->FirstKbdCharPtr
)
158 while (CurOfs
== data
->FirstKbdCharPtr
) {
159 /* no input available yet, so wait... */
163 /* read from keyboard queue */
164 TRACE("(%p,%p,%d) -> %02x %02x\n",ascii
,scan
,peek
,((BYTE
*)data
)[CurOfs
],((BYTE
*)data
)[CurOfs
+1]);
165 if (ascii
) *ascii
= ((BYTE
*)data
)[CurOfs
];
166 if (scan
) *scan
= ((BYTE
*)data
)[CurOfs
+1];
169 if (CurOfs
>= data
->KbdBufferEnd
) CurOfs
= data
->KbdBufferStart
;
170 data
->NextKbdCharPtr
= CurOfs
;
175 int WINAPI
DOSVM_Int16AddChar(BYTE ascii
,BYTE scan
)
177 BIOSDATA
*data
= BIOS_DATA
;
178 WORD CurOfs
= data
->FirstKbdCharPtr
;
179 WORD NextOfs
= CurOfs
+ 2;
181 TRACE("(%02x,%02x)\n",ascii
,scan
);
182 if (NextOfs
>= data
->KbdBufferEnd
) NextOfs
= data
->KbdBufferStart
;
183 /* check if buffer is full */
184 if (NextOfs
== data
->NextKbdCharPtr
) return 0;
186 /* okay, insert character in ring buffer */
187 ((BYTE
*)data
)[CurOfs
] = ascii
;
188 ((BYTE
*)data
)[CurOfs
+1] = scan
;
190 data
->FirstKbdCharPtr
= NextOfs
;