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"
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
42 * FIXME: Delete this reference when all int21 code has been moved to winedos.
44 extern void WINAPI INT_Int21Handler( CONTEXT86 *context );
46 WINE_DEFAULT_DEBUG_CHANNEL(int21);
52 * Structure for DOS data that can be accessed directly from applications.
53 * Real and protected mode pointers will be returned to this structure so
54 * the structure must be correctly packed.
56 typedef struct _INT21_HEAP {
57 WORD uppercase_size; /* Size of the following table in bytes */
58 BYTE uppercase_table[128]; /* Uppercase equivalents of chars from 0x80 to 0xff. */
60 WORD lowercase_size; /* Size of the following table in bytes */
61 BYTE lowercase_table[256]; /* Lowercase equivalents of chars from 0x00 to 0xff. */
63 WORD collating_size; /* Size of the following table in bytes */
64 BYTE collating_table[256]; /* Values used to sort characters from 0x00 to 0xff. */
66 WORD filename_size; /* Size of the following filename data in bytes */
67 BYTE filename_reserved1; /* 0x01 for MS-DOS 3.30-6.00 */
68 BYTE filename_lowest; /* Lowest permissible character value for filename */
69 BYTE filename_highest; /* Highest permissible character value for filename */
70 BYTE filename_reserved2; /* 0x00 for MS-DOS 3.30-6.00 */
71 BYTE filename_exclude_first; /* First illegal character in permissible range */
72 BYTE filename_exclude_last; /* Last illegal character in permissible range */
73 BYTE filename_reserved3; /* 0x02 for MS-DOS 3.30-6.00 */
74 BYTE filename_illegal_size; /* Number of terminators in the following table */
75 BYTE filename_illegal_table[16]; /* Characters which terminate a filename */
77 WORD dbcs_size; /* Number of valid ranges in the following table */
78 BYTE dbcs_table[16]; /* Start/end bytes for N ranges and 00/00 as terminator */
80 BYTE misc_indos; /* Interrupt 21 nesting flag */
86 /***********************************************************************
89 * Reads a character from the standard input.
90 * Extended keycodes will be returned as two separate characters.
92 static BOOL INT21_ReadChar( BYTE *input, BOOL peek )
94 static BYTE pending_scan = 0;
99 *input = pending_scan;
108 if (!DOSVM_Int16ReadChar( &ascii, &scan, peek ))
120 /***********************************************************************
121 * INT21_GetSystemCountryCode
123 * Return DOS country code for default system locale.
125 static WORD INT21_GetSystemCountryCode()
128 * FIXME: Determine country code. We should probably use
129 * DOSCONF structure for that.
131 return GetSystemDefaultLangID();
135 /***********************************************************************
136 * INT21_FillCountryInformation
138 * Fill 34-byte buffer with country information data using
139 * default system locale.
141 static void INT21_FillCountryInformation( BYTE *buffer )
143 /* 00 - WORD: date format
148 *(WORD*)(buffer + 0) = 0; /* FIXME: Get from locale */
150 /* 02 - BYTE[5]: ASCIIZ currency symbol string */
151 buffer[2] = '$'; /* FIXME: Get from locale */
154 /* 07 - BYTE[2]: ASCIIZ thousands separator */
155 buffer[7] = 0; /* FIXME: Get from locale */
158 /* 09 - BYTE[2]: ASCIIZ decimal separator */
159 buffer[9] = '.'; /* FIXME: Get from locale */
162 /* 11 - BYTE[2]: ASCIIZ date separator */
163 buffer[11] = '/'; /* FIXME: Get from locale */
166 /* 13 - BYTE[2]: ASCIIZ time separator */
167 buffer[13] = ':'; /* FIXME: Get from locale */
170 /* 15 - BYTE: Currency format
171 * bit 2 = set if currency symbol replaces decimal point
172 * bit 1 = number of spaces between value and currency symbol
173 * bit 0 = 0 if currency symbol precedes value
174 * 1 if currency symbol follows value
176 buffer[15] = 0; /* FIXME: Get from locale */
178 /* 16 - BYTE: Number of digits after decimal in currency */
179 buffer[16] = 0; /* FIXME: Get from locale */
181 /* 17 - BYTE: Time format
182 * bit 0 = 0 if 12-hour clock
185 buffer[17] = 1; /* FIXME: Get from locale */
187 /* 18 - DWORD: Address of case map routine */
188 *(DWORD*)(buffer + 18) = 0; /* FIXME: ptr to case map routine */
190 /* 22 - BYTE[2]: ASCIIZ data-list separator */
191 buffer[22] = ','; /* FIXME: Get from locale */
194 /* 24 - BYTE[10]: Reserved */
195 memset( buffer + 24, 0, 10 );
199 /***********************************************************************
202 * Initialize DOS heap.
204 static void INT21_FillHeap( INT21_HEAP *heap )
206 static const char terminators[] = "\"\\./[]:|<>+=;,";
212 heap->uppercase_size = 128;
213 for (i = 0; i < 128; i++)
214 heap->uppercase_table[i] = toupper( 128 + i );
219 heap->lowercase_size = 256;
220 for (i = 0; i < 256; i++)
221 heap->lowercase_table[i] = tolower( i );
226 heap->collating_size = 256;
227 for (i = 0; i < 256; i++)
228 heap->collating_table[i] = i;
233 heap->filename_size = 8 + strlen(terminators);
234 heap->filename_illegal_size = strlen(terminators);
235 strcpy( heap->filename_illegal_table, terminators );
237 heap->filename_reserved1 = 0x01;
238 heap->filename_lowest = 0; /* FIXME: correct value? */
239 heap->filename_highest = 0xff; /* FIXME: correct value? */
240 heap->filename_reserved2 = 0x00;
241 heap->filename_exclude_first = 0x00; /* FIXME: correct value? */
242 heap->filename_exclude_last = 0x00; /* FIXME: correct value? */
243 heap->filename_reserved3 = 0x02;
246 * DBCS lead byte table. This table is empty.
249 memset( heap->dbcs_table, 0, sizeof(heap->dbcs_table) );
252 * Initialize InDos flag.
254 heap->misc_indos = 0;
258 /***********************************************************************
259 * INT21_GetHeapSelector
261 * Get segment/selector for DOS heap (INT21_HEAP).
262 * Creates and initializes heap on first call.
264 static WORD INT21_GetHeapSelector( CONTEXT86 *context )
266 static WORD heap_segment = 0;
267 static WORD heap_selector = 0;
268 static BOOL heap_initialized = FALSE;
270 if (!heap_initialized)
272 INT21_HEAP *ptr = DOSVM_AllocDataUMB( sizeof(INT21_HEAP),
275 INT21_FillHeap( ptr );
276 heap_initialized = TRUE;
279 if (!ISV86(context) && DOSVM_IsWin16())
280 return heap_selector;
286 /***********************************************************************
287 * INT21_BufferedInput
289 * Handler for function 0x0a.
291 * Reads a string of characters from standard input until
292 * enter key is pressed.
294 static void INT21_BufferedInput( CONTEXT86 *context )
296 BYTE *ptr = CTX_SEG_OFF_TO_LIN(context,
299 BYTE capacity = ptr[0]; /* includes CR */
300 BYTE length = 0; /* excludes CR */
302 TRACE( "BUFFERED INPUT (size=%d)\n", capacity );
305 * Return immediately if capacity is zero.
307 * FIXME: What to return to application?
313 * FIXME: Some documents state that
314 * ptr[1] holds number of chars from last input which
315 * may be recalled on entry, other documents do not mention
319 TRACE( "Handle old chars in buffer!\n" );
326 DOSVM_Int16ReadChar( &ascii, &scan, FALSE );
328 if (ascii == '\r' || ascii == '\n')
331 * FIXME: What should be echoed here?
333 DOSVM_PutChar( '\r' );
334 DOSVM_PutChar( '\n' );
336 ptr[2 + length] = '\r';
341 * FIXME: This function is supposed to support
342 * DOS editing keys...
346 * If the buffer becomes filled to within one byte of
347 * capacity, DOS rejects all further characters up to,
348 * but not including, the terminating carriage return.
350 if (ascii != 0 && length < capacity-1)
352 DOSVM_PutChar( ascii );
353 ptr[2 + length] = ascii;
360 /***********************************************************************
361 * INT21_ExtendedCountryInformation
363 * Handler for function 0x65.
365 static void INT21_ExtendedCountryInformation( CONTEXT86 *context )
367 BYTE *dataptr = CTX_SEG_OFF_TO_LIN( context, context->SegEs, context->Edi );
369 TRACE( "GET EXTENDED COUNTRY INFORMATION, subfunction %02x\n",
373 * Check subfunctions that are passed country and code page.
375 if (AL_reg(context) >= 0x01 && AL_reg(context) <= 0x07)
377 WORD country = DX_reg(context);
378 WORD codepage = BX_reg(context);
380 if (country != 0xffff && country != INT21_GetSystemCountryCode())
381 FIXME( "Requested info on non-default country %04x\n", country );
383 if (codepage != 0xffff && codepage != GetOEMCP())
384 FIXME( "Requested info on non-default code page %04x\n", codepage );
387 switch (AL_reg(context)) {
388 case 0x00: /* SET GENERAL INTERNATIONALIZATION INFO */
389 INT_BARF( context, 0x21 );
390 SET_CFLAG( context );
393 case 0x01: /* GET GENERAL INTERNATIONALIZATION INFO */
394 TRACE( "Get general internationalization info\n" );
395 dataptr[0] = 0x01; /* Info ID */
396 *(WORD*)(dataptr+1) = 38; /* Size of the following info */
397 *(WORD*)(dataptr+3) = INT21_GetSystemCountryCode(); /* Country ID */
398 *(WORD*)(dataptr+5) = GetOEMCP(); /* Code page */
399 INT21_FillCountryInformation( dataptr + 7 );
400 SET_CX( context, 41 ); /* Size of returned info */
403 case 0x02: /* GET POINTER TO UPPERCASE TABLE */
404 case 0x04: /* GET POINTER TO FILENAME UPPERCASE TABLE */
405 TRACE( "Get pointer to uppercase table\n" );
406 dataptr[0] = AL_reg(context); /* Info ID */
407 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
408 offsetof(INT21_HEAP, uppercase_size) );
409 SET_CX( context, 5 ); /* Size of returned info */
412 case 0x03: /* GET POINTER TO LOWERCASE TABLE */
413 TRACE( "Get pointer to lowercase table\n" );
414 dataptr[0] = 0x03; /* Info ID */
415 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
416 offsetof(INT21_HEAP, lowercase_size) );
417 SET_CX( context, 5 ); /* Size of returned info */
420 case 0x05: /* GET POINTER TO FILENAME TERMINATOR TABLE */
421 TRACE("Get pointer to filename terminator table\n");
422 dataptr[0] = 0x05; /* Info ID */
423 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
424 offsetof(INT21_HEAP, filename_size) );
425 SET_CX( context, 5 ); /* Size of returned info */
428 case 0x06: /* GET POINTER TO COLLATING SEQUENCE TABLE */
429 TRACE("Get pointer to collating sequence table\n");
430 dataptr[0] = 0x06; /* Info ID */
431 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
432 offsetof(INT21_HEAP, collating_size) );
433 SET_CX( context, 5 ); /* Size of returned info */
436 case 0x07: /* GET POINTER TO DBCS LEAD BYTE TABLE */
437 TRACE("Get pointer to DBCS lead byte table\n");
438 dataptr[0] = 0x07; /* Info ID */
439 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
440 offsetof(INT21_HEAP, dbcs_size) );
441 SET_CX( context, 5 ); /* Size of returned info */
444 case 0x20: /* CAPITALIZE CHARACTER */
445 case 0xa0: /* CAPITALIZE FILENAME CHARACTER */
446 TRACE("Convert char to uppercase\n");
447 SET_DL( context, toupper(DL_reg(context)) );
450 case 0x21: /* CAPITALIZE STRING */
451 case 0xa1: /* CAPITALIZE COUNTED FILENAME STRING */
452 TRACE("Convert string to uppercase with length\n");
454 char *ptr = (char *)CTX_SEG_OFF_TO_LIN( context,
457 WORD len = CX_reg(context);
458 while (len--) { *ptr = toupper(*ptr); ptr++; }
462 case 0x22: /* CAPITALIZE ASCIIZ STRING */
463 case 0xa2: /* CAPITALIZE ASCIIZ FILENAME */
464 TRACE("Convert ASCIIZ string to uppercase\n");
465 _strupr( (LPSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx) );
468 case 0x23: /* DETERMINE IF CHARACTER REPRESENTS YES/NO RESPONSE */
469 INT_BARF( context, 0x21 );
470 SET_CFLAG( context );
474 INT_BARF( context, 0x21 );
481 /***********************************************************************
484 * Handler for function 0x57.
486 static BOOL INT21_FileDateTime( CONTEXT86 *context )
488 HANDLE handle = DosFileHandleToWin32Handle(BX_reg(context));
492 switch (AL_reg(context)) {
493 case 0x00: /* Get last-written stamp */
494 TRACE( "GET FILE LAST-WRITTEN DATE AND TIME, handle %d\n",
497 if (!GetFileTime( handle, NULL, NULL, &filetime ))
499 FileTimeToDosDateTime( &filetime, &date, &time );
500 SET_DX( context, date );
501 SET_CX( context, time );
505 case 0x01: /* Set last-written stamp */
506 TRACE( "SET FILE LAST-WRITTEN DATE AND TIME, handle %d\n",
509 DosDateTimeToFileTime( DX_reg(context),
512 if (!SetFileTime( handle, NULL, NULL, &filetime ))
517 case 0x04: /* Get last access stamp, DOS 7 */
518 TRACE( "GET FILE LAST ACCESS DATE AND TIME, handle %d\n",
521 if (!GetFileTime( handle, NULL, &filetime, NULL ))
523 FileTimeToDosDateTime( &filetime, &date, &time );
524 SET_DX( context, date );
525 SET_CX( context, time );
529 case 0x05: /* Set last access stamp, DOS 7 */
530 TRACE( "SET FILE LAST ACCESS DATE AND TIME, handle %d\n",
533 DosDateTimeToFileTime( DX_reg(context),
536 if (!SetFileTime( handle, NULL, &filetime, NULL ))
541 case 0x06: /* Get creation stamp, DOS 7 */
542 TRACE( "GET FILE CREATION DATE AND TIME, handle %d\n",
545 if (!GetFileTime( handle, &filetime, NULL, NULL ))
547 FileTimeToDosDateTime( &filetime, &date, &time );
548 SET_DX( context, date );
549 SET_CX( context, time );
551 * FIXME: SI has number of 10-millisecond units past time in CX.
553 SET_SI( context, 0 );
557 case 0x07: /* Set creation stamp, DOS 7 */
558 TRACE( "SET FILE CREATION DATE AND TIME, handle %d\n",
562 * FIXME: SI has number of 10-millisecond units past time in CX.
564 DosDateTimeToFileTime( DX_reg(context),
567 if (!SetFileTime( handle, &filetime, NULL, NULL ))
573 INT_BARF( context, 0x21 );
581 /***********************************************************************
584 * Handler for functions 0x51 and 0x62.
586 static void INT21_GetPSP( CONTEXT86 *context )
588 TRACE( "GET CURRENT PSP ADDRESS (%02x)\n", AH_reg(context) );
591 * FIXME: should we return the original DOS PSP upon
594 if (!ISV86(context) && DOSVM_IsWin16())
595 SET_BX( context, LOWORD(GetCurrentPDB16()) );
597 SET_BX( context, DOSVM_psp );
601 /***********************************************************************
604 * Handler for block device IOCTLs.
606 static void INT21_Ioctl_Block( CONTEXT86 *context )
608 INT_Int21Handler( context );
612 /***********************************************************************
615 * Handler for character device IOCTLs.
617 static void INT21_Ioctl_Char( CONTEXT86 *context )
619 static const WCHAR emmxxxx0W[] = {'E','M','M','X','X','X','X','0',0};
620 static const WCHAR scsimgrW[] = {'S','C','S','I','M','G','R','$',0};
622 HANDLE handle = DosFileHandleToWin32Handle(BX_reg(context));
623 const DOS_DEVICE *dev = DOSFS_GetDeviceByHandle(handle);
625 if (dev && !strcmpiW( dev->name, emmxxxx0W ))
627 EMS_Ioctl_Handler(context);
631 if (dev && !strcmpiW( dev->name, scsimgrW ) && AL_reg(context) == 2)
633 DOSVM_ASPIHandler(context);
637 INT_Int21Handler( context );
641 /***********************************************************************
644 * Handler for function 0x44.
646 static void INT21_Ioctl( CONTEXT86 *context )
648 switch (AL_reg(context))
654 INT21_Ioctl_Char( context );
659 INT21_Ioctl_Block( context );
664 INT21_Ioctl_Char( context );
669 INT21_Ioctl_Block( context );
673 INT21_Ioctl_Char( context );
676 case 0x0b: /* SET SHARING RETRY COUNT */
677 TRACE( "SET SHARING RETRY COUNT: Pause %d, retries %d.\n",
678 CX_reg(context), DX_reg(context) );
679 if (!CX_reg(context))
681 SET_AX( context, 1 );
682 SET_CFLAG( context );
686 DOSMEM_LOL()->sharing_retry_delay = CX_reg(context);
688 DOSMEM_LOL()->sharing_retry_count = DX_reg(context);
689 RESET_CFLAG( context );
694 INT21_Ioctl_Char( context );
700 INT21_Ioctl_Block( context );
704 INT21_Ioctl_Char( context );
708 INT21_Ioctl_Block( context );
711 case 0x12: /* DR DOS - DETERMINE DOS TYPE (OBSOLETE FUNCTION) */
712 TRACE( "DR DOS - DETERMINE DOS TYPE (OBSOLETE FUNCTION)\n" );
713 SET_CFLAG(context); /* Error / This is not DR DOS. */
714 SET_AX( context, 0x0001 ); /* Invalid function */
717 case 0x52: /* DR DOS - DETERMINE DOS TYPE */
718 TRACE( "DR DOS - DETERMINE DOS TYPE\n" );
719 SET_CFLAG(context); /* Error / This is not DR DOS. */
720 SET_AX( context, 0x0001 ); /* Invalid function */
723 case 0xe0: /* Sun PC-NFS API */
724 TRACE( "Sun PC-NFS API\n" );
729 INT_BARF( context, 0x21 );
734 /***********************************************************************
737 * Handler for function 0x71.
739 static void INT21_LongFilename( CONTEXT86 *context )
741 BOOL bSetDOSExtendedError = FALSE;
743 if (HIBYTE(HIWORD(GetVersion16())) < 0x07)
745 TRACE( "LONG FILENAME - functions supported only under DOS7\n" );
746 SET_CFLAG( context );
747 SET_AL( context, 0 );
751 switch (AL_reg(context))
753 case 0x0d: /* RESET DRIVE */
754 case 0x39: /* LONG FILENAME - MAKE DIRECTORY */
755 INT_Int21Handler( context );
758 case 0x3a: /* LONG FILENAME - REMOVE DIRECTORY */
760 WCHAR dirW[MAX_PATH];
761 char *dirA = CTX_SEG_OFF_TO_LIN(context,
762 context->SegDs, context->Edx);
764 TRACE( "LONG FILENAME - REMOVE DIRECTORY %s\n", dirA );
765 MultiByteToWideChar(CP_OEMCP, 0, dirA, -1, dirW, MAX_PATH);
767 if (!RemoveDirectoryW( dirW ))
768 bSetDOSExtendedError = TRUE;
772 case 0x3b: /* LONG FILENAME - CHANGE DIRECTORY */
773 INT_Int21Handler( context );
776 case 0x41: /* LONG FILENAME - DELETE FILE */
778 WCHAR fileW[MAX_PATH];
779 char *fileA = CTX_SEG_OFF_TO_LIN(context,
780 context->SegDs, context->Edx);
782 TRACE( "LONG FILENAME - DELETE FILE %s\n", fileA );
783 MultiByteToWideChar(CP_OEMCP, 0, fileA, -1, fileW, MAX_PATH);
785 if (!DeleteFileW( fileW ))
786 bSetDOSExtendedError = TRUE;
790 case 0x43: /* LONG FILENAME - EXTENDED GET/SET FILE ATTRIBUTES */
791 case 0x47: /* LONG FILENAME - GET CURRENT DIRECTORY */
792 case 0x4e: /* LONG FILENAME - FIND FIRST MATCHING FILE */
793 case 0x4f: /* LONG FILENAME - FIND NEXT MATCHING FILE */
794 INT_Int21Handler( context );
797 case 0x56: /* LONG FILENAME - RENAME FILE */
799 WCHAR fromW[MAX_PATH];
801 char *fromA = CTX_SEG_OFF_TO_LIN(context,
802 context->SegDs,context->Edx);
803 char *toA = CTX_SEG_OFF_TO_LIN(context,
804 context->SegEs,context->Edi);
806 TRACE( "LONG FILENAME - RENAME FILE %s to %s\n", fromA, toA );
807 MultiByteToWideChar(CP_OEMCP, 0, fromA, -1, fromW, MAX_PATH);
808 MultiByteToWideChar(CP_OEMCP, 0, toA, -1, toW, MAX_PATH);
810 if (!MoveFileW( fromW, toW ))
811 bSetDOSExtendedError = TRUE;
815 case 0x60: /* LONG FILENAME - CONVERT PATH */
816 case 0x6c: /* LONG FILENAME - CREATE OR OPEN FILE */
817 case 0xa0: /* LONG FILENAME - GET VOLUME INFORMATION */
818 case 0xa1: /* LONG FILENAME - "FindClose" - TERMINATE DIRECTORY SEARCH */
819 case 0xa6: /* LONG FILENAME - GET FILE INFO BY HANDLE */
820 case 0xa7: /* LONG FILENAME - CONVERT TIME */
821 case 0xa8: /* LONG FILENAME - GENERATE SHORT FILENAME */
822 case 0xa9: /* LONG FILENAME - SERVER CREATE OR OPEN FILE */
823 case 0xaa: /* LONG FILENAME - SUBST */
824 INT_Int21Handler( context );
828 INT_BARF( context, 0x21 );
831 if (bSetDOSExtendedError)
833 SET_AX( context, GetLastError() );
834 SET_CFLAG( context );
839 /***********************************************************************
840 * INT21_GetExtendedError
842 static void INT21_GetExtendedError( CONTEXT86 *context )
844 BYTE class, action, locus;
845 WORD error = GetLastError();
850 class = action = locus = 0;
852 case ERROR_DIR_NOT_EMPTY:
857 case ERROR_ACCESS_DENIED:
858 class = EC_AccessDenied;
862 case ERROR_CANNOT_MAKE:
863 class = EC_AccessDenied;
867 case ERROR_DISK_FULL:
868 case ERROR_HANDLE_DISK_FULL:
869 class = EC_MediaError;
873 case ERROR_FILE_EXISTS:
874 case ERROR_ALREADY_EXISTS:
879 case ERROR_FILE_NOT_FOUND:
884 case ER_GeneralFailure:
885 class = EC_SystemFailure;
889 case ERROR_INVALID_DRIVE:
890 class = EC_MediaError;
894 case ERROR_INVALID_HANDLE:
895 class = EC_ProgramError;
899 case ERROR_LOCK_VIOLATION:
900 class = EC_AccessDenied;
904 case ERROR_NO_MORE_FILES:
905 class = EC_MediaError;
914 case ERROR_NOT_ENOUGH_MEMORY:
915 class = EC_OutOfResource;
919 case ERROR_PATH_NOT_FOUND:
929 case ERROR_SHARING_VIOLATION:
930 class = EC_Temporary;
934 case ERROR_TOO_MANY_OPEN_FILES:
935 class = EC_ProgramError;
940 FIXME("Unknown error %d\n", error );
941 class = EC_SystemFailure;
946 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
947 error, class, action, locus );
948 SET_AX( context, error );
949 SET_BH( context, class );
950 SET_BL( context, action );
951 SET_CH( context, locus );
955 /***********************************************************************
958 * Interrupt 0x21 handler.
960 void WINAPI DOSVM_Int21Handler( CONTEXT86 *context )
962 BOOL bSetDOSExtendedError = FALSE;
964 TRACE( "AX=%04x BX=%04x CX=%04x DX=%04x "
965 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
966 AX_reg(context), BX_reg(context),
967 CX_reg(context), DX_reg(context),
968 SI_reg(context), DI_reg(context),
969 (WORD)context->SegDs, (WORD)context->SegEs,
973 * Extended error is used by (at least) functions 0x2f to 0x62.
974 * Function 0x59 returns extended error and error should not
975 * be cleared before handling the function.
977 if (AH_reg(context) >= 0x2f && AH_reg(context) != 0x59)
980 RESET_CFLAG(context); /* Not sure if this is a good idea. */
982 switch(AH_reg(context))
984 case 0x00: /* TERMINATE PROGRAM */
985 TRACE("TERMINATE PROGRAM\n");
989 MZ_Exit( context, FALSE, 0 );
992 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
995 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
996 INT21_ReadChar( &ascii, FALSE );
997 SET_AL( context, ascii );
999 * FIXME: What to echo when extended keycodes are read?
1001 DOSVM_PutChar(AL_reg(context));
1005 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1006 TRACE("Write Character to Standard Output\n");
1007 DOSVM_PutChar(DL_reg(context));
1010 case 0x03: /* READ CHARACTER FROM STDAUX */
1011 case 0x04: /* WRITE CHARACTER TO STDAUX */
1012 case 0x05: /* WRITE CHARACTER TO PRINTER */
1013 INT_BARF( context, 0x21 );
1016 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1017 if (DL_reg(context) == 0xff)
1019 TRACE("Direct Console Input\n");
1021 if (INT21_ReadChar( NULL, TRUE ))
1024 INT21_ReadChar( &ascii, FALSE );
1025 SET_AL( context, ascii );
1026 RESET_ZFLAG( context );
1030 /* no character available */
1031 SET_AL( context, 0 );
1032 SET_ZFLAG( context );
1037 TRACE("Direct Console Output\n");
1038 DOSVM_PutChar(DL_reg(context));
1040 * At least DOS versions 2.1-7.0 return character
1041 * that was written in AL register.
1043 SET_AL( context, DL_reg(context) );
1047 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1050 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1051 INT21_ReadChar( &ascii, FALSE );
1052 SET_AL( context, ascii );
1056 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1059 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
1060 INT21_ReadChar( &ascii, FALSE );
1061 SET_AL( context, ascii );
1065 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1066 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1067 context->SegDs, DX_reg(context) );
1069 LPSTR data = CTX_SEG_OFF_TO_LIN( context,
1070 context->SegDs, context->Edx );
1074 * Do NOT use strchr() to calculate the string length,
1075 * as '\0' is valid string content, too!
1076 * Maybe we should check for non-'$' strings, but DOS doesn't.
1078 while (*p != '$') p++;
1080 if (DOSVM_IsWin16())
1081 WriteFile( DosFileHandleToWin32Handle(1),
1082 data, p - data, 0, 0 );
1084 for(; data != p; data++)
1085 DOSVM_PutChar( *data );
1087 SET_AL( context, '$' ); /* yes, '$' (0x24) gets returned in AL */
1091 case 0x0a: /* BUFFERED INPUT */
1092 INT21_BufferedInput( context );
1095 case 0x0b: /* GET STDIN STATUS */
1096 TRACE( "GET STDIN STATUS\n" );
1098 if (INT21_ReadChar( NULL, TRUE ))
1099 SET_AL( context, 0xff ); /* character available */
1101 SET_AL( context, 0 ); /* no character available */
1105 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
1107 BYTE al = AL_reg(context); /* Input function to execute after flush. */
1109 TRACE( "FLUSH BUFFER AND READ STANDARD INPUT - 0x%02x\n", al );
1111 /* FIXME: buffers are not flushed */
1114 * If AL is one of 0x01, 0x06, 0x07, 0x08, or 0x0a,
1115 * int21 function identified by AL will be called.
1117 if(al == 0x01 || al == 0x06 || al == 0x07 || al == 0x08 || al == 0x0a)
1119 SET_AH( context, al );
1120 DOSVM_Int21Handler( context );
1125 case 0x0d: /* DISK BUFFER FLUSH */
1126 TRACE("DISK BUFFER FLUSH ignored\n");
1129 case 0x0e: /* SELECT DEFAULT DRIVE */
1130 INT_Int21Handler( context );
1133 case 0x0f: /* OPEN FILE USING FCB */
1134 case 0x10: /* CLOSE FILE USING FCB */
1135 INT_BARF( context, 0x21 );
1138 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1139 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1140 INT_Int21Handler( context );
1143 case 0x13: /* DELETE FILE USING FCB */
1144 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1145 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1146 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1147 case 0x17: /* RENAME FILE USING FCB */
1148 INT_BARF( context, 0x21 );
1151 case 0x18: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
1152 SET_AL( context, 0 );
1155 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1156 INT_Int21Handler( context );
1159 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1160 TRACE( "SET DISK TRANSFER AREA ADDRESS %04lX:%04X\n",
1161 context->SegDs, DX_reg(context) );
1163 TDB *task = GlobalLock16( GetCurrentTask() );
1164 task->dta = MAKESEGPTR( context->SegDs, DX_reg(context) );
1168 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1169 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1170 INT_Int21Handler( context );
1173 case 0x1d: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
1174 case 0x1e: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
1175 SET_AL( context, 0 );
1178 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1179 INT_Int21Handler( context );
1182 case 0x20: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
1183 SET_AL( context, 0 );
1186 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1187 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1188 case 0x23: /* GET FILE SIZE FOR FCB */
1189 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1190 INT_BARF( context, 0x21 );
1193 case 0x25: /* SET INTERRUPT VECTOR */
1194 TRACE("SET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1196 FARPROC16 ptr = (FARPROC16)MAKESEGPTR( context->SegDs, DX_reg(context) );
1197 if (!ISV86(context) && DOSVM_IsWin16())
1198 DOSVM_SetPMHandler16( AL_reg(context), ptr );
1200 DOSVM_SetRMHandler( AL_reg(context), ptr );
1204 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1205 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1206 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1207 INT_BARF( context, 0x21 );
1210 case 0x29: /* PARSE FILENAME INTO FCB */
1211 INT_Int21Handler( context );
1214 case 0x2a: /* GET SYSTEM DATE */
1215 TRACE( "GET SYSTEM DATE\n" );
1218 GetLocalTime( &systime );
1219 SET_CX( context, systime.wYear );
1220 SET_DH( context, systime.wMonth );
1221 SET_DL( context, systime.wDay );
1222 SET_AL( context, systime.wDayOfWeek );
1226 case 0x2b: /* SET SYSTEM DATE */
1227 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
1228 DL_reg(context), DH_reg(context), CX_reg(context) );
1229 SET_AL( context, 0 ); /* Let's pretend we succeeded */
1232 case 0x2c: /* GET SYSTEM TIME */
1233 TRACE( "GET SYSTEM TIME\n" );
1236 GetLocalTime( &systime );
1237 SET_CH( context, systime.wHour );
1238 SET_CL( context, systime.wMinute );
1239 SET_DH( context, systime.wSecond );
1240 SET_DL( context, systime.wMilliseconds / 10 );
1244 case 0x2d: /* SET SYSTEM TIME */
1245 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1246 CH_reg(context), CL_reg(context),
1247 DH_reg(context), DL_reg(context) );
1248 SET_AL( context, 0 ); /* Let's pretend we succeeded */
1251 case 0x2e: /* SET VERIFY FLAG */
1252 TRACE("SET VERIFY FLAG ignored\n");
1253 /* we cannot change the behaviour anyway, so just ignore it */
1256 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1257 TRACE( "GET DISK TRANSFER AREA ADDRESS\n" );
1259 TDB *task = GlobalLock16( GetCurrentTask() );
1260 context->SegEs = SELECTOROF( task->dta );
1261 SET_BX( context, OFFSETOF( task->dta ) );
1265 case 0x30: /* GET DOS VERSION */
1266 TRACE( "GET DOS VERSION - %s requested\n",
1267 (AL_reg(context) == 0x00) ? "OEM number" : "version flag" );
1269 SET_AL( context, HIBYTE(HIWORD(GetVersion16())) ); /* major version */
1270 SET_AH( context, LOBYTE(HIWORD(GetVersion16())) ); /* minor version */
1272 if (AL_reg(context) == 0x00)
1273 SET_BH( context, 0xff ); /* OEM number => undefined */
1275 SET_BH( context, 0x08 ); /* version flag => DOS is in ROM */
1277 SET_BL( context, 0x12 ); /* 0x123456 is Wine's serial # */
1278 SET_CX( context, 0x3456 );
1281 case 0x31: /* TERMINATE AND STAY RESIDENT */
1282 FIXME("TERMINATE AND STAY RESIDENT stub\n");
1285 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1286 case 0x33: /* MULTIPLEXED */
1287 INT_Int21Handler( context );
1290 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1291 TRACE( "GET ADDRESS OF INDOS FLAG\n" );
1292 context->SegEs = INT21_GetHeapSelector( context );
1293 SET_BX( context, offsetof(INT21_HEAP, misc_indos) );
1296 case 0x35: /* GET INTERRUPT VECTOR */
1297 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1300 if (!ISV86(context) && DOSVM_IsWin16())
1301 addr = DOSVM_GetPMHandler16( AL_reg(context) );
1303 addr = DOSVM_GetRMHandler( AL_reg(context) );
1304 context->SegEs = SELECTOROF(addr);
1305 SET_BX( context, OFFSETOF(addr) );
1309 case 0x36: /* GET FREE DISK SPACE */
1310 INT_Int21Handler( context );
1313 case 0x37: /* SWITCHAR */
1315 switch (AL_reg(context))
1317 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1318 TRACE( "SWITCHAR - GET SWITCH CHARACTER\n" );
1319 SET_AL( context, 0x00 ); /* success*/
1320 SET_DL( context, '/' );
1322 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1323 FIXME( "SWITCHAR - SET SWITCH CHARACTER: %c\n",
1325 SET_AL( context, 0x00 ); /* success*/
1328 INT_BARF( context, 0x21 );
1334 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1335 TRACE( "GET COUNTRY-SPECIFIC INFORMATION\n" );
1336 if (AL_reg(context))
1338 WORD country = AL_reg(context);
1339 if (country == 0xff)
1340 country = BX_reg(context);
1341 if (country != INT21_GetSystemCountryCode())
1342 FIXME( "Requested info on non-default country %04x\n", country );
1344 INT21_FillCountryInformation( CTX_SEG_OFF_TO_LIN(context,
1347 SET_AX( context, INT21_GetSystemCountryCode() );
1348 SET_BX( context, INT21_GetSystemCountryCode() );
1351 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1352 INT_Int21Handler( context );
1355 case 0x3a: /* "RMDIR" - REMOVE DIRECTORY */
1357 WCHAR dirW[MAX_PATH];
1358 char *dirA = CTX_SEG_OFF_TO_LIN(context,
1359 context->SegDs, context->Edx);
1361 TRACE( "REMOVE DIRECTORY %s\n", dirA );
1363 MultiByteToWideChar(CP_OEMCP, 0, dirA, -1, dirW, MAX_PATH);
1365 if (!RemoveDirectoryW( dirW ))
1366 bSetDOSExtendedError = TRUE;
1370 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1371 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1372 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1373 INT_Int21Handler( context );
1376 case 0x3e: /* "CLOSE" - CLOSE FILE */
1377 TRACE( "CLOSE handle %d\n", BX_reg(context) );
1378 if (_lclose16( BX_reg(context) ) == HFILE_ERROR16)
1379 bSetDOSExtendedError = TRUE;
1382 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1383 INT_Int21Handler( context );
1386 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1387 TRACE( "WRITE from %04lX:%04X to handle %d for %d byte\n",
1388 context->SegDs, DX_reg(context),
1389 BX_reg(context), CX_reg(context) );
1391 BYTE *ptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
1393 if (!DOSVM_IsWin16() && BX_reg(context) == 1)
1396 for(i=0; i<CX_reg(context); i++)
1397 DOSVM_PutChar(ptr[i]);
1398 SET_AX(context, CX_reg(context));
1402 HFILE handle = (HFILE)DosFileHandleToWin32Handle(BX_reg(context));
1403 LONG result = _hwrite( handle, ptr, CX_reg(context) );
1404 if (result == HFILE_ERROR)
1405 bSetDOSExtendedError = TRUE;
1407 SET_AX( context, (WORD)result );
1412 case 0x41: /* "UNLINK" - DELETE FILE */
1414 WCHAR fileW[MAX_PATH];
1415 char *fileA = CTX_SEG_OFF_TO_LIN(context,
1419 TRACE( "UNLINK %s\n", fileA );
1420 MultiByteToWideChar(CP_OEMCP, 0, fileA, -1, fileW, MAX_PATH);
1422 if (!DeleteFileW( fileW ))
1423 bSetDOSExtendedError = TRUE;
1427 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1428 case 0x43: /* FILE ATTRIBUTES */
1429 INT_Int21Handler( context );
1432 case 0x44: /* IOCTL */
1433 INT21_Ioctl( context );
1436 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1437 TRACE( "DUPLICATE FILE HANDLE %d\n", BX_reg(context) );
1440 HFILE handle16 = HFILE_ERROR;
1442 if (DuplicateHandle( GetCurrentProcess(),
1443 DosFileHandleToWin32Handle(BX_reg(context)),
1444 GetCurrentProcess(),
1446 0, TRUE, DUPLICATE_SAME_ACCESS ))
1447 handle16 = Win32HandleToDosFileHandle(handle32);
1449 if (handle16 == HFILE_ERROR)
1450 bSetDOSExtendedError = TRUE;
1452 SET_AX( context, handle16 );
1456 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1457 TRACE( "FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1458 BX_reg(context), CX_reg(context) );
1459 if (FILE_Dup2( BX_reg(context), CX_reg(context) ) == HFILE_ERROR16)
1460 bSetDOSExtendedError = TRUE;
1463 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1464 INT_Int21Handler( context );
1467 case 0x48: /* ALLOCATE MEMORY */
1468 TRACE( "ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context) );
1471 DWORD bytes = (DWORD)BX_reg(context) << 4;
1473 if (!ISV86(context) && DOSVM_IsWin16())
1475 DWORD rv = GlobalDOSAlloc16( bytes );
1476 selector = LOWORD( rv );
1479 DOSMEM_GetBlock( bytes, &selector );
1482 SET_AX( context, selector );
1486 SET_AX( context, 0x0008 ); /* insufficient memory */
1487 SET_BX( context, DOSMEM_Available() >> 4 );
1492 case 0x49: /* FREE MEMORY */
1493 TRACE( "FREE MEMORY segment %04lX\n", context->SegEs );
1497 if (!ISV86(context) && DOSVM_IsWin16())
1499 ok = !GlobalDOSFree16( context->SegEs );
1501 /* If we don't reset ES_reg, we will fail in the relay code */
1506 ok = DOSMEM_FreeBlock( (void*)((DWORD)context->SegEs << 4) );
1510 TRACE("FREE MEMORY failed\n");
1512 SET_AX( context, 0x0009 ); /* memory block address invalid */
1517 case 0x4a: /* RESIZE MEMORY BLOCK */
1518 TRACE( "RESIZE MEMORY segment %04lX to %d paragraphs\n",
1519 context->SegEs, BX_reg(context) );
1521 DWORD newsize = (DWORD)BX_reg(context) << 4;
1523 if (!ISV86(context) && DOSVM_IsWin16())
1525 FIXME( "Resize memory block - unsupported under Win16\n" );
1529 LPVOID address = (void*)((DWORD)context->SegEs << 4);
1530 UINT blocksize = DOSMEM_ResizeBlock( address, newsize, FALSE );
1532 if (blocksize == (UINT)-1)
1534 SET_CFLAG( context );
1535 SET_AX( context, 0x0009 ); /* illegal address */
1537 else if(blocksize != newsize)
1539 SET_CFLAG( context );
1540 SET_AX( context, 0x0008 ); /* insufficient memory */
1541 SET_BX( context, blocksize >> 4 ); /* new block size */
1547 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1549 BYTE *program = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
1550 BYTE *paramblk = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
1552 TRACE( "EXEC %s\n", program );
1554 if (DOSVM_IsWin16())
1556 HINSTANCE16 instance = WinExec16( program, SW_NORMAL );
1559 SET_CFLAG( context );
1560 SET_AX( context, instance );
1565 if (!MZ_Exec( context, program, AL_reg(context), paramblk))
1566 bSetDOSExtendedError = TRUE;
1571 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1572 TRACE( "EXIT with return code %d\n", AL_reg(context) );
1573 if (DOSVM_IsWin16())
1574 ExitThread( AL_reg(context) );
1576 MZ_Exit( context, FALSE, AL_reg(context) );
1579 case 0x4d: /* GET RETURN CODE */
1580 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
1581 SET_AX( context, DOSVM_retval );
1585 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1586 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1587 INT_Int21Handler( context );
1590 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1591 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1592 DOSVM_psp = BX_reg(context);
1595 case 0x51: /* GET PSP ADDRESS */
1596 INT21_GetPSP( context );
1599 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1600 if (!ISV86(context) && DOSVM_IsWin16())
1602 SEGPTR ptr = DOSMEM_LOL()->wine_pm_lol;
1603 context->SegEs = SELECTOROF(ptr);
1604 SET_BX( context, OFFSETOF(ptr) );
1608 SEGPTR ptr = DOSMEM_LOL()->wine_rm_lol;
1609 context->SegEs = SELECTOROF(ptr);
1610 SET_BX( context, OFFSETOF(ptr) );
1614 case 0x54: /* Get Verify Flag */
1615 TRACE("Get Verify Flag - Not Supported\n");
1616 SET_AL( context, 0x00 ); /* pretend we can tell. 00h = off 01h = on */
1619 case 0x56: /* "RENAME" - RENAME FILE */
1621 WCHAR fromW[MAX_PATH];
1622 WCHAR toW[MAX_PATH];
1623 char *fromA = CTX_SEG_OFF_TO_LIN(context,
1624 context->SegDs,context->Edx);
1625 char *toA = CTX_SEG_OFF_TO_LIN(context,
1626 context->SegEs,context->Edi);
1628 TRACE( "RENAME %s to %s\n", fromA, toA );
1629 MultiByteToWideChar(CP_OEMCP, 0, fromA, -1, fromW, MAX_PATH);
1630 MultiByteToWideChar(CP_OEMCP, 0, toA, -1, toW, MAX_PATH);
1632 if (!MoveFileW( fromW, toW ))
1633 bSetDOSExtendedError = TRUE;
1637 case 0x57: /* FILE DATE AND TIME */
1638 if (!INT21_FileDateTime( context ))
1639 bSetDOSExtendedError = TRUE;
1642 case 0x58: /* GET OR SET MEMORY ALLOCATION STRATEGY */
1643 switch (AL_reg(context))
1645 case 0x00: /* GET MEMORY ALLOCATION STRATEGY */
1646 TRACE( "GET MEMORY ALLOCATION STRATEGY\n" );
1647 SET_AX( context, 0 ); /* low memory first fit */
1650 case 0x01: /* SET ALLOCATION STRATEGY */
1651 TRACE( "SET MEMORY ALLOCATION STRATEGY to %d - ignored\n",
1655 case 0x02: /* GET UMB LINK STATE */
1656 TRACE( "GET UMB LINK STATE\n" );
1657 SET_AL( context, 0 ); /* UMBs not part of DOS memory chain */
1660 case 0x03: /* SET UMB LINK STATE */
1661 TRACE( "SET UMB LINK STATE to %d - ignored\n",
1666 INT_BARF( context, 0x21 );
1670 case 0x59: /* GET EXTENDED ERROR INFO */
1671 INT21_GetExtendedError( context );
1674 case 0x5a: /* CREATE TEMPORARY FILE */
1675 case 0x5b: /* CREATE NEW FILE */
1676 INT_Int21Handler( context );
1679 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1681 DWORD offset = MAKELONG(DX_reg(context), CX_reg(context));
1682 DWORD length = MAKELONG(DI_reg(context), SI_reg(context));
1683 HANDLE handle = DosFileHandleToWin32Handle(BX_reg(context));
1685 switch (AL_reg(context))
1687 case 0x00: /* LOCK */
1688 TRACE( "lock handle %d offset %ld length %ld\n",
1689 BX_reg(context), offset, length );
1690 if (!LockFile( handle, offset, 0, length, 0 ))
1691 bSetDOSExtendedError = TRUE;
1694 case 0x01: /* UNLOCK */
1695 TRACE( "unlock handle %d offset %ld length %ld\n",
1696 BX_reg(context), offset, length );
1697 if (!UnlockFile( handle, offset, 0, length, 0 ))
1698 bSetDOSExtendedError = TRUE;
1702 INT_BARF( context, 0x21 );
1707 case 0x5d: /* NETWORK 5D */
1708 FIXME( "Network function 5D not implemented.\n" );
1709 SetLastError( ER_NoNetwork );
1710 bSetDOSExtendedError = TRUE;
1713 case 0x5e: /* NETWORK 5E */
1714 case 0x5f: /* NETWORK 5F */
1715 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1716 INT_Int21Handler( context );
1719 case 0x61: /* UNUSED */
1720 SET_AL( context, 0 );
1723 case 0x62: /* GET PSP ADDRESS */
1724 INT21_GetPSP( context );
1727 case 0x63: /* MISC. LANGUAGE SUPPORT */
1728 switch (AL_reg(context)) {
1729 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1730 TRACE( "GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE\n" );
1731 context->SegDs = INT21_GetHeapSelector( context );
1732 SET_SI( context, offsetof(INT21_HEAP, dbcs_table) );
1733 SET_AL( context, 0 ); /* success */
1738 case 0x64: /* OS/2 DOS BOX */
1739 INT_BARF( context, 0x21 );
1743 case 0x65: /* EXTENDED COUNTRY INFORMATION */
1744 INT21_ExtendedCountryInformation( context );
1747 case 0x66: /* GLOBAL CODE PAGE TABLE */
1748 switch (AL_reg(context))
1751 TRACE( "GET GLOBAL CODE PAGE TABLE\n" );
1752 SET_BX( context, GetOEMCP() );
1753 SET_DX( context, GetOEMCP() );
1756 FIXME( "SET GLOBAL CODE PAGE TABLE, active %d, system %d - ignored\n",
1757 BX_reg(context), DX_reg(context) );
1762 case 0x67: /* SET HANDLE COUNT */
1763 TRACE( "SET HANDLE COUNT to %d\n", BX_reg(context) );
1764 if (SetHandleCount( BX_reg(context) ) < BX_reg(context) )
1765 bSetDOSExtendedError = TRUE;
1768 case 0x68: /* "FFLUSH" - COMMIT FILE */
1769 TRACE( "FFLUSH - handle %d\n", BX_reg(context) );
1770 if (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context)) ))
1771 bSetDOSExtendedError = TRUE;
1774 case 0x69: /* DISK SERIAL NUMBER */
1775 INT_Int21Handler( context );
1778 case 0x6a: /* COMMIT FILE */
1779 TRACE( "COMMIT FILE - handle %d\n", BX_reg(context) );
1780 if (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context)) ))
1781 bSetDOSExtendedError = TRUE;
1784 case 0x6b: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
1785 SET_AL( context, 0 );
1788 case 0x6c: /* EXTENDED OPEN/CREATE */
1789 INT_Int21Handler( context );
1792 case 0x70: /* MSDOS 7 - GET/SET INTERNATIONALIZATION INFORMATION */
1793 FIXME( "MS-DOS 7 - GET/SET INTERNATIONALIZATION INFORMATION\n" );
1794 SET_CFLAG( context );
1795 SET_AL( context, 0 );
1798 case 0x71: /* MSDOS 7 - LONG FILENAME FUNCTIONS */
1799 INT21_LongFilename( context );
1802 case 0x73: /* MSDOS7 - FAT32 */
1803 INT_Int21Handler( context );
1806 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1807 TRACE( "CONNECTION SERVICES - GET CONNECTION NUMBER - ignored\n" );
1810 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1811 TRACE( "NOVELL NETWARE - RETURN SHELL VERSION - ignored\n" );
1815 INT_BARF( context, 0x21 );
1818 } /* END OF SWITCH */
1820 /* Set general error condition. */
1821 if (bSetDOSExtendedError)
1823 SET_AX( context, GetLastError() );
1824 SET_CFLAG( context );
1827 /* Print error code if carry flag is set. */
1828 if (context->EFlags & 0x0001)
1829 TRACE("failed, error %ld\n", GetLastError() );
1831 TRACE( "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
1832 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1833 AX_reg(context), BX_reg(context),
1834 CX_reg(context), DX_reg(context),
1835 SI_reg(context), DI_reg(context),
1836 (WORD)context->SegDs, (WORD)context->SegEs,