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 /***********************************************************************
735 * INT21_GetExtendedError
737 static void INT21_GetExtendedError( CONTEXT86 *context )
739 BYTE class, action, locus;
740 WORD error = GetLastError();
745 class = action = locus = 0;
747 case ERROR_DIR_NOT_EMPTY:
752 case ERROR_ACCESS_DENIED:
753 class = EC_AccessDenied;
757 case ERROR_CANNOT_MAKE:
758 class = EC_AccessDenied;
762 case ERROR_DISK_FULL:
763 case ERROR_HANDLE_DISK_FULL:
764 class = EC_MediaError;
768 case ERROR_FILE_EXISTS:
769 case ERROR_ALREADY_EXISTS:
774 case ERROR_FILE_NOT_FOUND:
779 case ER_GeneralFailure:
780 class = EC_SystemFailure;
784 case ERROR_INVALID_DRIVE:
785 class = EC_MediaError;
789 case ERROR_INVALID_HANDLE:
790 class = EC_ProgramError;
794 case ERROR_LOCK_VIOLATION:
795 class = EC_AccessDenied;
799 case ERROR_NO_MORE_FILES:
800 class = EC_MediaError;
809 case ERROR_NOT_ENOUGH_MEMORY:
810 class = EC_OutOfResource;
814 case ERROR_PATH_NOT_FOUND:
824 case ERROR_SHARING_VIOLATION:
825 class = EC_Temporary;
829 case ERROR_TOO_MANY_OPEN_FILES:
830 class = EC_ProgramError;
835 FIXME("Unknown error %d\n", error );
836 class = EC_SystemFailure;
841 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
842 error, class, action, locus );
843 SET_AX( context, error );
844 SET_BH( context, class );
845 SET_BL( context, action );
846 SET_CH( context, locus );
850 /***********************************************************************
853 * Interrupt 0x21 handler.
855 void WINAPI DOSVM_Int21Handler( CONTEXT86 *context )
857 BOOL bSetDOSExtendedError = FALSE;
859 TRACE( "AX=%04x BX=%04x CX=%04x DX=%04x "
860 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
861 AX_reg(context), BX_reg(context),
862 CX_reg(context), DX_reg(context),
863 SI_reg(context), DI_reg(context),
864 (WORD)context->SegDs, (WORD)context->SegEs,
868 * Extended error is used by (at least) functions 0x2f to 0x62.
869 * Function 0x59 returns extended error and error should not
870 * be cleared before handling the function.
872 if (AH_reg(context) >= 0x2f && AH_reg(context) != 0x59)
875 RESET_CFLAG(context); /* Not sure if this is a good idea. */
877 switch(AH_reg(context))
879 case 0x00: /* TERMINATE PROGRAM */
880 TRACE("TERMINATE PROGRAM\n");
884 MZ_Exit( context, FALSE, 0 );
887 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
890 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
891 INT21_ReadChar( &ascii, FALSE );
892 SET_AL( context, ascii );
894 * FIXME: What to echo when extended keycodes are read?
896 DOSVM_PutChar(AL_reg(context));
900 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
901 TRACE("Write Character to Standard Output\n");
902 DOSVM_PutChar(DL_reg(context));
905 case 0x03: /* READ CHARACTER FROM STDAUX */
906 case 0x04: /* WRITE CHARACTER TO STDAUX */
907 case 0x05: /* WRITE CHARACTER TO PRINTER */
908 INT_BARF( context, 0x21 );
911 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
912 if (DL_reg(context) == 0xff)
914 TRACE("Direct Console Input\n");
916 if (INT21_ReadChar( NULL, TRUE ))
919 INT21_ReadChar( &ascii, FALSE );
920 SET_AL( context, ascii );
921 RESET_ZFLAG( context );
925 /* no character available */
926 SET_AL( context, 0 );
927 SET_ZFLAG( context );
932 TRACE("Direct Console Output\n");
933 DOSVM_PutChar(DL_reg(context));
935 * At least DOS versions 2.1-7.0 return character
936 * that was written in AL register.
938 SET_AL( context, DL_reg(context) );
942 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
945 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
946 INT21_ReadChar( &ascii, FALSE );
947 SET_AL( context, ascii );
951 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
954 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
955 INT21_ReadChar( &ascii, FALSE );
956 SET_AL( context, ascii );
960 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
961 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
962 context->SegDs, DX_reg(context) );
964 LPSTR data = CTX_SEG_OFF_TO_LIN( context,
965 context->SegDs, context->Edx );
969 * Do NOT use strchr() to calculate the string length,
970 * as '\0' is valid string content, too!
971 * Maybe we should check for non-'$' strings, but DOS doesn't.
973 while (*p != '$') p++;
976 WriteFile( DosFileHandleToWin32Handle(1),
977 data, p - data, 0, 0 );
979 for(; data != p; data++)
980 DOSVM_PutChar( *data );
982 SET_AL( context, '$' ); /* yes, '$' (0x24) gets returned in AL */
986 case 0x0a: /* BUFFERED INPUT */
987 INT21_BufferedInput( context );
990 case 0x0b: /* GET STDIN STATUS */
991 TRACE( "GET STDIN STATUS\n" );
993 if (INT21_ReadChar( NULL, TRUE ))
994 SET_AL( context, 0xff ); /* character available */
996 SET_AL( context, 0 ); /* no character available */
1000 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
1002 BYTE al = AL_reg(context); /* Input function to execute after flush. */
1004 TRACE( "FLUSH BUFFER AND READ STANDARD INPUT - 0x%02x\n", al );
1006 /* FIXME: buffers are not flushed */
1009 * If AL is one of 0x01, 0x06, 0x07, 0x08, or 0x0a,
1010 * int21 function identified by AL will be called.
1012 if(al == 0x01 || al == 0x06 || al == 0x07 || al == 0x08 || al == 0x0a)
1014 SET_AH( context, al );
1015 DOSVM_Int21Handler( context );
1020 case 0x0d: /* DISK BUFFER FLUSH */
1021 TRACE("DISK BUFFER FLUSH ignored\n");
1024 case 0x0e: /* SELECT DEFAULT DRIVE */
1025 INT_Int21Handler( context );
1028 case 0x0f: /* OPEN FILE USING FCB */
1029 case 0x10: /* CLOSE FILE USING FCB */
1030 INT_BARF( context, 0x21 );
1033 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1034 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1035 INT_Int21Handler( context );
1038 case 0x13: /* DELETE FILE USING FCB */
1039 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1040 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1041 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1042 case 0x17: /* RENAME FILE USING FCB */
1043 INT_BARF( context, 0x21 );
1046 case 0x18: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
1047 SET_AL( context, 0 );
1050 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1051 INT_Int21Handler( context );
1054 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1055 TRACE( "SET DISK TRANSFER AREA ADDRESS %04lX:%04X\n",
1056 context->SegDs, DX_reg(context) );
1058 TDB *task = GlobalLock16( GetCurrentTask() );
1059 task->dta = MAKESEGPTR( context->SegDs, DX_reg(context) );
1063 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1064 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1065 INT_Int21Handler( context );
1068 case 0x1d: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
1069 case 0x1e: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
1070 SET_AL( context, 0 );
1073 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1074 INT_Int21Handler( context );
1077 case 0x20: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
1078 SET_AL( context, 0 );
1081 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1082 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1083 case 0x23: /* GET FILE SIZE FOR FCB */
1084 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1085 INT_BARF( context, 0x21 );
1088 case 0x25: /* SET INTERRUPT VECTOR */
1089 TRACE("SET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1091 FARPROC16 ptr = (FARPROC16)MAKESEGPTR( context->SegDs, DX_reg(context) );
1092 if (!ISV86(context) && DOSVM_IsWin16())
1093 DOSVM_SetPMHandler16( AL_reg(context), ptr );
1095 DOSVM_SetRMHandler( AL_reg(context), ptr );
1099 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1100 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1101 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1102 INT_BARF( context, 0x21 );
1105 case 0x29: /* PARSE FILENAME INTO FCB */
1106 INT_Int21Handler( context );
1109 case 0x2a: /* GET SYSTEM DATE */
1110 TRACE( "GET SYSTEM DATE\n" );
1113 GetLocalTime( &systime );
1114 SET_CX( context, systime.wYear );
1115 SET_DH( context, systime.wMonth );
1116 SET_DL( context, systime.wDay );
1117 SET_AL( context, systime.wDayOfWeek );
1121 case 0x2b: /* SET SYSTEM DATE */
1122 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
1123 DL_reg(context), DH_reg(context), CX_reg(context) );
1124 SET_AL( context, 0 ); /* Let's pretend we succeeded */
1127 case 0x2c: /* GET SYSTEM TIME */
1128 TRACE( "GET SYSTEM TIME\n" );
1131 GetLocalTime( &systime );
1132 SET_CH( context, systime.wHour );
1133 SET_CL( context, systime.wMinute );
1134 SET_DH( context, systime.wSecond );
1135 SET_DL( context, systime.wMilliseconds / 10 );
1139 case 0x2d: /* SET SYSTEM TIME */
1140 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1141 CH_reg(context), CL_reg(context),
1142 DH_reg(context), DL_reg(context) );
1143 SET_AL( context, 0 ); /* Let's pretend we succeeded */
1146 case 0x2e: /* SET VERIFY FLAG */
1147 TRACE("SET VERIFY FLAG ignored\n");
1148 /* we cannot change the behaviour anyway, so just ignore it */
1151 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1152 TRACE( "GET DISK TRANSFER AREA ADDRESS\n" );
1154 TDB *task = GlobalLock16( GetCurrentTask() );
1155 context->SegEs = SELECTOROF( task->dta );
1156 SET_BX( context, OFFSETOF( task->dta ) );
1160 case 0x30: /* GET DOS VERSION */
1161 TRACE( "GET DOS VERSION - %s requested\n",
1162 (AL_reg(context) == 0x00) ? "OEM number" : "version flag" );
1164 SET_AL( context, HIBYTE(HIWORD(GetVersion16())) ); /* major version */
1165 SET_AH( context, LOBYTE(HIWORD(GetVersion16())) ); /* minor version */
1167 if (AL_reg(context) == 0x00)
1168 SET_BH( context, 0xff ); /* OEM number => undefined */
1170 SET_BH( context, 0x08 ); /* version flag => DOS is in ROM */
1172 SET_BL( context, 0x12 ); /* 0x123456 is Wine's serial # */
1173 SET_CX( context, 0x3456 );
1176 case 0x31: /* TERMINATE AND STAY RESIDENT */
1177 FIXME("TERMINATE AND STAY RESIDENT stub\n");
1180 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1181 case 0x33: /* MULTIPLEXED */
1182 INT_Int21Handler( context );
1185 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1186 TRACE( "GET ADDRESS OF INDOS FLAG\n" );
1187 context->SegEs = INT21_GetHeapSelector( context );
1188 SET_BX( context, offsetof(INT21_HEAP, misc_indos) );
1191 case 0x35: /* GET INTERRUPT VECTOR */
1192 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1195 if (!ISV86(context) && DOSVM_IsWin16())
1196 addr = DOSVM_GetPMHandler16( AL_reg(context) );
1198 addr = DOSVM_GetRMHandler( AL_reg(context) );
1199 context->SegEs = SELECTOROF(addr);
1200 SET_BX( context, OFFSETOF(addr) );
1204 case 0x36: /* GET FREE DISK SPACE */
1205 INT_Int21Handler( context );
1208 case 0x37: /* SWITCHAR */
1210 switch (AL_reg(context))
1212 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1213 TRACE( "SWITCHAR - GET SWITCH CHARACTER\n" );
1214 SET_AL( context, 0x00 ); /* success*/
1215 SET_DL( context, '/' );
1217 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1218 FIXME( "SWITCHAR - SET SWITCH CHARACTER: %c\n",
1220 SET_AL( context, 0x00 ); /* success*/
1223 INT_BARF( context, 0x21 );
1229 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1230 TRACE( "GET COUNTRY-SPECIFIC INFORMATION\n" );
1231 if (AL_reg(context))
1233 WORD country = AL_reg(context);
1234 if (country == 0xff)
1235 country = BX_reg(context);
1236 if (country != INT21_GetSystemCountryCode())
1237 FIXME( "Requested info on non-default country %04x\n", country );
1239 INT21_FillCountryInformation( CTX_SEG_OFF_TO_LIN(context,
1242 SET_AX( context, INT21_GetSystemCountryCode() );
1243 SET_BX( context, INT21_GetSystemCountryCode() );
1246 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1247 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1248 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1249 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1250 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1251 case 0x3e: /* "CLOSE" - CLOSE FILE */
1252 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1253 INT_Int21Handler( context );
1256 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1257 TRACE( "WRITE from %04lX:%04X to handle %d for %d byte\n",
1258 context->SegDs, DX_reg(context),
1259 BX_reg(context), CX_reg(context) );
1261 BYTE *ptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
1263 if (!DOSVM_IsWin16() && BX_reg(context) == 1)
1266 for(i=0; i<CX_reg(context); i++)
1267 DOSVM_PutChar(ptr[i]);
1268 SET_AX(context, CX_reg(context));
1272 HFILE handle = (HFILE)DosFileHandleToWin32Handle(BX_reg(context));
1273 LONG result = _hwrite( handle, ptr, CX_reg(context) );
1274 if (result == HFILE_ERROR)
1275 bSetDOSExtendedError = TRUE;
1277 SET_AX( context, (WORD)result );
1282 case 0x41: /* "UNLINK" - DELETE FILE */
1283 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1284 case 0x43: /* FILE ATTRIBUTES */
1285 INT_Int21Handler( context );
1288 case 0x44: /* IOCTL */
1289 INT21_Ioctl( context );
1292 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1293 TRACE( "DUPLICATE FILE HANDLE %d\n", BX_reg(context) );
1296 HFILE handle16 = HFILE_ERROR;
1298 if (DuplicateHandle( GetCurrentProcess(),
1299 DosFileHandleToWin32Handle(BX_reg(context)),
1300 GetCurrentProcess(),
1302 0, TRUE, DUPLICATE_SAME_ACCESS ))
1303 handle16 = Win32HandleToDosFileHandle(handle32);
1305 if (handle16 == HFILE_ERROR)
1306 bSetDOSExtendedError = TRUE;
1308 SET_AX( context, handle16 );
1312 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1313 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1314 INT_Int21Handler( context );
1317 case 0x48: /* ALLOCATE MEMORY */
1318 TRACE( "ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context) );
1321 DWORD bytes = (DWORD)BX_reg(context) << 4;
1323 if (!ISV86(context) && DOSVM_IsWin16())
1325 DWORD rv = GlobalDOSAlloc16( bytes );
1326 selector = LOWORD( rv );
1329 DOSMEM_GetBlock( bytes, &selector );
1332 SET_AX( context, selector );
1336 SET_AX( context, 0x0008 ); /* insufficient memory */
1337 SET_BX( context, DOSMEM_Available() >> 4 );
1342 case 0x49: /* FREE MEMORY */
1343 TRACE( "FREE MEMORY segment %04lX\n", context->SegEs );
1347 if (!ISV86(context) && DOSVM_IsWin16())
1349 ok = !GlobalDOSFree16( context->SegEs );
1351 /* If we don't reset ES_reg, we will fail in the relay code */
1356 ok = DOSMEM_FreeBlock( (void*)((DWORD)context->SegEs << 4) );
1360 TRACE("FREE MEMORY failed\n");
1362 SET_AX( context, 0x0009 ); /* memory block address invalid */
1367 case 0x4a: /* RESIZE MEMORY BLOCK */
1368 INT_Int21Handler( context );
1371 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1373 BYTE *program = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
1374 BYTE *paramblk = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
1376 TRACE( "EXEC %s\n", program );
1378 if (DOSVM_IsWin16())
1380 HINSTANCE16 instance = WinExec16( program, SW_NORMAL );
1383 SET_CFLAG( context );
1384 SET_AX( context, instance );
1389 if (!MZ_Exec( context, program, AL_reg(context), paramblk))
1390 bSetDOSExtendedError = TRUE;
1395 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1396 TRACE( "EXIT with return code %d\n", AL_reg(context) );
1397 if (DOSVM_IsWin16())
1398 ExitThread( AL_reg(context) );
1400 MZ_Exit( context, FALSE, AL_reg(context) );
1403 case 0x4d: /* GET RETURN CODE */
1404 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
1405 SET_AX( context, DOSVM_retval );
1409 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1410 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1411 INT_Int21Handler( context );
1414 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1415 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1416 DOSVM_psp = BX_reg(context);
1419 case 0x51: /* GET PSP ADDRESS */
1420 INT21_GetPSP( context );
1423 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1424 if (!ISV86(context) && DOSVM_IsWin16())
1426 SEGPTR ptr = DOSMEM_LOL()->wine_pm_lol;
1427 context->SegEs = SELECTOROF(ptr);
1428 SET_BX( context, OFFSETOF(ptr) );
1432 SEGPTR ptr = DOSMEM_LOL()->wine_rm_lol;
1433 context->SegEs = SELECTOROF(ptr);
1434 SET_BX( context, OFFSETOF(ptr) );
1438 case 0x54: /* Get Verify Flag */
1439 TRACE("Get Verify Flag - Not Supported\n");
1440 SET_AL( context, 0x00 ); /* pretend we can tell. 00h = off 01h = on */
1443 case 0x56: /* "RENAME" - RENAME FILE */
1444 INT_Int21Handler( context );
1447 case 0x57: /* FILE DATE AND TIME */
1448 if (!INT21_FileDateTime( context ))
1449 bSetDOSExtendedError = TRUE;
1452 case 0x58: /* GET OR SET MEMORY ALLOCATION STRATEGY */
1453 switch (AL_reg(context))
1455 case 0x00: /* GET MEMORY ALLOCATION STRATEGY */
1456 TRACE( "GET MEMORY ALLOCATION STRATEGY\n" );
1457 SET_AX( context, 0 ); /* low memory first fit */
1460 case 0x01: /* SET ALLOCATION STRATEGY */
1461 TRACE( "SET MEMORY ALLOCATION STRATEGY to %d - ignored\n",
1465 case 0x02: /* GET UMB LINK STATE */
1466 TRACE( "GET UMB LINK STATE\n" );
1467 SET_AL( context, 0 ); /* UMBs not part of DOS memory chain */
1470 case 0x03: /* SET UMB LINK STATE */
1471 TRACE( "SET UMB LINK STATE to %d - ignored\n",
1476 INT_BARF( context, 0x21 );
1480 case 0x59: /* GET EXTENDED ERROR INFO */
1481 INT21_GetExtendedError( context );
1484 case 0x5a: /* CREATE TEMPORARY FILE */
1485 case 0x5b: /* CREATE NEW FILE */
1486 INT_Int21Handler( context );
1489 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1491 DWORD offset = MAKELONG(DX_reg(context), CX_reg(context));
1492 DWORD length = MAKELONG(DI_reg(context), SI_reg(context));
1493 HANDLE handle = DosFileHandleToWin32Handle(BX_reg(context));
1495 switch (AL_reg(context))
1497 case 0x00: /* LOCK */
1498 TRACE( "lock handle %d offset %ld length %ld\n",
1499 BX_reg(context), offset, length );
1500 if (!LockFile( handle, offset, 0, length, 0 ))
1501 bSetDOSExtendedError = TRUE;
1504 case 0x01: /* UNLOCK */
1505 TRACE( "unlock handle %d offset %ld length %ld\n",
1506 BX_reg(context), offset, length );
1507 if (!UnlockFile( handle, offset, 0, length, 0 ))
1508 bSetDOSExtendedError = TRUE;
1512 INT_BARF( context, 0x21 );
1517 case 0x5d: /* NETWORK 5D */
1518 FIXME( "Network function 5D not implemented.\n" );
1519 SetLastError( ER_NoNetwork );
1520 bSetDOSExtendedError = TRUE;
1523 case 0x5e: /* NETWORK 5E */
1524 case 0x5f: /* NETWORK 5F */
1525 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1526 INT_Int21Handler( context );
1529 case 0x61: /* UNUSED */
1530 SET_AL( context, 0 );
1533 case 0x62: /* GET PSP ADDRESS */
1534 INT21_GetPSP( context );
1537 case 0x63: /* MISC. LANGUAGE SUPPORT */
1538 switch (AL_reg(context)) {
1539 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1540 TRACE( "GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE\n" );
1541 context->SegDs = INT21_GetHeapSelector( context );
1542 SET_SI( context, offsetof(INT21_HEAP, dbcs_table) );
1543 SET_AL( context, 0 ); /* success */
1548 case 0x64: /* OS/2 DOS BOX */
1549 INT_BARF( context, 0x21 );
1553 case 0x65: /* EXTENDED COUNTRY INFORMATION */
1554 INT21_ExtendedCountryInformation( context );
1557 case 0x66: /* GLOBAL CODE PAGE TABLE */
1558 switch (AL_reg(context))
1561 TRACE( "GET GLOBAL CODE PAGE TABLE\n" );
1562 SET_BX( context, GetOEMCP() );
1563 SET_DX( context, GetOEMCP() );
1566 FIXME( "SET GLOBAL CODE PAGE TABLE, active %d, system %d - ignored\n",
1567 BX_reg(context), DX_reg(context) );
1572 case 0x67: /* SET HANDLE COUNT */
1573 TRACE( "SET HANDLE COUNT to %d\n", BX_reg(context) );
1574 if (SetHandleCount( BX_reg(context) ) < BX_reg(context) )
1575 bSetDOSExtendedError = TRUE;
1578 case 0x68: /* "FFLUSH" - COMMIT FILE */
1579 TRACE( "FFLUSH - handle %d\n", BX_reg(context) );
1580 if (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context)) ))
1581 bSetDOSExtendedError = TRUE;
1584 case 0x69: /* DISK SERIAL NUMBER */
1585 INT_Int21Handler( context );
1588 case 0x6a: /* COMMIT FILE */
1589 TRACE( "COMMIT FILE - handle %d\n", BX_reg(context) );
1590 if (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context)) ))
1591 bSetDOSExtendedError = TRUE;
1594 case 0x6b: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
1595 SET_AL( context, 0 );
1598 case 0x6c: /* EXTENDED OPEN/CREATE */
1599 INT_Int21Handler( context );
1602 case 0x70: /* MSDOS 7 - GET/SET INTERNATIONALIZATION INFORMATION */
1603 FIXME( "MS-DOS 7 - GET/SET INTERNATIONALIZATION INFORMATION\n" );
1604 SET_CFLAG( context );
1605 SET_AL( context, 0 );
1608 case 0x71: /* MSDOS 7 - LONG FILENAME FUNCTIONS */
1609 INT_Int21Handler( context );
1612 case 0x73: /* MSDOS7 - FAT32 */
1613 INT_Int21Handler( context );
1616 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1617 TRACE( "CONNECTION SERVICES - GET CONNECTION NUMBER - ignored\n" );
1620 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1621 TRACE( "NOVELL NETWARE - RETURN SHELL VERSION - ignored\n" );
1625 INT_BARF( context, 0x21 );
1628 } /* END OF SWITCH */
1630 /* Set general error condition. */
1631 if (bSetDOSExtendedError)
1633 SET_AX( context, GetLastError() );
1634 SET_CFLAG( context );
1637 /* Print error code if carry flag is set. */
1638 if (context->EFlags & 0x0001)
1639 TRACE("failed, error %ld\n", GetLastError() );
1641 TRACE( "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
1642 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1643 AX_reg(context), BX_reg(context),
1644 CX_reg(context), DX_reg(context),
1645 SI_reg(context), DI_reg(context),
1646 (WORD)context->SegDs, (WORD)context->SegEs,