Removed obsolete console driver.
[wine] / dlls / winedos / int21.c
1 /*
2  * DOS interrupt 21h handler
3  *
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
9  *
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.
14  *
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.
19  *
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
23  */
24
25 #include "config.h"
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "ntddk.h"
30 #include "wine/winbase16.h"
31 #include "dosexe.h"
32 #include "miscemu.h"
33 #include "msdos.h"
34 #include "file.h"
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(int21);
38
39 void WINAPI DOSVM_Int21Handler_Ioctl( CONTEXT86 *context )
40 {
41   const DOS_DEVICE *dev = DOSFS_GetDeviceByHandle(
42       DosFileHandleToWin32Handle(BX_reg(context)) );
43
44   if (dev && !strcasecmp( dev->name, "EMMXXXX0" )) {
45     EMS_Ioctl_Handler(context);
46     return;
47   }
48
49   switch (AL_reg(context))
50   {
51   case 0x0b: /* SET SHARING RETRY COUNT */
52       TRACE("IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
53            CX_reg(context), DX_reg(context));
54       if (!CX_reg(context))
55       {
56          AX_reg(context) = 1;
57          SET_CFLAG(context);
58          break;
59       }
60       DOSMEM_LOL()->sharing_retry_delay = CX_reg(context);
61       if (!DX_reg(context))
62          DOSMEM_LOL()->sharing_retry_count = DX_reg(context);
63       RESET_CFLAG(context);
64       break;
65   default:
66       DOS3Call( context );
67   }
68 }
69
70 /***********************************************************************
71  *           DOSVM_Int21Handler
72  *
73  * int 21h real-mode handler. Most calls are passed directly to DOS3Call.
74  */
75 void WINAPI DOSVM_Int21Handler( CONTEXT86 *context )
76 {
77     RESET_CFLAG(context);  /* Not sure if this is a good idea */
78
79     switch(AH_reg(context))
80     {
81     case 0x00: /* TERMINATE PROGRAM */
82         TRACE("TERMINATE PROGRAM\n");
83         MZ_Exit( context, FALSE, 0 );
84         break;
85
86     case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
87         TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
88         DOSVM_Int16ReadChar(&AL_reg(context), NULL, FALSE);
89         DOSVM_PutChar(AL_reg(context));
90         break;
91
92     case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
93         TRACE("Write Character to Standard Output\n");
94         DOSVM_PutChar(DL_reg(context));
95         break;
96
97     case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
98         /* FIXME: Use DOSDEV_Peek/Read/Write(DOSDEV_Console(),...) !! */
99         if (DL_reg(context) == 0xff) {
100             static char scan = 0;
101             TRACE("Direct Console Input\n");
102             if (scan) {
103                 /* return pending scancode */
104                 AL_reg(context) = scan;
105                 RESET_ZFLAG(context);
106                 scan = 0;
107             } else {
108                 char ascii;
109                 if (DOSVM_Int16ReadChar(&ascii,&scan,TRUE)) {
110                     DOSVM_Int16ReadChar(&ascii,&scan,FALSE);
111                     /* return ASCII code */
112                     AL_reg(context) = ascii;
113                     RESET_ZFLAG(context);
114                     /* return scan code on next call only if ascii==0 */
115                     if (ascii) scan = 0;
116                 } else {
117                     /* nothing pending, clear everything */
118                     AL_reg(context) = 0;
119                     SET_ZFLAG(context);
120                     scan = 0; /* just in case */
121                 }
122             }
123         } else {
124             TRACE("Direct Console Output\n");
125             DOSVM_PutChar(DL_reg(context));
126         }
127         break;
128
129     case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
130         /* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
131         TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
132         DOSVM_Int16ReadChar(&AL_reg(context), NULL, FALSE);
133         break;
134
135     case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
136         /* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
137         TRACE("CHARACTER INPUT WITHOUT ECHO\n");
138         DOSVM_Int16ReadChar(&AL_reg(context), NULL, FALSE);
139         break;
140
141     case 0x0b: /* GET STDIN STATUS */
142         {
143             BIOSDATA *data = DOSMEM_BiosData();
144             if(data->FirstKbdCharPtr == data->NextKbdCharPtr)
145                 AL_reg(context) = 0;
146             else
147                 AL_reg(context) = 0xff;
148         }
149         break;
150
151     case 0x25: /* SET INTERRUPT VECTOR */
152         DOSVM_SetRMHandler( AL_reg(context),
153                             (FARPROC16)MAKESEGPTR( context->SegDs, DX_reg(context)));
154         break;
155
156     case 0x35: /* GET INTERRUPT VECTOR */
157         TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
158         {
159             FARPROC16 addr = DOSVM_GetRMHandler( AL_reg(context) );
160             context->SegEs = SELECTOROF(addr);
161             BX_reg(context) = OFFSETOF(addr);
162         }
163         break;
164
165     case 0x40: /* WRITE TO FILE OR DEVICE */
166         /* Writes to stdout are handled here. */
167         if (BX_reg(context) == 1) {
168           BYTE *ptr = CTX_SEG_OFF_TO_LIN(context,
169                                          context->SegDs,
170                                          context->Edx);
171           int i;
172
173           for(i=0; i<CX_reg(context); i++)
174             DOSVM_PutChar(ptr[i]);
175         } else
176           DOS3Call( context );
177         break;
178
179     case 0x44: /* IOCTL */
180         DOSVM_Int21Handler_Ioctl( context );
181         break;
182
183     case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
184         TRACE("EXEC %s\n", (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx ));
185         if (!MZ_Exec( context, CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx),
186                       AL_reg(context), CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx) ))
187         {
188             AX_reg(context) = GetLastError();
189             SET_CFLAG(context);
190         }
191         break;
192
193     case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
194         TRACE("EXIT with return code %d\n",AL_reg(context));
195         MZ_Exit( context, FALSE, AL_reg(context) );
196         break;
197
198     case 0x4d: /* GET RETURN CODE */
199         TRACE("GET RETURN CODE (ERRORLEVEL)\n");
200         AX_reg(context) = DOSVM_retval;
201         DOSVM_retval = 0;
202         break;
203
204     case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
205         TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
206         DOSVM_psp = BX_reg(context);
207         break;
208
209     case 0x51: /* GET PSP ADDRESS */
210         TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
211         /* FIXME: should we return the original DOS PSP upon */
212         /*        Windows startup ? */
213         BX_reg(context) = DOSVM_psp;
214         break;
215
216     case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
217         TRACE("SYSVARS - GET LIST OF LISTS\n");
218         {
219             context->SegEs = HIWORD(DOS_LOLSeg);
220             BX_reg(context) = FIELD_OFFSET(DOS_LISTOFLISTS, ptr_first_DPB);
221         }
222         break;
223
224     case 0x62: /* GET PSP ADDRESS */
225         TRACE("GET CURRENT PSP ADDRESS\n");
226         /* FIXME: should we return the original DOS PSP upon */
227         /*        Windows startup ? */
228         BX_reg(context) = DOSVM_psp;
229         break;
230
231     default:
232         DOS3Call( context );
233     }
234 }