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"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
40 * FIXME: Delete this reference when all int21 code has been moved to winedos.
42 extern void WINAPI INT_Int21Handler( CONTEXT86 *context );
44 WINE_DEFAULT_DEBUG_CHANNEL(int21);
50 * Structure for DOS data that can be accessed directly from applications.
51 * Real and protected mode pointers will be returned to this structure so
52 * the structure must be correctly packed.
54 typedef struct _INT21_HEAP {
55 WORD uppercase_size; /* Size of the following table in bytes */
56 BYTE uppercase_table[128]; /* Uppercase equivalents of chars from 0x80 to 0xff. */
58 WORD lowercase_size; /* Size of the following table in bytes */
59 BYTE lowercase_table[256]; /* Lowercase equivalents of chars from 0x00 to 0xff. */
61 WORD collating_size; /* Size of the following table in bytes */
62 BYTE collating_table[256]; /* Values used to sort characters from 0x00 to 0xff. */
64 WORD filename_size; /* Size of the following filename data in bytes */
65 BYTE filename_reserved1; /* 0x01 for MS-DOS 3.30-6.00 */
66 BYTE filename_lowest; /* Lowest permissible character value for filename */
67 BYTE filename_highest; /* Highest permissible character value for filename */
68 BYTE filename_reserved2; /* 0x00 for MS-DOS 3.30-6.00 */
69 BYTE filename_exclude_first; /* First illegal character in permissible range */
70 BYTE filename_exclude_last; /* Last illegal character in permissible range */
71 BYTE filename_reserved3; /* 0x02 for MS-DOS 3.30-6.00 */
72 BYTE filename_illegal_size; /* Number of terminators in the following table */
73 BYTE filename_illegal_table[16]; /* Characters which terminate a filename */
75 WORD dbcs_size; /* Number of valid ranges in the following table */
76 BYTE dbcs_table[16]; /* Start/end bytes for N ranges and 00/00 as terminator */
78 BYTE misc_indos; /* Interrupt 21 nesting flag */
84 /***********************************************************************
85 * INT21_GetSystemCountryCode
87 * Return DOS country code for default system locale.
89 static WORD INT21_GetSystemCountryCode()
92 * FIXME: Determine country code. We should probably use
93 * DOSCONF structure for that.
95 return GetSystemDefaultLangID();
99 /***********************************************************************
100 * INT21_FillCountryInformation
102 * Fill 34-byte buffer with country information data using
103 * default system locale.
105 static void INT21_FillCountryInformation( BYTE *buffer )
107 /* 00 - WORD: date format
112 *(WORD*)(buffer + 0) = 0; /* FIXME: Get from locale */
114 /* 02 - BYTE[5]: ASCIIZ currency symbol string */
115 buffer[2] = '$'; /* FIXME: Get from locale */
118 /* 07 - BYTE[2]: ASCIIZ thousands separator */
119 buffer[7] = 0; /* FIXME: Get from locale */
122 /* 09 - BYTE[2]: ASCIIZ decimal separator */
123 buffer[9] = '.'; /* FIXME: Get from locale */
126 /* 11 - BYTE[2]: ASCIIZ date separator */
127 buffer[11] = '/'; /* FIXME: Get from locale */
130 /* 13 - BYTE[2]: ASCIIZ time separator */
131 buffer[13] = ':'; /* FIXME: Get from locale */
134 /* 15 - BYTE: Currency format
135 * bit 2 = set if currency symbol replaces decimal point
136 * bit 1 = number of spaces between value and currency symbol
137 * bit 0 = 0 if currency symbol precedes value
138 * 1 if currency symbol follows value
140 buffer[15] = 0; /* FIXME: Get from locale */
142 /* 16 - BYTE: Number of digits after decimal in currency */
143 buffer[16] = 0; /* FIXME: Get from locale */
145 /* 17 - BYTE: Time format
146 * bit 0 = 0 if 12-hour clock
149 buffer[17] = 1; /* FIXME: Get from locale */
151 /* 18 - DWORD: Address of case map routine */
152 *(DWORD*)(buffer + 18) = 0; /* FIXME: ptr to case map routine */
154 /* 22 - BYTE[2]: ASCIIZ data-list separator */
155 buffer[22] = ','; /* FIXME: Get from locale */
158 /* 24 - BYTE[10]: Reserved */
159 memset( buffer + 24, 0, 10 );
163 /***********************************************************************
166 * Initialize DOS heap.
168 static void INT21_FillHeap( INT21_HEAP *heap )
170 static const char terminators[] = "\"\\./[]:|<>+=;,";
176 heap->uppercase_size = 128;
177 for (i = 0; i < 128; i++)
178 heap->uppercase_table[i] = toupper( 128 + i );
183 heap->lowercase_size = 256;
184 for (i = 0; i < 256; i++)
185 heap->lowercase_table[i] = tolower( i );
190 heap->collating_size = 256;
191 for (i = 0; i < 256; i++)
192 heap->collating_table[i] = i;
197 heap->filename_size = 8 + strlen(terminators);
198 heap->filename_illegal_size = strlen(terminators);
199 strcpy( heap->filename_illegal_table, terminators );
201 heap->filename_reserved1 = 0x01;
202 heap->filename_lowest = 0; /* FIXME: correct value? */
203 heap->filename_highest = 0xff; /* FIXME: correct value? */
204 heap->filename_reserved2 = 0x00;
205 heap->filename_exclude_first = 0x00; /* FIXME: correct value? */
206 heap->filename_exclude_last = 0x00; /* FIXME: correct value? */
207 heap->filename_reserved3 = 0x02;
210 * DBCS lead byte table. This table is empty.
213 memset( heap->dbcs_table, 0, sizeof(heap->dbcs_table) );
216 * Initialize InDos flag.
218 heap->misc_indos = 0;
222 /***********************************************************************
223 * INT21_GetHeapSelector
225 * Get segment/selector for DOS heap (INT21_HEAP).
226 * Creates and initializes heap on first call.
228 static WORD INT21_GetHeapSelector( CONTEXT86 *context )
230 static WORD heap_segment = 0;
231 static WORD heap_selector = 0;
232 static BOOL heap_initialized = FALSE;
234 if (!heap_initialized)
236 INT21_HEAP *ptr = DOSVM_AllocDataUMB( sizeof(INT21_HEAP),
239 INT21_FillHeap( ptr );
240 heap_initialized = TRUE;
243 if (!ISV86(context) && DOSVM_IsWin16())
244 return heap_selector;
250 /***********************************************************************
251 * INT21_ExtendedCountryInformation
253 * Handler for function 0x65.
255 static void INT21_ExtendedCountryInformation( CONTEXT86 *context )
257 BYTE *dataptr = CTX_SEG_OFF_TO_LIN( context, context->SegEs, context->Edi );
259 TRACE( "GET EXTENDED COUNTRY INFORMATION, subfunction %02x\n",
263 * Check subfunctions that are passed country and code page.
265 if (AL_reg(context) >= 0x01 && AL_reg(context) <= 0x07)
267 WORD country = DX_reg(context);
268 WORD codepage = BX_reg(context);
270 if (country != 0xffff && country != INT21_GetSystemCountryCode())
271 FIXME( "Requested info on non-default country %04x\n", country );
273 if (codepage != 0xffff && codepage != GetOEMCP())
274 FIXME( "Requested info on non-default code page %04x\n", codepage );
277 switch (AL_reg(context)) {
278 case 0x00: /* SET GENERAL INTERNATIONALIZATION INFO */
279 INT_BARF( context, 0x21 );
280 SET_CFLAG( context );
283 case 0x01: /* GET GENERAL INTERNATIONALIZATION INFO */
284 TRACE( "Get general internationalization info\n" );
285 dataptr[0] = 0x01; /* Info ID */
286 *(WORD*)(dataptr+1) = 38; /* Size of the following info */
287 *(WORD*)(dataptr+3) = INT21_GetSystemCountryCode(); /* Country ID */
288 *(WORD*)(dataptr+5) = GetOEMCP(); /* Code page */
289 INT21_FillCountryInformation( dataptr + 7 );
290 SET_CX( context, 41 ); /* Size of returned info */
293 case 0x02: /* GET POINTER TO UPPERCASE TABLE */
294 case 0x04: /* GET POINTER TO FILENAME UPPERCASE TABLE */
295 TRACE( "Get pointer to uppercase table\n" );
296 dataptr[0] = AL_reg(context); /* Info ID */
297 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
298 offsetof(INT21_HEAP, uppercase_size) );
299 SET_CX( context, 5 ); /* Size of returned info */
302 case 0x03: /* GET POINTER TO LOWERCASE TABLE */
303 TRACE( "Get pointer to lowercase table\n" );
304 dataptr[0] = 0x03; /* Info ID */
305 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
306 offsetof(INT21_HEAP, lowercase_size) );
307 SET_CX( context, 5 ); /* Size of returned info */
310 case 0x05: /* GET POINTER TO FILENAME TERMINATOR TABLE */
311 TRACE("Get pointer to filename terminator table\n");
312 dataptr[0] = 0x05; /* Info ID */
313 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
314 offsetof(INT21_HEAP, filename_size) );
315 SET_CX( context, 5 ); /* Size of returned info */
318 case 0x06: /* GET POINTER TO COLLATING SEQUENCE TABLE */
319 TRACE("Get pointer to collating sequence table\n");
320 dataptr[0] = 0x06; /* Info ID */
321 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
322 offsetof(INT21_HEAP, collating_size) );
323 SET_CX( context, 5 ); /* Size of returned info */
326 case 0x07: /* GET POINTER TO DBCS LEAD BYTE TABLE */
327 TRACE("Get pointer to DBCS lead byte table\n");
328 dataptr[0] = 0x07; /* Info ID */
329 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
330 offsetof(INT21_HEAP, dbcs_size) );
331 SET_CX( context, 5 ); /* Size of returned info */
334 case 0x20: /* CAPITALIZE CHARACTER */
335 case 0xa0: /* CAPITALIZE FILENAME CHARACTER */
336 TRACE("Convert char to uppercase\n");
337 SET_DL( context, toupper(DL_reg(context)) );
340 case 0x21: /* CAPITALIZE STRING */
341 case 0xa1: /* CAPITALIZE COUNTED FILENAME STRING */
342 TRACE("Convert string to uppercase with length\n");
344 char *ptr = (char *)CTX_SEG_OFF_TO_LIN( context,
347 WORD len = CX_reg(context);
348 while (len--) { *ptr = toupper(*ptr); ptr++; }
352 case 0x22: /* CAPITALIZE ASCIIZ STRING */
353 case 0xa2: /* CAPITALIZE ASCIIZ FILENAME */
354 TRACE("Convert ASCIIZ string to uppercase\n");
355 _strupr( (LPSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx) );
358 case 0x23: /* DETERMINE IF CHARACTER REPRESENTS YES/NO RESPONSE */
359 INT_BARF( context, 0x21 );
360 SET_CFLAG( context );
364 INT_BARF( context, 0x21 );
371 /***********************************************************************
374 * Handler for functions 0x51 and 0x62.
376 static void INT21_GetPSP( CONTEXT86 *context )
378 TRACE( "GET CURRENT PSP ADDRESS (%02x)\n", AH_reg(context) );
381 * FIXME: should we return the original DOS PSP upon
384 if (!ISV86(context) && DOSVM_IsWin16())
385 SET_BX( context, LOWORD(GetCurrentPDB16()) );
387 SET_BX( context, DOSVM_psp );
391 /***********************************************************************
394 * Handler for function 0x44.
396 static void INT21_Ioctl( CONTEXT86 *context )
398 static const WCHAR emmxxxx0W[] = {'E','M','M','X','X','X','X','0',0};
399 const DOS_DEVICE *dev = DOSFS_GetDeviceByHandle(
400 DosFileHandleToWin32Handle(BX_reg(context)) );
402 if (dev && !strcmpiW( dev->name, emmxxxx0W )) {
403 EMS_Ioctl_Handler(context);
407 switch (AL_reg(context))
409 case 0x0b: /* SET SHARING RETRY COUNT */
410 TRACE("IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
411 CX_reg(context), DX_reg(context));
412 if (!CX_reg(context))
414 SET_AX( context, 1 );
418 DOSMEM_LOL()->sharing_retry_delay = CX_reg(context);
419 if (!DX_reg(context))
420 DOSMEM_LOL()->sharing_retry_count = DX_reg(context);
421 RESET_CFLAG(context);
424 INT_Int21Handler( context );
429 /***********************************************************************
430 * INT21_GetExtendedError
432 static void INT21_GetExtendedError( CONTEXT86 *context )
434 BYTE class, action, locus;
435 WORD error = GetLastError();
440 class = action = locus = 0;
442 case ERROR_DIR_NOT_EMPTY:
447 case ERROR_ACCESS_DENIED:
448 class = EC_AccessDenied;
452 case ERROR_CANNOT_MAKE:
453 class = EC_AccessDenied;
457 case ERROR_DISK_FULL:
458 case ERROR_HANDLE_DISK_FULL:
459 class = EC_MediaError;
463 case ERROR_FILE_EXISTS:
464 case ERROR_ALREADY_EXISTS:
469 case ERROR_FILE_NOT_FOUND:
474 case ER_GeneralFailure:
475 class = EC_SystemFailure;
479 case ERROR_INVALID_DRIVE:
480 class = EC_MediaError;
484 case ERROR_INVALID_HANDLE:
485 class = EC_ProgramError;
489 case ERROR_LOCK_VIOLATION:
490 class = EC_AccessDenied;
494 case ERROR_NO_MORE_FILES:
495 class = EC_MediaError;
504 case ERROR_NOT_ENOUGH_MEMORY:
505 class = EC_OutOfResource;
509 case ERROR_PATH_NOT_FOUND:
519 case ERROR_SHARING_VIOLATION:
520 class = EC_Temporary;
524 case ERROR_TOO_MANY_OPEN_FILES:
525 class = EC_ProgramError;
530 FIXME("Unknown error %d\n", error );
531 class = EC_SystemFailure;
536 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
537 error, class, action, locus );
538 SET_AX( context, error );
539 SET_BH( context, class );
540 SET_BL( context, action );
541 SET_CH( context, locus );
545 /***********************************************************************
546 * DOSVM_Int21Handler (WINEDOS16.133)
548 * Interrupt 0x21 handler.
550 void WINAPI DOSVM_Int21Handler( CONTEXT86 *context )
552 BOOL bSetDOSExtendedError = FALSE;
554 TRACE( "AX=%04x BX=%04x CX=%04x DX=%04x "
555 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
556 AX_reg(context), BX_reg(context),
557 CX_reg(context), DX_reg(context),
558 SI_reg(context), DI_reg(context),
559 (WORD)context->SegDs, (WORD)context->SegEs,
563 * Extended error is used by (at least) functions 0x2f to 0x62.
564 * Function 0x59 returns extended error and error should not
565 * be cleared before handling the function.
567 if (AH_reg(context) >= 0x2f && AH_reg(context) != 0x59)
570 RESET_CFLAG(context); /* Not sure if this is a good idea. */
572 switch(AH_reg(context))
574 case 0x00: /* TERMINATE PROGRAM */
575 TRACE("TERMINATE PROGRAM\n");
579 MZ_Exit( context, FALSE, 0 );
582 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
585 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
586 DOSVM_Int16ReadChar(&ascii, NULL, FALSE);
587 SET_AL( context, ascii );
588 DOSVM_PutChar(AL_reg(context));
592 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
593 TRACE("Write Character to Standard Output\n");
594 DOSVM_PutChar(DL_reg(context));
597 case 0x03: /* READ CHARACTER FROM STDAUX */
598 case 0x04: /* WRITE CHARACTER TO STDAUX */
599 case 0x05: /* WRITE CHARACTER TO PRINTER */
600 INT_BARF( context, 0x21 );
603 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
604 /* FIXME: Use DOSDEV_Peek/Read/Write(DOSDEV_Console(),...) !! */
605 if (DL_reg(context) == 0xff) {
606 static char scan = 0;
607 TRACE("Direct Console Input\n");
609 /* return pending scancode */
610 SET_AL( context, scan );
611 RESET_ZFLAG(context);
615 if (DOSVM_Int16ReadChar(&ascii,&scan,TRUE)) {
616 DOSVM_Int16ReadChar(&ascii,&scan,FALSE);
617 /* return ASCII code */
618 SET_AL( context, ascii );
619 RESET_ZFLAG(context);
620 /* return scan code on next call only if ascii==0 */
623 /* nothing pending, clear everything */
624 SET_AL( context, 0 );
626 scan = 0; /* just in case */
630 TRACE("Direct Console Output\n");
631 DOSVM_PutChar(DL_reg(context));
635 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
638 /* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
639 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
640 DOSVM_Int16ReadChar(&ascii, NULL, FALSE);
641 SET_AL( context, ascii );
645 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
648 /* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
649 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
650 DOSVM_Int16ReadChar(&ascii, NULL, FALSE);
651 SET_AL( context, ascii );
655 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
656 INT_Int21Handler( context );
659 case 0x0a: /* BUFFERED INPUT */
660 INT_Int21Handler( context );
663 case 0x0b: /* GET STDIN STATUS */
664 TRACE( "GET STDIN STATUS\n" );
666 BIOSDATA *data = BIOS_DATA;
667 if(data->FirstKbdCharPtr == data->NextKbdCharPtr)
668 SET_AL( context, 0 );
670 SET_AL( context, 0xff );
674 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
676 BYTE al = AL_reg(context); /* Input function to execute after flush. */
678 TRACE( "FLUSH BUFFER AND READ STANDARD INPUT - 0x%02x\n", al );
680 /* FIXME: buffers are not flushed */
683 * If AL is one of 0x01, 0x06, 0x07, 0x08, or 0x0a,
684 * int21 function identified by AL will be called.
686 if(al == 0x01 || al == 0x06 || al == 0x07 || al == 0x08 || al == 0x0a)
688 SET_AH( context, al );
689 DOSVM_Int21Handler( context );
694 case 0x0d: /* DISK BUFFER FLUSH */
695 TRACE("DISK BUFFER FLUSH ignored\n");
698 case 0x0e: /* SELECT DEFAULT DRIVE */
699 INT_Int21Handler( context );
702 case 0x0f: /* OPEN FILE USING FCB */
703 case 0x10: /* CLOSE FILE USING FCB */
704 INT_BARF( context, 0x21 );
707 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
708 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
709 case 0x13: /* DELETE FILE USING FCB */
710 INT_Int21Handler( context );
713 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
714 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
715 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
716 INT_BARF( context, 0x21 );
719 case 0x17: /* RENAME FILE USING FCB */
720 INT_Int21Handler( context );
723 case 0x18: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
724 SET_AL( context, 0 );
727 case 0x19: /* GET CURRENT DEFAULT DRIVE */
728 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
729 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
730 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
731 INT_Int21Handler( context );
734 case 0x1d: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
735 case 0x1e: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
736 SET_AL( context, 0 );
739 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
740 INT_Int21Handler( context );
743 case 0x20: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
744 SET_AL( context, 0 );
747 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
748 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
749 case 0x23: /* GET FILE SIZE FOR FCB */
750 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
751 INT_BARF( context, 0x21 );
754 case 0x25: /* SET INTERRUPT VECTOR */
755 TRACE("SET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
757 FARPROC16 ptr = (FARPROC16)MAKESEGPTR( context->SegDs, DX_reg(context) );
758 if (!ISV86(context) && DOSVM_IsWin16())
759 DOSVM_SetPMHandler16( AL_reg(context), ptr );
761 DOSVM_SetRMHandler( AL_reg(context), ptr );
765 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
766 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
767 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
768 INT_BARF( context, 0x21 );
771 case 0x29: /* PARSE FILENAME INTO FCB */
772 INT_Int21Handler( context );
775 case 0x2a: /* GET SYSTEM DATE */
776 TRACE( "GET SYSTEM DATE\n" );
779 GetLocalTime( &systime );
780 SET_CX( context, systime.wYear );
781 SET_DH( context, systime.wMonth );
782 SET_DL( context, systime.wDay );
783 SET_AL( context, systime.wDayOfWeek );
787 case 0x2b: /* SET SYSTEM DATE */
788 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
789 DL_reg(context), DH_reg(context), CX_reg(context) );
790 SET_AL( context, 0 ); /* Let's pretend we succeeded */
793 case 0x2c: /* GET SYSTEM TIME */
794 TRACE( "GET SYSTEM TIME\n" );
797 GetLocalTime( &systime );
798 SET_CH( context, systime.wHour );
799 SET_CL( context, systime.wMinute );
800 SET_DH( context, systime.wSecond );
801 SET_DL( context, systime.wMilliseconds / 10 );
805 case 0x2d: /* SET SYSTEM TIME */
806 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
807 CH_reg(context), CL_reg(context),
808 DH_reg(context), DL_reg(context) );
809 SET_AL( context, 0 ); /* Let's pretend we succeeded */
812 case 0x2e: /* SET VERIFY FLAG */
813 TRACE("SET VERIFY FLAG ignored\n");
814 /* we cannot change the behaviour anyway, so just ignore it */
817 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
818 case 0x30: /* GET DOS VERSION */
819 INT_Int21Handler( context );
822 case 0x31: /* TERMINATE AND STAY RESIDENT */
823 FIXME("TERMINATE AND STAY RESIDENT stub\n");
826 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
827 case 0x33: /* MULTIPLEXED */
828 INT_Int21Handler( context );
831 case 0x34: /* GET ADDRESS OF INDOS FLAG */
832 TRACE( "GET ADDRESS OF INDOS FLAG\n" );
833 context->SegEs = INT21_GetHeapSelector( context );
834 SET_BX( context, offsetof(INT21_HEAP, misc_indos) );
837 case 0x35: /* GET INTERRUPT VECTOR */
838 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
841 if (!ISV86(context) && DOSVM_IsWin16())
842 addr = DOSVM_GetPMHandler16( AL_reg(context) );
844 addr = DOSVM_GetRMHandler( AL_reg(context) );
845 context->SegEs = SELECTOROF(addr);
846 SET_BX( context, OFFSETOF(addr) );
850 case 0x36: /* GET FREE DISK SPACE */
851 case 0x37: /* SWITCHAR */
852 INT_Int21Handler( context );
855 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
856 TRACE( "GET COUNTRY-SPECIFIC INFORMATION\n" );
859 WORD country = AL_reg(context);
861 country = BX_reg(context);
862 if (country != INT21_GetSystemCountryCode())
863 FIXME( "Requested info on non-default country %04x\n", country );
865 INT21_FillCountryInformation( CTX_SEG_OFF_TO_LIN(context,
868 SET_AX( context, INT21_GetSystemCountryCode() );
869 SET_BX( context, INT21_GetSystemCountryCode() );
872 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
873 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
874 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
875 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
876 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
877 case 0x3e: /* "CLOSE" - CLOSE FILE */
878 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
879 INT_Int21Handler( context );
882 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
883 /* Writes to stdout are handled here. */
884 if (!DOSVM_IsWin16() && BX_reg(context) == 1) {
885 BYTE *ptr = CTX_SEG_OFF_TO_LIN(context,
890 for(i=0; i<CX_reg(context); i++)
891 DOSVM_PutChar(ptr[i]);
893 INT_Int21Handler( context );
896 case 0x41: /* "UNLINK" - DELETE FILE */
897 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
898 case 0x43: /* FILE ATTRIBUTES */
899 INT_Int21Handler( context );
902 case 0x44: /* IOCTL */
903 INT21_Ioctl( context );
906 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
907 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
908 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
909 INT_Int21Handler( context );
912 case 0x48: /* ALLOCATE MEMORY */
913 TRACE( "ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context) );
916 DWORD bytes = (DWORD)BX_reg(context) << 4;
918 if (!ISV86(context) && DOSVM_IsWin16())
920 DWORD rv = GlobalDOSAlloc16( bytes );
921 selector = LOWORD( rv );
924 DOSMEM_GetBlock( bytes, &selector );
927 SET_AX( context, selector );
931 SET_AX( context, 0x0008 ); /* insufficient memory */
932 SET_BX( context, DOSMEM_Available() >> 4 );
937 case 0x49: /* FREE MEMORY */
938 TRACE( "FREE MEMORY segment %04lX\n", context->SegEs );
942 if (!ISV86(context) && DOSVM_IsWin16())
944 ok = !GlobalDOSFree16( context->SegEs );
946 /* If we don't reset ES_reg, we will fail in the relay code */
951 ok = DOSMEM_FreeBlock( (void*)((DWORD)context->SegEs << 4) );
955 TRACE("FREE MEMORY failed\n");
957 SET_AX( context, 0x0009 ); /* memory block address invalid */
962 case 0x4a: /* RESIZE MEMORY BLOCK */
963 INT_Int21Handler( context );
966 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
967 if(DOSVM_IsWin16()) {
968 INT_Int21Handler( context );
972 TRACE("EXEC %s\n", (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx ));
973 if (!MZ_Exec( context, CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx),
974 AL_reg(context), CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx) ))
976 SET_AX( context, GetLastError() );
981 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
982 TRACE( "EXIT with return code %d\n", AL_reg(context) );
984 ExitThread( AL_reg(context) );
986 MZ_Exit( context, FALSE, AL_reg(context) );
989 case 0x4d: /* GET RETURN CODE */
990 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
991 SET_AX( context, DOSVM_retval );
995 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
996 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
997 INT_Int21Handler( context );
1000 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1001 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1002 DOSVM_psp = BX_reg(context);
1005 case 0x51: /* GET PSP ADDRESS */
1006 INT21_GetPSP( context );
1009 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1010 if (!ISV86(context) && DOSVM_IsWin16())
1012 SEGPTR ptr = DOSMEM_LOL()->wine_pm_lol;
1013 context->SegEs = SELECTOROF(ptr);
1014 SET_BX( context, OFFSETOF(ptr) );
1018 SEGPTR ptr = DOSMEM_LOL()->wine_rm_lol;
1019 context->SegEs = SELECTOROF(ptr);
1020 SET_BX( context, OFFSETOF(ptr) );
1024 case 0x54: /* Get Verify Flag */
1025 TRACE("Get Verify Flag - Not Supported\n");
1026 SET_AL( context, 0x00 ); /* pretend we can tell. 00h = off 01h = on */
1029 case 0x56: /* "RENAME" - RENAME FILE */
1030 case 0x57: /* FILE DATE AND TIME */
1031 INT_Int21Handler( context );
1034 case 0x58: /* GET OR SET MEMORY ALLOCATION STRATEGY */
1035 TRACE( "GET OR SET MEMORY ALLOCATION STRATEGY, subfunction %d\n",
1037 switch (AL_reg(context))
1039 case 0x00: /* GET ALLOCATION STRATEGY */
1040 SET_AX( context, 1 ); /* low memory best fit */
1043 case 0x01: /* SET ALLOCATION STRATEGY */
1044 TRACE( "Set allocation strategy to %d - ignored\n",
1049 INT_BARF( context, 0x21 );
1054 case 0x59: /* GET EXTENDED ERROR INFO */
1055 INT21_GetExtendedError( context );
1058 case 0x5a: /* CREATE TEMPORARY FILE */
1059 case 0x5b: /* CREATE NEW FILE */
1060 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1061 case 0x5d: /* NETWORK 5D */
1062 case 0x5e: /* NETWORK 5E */
1063 case 0x5f: /* NETWORK 5F */
1064 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1065 INT_Int21Handler( context );
1068 case 0x61: /* UNUSED */
1069 SET_AL( context, 0 );
1072 case 0x62: /* GET PSP ADDRESS */
1073 INT21_GetPSP( context );
1076 case 0x63: /* MISC. LANGUAGE SUPPORT */
1077 switch (AL_reg(context)) {
1078 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1079 TRACE( "GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE\n" );
1080 context->SegDs = INT21_GetHeapSelector( context );
1081 SET_SI( context, offsetof(INT21_HEAP, dbcs_table) );
1082 SET_AL( context, 0 ); /* success */
1087 case 0x64: /* OS/2 DOS BOX */
1088 INT_BARF( context, 0x21 );
1092 case 0x65: /* EXTENDED COUNTRY INFORMATION */
1093 INT21_ExtendedCountryInformation( context );
1096 case 0x66: /* GLOBAL CODE PAGE TABLE */
1097 switch (AL_reg(context))
1100 TRACE( "GET GLOBAL CODE PAGE TABLE\n" );
1101 SET_BX( context, GetOEMCP() );
1102 SET_DX( context, GetOEMCP() );
1105 FIXME( "SET GLOBAL CODE PAGE TABLE, active %d, system %d - ignored\n",
1106 BX_reg(context), DX_reg(context) );
1111 case 0x67: /* SET HANDLE COUNT */
1112 TRACE( "SET HANDLE COUNT to %d\n", BX_reg(context) );
1113 if (SetHandleCount( BX_reg(context) ) < BX_reg(context) )
1114 bSetDOSExtendedError = TRUE;
1117 case 0x68: /* "FFLUSH" - COMMIT FILE */
1118 case 0x69: /* DISK SERIAL NUMBER */
1119 case 0x6a: /* COMMIT FILE */
1120 INT_Int21Handler( context );
1123 case 0x6b: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
1124 SET_AL( context, 0 );
1127 case 0x6c: /* EXTENDED OPEN/CREATE */
1128 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
1129 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1130 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
1131 case 0x73: /* MULTIPLEXED: Win95 OSR2/Win98 FAT32 calls */
1132 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1133 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1134 INT_Int21Handler( context );
1138 INT_BARF( context, 0x21 );
1141 } /* END OF SWITCH */
1143 /* Set general error condition. */
1144 if (bSetDOSExtendedError)
1146 SET_AX( context, GetLastError() );
1147 SET_CFLAG( context );
1150 /* Print error code if carry flag is set. */
1151 if (context->EFlags & 0x0001)
1152 TRACE("failed, error %ld\n", GetLastError() );
1154 TRACE( "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
1155 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1156 AX_reg(context), BX_reg(context),
1157 CX_reg(context), DX_reg(context),
1158 SI_reg(context), DI_reg(context),
1159 (WORD)context->SegDs, (WORD)context->SegEs,