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 /***********************************************************************
86 * INT21_GetSystemCountryCode
88 * Return DOS country code for default system locale.
90 static WORD INT21_GetSystemCountryCode()
93 * FIXME: Determine country code. We should probably use
94 * DOSCONF structure for that.
96 return GetSystemDefaultLangID();
100 /***********************************************************************
101 * INT21_FillCountryInformation
103 * Fill 34-byte buffer with country information data using
104 * default system locale.
106 static void INT21_FillCountryInformation( BYTE *buffer )
108 /* 00 - WORD: date format
113 *(WORD*)(buffer + 0) = 0; /* FIXME: Get from locale */
115 /* 02 - BYTE[5]: ASCIIZ currency symbol string */
116 buffer[2] = '$'; /* FIXME: Get from locale */
119 /* 07 - BYTE[2]: ASCIIZ thousands separator */
120 buffer[7] = 0; /* FIXME: Get from locale */
123 /* 09 - BYTE[2]: ASCIIZ decimal separator */
124 buffer[9] = '.'; /* FIXME: Get from locale */
127 /* 11 - BYTE[2]: ASCIIZ date separator */
128 buffer[11] = '/'; /* FIXME: Get from locale */
131 /* 13 - BYTE[2]: ASCIIZ time separator */
132 buffer[13] = ':'; /* FIXME: Get from locale */
135 /* 15 - BYTE: Currency format
136 * bit 2 = set if currency symbol replaces decimal point
137 * bit 1 = number of spaces between value and currency symbol
138 * bit 0 = 0 if currency symbol precedes value
139 * 1 if currency symbol follows value
141 buffer[15] = 0; /* FIXME: Get from locale */
143 /* 16 - BYTE: Number of digits after decimal in currency */
144 buffer[16] = 0; /* FIXME: Get from locale */
146 /* 17 - BYTE: Time format
147 * bit 0 = 0 if 12-hour clock
150 buffer[17] = 1; /* FIXME: Get from locale */
152 /* 18 - DWORD: Address of case map routine */
153 *(DWORD*)(buffer + 18) = 0; /* FIXME: ptr to case map routine */
155 /* 22 - BYTE[2]: ASCIIZ data-list separator */
156 buffer[22] = ','; /* FIXME: Get from locale */
159 /* 24 - BYTE[10]: Reserved */
160 memset( buffer + 24, 0, 10 );
164 /***********************************************************************
167 * Initialize DOS heap.
169 static void INT21_FillHeap( INT21_HEAP *heap )
171 static const char terminators[] = "\"\\./[]:|<>+=;,";
177 heap->uppercase_size = 128;
178 for (i = 0; i < 128; i++)
179 heap->uppercase_table[i] = toupper( 128 + i );
184 heap->lowercase_size = 256;
185 for (i = 0; i < 256; i++)
186 heap->lowercase_table[i] = tolower( i );
191 heap->collating_size = 256;
192 for (i = 0; i < 256; i++)
193 heap->collating_table[i] = i;
198 heap->filename_size = 8 + strlen(terminators);
199 heap->filename_illegal_size = strlen(terminators);
200 strcpy( heap->filename_illegal_table, terminators );
202 heap->filename_reserved1 = 0x01;
203 heap->filename_lowest = 0; /* FIXME: correct value? */
204 heap->filename_highest = 0xff; /* FIXME: correct value? */
205 heap->filename_reserved2 = 0x00;
206 heap->filename_exclude_first = 0x00; /* FIXME: correct value? */
207 heap->filename_exclude_last = 0x00; /* FIXME: correct value? */
208 heap->filename_reserved3 = 0x02;
211 * DBCS lead byte table. This table is empty.
214 memset( heap->dbcs_table, 0, sizeof(heap->dbcs_table) );
217 * Initialize InDos flag.
219 heap->misc_indos = 0;
223 /***********************************************************************
224 * INT21_GetHeapSelector
226 * Get segment/selector for DOS heap (INT21_HEAP).
227 * Creates and initializes heap on first call.
229 static WORD INT21_GetHeapSelector( CONTEXT86 *context )
231 static WORD heap_segment = 0;
232 static WORD heap_selector = 0;
233 static BOOL heap_initialized = FALSE;
235 if (!heap_initialized)
237 INT21_HEAP *ptr = DOSVM_AllocDataUMB( sizeof(INT21_HEAP),
240 INT21_FillHeap( ptr );
241 heap_initialized = TRUE;
244 if (!ISV86(context) && DOSVM_IsWin16())
245 return heap_selector;
251 /***********************************************************************
252 * INT21_ExtendedCountryInformation
254 * Handler for function 0x65.
256 static void INT21_ExtendedCountryInformation( CONTEXT86 *context )
258 BYTE *dataptr = CTX_SEG_OFF_TO_LIN( context, context->SegEs, context->Edi );
260 TRACE( "GET EXTENDED COUNTRY INFORMATION, subfunction %02x\n",
264 * Check subfunctions that are passed country and code page.
266 if (AL_reg(context) >= 0x01 && AL_reg(context) <= 0x07)
268 WORD country = DX_reg(context);
269 WORD codepage = BX_reg(context);
271 if (country != 0xffff && country != INT21_GetSystemCountryCode())
272 FIXME( "Requested info on non-default country %04x\n", country );
274 if (codepage != 0xffff && codepage != GetOEMCP())
275 FIXME( "Requested info on non-default code page %04x\n", codepage );
278 switch (AL_reg(context)) {
279 case 0x00: /* SET GENERAL INTERNATIONALIZATION INFO */
280 INT_BARF( context, 0x21 );
281 SET_CFLAG( context );
284 case 0x01: /* GET GENERAL INTERNATIONALIZATION INFO */
285 TRACE( "Get general internationalization info\n" );
286 dataptr[0] = 0x01; /* Info ID */
287 *(WORD*)(dataptr+1) = 38; /* Size of the following info */
288 *(WORD*)(dataptr+3) = INT21_GetSystemCountryCode(); /* Country ID */
289 *(WORD*)(dataptr+5) = GetOEMCP(); /* Code page */
290 INT21_FillCountryInformation( dataptr + 7 );
291 SET_CX( context, 41 ); /* Size of returned info */
294 case 0x02: /* GET POINTER TO UPPERCASE TABLE */
295 case 0x04: /* GET POINTER TO FILENAME UPPERCASE TABLE */
296 TRACE( "Get pointer to uppercase table\n" );
297 dataptr[0] = AL_reg(context); /* Info ID */
298 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
299 offsetof(INT21_HEAP, uppercase_size) );
300 SET_CX( context, 5 ); /* Size of returned info */
303 case 0x03: /* GET POINTER TO LOWERCASE TABLE */
304 TRACE( "Get pointer to lowercase table\n" );
305 dataptr[0] = 0x03; /* Info ID */
306 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
307 offsetof(INT21_HEAP, lowercase_size) );
308 SET_CX( context, 5 ); /* Size of returned info */
311 case 0x05: /* GET POINTER TO FILENAME TERMINATOR TABLE */
312 TRACE("Get pointer to filename terminator table\n");
313 dataptr[0] = 0x05; /* Info ID */
314 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
315 offsetof(INT21_HEAP, filename_size) );
316 SET_CX( context, 5 ); /* Size of returned info */
319 case 0x06: /* GET POINTER TO COLLATING SEQUENCE TABLE */
320 TRACE("Get pointer to collating sequence table\n");
321 dataptr[0] = 0x06; /* Info ID */
322 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
323 offsetof(INT21_HEAP, collating_size) );
324 SET_CX( context, 5 ); /* Size of returned info */
327 case 0x07: /* GET POINTER TO DBCS LEAD BYTE TABLE */
328 TRACE("Get pointer to DBCS lead byte table\n");
329 dataptr[0] = 0x07; /* Info ID */
330 *(DWORD*)(dataptr+1) = MAKESEGPTR( INT21_GetHeapSelector( context ),
331 offsetof(INT21_HEAP, dbcs_size) );
332 SET_CX( context, 5 ); /* Size of returned info */
335 case 0x20: /* CAPITALIZE CHARACTER */
336 case 0xa0: /* CAPITALIZE FILENAME CHARACTER */
337 TRACE("Convert char to uppercase\n");
338 SET_DL( context, toupper(DL_reg(context)) );
341 case 0x21: /* CAPITALIZE STRING */
342 case 0xa1: /* CAPITALIZE COUNTED FILENAME STRING */
343 TRACE("Convert string to uppercase with length\n");
345 char *ptr = (char *)CTX_SEG_OFF_TO_LIN( context,
348 WORD len = CX_reg(context);
349 while (len--) { *ptr = toupper(*ptr); ptr++; }
353 case 0x22: /* CAPITALIZE ASCIIZ STRING */
354 case 0xa2: /* CAPITALIZE ASCIIZ FILENAME */
355 TRACE("Convert ASCIIZ string to uppercase\n");
356 _strupr( (LPSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx) );
359 case 0x23: /* DETERMINE IF CHARACTER REPRESENTS YES/NO RESPONSE */
360 INT_BARF( context, 0x21 );
361 SET_CFLAG( context );
365 INT_BARF( context, 0x21 );
372 /***********************************************************************
375 * Handler for functions 0x51 and 0x62.
377 static void INT21_GetPSP( CONTEXT86 *context )
379 TRACE( "GET CURRENT PSP ADDRESS (%02x)\n", AH_reg(context) );
382 * FIXME: should we return the original DOS PSP upon
385 if (!ISV86(context) && DOSVM_IsWin16())
386 SET_BX( context, LOWORD(GetCurrentPDB16()) );
388 SET_BX( context, DOSVM_psp );
392 /***********************************************************************
395 * Handler for function 0x44.
397 static void INT21_Ioctl( CONTEXT86 *context )
399 static const WCHAR emmxxxx0W[] = {'E','M','M','X','X','X','X','0',0};
400 const DOS_DEVICE *dev = DOSFS_GetDeviceByHandle(
401 DosFileHandleToWin32Handle(BX_reg(context)) );
403 if (dev && !strcmpiW( dev->name, emmxxxx0W )) {
404 EMS_Ioctl_Handler(context);
408 switch (AL_reg(context))
410 case 0x0b: /* SET SHARING RETRY COUNT */
411 TRACE("IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
412 CX_reg(context), DX_reg(context));
413 if (!CX_reg(context))
415 SET_AX( context, 1 );
419 DOSMEM_LOL()->sharing_retry_delay = CX_reg(context);
420 if (!DX_reg(context))
421 DOSMEM_LOL()->sharing_retry_count = DX_reg(context);
422 RESET_CFLAG(context);
425 INT_Int21Handler( context );
430 /***********************************************************************
431 * INT21_GetExtendedError
433 static void INT21_GetExtendedError( CONTEXT86 *context )
435 BYTE class, action, locus;
436 WORD error = GetLastError();
441 class = action = locus = 0;
443 case ERROR_DIR_NOT_EMPTY:
448 case ERROR_ACCESS_DENIED:
449 class = EC_AccessDenied;
453 case ERROR_CANNOT_MAKE:
454 class = EC_AccessDenied;
458 case ERROR_DISK_FULL:
459 case ERROR_HANDLE_DISK_FULL:
460 class = EC_MediaError;
464 case ERROR_FILE_EXISTS:
465 case ERROR_ALREADY_EXISTS:
470 case ERROR_FILE_NOT_FOUND:
475 case ER_GeneralFailure:
476 class = EC_SystemFailure;
480 case ERROR_INVALID_DRIVE:
481 class = EC_MediaError;
485 case ERROR_INVALID_HANDLE:
486 class = EC_ProgramError;
490 case ERROR_LOCK_VIOLATION:
491 class = EC_AccessDenied;
495 case ERROR_NO_MORE_FILES:
496 class = EC_MediaError;
505 case ERROR_NOT_ENOUGH_MEMORY:
506 class = EC_OutOfResource;
510 case ERROR_PATH_NOT_FOUND:
520 case ERROR_SHARING_VIOLATION:
521 class = EC_Temporary;
525 case ERROR_TOO_MANY_OPEN_FILES:
526 class = EC_ProgramError;
531 FIXME("Unknown error %d\n", error );
532 class = EC_SystemFailure;
537 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
538 error, class, action, locus );
539 SET_AX( context, error );
540 SET_BH( context, class );
541 SET_BL( context, action );
542 SET_CH( context, locus );
546 /***********************************************************************
547 * DOSVM_Int21Handler (WINEDOS16.133)
549 * Interrupt 0x21 handler.
551 void WINAPI DOSVM_Int21Handler( CONTEXT86 *context )
553 BOOL bSetDOSExtendedError = FALSE;
555 TRACE( "AX=%04x BX=%04x CX=%04x DX=%04x "
556 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
557 AX_reg(context), BX_reg(context),
558 CX_reg(context), DX_reg(context),
559 SI_reg(context), DI_reg(context),
560 (WORD)context->SegDs, (WORD)context->SegEs,
564 * Extended error is used by (at least) functions 0x2f to 0x62.
565 * Function 0x59 returns extended error and error should not
566 * be cleared before handling the function.
568 if (AH_reg(context) >= 0x2f && AH_reg(context) != 0x59)
571 RESET_CFLAG(context); /* Not sure if this is a good idea. */
573 switch(AH_reg(context))
575 case 0x00: /* TERMINATE PROGRAM */
576 TRACE("TERMINATE PROGRAM\n");
580 MZ_Exit( context, FALSE, 0 );
583 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
586 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
587 DOSVM_Int16ReadChar(&ascii, NULL, FALSE);
588 SET_AL( context, ascii );
589 DOSVM_PutChar(AL_reg(context));
593 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
594 TRACE("Write Character to Standard Output\n");
595 DOSVM_PutChar(DL_reg(context));
598 case 0x03: /* READ CHARACTER FROM STDAUX */
599 case 0x04: /* WRITE CHARACTER TO STDAUX */
600 case 0x05: /* WRITE CHARACTER TO PRINTER */
601 INT_BARF( context, 0x21 );
604 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
605 /* FIXME: Use DOSDEV_Peek/Read/Write(DOSDEV_Console(),...) !! */
606 if (DL_reg(context) == 0xff) {
607 static char scan = 0;
608 TRACE("Direct Console Input\n");
610 /* return pending scancode */
611 SET_AL( context, scan );
612 RESET_ZFLAG(context);
616 if (DOSVM_Int16ReadChar(&ascii,&scan,TRUE)) {
617 DOSVM_Int16ReadChar(&ascii,&scan,FALSE);
618 /* return ASCII code */
619 SET_AL( context, ascii );
620 RESET_ZFLAG(context);
621 /* return scan code on next call only if ascii==0 */
624 /* nothing pending, clear everything */
625 SET_AL( context, 0 );
627 scan = 0; /* just in case */
631 TRACE("Direct Console Output\n");
632 DOSVM_PutChar(DL_reg(context));
636 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
639 /* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
640 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
641 DOSVM_Int16ReadChar(&ascii, NULL, FALSE);
642 SET_AL( context, ascii );
646 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
649 /* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
650 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
651 DOSVM_Int16ReadChar(&ascii, NULL, FALSE);
652 SET_AL( context, ascii );
656 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
657 INT_Int21Handler( context );
660 case 0x0a: /* BUFFERED INPUT */
661 INT_Int21Handler( context );
664 case 0x0b: /* GET STDIN STATUS */
665 TRACE( "GET STDIN STATUS\n" );
667 BIOSDATA *data = BIOS_DATA;
668 if(data->FirstKbdCharPtr == data->NextKbdCharPtr)
669 SET_AL( context, 0 );
671 SET_AL( context, 0xff );
675 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
677 BYTE al = AL_reg(context); /* Input function to execute after flush. */
679 TRACE( "FLUSH BUFFER AND READ STANDARD INPUT - 0x%02x\n", al );
681 /* FIXME: buffers are not flushed */
684 * If AL is one of 0x01, 0x06, 0x07, 0x08, or 0x0a,
685 * int21 function identified by AL will be called.
687 if(al == 0x01 || al == 0x06 || al == 0x07 || al == 0x08 || al == 0x0a)
689 SET_AH( context, al );
690 DOSVM_Int21Handler( context );
695 case 0x0d: /* DISK BUFFER FLUSH */
696 TRACE("DISK BUFFER FLUSH ignored\n");
699 case 0x0e: /* SELECT DEFAULT DRIVE */
700 INT_Int21Handler( context );
703 case 0x0f: /* OPEN FILE USING FCB */
704 case 0x10: /* CLOSE FILE USING FCB */
705 INT_BARF( context, 0x21 );
708 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
709 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
710 INT_Int21Handler( context );
713 case 0x13: /* DELETE FILE USING FCB */
714 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
715 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
716 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
717 case 0x17: /* RENAME FILE USING FCB */
718 INT_BARF( context, 0x21 );
721 case 0x18: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
722 SET_AL( context, 0 );
725 case 0x19: /* GET CURRENT DEFAULT DRIVE */
726 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
727 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
728 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
729 INT_Int21Handler( context );
732 case 0x1d: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
733 case 0x1e: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
734 SET_AL( context, 0 );
737 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
738 INT_Int21Handler( context );
741 case 0x20: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
742 SET_AL( context, 0 );
745 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
746 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
747 case 0x23: /* GET FILE SIZE FOR FCB */
748 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
749 INT_BARF( context, 0x21 );
752 case 0x25: /* SET INTERRUPT VECTOR */
753 TRACE("SET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
755 FARPROC16 ptr = (FARPROC16)MAKESEGPTR( context->SegDs, DX_reg(context) );
756 if (!ISV86(context) && DOSVM_IsWin16())
757 DOSVM_SetPMHandler16( AL_reg(context), ptr );
759 DOSVM_SetRMHandler( AL_reg(context), ptr );
763 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
764 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
765 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
766 INT_BARF( context, 0x21 );
769 case 0x29: /* PARSE FILENAME INTO FCB */
770 INT_Int21Handler( context );
773 case 0x2a: /* GET SYSTEM DATE */
774 TRACE( "GET SYSTEM DATE\n" );
777 GetLocalTime( &systime );
778 SET_CX( context, systime.wYear );
779 SET_DH( context, systime.wMonth );
780 SET_DL( context, systime.wDay );
781 SET_AL( context, systime.wDayOfWeek );
785 case 0x2b: /* SET SYSTEM DATE */
786 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
787 DL_reg(context), DH_reg(context), CX_reg(context) );
788 SET_AL( context, 0 ); /* Let's pretend we succeeded */
791 case 0x2c: /* GET SYSTEM TIME */
792 TRACE( "GET SYSTEM TIME\n" );
795 GetLocalTime( &systime );
796 SET_CH( context, systime.wHour );
797 SET_CL( context, systime.wMinute );
798 SET_DH( context, systime.wSecond );
799 SET_DL( context, systime.wMilliseconds / 10 );
803 case 0x2d: /* SET SYSTEM TIME */
804 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
805 CH_reg(context), CL_reg(context),
806 DH_reg(context), DL_reg(context) );
807 SET_AL( context, 0 ); /* Let's pretend we succeeded */
810 case 0x2e: /* SET VERIFY FLAG */
811 TRACE("SET VERIFY FLAG ignored\n");
812 /* we cannot change the behaviour anyway, so just ignore it */
815 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
816 INT_Int21Handler( context );
819 case 0x30: /* GET DOS VERSION */
820 TRACE( "GET DOS VERSION - %s requested\n",
821 (AL_reg(context) == 0x00) ? "OEM number" : "version flag" );
823 SET_AL( context, HIBYTE(HIWORD(GetVersion16())) ); /* major version */
824 SET_AH( context, LOBYTE(HIWORD(GetVersion16())) ); /* minor version */
826 if (AL_reg(context) == 0x00)
827 SET_BH( context, 0xff ); /* OEM number => undefined */
829 SET_BH( context, 0x08 ); /* version flag => DOS is in ROM */
831 SET_BL( context, 0x12 ); /* 0x123456 is Wine's serial # */
832 SET_CX( context, 0x3456 );
835 case 0x31: /* TERMINATE AND STAY RESIDENT */
836 FIXME("TERMINATE AND STAY RESIDENT stub\n");
839 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
840 case 0x33: /* MULTIPLEXED */
841 INT_Int21Handler( context );
844 case 0x34: /* GET ADDRESS OF INDOS FLAG */
845 TRACE( "GET ADDRESS OF INDOS FLAG\n" );
846 context->SegEs = INT21_GetHeapSelector( context );
847 SET_BX( context, offsetof(INT21_HEAP, misc_indos) );
850 case 0x35: /* GET INTERRUPT VECTOR */
851 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
854 if (!ISV86(context) && DOSVM_IsWin16())
855 addr = DOSVM_GetPMHandler16( AL_reg(context) );
857 addr = DOSVM_GetRMHandler( AL_reg(context) );
858 context->SegEs = SELECTOROF(addr);
859 SET_BX( context, OFFSETOF(addr) );
863 case 0x36: /* GET FREE DISK SPACE */
864 case 0x37: /* SWITCHAR */
865 INT_Int21Handler( context );
868 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
869 TRACE( "GET COUNTRY-SPECIFIC INFORMATION\n" );
872 WORD country = AL_reg(context);
874 country = BX_reg(context);
875 if (country != INT21_GetSystemCountryCode())
876 FIXME( "Requested info on non-default country %04x\n", country );
878 INT21_FillCountryInformation( CTX_SEG_OFF_TO_LIN(context,
881 SET_AX( context, INT21_GetSystemCountryCode() );
882 SET_BX( context, INT21_GetSystemCountryCode() );
885 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
886 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
887 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
888 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
889 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
890 case 0x3e: /* "CLOSE" - CLOSE FILE */
891 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
892 INT_Int21Handler( context );
895 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
896 TRACE( "WRITE from %04lX:%04X to handle %d for %d byte\n",
897 context->SegDs, DX_reg(context),
898 BX_reg(context), CX_reg(context) );
900 BYTE *ptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
902 if (!DOSVM_IsWin16() && BX_reg(context) == 1)
905 for(i=0; i<CX_reg(context); i++)
906 DOSVM_PutChar(ptr[i]);
907 SET_AX(context, CX_reg(context));
911 HFILE handle = (HFILE)DosFileHandleToWin32Handle(BX_reg(context));
912 LONG result = _hwrite( handle, ptr, CX_reg(context) );
913 if (result == HFILE_ERROR)
914 bSetDOSExtendedError = TRUE;
916 SET_AX( context, (WORD)result );
921 case 0x41: /* "UNLINK" - DELETE FILE */
922 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
923 case 0x43: /* FILE ATTRIBUTES */
924 INT_Int21Handler( context );
927 case 0x44: /* IOCTL */
928 INT21_Ioctl( context );
931 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
932 TRACE( "DUPLICATE FILE HANDLE %d\n", BX_reg(context) );
935 HFILE handle16 = HFILE_ERROR;
937 if (DuplicateHandle( GetCurrentProcess(),
938 DosFileHandleToWin32Handle(BX_reg(context)),
941 0, TRUE, DUPLICATE_SAME_ACCESS ))
942 handle16 = Win32HandleToDosFileHandle(handle32);
944 if (handle16 == HFILE_ERROR)
945 bSetDOSExtendedError = TRUE;
947 SET_AX( context, handle16 );
951 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
952 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
953 INT_Int21Handler( context );
956 case 0x48: /* ALLOCATE MEMORY */
957 TRACE( "ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context) );
960 DWORD bytes = (DWORD)BX_reg(context) << 4;
962 if (!ISV86(context) && DOSVM_IsWin16())
964 DWORD rv = GlobalDOSAlloc16( bytes );
965 selector = LOWORD( rv );
968 DOSMEM_GetBlock( bytes, &selector );
971 SET_AX( context, selector );
975 SET_AX( context, 0x0008 ); /* insufficient memory */
976 SET_BX( context, DOSMEM_Available() >> 4 );
981 case 0x49: /* FREE MEMORY */
982 TRACE( "FREE MEMORY segment %04lX\n", context->SegEs );
986 if (!ISV86(context) && DOSVM_IsWin16())
988 ok = !GlobalDOSFree16( context->SegEs );
990 /* If we don't reset ES_reg, we will fail in the relay code */
995 ok = DOSMEM_FreeBlock( (void*)((DWORD)context->SegEs << 4) );
999 TRACE("FREE MEMORY failed\n");
1001 SET_AX( context, 0x0009 ); /* memory block address invalid */
1006 case 0x4a: /* RESIZE MEMORY BLOCK */
1007 INT_Int21Handler( context );
1010 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1012 BYTE *program = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
1013 BYTE *paramblk = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
1015 TRACE( "EXEC %s\n", program );
1017 if (DOSVM_IsWin16())
1019 HINSTANCE16 instance = WinExec16( program, SW_NORMAL );
1022 SET_CFLAG( context );
1023 SET_AX( context, instance );
1028 if (!MZ_Exec( context, program, AL_reg(context), paramblk))
1029 bSetDOSExtendedError = TRUE;
1034 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1035 TRACE( "EXIT with return code %d\n", AL_reg(context) );
1036 if (DOSVM_IsWin16())
1037 ExitThread( AL_reg(context) );
1039 MZ_Exit( context, FALSE, AL_reg(context) );
1042 case 0x4d: /* GET RETURN CODE */
1043 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
1044 SET_AX( context, DOSVM_retval );
1048 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1049 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1050 INT_Int21Handler( context );
1053 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1054 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1055 DOSVM_psp = BX_reg(context);
1058 case 0x51: /* GET PSP ADDRESS */
1059 INT21_GetPSP( context );
1062 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1063 if (!ISV86(context) && DOSVM_IsWin16())
1065 SEGPTR ptr = DOSMEM_LOL()->wine_pm_lol;
1066 context->SegEs = SELECTOROF(ptr);
1067 SET_BX( context, OFFSETOF(ptr) );
1071 SEGPTR ptr = DOSMEM_LOL()->wine_rm_lol;
1072 context->SegEs = SELECTOROF(ptr);
1073 SET_BX( context, OFFSETOF(ptr) );
1077 case 0x54: /* Get Verify Flag */
1078 TRACE("Get Verify Flag - Not Supported\n");
1079 SET_AL( context, 0x00 ); /* pretend we can tell. 00h = off 01h = on */
1082 case 0x56: /* "RENAME" - RENAME FILE */
1083 case 0x57: /* FILE DATE AND TIME */
1084 INT_Int21Handler( context );
1087 case 0x58: /* GET OR SET MEMORY ALLOCATION STRATEGY */
1088 TRACE( "GET OR SET MEMORY ALLOCATION STRATEGY, subfunction %d\n",
1090 switch (AL_reg(context))
1092 case 0x00: /* GET ALLOCATION STRATEGY */
1093 SET_AX( context, 1 ); /* low memory best fit */
1096 case 0x01: /* SET ALLOCATION STRATEGY */
1097 TRACE( "Set allocation strategy to %d - ignored\n",
1102 INT_BARF( context, 0x21 );
1107 case 0x59: /* GET EXTENDED ERROR INFO */
1108 INT21_GetExtendedError( context );
1111 case 0x5a: /* CREATE TEMPORARY FILE */
1112 case 0x5b: /* CREATE NEW FILE */
1113 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1114 case 0x5d: /* NETWORK 5D */
1115 case 0x5e: /* NETWORK 5E */
1116 case 0x5f: /* NETWORK 5F */
1117 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1118 INT_Int21Handler( context );
1121 case 0x61: /* UNUSED */
1122 SET_AL( context, 0 );
1125 case 0x62: /* GET PSP ADDRESS */
1126 INT21_GetPSP( context );
1129 case 0x63: /* MISC. LANGUAGE SUPPORT */
1130 switch (AL_reg(context)) {
1131 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1132 TRACE( "GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE\n" );
1133 context->SegDs = INT21_GetHeapSelector( context );
1134 SET_SI( context, offsetof(INT21_HEAP, dbcs_table) );
1135 SET_AL( context, 0 ); /* success */
1140 case 0x64: /* OS/2 DOS BOX */
1141 INT_BARF( context, 0x21 );
1145 case 0x65: /* EXTENDED COUNTRY INFORMATION */
1146 INT21_ExtendedCountryInformation( context );
1149 case 0x66: /* GLOBAL CODE PAGE TABLE */
1150 switch (AL_reg(context))
1153 TRACE( "GET GLOBAL CODE PAGE TABLE\n" );
1154 SET_BX( context, GetOEMCP() );
1155 SET_DX( context, GetOEMCP() );
1158 FIXME( "SET GLOBAL CODE PAGE TABLE, active %d, system %d - ignored\n",
1159 BX_reg(context), DX_reg(context) );
1164 case 0x67: /* SET HANDLE COUNT */
1165 TRACE( "SET HANDLE COUNT to %d\n", BX_reg(context) );
1166 if (SetHandleCount( BX_reg(context) ) < BX_reg(context) )
1167 bSetDOSExtendedError = TRUE;
1170 case 0x68: /* "FFLUSH" - COMMIT FILE */
1171 TRACE( "FFLUSH - handle %d\n", BX_reg(context) );
1172 if (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context)) ))
1173 bSetDOSExtendedError = TRUE;
1176 case 0x69: /* DISK SERIAL NUMBER */
1177 INT_Int21Handler( context );
1180 case 0x6a: /* COMMIT FILE */
1181 TRACE( "COMMIT FILE - handle %d\n", BX_reg(context) );
1182 if (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context)) ))
1183 bSetDOSExtendedError = TRUE;
1186 case 0x6b: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
1187 SET_AL( context, 0 );
1190 case 0x6c: /* EXTENDED OPEN/CREATE */
1191 INT_Int21Handler( context );
1194 case 0x70: /* MSDOS 7 - GET/SET INTERNATIONALIZATION INFORMATION */
1195 FIXME( "MS-DOS 7 - GET/SET INTERNATIONALIZATION INFORMATION\n" );
1196 SET_CFLAG( context );
1197 SET_AL( context, 0 );
1200 case 0x71: /* MSDOS 7 - LONG FILENAME FUNCTIONS */
1201 INT_Int21Handler( context );
1204 case 0x73: /* MSDOS7 - FAT32 */
1205 INT_Int21Handler( context );
1208 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1209 TRACE( "CONNECTION SERVICES - GET CONNECTION NUMBER - ignored\n" );
1212 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1213 TRACE( "NOVELL NETWARE - RETURN SHELL VERSION - ignored\n" );
1217 INT_BARF( context, 0x21 );
1220 } /* END OF SWITCH */
1222 /* Set general error condition. */
1223 if (bSetDOSExtendedError)
1225 SET_AX( context, GetLastError() );
1226 SET_CFLAG( context );
1229 /* Print error code if carry flag is set. */
1230 if (context->EFlags & 0x0001)
1231 TRACE("failed, error %ld\n", GetLastError() );
1233 TRACE( "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
1234 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1235 AX_reg(context), BX_reg(context),
1236 CX_reg(context), DX_reg(context),
1237 SI_reg(context), DI_reg(context),
1238 (WORD)context->SegDs, (WORD)context->SegEs,