2 * DOS interrupt 21h handler
10 # include <sys/file.h>
15 #include <sys/types.h>
28 #include "dosexe.h" /* for the MZ_SUPPORTED define */
32 #if defined(__svr4__) || defined(_SCO_DS)
33 /* SVR4 DOESNT do locking the same way must implement properly */
40 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
42 /* Define the drive parameter block, as used by int21/1F
43 * and int21/32. This table can be accessed through the
44 * global 'dpb' pointer, which points into the local dos
49 BYTE drive_num
; /* 0=A, etc. */
50 BYTE unit_num
; /* Drive's unit number (?) */
51 WORD sector_size
; /* Sector size in bytes */
52 BYTE high_sector
; /* Highest sector in a cluster */
53 BYTE shift
; /* Shift count (?) */
54 WORD reserved
; /* Number of reserved sectors at start */
55 BYTE num_FAT
; /* Number of FATs */
56 WORD dir_entries
; /* Number of root dir entries */
57 WORD first_data
; /* First data sector */
58 WORD high_cluster
; /* Highest cluster number */
59 WORD sectors_in_FAT
; /* Number of sectors per FAT */
60 WORD start_dir
; /* Starting sector of first dir */
61 DWORD driver_head
; /* Address of device driver header (?) */
62 BYTE media_ID
; /* Media ID */
63 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
64 DWORD next
; /* Pointer to next DPB in list */
65 WORD free_search
; /* Free cluster search start */
66 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
77 BYTE DummyDBCSLeadTable
[6];
79 static struct DosHeap
*heap
;
80 static WORD DosHeapHandle
;
82 WORD sharing_retries
= 3; /* number of retries at sharing violation */
83 WORD sharing_pause
= 1; /* pause between retries */
85 extern char TempDirectory
[];
87 static BOOL32
INT21_CreateHeap(void)
89 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
91 WARN(int21
, "Out of memory\n");
94 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
95 dpbsegptr
= PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
97 strcpy(heap
->biosdate
, "01/01/80");
98 memset(heap
->DummyDBCSLeadTable
, 0, 6);
102 static BYTE
*GetCurrentDTA( CONTEXT
*context
)
104 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
106 /* FIXME: This assumes DTA was set correctly! */
107 return (BYTE
*)CTX_SEG_OFF_TO_LIN( context
, SELECTOROF(pTask
->dta
),
108 (DWORD
)OFFSETOF(pTask
->dta
) );
112 void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
113 /* limited == TRUE is used with INT 0x21/0x440d */
118 setword(&data
[3], 0);
120 setword(&data
[6], 240);
121 setword(&data
[8], 64000);
123 setword(&data
[0x0b], 40);
124 setword(&data
[0x0d], 56);
125 setword(&data
[0x0f], 2);
126 setword(&data
[0x11], 0);
128 setword(&data
[0x1f], 800);
130 setword(&data
[0x22], 1);
132 } else { /* 1.44mb */
135 setword(&data
[3], 0);
137 setword(&data
[6], 240);
138 setword(&data
[8], 2880);
140 setword(&data
[0x0b], 6);
141 setword(&data
[0x0d], 18);
142 setword(&data
[0x0f], 2);
143 setword(&data
[0x11], 0);
145 setword(&data
[0x1f], 80);
147 setword(&data
[0x22], 2);
152 static int INT21_GetFreeDiskSpace( CONTEXT
*context
)
154 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
155 char root
[] = "A:\\";
157 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
158 if (!GetDiskFreeSpace32A( root
, &cluster_sectors
, §or_bytes
,
159 &free_clusters
, &total_clusters
)) return 0;
160 AX_reg(context
) = cluster_sectors
;
161 BX_reg(context
) = free_clusters
;
162 CX_reg(context
) = sector_bytes
;
163 DX_reg(context
) = total_clusters
;
167 static int INT21_GetDriveAllocInfo( CONTEXT
*context
)
169 if (!INT21_GetFreeDiskSpace( context
)) return 0;
170 if (!heap
&& !INT21_CreateHeap()) return 0;
171 heap
->mediaID
= 0xf0;
172 DS_reg(context
) = DosHeapHandle
;
173 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
177 static void GetDrivePB( CONTEXT
*context
, int drive
)
179 if(!DRIVE_IsValid(drive
))
181 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
182 AX_reg(context
) = 0x00ff;
184 else if (heap
|| INT21_CreateHeap())
186 FIXME(int21
, "GetDrivePB not fully implemented.\n");
188 /* FIXME: I have no idea what a lot of this information should
189 * say or whether it even really matters since we're not allowing
190 * direct block access. However, some programs seem to depend on
191 * getting at least _something_ back from here. The 'next' pointer
192 * does worry me, though. Should we have a complete table of
193 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
195 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
196 heap
->dpb
.sector_size
= 512;
197 heap
->dpb
.high_sector
= 1;
198 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
199 heap
->dpb
.reserved
= 0;
200 heap
->dpb
.num_FAT
= 1;
201 heap
->dpb
.dir_entries
= 2;
202 heap
->dpb
.first_data
= 2;
203 heap
->dpb
.high_cluster
= 64000;
204 heap
->dpb
.sectors_in_FAT
= 1;
205 heap
->dpb
.start_dir
= 1;
206 heap
->dpb
.driver_head
= 0;
207 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
208 heap
->dpb
.access_flag
= 0;
210 heap
->dpb
.free_search
= 0;
211 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
213 AL_reg(context
) = 0x00;
214 DS_reg(context
) = SELECTOROF(dpbsegptr
);
215 BX_reg(context
) = OFFSETOF(dpbsegptr
);
220 static void ioctlGetDeviceInfo( CONTEXT
*context
)
223 const DOS_DEVICE
*dev
;
225 TRACE(int21
, "(%d)\n", BX_reg(context
));
227 RESET_CFLAG(context
);
230 if ((dev
= DOSFS_GetDeviceByHandle( FILE_GetHandle32(BX_reg(context
)) )))
232 DX_reg(context
) = dev
->flags
;
236 /* it seems to be a file */
237 curr_drive
= DRIVE_GetCurrentDrive();
238 DX_reg(context
) = 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0);
240 /* bits 0-5 are current drive
241 * bit 6 - file has NOT been written..FIXME: correct?
242 * bit 8 - generate int24 if no diskspace on write/ read past end of file
243 * bit 11 - media not removable
244 * bit 14 - don't set file date/time on closing
245 * bit 15 - file is remote
249 static BOOL32
ioctlGenericBlkDevReq( CONTEXT
*context
)
251 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
252 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
254 if (!DRIVE_IsValid(drive
))
256 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
260 if (CH_reg(context
) != 0x08)
262 INT_BARF( context
, 0x21 );
266 switch (CL_reg(context
))
268 case 0x4a: /* lock logical volume */
269 TRACE(int21
,"lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
272 case 0x60: /* get device parameters */
273 /* used by w4wgrp's winfile */
274 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
276 dataptr
[6] = 0; /* media type */
279 dataptr
[1] = 0x05; /* fixed disk */
280 setword(&dataptr
[2], 0x01); /* non removable */
281 setword(&dataptr
[4], 0x300); /* # of cylinders */
285 dataptr
[1] = 0x07; /* block dev, floppy */
286 setword(&dataptr
[2], 0x02); /* removable */
287 setword(&dataptr
[4], 80); /* # of cylinders */
289 CreateBPB(drive
, &dataptr
[7], TRUE
);
290 RESET_CFLAG(context
);
293 case 0x41: /* write logical device track */
294 case 0x61: /* read logical device track */
296 BYTE drive
= BL_reg(context
) ?
297 BL_reg(context
) : DRIVE_GetCurrentDrive();
298 WORD head
= *(WORD
*)dataptr
+1;
299 WORD cyl
= *(WORD
*)dataptr
+3;
300 WORD sect
= *(WORD
*)dataptr
+5;
301 WORD nrsect
= *(WORD
*)dataptr
+7;
302 BYTE
*data
= (BYTE
*)dataptr
+9;
303 int (*raw_func
)(BYTE
, DWORD
, DWORD
, BYTE
*, BOOL32
);
305 raw_func
= (CL_reg(context
) == 0x41) ?
306 DRIVE_RawWrite
: DRIVE_RawRead
;
308 if (raw_func(drive
, head
*cyl
*sect
, nrsect
, data
, FALSE
))
309 RESET_CFLAG(context
);
312 AX_reg(context
) = 0x1e; /* read fault */
317 case 0x66:/* get disk serial number */
319 char label
[12],fsname
[9],path
[4];
322 strcpy(path
,"x:\\");path
[0]=drive
+'A';
323 GetVolumeInformation32A(
324 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
327 memcpy(dataptr
+2,&serial
,4);
328 memcpy(dataptr
+6,label
,11);
329 memcpy(dataptr
+17,fsname
,8);
334 TRACE(int21
,"logical volume %d unlocked.\n",drive
);
338 memset(dataptr
+1, '\0', dataptr
[0]-1);
339 dataptr
[1] = dataptr
[0];
340 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
341 dataptr
[3] = 0xFF; /* no physical drive */
345 INT_BARF( context
, 0x21 );
350 static void INT21_ParseFileNameIntoFCB( CONTEXT
*context
)
353 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
) );
355 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), EDI_reg(context
) );
356 char *buffer
, *s
, *d
;
358 AL_reg(context
) = 0xff; /* failed */
360 TRACE(int21
, "filename: '%s'\n", filename
);
362 buffer
= HeapAlloc( GetProcessHeap(), 0, strlen(filename
) + 1);
368 if ((*s
!= ' ') && (*s
!= '\r') && (*s
!= '\n'))
375 DOSFS_ToDosFCBFormat(buffer
, fcb
+ 1);
377 TRACE(int21
, "FCB: '%s'\n", ((CHAR
*)fcb
+ 1));
379 HeapFree( GetProcessHeap(), 0, buffer
);
382 ((strchr(filename
, '*')) || (strchr(filename
, '$'))) != 0;
384 /* point DS:SI to first unparsed character */
385 SI_reg(context
) += (int)s
- (int)filename
;
388 static void INT21_GetSystemDate( CONTEXT
*context
)
391 GetLocalTime( &systime
);
392 CX_reg(context
) = systime
.wYear
;
393 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
394 AX_reg(context
) = systime
.wDayOfWeek
;
397 static void INT21_GetSystemTime( CONTEXT
*context
)
400 GetLocalTime( &systime
);
401 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
402 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
405 /* Many calls translate a drive argument like this:
406 drive number (00h = default, 01h = A:, etc)
408 static char drivestring
[]="default";
410 char *INT21_DriveName(int drive
)
415 drivestring
[0]= (unsigned char)drive
+ '@';
421 static BOOL32
INT21_CreateFile( CONTEXT
*context
)
423 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
424 EDX_reg(context
) ), CX_reg(context
) );
425 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
429 static void OpenExistingFile( CONTEXT
*context
)
431 AX_reg(context
) = _lopen16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
433 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
435 AX_reg(context
) = DOS_ExtendedError
;
444 switch (AX_reg(context
) & 0x0070)
446 case 0x00: /* compatability mode */
447 case 0x40: /* DENYNONE */
451 case 0x30: /* DENYREAD */
452 TRACE(int21
, "(%s): DENYREAD changed to DENYALL\n",
453 (char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
454 case 0x10: /* DENYALL */
458 case 0x20: /* DENYWRITE */
469 int result
,retries
=sharing_retries
;
471 #if defined(__svr4__) || defined(_SCO_DS)
472 ERR(int21
, "Should call flock and needs porting to lockf\n");
476 result
= flock(handle
, lock
| LOCK_NB
);
478 if ( retries
&& (!result
) )
481 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
482 result
++; /* stop the optimizer */
483 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
487 while( (!result
) && (!(retries
--)) );
492 AX_reg(context
) = DOS_ExtendedError
;
501 AX_reg(context
) = handle
;
502 RESET_CFLAG(context
);
507 static void CloseFile( CONTEXT
*context
)
509 if ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0)
511 AX_reg(context
) = DOS_ExtendedError
;
516 static BOOL32
INT21_ExtendedOpenCreateFile(CONTEXT
*context
)
518 BOOL32 bExtendedError
= FALSE
;
519 BYTE action
= DL_reg(context
);
521 /* Shuffle arguments to call OpenExistingFile */
522 AL_reg(context
) = BL_reg(context
);
523 DX_reg(context
) = SI_reg(context
);
524 /* BX,CX and DX should be preserved */
525 OpenExistingFile(context
);
527 if ((EFL_reg(context
) & 0x0001) == 0) /* File exists */
529 UINT16 uReturnCX
= 0;
531 /* Now decide what do do */
533 if ((action
& 0x07) == 0)
535 BX_reg(context
) = AX_reg(context
);
537 AX_reg(context
) = 0x0050; /*File exists*/
539 WARN(int21
, "extended open/create: failed because file exists \n");
541 else if ((action
& 0x07) == 2)
543 /* Truncate it, but first check if opened for write */
544 if ((BL_reg(context
) & 0x0007)== 0)
546 BX_reg(context
) = AX_reg(context
);
548 WARN(int21
, "extended open/create: failed, trunc on ro file\n");
549 AX_reg(context
) = 0x000C; /*Access code invalid*/
554 /* Shuffle arguments to call CloseFile while
555 * preserving BX and DX */
557 TRACE(int21
, "extended open/create: Closing before truncate\n");
558 BX_reg(context
) = AX_reg(context
);
560 if (EFL_reg(context
) & 0x0001)
562 WARN(int21
, "extended open/create: close before trunc failed\n");
563 AX_reg(context
) = 0x0019; /*Seek Error*/
567 /* Shuffle arguments to call CreateFile */
569 TRACE(int21
, "extended open/create: Truncating\n");
570 AL_reg(context
) = BL_reg(context
);
571 /* CX is still the same */
572 DX_reg(context
) = SI_reg(context
);
573 bExtendedError
= INT21_CreateFile(context
);
575 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
577 WARN(int21
, "extended open/create: trunc failed\n");
578 return bExtendedError
;
583 else uReturnCX
= 0x1;
585 CX_reg(context
) = uReturnCX
;
587 else /* file does not exist */
589 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
590 if ((action
& 0xF0)== 0)
594 WARN(int21
, "extended open/create: failed, file dosen't exist\n");
598 /* Shuffle arguments to call CreateFile */
599 TRACE(int21
, "extended open/create: Creating\n");
600 AL_reg(context
) = BL_reg(context
);
601 /* CX should still be the same */
602 DX_reg(context
) = SI_reg(context
);
603 bExtendedError
= INT21_CreateFile(context
);
604 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
606 WARN(int21
, "extended open/create: create failed\n");
607 return bExtendedError
;
613 return bExtendedError
;
617 static BOOL32
INT21_ChangeDir( CONTEXT
*context
)
620 char *dirname
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
));
622 TRACE(int21
,"changedir %s\n", dirname
);
623 if (dirname
[0] && (dirname
[1] == ':'))
625 drive
= toupper(dirname
[0]) - 'A';
628 else drive
= DRIVE_GetCurrentDrive();
629 return DRIVE_Chdir( drive
, dirname
);
633 static int INT21_FindFirst( CONTEXT
*context
)
637 DOS_FULL_NAME full_name
;
638 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
640 path
= (const char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
641 dta
->unixPath
= NULL
;
642 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
644 AX_reg(context
) = DOS_ExtendedError
;
648 dta
->unixPath
= HEAP_strdupA( GetProcessHeap(), 0, full_name
.long_name
);
649 p
= strrchr( dta
->unixPath
, '/' );
652 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
653 * (doesn't matter as it is set below anyway)
655 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
657 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
658 dta
->unixPath
= NULL
;
659 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
660 AX_reg(context
) = ER_FileNotFound
;
664 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
665 : DRIVE_GetCurrentDrive();
667 dta
->search_attr
= CL_reg(context
);
672 static int INT21_FindNext( CONTEXT
*context
)
674 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
675 WIN32_FIND_DATA32A entry
;
678 if (!dta
->unixPath
) return 0;
679 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
680 dta
->search_attr
, dta
->count
, &entry
)))
682 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
683 dta
->unixPath
= NULL
;
686 if ((int)dta
->count
+ count
> 0xffff)
688 WARN(int21
, "Too many directory entries in %s\n", dta
->unixPath
);
689 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
690 dta
->unixPath
= NULL
;
694 dta
->fileattr
= entry
.dwFileAttributes
;
695 dta
->filesize
= entry
.nFileSizeLow
;
696 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
697 &dta
->filedate
, &dta
->filetime
);
698 strcpy( dta
->filename
, entry
.cAlternateFileName
);
699 if (!memchr(dta
->mask
,'?',11)) {
700 /* wildcardless search, release resources in case no findnext will
701 * be issued, and as a workaround in case file creation messes up
702 * findnext, as sometimes happens with pkunzip */
703 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
704 dta
->unixPath
= NULL
;
710 static BOOL32
INT21_CreateTempFile( CONTEXT
*context
)
712 static int counter
= 0;
713 char *name
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
) );
714 char *p
= name
+ strlen(name
);
716 /* despite what Ralf Brown says, some programs seem to call without
717 * ending backslash (DOS accepts that, so we accept it too) */
718 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
722 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
723 counter
= (counter
+ 1) % 1000;
725 if ((AX_reg(context
) = _lcreat16_uniq( name
, 0 )) != (WORD
)HFILE_ERROR16
)
727 TRACE(int21
, "created %s\n", name
);
730 if (DOS_ExtendedError
!= ER_FileExists
) return FALSE
;
735 static BOOL32
INT21_GetCurrentDirectory( CONTEXT
*context
)
737 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
738 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
) );
740 if (!DRIVE_IsValid(drive
))
742 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
745 lstrcpyn32A( ptr
, DRIVE_GetDosCwd(drive
), 64 );
746 AX_reg(context
) = 0x0100; /* success return code */
751 static void INT21_GetDBCSLeadTable( CONTEXT
*context
)
753 if (heap
|| INT21_CreateHeap())
754 { /* return an empty table just as DOS 4.0+ does */
755 DS_reg(context
) = DosHeapHandle
;
756 SI_reg(context
) = (int)&heap
->DummyDBCSLeadTable
- (int)heap
;
760 AX_reg(context
) = 0x1; /* error */
766 static int INT21_GetDiskSerialNumber( CONTEXT
*context
)
768 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
769 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
771 if (!DRIVE_IsValid(drive
))
773 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
777 *(WORD
*)dataptr
= 0;
778 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
779 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
780 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
785 static int INT21_SetDiskSerialNumber( CONTEXT
*context
)
787 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
788 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
790 if (!DRIVE_IsValid(drive
))
792 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
796 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
801 /* microsoft's programmers should be shot for using CP/M style int21
802 calls in Windows for Workgroup's winfile.exe */
804 static int INT21_FindFirstFCB( CONTEXT
*context
)
806 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
811 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
812 else pFCB
= (FINDFILE_FCB
*)fcb
;
813 drive
= DOS_GET_DRIVE( pFCB
->drive
);
814 if (!DRIVE_IsValid( drive
)) return 0;
815 root
= DRIVE_GetRoot( drive
);
816 cwd
= DRIVE_GetUnixCwd( drive
);
817 pFCB
->unixPath
= HeapAlloc( GetProcessHeap(), 0,
818 strlen(root
)+strlen(cwd
)+2 );
819 if (!pFCB
->unixPath
) return 0;
820 strcpy( pFCB
->unixPath
, root
);
821 strcat( pFCB
->unixPath
, "/" );
822 strcat( pFCB
->unixPath
, cwd
);
828 static int INT21_FindNextFCB( CONTEXT
*context
)
830 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
832 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA(context
);
833 WIN32_FIND_DATA32A entry
;
837 if (*fcb
== 0xff) /* extended FCB ? */
840 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
845 pFCB
= (FINDFILE_FCB
*)fcb
;
848 if (!pFCB
->unixPath
) return 0;
849 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
850 DOS_GET_DRIVE( pFCB
->drive
), attr
,
851 pFCB
->count
, &entry
)))
853 HeapFree( GetProcessHeap(), 0, pFCB
->unixPath
);
854 pFCB
->unixPath
= NULL
;
857 pFCB
->count
+= count
;
859 if (*fcb
== 0xff) { /* place extended FCB header before pResult if called with extended FCB */
860 *(BYTE
*)pResult
= 0xff;
861 (BYTE
*)pResult
+=6; /* leave reserved field behind */
862 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
865 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
867 pResult
->fileattr
= entry
.dwFileAttributes
;
868 pResult
->cluster
= 0; /* what else? */
869 pResult
->filesize
= entry
.nFileSizeLow
;
870 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
871 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
872 &pResult
->filedate
, &pResult
->filetime
);
874 /* Convert file name to FCB format */
876 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
877 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
878 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
879 pResult
->filename
[0] = pResult
->filename
[1] = '.';
882 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
883 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
885 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
886 MIN( (p
- entry
.cAlternateFileName
), 8 ) );
887 memcpy( pResult
->filename
+ 8, p
+ 1, MIN( strlen(p
), 3 ) );
890 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
891 MIN( strlen(entry
.cAlternateFileName
), 8 ) );
897 static void DeleteFileFCB( CONTEXT
*context
)
899 FIXME(int21
, "(%p): stub\n", context
);
902 static void RenameFileFCB( CONTEXT
*context
)
904 FIXME(int21
, "(%p): stub\n", context
);
909 static void fLock( CONTEXT
* context
)
912 switch ( AX_reg(context
) & 0xff )
914 case 0x00: /* LOCK */
915 TRACE(int21
,"lock handle %d offset %ld length %ld\n",
917 MAKELONG(DX_reg(context
),CX_reg(context
)),
918 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
919 if (!LockFile(FILE_GetHandle32(BX_reg(context
)),
920 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
921 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
922 AX_reg(context
) = DOS_ExtendedError
;
927 case 0x01: /* UNLOCK */
928 TRACE(int21
,"unlock handle %d offset %ld length %ld\n",
930 MAKELONG(DX_reg(context
),CX_reg(context
)),
931 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
932 if (!UnlockFile(FILE_GetHandle32(BX_reg(context
)),
933 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
934 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
935 AX_reg(context
) = DOS_ExtendedError
;
940 AX_reg(context
) = 0x0001;
947 INT21_networkfunc (CONTEXT
*context
)
949 switch (AL_reg(context
)) {
950 case 0x00: /* Get machine name. */
952 char *dst
= CTX_SEG_OFF_TO_LIN (context
,DS_reg(context
),EDX_reg(context
));
953 TRACE(int21
, "getting machine name to %p\n", dst
);
954 if (gethostname (dst
, 15))
956 WARN(int21
,"failed!\n");
957 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
960 int len
= strlen (dst
);
964 CH_reg(context
) = 1; /* Valid */
965 CL_reg(context
) = 1; /* NETbios number??? */
966 TRACE(int21
, "returning %s\n", debugstr_an (dst
, 16));
972 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
977 static void INT21_SetCurrentPSP(WORD psp
)
980 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
981 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
983 GlobalUnlock16( GetCurrentTask() );
984 if (pModule
->lpDosTask
)
985 pModule
->lpDosTask
->psp_seg
= psp
;
988 ERR(int21
, "Cannot change PSP for non-DOS task!\n");
991 static WORD
INT21_GetCurrentPSP()
994 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
995 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
997 GlobalUnlock16( GetCurrentTask() );
998 if (pModule
->lpDosTask
)
999 return pModule
->lpDosTask
->psp_seg
;
1002 return GetCurrentPDB();
1006 SEGPTR
INT21_GetListOfLists()
1008 static DOS_LISTOFLISTS
*LOL
;
1009 static SEGPTR seg_LOL
;
1014 0133:0020 6A 13-33 01 CC 00 33 01 59 00 j.3...3.Y.
1015 0133:0030 70 00 00 00 72 02 00 02-6D 00 33 01 00 00 2E 05 p...r...m.3.....
1016 0133:0040 00 00 FC 04 00 00 03 08-92 21 11 E0 04 80 C6 0D .........!......
1017 0133:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..NUL ......
1018 0133:0060 00 4B BA C1 06 14 00 00-00 03 01 00 04 70 CE FF .K...........p..
1019 0133:0070 FF 00 00 00 00 00 00 00-00 01 00 00 0D 05 00 00 ................
1020 0133:0080 00 FF FF 00 00 00 00 FE-00 00 F8 03 FF 9F 70 02 ..............p.
1021 0133:0090 D0 44 C8 FD D4 44 C8 FD-D4 44 C8 FD D0 44 C8 FD .D...D...D...D..
1022 0133:00A0 D0 44 C8 FD D0 44 .D...D
1025 LOL
= SEGPTR_ALLOC(sizeof(DOS_LISTOFLISTS
));
1027 LOL
->CX_Int21_5e01
= 0x0;
1028 LOL
->LRU_count_FCB_cache
= 0x0;
1029 LOL
->LRU_count_FCB_open
= 0x0;
1030 LOL
->OEM_func_handler
= -1; /* not available */
1031 LOL
->INT21_offset
= 0x0;
1032 LOL
->sharing_retry_count
= sharing_retries
; /* default value: 3 */
1033 LOL
->sharing_retry_delay
= sharing_pause
; /* default value: 1 */
1034 LOL
->ptr_disk_buf
= 0x0;
1035 LOL
->offs_unread_CON
= 0x0;
1036 LOL
->seg_first_MCB
= 0x0;
1037 LOL
->ptr_first_DPB
= 0x0;
1038 LOL
->ptr_first_SysFileTable
= 0x0;
1039 LOL
->ptr_clock_dev_hdr
= 0x0;
1040 LOL
->ptr_CON_dev_hdr
= 0x0;
1041 LOL
->max_byte_per_sec
= 512;
1042 LOL
->ptr_disk_buf_info
= 0x0;
1043 LOL
->ptr_array_CDS
= 0x0;
1044 LOL
->ptr_sys_FCB
= 0x0;
1045 LOL
->nr_protect_FCB
= 0x0;
1046 LOL
->nr_block_dev
= 0x0;
1047 LOL
->nr_avail_drive_letters
= 26; /* A - Z */
1048 LOL
->nr_drives_JOINed
= 0x0;
1049 LOL
->ptr_spec_prg_names
= 0x0;
1050 LOL
->ptr_SETVER_prg_list
= 0x0; /* no SETVER list */
1051 LOL
->DOS_HIGH_A20_func_offs
= 0x0;
1052 LOL
->PSP_last_exec
= 0x0;
1053 LOL
->BUFFERS_val
= 99; /* maximum: 99 */
1054 LOL
->BUFFERS_nr_lookahead
= 8; /* maximum: 8 */
1055 LOL
->boot_drive
= 3; /* C: */
1056 LOL
->flag_DWORD_moves
= 0x01; /* i386+ */
1057 LOL
->size_extended_mem
= 0xf000; /* very high value */
1059 if (!seg_LOL
) seg_LOL
= SEGPTR_GET(LOL
);
1060 return seg_LOL
+(WORD
)&((DOS_LISTOFLISTS
*)0)->ptr_first_DPB
;
1063 /***********************************************************************
1064 * DOS3Call (KERNEL.102)
1066 void WINAPI
DOS3Call( CONTEXT
*context
)
1068 BOOL32 bSetDOSExtendedError
= FALSE
;
1071 TRACE(int21
, "AX=%04x BX=%04x CX=%04x DX=%04x "
1072 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1073 AX_reg(context
), BX_reg(context
), CX_reg(context
), DX_reg(context
),
1074 SI_reg(context
), DI_reg(context
),
1075 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
1079 if (AH_reg(context
) == 0x59) /* Get extended error info */
1081 TRACE(int21
, "GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1082 DOS_ExtendedError
, DOS_ErrorClass
, DOS_ErrorAction
, DOS_ErrorLocus
);
1083 AX_reg(context
) = DOS_ExtendedError
;
1084 BH_reg(context
) = DOS_ErrorClass
;
1085 BL_reg(context
) = DOS_ErrorAction
;
1086 CH_reg(context
) = DOS_ErrorLocus
;
1090 if (AH_reg(context
) == 0x0C) /* Flush buffer and read standard input */
1092 TRACE(int21
, "FLUSH BUFFER AND READ STANDARD INPUT\n");
1093 /* no flush here yet */
1094 AH_reg(context
) = AL_reg(context
);
1097 if (AH_reg(context
)>=0x2f) {
1098 /* extended error is used by (at least) functions 0x2f to 0x62 */
1099 DOS_ERROR( 0, 0, 0, 0 );
1101 RESET_CFLAG(context
); /* Not sure if this is a good idea */
1103 switch(AH_reg(context
))
1105 case 0x03: /* READ CHARACTER FROM STDAUX */
1106 case 0x04: /* WRITE CHARACTER TO STDAUX */
1107 case 0x05: /* WRITE CHARACTER TO PRINTER */
1108 case 0x0f: /* OPEN FILE USING FCB */
1109 case 0x10: /* CLOSE FILE USING FCB */
1110 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1111 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1112 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1113 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1114 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1115 case 0x23: /* GET FILE SIZE FOR FCB */
1116 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1117 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1118 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1119 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1120 case 0x54: /* GET VERIFY FLAG */
1121 INT_BARF( context
, 0x21 );
1124 case 0x00: /* TERMINATE PROGRAM */
1125 TRACE(int21
,"TERMINATE PROGRAM\n");
1129 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1130 TRACE(int21
,"DIRECT CHARACTER INPUT WITH ECHO\n");
1131 AL_reg(context
) = CONSOLE_GetCharacter();
1132 /* FIXME: no echo */
1135 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1136 TRACE(int21
, "Write Character to Standard Output\n");
1137 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1140 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1141 TRACE(int21
, "Direct Console Input/Output\n");
1142 if (DL_reg(context
) == 0xff) {
1143 FIXME(int21
,"Direct Console Input should not block\n");
1144 AL_reg(context
) = CONSOLE_GetCharacter();
1145 FL_reg(context
) &= ~0x40; /* clear ZF */
1147 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1150 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1151 TRACE(int21
,"DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1152 AL_reg(context
) = CONSOLE_GetCharacter();
1155 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1156 TRACE(int21
,"CHARACTER INPUT WITHOUT ECHO\n");
1157 AL_reg(context
) = CONSOLE_GetCharacter();
1160 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1161 TRACE(int21
,"WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1162 DS_reg(context
),DX_reg(context
) );
1164 LPSTR data
= CTX_SEG_OFF_TO_LIN(context
,DS_reg(context
),EDX_reg(context
));
1166 /* do NOT use strchr() to calculate the string length,
1167 as '\0' is valid string content, too !
1168 Maybe we should check for non-'$' strings, but DOS doesn't. */
1169 while (*p
!= '$') p
++;
1170 _hwrite16( 1, data
, (int)p
- (int)data
);
1171 AL_reg(context
) = '$'; /* yes, '$' (0x24) gets returned in AL */
1175 case 0x0a: /* BUFFERED INPUT */
1177 char *buffer
= ((char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1178 EDX_reg(context
) ));
1181 TRACE(int21
,"BUFFERED INPUT (size=%d)\n",buffer
[0]);
1183 TRACE(int21
,"Handle old chars in buffer!\n");
1184 res
=_lread16( 0, buffer
+2,buffer
[0]);
1186 if(buffer
[res
+1] == '\n')
1187 buffer
[res
+1] = '\r';
1191 case 0x0b: {/* GET STDIN STATUS */
1194 if (CONSOLE_CheckForKeystroke(&x1
,&x2
))
1195 AL_reg(context
) = 0xff;
1197 AL_reg(context
) = 0;
1200 case 0x2e: /* SET VERIFY FLAG */
1201 TRACE(int21
,"SET VERIFY FLAG ignored\n");
1202 /* we cannot change the behaviour anyway, so just ignore it */
1205 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1209 case 0x6b: /* NULL FUNCTION */
1210 AL_reg(context
) = 0;
1213 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1217 case 0x0d: /* DISK BUFFER FLUSH */
1218 TRACE(int21
,"DISK BUFFER FLUSH ignored\n");
1219 RESET_CFLAG(context
); /* dos 6+ only */
1222 case 0x0e: /* SELECT DEFAULT DRIVE */
1223 TRACE(int21
,"SELECT DEFAULT DRIVE %d\n", DL_reg(context
));
1224 DRIVE_SetCurrentDrive( DL_reg(context
) );
1225 AL_reg(context
) = MAX_DOS_DRIVES
;
1228 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1229 TRACE(int21
,"FIND FIRST MATCHING FILE USING FCB %p\n",
1230 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1231 if (!INT21_FindFirstFCB(context
))
1233 AL_reg(context
) = 0xff;
1236 /* else fall through */
1238 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1239 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
1242 case 0x13: /* DELETE FILE USING FCB */
1243 DeleteFileFCB(context
);
1246 case 0x17: /* RENAME FILE USING FCB */
1247 RenameFileFCB(context
);
1250 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1251 AL_reg(context
) = DRIVE_GetCurrentDrive();
1254 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1256 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1257 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(context
),DX_reg(context
));
1258 TRACE(int21
, "Set DTA: %08lx\n", pTask
->dta
);
1262 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1263 DL_reg(context
) = 0;
1264 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1267 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1268 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1271 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1272 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1275 case 0x25: /* SET INTERRUPT VECTOR */
1276 INT_CtxSetHandler( context
, AL_reg(context
),
1277 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1281 case 0x29: /* PARSE FILENAME INTO FCB */
1282 INT21_ParseFileNameIntoFCB(context
);
1285 case 0x2a: /* GET SYSTEM DATE */
1286 INT21_GetSystemDate(context
);
1289 case 0x2b: /* SET SYSTEM DATE */
1290 FIXME(int21
, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1291 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1292 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1295 case 0x2c: /* GET SYSTEM TIME */
1296 INT21_GetSystemTime(context
);
1299 case 0x2d: /* SET SYSTEM TIME */
1300 FIXME(int21
, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1301 CH_reg(context
), CL_reg(context
),
1302 DH_reg(context
), DL_reg(context
) );
1303 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1306 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1307 TRACE(int21
,"GET DISK TRANSFER AREA ADDRESS\n");
1309 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1310 ES_reg(context
) = SELECTOROF( pTask
->dta
);
1311 BX_reg(context
) = OFFSETOF( pTask
->dta
);
1315 case 0x30: /* GET DOS VERSION */
1316 TRACE(int21
,"GET DOS VERSION %s requested\n",
1317 (AL_reg(context
) == 0x00)?"OEM number":"version flag");
1318 AX_reg(context
) = (HIWORD(GetVersion16()) >> 8) |
1319 (HIWORD(GetVersion16()) << 8);
1321 AH_reg(context
) = 0x7;
1322 AL_reg(context
) = 0xA;
1325 BX_reg(context
) = 0x00FF; /* 0x123456 is Wine's serial # */
1326 CX_reg(context
) = 0x0000;
1329 case 0x31: /* TERMINATE AND STAY RESIDENT */
1330 FIXME(int21
,"TERMINATE AND STAY RESIDENT stub\n");
1333 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1334 TRACE(int21
,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1335 INT21_DriveName( DL_reg(context
)));
1336 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1339 case 0x33: /* MULTIPLEXED */
1340 switch (AL_reg(context
))
1342 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1343 TRACE(int21
,"GET CURRENT EXTENDED BREAK STATE\n");
1344 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1347 case 0x01: /* SET EXTENDED BREAK STATE */
1348 TRACE(int21
,"SET CURRENT EXTENDED BREAK STATE\n");
1349 DOSCONF_config
.brk_flag
= (DL_reg(context
) > 0);
1352 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1353 TRACE(int21
,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1354 /* ugly coding in order to stay reentrant */
1355 if (DL_reg(context
))
1357 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1358 DOSCONF_config
.brk_flag
= 1;
1362 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1363 DOSCONF_config
.brk_flag
= 0;
1367 case 0x05: /* GET BOOT DRIVE */
1368 TRACE(int21
,"GET BOOT DRIVE\n");
1369 DL_reg(context
) = 3;
1370 /* c: is Wine's bootdrive (a: is 1)*/
1373 case 0x06: /* GET TRUE VERSION NUMBER */
1374 TRACE(int21
,"GET TRUE VERSION NUMBER\n");
1375 BX_reg(context
) = (HIWORD(GetVersion16() >> 8)) |
1376 (HIWORD(GetVersion16() << 8));
1377 DX_reg(context
) = 0x00;
1381 INT_BARF( context
, 0x21 );
1386 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1387 TRACE(int21
,"GET ADDRESS OF INDOS FLAG\n");
1388 if (!heap
) INT21_CreateHeap();
1389 ES_reg(context
) = DosHeapHandle
;
1390 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1393 case 0x35: /* GET INTERRUPT VECTOR */
1394 TRACE(int21
,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
1396 FARPROC16 addr
= INT_CtxGetHandler( context
, AL_reg(context
) );
1397 ES_reg(context
) = SELECTOROF(addr
);
1398 BX_reg(context
) = OFFSETOF(addr
);
1402 case 0x36: /* GET FREE DISK SPACE */
1403 TRACE(int21
,"GET FREE DISK SPACE FOR DRIVE %s\n",
1404 INT21_DriveName( DL_reg(context
)));
1405 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1410 unsigned char switchchar
='/';
1411 switch (AL_reg(context
))
1413 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1414 TRACE(int21
,"SWITCHAR - GET SWITCH CHARACTER\n");
1415 AL_reg(context
) = 0x00; /* success*/
1416 DL_reg(context
) = switchchar
;
1418 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1419 TRACE(int21
,"SWITCHAR - SET SWITCH CHARACTER\n");
1420 switchchar
= DL_reg(context
);
1421 AL_reg(context
) = 0x00; /* success*/
1423 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1424 INT_BARF( context
, 0x21 );
1430 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1431 TRACE(int21
,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1433 AX_reg(context
) = 0x02; /* no country support available */
1437 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1438 TRACE(int21
,"MKDIR %s\n",
1439 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1440 bSetDOSExtendedError
= (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1441 EDX_reg(context
) ), NULL
));
1444 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1445 TRACE(int21
,"RMDIR %s\n",
1446 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1447 bSetDOSExtendedError
= (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1448 EDX_reg(context
) )));
1451 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1452 TRACE(int21
,"CHDIR %s\n",
1453 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1454 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1457 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1458 TRACE(int21
,"CREAT flag 0x%02x %s\n",CX_reg(context
),
1459 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1460 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1461 EDX_reg(context
) ), CX_reg(context
) );
1462 bSetDOSExtendedError
= (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
1465 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1466 TRACE(int21
,"OPEN mode 0x%02x %s\n",AL_reg(context
),
1467 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1468 OpenExistingFile(context
);
1471 case 0x3e: /* "CLOSE" - CLOSE FILE */
1472 TRACE(int21
,"CLOSE handle %d\n",BX_reg(context
));
1473 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1476 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1477 TRACE(int21
,"READ from %d to %04lX:%04X for %d byte\n",BX_reg(context
),
1478 DS_reg(context
),DX_reg(context
),CX_reg(context
) );
1482 result
= _hread16( BX_reg(context
),
1483 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1487 result
= WIN16_hread( BX_reg(context
),
1488 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1491 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1492 else AX_reg(context
) = (WORD
)result
;
1496 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1497 TRACE(int21
,"WRITE from %04lX:%04X to handle %d for %d byte\n",
1498 DS_reg(context
),DX_reg(context
),BX_reg(context
),CX_reg(context
) );
1500 LONG result
= _hwrite16( BX_reg(context
),
1501 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1504 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1505 else AX_reg(context
) = (WORD
)result
;
1509 case 0x41: /* "UNLINK" - DELETE FILE */
1510 TRACE(int21
,"UNLINK%s\n",
1511 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1512 bSetDOSExtendedError
= (!DeleteFile32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1513 EDX_reg(context
) )));
1516 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1517 TRACE(int21
,"LSEEK handle %d offset %ld from %s\n",
1518 BX_reg(context
), MAKELONG(DX_reg(context
),CX_reg(context
)),
1519 (AL_reg(context
)==0)?"start of file":(AL_reg(context
)==1)?
1520 "current file position":"end of file");
1522 LONG status
= _llseek16( BX_reg(context
),
1523 MAKELONG(DX_reg(context
),CX_reg(context
)),
1525 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1528 AX_reg(context
) = LOWORD(status
);
1529 DX_reg(context
) = HIWORD(status
);
1534 case 0x43: /* FILE ATTRIBUTES */
1535 switch (AL_reg(context
))
1538 TRACE(int21
,"GET FILE ATTRIBUTES for %s\n",
1539 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1540 AX_reg(context
) = (WORD
)GetFileAttributes32A(
1541 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1543 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1544 else CX_reg(context
) = AX_reg(context
);
1548 TRACE(int21
,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context
),
1549 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1550 bSetDOSExtendedError
=
1551 (!SetFileAttributes32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1556 TRACE(int21
,"GET COMPRESSED FILE SIZE for %s stub\n",
1557 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1561 case 0x44: /* IOCTL */
1562 switch (AL_reg(context
))
1565 ioctlGetDeviceInfo(context
);
1571 const DOS_DEVICE
*dev
;
1572 if ((dev
= DOSFS_GetDeviceByHandle( FILE_GetHandle32(BX_reg(context
)) )) &&
1573 !strcasecmp( dev
->name
, "SCSIMGR$" ))
1575 ASPI_DOS_HandleInt(context
);
1579 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1580 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));*/
1581 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1583 FIXME(int21
,"program tried to write to block device control channel of drive %d:\n",drive
);
1584 /* for (i=0;i<CX_reg(context);i++)
1585 fprintf(stdnimp,"%02x ",dataptr[i]);
1586 fprintf(stdnimp,"\n");*/
1587 AX_reg(context
)=CX_reg(context
);
1590 case 0x08: /* Check if drive is removable. */
1591 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1592 INT21_DriveName( BL_reg(context
)));
1593 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1595 case DRIVE_CANNOTDETERMINE
:
1596 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1597 AX_reg(context
) = ER_InvalidDrive
;
1600 case DRIVE_REMOVABLE
:
1601 AX_reg(context
) = 0; /* removable */
1604 AX_reg(context
) = 1; /* not removable */
1609 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1610 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1611 INT21_DriveName( BL_reg(context
)));
1612 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1614 case DRIVE_CANNOTDETERMINE
:
1615 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1616 AX_reg(context
) = ER_InvalidDrive
;
1620 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1623 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1628 case 0x0a: /* check if handle (BX) is remote */
1629 TRACE(int21
,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context
));
1630 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1633 DX_reg(context
) = 0;
1636 case 0x0b: /* SET SHARING RETRY COUNT */
1637 TRACE(int21
,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1638 CX_reg(context
), DX_reg(context
));
1639 if (!CX_reg(context
))
1641 AX_reg(context
) = 1;
1645 sharing_pause
= CX_reg(context
);
1646 if (!DX_reg(context
))
1647 sharing_retries
= DX_reg(context
);
1648 RESET_CFLAG(context
);
1652 TRACE(int21
,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1653 INT21_DriveName( BL_reg(context
)));
1654 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1657 case 0x0e: /* get logical drive mapping */
1658 TRACE(int21
,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1659 INT21_DriveName( BL_reg(context
)));
1660 AL_reg(context
) = 0; /* drive has no mapping - FIXME: may be wrong*/
1663 case 0x0F: /* Set logical drive mapping */
1666 TRACE(int21
,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1667 INT21_DriveName( BL_reg(context
)));
1668 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1669 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1672 AX_reg(context
) = 0x000F; /* invalid drive */
1677 case 0xe0: /* Sun PC-NFS API */
1682 INT_BARF( context
, 0x21 );
1687 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1690 TRACE(int21
,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context
));
1691 if ((bSetDOSExtendedError
= !DuplicateHandle( GetCurrentProcess(),
1692 FILE_GetHandle32(BX_reg(context
)),
1693 GetCurrentProcess(), &handle
,
1694 0, TRUE
, DUPLICATE_SAME_ACCESS
)))
1695 AX_reg(context
) = HFILE_ERROR16
;
1697 AX_reg(context
) = FILE_AllocDosHandle(handle
);
1701 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1702 TRACE(int21
,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1703 BX_reg(context
),CX_reg(context
));
1704 bSetDOSExtendedError
= (FILE_Dup2( BX_reg(context
), CX_reg(context
) ) == HFILE_ERROR16
);
1707 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1708 TRACE(int21
,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1709 INT21_DriveName( DL_reg(context
)));
1710 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1713 case 0x48: /* ALLOCATE MEMORY */
1714 TRACE(int21
,"ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
));
1719 mem
= DOSMEM_GetBlock(0,(DWORD
)BX_reg(context
)<<4,NULL
);
1721 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1725 mem
= (LPVOID
)GlobalDOSAlloc(BX_reg(context
)<<4);
1727 AX_reg(context
) = (DWORD
)mem
&0xffff;
1732 AX_reg(context
) = 0x0008; /* insufficient memory */
1733 BX_reg(context
) = DOSMEM_Available(0)>>4;
1738 case 0x49: /* FREE MEMORY */
1739 TRACE(int21
,"FREE MEMORY segment %04lX\n", ES_reg(context
));
1743 ret
= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4));
1746 ret
= !GlobalDOSFree(ES_reg(context
));
1747 /* If we don't reset ES_reg, we will fail in the relay code */
1748 ES_reg(context
)=ret
;
1752 TRACE(int21
,"FREE MEMORY failed\n");
1754 AX_reg(context
) = 0x0009; /* memory block address invalid */
1759 case 0x4a: /* RESIZE MEMORY BLOCK */
1760 TRACE(int21
,"RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context
), BX_reg(context
));
1761 if (!ISV86(context
))
1762 FIXME(int21
,"RESIZE MEMORY probably insufficent implementation. Expect crash soon\n");
1764 LPVOID
*mem
= DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4),
1765 BX_reg(context
)<<4,NULL
);
1767 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1770 AX_reg(context
) = 0x0008; /* insufficient memory */
1771 BX_reg(context
) = DOSMEM_Available(0)>>4; /* not quite right */
1776 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1777 TRACE(int21
,"EXEC %s\n",
1778 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
) ));
1779 AX_reg(context
) = WinExec16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1782 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1785 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1786 TRACE(int21
,"EXIT with return code %d\n",AL_reg(context
));
1787 ExitProcess( AL_reg(context
) );
1790 case 0x4d: /* GET RETURN CODE */
1791 TRACE(int21
,"GET RETURN CODE (ERRORLEVEL)\n");
1792 AX_reg(context
) = 0; /* normal exit */
1795 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1796 TRACE(int21
,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
1797 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1798 if (!INT21_FindFirst(context
)) break;
1801 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1802 TRACE(int21
,"FINDNEXT\n");
1803 if (!INT21_FindNext(context
))
1805 DOS_ERROR( ER_NoMoreFiles
, EC_MediaError
, SA_Abort
, EL_Disk
);
1806 AX_reg(context
) = ER_NoMoreFiles
;
1809 else AX_reg(context
) = 0; /* OK */
1811 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1812 TRACE(int21
, "SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1813 INT21_SetCurrentPSP(BX_reg(context
));
1815 case 0x51: /* GET PSP ADDRESS */
1816 TRACE(int21
,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1817 /* FIXME: should we return the original DOS PSP upon */
1818 /* Windows startup ? */
1819 BX_reg(context
) = INT21_GetCurrentPSP();
1821 case 0x62: /* GET PSP ADDRESS */
1822 TRACE(int21
,"GET CURRENT PSP ADDRESS\n");
1823 /* FIXME: should we return the original DOS PSP upon */
1824 /* Windows startup ? */
1825 BX_reg(context
) = INT21_GetCurrentPSP();
1828 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1829 TRACE(int21
,"SYSVARS - GET LIST OF LISTS\n");
1832 lol
= INT21_GetListOfLists();
1833 ES_reg(context
) = HIWORD(lol
);
1834 BX_reg(context
) = LOWORD(lol
);
1838 case 0x56: /* "RENAME" - RENAME FILE */
1839 TRACE(int21
,"RENAME %s to %s\n",
1840 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1841 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
)));
1842 bSetDOSExtendedError
=
1843 (!MoveFile32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1844 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
))));
1847 case 0x57: /* FILE DATE AND TIME */
1848 switch (AL_reg(context
))
1850 case 0x00: /* Get */
1853 TRACE(int21
,"GET FILE DATE AND TIME for handle %d\n",
1855 if (!GetFileTime( FILE_GetHandle32(BX_reg(context
)), NULL
, NULL
, &filetime
))
1856 bSetDOSExtendedError
= TRUE
;
1857 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1862 case 0x01: /* Set */
1865 TRACE(int21
,"SET FILE DATE AND TIME for handle %d\n",
1867 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1869 bSetDOSExtendedError
=
1870 (!SetFileTime( FILE_GetHandle32(BX_reg(context
)),
1871 NULL
, NULL
, &filetime
));
1877 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1878 TRACE(int21
,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1880 switch (AL_reg(context
))
1883 AX_reg(context
) = 1;
1886 AX_reg(context
) = 0;
1892 RESET_CFLAG(context
);
1895 case 0x5a: /* CREATE TEMPORARY FILE */
1896 TRACE(int21
,"CREATE TEMPORARY FILE\n");
1897 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1900 case 0x5b: /* CREATE NEW FILE */
1901 TRACE(int21
,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context
),
1902 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1903 bSetDOSExtendedError
= ((AX_reg(context
) =
1904 _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)), 0 ))
1905 == (WORD
)HFILE_ERROR16
);
1908 case 0x5d: /* NETWORK */
1909 FIXME(int21
,"Function 0x%04x not implemented.\n", AX_reg (context
));
1910 /* Fix the following while you're at it. */
1911 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1912 bSetDOSExtendedError
= TRUE
;
1916 bSetDOSExtendedError
= INT21_networkfunc (context
);
1919 case 0x5f: /* NETWORK */
1920 switch (AL_reg(context
))
1922 case 0x07: /* ENABLE DRIVE */
1923 TRACE(int21
,"ENABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1924 if (!DRIVE_Enable( DL_reg(context
) ))
1926 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1927 bSetDOSExtendedError
= TRUE
;
1931 case 0x08: /* DISABLE DRIVE */
1932 TRACE(int21
,"DISABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1933 if (!DRIVE_Disable( DL_reg(context
) ))
1935 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1936 bSetDOSExtendedError
= TRUE
;
1941 /* network software not installed */
1942 TRACE(int21
,"NETWORK function AX=%04x not implemented\n",AX_reg(context
));
1943 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1944 bSetDOSExtendedError
= TRUE
;
1949 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1950 TRACE(int21
,"TRUENAME %s\n",
1951 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),ESI_reg(context
)));
1953 if (!GetFullPathName32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1954 ESI_reg(context
)), 128,
1955 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
1956 EDI_reg(context
)),NULL
))
1957 bSetDOSExtendedError
= TRUE
;
1958 else AX_reg(context
) = 0;
1962 case 0x61: /* UNUSED */
1963 case 0x63: /* misc. language support */
1964 switch (AL_reg(context
)) {
1965 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1966 INT21_GetDBCSLeadTable(context
);
1970 case 0x64: /* OS/2 DOS BOX */
1971 INT_BARF( context
, 0x21 );
1975 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1976 extern WORD WINE_LanguageId
;
1977 BYTE
*dataptr
=CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
));
1978 TRACE(int21
,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1979 BX_reg(context
), DX_reg(context
));
1980 switch (AL_reg(context
)) {
1982 TRACE(int21
,"\tget general internationalization info\n");
1984 *(WORD
*)(dataptr
+1) = 41;
1985 *(WORD
*)(dataptr
+3) = WINE_LanguageId
;
1986 *(WORD
*)(dataptr
+5) = CodePage
;
1987 *(DWORD
*)(dataptr
+0x19) = 0; /* FIXME: ptr to case map routine */
1990 TRACE(int21
,"\tget pointer to collating sequence table\n");
1992 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
1993 CX_reg(context
) = 258;/*FIXME: size of table?*/
1996 TRACE(int21
,"\tunimplemented function %d\n",AL_reg(context
));
1997 INT_BARF( context
, 0x21 );
2003 case 0x66: /* GLOBAL CODE PAGE TABLE */
2004 switch (AL_reg(context
))
2007 TRACE(int21
,"GET GLOBAL CODE PAGE TABLE\n");
2008 DX_reg(context
) = BX_reg(context
) = CodePage
;
2009 RESET_CFLAG(context
);
2012 TRACE(int21
,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2013 BX_reg(context
),DX_reg(context
));
2014 CodePage
= BX_reg(context
);
2015 RESET_CFLAG(context
);
2020 case 0x67: /* SET HANDLE COUNT */
2021 TRACE(int21
,"SET HANDLE COUNT to %d\n",BX_reg(context
) );
2022 SetHandleCount16( BX_reg(context
) );
2023 if (DOS_ExtendedError
) bSetDOSExtendedError
= TRUE
;
2026 case 0x68: /* "FFLUSH" - COMMIT FILE */
2027 case 0x6a: /* COMMIT FILE */
2028 TRACE(int21
,"FFLUSH/COMMIT handle %d\n",BX_reg(context
));
2029 bSetDOSExtendedError
= (!FlushFileBuffers( FILE_GetHandle32(BX_reg(context
)) ));
2032 case 0x69: /* DISK SERIAL NUMBER */
2033 switch (AL_reg(context
))
2036 TRACE(int21
,"GET DISK SERIAL NUMBER for drive %s\n",
2037 INT21_DriveName(BL_reg(context
)));
2038 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2039 else AX_reg(context
) = 0;
2043 TRACE(int21
,"SET DISK SERIAL NUMBER for drive %s\n",
2044 INT21_DriveName(BL_reg(context
)));
2045 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2046 else AX_reg(context
) = 1;
2051 case 0x6C: /* Extended Open/Create*/
2052 TRACE(int21
,"EXTENDED OPEN/CREATE %s\n",
2053 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDI_reg(context
)));
2054 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2057 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2058 if ((GetVersion32()&0xC0000004)!=0xC0000004) {
2059 /* not supported on anything but Win95 */
2060 TRACE(int21
,"LONG FILENAME functions supported only by win95\n");
2062 AL_reg(context
) = 0;
2064 switch(AL_reg(context
))
2066 case 0x39: /* Create directory */
2067 TRACE(int21
,"LONG FILENAME - MAKE DIRECTORY %s\n",
2068 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2069 bSetDOSExtendedError
= (!CreateDirectory32A(
2070 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2071 EDX_reg(context
) ), NULL
));
2073 case 0x3a: /* Remove directory */
2074 TRACE(int21
,"LONG FILENAME - REMOVE DIRECTORY %s\n",
2075 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2076 bSetDOSExtendedError
= (!RemoveDirectory32A(
2077 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2078 EDX_reg(context
) )));
2080 case 0x43: /* Get/Set file attributes */
2081 TRACE(int21
,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2082 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2083 switch (BL_reg(context
))
2085 case 0x00: /* Get file attributes */
2086 TRACE(int21
,"\tretrieve attributes\n");
2087 CX_reg(context
) = (WORD
)GetFileAttributes32A(
2088 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2090 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
2093 TRACE(int21
,"\tset attributes 0x%04x\n",CX_reg(context
));
2094 bSetDOSExtendedError
= (!SetFileAttributes32A(
2095 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2097 CX_reg(context
) ) );
2100 FIXME(int21
, "Unimplemented long file name function:\n");
2101 INT_BARF( context
, 0x21 );
2103 AL_reg(context
) = 0;
2107 case 0x47: /* Get current directory */
2108 TRACE(int21
," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2109 INT21_DriveName(DL_reg(context
)));
2110 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
2113 case 0x4e: /* Find first file */
2114 TRACE(int21
," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2115 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2116 /* FIXME: use attributes in CX */
2117 if ((AX_reg(context
) = FindFirstFile16(
2118 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
2119 (WIN32_FIND_DATA32A
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2121 == INVALID_HANDLE_VALUE16
)
2122 bSetDOSExtendedError
= TRUE
;
2124 case 0x4f: /* Find next file */
2125 TRACE(int21
,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2127 if (!FindNextFile16( BX_reg(context
),
2128 (WIN32_FIND_DATA32A
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2130 bSetDOSExtendedError
= TRUE
;
2132 case 0xa1: /* Find close */
2133 TRACE(int21
,"LONG FILENAME - FINDCLOSE for handle %d\n",
2135 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
2138 TRACE(int21
,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2139 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2142 switch(CL_reg(context
))
2144 case 0x01: /*Get short filename or path */
2145 if (!GetShortPathName32A
2146 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2148 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2149 EDI_reg(context
)), 67))
2150 bSetDOSExtendedError
= TRUE
;
2151 else AX_reg(context
) = 0;
2153 case 0x02: /*Get canonical long filename or path */
2154 if (!GetFullPathName32A
2155 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2156 ESI_reg(context
)), 128,
2157 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2158 EDI_reg(context
)),NULL
))
2159 bSetDOSExtendedError
= TRUE
;
2160 else AX_reg(context
) = 0;
2163 FIXME(int21
, "Unimplemented long file name function:\n");
2164 INT_BARF( context
, 0x21 );
2166 AL_reg(context
) = 0;
2170 case 0x6c: /* Create or open file */
2171 TRACE(int21
,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
2172 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
)));
2173 /* translate Dos 7 action to Dos 6 action */
2174 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2177 case 0x3b: /* Change directory */
2178 TRACE(int21
,"LONG FILENAME - CHANGE DIRECTORY %s\n",
2179 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
2180 if (!SetCurrentDirectory32A(CTX_SEG_OFF_TO_LIN(context
,
2186 AL_reg(context
) = DOS_ExtendedError
;
2189 case 0x41: /* Delete file */
2190 TRACE(int21
,"LONG FILENAME - DELETE FILE %s\n",
2191 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
2192 if (!DeleteFile32A(CTX_SEG_OFF_TO_LIN(context
,
2197 AL_reg(context
) = DOS_ExtendedError
;
2200 case 0x56: /* Move (rename) file */
2201 TRACE(int21
,"LONG FILENAME - RENAME FILE %s to %s stub\n",
2202 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)),
2203 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), EDI_reg(context
)));
2205 FIXME(int21
, "Unimplemented long file name function:\n");
2206 INT_BARF( context
, 0x21 );
2208 AL_reg(context
) = 0;
2213 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2214 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2215 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2216 TRACE(int21
,"windows95 function AX %04x\n",
2218 WARN(int21
, " returning unimplemented\n");
2220 AL_reg(context
) = 0;
2223 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2224 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2228 INT_BARF( context
, 0x21 );
2231 } /* END OF SWITCH */
2233 if( bSetDOSExtendedError
) /* set general error condition */
2235 AX_reg(context
) = DOS_ExtendedError
;
2239 if ((EFL_reg(context
) & 0x0001))
2240 TRACE(int21
, "failed, errorcode 0x%02x class 0x%02x action 0x%02x locus %02x\n",
2241 DOS_ExtendedError
, DOS_ErrorClass
, DOS_ErrorAction
, DOS_ErrorLocus
);
2243 TRACE(int21
, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2244 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2245 AX_reg(context
), BX_reg(context
), CX_reg(context
),
2246 DX_reg(context
), SI_reg(context
), DI_reg(context
),
2247 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
2251 FARPROC16 WINAPI
GetSetKernelDOSProc(FARPROC16 DosProc
)
2253 FIXME(int21
, "(DosProc=0x%08x): stub\n", (UINT32
)DosProc
);