2 * DOS interrupt 21h handler
10 # include <sys/file.h>
15 #include <sys/types.h>
30 #if defined(__svr4__) || defined(_SCO_DS)
31 /* SVR4 DOESNT do locking the same way must implement properly */
38 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
40 /* Define the drive parameter block, as used by int21/1F
41 * and int21/32. This table can be accessed through the
42 * global 'dpb' pointer, which points into the local dos
47 BYTE drive_num
; /* 0=A, etc. */
48 BYTE unit_num
; /* Drive's unit number (?) */
49 WORD sector_size
; /* Sector size in bytes */
50 BYTE high_sector
; /* Highest sector in a cluster */
51 BYTE shift
; /* Shift count (?) */
52 WORD reserved
; /* Number of reserved sectors at start */
53 BYTE num_FAT
; /* Number of FATs */
54 WORD dir_entries
; /* Number of root dir entries */
55 WORD first_data
; /* First data sector */
56 WORD high_cluster
; /* Highest cluster number */
57 WORD sectors_in_FAT
; /* Number of sectors per FAT */
58 WORD start_dir
; /* Starting sector of first dir */
59 DWORD driver_head
; /* Address of device driver header (?) */
60 BYTE media_ID
; /* Media ID */
61 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
62 DWORD next
; /* Pointer to next DPB in list */
63 WORD free_search
; /* Free cluster search start */
64 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
75 BYTE DummyDBCSLeadTable
[6];
77 static struct DosHeap
*heap
;
78 static WORD DosHeapHandle
;
80 WORD sharing_retries
= 3; /* number of retries at sharing violation */
81 WORD sharing_pause
= 1; /* pause between retries */
83 extern char TempDirectory
[];
85 static BOOL32
INT21_CreateHeap(void)
87 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
89 WARN(int21
, "Out of memory\n");
92 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
93 dpbsegptr
= PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
95 strcpy(heap
->biosdate
, "01/01/80");
96 memset(heap
->DummyDBCSLeadTable
, 0, 6);
100 static BYTE
*GetCurrentDTA( CONTEXT
*context
)
102 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
104 /* FIXME: This assumes DTA was set correctly! */
105 return (BYTE
*)CTX_SEG_OFF_TO_LIN( context
, SELECTOROF(pTask
->dta
),
106 (DWORD
)OFFSETOF(pTask
->dta
) );
110 void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
111 /* limited == TRUE is used with INT 0x21/0x440d */
116 setword(&data
[3], 0);
118 setword(&data
[6], 240);
119 setword(&data
[8], 64000);
121 setword(&data
[0x0b], 40);
122 setword(&data
[0x0d], 56);
123 setword(&data
[0x0f], 2);
124 setword(&data
[0x11], 0);
126 setword(&data
[0x1f], 800);
128 setword(&data
[0x22], 1);
130 } else { /* 1.44mb */
133 setword(&data
[3], 0);
135 setword(&data
[6], 240);
136 setword(&data
[8], 2880);
138 setword(&data
[0x0b], 6);
139 setword(&data
[0x0d], 18);
140 setword(&data
[0x0f], 2);
141 setword(&data
[0x11], 0);
143 setword(&data
[0x1f], 80);
145 setword(&data
[0x22], 2);
150 static int INT21_GetFreeDiskSpace( CONTEXT
*context
)
152 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
153 char root
[] = "A:\\";
155 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
156 if (!GetDiskFreeSpace32A( root
, &cluster_sectors
, §or_bytes
,
157 &free_clusters
, &total_clusters
)) return 0;
158 AX_reg(context
) = cluster_sectors
;
159 BX_reg(context
) = free_clusters
;
160 CX_reg(context
) = sector_bytes
;
161 DX_reg(context
) = total_clusters
;
165 static int INT21_GetDriveAllocInfo( CONTEXT
*context
)
167 if (!INT21_GetFreeDiskSpace( context
)) return 0;
168 if (!heap
&& !INT21_CreateHeap()) return 0;
169 heap
->mediaID
= 0xf0;
170 DS_reg(context
) = DosHeapHandle
;
171 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
175 static void GetDrivePB( CONTEXT
*context
, int drive
)
177 if(!DRIVE_IsValid(drive
))
179 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
180 AX_reg(context
) = 0x00ff;
182 else if (heap
|| INT21_CreateHeap())
184 FIXME(int21
, "GetDrivePB not fully implemented.\n");
186 /* FIXME: I have no idea what a lot of this information should
187 * say or whether it even really matters since we're not allowing
188 * direct block access. However, some programs seem to depend on
189 * getting at least _something_ back from here. The 'next' pointer
190 * does worry me, though. Should we have a complete table of
191 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
193 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
194 heap
->dpb
.sector_size
= 512;
195 heap
->dpb
.high_sector
= 1;
196 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
197 heap
->dpb
.reserved
= 0;
198 heap
->dpb
.num_FAT
= 1;
199 heap
->dpb
.dir_entries
= 2;
200 heap
->dpb
.first_data
= 2;
201 heap
->dpb
.high_cluster
= 64000;
202 heap
->dpb
.sectors_in_FAT
= 1;
203 heap
->dpb
.start_dir
= 1;
204 heap
->dpb
.driver_head
= 0;
205 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
206 heap
->dpb
.access_flag
= 0;
208 heap
->dpb
.free_search
= 0;
209 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
211 AL_reg(context
) = 0x00;
212 DS_reg(context
) = SELECTOROF(dpbsegptr
);
213 BX_reg(context
) = OFFSETOF(dpbsegptr
);
218 static void ioctlGetDeviceInfo( CONTEXT
*context
)
223 TRACE(int21
, "(%d)\n", BX_reg(context
));
225 RESET_CFLAG(context
);
228 if ((file
= FILE_GetFile( HFILE16_TO_HFILE32(BX_reg(context
)), 0, NULL
)))
230 const DOS_DEVICE
*dev
= DOSFS_GetDevice( file
->unix_name
);
231 FILE_ReleaseFile( file
);
234 DX_reg(context
) = dev
->flags
;
239 /* it seems to be a file */
240 curr_drive
= DRIVE_GetCurrentDrive();
241 DX_reg(context
) = 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0);
243 /* bits 0-5 are current drive
244 * bit 6 - file has NOT been written..FIXME: correct?
245 * bit 8 - generate int24 if no diskspace on write/ read past end of file
246 * bit 11 - media not removable
247 * bit 14 - don't set file date/time on closing
248 * bit 15 - file is remote
252 static BOOL32
ioctlGenericBlkDevReq( CONTEXT
*context
)
254 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
255 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
257 if (!DRIVE_IsValid(drive
))
259 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
263 if (CH_reg(context
) != 0x08)
265 INT_BARF( context
, 0x21 );
269 switch (CL_reg(context
))
271 case 0x4a: /* lock logical volume */
272 TRACE(int21
,"lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
275 case 0x60: /* get device parameters */
276 /* used by w4wgrp's winfile */
277 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
279 dataptr
[6] = 0; /* media type */
282 dataptr
[1] = 0x05; /* fixed disk */
283 setword(&dataptr
[2], 0x01); /* non removable */
284 setword(&dataptr
[4], 0x300); /* # of cylinders */
288 dataptr
[1] = 0x07; /* block dev, floppy */
289 setword(&dataptr
[2], 0x02); /* removable */
290 setword(&dataptr
[4], 80); /* # of cylinders */
292 CreateBPB(drive
, &dataptr
[7], TRUE
);
293 RESET_CFLAG(context
);
296 case 0x41: /* write logical device track */
297 case 0x61: /* read logical device track */
299 BYTE drive
= BL_reg(context
) ?
300 BL_reg(context
) : DRIVE_GetCurrentDrive();
301 WORD head
= *(WORD
*)dataptr
+1;
302 WORD cyl
= *(WORD
*)dataptr
+3;
303 WORD sect
= *(WORD
*)dataptr
+5;
304 WORD nrsect
= *(WORD
*)dataptr
+7;
305 BYTE
*data
= (BYTE
**)dataptr
+9;
306 int (*raw_func
)(BYTE
, DWORD
, DWORD
, BYTE
*, BOOL32
);
308 raw_func
= (CL_reg(context
) == 0x41) ?
309 DRIVE_RawWrite
: DRIVE_RawRead
;
311 if (raw_func(drive
, head
*cyl
*sect
, nrsect
, data
, FALSE
))
312 RESET_CFLAG(context
);
315 AX_reg(context
) = 0x1e; /* read fault */
320 case 0x66:/* get disk serial number */
322 char label
[12],fsname
[9],path
[4];
325 strcpy(path
,"x:\\");path
[0]=drive
+'A';
326 GetVolumeInformation32A(
327 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
330 memcpy(dataptr
+2,&serial
,4);
331 memcpy(dataptr
+6,label
,11);
332 memcpy(dataptr
+17,fsname
,8);
337 TRACE(int21
,"logical volume %d unlocked.\n",drive
);
341 memset(dataptr
+1, '\0', dataptr
[0]-1);
342 dataptr
[1] = dataptr
[0];
343 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
344 dataptr
[3] = 0xFF; /* no physical drive */
348 INT_BARF( context
, 0x21 );
353 static void INT21_ParseFileNameIntoFCB( CONTEXT
*context
)
356 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
) );
358 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), EDI_reg(context
) );
359 char *buffer
, *s
, *d
;
361 AL_reg(context
) = 0xff; /* failed */
363 TRACE(int21
, "filename: '%s'\n", filename
);
365 buffer
= HeapAlloc( GetProcessHeap(), 0, strlen(filename
) + 1);
371 if ((*s
!= ' ') && (*s
!= '\r') && (*s
!= '\n'))
378 DOSFS_ToDosFCBFormat(buffer
, fcb
+ 1);
380 TRACE(int21
, "FCB: '%s'\n", ((CHAR
*)fcb
+ 1));
382 HeapFree( GetProcessHeap(), 0, buffer
);
385 ((strchr(filename
, '*')) || (strchr(filename
, '$'))) != 0;
387 /* point DS:SI to first unparsed character */
388 SI_reg(context
) += (int)s
- (int)filename
;
391 static void INT21_GetSystemDate( CONTEXT
*context
)
394 GetLocalTime( &systime
);
395 CX_reg(context
) = systime
.wYear
;
396 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
397 AX_reg(context
) = systime
.wDayOfWeek
;
400 static void INT21_GetSystemTime( CONTEXT
*context
)
403 GetLocalTime( &systime
);
404 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
405 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
408 /* Many calls translate a drive argument like this:
409 drive number (00h = default, 01h = A:, etc)
411 static char drivestring
[]="default";
413 char *INT21_DriveName(int drive
)
418 drivestring
[0]= (unsigned char)drive
+ '@';
424 static BOOL32
INT21_CreateFile( CONTEXT
*context
)
426 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
427 EDX_reg(context
) ), CX_reg(context
) );
428 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
432 static void OpenExistingFile( CONTEXT
*context
)
434 AX_reg(context
) = _lopen16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
436 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
438 AX_reg(context
) = DOS_ExtendedError
;
447 switch (AX_reg(context
) & 0x0070)
449 case 0x00: /* compatability mode */
450 case 0x40: /* DENYNONE */
454 case 0x30: /* DENYREAD */
455 TRACE(int21
, "(%s): DENYREAD changed to DENYALL\n",
456 (char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
457 case 0x10: /* DENYALL */
461 case 0x20: /* DENYWRITE */
472 int result
,retries
=sharing_retries
;
474 #if defined(__svr4__) || defined(_SCO_DS)
475 ERR(int21
, "Should call flock and needs porting to lockf\n");
479 result
= flock(handle
, lock
| LOCK_NB
);
481 if ( retries
&& (!result
) )
484 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
485 result
++; /* stop the optimizer */
486 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
490 while( (!result
) && (!(retries
--)) );
495 AX_reg(context
) = DOS_ExtendedError
;
504 AX_reg(context
) = handle
;
505 RESET_CFLAG(context
);
510 static void CloseFile( CONTEXT
*context
)
512 if ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0)
514 AX_reg(context
) = DOS_ExtendedError
;
519 static BOOL32
INT21_ExtendedOpenCreateFile(CONTEXT
*context
)
521 BOOL32 bExtendedError
= FALSE
;
522 BYTE action
= DL_reg(context
);
524 /* Shuffle arguments to call OpenExistingFile */
525 AL_reg(context
) = BL_reg(context
);
526 DX_reg(context
) = SI_reg(context
);
527 /* BX,CX and DX should be preserved */
528 OpenExistingFile(context
);
530 if ((EFL_reg(context
) & 0x0001) == 0) /* File exists */
532 UINT16 uReturnCX
= 0;
534 /* Now decide what do do */
536 if ((action
& 0x07) == 0)
538 BX_reg(context
) = AX_reg(context
);
540 AX_reg(context
) = 0x0050; /*File exists*/
542 WARN(int21
, "extended open/create: failed because file exists \n");
544 else if ((action
& 0x07) == 2)
546 /* Truncate it, but first check if opened for write */
547 if ((BL_reg(context
) & 0x0007)== 0)
549 BX_reg(context
) = AX_reg(context
);
551 WARN(int21
, "extended open/create: failed, trunc on ro file\n");
552 AX_reg(context
) = 0x000C; /*Access code invalid*/
557 /* Shuffle arguments to call CloseFile while
558 * preserving BX and DX */
560 TRACE(int21
, "extended open/create: Closing before truncate\n");
561 BX_reg(context
) = AX_reg(context
);
563 if (EFL_reg(context
) & 0x0001)
565 WARN(int21
, "extended open/create: close before trunc failed\n");
566 AX_reg(context
) = 0x0019; /*Seek Error*/
570 /* Shuffle arguments to call CreateFile */
572 TRACE(int21
, "extended open/create: Truncating\n");
573 AL_reg(context
) = BL_reg(context
);
574 /* CX is still the same */
575 DX_reg(context
) = SI_reg(context
);
576 bExtendedError
= INT21_CreateFile(context
);
578 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
580 WARN(int21
, "extended open/create: trunc failed\n");
581 return bExtendedError
;
586 else uReturnCX
= 0x1;
588 CX_reg(context
) = uReturnCX
;
590 else /* file does not exist */
592 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
593 if ((action
& 0xF0)== 0)
597 WARN(int21
, "extended open/create: failed, file dosen't exist\n");
601 /* Shuffle arguments to call CreateFile */
602 TRACE(int21
, "extended open/create: Creating\n");
603 AL_reg(context
) = BL_reg(context
);
604 /* CX should still be the same */
605 DX_reg(context
) = SI_reg(context
);
606 bExtendedError
= INT21_CreateFile(context
);
607 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
609 WARN(int21
, "extended open/create: create failed\n");
610 return bExtendedError
;
616 return bExtendedError
;
620 static BOOL32
INT21_ChangeDir( CONTEXT
*context
)
623 char *dirname
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
));
625 TRACE(int21
,"changedir %s\n", dirname
);
626 if (dirname
[0] && (dirname
[1] == ':'))
628 drive
= toupper(dirname
[0]) - 'A';
631 else drive
= DRIVE_GetCurrentDrive();
632 return DRIVE_Chdir( drive
, dirname
);
636 static int INT21_FindFirst( CONTEXT
*context
)
640 DOS_FULL_NAME full_name
;
641 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
643 path
= (const char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
644 dta
->unixPath
= NULL
;
645 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
647 AX_reg(context
) = DOS_ExtendedError
;
651 dta
->unixPath
= HEAP_strdupA( GetProcessHeap(), 0, full_name
.long_name
);
652 p
= strrchr( dta
->unixPath
, '/' );
655 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
656 * (doesn't matter as it is set below anyway)
658 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
660 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
661 dta
->unixPath
= NULL
;
662 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
663 AX_reg(context
) = ER_FileNotFound
;
667 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
668 : DRIVE_GetCurrentDrive();
670 dta
->search_attr
= CL_reg(context
);
675 static int INT21_FindNext( CONTEXT
*context
)
677 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
678 WIN32_FIND_DATA32A entry
;
681 if (!dta
->unixPath
) return 0;
682 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
683 dta
->search_attr
, dta
->count
, &entry
)))
685 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
686 dta
->unixPath
= NULL
;
689 if ((int)dta
->count
+ count
> 0xffff)
691 WARN(int21
, "Too many directory entries in %s\n", dta
->unixPath
);
692 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
693 dta
->unixPath
= NULL
;
697 dta
->fileattr
= entry
.dwFileAttributes
;
698 dta
->filesize
= entry
.nFileSizeLow
;
699 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
700 &dta
->filedate
, &dta
->filetime
);
701 strcpy( dta
->filename
, entry
.cAlternateFileName
);
702 if (!memchr(dta
->mask
,'?',11)) {
703 /* wildcardless search, release resources in case no findnext will
704 * be issued, and as a workaround in case file creation messes up
705 * findnext, as sometimes happens with pkunzip */
706 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
707 dta
->unixPath
= NULL
;
713 static BOOL32
INT21_CreateTempFile( CONTEXT
*context
)
715 static int counter
= 0;
716 char *name
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
) );
717 char *p
= name
+ strlen(name
);
719 /* despite what Ralf Brown says, some programs seem to call without
720 * ending backslash (DOS accepts that, so we accept it too) */
721 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
725 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
726 counter
= (counter
+ 1) % 1000;
728 if ((AX_reg(context
) = HFILE32_TO_HFILE16(_lcreat_uniq( name
, 0 ))) != (WORD
)HFILE_ERROR16
)
730 TRACE(int21
, "created %s\n", name
);
733 if (DOS_ExtendedError
!= ER_FileExists
) return FALSE
;
738 static BOOL32
INT21_GetCurrentDirectory( CONTEXT
*context
)
740 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
741 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
) );
743 if (!DRIVE_IsValid(drive
))
745 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
748 lstrcpyn32A( ptr
, DRIVE_GetDosCwd(drive
), 64 );
749 AX_reg(context
) = 0x0100; /* success return code */
754 static void INT21_GetDBCSLeadTable( CONTEXT
*context
)
756 if (heap
|| INT21_CreateHeap())
757 { /* return an empty table just as DOS 4.0+ does */
758 DS_reg(context
) = DosHeapHandle
;
759 SI_reg(context
) = (int)&heap
->DummyDBCSLeadTable
- (int)heap
;
763 AX_reg(context
) = 0x1; /* error */
769 static int INT21_GetDiskSerialNumber( CONTEXT
*context
)
771 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
772 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
774 if (!DRIVE_IsValid(drive
))
776 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
780 *(WORD
*)dataptr
= 0;
781 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
782 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
783 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
788 static int INT21_SetDiskSerialNumber( CONTEXT
*context
)
790 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
791 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
793 if (!DRIVE_IsValid(drive
))
795 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
799 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
804 /* microsoft's programmers should be shot for using CP/M style int21
805 calls in Windows for Workgroup's winfile.exe */
807 static int INT21_FindFirstFCB( CONTEXT
*context
)
809 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
814 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
815 else pFCB
= (FINDFILE_FCB
*)fcb
;
816 drive
= DOS_GET_DRIVE( pFCB
->drive
);
817 if (!DRIVE_IsValid( drive
)) return 0;
818 root
= DRIVE_GetRoot( drive
);
819 cwd
= DRIVE_GetUnixCwd( drive
);
820 pFCB
->unixPath
= HeapAlloc( GetProcessHeap(), 0,
821 strlen(root
)+strlen(cwd
)+2 );
822 if (!pFCB
->unixPath
) return 0;
823 strcpy( pFCB
->unixPath
, root
);
824 strcat( pFCB
->unixPath
, "/" );
825 strcat( pFCB
->unixPath
, cwd
);
831 static int INT21_FindNextFCB( CONTEXT
*context
)
833 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
835 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA(context
);
836 WIN32_FIND_DATA32A entry
;
840 if (*fcb
== 0xff) /* extended FCB ? */
843 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
848 pFCB
= (FINDFILE_FCB
*)fcb
;
851 if (!pFCB
->unixPath
) return 0;
852 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
853 DOS_GET_DRIVE( pFCB
->drive
), attr
,
854 pFCB
->count
, &entry
)))
856 HeapFree( GetProcessHeap(), 0, pFCB
->unixPath
);
857 pFCB
->unixPath
= NULL
;
860 pFCB
->count
+= count
;
862 if (*fcb
== 0xff) { /* place extended FCB header before pResult if called with extended FCB */
863 *(BYTE
*)pResult
= 0xff;
864 (BYTE
*)pResult
+=6; /* leave reserved field behind */
865 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
868 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
870 pResult
->fileattr
= entry
.dwFileAttributes
;
871 pResult
->cluster
= 0; /* what else? */
872 pResult
->filesize
= entry
.nFileSizeLow
;
873 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
874 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
875 &pResult
->filedate
, &pResult
->filetime
);
877 /* Convert file name to FCB format */
879 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
880 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
881 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
882 pResult
->filename
[0] = pResult
->filename
[1] = '.';
885 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
886 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
888 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
889 MIN( (p
- entry
.cAlternateFileName
), 8 ) );
890 memcpy( pResult
->filename
+ 8, p
+ 1, MIN( strlen(p
), 3 ) );
893 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
894 MIN( strlen(entry
.cAlternateFileName
), 8 ) );
900 static void DeleteFileFCB( CONTEXT
*context
)
902 FIXME(int21
, "(%p): stub\n", context
);
905 static void RenameFileFCB( CONTEXT
*context
)
907 FIXME(int21
, "(%p): stub\n", context
);
912 static void fLock( CONTEXT
* context
)
915 switch ( AX_reg(context
) & 0xff )
917 case 0x00: /* LOCK */
918 TRACE(int21
,"lock handle %d offset %ld length %ld\n",
920 MAKELONG(DX_reg(context
),CX_reg(context
)),
921 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
922 if (!LockFile(HFILE16_TO_HFILE32(BX_reg(context
)),
923 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
924 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
925 AX_reg(context
) = DOS_ExtendedError
;
930 case 0x01: /* UNLOCK */
931 TRACE(int21
,"unlock handle %d offset %ld length %ld\n",
933 MAKELONG(DX_reg(context
),CX_reg(context
)),
934 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
935 if (!UnlockFile(HFILE16_TO_HFILE32(BX_reg(context
)),
936 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
937 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
938 AX_reg(context
) = DOS_ExtendedError
;
943 AX_reg(context
) = 0x0001;
950 INT21_networkfunc (CONTEXT
*context
)
952 switch (AL_reg(context
)) {
953 case 0x00: /* Get machine name. */
955 char *dst
= CTX_SEG_OFF_TO_LIN (context
,DS_reg(context
),EDX_reg(context
));
956 TRACE(int21
, "getting machine name to %p\n", dst
);
957 if (gethostname (dst
, 15))
959 WARN(int21
,"failed!\n");
960 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
963 int len
= strlen (dst
);
967 CH_reg(context
) = 1; /* Valid */
968 CL_reg(context
) = 1; /* NETbios number??? */
969 TRACE(int21
, "returning %s\n", debugstr_an (dst
, 16));
975 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
980 static void INT21_SetCurrentPSP(WORD psp
)
983 TDB
*pTask
= hModule
? NULL
: (TDB
*)GlobalLock16( GetCurrentTask() );
984 NE_MODULE
*pModule
= (hModule
|| pTask
) ? NE_GetPtr( hModule
? hModule
: pTask
->hModule
) : NULL
;
986 GlobalUnlock16( GetCurrentTask() );
987 if (pModule
->lpDosTask
)
988 pModule
->lpDosTask
->psp_seg
= psp
;
991 ERR(int21
, "Cannot change PSP for non-DOS task!\n");
994 static WORD
INT21_GetCurrentPSP()
997 TDB
*pTask
= hModule
? NULL
: (TDB
*)GlobalLock16( GetCurrentTask() );
998 NE_MODULE
*pModule
= (hModule
|| pTask
) ? NE_GetPtr( hModule
? hModule
: pTask
->hModule
) : NULL
;
1000 GlobalUnlock16( GetCurrentTask() );
1001 if (pModule
->lpDosTask
)
1002 return pModule
->lpDosTask
->psp_seg
;
1005 return GetCurrentPDB();
1009 SEGPTR
INT21_GetListOfLists()
1011 static DOS_LISTOFLISTS
*LOL
;
1012 static SEGPTR seg_LOL
;
1017 0133:0020 6A 13-33 01 CC 00 33 01 59 00 j.3...3.Y.
1018 0133:0030 70 00 00 00 72 02 00 02-6D 00 33 01 00 00 2E 05 p...r...m.3.....
1019 0133:0040 00 00 FC 04 00 00 03 08-92 21 11 E0 04 80 C6 0D .........!......
1020 0133:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..NUL ......
1021 0133:0060 00 4B BA C1 06 14 00 00-00 03 01 00 04 70 CE FF .K...........p..
1022 0133:0070 FF 00 00 00 00 00 00 00-00 01 00 00 0D 05 00 00 ................
1023 0133:0080 00 FF FF 00 00 00 00 FE-00 00 F8 03 FF 9F 70 02 ..............p.
1024 0133:0090 D0 44 C8 FD D4 44 C8 FD-D4 44 C8 FD D0 44 C8 FD .D...D...D...D..
1025 0133:00A0 D0 44 C8 FD D0 44 .D...D
1028 LOL
= SEGPTR_ALLOC(sizeof(DOS_LISTOFLISTS
));
1030 LOL
->CX_Int21_5e01
= 0x0;
1031 LOL
->LRU_count_FCB_cache
= 0x0;
1032 LOL
->LRU_count_FCB_open
= 0x0;
1033 LOL
->OEM_func_handler
= -1; /* not available */
1034 LOL
->INT21_offset
= 0x0;
1035 LOL
->sharing_retry_count
= sharing_retries
; /* default value: 3 */
1036 LOL
->sharing_retry_delay
= sharing_pause
; /* default value: 1 */
1037 LOL
->ptr_disk_buf
= 0x0;
1038 LOL
->offs_unread_CON
= 0x0;
1039 LOL
->seg_first_MCB
= 0x0;
1040 LOL
->ptr_first_DPB
= 0x0;
1041 LOL
->ptr_first_SysFileTable
= 0x0;
1042 LOL
->ptr_clock_dev_hdr
= 0x0;
1043 LOL
->ptr_CON_dev_hdr
= 0x0;
1044 LOL
->max_byte_per_sec
= 512;
1045 LOL
->ptr_disk_buf_info
= 0x0;
1046 LOL
->ptr_array_CDS
= 0x0;
1047 LOL
->ptr_sys_FCB
= 0x0;
1048 LOL
->nr_protect_FCB
= 0x0;
1049 LOL
->nr_block_dev
= 0x0;
1050 LOL
->nr_avail_drive_letters
= 26; /* A - Z */
1051 LOL
->nr_drives_JOINed
= 0x0;
1052 LOL
->ptr_spec_prg_names
= 0x0;
1053 LOL
->ptr_SETVER_prg_list
= 0x0; /* no SETVER list */
1054 LOL
->DOS_HIGH_A20_func_offs
= 0x0;
1055 LOL
->PSP_last_exec
= 0x0;
1056 LOL
->BUFFERS_val
= 99; /* maximum: 99 */
1057 LOL
->BUFFERS_nr_lookahead
= 8; /* maximum: 8 */
1058 LOL
->boot_drive
= 3; /* C: */
1059 LOL
->flag_DWORD_moves
= 0x01; /* i386+ */
1060 LOL
->size_extended_mem
= 0xf000; /* very high value */
1062 if (!seg_LOL
) seg_LOL
= SEGPTR_GET(LOL
);
1063 return seg_LOL
+(WORD
)&((DOS_LISTOFLISTS
*)0)->ptr_first_DPB
;
1066 /***********************************************************************
1067 * DOS3Call (KERNEL.102)
1069 void WINAPI
DOS3Call( CONTEXT
*context
)
1071 BOOL32 bSetDOSExtendedError
= FALSE
;
1074 TRACE(int21
, "AX=%04x BX=%04x CX=%04x DX=%04x "
1075 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1076 AX_reg(context
), BX_reg(context
), CX_reg(context
), DX_reg(context
),
1077 SI_reg(context
), DI_reg(context
),
1078 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
1082 if (AH_reg(context
) == 0x59) /* Get extended error info */
1084 TRACE(int21
, "GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1085 DOS_ExtendedError
, DOS_ErrorClass
, DOS_ErrorAction
, DOS_ErrorLocus
);
1086 AX_reg(context
) = DOS_ExtendedError
;
1087 BH_reg(context
) = DOS_ErrorClass
;
1088 BL_reg(context
) = DOS_ErrorAction
;
1089 CH_reg(context
) = DOS_ErrorLocus
;
1093 if (AH_reg(context
) == 0x0C) /* Flush buffer and read standard input */
1095 TRACE(int21
, "FLUSH BUFFER AND READ STANDARD INPUT\n");
1096 /* no flush here yet */
1097 AH_reg(context
) = AL_reg(context
);
1100 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 _lread16(1, (BYTE
*)&context
->Eax
, 1);
1133 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1134 TRACE(int21
, "Write Character to Standard Output\n");
1135 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1138 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1139 TRACE(int21
, "Direct Console Input/Output\n");
1140 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1143 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1144 TRACE(int21
,"DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1145 AL_reg(context
) = CONSOLE_GetCharacter();
1148 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1149 TRACE(int21
,"CHARACTER INPUT WITHOUT ECHO\n");
1150 AL_reg(context
) = CONSOLE_GetCharacter();
1153 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1154 TRACE(int21
,"WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1155 DS_reg(context
),DX_reg(context
) );
1157 LPSTR data
= CTX_SEG_OFF_TO_LIN(context
,DS_reg(context
),EDX_reg(context
));
1158 LONG length
= strchr(data
,'$')-data
;
1159 _hwrite16( 1, data
, length
);
1160 AL_reg(context
) = '$'; /* yes, '$' (0x24) gets returned in AL */
1164 case 0x0a: /* BUFFERED INPUT */
1166 char *buffer
= ((char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1167 EDX_reg(context
) ));
1170 TRACE(int21
,"BUFFERED INPUT (size=%d)\n",buffer
[0]);
1172 TRACE(int21
,"Handle old chars in buffer!\n");
1173 res
=_lread16( 0, buffer
+2,buffer
[0]);
1175 if(buffer
[res
+1] == '\n')
1176 buffer
[res
+1] = '\r';
1180 case 0x0b: /* GET STDIN STATUS */
1184 AL_reg(context
) = CONSOLE_CheckForKeystroke(&dummy
, &dummy
);
1187 case 0x2e: /* SET VERIFY FLAG */
1188 TRACE(int21
,"SET VERIFY FLAG ignored\n");
1189 /* we cannot change the behaviour anyway, so just ignore it */
1192 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1196 case 0x6b: /* NULL FUNCTION */
1197 AL_reg(context
) = 0;
1200 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1204 case 0x0d: /* DISK BUFFER FLUSH */
1205 TRACE(int21
,"DISK BUFFER FLUSH ignored\n");
1206 RESET_CFLAG(context
); /* dos 6+ only */
1209 case 0x0e: /* SELECT DEFAULT DRIVE */
1210 TRACE(int21
,"SELECT DEFAULT DRIVE %d\n", DL_reg(context
));
1211 DRIVE_SetCurrentDrive( DL_reg(context
) );
1212 AL_reg(context
) = MAX_DOS_DRIVES
;
1215 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1216 TRACE(int21
,"FIND FIRST MATCHING FILE USING FCB %p\n",
1217 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1218 if (!INT21_FindFirstFCB(context
))
1220 AL_reg(context
) = 0xff;
1223 /* else fall through */
1225 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1226 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
1229 case 0x13: /* DELETE FILE USING FCB */
1230 DeleteFileFCB(context
);
1233 case 0x17: /* RENAME FILE USING FCB */
1234 RenameFileFCB(context
);
1237 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1238 AL_reg(context
) = DRIVE_GetCurrentDrive();
1241 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1243 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1244 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(context
),DX_reg(context
));
1245 TRACE(int21
, "Set DTA: %08lx\n", pTask
->dta
);
1249 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1250 DL_reg(context
) = 0;
1251 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1254 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1255 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1258 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1259 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1262 case 0x25: /* SET INTERRUPT VECTOR */
1263 INT_CtxSetHandler( context
, AL_reg(context
),
1264 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1268 case 0x29: /* PARSE FILENAME INTO FCB */
1269 INT21_ParseFileNameIntoFCB(context
);
1272 case 0x2a: /* GET SYSTEM DATE */
1273 INT21_GetSystemDate(context
);
1276 case 0x2b: /* SET SYSTEM DATE */
1277 FIXME(int21
, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1278 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1279 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1282 case 0x2c: /* GET SYSTEM TIME */
1283 INT21_GetSystemTime(context
);
1286 case 0x2d: /* SET SYSTEM TIME */
1287 FIXME(int21
, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1288 CH_reg(context
), CL_reg(context
),
1289 DH_reg(context
), DL_reg(context
) );
1290 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1293 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1294 TRACE(int21
,"GET DISK TRANSFER AREA ADDRESS\n");
1296 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1297 ES_reg(context
) = SELECTOROF( pTask
->dta
);
1298 BX_reg(context
) = OFFSETOF( pTask
->dta
);
1302 case 0x30: /* GET DOS VERSION */
1303 TRACE(int21
,"GET DOS VERSION %s requested\n",
1304 (AL_reg(context
) == 0x00)?"OEM number":"version flag");
1305 AX_reg(context
) = (HIWORD(GetVersion16()) >> 8) |
1306 (HIWORD(GetVersion16()) << 8);
1308 AH_reg(context
) = 0x7;
1309 AL_reg(context
) = 0xA;
1312 BX_reg(context
) = 0x00FF; /* 0x123456 is Wine's serial # */
1313 CX_reg(context
) = 0x0000;
1316 case 0x31: /* TERMINATE AND STAY RESIDENT */
1317 FIXME(int21
,"TERMINATE AND STAY RESIDENT stub\n");
1320 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1321 TRACE(int21
,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1322 INT21_DriveName( DL_reg(context
)));
1323 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1326 case 0x33: /* MULTIPLEXED */
1327 switch (AL_reg(context
))
1329 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1330 TRACE(int21
,"GET CURRENT EXTENDED BREAK STATE\n");
1331 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1334 case 0x01: /* SET EXTENDED BREAK STATE */
1335 TRACE(int21
,"SET CURRENT EXTENDED BREAK STATE\n");
1336 DOSCONF_config
.brk_flag
= (DL_reg(context
) > 0);
1339 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1340 TRACE(int21
,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1341 /* ugly coding in order to stay reentrant */
1342 if (DL_reg(context
))
1344 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1345 DOSCONF_config
.brk_flag
= 1;
1349 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1350 DOSCONF_config
.brk_flag
= 0;
1354 case 0x05: /* GET BOOT DRIVE */
1355 TRACE(int21
,"GET BOOT DRIVE\n");
1356 DL_reg(context
) = 3;
1357 /* c: is Wine's bootdrive (a: is 1)*/
1360 case 0x06: /* GET TRUE VERSION NUMBER */
1361 TRACE(int21
,"GET TRUE VERSION NUMBER\n");
1362 BX_reg(context
) = (HIWORD(GetVersion16() >> 8)) |
1363 (HIWORD(GetVersion16() << 8));
1364 DX_reg(context
) = 0x00;
1368 INT_BARF( context
, 0x21 );
1373 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1374 TRACE(int21
,"GET ADDRESS OF INDOS FLAG\n");
1375 if (!heap
) INT21_CreateHeap();
1376 ES_reg(context
) = DosHeapHandle
;
1377 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1380 case 0x35: /* GET INTERRUPT VECTOR */
1381 TRACE(int21
,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
1383 FARPROC16 addr
= INT_CtxGetHandler( context
, AL_reg(context
) );
1384 ES_reg(context
) = SELECTOROF(addr
);
1385 BX_reg(context
) = OFFSETOF(addr
);
1389 case 0x36: /* GET FREE DISK SPACE */
1390 TRACE(int21
,"GET FREE DISK SPACE FOR DRIVE %s\n",
1391 INT21_DriveName( DL_reg(context
)));
1392 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1397 unsigned char switchchar
='/';
1398 switch (AL_reg(context
))
1400 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1401 TRACE(int21
,"SWITCHAR - GET SWITCH CHARACTER\n");
1402 AL_reg(context
) = 0x00; /* success*/
1403 DL_reg(context
) = switchchar
;
1405 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1406 TRACE(int21
,"SWITCHAR - SET SWITCH CHARACTER\n");
1407 switchchar
= DL_reg(context
);
1408 AL_reg(context
) = 0x00; /* success*/
1410 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1411 INT_BARF( context
, 0x21 );
1417 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1418 TRACE(int21
,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1420 AX_reg(context
) = 0x02; /* no country support available */
1424 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1425 TRACE(int21
,"MKDIR %s\n",
1426 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1427 bSetDOSExtendedError
= (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1428 EDX_reg(context
) ), NULL
));
1431 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1432 TRACE(int21
,"RMDIR %s\n",
1433 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1434 bSetDOSExtendedError
= (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1435 EDX_reg(context
) )));
1438 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1439 TRACE(int21
,"CHDIR %s\n",
1440 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1441 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1444 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1445 TRACE(int21
,"CREAT flag 0x%02x %s\n",CX_reg(context
),
1446 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1447 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1448 EDX_reg(context
) ), CX_reg(context
) );
1449 bSetDOSExtendedError
= (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
1452 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1453 TRACE(int21
,"OPEN mode 0x%02x %s\n",AL_reg(context
),
1454 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1455 OpenExistingFile(context
);
1458 case 0x3e: /* "CLOSE" - CLOSE FILE */
1459 TRACE(int21
,"CLOSE handle %d\n",BX_reg(context
));
1460 if ((BX_reg(context
)<5)||
1461 /* FIXME: need to improve on those handle conversion macros */
1462 (BX_reg(context
)==HFILE32_TO_HFILE16(GetStdHandle(STD_INPUT_HANDLE
)))||
1463 (BX_reg(context
)==HFILE32_TO_HFILE16(GetStdHandle(STD_OUTPUT_HANDLE
)))||
1464 (BX_reg(context
)==HFILE32_TO_HFILE16(GetStdHandle(STD_ERROR_HANDLE
)))) {
1465 /* hack to make sure stdio isn't closed */
1466 FIXME(int21
, "stdio handle closed, need proper conversion\n");
1467 DOS_ExtendedError
= 0x06;
1468 bSetDOSExtendedError
= TRUE
;
1470 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1473 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1474 TRACE(int21
,"READ from %d to %04lX:%04X for %d byte\n",BX_reg(context
),
1475 DS_reg(context
),DX_reg(context
),CX_reg(context
) );
1479 result
= _hread16( BX_reg(context
),
1480 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1484 result
= WIN16_hread( BX_reg(context
),
1485 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1488 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1489 else AX_reg(context
) = (WORD
)result
;
1493 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1494 TRACE(int21
,"WRITE from %04lX:%04X to handle %d for %d byte\n",
1495 DS_reg(context
),DX_reg(context
),BX_reg(context
),CX_reg(context
) );
1497 LONG result
= _hwrite16( BX_reg(context
),
1498 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1501 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1502 else AX_reg(context
) = (WORD
)result
;
1506 case 0x41: /* "UNLINK" - DELETE FILE */
1507 TRACE(int21
,"UNLINK%s\n",
1508 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1509 bSetDOSExtendedError
= (!DeleteFile32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1510 EDX_reg(context
) )));
1513 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1514 TRACE(int21
,"LSEEK handle %d offset %ld from %s\n",
1515 BX_reg(context
), MAKELONG(DX_reg(context
),CX_reg(context
)),
1516 (AL_reg(context
)==0)?"start of file":(AL_reg(context
)==1)?
1517 "current file position":"end of file");
1519 LONG status
= _llseek16( BX_reg(context
),
1520 MAKELONG(DX_reg(context
),CX_reg(context
)),
1522 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1525 AX_reg(context
) = LOWORD(status
);
1526 DX_reg(context
) = HIWORD(status
);
1531 case 0x43: /* FILE ATTRIBUTES */
1532 switch (AL_reg(context
))
1535 TRACE(int21
,"GET FILE ATTRIBUTES for %s\n",
1536 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1537 AX_reg(context
) = (WORD
)GetFileAttributes32A(
1538 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1540 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1541 else CX_reg(context
) = AX_reg(context
);
1545 TRACE(int21
,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context
),
1546 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1547 bSetDOSExtendedError
=
1548 (!SetFileAttributes32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1553 TRACE(int21
,"GET COMPRESSED FILE SIZE for %s stub\n",
1554 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1558 case 0x44: /* IOCTL */
1559 switch (AL_reg(context
))
1562 ioctlGetDeviceInfo(context
);
1569 file
= FILE_GetFile(HFILE16_TO_HFILE32(BX_reg(context
)),0,NULL
);
1570 if (!strcasecmp(file
->unix_name
, "SCSIMGR$"))
1571 ASPI_DOS_HandleInt(context
);
1572 FILE_ReleaseFile( file
);
1575 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1576 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));*/
1577 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1579 FIXME(int21
,"program tried to write to block device control channel of drive %d:\n",drive
);
1580 /* for (i=0;i<CX_reg(context);i++)
1581 fprintf(stdnimp,"%02x ",dataptr[i]);
1582 fprintf(stdnimp,"\n");*/
1583 AX_reg(context
)=CX_reg(context
);
1586 case 0x08: /* Check if drive is removable. */
1587 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1588 INT21_DriveName( BL_reg(context
)));
1589 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1591 case DRIVE_CANNOTDETERMINE
:
1592 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1593 AX_reg(context
) = ER_InvalidDrive
;
1596 case DRIVE_REMOVABLE
:
1597 AX_reg(context
) = 0; /* removable */
1600 AX_reg(context
) = 1; /* not removable */
1605 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1606 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1607 INT21_DriveName( BL_reg(context
)));
1608 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1610 case DRIVE_CANNOTDETERMINE
:
1611 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1612 AX_reg(context
) = ER_InvalidDrive
;
1616 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1619 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1624 case 0x0a: /* check if handle (BX) is remote */
1625 TRACE(int21
,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context
));
1626 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1629 DX_reg(context
) = 0;
1632 case 0x0b: /* SET SHARING RETRY COUNT */
1633 TRACE(int21
,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1634 CX_reg(context
), DX_reg(context
));
1635 if (!CX_reg(context
))
1637 AX_reg(context
) = 1;
1641 sharing_pause
= CX_reg(context
);
1642 if (!DX_reg(context
))
1643 sharing_retries
= DX_reg(context
);
1644 RESET_CFLAG(context
);
1648 TRACE(int21
,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1649 INT21_DriveName( BL_reg(context
)));
1650 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1653 case 0x0e: /* get logical drive mapping */
1654 TRACE(int21
,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1655 INT21_DriveName( BL_reg(context
)));
1656 AL_reg(context
) = 0; /* drive has no mapping - FIXME: may be wrong*/
1659 case 0x0F: /* Set logical drive mapping */
1662 TRACE(int21
,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1663 INT21_DriveName( BL_reg(context
)));
1664 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1665 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1668 AX_reg(context
) = 0x000F; /* invalid drive */
1673 case 0xe0: /* Sun PC-NFS API */
1678 INT_BARF( context
, 0x21 );
1683 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1686 TRACE(int21
,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context
));
1687 if ((bSetDOSExtendedError
= !DuplicateHandle( GetCurrentProcess(),
1688 HFILE16_TO_HFILE32(BX_reg(context
)),
1689 GetCurrentProcess(), &handle
,
1690 0, TRUE
, DUPLICATE_SAME_ACCESS
)))
1691 AX_reg(context
) = HFILE_ERROR16
;
1693 AX_reg(context
) = HFILE32_TO_HFILE16(handle
);
1697 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1698 TRACE(int21
,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1699 BX_reg(context
),CX_reg(context
));
1700 bSetDOSExtendedError
= (FILE_Dup2( HFILE16_TO_HFILE32(BX_reg(context
)), HFILE16_TO_HFILE32(CX_reg(context
)) ) == HFILE_ERROR32
);
1703 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1704 TRACE(int21
,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1705 INT21_DriveName( DL_reg(context
)));
1706 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1709 case 0x48: /* ALLOCATE MEMORY */
1710 TRACE(int21
,"ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
));
1715 mem
= DOSMEM_GetBlock(0,(DWORD
)BX_reg(context
)<<4,NULL
);
1717 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1721 mem
= (LPVOID
)GlobalDOSAlloc(BX_reg(context
)<<4);
1723 AX_reg(context
) = (DWORD
)mem
&0xffff;
1728 AX_reg(context
) = 0x0008; /* insufficient memory */
1729 BX_reg(context
) = DOSMEM_Available(0)>>4;
1734 case 0x49: /* FREE MEMORY */
1735 TRACE(int21
,"FREE MEMORY segment %04lX\n", ES_reg(context
));
1739 ret
= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4));
1742 ret
= !GlobalDOSFree(ES_reg(context
));
1743 /* If we don't reset ES_reg, we will fail in the relay code */
1744 ES_reg(context
)=ret
;
1748 TRACE(int21
,"FREE MEMORY failed\n");
1750 AX_reg(context
) = 0x0009; /* memory block address invalid */
1755 case 0x4a: /* RESIZE MEMORY BLOCK */
1756 TRACE(int21
,"RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context
), BX_reg(context
));
1757 if (!ISV86(context
))
1758 FIXME(int21
,"RESIZE MEMORY probably insufficent implementation. Expect crash soon\n");
1760 LPVOID
*mem
= DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4),
1761 BX_reg(context
)<<4,NULL
);
1763 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1766 AX_reg(context
) = 0x0008; /* insufficient memory */
1767 BX_reg(context
) = DOSMEM_Available(0)>>4; /* not quite right */
1772 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1773 TRACE(int21
,"EXEC %s\n",
1774 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
) ));
1775 AX_reg(context
) = WinExec16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1778 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1781 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1782 TRACE(int21
,"EXIT with return code %d\n",AL_reg(context
));
1783 ExitProcess( AL_reg(context
) );
1786 case 0x4d: /* GET RETURN CODE */
1787 TRACE(int21
,"GET RETURN CODE (ERRORLEVEL)\n");
1788 AX_reg(context
) = 0; /* normal exit */
1791 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1792 TRACE(int21
,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
1793 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1794 if (!INT21_FindFirst(context
)) break;
1797 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1798 TRACE(int21
,"FINDNEXT\n");
1799 if (!INT21_FindNext(context
))
1801 DOS_ERROR( ER_NoMoreFiles
, EC_MediaError
, SA_Abort
, EL_Disk
);
1802 AX_reg(context
) = ER_NoMoreFiles
;
1805 else AX_reg(context
) = 0; /* OK */
1807 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1808 TRACE(int21
, "SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1809 INT21_SetCurrentPSP(BX_reg(context
));
1811 case 0x51: /* GET PSP ADDRESS */
1812 TRACE(int21
,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1813 /* FIXME: should we return the original DOS PSP upon */
1814 /* Windows startup ? */
1815 BX_reg(context
) = INT21_GetCurrentPSP();
1817 case 0x62: /* GET PSP ADDRESS */
1818 TRACE(int21
,"GET CURRENT PSP ADDRESS\n");
1819 /* FIXME: should we return the original DOS PSP upon */
1820 /* Windows startup ? */
1821 BX_reg(context
) = INT21_GetCurrentPSP();
1824 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1825 TRACE(int21
,"SYSVARS - GET LIST OF LISTS\n");
1828 lol
= INT21_GetListOfLists();
1829 ES_reg(context
) = HIWORD(lol
);
1830 BX_reg(context
) = LOWORD(lol
);
1834 case 0x56: /* "RENAME" - RENAME FILE */
1835 TRACE(int21
,"RENAME %s to %s\n",
1836 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1837 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
)));
1838 bSetDOSExtendedError
=
1839 (!MoveFile32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1840 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
))));
1843 case 0x57: /* FILE DATE AND TIME */
1844 switch (AL_reg(context
))
1846 case 0x00: /* Get */
1849 TRACE(int21
,"GET FILE DATE AND TIME for handle %d\n",
1851 if (!GetFileTime( HFILE16_TO_HFILE32(BX_reg(context
)), NULL
, NULL
, &filetime
))
1852 bSetDOSExtendedError
= TRUE
;
1853 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1858 case 0x01: /* Set */
1861 TRACE(int21
,"SET FILE DATE AND TIME for handle %d\n",
1863 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1865 bSetDOSExtendedError
=
1866 (!SetFileTime( HFILE16_TO_HFILE32(BX_reg(context
)),
1867 NULL
, NULL
, &filetime
));
1873 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1874 TRACE(int21
,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1876 switch (AL_reg(context
))
1879 AX_reg(context
) = 1;
1882 AX_reg(context
) = 0;
1888 RESET_CFLAG(context
);
1891 case 0x5a: /* CREATE TEMPORARY FILE */
1892 TRACE(int21
,"CREATE TEMPORARY FILE\n");
1893 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1896 case 0x5b: /* CREATE NEW FILE */
1897 TRACE(int21
,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context
),
1898 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1899 bSetDOSExtendedError
= ((AX_reg(context
) =
1900 HFILE32_TO_HFILE16(_lcreat_uniq( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)), 0 )))
1901 == (WORD
)HFILE_ERROR16
);
1904 case 0x5d: /* NETWORK */
1905 FIXME(int21
,"Function 0x%04x not implemented.\n", AX_reg (context
));
1906 /* Fix the following while you're at it. */
1907 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1908 bSetDOSExtendedError
= TRUE
;
1912 bSetDOSExtendedError
= INT21_networkfunc (context
);
1915 case 0x5f: /* NETWORK */
1916 switch (AL_reg(context
))
1918 case 0x07: /* ENABLE DRIVE */
1919 TRACE(int21
,"ENABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1920 if (!DRIVE_Enable( DL_reg(context
) ))
1922 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1923 bSetDOSExtendedError
= TRUE
;
1927 case 0x08: /* DISABLE DRIVE */
1928 TRACE(int21
,"DISABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1929 if (!DRIVE_Disable( DL_reg(context
) ))
1931 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1932 bSetDOSExtendedError
= TRUE
;
1937 /* network software not installed */
1938 TRACE(int21
,"NETWORK function AX=%04x not implemented\n",AX_reg(context
));
1939 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1940 bSetDOSExtendedError
= TRUE
;
1945 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1946 TRACE(int21
,"TRUENAME %s\n",
1947 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),ESI_reg(context
)));
1949 if (!GetFullPathName32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1950 ESI_reg(context
)), 128,
1951 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
1952 EDI_reg(context
)),NULL
))
1953 bSetDOSExtendedError
= TRUE
;
1954 else AX_reg(context
) = 0;
1958 case 0x61: /* UNUSED */
1959 case 0x63: /* misc. language support */
1960 switch (AL_reg(context
)) {
1961 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1962 INT21_GetDBCSLeadTable(context
);
1966 case 0x64: /* OS/2 DOS BOX */
1967 INT_BARF( context
, 0x21 );
1971 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1972 extern WORD WINE_LanguageId
;
1973 BYTE
*dataptr
=CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
));
1974 TRACE(int21
,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1975 BX_reg(context
), DX_reg(context
));
1976 switch (AL_reg(context
)) {
1978 TRACE(int21
,"\tget general internationalization info\n");
1980 *(WORD
*)(dataptr
+1) = 41;
1981 *(WORD
*)(dataptr
+3) = WINE_LanguageId
;
1982 *(WORD
*)(dataptr
+5) = CodePage
;
1983 *(DWORD
*)(dataptr
+0x19) = 0; /* FIXME: ptr to case map routine */
1986 TRACE(int21
,"\tget pointer to collating sequence table\n");
1988 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
1989 CX_reg(context
) = 258;/*FIXME: size of table?*/
1992 TRACE(int21
,"\tunimplemented function %d\n",AL_reg(context
));
1993 INT_BARF( context
, 0x21 );
1999 case 0x66: /* GLOBAL CODE PAGE TABLE */
2000 switch (AL_reg(context
))
2003 TRACE(int21
,"GET GLOBAL CODE PAGE TABLE\n");
2004 DX_reg(context
) = BX_reg(context
) = CodePage
;
2005 RESET_CFLAG(context
);
2008 TRACE(int21
,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2009 BX_reg(context
),DX_reg(context
));
2010 CodePage
= BX_reg(context
);
2011 RESET_CFLAG(context
);
2016 case 0x67: /* SET HANDLE COUNT */
2017 TRACE(int21
,"SET HANDLE COUNT to %d\n",BX_reg(context
) );
2018 SetHandleCount16( BX_reg(context
) );
2019 if (DOS_ExtendedError
) bSetDOSExtendedError
= TRUE
;
2022 case 0x68: /* "FFLUSH" - COMMIT FILE */
2023 case 0x6a: /* COMMIT FILE */
2024 TRACE(int21
,"FFLUSH/COMMIT handle %d\n",BX_reg(context
));
2025 bSetDOSExtendedError
= (!FlushFileBuffers( HFILE16_TO_HFILE32(BX_reg(context
)) ));
2028 case 0x69: /* DISK SERIAL NUMBER */
2029 switch (AL_reg(context
))
2032 TRACE(int21
,"GET DISK SERIAL NUMBER for drive %s\n",
2033 INT21_DriveName(BL_reg(context
)));
2034 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2035 else AX_reg(context
) = 0;
2039 TRACE(int21
,"SET DISK SERIAL NUMBER for drive %s\n",
2040 INT21_DriveName(BL_reg(context
)));
2041 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2042 else AX_reg(context
) = 1;
2047 case 0x6C: /* Extended Open/Create*/
2048 TRACE(int21
,"EXTENDED OPEN/CREATE %s\n",
2049 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDI_reg(context
)));
2050 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2053 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2054 if ((GetVersion32()&0xC0000004)!=0xC0000004) {
2055 /* not supported on anything but Win95 */
2056 TRACE(int21
,"LONG FILENAME functions supported only by win95\n");
2058 AL_reg(context
) = 0;
2060 switch(AL_reg(context
))
2062 case 0x39: /* Create directory */
2063 TRACE(int21
,"LONG FILENAME - MAKE DIRECTORY %s\n",
2064 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2065 bSetDOSExtendedError
= (!CreateDirectory32A(
2066 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2067 EDX_reg(context
) ), NULL
));
2069 case 0x3a: /* Remove directory */
2070 TRACE(int21
,"LONG FILENAME - REMOVE DIRECTORY %s\n",
2071 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2072 bSetDOSExtendedError
= (!RemoveDirectory32A(
2073 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2074 EDX_reg(context
) )));
2076 case 0x43: /* Get/Set file attributes */
2077 TRACE(int21
,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2078 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2079 switch (BL_reg(context
))
2081 case 0x00: /* Get file attributes */
2082 TRACE(int21
,"\tretrieve attributes\n");
2083 CX_reg(context
) = (WORD
)GetFileAttributes32A(
2084 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2086 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
2089 TRACE(int21
,"\tset attributes 0x%04x\n",CX_reg(context
));
2090 bSetDOSExtendedError
= (!SetFileAttributes32A(
2091 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2093 CX_reg(context
) ) );
2096 FIXME(int21
, "Unimplemented long file name function:\n");
2097 INT_BARF( context
, 0x21 );
2099 AL_reg(context
) = 0;
2103 case 0x47: /* Get current directory */
2104 TRACE(int21
," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2105 INT21_DriveName(DL_reg(context
)));
2106 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
2109 case 0x4e: /* Find first file */
2110 TRACE(int21
," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2111 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2112 /* FIXME: use attributes in CX */
2113 if ((AX_reg(context
) = FindFirstFile16(
2114 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
2115 (WIN32_FIND_DATA32A
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2117 == INVALID_HANDLE_VALUE16
)
2118 bSetDOSExtendedError
= TRUE
;
2120 case 0x4f: /* Find next file */
2121 TRACE(int21
,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2123 if (!FindNextFile16( BX_reg(context
),
2124 (WIN32_FIND_DATA32A
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2126 bSetDOSExtendedError
= TRUE
;
2128 case 0xa1: /* Find close */
2129 TRACE(int21
,"LONG FILENAME - FINDCLOSE for handle %d\n",
2131 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
2134 TRACE(int21
,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2135 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2138 switch(CL_reg(context
))
2140 case 0x01: /*Get short filename or path */
2141 if (!GetShortPathName32A
2142 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2144 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2145 EDI_reg(context
)), 67))
2146 bSetDOSExtendedError
= TRUE
;
2147 else AX_reg(context
) = 0;
2149 case 0x02: /*Get canonical long filename or path */
2150 if (!GetFullPathName32A
2151 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2152 ESI_reg(context
)), 128,
2153 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2154 EDI_reg(context
)),NULL
))
2155 bSetDOSExtendedError
= TRUE
;
2156 else AX_reg(context
) = 0;
2159 FIXME(int21
, "Unimplemented long file name function:\n");
2160 INT_BARF( context
, 0x21 );
2162 AL_reg(context
) = 0;
2166 case 0x6c: /* Create or open file */
2167 TRACE(int21
,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
2168 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
)));
2169 /* translate Dos 7 action to Dos 6 action */
2170 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2173 case 0x3b: /* Change directory */
2174 TRACE(int21
,"LONG FILENAME - CHANGE DIRECTORY %s\n",
2175 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
2176 if (!SetCurrentDirectory32A(CTX_SEG_OFF_TO_LIN(context
,
2182 AL_reg(context
) = DOS_ExtendedError
;
2185 case 0x41: /* Delete file */
2186 TRACE(int21
,"LONG FILENAME - DELETE FILE %s\n",
2187 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
2188 if (!DeleteFile32A(CTX_SEG_OFF_TO_LIN(context
,
2193 AL_reg(context
) = DOS_ExtendedError
;
2196 case 0x56: /* Move (rename) file */
2197 TRACE(int21
,"LONG FILENAME - RENAME FILE %s to %s stub\n",
2198 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)),
2199 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), EDI_reg(context
)));
2201 FIXME(int21
, "Unimplemented long file name function:\n");
2202 INT_BARF( context
, 0x21 );
2204 AL_reg(context
) = 0;
2209 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2210 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2211 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2212 TRACE(int21
,"windows95 function AX %04x\n",
2214 WARN(int21
, " returning unimplemented\n");
2216 AL_reg(context
) = 0;
2219 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2220 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2224 INT_BARF( context
, 0x21 );
2227 } /* END OF SWITCH */
2229 if( bSetDOSExtendedError
) /* set general error condition */
2231 AX_reg(context
) = DOS_ExtendedError
;
2235 if ((EFL_reg(context
) & 0x0001))
2236 TRACE(int21
, "failed, errorcode 0x%02x class 0x%02x action 0x%02x locus %02x\n",
2237 DOS_ExtendedError
, DOS_ErrorClass
, DOS_ErrorAction
, DOS_ErrorLocus
);
2239 TRACE(int21
, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2240 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2241 AX_reg(context
), BX_reg(context
), CX_reg(context
),
2242 DX_reg(context
), SI_reg(context
), DI_reg(context
),
2243 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
2247 FARPROC16 WINAPI
GetSetKernelDOSProc(FARPROC16 DosProc
)
2249 FIXME(int21
, "(DosProc=0x%08x): stub\n", (UINT32
)DosProc
);