2 * DOS interrupt 21h handler
10 #include "wine/winbase16.h"
15 #include "debugtools.h"
17 DEFAULT_DEBUG_CHANNEL(int21);
20 /***********************************************************************
23 * int 21h real-mode handler. Most calls are passed directly to DOS3Call.
25 void WINAPI DOSVM_Int21Handler( CONTEXT86 *context )
27 RESET_CFLAG(context); /* Not sure if this is a good idea */
29 switch(AH_reg(context))
31 case 0x00: /* TERMINATE PROGRAM */
32 TRACE("TERMINATE PROGRAM\n");
33 MZ_Exit( context, FALSE, 0 );
36 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
37 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
38 AL_reg(context) = CONSOLE_GetCharacter();
42 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
43 TRACE("Write Character to Standard Output\n");
44 CONSOLE_Write(DL_reg(context), 0, 0, 0);
47 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
48 /* FIXME: Use DOSDEV_Peek/Read/Write(DOSDEV_Console(),...) !! */
49 if (DL_reg(context) == 0xff) {
51 TRACE("Direct Console Input\n");
53 /* return pending scancode */
54 AL_reg(context) = scan;
59 if (DOSVM_Int16ReadChar(&ascii,&scan,TRUE)) {
60 DOSVM_Int16ReadChar(&ascii,&scan,FALSE);
61 /* return ASCII code */
62 AL_reg(context) = ascii;
64 /* return scan code on next call only if ascii==0 */
67 /* nothing pending, clear everything */
70 scan = 0; /* just in case */
74 TRACE("Direct Console Output\n");
75 CONSOLE_Write(DL_reg(context), 0, 0, 0);
79 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
80 /* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
81 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
82 DOSVM_Int16ReadChar(&AL_reg(context), NULL, FALSE);
85 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
86 /* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
87 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
88 DOSVM_Int16ReadChar(&AL_reg(context), NULL, FALSE);
91 case 0x0b: /* GET STDIN STATUS */
95 if (CONSOLE_CheckForKeystroke(&x1,&x2))
96 AL_reg(context) = 0xff;
102 case 0x25: /* SET INTERRUPT VECTOR */
103 DOSVM_SetRMHandler( AL_reg(context),
104 (FARPROC16)MAKESEGPTR( context->SegDs, DX_reg(context)));
107 case 0x35: /* GET INTERRUPT VECTOR */
108 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
110 FARPROC16 addr = DOSVM_GetRMHandler( AL_reg(context) );
111 context->SegEs = SELECTOROF(addr);
112 BX_reg(context) = OFFSETOF(addr);
116 case 0x44: /* IOCTL */
117 switch (AL_reg(context))
119 case 0x0b: /* SET SHARING RETRY COUNT */
120 TRACE("IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
121 CX_reg(context), DX_reg(context));
122 if (!CX_reg(context))
128 DOSMEM_LOL()->sharing_retry_delay = CX_reg(context);
129 if (!DX_reg(context))
130 DOSMEM_LOL()->sharing_retry_count = DX_reg(context);
131 RESET_CFLAG(context);
136 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
137 TRACE("EXEC %s\n", (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx ));
138 if (!MZ_Exec( context, CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx),
139 AL_reg(context), CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx) ))
141 AX_reg(context) = GetLastError();
146 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
147 TRACE("EXIT with return code %d\n",AL_reg(context));
148 MZ_Exit( context, FALSE, AL_reg(context) );
151 case 0x4d: /* GET RETURN CODE */
152 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
153 AX_reg(context) = DOSVM_retval;
157 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
158 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
159 DOSVM_psp = BX_reg(context);
162 case 0x51: /* GET PSP ADDRESS */
163 TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
164 /* FIXME: should we return the original DOS PSP upon */
165 /* Windows startup ? */
166 BX_reg(context) = DOSVM_psp;
169 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
170 TRACE("SYSVARS - GET LIST OF LISTS\n");
172 context->SegEs = HIWORD(DOS_LOLSeg);
173 BX_reg(context) = FIELD_OFFSET(DOS_LISTOFLISTS, ptr_first_DPB);
177 case 0x62: /* GET PSP ADDRESS */
178 TRACE("GET CURRENT PSP ADDRESS\n");
179 /* FIXME: should we return the original DOS PSP upon */
180 /* Windows startup ? */
181 BX_reg(context) = DOSVM_psp;