2001-12-04 20:54:44 +01:00
|
|
|
/*
|
|
|
|
* DOS interrupt 21h handler
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* Copyright 1993, 1994 Erik Bos
|
|
|
|
* Copyright 1996 Alexandre Julliard
|
|
|
|
* Copyright 1997 Andreas Mohr
|
|
|
|
* Copyright 1998 Uwe Bonnes
|
|
|
|
* Copyright 1998, 1999 Ove Kaaven
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-12-04 20:54:44 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2001-12-04 20:54:44 +01:00
|
|
|
#include "wine/winbase16.h"
|
|
|
|
#include "dosexe.h"
|
|
|
|
#include "miscemu.h"
|
|
|
|
#include "msdos.h"
|
2002-01-29 18:55:21 +01:00
|
|
|
#include "file.h"
|
2002-08-27 03:13:58 +02:00
|
|
|
#include "wine/unicode.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2001-12-04 20:54:44 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(int21);
|
2001-12-04 20:54:44 +01:00
|
|
|
|
2002-01-29 18:55:21 +01:00
|
|
|
void WINAPI DOSVM_Int21Handler_Ioctl( CONTEXT86 *context )
|
|
|
|
{
|
2002-08-27 03:13:58 +02:00
|
|
|
static const WCHAR emmxxxx0W[] = {'E','M','M','X','X','X','X','0',0};
|
2002-01-29 18:55:21 +01:00
|
|
|
const DOS_DEVICE *dev = DOSFS_GetDeviceByHandle(
|
|
|
|
DosFileHandleToWin32Handle(BX_reg(context)) );
|
|
|
|
|
2002-08-27 03:13:58 +02:00
|
|
|
if (dev && !strcmpiW( dev->name, emmxxxx0W )) {
|
2002-01-29 18:55:21 +01:00
|
|
|
EMS_Ioctl_Handler(context);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (AL_reg(context))
|
|
|
|
{
|
|
|
|
case 0x0b: /* SET SHARING RETRY COUNT */
|
|
|
|
TRACE("IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
|
|
|
|
CX_reg(context), DX_reg(context));
|
|
|
|
if (!CX_reg(context))
|
|
|
|
{
|
2002-08-31 20:47:00 +02:00
|
|
|
SET_AX( context, 1 );
|
2002-01-29 18:55:21 +01:00
|
|
|
SET_CFLAG(context);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DOSMEM_LOL()->sharing_retry_delay = CX_reg(context);
|
|
|
|
if (!DX_reg(context))
|
|
|
|
DOSMEM_LOL()->sharing_retry_count = DX_reg(context);
|
|
|
|
RESET_CFLAG(context);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DOS3Call( context );
|
|
|
|
}
|
|
|
|
}
|
2001-12-04 20:54:44 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
2002-11-06 20:57:49 +01:00
|
|
|
* DOSVM_Int21Handler (WINEDOS16.133)
|
2001-12-04 20:54:44 +01:00
|
|
|
*
|
2002-10-30 00:09:30 +01:00
|
|
|
* int 21h handler. Most calls are passed directly to DOS3Call.
|
2001-12-04 20:54:44 +01:00
|
|
|
*/
|
|
|
|
void WINAPI DOSVM_Int21Handler( CONTEXT86 *context )
|
|
|
|
{
|
2002-08-31 20:47:00 +02:00
|
|
|
BYTE ascii;
|
2002-10-30 00:09:30 +01:00
|
|
|
|
|
|
|
if (DOSVM_IsWin16()) {
|
|
|
|
DOS3Call( context );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-12-04 20:54:44 +01:00
|
|
|
RESET_CFLAG(context); /* Not sure if this is a good idea */
|
|
|
|
|
2002-05-05 22:22:06 +02:00
|
|
|
if(AH_reg(context) == 0x0c) /* FLUSH BUFFER AND READ STANDARD INPUT */
|
|
|
|
{
|
|
|
|
BYTE al = AL_reg(context); /* Input function to execute after flush. */
|
|
|
|
|
|
|
|
/* FIXME: buffers are not flushed */
|
|
|
|
|
|
|
|
/*
|
2002-06-01 01:06:46 +02:00
|
|
|
* If AL is not one of 0x01, 0x06, 0x07, 0x08, or 0x0a,
|
2002-05-05 22:22:06 +02:00
|
|
|
* the buffer is flushed but no input is attempted.
|
|
|
|
*/
|
|
|
|
if(al != 0x01 && al != 0x06 && al != 0x07 && al != 0x08 && al != 0x0a)
|
|
|
|
return;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-08-31 20:47:00 +02:00
|
|
|
SET_AH( context, al );
|
2002-05-05 22:22:06 +02:00
|
|
|
}
|
|
|
|
|
2001-12-04 20:54:44 +01:00
|
|
|
switch(AH_reg(context))
|
|
|
|
{
|
|
|
|
case 0x00: /* TERMINATE PROGRAM */
|
|
|
|
TRACE("TERMINATE PROGRAM\n");
|
|
|
|
MZ_Exit( context, FALSE, 0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
|
|
|
|
TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
|
2002-08-31 20:47:00 +02:00
|
|
|
DOSVM_Int16ReadChar(&ascii, NULL, FALSE);
|
|
|
|
SET_AL( context, ascii );
|
2002-04-08 22:11:47 +02:00
|
|
|
DOSVM_PutChar(AL_reg(context));
|
2002-08-31 20:47:00 +02:00
|
|
|
break;
|
2001-12-04 20:54:44 +01:00
|
|
|
|
|
|
|
case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
|
|
|
|
TRACE("Write Character to Standard Output\n");
|
2002-04-03 04:34:45 +02:00
|
|
|
DOSVM_PutChar(DL_reg(context));
|
2001-12-04 20:54:44 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
|
|
|
|
/* FIXME: Use DOSDEV_Peek/Read/Write(DOSDEV_Console(),...) !! */
|
|
|
|
if (DL_reg(context) == 0xff) {
|
|
|
|
static char scan = 0;
|
|
|
|
TRACE("Direct Console Input\n");
|
|
|
|
if (scan) {
|
|
|
|
/* return pending scancode */
|
2002-08-31 20:47:00 +02:00
|
|
|
SET_AL( context, scan );
|
2001-12-04 20:54:44 +01:00
|
|
|
RESET_ZFLAG(context);
|
|
|
|
scan = 0;
|
|
|
|
} else {
|
|
|
|
if (DOSVM_Int16ReadChar(&ascii,&scan,TRUE)) {
|
|
|
|
DOSVM_Int16ReadChar(&ascii,&scan,FALSE);
|
|
|
|
/* return ASCII code */
|
2002-08-31 20:47:00 +02:00
|
|
|
SET_AL( context, ascii );
|
2001-12-04 20:54:44 +01:00
|
|
|
RESET_ZFLAG(context);
|
|
|
|
/* return scan code on next call only if ascii==0 */
|
|
|
|
if (ascii) scan = 0;
|
|
|
|
} else {
|
|
|
|
/* nothing pending, clear everything */
|
2002-08-31 20:47:00 +02:00
|
|
|
SET_AL( context, 0 );
|
2001-12-04 20:54:44 +01:00
|
|
|
SET_ZFLAG(context);
|
|
|
|
scan = 0; /* just in case */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
TRACE("Direct Console Output\n");
|
2002-04-03 04:34:45 +02:00
|
|
|
DOSVM_PutChar(DL_reg(context));
|
2001-12-04 20:54:44 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
|
|
|
|
/* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
|
|
|
|
TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
|
2002-08-31 20:47:00 +02:00
|
|
|
DOSVM_Int16ReadChar(&ascii, NULL, FALSE);
|
|
|
|
SET_AL( context, ascii );
|
2001-12-04 20:54:44 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
|
|
|
|
/* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
|
|
|
|
TRACE("CHARACTER INPUT WITHOUT ECHO\n");
|
2002-08-31 20:47:00 +02:00
|
|
|
DOSVM_Int16ReadChar(&ascii, NULL, FALSE);
|
|
|
|
SET_AL( context, ascii );
|
2001-12-04 20:54:44 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0b: /* GET STDIN STATUS */
|
|
|
|
{
|
2002-08-30 02:03:25 +02:00
|
|
|
BIOSDATA *data = BIOS_DATA;
|
2002-01-31 22:47:57 +01:00
|
|
|
if(data->FirstKbdCharPtr == data->NextKbdCharPtr)
|
2002-08-31 20:47:00 +02:00
|
|
|
SET_AL( context, 0 );
|
2002-01-31 22:47:57 +01:00
|
|
|
else
|
2002-08-31 20:47:00 +02:00
|
|
|
SET_AL( context, 0xff );
|
2001-12-04 20:54:44 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x25: /* SET INTERRUPT VECTOR */
|
|
|
|
DOSVM_SetRMHandler( AL_reg(context),
|
|
|
|
(FARPROC16)MAKESEGPTR( context->SegDs, DX_reg(context)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x35: /* GET INTERRUPT VECTOR */
|
|
|
|
TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
|
|
|
|
{
|
|
|
|
FARPROC16 addr = DOSVM_GetRMHandler( AL_reg(context) );
|
|
|
|
context->SegEs = SELECTOROF(addr);
|
2002-08-31 20:47:00 +02:00
|
|
|
SET_BX( context, OFFSETOF(addr) );
|
2001-12-04 20:54:44 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-04-03 04:34:45 +02:00
|
|
|
case 0x40: /* WRITE TO FILE OR DEVICE */
|
|
|
|
/* Writes to stdout are handled here. */
|
|
|
|
if (BX_reg(context) == 1) {
|
|
|
|
BYTE *ptr = CTX_SEG_OFF_TO_LIN(context,
|
|
|
|
context->SegDs,
|
|
|
|
context->Edx);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i=0; i<CX_reg(context); i++)
|
|
|
|
DOSVM_PutChar(ptr[i]);
|
|
|
|
} else
|
|
|
|
DOS3Call( context );
|
|
|
|
break;
|
|
|
|
|
2001-12-04 20:54:44 +01:00
|
|
|
case 0x44: /* IOCTL */
|
2002-01-29 18:55:21 +01:00
|
|
|
DOSVM_Int21Handler_Ioctl( context );
|
2001-12-04 20:54:44 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
|
|
|
|
TRACE("EXEC %s\n", (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx ));
|
|
|
|
if (!MZ_Exec( context, CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx),
|
|
|
|
AL_reg(context), CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx) ))
|
|
|
|
{
|
2002-08-31 20:47:00 +02:00
|
|
|
SET_AX( context, GetLastError() );
|
2001-12-04 20:54:44 +01:00
|
|
|
SET_CFLAG(context);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
|
|
|
|
TRACE("EXIT with return code %d\n",AL_reg(context));
|
|
|
|
MZ_Exit( context, FALSE, AL_reg(context) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x4d: /* GET RETURN CODE */
|
|
|
|
TRACE("GET RETURN CODE (ERRORLEVEL)\n");
|
2002-08-31 20:47:00 +02:00
|
|
|
SET_AX( context, DOSVM_retval );
|
2001-12-04 20:54:44 +01:00
|
|
|
DOSVM_retval = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
|
|
|
|
TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
|
|
|
|
DOSVM_psp = BX_reg(context);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x51: /* GET PSP ADDRESS */
|
|
|
|
TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
|
|
|
|
/* FIXME: should we return the original DOS PSP upon */
|
|
|
|
/* Windows startup ? */
|
2002-08-31 20:47:00 +02:00
|
|
|
SET_BX( context, DOSVM_psp );
|
2001-12-04 20:54:44 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
|
|
|
|
TRACE("SYSVARS - GET LIST OF LISTS\n");
|
|
|
|
{
|
|
|
|
context->SegEs = HIWORD(DOS_LOLSeg);
|
2002-08-31 20:47:00 +02:00
|
|
|
SET_BX( context, FIELD_OFFSET(DOS_LISTOFLISTS, ptr_first_DPB) );
|
2001-12-04 20:54:44 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x62: /* GET PSP ADDRESS */
|
|
|
|
TRACE("GET CURRENT PSP ADDRESS\n");
|
|
|
|
/* FIXME: should we return the original DOS PSP upon */
|
|
|
|
/* Windows startup ? */
|
2002-08-31 20:47:00 +02:00
|
|
|
SET_BX( context, DOSVM_psp );
|
2001-12-04 20:54:44 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DOS3Call( context );
|
|
|
|
}
|
|
|
|
}
|