2 * DOS interrupt 21h handler
10 #include "wine/winbase16.h"
16 #include "debugtools.h"
18 DEFAULT_DEBUG_CHANNEL(int21);
20 void WINAPI DOSVM_Int21Handler_Ioctl( CONTEXT86 *context )
22 const DOS_DEVICE *dev = DOSFS_GetDeviceByHandle(
23 DosFileHandleToWin32Handle(BX_reg(context)) );
25 if (dev && !strcasecmp( dev->name, "EMMXXXX0" )) {
26 EMS_Ioctl_Handler(context);
30 switch (AL_reg(context))
32 case 0x0b: /* SET SHARING RETRY COUNT */
33 TRACE("IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
34 CX_reg(context), DX_reg(context));
41 DOSMEM_LOL()->sharing_retry_delay = CX_reg(context);
43 DOSMEM_LOL()->sharing_retry_count = DX_reg(context);
51 /***********************************************************************
54 * int 21h real-mode handler. Most calls are passed directly to DOS3Call.
56 void WINAPI DOSVM_Int21Handler( CONTEXT86 *context )
58 RESET_CFLAG(context); /* Not sure if this is a good idea */
60 switch(AH_reg(context))
62 case 0x00: /* TERMINATE PROGRAM */
63 TRACE("TERMINATE PROGRAM\n");
64 MZ_Exit( context, FALSE, 0 );
67 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
68 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
69 AL_reg(context) = CONSOLE_GetCharacter();
73 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
74 TRACE("Write Character to Standard Output\n");
75 CONSOLE_Write(DL_reg(context), 0, 0, 0);
78 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
79 /* FIXME: Use DOSDEV_Peek/Read/Write(DOSDEV_Console(),...) !! */
80 if (DL_reg(context) == 0xff) {
82 TRACE("Direct Console Input\n");
84 /* return pending scancode */
85 AL_reg(context) = scan;
90 if (DOSVM_Int16ReadChar(&ascii,&scan,TRUE)) {
91 DOSVM_Int16ReadChar(&ascii,&scan,FALSE);
92 /* return ASCII code */
93 AL_reg(context) = ascii;
95 /* return scan code on next call only if ascii==0 */
98 /* nothing pending, clear everything */
101 scan = 0; /* just in case */
105 TRACE("Direct Console Output\n");
106 CONSOLE_Write(DL_reg(context), 0, 0, 0);
110 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
111 /* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
112 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
113 DOSVM_Int16ReadChar(&AL_reg(context), NULL, FALSE);
116 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
117 /* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
118 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
119 DOSVM_Int16ReadChar(&AL_reg(context), NULL, FALSE);
122 case 0x0b: /* GET STDIN STATUS */
124 BIOSDATA *data = DOSMEM_BiosData();
125 if(data->FirstKbdCharPtr == data->NextKbdCharPtr)
128 AL_reg(context) = 0xff;
132 case 0x25: /* SET INTERRUPT VECTOR */
133 DOSVM_SetRMHandler( AL_reg(context),
134 (FARPROC16)MAKESEGPTR( context->SegDs, DX_reg(context)));
137 case 0x35: /* GET INTERRUPT VECTOR */
138 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
140 FARPROC16 addr = DOSVM_GetRMHandler( AL_reg(context) );
141 context->SegEs = SELECTOROF(addr);
142 BX_reg(context) = OFFSETOF(addr);
146 case 0x44: /* IOCTL */
147 DOSVM_Int21Handler_Ioctl( context );
150 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
151 TRACE("EXEC %s\n", (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx ));
152 if (!MZ_Exec( context, CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx),
153 AL_reg(context), CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx) ))
155 AX_reg(context) = GetLastError();
160 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
161 TRACE("EXIT with return code %d\n",AL_reg(context));
162 MZ_Exit( context, FALSE, AL_reg(context) );
165 case 0x4d: /* GET RETURN CODE */
166 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
167 AX_reg(context) = DOSVM_retval;
171 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
172 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
173 DOSVM_psp = BX_reg(context);
176 case 0x51: /* GET PSP ADDRESS */
177 TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
178 /* FIXME: should we return the original DOS PSP upon */
179 /* Windows startup ? */
180 BX_reg(context) = DOSVM_psp;
183 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
184 TRACE("SYSVARS - GET LIST OF LISTS\n");
186 context->SegEs = HIWORD(DOS_LOLSeg);
187 BX_reg(context) = FIELD_OFFSET(DOS_LISTOFLISTS, ptr_first_DPB);
191 case 0x62: /* GET PSP ADDRESS */
192 TRACE("GET CURRENT PSP ADDRESS\n");
193 /* FIXME: should we return the original DOS PSP upon */
194 /* Windows startup ? */
195 BX_reg(context) = DOSVM_psp;