2 * DOS interrupt 21h handler
14 #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) */
76 static struct DosHeap
*heap
;
77 static WORD DosHeapHandle
;
79 WORD sharing_retries
= 3; /* number of retries at sharing violation */
80 WORD sharing_pause
= 1; /* pause between retries */
82 extern char TempDirectory
[];
84 static BOOL32
INT21_CreateHeap(void)
86 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
88 fprintf( stderr
, "INT21_Init: Out of memory\n");
91 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
92 dpbsegptr
= PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
94 strcpy(heap
->biosdate
, "01/01/80");
98 BYTE
*GetCurrentDTA(void)
100 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
101 return (BYTE
*)PTR_SEG_TO_LIN( pTask
->dta
);
105 void ChopOffWhiteSpace(char *string
)
109 for (length
= strlen(string
) ; length
; length
--)
110 if (string
[length
] == ' ')
111 string
[length
] = '\0';
114 void CreateBPB(int drive
, BYTE
*data
)
119 setword(&data
[3], 0);
121 setword(&data
[6], 240);
122 setword(&data
[8], 64000);
124 setword(&data
[0x0b], 40);
125 setword(&data
[0x0d], 56);
126 setword(&data
[0x0f], 2);
127 setword(&data
[0x11], 0);
128 setword(&data
[0x1f], 800);
130 setword(&data
[0x22], 1);
131 } else { /* 1.44mb */
134 setword(&data
[3], 0);
136 setword(&data
[6], 240);
137 setword(&data
[8], 2880);
139 setword(&data
[0x0b], 6);
140 setword(&data
[0x0d], 18);
141 setword(&data
[0x0f], 2);
142 setword(&data
[0x11], 0);
143 setword(&data
[0x1f], 80);
145 setword(&data
[0x22], 2);
149 static int INT21_GetFreeDiskSpace( CONTEXT
*context
)
151 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
152 char root
[] = "A:\\";
154 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
155 if (!GetDiskFreeSpace32A( root
, &cluster_sectors
, §or_bytes
,
156 &free_clusters
, &total_clusters
)) return 0;
157 AX_reg(context
) = cluster_sectors
;
158 BX_reg(context
) = free_clusters
;
159 CX_reg(context
) = sector_bytes
;
160 DX_reg(context
) = total_clusters
;
164 static int INT21_GetDriveAllocInfo( CONTEXT
*context
)
166 if (!INT21_GetFreeDiskSpace( context
)) return 0;
167 if (!heap
&& !INT21_CreateHeap()) return 0;
168 heap
->mediaID
= 0xf0;
169 DS_reg(context
) = DosHeapHandle
;
170 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
174 static void GetDrivePB( CONTEXT
*context
, int drive
)
176 if(!DRIVE_IsValid(drive
))
178 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
179 AX_reg(context
) = 0x00ff;
181 else if (heap
|| INT21_CreateHeap())
183 dprintf_int(stddeb
, "int21: GetDrivePB not fully implemented.\n");
185 /* FIXME: I have no idea what a lot of this information should
186 * say or whether it even really matters since we're not allowing
187 * direct block access. However, some programs seem to depend on
188 * getting at least _something_ back from here. The 'next' pointer
189 * does worry me, though. Should we have a complete table of
190 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
192 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
193 heap
->dpb
.sector_size
= 512;
194 heap
->dpb
.high_sector
= 1;
195 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
196 heap
->dpb
.reserved
= 0;
197 heap
->dpb
.num_FAT
= 1;
198 heap
->dpb
.dir_entries
= 2;
199 heap
->dpb
.first_data
= 2;
200 heap
->dpb
.high_cluster
= 64000;
201 heap
->dpb
.sectors_in_FAT
= 1;
202 heap
->dpb
.start_dir
= 1;
203 heap
->dpb
.driver_head
= 0;
204 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
205 heap
->dpb
.access_flag
= 0;
207 heap
->dpb
.free_search
= 0;
208 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
210 AL_reg(context
) = 0x00;
211 DS_reg(context
) = SELECTOROF(dpbsegptr
);
212 BX_reg(context
) = OFFSETOF(dpbsegptr
);
217 static void ioctlGetDeviceInfo( CONTEXT
*context
)
219 dprintf_int (stddeb
, "int21: ioctl (%d, GetDeviceInfo)\n", BX_reg(context
));
221 DX_reg(context
) = 0x0942;
222 /* bits 0-5 are current drive
223 * bit 6 - file has NOT been written..FIXME: correct?
224 * bit 8 - generate int24 if no diskspace on write/ read past end of file
225 * bit 11 - media not removable
227 RESET_CFLAG(context
);
230 static BOOL32
ioctlGenericBlkDevReq( CONTEXT
*context
)
232 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
233 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
235 if (!DRIVE_IsValid(drive
))
237 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
241 if (CH_reg(context
) != 0x08)
243 INT_BARF( context
, 0x21 );
247 switch (CL_reg(context
))
249 case 0x4a: /* lock logical volume */
250 dprintf_int(stddeb
,"int21: lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
253 case 0x60: /* get device parameters */
254 /* used by w4wgrp's winfile */
255 memset(dataptr
, 0, 0x26);
257 dataptr
[6] = 0; /* media type */
260 dataptr
[1] = 0x05; /* fixed disk */
261 setword(&dataptr
[2], 0x01); /* non removable */
262 setword(&dataptr
[4], 0x300); /* # of cylinders */
266 dataptr
[1] = 0x07; /* block dev, floppy */
267 setword(&dataptr
[2], 0x02); /* removable */
268 setword(&dataptr
[4], 80); /* # of cylinders */
270 CreateBPB(drive
, &dataptr
[7]);
271 RESET_CFLAG(context
);
274 case 0x66:/* get disk serial number */
276 char label
[12],fsname
[9],path
[4];
279 strcpy(path
,"x:\\");path
[0]=drive
+'A';
280 GetVolumeInformation32A(
281 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
284 memcpy(dataptr
+2,&serial
,4);
285 memcpy(dataptr
+6,label
,11);
286 memcpy(dataptr
+17,fsname
,8);
291 dprintf_int(stddeb
,"int21: logical volume %d unlocked.\n",drive
);
295 INT_BARF( context
, 0x21 );
300 static void INT21_GetSystemDate( CONTEXT
*context
)
303 GetLocalTime( &systime
);
304 CX_reg(context
) = systime
.wYear
;
305 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
306 AX_reg(context
) = systime
.wDayOfWeek
;
309 static void INT21_GetSystemTime( CONTEXT
*context
)
312 GetLocalTime( &systime
);
313 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
314 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
317 static BOOL32
INT21_CreateFile( CONTEXT
*context
)
319 AX_reg(context
) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
320 DX_reg(context
) ), CX_reg(context
) );
321 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
325 void OpenExistingFile( CONTEXT
*context
)
327 AX_reg(context
) = _lopen16( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
329 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
331 AX_reg(context
) = DOS_ExtendedError
;
339 switch (AX_reg(context
) & 0x0070)
341 case 0x00: /* compatability mode */
342 case 0x40: /* DENYNONE */
346 case 0x30: /* DENYREAD */
348 "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
349 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)));
350 case 0x10: /* DENYALL */
354 case 0x20: /* DENYWRITE */
365 int result
,retries
=sharing_retries
;
367 #if defined(__svr4__) || defined(_SCO_DS)
368 printf("Should call flock and needs porting to lockf\n");
372 result
= flock(handle
, lock
| LOCK_NB
);
374 if ( retries
&& (!result
) )
377 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
378 result
++; /* stop the optimizer */
379 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
383 while( (!result
) && (!(retries
--)) );
388 AX_reg(context
) = ExtendedError
;
397 AX_reg(context
) = handle
;
398 RESET_CFLAG(context
);
402 static void CloseFile( CONTEXT
*context
)
404 if ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0)
406 AX_reg(context
) = DOS_ExtendedError
;
411 static BOOL32
INT21_ExtendedOpenCreateFile(CONTEXT
*context
)
413 BOOL32 bExtendedError
= FALSE
;
414 BYTE action
= DL_reg(context
);
416 /* Shuffle arguments to call OpenExistingFile */
417 AL_reg(context
) = BL_reg(context
);
418 DX_reg(context
) = SI_reg(context
);
419 /* BX,CX and DX should be preserved */
420 OpenExistingFile(context
);
422 if ((EFL_reg(context
) & 0x0001) == 0) /* File exists */
424 UINT16 uReturnCX
= 0;
426 /* Now decide what do do */
428 if ((action
& 0x07) == 0)
430 BX_reg(context
) = AX_reg(context
);
432 AX_reg(context
) = 0x0050; /*File exists*/
434 dprintf_int(stddeb
, "int21: extended open/create: failed because file exists \n");
436 else if ((action
& 0x07) == 2)
438 /* Truncate it, but first check if opened for write */
439 if ((BL_reg(context
) & 0x0007)== 0)
441 BX_reg(context
) = AX_reg(context
);
443 dprintf_int(stddeb
, "int21: extended open/create: failed, trunc on ro file");
444 AX_reg(context
) = 0x000C; /*Access code invalid*/
449 /* Shuffle arguments to call CloseFile while
450 * preserving BX and DX */
452 dprintf_int(stddeb
, "int21: extended open/create: Closing before truncate\n");
453 BX_reg(context
) = AX_reg(context
);
455 if (EFL_reg(context
) & 0x0001)
457 dprintf_int(stddeb
, "int21: extended open/create: close before trunc failed");
458 AX_reg(context
) = 0x0019; /*Seek Error*/
462 /* Shuffle arguments to call CreateFile */
464 dprintf_int(stddeb
, "int21: extended open/create: Truncating\n");
465 AL_reg(context
) = BL_reg(context
);
466 /* CX is still the same */
467 DX_reg(context
) = SI_reg(context
);
468 bExtendedError
= INT21_CreateFile(context
);
470 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
472 dprintf_int(stddeb
, "int21: extended open/create: trunc failed");
473 return bExtendedError
;
478 else uReturnCX
= 0x1;
480 CX_reg(context
) = uReturnCX
;
482 else /* file does not exist */
484 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
485 if ((action
& 0xF0)== 0)
489 dprintf_int(stddeb
, "int21: extended open/create: failed, file dosen't exist\n");
493 /* Shuffle arguments to call CreateFile */
494 dprintf_int(stddeb
, "int21: extended open/create: Creating\n");
495 AL_reg(context
) = BL_reg(context
);
496 /* CX should still be the same */
497 DX_reg(context
) = SI_reg(context
);
498 bExtendedError
= INT21_CreateFile(context
);
499 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
501 dprintf_int(stddeb
, "int21: extended open/create: create failed\n");
502 return bExtendedError
;
508 return bExtendedError
;
512 static BOOL32
INT21_ChangeDir( CONTEXT
*context
)
515 char *dirname
= PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
));
517 dprintf_int(stddeb
,"int21: changedir %s\n", dirname
);
518 if (dirname
[0] && (dirname
[1] == ':'))
520 drive
= toupper(dirname
[0]) - 'A';
523 else drive
= DRIVE_GetCurrentDrive();
524 return DRIVE_Chdir( drive
, dirname
);
528 static int INT21_FindFirst( CONTEXT
*context
)
532 DOS_FULL_NAME full_name
;
533 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
535 path
= (const char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
536 dta
->unixPath
= NULL
;
537 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
539 AX_reg(context
) = DOS_ExtendedError
;
543 dta
->unixPath
= xstrdup( full_name
.long_name
);
544 p
= strrchr( dta
->unixPath
, '/' );
547 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
548 * (doesn't matter as it is set below anyway)
550 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
552 free( dta
->unixPath
);
553 dta
->unixPath
= NULL
;
554 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
555 AX_reg(context
) = ER_FileNotFound
;
559 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
560 : DRIVE_GetCurrentDrive();
562 dta
->search_attr
= CL_reg(context
);
567 static int INT21_FindNext( CONTEXT
*context
)
569 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
570 WIN32_FIND_DATA32A entry
;
573 if (!dta
->unixPath
) return 0;
574 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
575 dta
->search_attr
, dta
->count
, &entry
)))
577 free( dta
->unixPath
);
578 dta
->unixPath
= NULL
;
581 if ((int)dta
->count
+ count
> 0xffff)
583 fprintf( stderr
, "Too many directory entries in %s\n", dta
->unixPath
);
584 free( dta
->unixPath
);
585 dta
->unixPath
= NULL
;
589 dta
->fileattr
= entry
.dwFileAttributes
;
590 dta
->filesize
= entry
.nFileSizeLow
;
591 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
592 &dta
->filedate
, &dta
->filetime
);
593 strcpy( dta
->filename
, entry
.cAlternateFileName
);
598 static BOOL32
INT21_CreateTempFile( CONTEXT
*context
)
600 static int counter
= 0;
601 char *name
= PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
) );
602 char *p
= name
+ strlen(name
);
606 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
607 counter
= (counter
+ 1) % 1000;
609 if ((AX_reg(context
) = _lcreat_uniq( name
, 0 )) != (WORD
)HFILE_ERROR16
)
611 dprintf_int( stddeb
, "INT21_CreateTempFile: created %s\n", name
);
614 if (DOS_ExtendedError
!= ER_FileExists
) return FALSE
;
619 static BOOL32
INT21_GetCurrentDirectory( CONTEXT
*context
)
621 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
622 char *ptr
= (char *)PTR_SEG_OFF_TO_LIN( DS_reg(context
), SI_reg(context
) );
624 if (!DRIVE_IsValid(drive
))
626 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
629 lstrcpyn32A( ptr
, DRIVE_GetDosCwd(drive
), 64 );
630 AX_reg(context
) = 0x0100; /* success return code */
635 static int INT21_GetDiskSerialNumber( CONTEXT
*context
)
637 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
638 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
640 if (!DRIVE_IsValid(drive
))
642 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
646 *(WORD
*)dataptr
= 0;
647 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
648 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
649 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
654 static int INT21_SetDiskSerialNumber( CONTEXT
*context
)
656 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
657 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
659 if (!DRIVE_IsValid(drive
))
661 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
665 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
670 /* microsoft's programmers should be shot for using CP/M style int21
671 calls in Windows for Workgroup's winfile.exe */
673 static int INT21_FindFirstFCB( CONTEXT
*context
)
675 BYTE
*fcb
= (BYTE
*)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
680 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
681 else pFCB
= (FINDFILE_FCB
*)fcb
;
682 drive
= DOS_GET_DRIVE( pFCB
->drive
);
683 root
= DRIVE_GetRoot( drive
);
684 cwd
= DRIVE_GetUnixCwd( drive
);
685 pFCB
->unixPath
= HeapAlloc( SystemHeap
, 0, strlen(root
)+strlen(cwd
)+2 );
686 if (!pFCB
->unixPath
) return 0;
687 strcpy( pFCB
->unixPath
, root
);
688 strcat( pFCB
->unixPath
, "/" );
689 strcat( pFCB
->unixPath
, cwd
);
695 static int INT21_FindNextFCB( CONTEXT
*context
)
697 BYTE
*fcb
= (BYTE
*)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
699 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA();
700 WIN32_FIND_DATA32A entry
;
707 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
712 pFCB
= (FINDFILE_FCB
*)fcb
;
715 if (!pFCB
->unixPath
) return 0;
716 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
717 DOS_GET_DRIVE( pFCB
->drive
), attr
,
718 pFCB
->count
, &entry
)))
720 HeapFree( SystemHeap
, 0, pFCB
->unixPath
);
721 pFCB
->unixPath
= NULL
;
724 pFCB
->count
+= count
;
726 pResult
->fileattr
= entry
.dwFileAttributes
;
727 pResult
->cluster
= 0; /* what else? */
728 pResult
->filesize
= entry
.nFileSizeLow
;
729 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
730 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
731 &pResult
->filedate
, &pResult
->filetime
);
733 /* Convert file name to FCB format */
735 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
736 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
737 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
738 pResult
->filename
[0] = pResult
->filename
[1] = '.';
741 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
742 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
744 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
745 MIN( (p
- entry
.cAlternateFileName
), 8 ) );
746 memcpy( pResult
->filename
+ 8, p
+ 1, MIN( strlen(p
), 3 ) );
749 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
750 MIN( strlen(entry
.cAlternateFileName
), 8 ) );
756 static void DeleteFileFCB( CONTEXT
*context
)
758 fprintf( stderr
, "DeleteFileFCB: not implemented yet\n" );
760 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
761 struct dosdirent
*dp
;
762 char temp
[256], *ptr
;
763 int drive
= DOS_GET_DRIVE( *fcb
);
768 strcpy(temp
+1, DRIVE_GetDosCwd(drive
));
770 strncat(temp
, fcb
+ 1, 8);
771 ChopOffWhiteSpace(temp
);
772 strncat(temp
, fcb
+ 9, 3);
773 ChopOffWhiteSpace(temp
);
775 if ((dp
= DOS_opendir(temp
)) == NULL
) {
776 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
777 AX_reg(context
) = 0xff;
782 strcpy(temp
+1, DRIVE_GetDosCwd(drive
) );
785 ptr
= temp
+ strlen(temp
);
787 while (DOS_readdir(dp
) != NULL
)
789 strcpy(ptr
, dp
->filename
);
790 dprintf_int(stddeb
, "int21: delete file %s\n", temp
);
791 /* unlink(DOS_GetUnixFileName(temp)); */
798 static void RenameFileFCB( CONTEXT
*context
)
800 fprintf( stderr
, "RenameFileFCB: not implemented yet\n" );
802 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
803 struct dosdirent
*dp
;
804 char temp
[256], oldname
[256], newname
[256], *oldnameptr
, *newnameptr
;
805 int drive
= DOS_GET_DRIVE( *fcb
);
810 strcpy(temp
+1, DRIVE_GetDosCwd(drive
) );
812 strncat(temp
, fcb
+ 1, 8);
813 ChopOffWhiteSpace(temp
);
814 strncat(temp
, fcb
+ 9, 3);
815 ChopOffWhiteSpace(temp
);
817 if ((dp
= DOS_opendir(temp
)) == NULL
) {
818 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
819 AX_reg(context
) = 0xff;
824 strcpy(oldname
+1, DRIVE_GetDosCwd(drive
) );
825 strcat(oldname
, "\\");
826 strcpy( newname
, oldname
);
827 oldnameptr
= oldname
+ strlen(oldname
);
828 newnameptr
= newname
+ strlen(newname
);
830 while (DOS_readdir(dp
) != NULL
)
832 strcpy(oldnameptr
, dp
->filename
);
833 strcpy(newnameptr
, fcb
+ 1);
834 dprintf_int(stddeb
, "int21: renamefile %s -> %s\n",
844 static void fLock( CONTEXT
* context
)
848 int result
,retries
=sharing_retries
;
850 f
.l_start
= MAKELONG(DX_reg(context
),CX_reg(context
));
851 f
.l_len
= MAKELONG(DI_reg(context
),SI_reg(context
));
855 switch ( AX_reg(context
) & 0xff )
857 case 0x00: /* LOCK */
861 case 0x01: /* UNLOCK */
866 AX_reg(context
) = 0x0001;
872 result
= fcntl(BX_reg(context
),F_SETLK
,&f
);
873 if ( retries
&& (!result
) )
876 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
877 result
++; /* stop the optimizer */
878 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
882 while( (!result
) && (!(retries
--)) );
887 AX_reg(context
) = DOS_ExtendedError
;
895 extern void LOCAL_PrintHeap (WORD ds
);
897 /***********************************************************************
898 * DOS3Call (KERNEL.102)
900 void DOS3Call( CONTEXT
*context
)
902 BOOL32 bSetDOSExtendedError
= FALSE
;
904 dprintf_int( stddeb
, "int21: AX=%04x BX=%04x CX=%04x DX=%04x "
905 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
906 AX_reg(context
), BX_reg(context
), CX_reg(context
),
907 DX_reg(context
), SI_reg(context
), DI_reg(context
),
908 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
911 if (AH_reg(context
) == 0x59) /* Get extended error info */
913 AX_reg(context
) = DOS_ExtendedError
;
914 BH_reg(context
) = DOS_ErrorClass
;
915 BL_reg(context
) = DOS_ErrorAction
;
916 CH_reg(context
) = DOS_ErrorLocus
;
920 DOS_ERROR( 0, 0, 0, 0 );
921 RESET_CFLAG(context
); /* Not sure if this is a good idea */
923 switch(AH_reg(context
))
925 case 0x00: /* TERMINATE PROGRAM */
926 TASK_KillCurrentTask( 0 );
929 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
930 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
931 case 0x03: /* READ CHARACTER FROM STDAUX */
932 case 0x04: /* WRITE CHARACTER TO STDAUX */
933 case 0x05: /* WRITE CHARACTER TO PRINTER */
934 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
935 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
936 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
937 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
938 case 0x0a: /* BUFFERED INPUT */
939 case 0x0b: /* GET STDIN STATUS */
940 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
941 case 0x0f: /* OPEN FILE USING FCB */
942 case 0x10: /* CLOSE FILE USING FCB */
943 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
944 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
945 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
946 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
947 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
948 case 0x23: /* GET FILE SIZE FOR FCB */
949 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
950 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
951 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
952 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
953 case 0x29: /* PARSE FILENAME INTO FCB */
954 case 0x2e: /* SET VERIFY FLAG */
955 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
956 "SWITCHAR" - SET SWITCH CHARACTER
957 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
958 case 0x54: /* GET VERIFY FLAG */
959 INT_BARF( context
, 0x21 );
962 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
966 case 0x6b: /* NULL FUNCTION */
970 case 0x5c: /* "FLOCK" - RECORD LOCKING */
974 case 0x0d: /* DISK BUFFER FLUSH */
975 RESET_CFLAG(context
); /* dos 6+ only */
978 case 0x0e: /* SELECT DEFAULT DRIVE */
979 DRIVE_SetCurrentDrive( DL_reg(context
) );
980 AL_reg(context
) = MAX_DOS_DRIVES
;
983 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
984 if (!INT21_FindFirstFCB(context
))
986 AL_reg(context
) = 0xff;
989 /* else fall through */
991 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
992 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
995 case 0x13: /* DELETE FILE USING FCB */
996 DeleteFileFCB(context
);
999 case 0x17: /* RENAME FILE USING FCB */
1000 RenameFileFCB(context
);
1003 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1004 AL_reg(context
) = DRIVE_GetCurrentDrive();
1007 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1009 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1010 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(context
),DX_reg(context
));
1011 dprintf_int(stddeb
, "int21: Set DTA: %08lx\n", pTask
->dta
);
1015 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1016 DL_reg(context
) = 0;
1017 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1020 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1021 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1024 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1025 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1028 case 0x25: /* SET INTERRUPT VECTOR */
1029 INT_SetHandler( AL_reg(context
),
1030 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1034 case 0x2a: /* GET SYSTEM DATE */
1035 INT21_GetSystemDate(context
);
1038 case 0x2b: /* SET SYSTEM DATE */
1039 fprintf( stdnimp
, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1040 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1041 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1044 case 0x2c: /* GET SYSTEM TIME */
1045 INT21_GetSystemTime(context
);
1048 case 0x2d: /* SET SYSTEM TIME */
1049 fprintf( stdnimp
, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1050 CH_reg(context
), CL_reg(context
),
1051 DH_reg(context
), DL_reg(context
) );
1052 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1055 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1057 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1058 ES_reg(context
) = SELECTOROF( pTask
->dta
);
1059 BX_reg(context
) = OFFSETOF( pTask
->dta
);
1063 case 0x30: /* GET DOS VERSION */
1064 AX_reg(context
) = DOSVERSION
;
1065 BX_reg(context
) = 0x0012; /* 0x123456 is Wine's serial # */
1066 CX_reg(context
) = 0x3456;
1069 case 0x31: /* TERMINATE AND STAY RESIDENT */
1070 INT_BARF( context
, 0x21 );
1073 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1074 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1077 case 0x33: /* MULTIPLEXED */
1078 switch (AL_reg(context
))
1080 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1081 DL_reg(context
) = 0;
1084 case 0x01: /* SET EXTENDED BREAK STATE */
1087 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1088 DL_reg(context
) = 0;
1091 case 0x05: /* GET BOOT DRIVE */
1092 DL_reg(context
) = 3;
1093 /* c: is Wine's bootdrive (a: is 1)*/
1096 case 0x06: /* GET TRUE VERSION NUMBER */
1097 BX_reg(context
) = DOSVERSION
;
1098 DX_reg(context
) = 0x00;
1102 INT_BARF( context
, 0x21 );
1107 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1108 if (!heap
) INT21_CreateHeap();
1109 ES_reg(context
) = DosHeapHandle
;
1110 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1113 case 0x35: /* GET INTERRUPT VECTOR */
1115 FARPROC16 addr
= INT_GetHandler( AL_reg(context
) );
1116 ES_reg(context
) = SELECTOROF(addr
);
1117 BX_reg(context
) = OFFSETOF(addr
);
1121 case 0x36: /* GET FREE DISK SPACE */
1122 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1125 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1126 AX_reg(context
) = 0x02; /* no country support available */
1130 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1131 bSetDOSExtendedError
= (!CreateDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1132 DX_reg(context
) ), NULL
));
1135 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1136 bSetDOSExtendedError
= (!RemoveDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1137 DX_reg(context
) )));
1140 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1141 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1144 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1145 AX_reg(context
) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1146 DX_reg(context
) ), CX_reg(context
) );
1147 bSetDOSExtendedError
= (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
1150 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1151 OpenExistingFile(context
);
1154 case 0x3e: /* "CLOSE" - CLOSE FILE */
1155 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1158 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1160 LONG result
= WIN16_hread( BX_reg(context
),
1161 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1164 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1165 else AX_reg(context
) = (WORD
)result
;
1169 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1171 LONG result
= _hwrite16( BX_reg(context
),
1172 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1175 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1176 else AX_reg(context
) = (WORD
)result
;
1180 case 0x41: /* "UNLINK" - DELETE FILE */
1181 bSetDOSExtendedError
= (!DeleteFile32A( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1182 DX_reg(context
) )));
1185 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1187 LONG status
= _llseek16( BX_reg(context
),
1188 MAKELONG(DX_reg(context
),CX_reg(context
)),
1190 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1193 AX_reg(context
) = LOWORD(status
);
1194 DX_reg(context
) = HIWORD(status
);
1199 case 0x43: /* FILE ATTRIBUTES */
1200 switch (AL_reg(context
))
1203 AX_reg(context
) = (WORD
)GetFileAttributes32A(
1204 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1206 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1207 else CX_reg(context
) = AX_reg(context
);
1211 bSetDOSExtendedError
=
1212 (!SetFileAttributes32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1219 case 0x44: /* IOCTL */
1220 switch (AL_reg(context
))
1223 ioctlGetDeviceInfo(context
);
1228 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1229 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
));
1231 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1233 fprintf(stdnimp
,"int21: program tried to write to block device control channel of drive %d:\n",drive
);
1234 for (i
=0;i
<CX_reg(context
);i
++)
1235 fprintf(stdnimp
,"%02x ",dataptr
[i
]);
1236 fprintf(stdnimp
,"\n");
1237 AX_reg(context
)=CX_reg(context
);
1240 case 0x08: /* Check if drive is removable. */
1241 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1243 case DRIVE_CANNOTDETERMINE
:
1244 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1245 AX_reg(context
) = ER_InvalidDrive
;
1248 case DRIVE_REMOVABLE
:
1249 AX_reg(context
) = 0; /* removable */
1252 AX_reg(context
) = 1; /* not removable */
1257 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1258 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1260 case DRIVE_CANNOTDETERMINE
:
1261 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1262 AX_reg(context
) = ER_InvalidDrive
;
1266 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1269 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1274 case 0x0a: /* check if handle (BX) is remote */
1275 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1278 DX_reg(context
) = 0;
1281 case 0x0b: /* SET SHARING RETRY COUNT */
1282 if (!CX_reg(context
))
1284 AX_reg(context
) = 1;
1288 sharing_pause
= CX_reg(context
);
1289 if (!DX_reg(context
))
1290 sharing_retries
= DX_reg(context
);
1291 RESET_CFLAG(context
);
1295 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1298 case 0x0e: /* get logical drive mapping */
1299 AL_reg(context
) = 0; /* drive has no mapping */
1302 case 0x0F: /* Set logical drive mapping */
1303 /* FIXME: Not implemented at the moment, always returns error
1305 INT_BARF( context
, 0x21 );
1306 AX_reg(context
) = 0x0001; /* invalid function */
1311 INT_BARF( context
, 0x21 );
1316 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1317 bSetDOSExtendedError
= ((AX_reg(context
) = FILE_Dup(BX_reg(context
))) == (WORD
)HFILE_ERROR16
);
1320 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1321 bSetDOSExtendedError
= (FILE_Dup2( BX_reg(context
), CX_reg(context
) ) == HFILE_ERROR32
);
1324 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1325 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1328 case 0x48: /* ALLOCATE MEMORY */
1329 case 0x49: /* FREE MEMORY */
1330 case 0x4a: /* RESIZE MEMORY BLOCK */
1331 INT_BARF( context
, 0x21 );
1334 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1335 AX_reg(context
) = WinExec16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1338 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1341 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1342 TASK_KillCurrentTask( AL_reg(context
) );
1345 case 0x4d: /* GET RETURN CODE */
1346 AX_reg(context
) = 0; /* normal exit */
1349 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1350 if (!INT21_FindFirst(context
)) break;
1353 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1354 if (!INT21_FindNext(context
))
1356 DOS_ERROR( ER_NoMoreFiles
, EC_MediaError
, SA_Abort
, EL_Disk
);
1357 AX_reg(context
) = ER_NoMoreFiles
;
1362 case 0x51: /* GET PSP ADDRESS */
1363 case 0x62: /* GET PSP ADDRESS */
1364 /* FIXME: should we return the original DOS PSP upon */
1365 /* Windows startup ? */
1366 BX_reg(context
) = GetCurrentPDB();
1369 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1370 ES_reg(context
) = 0x0;
1371 BX_reg(context
) = 0x0;
1372 INT_BARF( context
, 0x21 );
1375 case 0x56: /* "RENAME" - RENAME FILE */
1376 bSetDOSExtendedError
=
1377 (!MoveFile32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
1378 PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
))));
1381 case 0x57: /* FILE DATE AND TIME */
1382 switch (AL_reg(context
))
1384 case 0x00: /* Get */
1387 if (!GetFileTime( BX_reg(context
), NULL
, NULL
, &filetime
))
1388 bSetDOSExtendedError
= TRUE
;
1389 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1394 case 0x01: /* Set */
1397 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1399 bSetDOSExtendedError
=
1400 (!SetFileTime( BX_reg(context
), NULL
, NULL
, &filetime
));
1406 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1407 switch (AL_reg(context
))
1410 AX_reg(context
) = 1;
1413 AX_reg(context
) = 0;
1419 RESET_CFLAG(context
);
1422 case 0x5a: /* CREATE TEMPORARY FILE */
1423 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1426 case 0x5b: /* CREATE NEW FILE */
1427 bSetDOSExtendedError
= ((AX_reg(context
) =
1428 _lcreat_uniq( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)), 0 ))
1429 == (WORD
)HFILE_ERROR16
);
1432 case 0x5d: /* NETWORK */
1434 /* network software not installed */
1435 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1436 bSetDOSExtendedError
= TRUE
;
1439 case 0x5f: /* NETWORK */
1440 switch (AL_reg(context
))
1442 case 0x07: /* ENABLE DRIVE */
1443 if (!DRIVE_Enable( DL_reg(context
) ))
1445 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1446 bSetDOSExtendedError
= TRUE
;
1450 case 0x08: /* DISABLE DRIVE */
1451 if (!DRIVE_Disable( DL_reg(context
) ))
1453 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1454 bSetDOSExtendedError
= TRUE
;
1459 /* network software not installed */
1460 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1461 bSetDOSExtendedError
= TRUE
;
1466 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1468 if (!GetFullPathName32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1469 SI_reg(context
)), 128,
1470 PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1471 DI_reg(context
)),NULL
))
1472 bSetDOSExtendedError
= TRUE
;
1473 else AX_reg(context
) = 0;
1477 case 0x61: /* UNUSED */
1478 case 0x63: /* UNUSED */
1479 case 0x64: /* OS/2 DOS BOX */
1480 INT_BARF( context
, 0x21 );
1484 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1485 extern WORD WINE_LanguageId
;
1486 BYTE
*dataptr
=PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
));;
1487 switch (AL_reg(context
)) {
1490 *(WORD
*)(dataptr
+1) = 41;
1491 *(WORD
*)(dataptr
+3) = WINE_LanguageId
;
1492 *(WORD
*)(dataptr
+5) = CodePage
;
1496 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
1497 CX_reg(context
) = 258;/*FIXME: size of table?*/
1500 INT_BARF( context
, 0x21 );
1506 case 0x66: /* GLOBAL CODE PAGE TABLE */
1507 switch (AL_reg(context
))
1510 DX_reg(context
) = BX_reg(context
) = CodePage
;
1511 RESET_CFLAG(context
);
1514 CodePage
= BX_reg(context
);
1515 RESET_CFLAG(context
);
1520 case 0x67: /* SET HANDLE COUNT */
1521 SetHandleCount16( BX_reg(context
) );
1522 if (DOS_ExtendedError
) bSetDOSExtendedError
= TRUE
;
1525 case 0x68: /* "FFLUSH" - COMMIT FILE */
1526 case 0x6a: /* COMMIT FILE */
1527 bSetDOSExtendedError
= (!FlushFileBuffers( BX_reg(context
) ));
1530 case 0x69: /* DISK SERIAL NUMBER */
1531 switch (AL_reg(context
))
1534 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1535 else AX_reg(context
) = 0;
1539 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1540 else AX_reg(context
) = 1;
1545 case 0x6C: /* Extended Open/Create*/
1546 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
1549 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1550 switch(AL_reg(context
))
1552 case 0x39: /* Create directory */
1553 bSetDOSExtendedError
= (!CreateDirectory32A(
1554 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1555 DX_reg(context
) ), NULL
));
1557 case 0x3a: /* Remove directory */
1558 bSetDOSExtendedError
= (!RemoveDirectory32A(
1559 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1560 DX_reg(context
) )));
1562 case 0x43: /* Get/Set file attributes */
1563 switch (BL_reg(context
))
1565 case 0x00: /* Get file attributes */
1566 CX_reg(context
) = (WORD
)GetFileAttributes32A(
1567 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1569 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1572 bSetDOSExtendedError
= (!SetFileAttributes32A(
1573 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1575 CX_reg(context
) ) );
1579 "Unimplemented int21 long file name function:\n");
1580 INT_BARF( context
, 0x21 );
1582 AL_reg(context
) = 0;
1586 case 0x47: /* Get current directory */
1587 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1590 case 0x4e: /* Find first file */
1591 /* FIXME: use attributes in CX */
1592 if ((AX_reg(context
) = FindFirstFile16(
1593 PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
1594 (WIN32_FIND_DATA32A
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1596 == INVALID_HANDLE_VALUE16
)
1597 bSetDOSExtendedError
= TRUE
;
1599 case 0x4f: /* Find next file */
1600 if (!FindNextFile16( BX_reg(context
),
1601 (WIN32_FIND_DATA32A
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1603 bSetDOSExtendedError
= TRUE
;
1605 case 0xa1: /* Find close */
1606 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
1611 switch(CL_reg(context
))
1613 case 0x02: /*Get canonical long filename or path */
1614 if (!GetFullPathName32A
1615 ( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1616 SI_reg(context
)), 128,
1617 PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1618 DI_reg(context
)),NULL
))
1619 bSetDOSExtendedError
= TRUE
;
1620 else AX_reg(context
) = 0;
1624 "Unimplemented int21 long file name function:\n");
1625 INT_BARF( context
, 0x21 );
1627 AL_reg(context
) = 0;
1631 case 0x6c: /* Create or open file */
1632 /* translate Dos 7 action to Dos 6 action */
1633 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
1636 case 0x3b: /* Change directory */
1637 if (!SetCurrentDirectory32A(PTR_SEG_OFF_TO_LIN(
1643 AL_reg(context
) = DOS_ExtendedError
;
1646 case 0x41: /* Delete file */
1647 case 0x56: /* Move (rename) file */
1649 fprintf( stderr
, "Unimplemented int21 long file name function:\n");
1650 INT_BARF( context
, 0x21 );
1652 AL_reg(context
) = 0;
1657 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
1658 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
1659 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
1660 dprintf_int(stddeb
,"int21: windows95 function AX %04x\n",
1662 dprintf_int(stddeb
, " returning unimplemented\n");
1664 AL_reg(context
) = 0;
1667 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1668 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1672 INT_BARF( context
, 0x21 );
1675 } /* END OF SWITCH */
1677 if( bSetDOSExtendedError
) /* set general error condition */
1679 AX_reg(context
) = DOS_ExtendedError
;
1683 dprintf_int( stddeb
, "ret21: AX=%04x BX=%04x CX=%04x DX=%04x "
1684 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1685 AX_reg(context
), BX_reg(context
), CX_reg(context
),
1686 DX_reg(context
), SI_reg(context
), DI_reg(context
),
1687 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),