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"
37 #include "wine/unicode.h"
38 #include "wine/debug.h"
41 * FIXME: Delete this reference when all int21 code has been moved to winedos.
43 extern void WINAPI INT_Int21Handler( CONTEXT86 *context );
45 WINE_DEFAULT_DEBUG_CHANNEL(int21);
51 * Structure for DOS data that can be accessed directly from applications.
52 * Real and protected mode pointers will be returned to this structure so
53 * the structure must be correctly packed.
55 typedef struct _INT21_HEAP {
56 WORD uppercase_size; /* Size of the following table in bytes */
57 BYTE uppercase_table[128]; /* Uppercase equivalents of chars from 0x80 to 0xff. */
59 WORD lowercase_size; /* Size of the following table in bytes */
60 BYTE lowercase_table[256]; /* Lowercase equivalents of chars from 0x00 to 0xff. */
62 WORD collating_size; /* Size of the following table in bytes */
63 BYTE collating_table[256]; /* Values used to sort characters from 0x00 to 0xff. */
65 WORD filename_size; /* Size of the following filename data in bytes */
66 BYTE filename_reserved1; /* 0x01 for MS-DOS 3.30-6.00 */
67 BYTE filename_lowest; /* Lowest permissible character value for filename */
68 BYTE filename_highest; /* Highest permissible character value for filename */
69 BYTE filename_reserved2; /* 0x00 for MS-DOS 3.30-6.00 */
70 BYTE filename_exclude_first; /* First illegal character in permissible range */
71 BYTE filename_exclude_last; /* Last illegal character in permissible range */
72 BYTE filename_reserved3; /* 0x02 for MS-DOS 3.30-6.00 */
73 BYTE filename_illegal_size; /* Number of terminators in the following table */
74 BYTE filename_illegal_table[16]; /* Characters which terminate a filename */
76 WORD dbcs_size; /* Number of valid ranges in the following table */
77 BYTE dbcs_table[16]; /* Start/end bytes for N ranges and 00/00 as terminator */
79 BYTE misc_indos; /* Interrupt 21 nesting flag */
85 /***********************************************************************
88 * Reads a character from the standard input.
89 * Extended keycodes will be returned as two separate characters.
91 static BOOL INT21_ReadChar( BYTE *input, BOOL peek )
93 static BYTE pending_scan = 0;
98 *input = pending_scan;
107 if (!DOSVM_Int16ReadChar( &ascii, &scan, peek ))
119 /***********************************************************************
120 * INT21_GetSystemCountryCode
122 * Return DOS country code for default system locale.
124 static WORD INT21_GetSystemCountryCode()
127 * FIXME: Determine country code. We should probably use
128 * DOSCONF structure for that.
130 return GetSystemDefaultLangID();
134 /***********************************************************************
135 * INT21_FillCountryInformation
137 * Fill 34-byte buffer with country information data using
138 * default system locale.
140 static void INT21_FillCountryInformation( BYTE *buffer )
142 /* 00 - WORD: date format
147 *(WORD*)(buffer + 0) = 0; /* FIXME: Get from locale */
149 /* 02 - BYTE[5]: ASCIIZ currency symbol string */
150 buffer[2] = '$'; /* FIXME: Get from locale */
153 /* 07 - BYTE[2]: ASCIIZ thousands separator */
154 buffer[7] = 0; /* FIXME: Get from locale */
157 /* 09 - BYTE[2]: ASCIIZ decimal separator */
158 buffer[9] = '.'; /* FIXME: Get from locale */
161 /* 11 - BYTE[2]: ASCIIZ date separator */
162 buffer[11] = '/'; /* FIXME: Get from locale */
165 /* 13 - BYTE[2]: ASCIIZ time separator */
166 buffer[13] = ':'; /* FIXME: Get from locale */
169 /* 15 - BYTE: Currency format
170 * bit 2 = set if currency symbol replaces decimal point
171 * bit 1 = number of spaces between value and currency symbol
172 * bit 0 = 0 if currency symbol precedes value
173 * 1 if currency symbol follows value
175 buffer[15] = 0; /* FIXME: Get from locale */
177 /* 16 - BYTE: Number of digits after decimal in currency */
178 buffer[16] = 0; /* FIXME: Get from locale */
180 /* 17 - BYTE: Time format
181 * bit 0 = 0 if 12-hour clock
184 buffer[17] = 1; /* FIXME: Get from locale */
186 /* 18 - DWORD: Address of case map routine */
187 *(DWORD*)(buffer + 18) = 0; /* FIXME: ptr to case map routine */
189 /* 22 - BYTE[2]: ASCIIZ data-list separator */
190 buffer[22] = ','; /* FIXME: Get from locale */
193 /* 24 - BYTE[10]: Reserved */
194 memset( buffer + 24, 0, 10 );
198 /***********************************************************************
201 * Initialize DOS heap.
203 static void INT21_FillHeap( INT21_HEAP *heap )
205 static const char terminators[] = "\"\\./[]:|<>+=;,";
211 heap->uppercase_size = 128;
212 for (i = 0; i < 128; i++)
213 heap->uppercase_table[i] = toupper( 128 + i );
218 heap->lowercase_size = 256;
219 for (i = 0; i < 256; i++)
220 heap->lowercase_table[i] = tolower( i );
225 heap->collating_size = 256;
226 for (i = 0; i < 256; i++)
227 heap->collating_table[i] = i;
232 heap->filename_size = 8 + strlen(terminators);
233 heap->filename_illegal_size = strlen(terminators);
234 strcpy( heap->filename_illegal_table, terminators );
236 heap->filename_reserved1 = 0x01;
237 heap->filename_lowest = 0; /* FIXME: correct value? */
238 heap->filename_highest = 0xff; /* FIXME: correct value? */
239 heap->filename_reserved2 = 0x00;
240 heap->filename_exclude_first = 0x00; /* FIXME: correct value? */
241 heap->filename_exclude_last = 0x00; /* FIXME: correct value? */
242 heap->filename_reserved3 = 0x02;
245 * DBCS lead byte table. This table is empty.
248 memset( heap->dbcs_table, 0, sizeof(heap->dbcs_table) );
251 * Initialize InDos flag.
253 heap->misc_indos = 0;
257 /***********************************************************************
258 * INT21_GetHeapSelector
260 * Get segment/selector for DOS heap (INT21_HEAP).
261 * Creates and initializes heap on first call.
263 static WORD INT21_GetHeapSelector( CONTEXT86 *context )
265 static WORD heap_segment = 0;
266 static WORD heap_selector = 0;
267 static BOOL heap_initialized = FALSE;
269 if (!heap_initialized)
271 INT21_HEAP *ptr = DOSVM_AllocDataUMB( sizeof(INT21_HEAP),
274 INT21_FillHeap( ptr );
275 heap_initialized = TRUE;
278 if (!ISV86(context) && DOSVM_IsWin16())
279 return heap_selector;
285 /***********************************************************************
286 * INT21_BufferedInput
288 * Handler for function 0x0a.
290 * Reads a string of characters from standard input until
291 * enter key is pressed.
293 static void INT21_BufferedInput( CONTEXT86 *context )
295 BYTE *ptr = CTX_SEG_OFF_TO_LIN(context,
298 BYTE capacity = ptr[0]; /* includes CR */
299 BYTE length = 0; /* excludes CR */
301 TRACE( "BUFFERED INPUT (size=%d)\n", capacity );
304 * Return immediately if capacity is zero.
306 * FIXME: What to return to application?
312 * FIXME: Some documents state that
313 * ptr[1] holds number of chars from last input which
314 * may be recalled on entry, other documents do not mention
318 TRACE( "Handle old chars in buffer!\n" );
325 DOSVM_Int16ReadChar( &ascii, &scan, FALSE );
327 if (ascii == '\r' || ascii == '\n')
330 * FIXME: What should be echoed here?
332 DOSVM_PutChar( '\r' );
333 DOSVM_PutChar( '\n' );
335 ptr[2 + length] = '\r';
340 * FIXME: This function is supposed to support
341 * DOS editing keys...
345 * If the buffer becomes filled to within one byte of
346 * capacity, DOS rejects all further characters up to,
347 * but not including, the terminating carriage return.
349 if (ascii != 0 && length < capacity-1)
351 DOSVM_PutChar( ascii );
352 ptr[2 + length] = ascii;
359 /***********************************************************************
360 * INT21_ExtendedCountryInformation
362 * Handler for function 0x65.
364 static void INT21_ExtendedCountryInformation( CONTEXT86 *context )
366 BYTE *dataptr = CTX_SEG_OFF_TO_LIN( context, context->SegEs, context->Edi );
368 TRACE( "GET EXTENDED COUNTRY INFORMATION, subfunction %02x\n",
372 * Check subfunctions that are passed country and code page.
374 if (AL_reg(context) >= 0x01 && AL_reg(context) <= 0x07)
376 WORD country = DX_reg(context);
377 WORD codepage = BX_reg(context);
379 if (country != 0xffff && country != INT21_GetSystemCountryCode())
380 FIXME( "Requested info on non-default country %04x\n", country );
382 if (codepage != 0xffff && codepage != GetOEMCP())
383 FIXME( "Requested info on non-default code page %04x\n", codepage );
386 switch (AL_reg(context)) {
387 case 0x00: /* SET GENERAL INTERNATIONALIZATION INFO */
388 INT_BARF( context, 0x21 );
389 SET_CFLAG( context );
392 case 0x01: /* GET GENERAL INTERNATIONALIZATION INFO */
393 TRACE( "Get general internationalization info\n" );
394 dataptr[0] = 0x01; /* Info ID */
395 *(WORD*)(dataptr+1) = 38; /* Size of the following info */
396 *(WORD*)(dataptr+3) = INT21_GetSystemCountryCode(); /* Country ID */
397 *(WORD*)(dataptr+5) = GetOEMCP(); /* Code page */
398 INT21_FillCountryInformation( dataptr + 7 );
399 SET_CX( context, 41 ); /* Size of returned info */
402 case 0x02: /* GET POINTER TO UPPERCASE TABLE */
403 case 0x04: /* GET POINTER TO FILENAME UPPERCASE TABLE */
404 TRACE( "Get pointer to uppercase table\n" );
405 dataptr[0] = AL_reg(context); /* Info ID */
406 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
407 offsetof(INT21_HEAP, uppercase_size) );
408 SET_CX( context, 5 ); /* Size of returned info */
411 case 0x03: /* GET POINTER TO LOWERCASE TABLE */
412 TRACE( "Get pointer to lowercase table\n" );
413 dataptr[0] = 0x03; /* Info ID */
414 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
415 offsetof(INT21_HEAP, lowercase_size) );
416 SET_CX( context, 5 ); /* Size of returned info */
419 case 0x05: /* GET POINTER TO FILENAME TERMINATOR TABLE */
420 TRACE("Get pointer to filename terminator table\n");
421 dataptr[0] = 0x05; /* Info ID */
422 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
423 offsetof(INT21_HEAP, filename_size) );
424 SET_CX( context, 5 ); /* Size of returned info */
427 case 0x06: /* GET POINTER TO COLLATING SEQUENCE TABLE */
428 TRACE("Get pointer to collating sequence table\n");
429 dataptr[0] = 0x06; /* Info ID */
430 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
431 offsetof(INT21_HEAP, collating_size) );
432 SET_CX( context, 5 ); /* Size of returned info */
435 case 0x07: /* GET POINTER TO DBCS LEAD BYTE TABLE */
436 TRACE("Get pointer to DBCS lead byte table\n");
437 dataptr[0] = 0x07; /* Info ID */
438 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
439 offsetof(INT21_HEAP, dbcs_size) );
440 SET_CX( context, 5 ); /* Size of returned info */
443 case 0x20: /* CAPITALIZE CHARACTER */
444 case 0xa0: /* CAPITALIZE FILENAME CHARACTER */
445 TRACE("Convert char to uppercase\n");
446 SET_DL( context, toupper(DL_reg(context)) );
449 case 0x21: /* CAPITALIZE STRING */
450 case 0xa1: /* CAPITALIZE COUNTED FILENAME STRING */
451 TRACE("Convert string to uppercase with length\n");
453 char *ptr = (char *)CTX_SEG_OFF_TO_LIN( context,
456 WORD len = CX_reg(context);
457 while (len--) { *ptr = toupper(*ptr); ptr++; }
461 case 0x22: /* CAPITALIZE ASCIIZ STRING */
462 case 0xa2: /* CAPITALIZE ASCIIZ FILENAME */
463 TRACE("Convert ASCIIZ string to uppercase\n");
464 _strupr( (LPSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx) );
467 case 0x23: /* DETERMINE IF CHARACTER REPRESENTS YES/NO RESPONSE */
468 INT_BARF( context, 0x21 );
469 SET_CFLAG( context );
473 INT_BARF( context, 0x21 );
480 /***********************************************************************
483 * Handler for function 0x57.
485 static BOOL INT21_FileDateTime( CONTEXT86 *context )
487 HANDLE handle = DosFileHandleToWin32Handle(BX_reg(context));
491 switch (AL_reg(context)) {
492 case 0x00: /* Get last-written stamp */
493 TRACE( "GET FILE LAST-WRITTEN DATE AND TIME, handle %d\n",
496 if (!GetFileTime( handle, NULL, NULL, &filetime ))
498 FileTimeToDosDateTime( &filetime, &date, &time );
499 SET_DX( context, date );
500 SET_CX( context, time );
504 case 0x01: /* Set last-written stamp */
505 TRACE( "SET FILE LAST-WRITTEN DATE AND TIME, handle %d\n",
508 DosDateTimeToFileTime( DX_reg(context),
511 if (!SetFileTime( handle, NULL, NULL, &filetime ))
516 case 0x04: /* Get last access stamp, DOS 7 */
517 TRACE( "GET FILE LAST ACCESS DATE AND TIME, handle %d\n",
520 if (!GetFileTime( handle, NULL, &filetime, NULL ))
522 FileTimeToDosDateTime( &filetime, &date, &time );
523 SET_DX( context, date );
524 SET_CX( context, time );
528 case 0x05: /* Set last access stamp, DOS 7 */
529 TRACE( "SET FILE LAST ACCESS DATE AND TIME, handle %d\n",
532 DosDateTimeToFileTime( DX_reg(context),
535 if (!SetFileTime( handle, NULL, &filetime, NULL ))
540 case 0x06: /* Get creation stamp, DOS 7 */
541 TRACE( "GET FILE CREATION DATE AND TIME, handle %d\n",
544 if (!GetFileTime( handle, &filetime, NULL, NULL ))
546 FileTimeToDosDateTime( &filetime, &date, &time );
547 SET_DX( context, date );
548 SET_CX( context, time );
550 * FIXME: SI has number of 10-millisecond units past time in CX.
552 SET_SI( context, 0 );
556 case 0x07: /* Set creation stamp, DOS 7 */
557 TRACE( "SET FILE CREATION DATE AND TIME, handle %d\n",
561 * FIXME: SI has number of 10-millisecond units past time in CX.
563 DosDateTimeToFileTime( DX_reg(context),
566 if (!SetFileTime( handle, &filetime, NULL, NULL ))
572 INT_BARF( context, 0x21 );
580 /***********************************************************************
583 * Handler for functions 0x51 and 0x62.
585 static void INT21_GetPSP( CONTEXT86 *context )
587 TRACE( "GET CURRENT PSP ADDRESS (%02x)\n", AH_reg(context) );
590 * FIXME: should we return the original DOS PSP upon
593 if (!ISV86(context) && DOSVM_IsWin16())
594 SET_BX( context, LOWORD(GetCurrentPDB16()) );
596 SET_BX( context, DOSVM_psp );
600 /***********************************************************************
603 * Handler for function 0x44.
605 static void INT21_Ioctl( CONTEXT86 *context )
607 static const WCHAR emmxxxx0W[] = {'E','M','M','X','X','X','X','0',0};
608 const DOS_DEVICE *dev = DOSFS_GetDeviceByHandle(
609 DosFileHandleToWin32Handle(BX_reg(context)) );
611 if (dev && !strcmpiW( dev->name, emmxxxx0W )) {
612 EMS_Ioctl_Handler(context);
616 switch (AL_reg(context))
618 case 0x0b: /* SET SHARING RETRY COUNT */
619 TRACE("IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
620 CX_reg(context), DX_reg(context));
621 if (!CX_reg(context))
623 SET_AX( context, 1 );
627 DOSMEM_LOL()->sharing_retry_delay = CX_reg(context);
628 if (!DX_reg(context))
629 DOSMEM_LOL()->sharing_retry_count = DX_reg(context);
630 RESET_CFLAG(context);
633 INT_Int21Handler( context );
638 /***********************************************************************
639 * INT21_GetExtendedError
641 static void INT21_GetExtendedError( CONTEXT86 *context )
643 BYTE class, action, locus;
644 WORD error = GetLastError();
649 class = action = locus = 0;
651 case ERROR_DIR_NOT_EMPTY:
656 case ERROR_ACCESS_DENIED:
657 class = EC_AccessDenied;
661 case ERROR_CANNOT_MAKE:
662 class = EC_AccessDenied;
666 case ERROR_DISK_FULL:
667 case ERROR_HANDLE_DISK_FULL:
668 class = EC_MediaError;
672 case ERROR_FILE_EXISTS:
673 case ERROR_ALREADY_EXISTS:
678 case ERROR_FILE_NOT_FOUND:
683 case ER_GeneralFailure:
684 class = EC_SystemFailure;
688 case ERROR_INVALID_DRIVE:
689 class = EC_MediaError;
693 case ERROR_INVALID_HANDLE:
694 class = EC_ProgramError;
698 case ERROR_LOCK_VIOLATION:
699 class = EC_AccessDenied;
703 case ERROR_NO_MORE_FILES:
704 class = EC_MediaError;
713 case ERROR_NOT_ENOUGH_MEMORY:
714 class = EC_OutOfResource;
718 case ERROR_PATH_NOT_FOUND:
728 case ERROR_SHARING_VIOLATION:
729 class = EC_Temporary;
733 case ERROR_TOO_MANY_OPEN_FILES:
734 class = EC_ProgramError;
739 FIXME("Unknown error %d\n", error );
740 class = EC_SystemFailure;
745 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
746 error, class, action, locus );
747 SET_AX( context, error );
748 SET_BH( context, class );
749 SET_BL( context, action );
750 SET_CH( context, locus );
754 /***********************************************************************
757 * Interrupt 0x21 handler.
759 void WINAPI DOSVM_Int21Handler( CONTEXT86 *context )
761 BOOL bSetDOSExtendedError = FALSE;
763 TRACE( "AX=%04x BX=%04x CX=%04x DX=%04x "
764 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
765 AX_reg(context), BX_reg(context),
766 CX_reg(context), DX_reg(context),
767 SI_reg(context), DI_reg(context),
768 (WORD)context->SegDs, (WORD)context->SegEs,
772 * Extended error is used by (at least) functions 0x2f to 0x62.
773 * Function 0x59 returns extended error and error should not
774 * be cleared before handling the function.
776 if (AH_reg(context) >= 0x2f && AH_reg(context) != 0x59)
779 RESET_CFLAG(context); /* Not sure if this is a good idea. */
781 switch(AH_reg(context))
783 case 0x00: /* TERMINATE PROGRAM */
784 TRACE("TERMINATE PROGRAM\n");
788 MZ_Exit( context, FALSE, 0 );
791 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
794 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
795 INT21_ReadChar( &ascii, FALSE );
796 SET_AL( context, ascii );
798 * FIXME: What to echo when extended keycodes are read?
800 DOSVM_PutChar(AL_reg(context));
804 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
805 TRACE("Write Character to Standard Output\n");
806 DOSVM_PutChar(DL_reg(context));
809 case 0x03: /* READ CHARACTER FROM STDAUX */
810 case 0x04: /* WRITE CHARACTER TO STDAUX */
811 case 0x05: /* WRITE CHARACTER TO PRINTER */
812 INT_BARF( context, 0x21 );
815 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
816 if (DL_reg(context) == 0xff)
818 TRACE("Direct Console Input\n");
820 if (INT21_ReadChar( NULL, TRUE ))
823 INT21_ReadChar( &ascii, FALSE );
824 SET_AL( context, ascii );
825 RESET_ZFLAG( context );
829 /* no character available */
830 SET_AL( context, 0 );
831 SET_ZFLAG( context );
836 TRACE("Direct Console Output\n");
837 DOSVM_PutChar(DL_reg(context));
839 * At least DOS versions 2.1-7.0 return character
840 * that was written in AL register.
842 SET_AL( context, DL_reg(context) );
846 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
849 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
850 INT21_ReadChar( &ascii, FALSE );
851 SET_AL( context, ascii );
855 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
858 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
859 INT21_ReadChar( &ascii, FALSE );
860 SET_AL( context, ascii );
864 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
865 INT_Int21Handler( context );
868 case 0x0a: /* BUFFERED INPUT */
869 INT21_BufferedInput( context );
872 case 0x0b: /* GET STDIN STATUS */
873 TRACE( "GET STDIN STATUS\n" );
875 if (INT21_ReadChar( NULL, TRUE ))
876 SET_AL( context, 0xff ); /* character available */
878 SET_AL( context, 0 ); /* no character available */
882 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
884 BYTE al = AL_reg(context); /* Input function to execute after flush. */
886 TRACE( "FLUSH BUFFER AND READ STANDARD INPUT - 0x%02x\n", al );
888 /* FIXME: buffers are not flushed */
891 * If AL is one of 0x01, 0x06, 0x07, 0x08, or 0x0a,
892 * int21 function identified by AL will be called.
894 if(al == 0x01 || al == 0x06 || al == 0x07 || al == 0x08 || al == 0x0a)
896 SET_AH( context, al );
897 DOSVM_Int21Handler( context );
902 case 0x0d: /* DISK BUFFER FLUSH */
903 TRACE("DISK BUFFER FLUSH ignored\n");
906 case 0x0e: /* SELECT DEFAULT DRIVE */
907 INT_Int21Handler( context );
910 case 0x0f: /* OPEN FILE USING FCB */
911 case 0x10: /* CLOSE FILE USING FCB */
912 INT_BARF( context, 0x21 );
915 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
916 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
917 INT_Int21Handler( context );
920 case 0x13: /* DELETE FILE USING FCB */
921 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
922 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
923 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
924 case 0x17: /* RENAME FILE USING FCB */
925 INT_BARF( context, 0x21 );
928 case 0x18: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
929 SET_AL( context, 0 );
932 case 0x19: /* GET CURRENT DEFAULT DRIVE */
933 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
934 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
935 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
936 INT_Int21Handler( context );
939 case 0x1d: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
940 case 0x1e: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
941 SET_AL( context, 0 );
944 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
945 INT_Int21Handler( context );
948 case 0x20: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
949 SET_AL( context, 0 );
952 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
953 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
954 case 0x23: /* GET FILE SIZE FOR FCB */
955 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
956 INT_BARF( context, 0x21 );
959 case 0x25: /* SET INTERRUPT VECTOR */
960 TRACE("SET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
962 FARPROC16 ptr = (FARPROC16)MAKESEGPTR( context->SegDs, DX_reg(context) );
963 if (!ISV86(context) && DOSVM_IsWin16())
964 DOSVM_SetPMHandler16( AL_reg(context), ptr );
966 DOSVM_SetRMHandler( AL_reg(context), ptr );
970 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
971 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
972 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
973 INT_BARF( context, 0x21 );
976 case 0x29: /* PARSE FILENAME INTO FCB */
977 INT_Int21Handler( context );
980 case 0x2a: /* GET SYSTEM DATE */
981 TRACE( "GET SYSTEM DATE\n" );
984 GetLocalTime( &systime );
985 SET_CX( context, systime.wYear );
986 SET_DH( context, systime.wMonth );
987 SET_DL( context, systime.wDay );
988 SET_AL( context, systime.wDayOfWeek );
992 case 0x2b: /* SET SYSTEM DATE */
993 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
994 DL_reg(context), DH_reg(context), CX_reg(context) );
995 SET_AL( context, 0 ); /* Let's pretend we succeeded */
998 case 0x2c: /* GET SYSTEM TIME */
999 TRACE( "GET SYSTEM TIME\n" );
1002 GetLocalTime( &systime );
1003 SET_CH( context, systime.wHour );
1004 SET_CL( context, systime.wMinute );
1005 SET_DH( context, systime.wSecond );
1006 SET_DL( context, systime.wMilliseconds / 10 );
1010 case 0x2d: /* SET SYSTEM TIME */
1011 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1012 CH_reg(context), CL_reg(context),
1013 DH_reg(context), DL_reg(context) );
1014 SET_AL( context, 0 ); /* Let's pretend we succeeded */
1017 case 0x2e: /* SET VERIFY FLAG */
1018 TRACE("SET VERIFY FLAG ignored\n");
1019 /* we cannot change the behaviour anyway, so just ignore it */
1022 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1023 INT_Int21Handler( context );
1026 case 0x30: /* GET DOS VERSION */
1027 TRACE( "GET DOS VERSION - %s requested\n",
1028 (AL_reg(context) == 0x00) ? "OEM number" : "version flag" );
1030 SET_AL( context, HIBYTE(HIWORD(GetVersion16())) ); /* major version */
1031 SET_AH( context, LOBYTE(HIWORD(GetVersion16())) ); /* minor version */
1033 if (AL_reg(context) == 0x00)
1034 SET_BH( context, 0xff ); /* OEM number => undefined */
1036 SET_BH( context, 0x08 ); /* version flag => DOS is in ROM */
1038 SET_BL( context, 0x12 ); /* 0x123456 is Wine's serial # */
1039 SET_CX( context, 0x3456 );
1042 case 0x31: /* TERMINATE AND STAY RESIDENT */
1043 FIXME("TERMINATE AND STAY RESIDENT stub\n");
1046 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1047 case 0x33: /* MULTIPLEXED */
1048 INT_Int21Handler( context );
1051 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1052 TRACE( "GET ADDRESS OF INDOS FLAG\n" );
1053 context->SegEs = INT21_GetHeapSelector( context );
1054 SET_BX( context, offsetof(INT21_HEAP, misc_indos) );
1057 case 0x35: /* GET INTERRUPT VECTOR */
1058 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1061 if (!ISV86(context) && DOSVM_IsWin16())
1062 addr = DOSVM_GetPMHandler16( AL_reg(context) );
1064 addr = DOSVM_GetRMHandler( AL_reg(context) );
1065 context->SegEs = SELECTOROF(addr);
1066 SET_BX( context, OFFSETOF(addr) );
1070 case 0x36: /* GET FREE DISK SPACE */
1071 case 0x37: /* SWITCHAR */
1072 INT_Int21Handler( context );
1075 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1076 TRACE( "GET COUNTRY-SPECIFIC INFORMATION\n" );
1077 if (AL_reg(context))
1079 WORD country = AL_reg(context);
1080 if (country == 0xff)
1081 country = BX_reg(context);
1082 if (country != INT21_GetSystemCountryCode())
1083 FIXME( "Requested info on non-default country %04x\n", country );
1085 INT21_FillCountryInformation( CTX_SEG_OFF_TO_LIN(context,
1088 SET_AX( context, INT21_GetSystemCountryCode() );
1089 SET_BX( context, INT21_GetSystemCountryCode() );
1092 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1093 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1094 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1095 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1096 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1097 case 0x3e: /* "CLOSE" - CLOSE FILE */
1098 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1099 INT_Int21Handler( context );
1102 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1103 TRACE( "WRITE from %04lX:%04X to handle %d for %d byte\n",
1104 context->SegDs, DX_reg(context),
1105 BX_reg(context), CX_reg(context) );
1107 BYTE *ptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
1109 if (!DOSVM_IsWin16() && BX_reg(context) == 1)
1112 for(i=0; i<CX_reg(context); i++)
1113 DOSVM_PutChar(ptr[i]);
1114 SET_AX(context, CX_reg(context));
1118 HFILE handle = (HFILE)DosFileHandleToWin32Handle(BX_reg(context));
1119 LONG result = _hwrite( handle, ptr, CX_reg(context) );
1120 if (result == HFILE_ERROR)
1121 bSetDOSExtendedError = TRUE;
1123 SET_AX( context, (WORD)result );
1128 case 0x41: /* "UNLINK" - DELETE FILE */
1129 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1130 case 0x43: /* FILE ATTRIBUTES */
1131 INT_Int21Handler( context );
1134 case 0x44: /* IOCTL */
1135 INT21_Ioctl( context );
1138 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1139 TRACE( "DUPLICATE FILE HANDLE %d\n", BX_reg(context) );
1142 HFILE handle16 = HFILE_ERROR;
1144 if (DuplicateHandle( GetCurrentProcess(),
1145 DosFileHandleToWin32Handle(BX_reg(context)),
1146 GetCurrentProcess(),
1148 0, TRUE, DUPLICATE_SAME_ACCESS ))
1149 handle16 = Win32HandleToDosFileHandle(handle32);
1151 if (handle16 == HFILE_ERROR)
1152 bSetDOSExtendedError = TRUE;
1154 SET_AX( context, handle16 );
1158 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1159 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1160 INT_Int21Handler( context );
1163 case 0x48: /* ALLOCATE MEMORY */
1164 TRACE( "ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context) );
1167 DWORD bytes = (DWORD)BX_reg(context) << 4;
1169 if (!ISV86(context) && DOSVM_IsWin16())
1171 DWORD rv = GlobalDOSAlloc16( bytes );
1172 selector = LOWORD( rv );
1175 DOSMEM_GetBlock( bytes, &selector );
1178 SET_AX( context, selector );
1182 SET_AX( context, 0x0008 ); /* insufficient memory */
1183 SET_BX( context, DOSMEM_Available() >> 4 );
1188 case 0x49: /* FREE MEMORY */
1189 TRACE( "FREE MEMORY segment %04lX\n", context->SegEs );
1193 if (!ISV86(context) && DOSVM_IsWin16())
1195 ok = !GlobalDOSFree16( context->SegEs );
1197 /* If we don't reset ES_reg, we will fail in the relay code */
1202 ok = DOSMEM_FreeBlock( (void*)((DWORD)context->SegEs << 4) );
1206 TRACE("FREE MEMORY failed\n");
1208 SET_AX( context, 0x0009 ); /* memory block address invalid */
1213 case 0x4a: /* RESIZE MEMORY BLOCK */
1214 INT_Int21Handler( context );
1217 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1219 BYTE *program = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
1220 BYTE *paramblk = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
1222 TRACE( "EXEC %s\n", program );
1224 if (DOSVM_IsWin16())
1226 HINSTANCE16 instance = WinExec16( program, SW_NORMAL );
1229 SET_CFLAG( context );
1230 SET_AX( context, instance );
1235 if (!MZ_Exec( context, program, AL_reg(context), paramblk))
1236 bSetDOSExtendedError = TRUE;
1241 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1242 TRACE( "EXIT with return code %d\n", AL_reg(context) );
1243 if (DOSVM_IsWin16())
1244 ExitThread( AL_reg(context) );
1246 MZ_Exit( context, FALSE, AL_reg(context) );
1249 case 0x4d: /* GET RETURN CODE */
1250 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
1251 SET_AX( context, DOSVM_retval );
1255 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1256 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1257 INT_Int21Handler( context );
1260 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1261 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1262 DOSVM_psp = BX_reg(context);
1265 case 0x51: /* GET PSP ADDRESS */
1266 INT21_GetPSP( context );
1269 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1270 if (!ISV86(context) && DOSVM_IsWin16())
1272 SEGPTR ptr = DOSMEM_LOL()->wine_pm_lol;
1273 context->SegEs = SELECTOROF(ptr);
1274 SET_BX( context, OFFSETOF(ptr) );
1278 SEGPTR ptr = DOSMEM_LOL()->wine_rm_lol;
1279 context->SegEs = SELECTOROF(ptr);
1280 SET_BX( context, OFFSETOF(ptr) );
1284 case 0x54: /* Get Verify Flag */
1285 TRACE("Get Verify Flag - Not Supported\n");
1286 SET_AL( context, 0x00 ); /* pretend we can tell. 00h = off 01h = on */
1289 case 0x56: /* "RENAME" - RENAME FILE */
1290 INT_Int21Handler( context );
1293 case 0x57: /* FILE DATE AND TIME */
1294 if (!INT21_FileDateTime( context ))
1295 bSetDOSExtendedError = TRUE;
1298 case 0x58: /* GET OR SET MEMORY ALLOCATION STRATEGY */
1299 switch (AL_reg(context))
1301 case 0x00: /* GET MEMORY ALLOCATION STRATEGY */
1302 TRACE( "GET MEMORY ALLOCATION STRATEGY\n" );
1303 SET_AX( context, 0 ); /* low memory first fit */
1306 case 0x01: /* SET ALLOCATION STRATEGY */
1307 TRACE( "SET MEMORY ALLOCATION STRATEGY to %d - ignored\n",
1311 case 0x02: /* GET UMB LINK STATE */
1312 TRACE( "GET UMB LINK STATE\n" );
1313 SET_AL( context, 0 ); /* UMBs not part of DOS memory chain */
1316 case 0x03: /* SET UMB LINK STATE */
1317 TRACE( "SET UMB LINK STATE to %d - ignored\n",
1322 INT_BARF( context, 0x21 );
1326 case 0x59: /* GET EXTENDED ERROR INFO */
1327 INT21_GetExtendedError( context );
1330 case 0x5a: /* CREATE TEMPORARY FILE */
1331 case 0x5b: /* CREATE NEW FILE */
1332 INT_Int21Handler( context );
1335 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1337 DWORD offset = MAKELONG(DX_reg(context), CX_reg(context));
1338 DWORD length = MAKELONG(DI_reg(context), SI_reg(context));
1339 HANDLE handle = DosFileHandleToWin32Handle(BX_reg(context));
1341 switch (AL_reg(context))
1343 case 0x00: /* LOCK */
1344 TRACE( "lock handle %d offset %ld length %ld\n",
1345 BX_reg(context), offset, length );
1346 if (!LockFile( handle, offset, 0, length, 0 ))
1347 bSetDOSExtendedError = TRUE;
1350 case 0x01: /* UNLOCK */
1351 TRACE( "unlock handle %d offset %ld length %ld\n",
1352 BX_reg(context), offset, length );
1353 if (!UnlockFile( handle, offset, 0, length, 0 ))
1354 bSetDOSExtendedError = TRUE;
1358 INT_BARF( context, 0x21 );
1363 case 0x5d: /* NETWORK 5D */
1364 FIXME( "Network function 5D not implemented.\n" );
1365 SetLastError( ER_NoNetwork );
1366 bSetDOSExtendedError = TRUE;
1369 case 0x5e: /* NETWORK 5E */
1370 case 0x5f: /* NETWORK 5F */
1371 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1372 INT_Int21Handler( context );
1375 case 0x61: /* UNUSED */
1376 SET_AL( context, 0 );
1379 case 0x62: /* GET PSP ADDRESS */
1380 INT21_GetPSP( context );
1383 case 0x63: /* MISC. LANGUAGE SUPPORT */
1384 switch (AL_reg(context)) {
1385 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1386 TRACE( "GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE\n" );
1387 context->SegDs = INT21_GetHeapSelector( context );
1388 SET_SI( context, offsetof(INT21_HEAP, dbcs_table) );
1389 SET_AL( context, 0 ); /* success */
1394 case 0x64: /* OS/2 DOS BOX */
1395 INT_BARF( context, 0x21 );
1399 case 0x65: /* EXTENDED COUNTRY INFORMATION */
1400 INT21_ExtendedCountryInformation( context );
1403 case 0x66: /* GLOBAL CODE PAGE TABLE */
1404 switch (AL_reg(context))
1407 TRACE( "GET GLOBAL CODE PAGE TABLE\n" );
1408 SET_BX( context, GetOEMCP() );
1409 SET_DX( context, GetOEMCP() );
1412 FIXME( "SET GLOBAL CODE PAGE TABLE, active %d, system %d - ignored\n",
1413 BX_reg(context), DX_reg(context) );
1418 case 0x67: /* SET HANDLE COUNT */
1419 TRACE( "SET HANDLE COUNT to %d\n", BX_reg(context) );
1420 if (SetHandleCount( BX_reg(context) ) < BX_reg(context) )
1421 bSetDOSExtendedError = TRUE;
1424 case 0x68: /* "FFLUSH" - COMMIT FILE */
1425 TRACE( "FFLUSH - handle %d\n", BX_reg(context) );
1426 if (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context)) ))
1427 bSetDOSExtendedError = TRUE;
1430 case 0x69: /* DISK SERIAL NUMBER */
1431 INT_Int21Handler( context );
1434 case 0x6a: /* COMMIT FILE */
1435 TRACE( "COMMIT FILE - handle %d\n", BX_reg(context) );
1436 if (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context)) ))
1437 bSetDOSExtendedError = TRUE;
1440 case 0x6b: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
1441 SET_AL( context, 0 );
1444 case 0x6c: /* EXTENDED OPEN/CREATE */
1445 INT_Int21Handler( context );
1448 case 0x70: /* MSDOS 7 - GET/SET INTERNATIONALIZATION INFORMATION */
1449 FIXME( "MS-DOS 7 - GET/SET INTERNATIONALIZATION INFORMATION\n" );
1450 SET_CFLAG( context );
1451 SET_AL( context, 0 );
1454 case 0x71: /* MSDOS 7 - LONG FILENAME FUNCTIONS */
1455 INT_Int21Handler( context );
1458 case 0x73: /* MSDOS7 - FAT32 */
1459 INT_Int21Handler( context );
1462 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1463 TRACE( "CONNECTION SERVICES - GET CONNECTION NUMBER - ignored\n" );
1466 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1467 TRACE( "NOVELL NETWARE - RETURN SHELL VERSION - ignored\n" );
1471 INT_BARF( context, 0x21 );
1474 } /* END OF SWITCH */
1476 /* Set general error condition. */
1477 if (bSetDOSExtendedError)
1479 SET_AX( context, GetLastError() );
1480 SET_CFLAG( context );
1483 /* Print error code if carry flag is set. */
1484 if (context->EFlags & 0x0001)
1485 TRACE("failed, error %ld\n", GetLastError() );
1487 TRACE( "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
1488 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1489 AX_reg(context), BX_reg(context),
1490 CX_reg(context), DX_reg(context),
1491 SI_reg(context), DI_reg(context),
1492 (WORD)context->SegDs, (WORD)context->SegEs,