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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #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 BIOSDATA
*data
= NULL
;
55 switch AH_reg(context
) {
57 case 0x00: /* Get Keystroke */
58 /* Returns: AH = Scan code
59 AL = ASCII character */
60 TRACE("Get Keystroke\n");
61 DOSVM_Int16ReadChar(&ascii
, &scan
, context
);
62 SET_AL( context
, ascii
);
63 SET_AH( context
, scan
);
66 case 0x01: /* Check for Keystroke */
67 /* Returns: ZF set if no keystroke */
69 /* AL = ASCII character */
70 TRACE("Check for Keystroke\n");
71 if (!DOSVM_Int16ReadChar(&ascii
, &scan
, NULL
))
77 SET_AL( context
, ascii
);
78 SET_AH( context
, scan
);
81 /* don't miss the opportunity to break some tight timing loop in DOS
82 * programs causing 100% CPU usage (by doing a Sleep here) */
86 case 0x02: /* Get Shift Flags */
88 /* read value from BIOS data segment's keyboard status flags field */
89 data
= DOSVM_BiosData();
90 SET_AL( context
, data
->KbdFlags1
);
92 TRACE("Get Shift Flags: returning 0x%02x\n", AL_reg(context
));
95 case 0x03: /* Set Typematic Rate and Delay */
96 FIXME("Set Typematic Rate and Delay - Not Supported\n");
99 case 0x05:/*simulate Keystroke*/
100 FIXME("Simulating a keystroke is not supported yet\n");
103 case 0x09: /* Get Keyboard Functionality */
104 FIXME("Get Keyboard Functionality - Not Supported\n");
105 /* As a temporary measure, say that "nothing" is supported... */
106 SET_AL( context
, 0 );
109 case 0x0a: /* Get Keyboard ID */
110 FIXME("Get Keyboard ID - Not Supported\n");
113 case 0x10: /* Get Enhanced Keystroke */
114 TRACE("Get Enhanced Keystroke - Partially supported\n");
115 /* Returns: AH = Scan code
116 AL = ASCII character */
117 DOSVM_Int16ReadChar(&ascii
, &scan
, context
);
118 SET_AL( context
, ascii
);
119 SET_AH( context
, scan
);
123 case 0x11: /* Check for Enhanced Keystroke */
124 /* Returns: ZF set if no keystroke */
126 /* AL = ASCII character */
127 TRACE("Check for Enhanced Keystroke - Partially supported\n");
128 if (!DOSVM_Int16ReadChar(&ascii
, &scan
, NULL
))
134 SET_AL( context
, ascii
);
135 SET_AH( context
, scan
);
136 RESET_ZFLAG(context
);
140 case 0x12: /* Get Extended Shift States */
141 FIXME("Get Extended Shift States - Not Supported\n");
145 FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context
));
151 /**********************************************************************
152 * DOSVM_Int16ReadChar
154 * Either peek into keyboard buffer or wait for next keystroke.
156 * If waitctx is NULL, return TRUE if buffer had keystrokes and
157 * FALSE if buffer is empty. Returned keystroke will be left into buffer.
159 * If waitctx is non-NULL, wait until keystrokes are available.
160 * Return value will always be TRUE and returned keystroke will be
161 * removed from buffer.
163 int DOSVM_Int16ReadChar(BYTE
*ascii
, BYTE
*scan
, CONTEXT86
*waitctx
)
165 BIOSDATA
*data
= DOSVM_BiosData();
166 WORD CurOfs
= data
->NextKbdCharPtr
;
168 /* check if there's data in buffer */
171 /* wait until input is available... */
172 while (CurOfs
== data
->FirstKbdCharPtr
)
173 DOSVM_Wait( waitctx
);
177 if (CurOfs
== data
->FirstKbdCharPtr
)
181 /* read from keyboard queue */
182 TRACE( "(%p,%p,%p) -> %02x %02x\n", ascii
, scan
, waitctx
,
183 ((BYTE
*)data
)[CurOfs
], ((BYTE
*)data
)[CurOfs
+1] );
185 if (ascii
) *ascii
= ((BYTE
*)data
)[CurOfs
];
186 if (scan
) *scan
= ((BYTE
*)data
)[CurOfs
+1];
191 if (CurOfs
>= data
->KbdBufferEnd
) CurOfs
= data
->KbdBufferStart
;
192 data
->NextKbdCharPtr
= CurOfs
;
198 int DOSVM_Int16AddChar(BYTE ascii
,BYTE scan
)
200 BIOSDATA
*data
= DOSVM_BiosData();
201 WORD CurOfs
= data
->FirstKbdCharPtr
;
202 WORD NextOfs
= CurOfs
+ 2;
204 TRACE("(%02x,%02x)\n",ascii
,scan
);
205 if (NextOfs
>= data
->KbdBufferEnd
) NextOfs
= data
->KbdBufferStart
;
206 /* check if buffer is full */
207 if (NextOfs
== data
->NextKbdCharPtr
) return 0;
209 /* okay, insert character in ring buffer */
210 ((BYTE
*)data
)[CurOfs
] = ascii
;
211 ((BYTE
*)data
)[CurOfs
+1] = scan
;
213 data
->FirstKbdCharPtr
= NextOfs
;