2 * DOS interrupt 21h handler
4 * Copyright 1993, 1994 Erik Bos
5 * Copyright 1996 Alexandre Julliard
6 * Copyright 1997 Andreas Mohr
7 * Copyright 1998 Uwe Bonnes
8 * Copyright 1998, 1999 Ove Kaaven
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "wine/winbase16.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(int21
);
40 void WINAPI
DOSVM_Int21Handler_Ioctl( CONTEXT86
*context
)
42 static const WCHAR emmxxxx0W
[] = {'E','M','M','X','X','X','X','0',0};
43 const DOS_DEVICE
*dev
= DOSFS_GetDeviceByHandle(
44 DosFileHandleToWin32Handle(BX_reg(context
)) );
46 if (dev
&& !strcmpiW( dev
->name
, emmxxxx0W
)) {
47 EMS_Ioctl_Handler(context
);
51 switch (AL_reg(context
))
53 case 0x0b: /* SET SHARING RETRY COUNT */
54 TRACE("IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
55 CX_reg(context
), DX_reg(context
));
62 DOSMEM_LOL()->sharing_retry_delay
= CX_reg(context
);
64 DOSMEM_LOL()->sharing_retry_count
= DX_reg(context
);
72 /***********************************************************************
75 * int 21h real-mode handler. Most calls are passed directly to DOS3Call.
77 void WINAPI
DOSVM_Int21Handler( CONTEXT86
*context
)
80 RESET_CFLAG(context
); /* Not sure if this is a good idea */
82 if(AH_reg(context
) == 0x0c) /* FLUSH BUFFER AND READ STANDARD INPUT */
84 BYTE al
= AL_reg(context
); /* Input function to execute after flush. */
86 /* FIXME: buffers are not flushed */
89 * If AL is not one of 0x01, 0x06, 0x07, 0x08, or 0x0a,
90 * the buffer is flushed but no input is attempted.
92 if(al
!= 0x01 && al
!= 0x06 && al
!= 0x07 && al
!= 0x08 && al
!= 0x0a)
95 SET_AH( context
, al
);
98 switch(AH_reg(context
))
100 case 0x00: /* TERMINATE PROGRAM */
101 TRACE("TERMINATE PROGRAM\n");
102 MZ_Exit( context
, FALSE
, 0 );
105 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
106 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
107 DOSVM_Int16ReadChar(&ascii
, NULL
, FALSE
);
108 SET_AL( context
, ascii
);
109 DOSVM_PutChar(AL_reg(context
));
112 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
113 TRACE("Write Character to Standard Output\n");
114 DOSVM_PutChar(DL_reg(context
));
117 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
118 /* FIXME: Use DOSDEV_Peek/Read/Write(DOSDEV_Console(),...) !! */
119 if (DL_reg(context
) == 0xff) {
120 static char scan
= 0;
121 TRACE("Direct Console Input\n");
123 /* return pending scancode */
124 SET_AL( context
, scan
);
125 RESET_ZFLAG(context
);
128 if (DOSVM_Int16ReadChar(&ascii
,&scan
,TRUE
)) {
129 DOSVM_Int16ReadChar(&ascii
,&scan
,FALSE
);
130 /* return ASCII code */
131 SET_AL( context
, ascii
);
132 RESET_ZFLAG(context
);
133 /* return scan code on next call only if ascii==0 */
136 /* nothing pending, clear everything */
137 SET_AL( context
, 0 );
139 scan
= 0; /* just in case */
143 TRACE("Direct Console Output\n");
144 DOSVM_PutChar(DL_reg(context
));
148 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
149 /* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
150 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
151 DOSVM_Int16ReadChar(&ascii
, NULL
, FALSE
);
152 SET_AL( context
, ascii
);
155 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
156 /* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
157 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
158 DOSVM_Int16ReadChar(&ascii
, NULL
, FALSE
);
159 SET_AL( context
, ascii
);
162 case 0x0b: /* GET STDIN STATUS */
164 BIOSDATA
*data
= BIOS_DATA
;
165 if(data
->FirstKbdCharPtr
== data
->NextKbdCharPtr
)
166 SET_AL( context
, 0 );
168 SET_AL( context
, 0xff );
172 case 0x25: /* SET INTERRUPT VECTOR */
173 DOSVM_SetRMHandler( AL_reg(context
),
174 (FARPROC16
)MAKESEGPTR( context
->SegDs
, DX_reg(context
)));
177 case 0x35: /* GET INTERRUPT VECTOR */
178 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
180 FARPROC16 addr
= DOSVM_GetRMHandler( AL_reg(context
) );
181 context
->SegEs
= SELECTOROF(addr
);
182 SET_BX( context
, OFFSETOF(addr
) );
186 case 0x40: /* WRITE TO FILE OR DEVICE */
187 /* Writes to stdout are handled here. */
188 if (BX_reg(context
) == 1) {
189 BYTE
*ptr
= CTX_SEG_OFF_TO_LIN(context
,
194 for(i
=0; i
<CX_reg(context
); i
++)
195 DOSVM_PutChar(ptr
[i
]);
200 case 0x44: /* IOCTL */
201 DOSVM_Int21Handler_Ioctl( context
);
204 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
205 TRACE("EXEC %s\n", (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
206 if (!MZ_Exec( context
, CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
),
207 AL_reg(context
), CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Ebx
) ))
209 SET_AX( context
, GetLastError() );
214 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
215 TRACE("EXIT with return code %d\n",AL_reg(context
));
216 MZ_Exit( context
, FALSE
, AL_reg(context
) );
219 case 0x4d: /* GET RETURN CODE */
220 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
221 SET_AX( context
, DOSVM_retval
);
225 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
226 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
227 DOSVM_psp
= BX_reg(context
);
230 case 0x51: /* GET PSP ADDRESS */
231 TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
232 /* FIXME: should we return the original DOS PSP upon */
233 /* Windows startup ? */
234 SET_BX( context
, DOSVM_psp
);
237 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
238 TRACE("SYSVARS - GET LIST OF LISTS\n");
240 context
->SegEs
= HIWORD(DOS_LOLSeg
);
241 SET_BX( context
, FIELD_OFFSET(DOS_LISTOFLISTS
, ptr_first_DPB
) );
245 case 0x62: /* GET PSP ADDRESS */
246 TRACE("GET CURRENT PSP ADDRESS\n");
247 /* FIXME: should we return the original DOS PSP upon */
248 /* Windows startup ? */
249 SET_BX( context
, DOSVM_psp
);