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
, context
);
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
, NULL
))
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 */
90 data
= DOSVM_BiosData();
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 0x05:/*simulate Keystroke*/
101 FIXME("Simulating a keystroke is not supported yet\n");
104 case 0x09: /* Get Keyboard Functionality */
105 FIXME("Get Keyboard Functionality - Not Supported\n");
106 /* As a temporary measure, say that "nothing" is supported... */
107 SET_AL( context
, 0 );
110 case 0x0a: /* Get Keyboard ID */
111 FIXME("Get Keyboard ID - Not Supported\n");
114 case 0x10: /* Get Enhanced Keystroke */
115 TRACE("Get Enhanced Keystroke - Partially supported\n");
116 /* Returns: AH = Scan code
117 AL = ASCII character */
118 DOSVM_Int16ReadChar(&ascii
, &scan
, context
);
119 SET_AL( context
, ascii
);
120 SET_AH( context
, scan
);
124 case 0x11: /* Check for Enhanced Keystroke */
125 /* Returns: ZF set if no keystroke */
127 /* AL = ASCII character */
128 TRACE("Check for Enhanced Keystroke - Partially supported\n");
129 if (!DOSVM_Int16ReadChar(&ascii
, &scan
, NULL
))
135 SET_AL( context
, ascii
);
136 SET_AH( context
, scan
);
137 RESET_ZFLAG(context
);
141 case 0x12: /* Get Extended Shift States */
142 FIXME("Get Extended Shift States - Not Supported\n");
146 FIXME("Unknown INT 16 function - 0x%x\n", AH_reg(context
));
152 /**********************************************************************
153 * DOSVM_Int16ReadChar
155 * Either peek into keyboard buffer or wait for next keystroke.
157 * If waitctx is NULL, return TRUE if buffer had keystrokes and
158 * FALSE if buffer is empty. Returned keystroke will be left into buffer.
160 * If waitctx is non-NULL, wait until keystrokes are available.
161 * Return value will always be TRUE and returned keystroke will be
162 * removed from buffer.
164 int WINAPI
DOSVM_Int16ReadChar(BYTE
*ascii
, BYTE
*scan
, CONTEXT86
*waitctx
)
166 BIOSDATA
*data
= DOSVM_BiosData();
167 WORD CurOfs
= data
->NextKbdCharPtr
;
169 /* check if there's data in buffer */
172 /* wait until input is available... */
173 while (CurOfs
== data
->FirstKbdCharPtr
)
174 DOSVM_Wait( waitctx
);
178 if (CurOfs
== data
->FirstKbdCharPtr
)
182 /* read from keyboard queue */
183 TRACE( "(%p,%p,%p) -> %02x %02x\n", ascii
, scan
, waitctx
,
184 ((BYTE
*)data
)[CurOfs
], ((BYTE
*)data
)[CurOfs
+1] );
186 if (ascii
) *ascii
= ((BYTE
*)data
)[CurOfs
];
187 if (scan
) *scan
= ((BYTE
*)data
)[CurOfs
+1];
192 if (CurOfs
>= data
->KbdBufferEnd
) CurOfs
= data
->KbdBufferStart
;
193 data
->NextKbdCharPtr
= CurOfs
;
199 int WINAPI
DOSVM_Int16AddChar(BYTE ascii
,BYTE scan
)
201 BIOSDATA
*data
= DOSVM_BiosData();
202 WORD CurOfs
= data
->FirstKbdCharPtr
;
203 WORD NextOfs
= CurOfs
+ 2;
205 TRACE("(%02x,%02x)\n",ascii
,scan
);
206 if (NextOfs
>= data
->KbdBufferEnd
) NextOfs
= data
->KbdBufferStart
;
207 /* check if buffer is full */
208 if (NextOfs
== data
->NextKbdCharPtr
) return 0;
210 /* okay, insert character in ring buffer */
211 ((BYTE
*)data
)[CurOfs
] = ascii
;
212 ((BYTE
*)data
)[CurOfs
+1] = scan
;
214 data
->FirstKbdCharPtr
= NextOfs
;