2 * (c) 1993, 1994 Erik Bos
14 #include <sys/types.h>
23 #include "registers.h"
31 #if defined(__svr4__) || defined(_SCO_DS)
32 /* SVR4 DOESNT do locking the same way must implement properly */
39 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
41 /* Define the drive parameter block, as used by int21/1F
42 * and int21/32. This table can be accessed through the
43 * global 'dpb' pointer, which points into the local dos
48 BYTE drive_num
; /* 0=A, etc. */
49 BYTE unit_num
; /* Drive's unit number (?) */
50 WORD sector_size
; /* Sector size in bytes */
51 BYTE high_sector
; /* Highest sector in a cluster */
52 BYTE shift
; /* Shift count (?) */
53 WORD reserved
; /* Number of reserved sectors at start */
54 BYTE num_FAT
; /* Number of FATs */
55 WORD dir_entries
; /* Number of root dir entries */
56 WORD first_data
; /* First data sector */
57 WORD high_cluster
; /* Highest cluster number */
58 WORD sectors_in_FAT
; /* Number of sectors per FAT */
59 WORD start_dir
; /* Starting sector of first dir */
60 DWORD driver_head
; /* Address of device driver header (?) */
61 BYTE media_ID
; /* Media ID */
62 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
63 DWORD next
; /* Pointer to next DPB in list */
64 WORD free_search
; /* Free cluster search start */
65 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
78 static struct DosHeap
*heap
;
79 static WORD DosHeapHandle
;
81 WORD sharing_retries
= 3; /* number of retries at sharing violation */
82 WORD sharing_pause
= 1; /* pause between retries */
84 extern char TempDirectory
[];
86 BYTE
*GetCurrentDTA(void)
88 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
89 return (BYTE
*)PTR_SEG_TO_LIN( pTask
->dta
);
93 void ChopOffWhiteSpace(char *string
)
97 for (length
= strlen(string
) ; length
; length
--)
98 if (string
[length
] == ' ')
99 string
[length
] = '\0';
102 static void CreateBPB(int drive
, BYTE
*data
)
107 setword(&data
[3], 0);
109 setword(&data
[6], 240);
110 setword(&data
[8], 64000);
112 setword(&data
[0x0b], 40);
113 setword(&data
[0x0d], 56);
114 setword(&data
[0x0f], 2);
115 setword(&data
[0x11], 0);
116 setword(&data
[0x1f], 800);
118 setword(&data
[0x22], 1);
119 } else { /* 1.44mb */
122 setword(&data
[3], 0);
124 setword(&data
[6], 240);
125 setword(&data
[8], 2880);
127 setword(&data
[0x0b], 6);
128 setword(&data
[0x0d], 18);
129 setword(&data
[0x0f], 2);
130 setword(&data
[0x11], 0);
131 setword(&data
[0x1f], 80);
133 setword(&data
[0x22], 2);
137 static int INT21_GetFreeDiskSpace( SIGCONTEXT
*context
)
139 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
140 char root
[] = "A:\\";
142 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
143 if (!GetDiskFreeSpace32A( root
, &cluster_sectors
, §or_bytes
,
144 &free_clusters
, &total_clusters
)) return 0;
145 AX_reg(context
) = cluster_sectors
;
146 BX_reg(context
) = free_clusters
;
147 CX_reg(context
) = sector_bytes
;
148 DX_reg(context
) = total_clusters
;
152 static int INT21_GetDriveAllocInfo( SIGCONTEXT
*context
)
154 if (!INT21_GetFreeDiskSpace( context
)) return 0;
155 heap
->mediaID
= 0xf0;
156 DS_reg(context
) = DosHeapHandle
;
157 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
161 static void GetDrivePB( SIGCONTEXT
*context
, int drive
)
163 if(!DRIVE_IsValid(drive
))
165 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
166 AX_reg(context
) = 0x00ff;
170 dprintf_int(stddeb
, "int21: GetDrivePB not fully implemented.\n");
172 /* FIXME: I have no idea what a lot of this information should
173 * say or whether it even really matters since we're not allowing
174 * direct block access. However, some programs seem to depend on
175 * getting at least _something_ back from here. The 'next' pointer
176 * does worry me, though. Should we have a complete table of
177 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
179 dpb
->drive_num
= dpb
->unit_num
= drive
; /* The same? */
180 dpb
->sector_size
= 512;
181 dpb
->high_sector
= 1;
182 dpb
->shift
= drive
< 2 ? 0 : 6; /* 6 for HD, 0 for floppy */
185 dpb
->dir_entries
= 2;
187 dpb
->high_cluster
= 64000;
188 dpb
->sectors_in_FAT
= 1;
190 dpb
->driver_head
= 0;
191 dpb
->media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
192 dpb
->access_flag
= 0;
194 dpb
->free_search
= 0;
195 dpb
->free_clusters
= 0xFFFF; /* unknown */
197 AL_reg(context
) = 0x00;
198 DS_reg(context
) = SELECTOROF(dpbsegptr
);
199 BX_reg(context
) = OFFSETOF(dpbsegptr
);
204 static void ioctlGetDeviceInfo( SIGCONTEXT
*context
)
206 dprintf_int (stddeb
, "int21: ioctl (%d, GetDeviceInfo)\n", BX_reg(context
));
208 DX_reg(context
) = 0x0942;
209 /* bits 0-5 are current drive
210 * bit 6 - file has NOT been written..FIXME: correct?
211 * bit 8 - generate int24 if no diskspace on write/ read past end of file
212 * bit 11 - media not removable
214 RESET_CFLAG(context
);
217 static void ioctlGenericBlkDevReq( SIGCONTEXT
*context
)
219 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
220 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
222 if (!DRIVE_IsValid(drive
))
224 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
225 AX_reg(context
) = DOS_ExtendedError
;
230 if (CH_reg(context
) != 0x08)
232 INT_BARF( context
, 0x21 );
235 switch (CL_reg(context
)) {
236 case 0x60: /* get device parameters */
237 /* used by w4wgrp's winfile */
238 memset(dataptr
, 0, 0x26);
240 dataptr
[6] = 0; /* media type */
243 dataptr
[1] = 0x05; /* fixed disk */
244 setword(&dataptr
[2], 0x01); /* non removable */
245 setword(&dataptr
[4], 0x300); /* # of cylinders */
249 dataptr
[1] = 0x07; /* block dev, floppy */
250 setword(&dataptr
[2], 0x02); /* removable */
251 setword(&dataptr
[4], 80); /* # of cylinders */
253 CreateBPB(drive
, &dataptr
[7]);
254 RESET_CFLAG(context
);
257 INT_BARF( context
, 0x21 );
261 static void GetSystemDate( SIGCONTEXT
*context
)
267 now
= localtime(<ime
);
269 CX_reg(context
) = now
->tm_year
+ 1900;
270 DX_reg(context
) = ((now
->tm_mon
+ 1) << 8) | now
->tm_mday
;
271 AX_reg(context
) = now
->tm_wday
;
274 static void INT21_GetSystemTime( SIGCONTEXT
*context
)
280 gettimeofday(&tv
,NULL
); /* Note use of gettimeofday(), instead of time() */
282 now
= localtime(&seconds
);
284 CX_reg(context
) = (now
->tm_hour
<<8) | now
->tm_min
;
285 DX_reg(context
) = (now
->tm_sec
<<8) | tv
.tv_usec
/10000;
286 /* Note hundredths of seconds */
289 static void CreateFile( SIGCONTEXT
*context
)
291 AX_reg(context
) = _lcreat( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
292 DX_reg(context
) ), CX_reg(context
) );
293 if (AX_reg(context
) == (WORD
)HFILE_ERROR
)
295 AX_reg(context
) = DOS_ExtendedError
;
301 void OpenExistingFile( SIGCONTEXT
*context
)
303 AX_reg(context
) = _lopen( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
305 if (AX_reg(context
) == (WORD
)HFILE_ERROR
)
307 AX_reg(context
) = DOS_ExtendedError
;
315 dprintf_int (stddeb
, "int21: open (%s, %d) = %d\n",
316 DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context
),
317 DX_reg(context
))), mode
, handle
);
319 switch (AX_reg(context
) & 0x0070)
321 case 0x00: /* compatability mode */
322 case 0x40: /* DENYNONE */
326 case 0x30: /* DENYREAD */
328 "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
329 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)));
330 case 0x10: /* DENYALL */
334 case 0x20: /* DENYWRITE */
345 int result
,retries
=sharing_retries
;
347 #if defined(__svr4__) || defined(_SCO_DS)
348 printf("Should call flock and needs porting to lockf\n");
352 result
= flock(handle
, lock
| LOCK_NB
);
354 if ( retries
&& (!result
) )
357 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
358 result
++; /* stop the optimizer */
359 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
363 while( (!result
) && (!(retries
--)) );
368 AX_reg(context
) = ExtendedError
;
377 AX_reg(context
) = handle
;
378 RESET_CFLAG(context
);
382 static void CloseFile( SIGCONTEXT
*context
)
384 if ((AX_reg(context
) = _lclose( BX_reg(context
) )) != 0)
386 AX_reg(context
) = DOS_ExtendedError
;
391 void ExtendedOpenCreateFile(SIGCONTEXT
*context
)
393 BYTE action
=DL_reg(context
);
394 dprintf_int(stddeb
, "int21: extended open/create: file= %s \n",
395 DOSFS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context
),SI_reg(context
)),FALSE
));
396 /* Shuffle arguments to call OpenExistingFile */
397 AL_reg(context
) = BL_reg(context
);
398 DX_reg(context
) = SI_reg(context
);
399 /* BX,CX and DX should be preserved */
400 OpenExistingFile(context
);
401 if ((EFL_reg(context
) & 0x0001)==0)
403 dprintf_int(stddeb
, "int21: extended open/create %s exists \n",
404 DOSFS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context
),SI_reg(context
)),TRUE
));
405 /* Now decide what do do */
406 if ((action
& 0x07)== 0)
408 BX_reg(context
) = AX_reg(context
);
410 AX_reg(context
) = 0x0050;/*File exists*/
413 dprintf_int(stddeb
, "int21: extended open/create: failed because file exixts \n");
416 if ((action
& 0x07)== 2) {
417 /* Truncate it, but first check if opend for write */
418 if ((BL_reg(context
) & 0x0007)== 0) {
419 BX_reg(context
) = AX_reg(context
);
421 dprintf_int(stddeb
, "int21: extended open/create: failed, trunc on ro file");
422 AX_reg(context
) = 0x000C;/*Access code invalid*/
427 /* Shuffle arguments to call CloseFile */
428 dprintf_int(stddeb
, "int21: extended open/create: Closing before truncate\n");
429 BX_reg(context
) = AX_reg(context
);
430 /* BX and DX should be preserved */
432 if (EFL_reg(context
) & 0x0001) {
433 dprintf_int(stddeb
, "int21: extended open/create: close before trunc failed");
434 AX_reg(context
) = 0x0019;/*Seek Error*/
438 /* Shuffle arguments to call CreateFile */
439 dprintf_int(stddeb
, "int21: extended open/create: Truncating\n");
440 AL_reg(context
) = BL_reg(context
);
441 /* CX is still the same */
442 DX_reg(context
) = SI_reg(context
);
444 if (EFL_reg(context
) & 0x0001) { /*no file open, flags set */
445 dprintf_int(stddeb
, "int21: extended open/create: truncfailed");
454 else /* file does not exist */
456 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
457 dprintf_int(stddeb
, "int21: extended open/create %s dosen't exists \n",
458 DOSFS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context
),SI_reg(context
)),FALSE
));
459 if ((action
& 0xF0)== 0) {
462 dprintf_int(stddeb
, "int21: extended open/create: failed, file dosen't exist\n");
465 /* Shuffle arguments to call CreateFile */
466 dprintf_int(stddeb
, "int21: extended open/create: Creating\n");
467 AL_reg(context
) = BL_reg(context
);
468 /* CX should still be the same */
469 DX_reg(context
) = SI_reg(context
);
471 if (EFL_reg(context
) & 0x0001) { /*no file open, flags set */
472 dprintf_int(stddeb
, "int21: extended open/create: create failed\n");
481 static int INT21_RenameFile( SIGCONTEXT
*context
)
483 const char *newname
, *oldname
;
486 /* FIXME: should not rename over an existing file */
487 dprintf_int(stddeb
,"int21: renaming %s to %s\n",
488 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
489 (char *)PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
)));
491 oldname
= DOSFS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
492 DX_reg(context
)), TRUE
);
493 if (!oldname
) return 0;
494 buffer
= xstrdup( oldname
);
495 newname
= DOSFS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(ES_reg(context
),
496 DI_reg(context
)), FALSE
);
503 if (rename( buffer
, newname
) == -1)
514 static void INT21_ChangeDir( SIGCONTEXT
*context
)
517 char *dirname
= PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
));
519 dprintf_int(stddeb
,"int21: changedir %s\n", dirname
);
520 if (dirname
[0] && (dirname
[1] == ':'))
522 drive
= toupper(dirname
[0]) - 'A';
525 else drive
= DRIVE_GetCurrentDrive();
526 if (!DRIVE_Chdir( drive
, dirname
))
528 AX_reg(context
) = DOS_ExtendedError
;
534 static int INT21_FindFirst( SIGCONTEXT
*context
)
536 const char *path
, *unixPath
, *mask
;
538 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
540 path
= (const char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
541 dta
->unixPath
= NULL
;
542 if (!(unixPath
= DOSFS_GetUnixFileName( path
, FALSE
)))
544 AX_reg(context
) = DOS_ExtendedError
;
548 dta
->unixPath
= xstrdup( unixPath
);
549 p
= strrchr( dta
->unixPath
, '/' );
551 if (!(mask
= DOSFS_ToDosFCBFormat( p
+ 1 )))
553 free( dta
->unixPath
);
554 dta
->unixPath
= NULL
;
555 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
556 AX_reg(context
) = ER_FileNotFound
;
560 memcpy( dta
->mask
, mask
, sizeof(dta
->mask
) );
561 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
562 : DRIVE_GetCurrentDrive();
564 dta
->search_attr
= CL_reg(context
);
569 static int INT21_FindNext( SIGCONTEXT
*context
)
571 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
575 if (!dta
->unixPath
) return 0;
576 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, dta
->drive
,
577 dta
->search_attr
, dta
->count
, &entry
)))
579 free( dta
->unixPath
);
580 dta
->unixPath
= NULL
;
583 if ((int)dta
->count
+ count
> 0xffff)
585 fprintf( stderr
, "Too many directory entries in %s\n", dta
->unixPath
);
586 free( dta
->unixPath
);
587 dta
->unixPath
= NULL
;
591 dta
->fileattr
= entry
.attr
;
592 dta
->filetime
= entry
.time
;
593 dta
->filedate
= entry
.date
;
594 dta
->filesize
= entry
.size
;
595 strcpy( dta
->filename
, DOSFS_ToDosDTAFormat( entry
.name
) );
600 static int INT21_CreateTempFile( SIGCONTEXT
*context
)
602 static int counter
= 0;
603 char *name
= PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
) );
604 char *p
= name
+ strlen(name
);
608 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
609 counter
= (counter
+ 1) % 1000;
611 if ((AX_reg(context
) = _lcreat_uniq( name
, 0 )) != (WORD
)HFILE_ERROR
)
613 dprintf_int( stddeb
, "INT21_CreateTempFile: created %s\n", name
);
616 if (DOS_ExtendedError
!= ER_FileExists
) return 0;
621 static int INT21_GetCurrentDirectory( SIGCONTEXT
*context
)
623 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
624 char *ptr
= (char *)PTR_SEG_OFF_TO_LIN( DS_reg(context
), SI_reg(context
) );
626 if (!DRIVE_IsValid(drive
))
628 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
632 lstrcpyn32A( ptr
, DRIVE_GetDosCwd(drive
), 64 );
633 if (!ptr
[0]) strcpy( ptr
, "\\" );
638 static int INT21_GetDiskSerialNumber( SIGCONTEXT
*context
)
640 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
641 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
643 if (!DRIVE_IsValid(drive
))
645 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
649 *(WORD
*)dataptr
= 0;
650 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
651 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
652 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
657 static int INT21_SetDiskSerialNumber( SIGCONTEXT
*context
)
659 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
660 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
662 if (!DRIVE_IsValid(drive
))
664 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
668 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
673 /* microsoft's programmers should be shot for using CP/M style int21
674 calls in Windows for Workgroup's winfile.exe */
676 static int INT21_FindFirstFCB( SIGCONTEXT
*context
)
678 BYTE
*fcb
= (BYTE
*)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
681 char buffer
[] = "A:.";
682 const char *unixPath
;
687 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
692 pFCB
= (FINDFILE_FCB
*)fcb
;
695 buffer
[0] += DOS_GET_DRIVE( pFCB
->drive
);
696 pFCB
->unixPath
= NULL
;
697 if (!(unixPath
= DOSFS_GetUnixFileName( buffer
, TRUE
))) return 0;
698 pFCB
->unixPath
= xstrdup( unixPath
);
704 static int INT21_FindNextFCB( SIGCONTEXT
*context
)
706 BYTE
*fcb
= (BYTE
*)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
708 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA();
716 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
721 pFCB
= (FINDFILE_FCB
*)fcb
;
724 if (!pFCB
->unixPath
) return 0;
725 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
,
726 DOS_GET_DRIVE( pFCB
->drive
), attr
,
727 pFCB
->count
, &entry
)))
729 free( pFCB
->unixPath
);
730 pFCB
->unixPath
= NULL
;
733 pFCB
->count
+= count
;
735 memcpy( pResult
->filename
, entry
.name
, sizeof(pResult
->filename
) );
736 pResult
->fileattr
= entry
.attr
;
737 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
738 pResult
->filetime
= entry
.time
;
739 pResult
->filedate
= entry
.date
;
740 pResult
->cluster
= 0; /* what else? */
741 pResult
->filesize
= entry
.size
;
746 static void DeleteFileFCB( SIGCONTEXT
*context
)
748 fprintf( stderr
, "DeleteFileFCB: not implemented yet\n" );
750 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
751 struct dosdirent
*dp
;
752 char temp
[256], *ptr
;
753 int drive
= DOS_GET_DRIVE( *fcb
);
758 strcpy(temp
+1, DRIVE_GetDosCwd(drive
));
760 strncat(temp
, fcb
+ 1, 8);
761 ChopOffWhiteSpace(temp
);
762 strncat(temp
, fcb
+ 9, 3);
763 ChopOffWhiteSpace(temp
);
765 if ((dp
= DOS_opendir(temp
)) == NULL
) {
766 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
767 AX_reg(context
) = 0xff;
772 strcpy(temp
+1, DRIVE_GetDosCwd(drive
) );
775 ptr
= temp
+ strlen(temp
);
777 while (DOS_readdir(dp
) != NULL
)
779 strcpy(ptr
, dp
->filename
);
780 dprintf_int(stddeb
, "int21: delete file %s\n", temp
);
781 /* unlink(DOS_GetUnixFileName(temp)); */
788 static void RenameFileFCB( SIGCONTEXT
*context
)
790 fprintf( stderr
, "RenameFileFCB: not implemented yet\n" );
792 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
793 struct dosdirent
*dp
;
794 char temp
[256], oldname
[256], newname
[256], *oldnameptr
, *newnameptr
;
795 int drive
= DOS_GET_DRIVE( *fcb
);
800 strcpy(temp
+1, DRIVE_GetDosCwd(drive
) );
802 strncat(temp
, fcb
+ 1, 8);
803 ChopOffWhiteSpace(temp
);
804 strncat(temp
, fcb
+ 9, 3);
805 ChopOffWhiteSpace(temp
);
807 if ((dp
= DOS_opendir(temp
)) == NULL
) {
808 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
809 AX_reg(context
) = 0xff;
814 strcpy(oldname
+1, DRIVE_GetDosCwd(drive
) );
815 strcat(oldname
, "\\");
816 strcpy( newname
, oldname
);
817 oldnameptr
= oldname
+ strlen(oldname
);
818 newnameptr
= newname
+ strlen(newname
);
820 while (DOS_readdir(dp
) != NULL
)
822 strcpy(oldnameptr
, dp
->filename
);
823 strcpy(newnameptr
, fcb
+ 1);
824 dprintf_int(stddeb
, "int21: renamefile %s -> %s\n",
834 static void fLock( SIGCONTEXT
* context
)
838 int result
,retries
=sharing_retries
;
840 f
.l_start
= MAKELONG(DX_reg(context
),CX_reg(context
));
841 f
.l_len
= MAKELONG(DI_reg(context
),SI_reg(context
));
845 switch ( AX_reg(context
) & 0xff )
847 case 0x00: /* LOCK */
851 case 0x01: /* UNLOCK */
856 AX_reg(context
) = 0x0001;
862 result
= fcntl(BX_reg(context
),F_SETLK
,&f
);
863 if ( retries
&& (!result
) )
866 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
867 result
++; /* stop the optimizer */
868 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
872 while( (!result
) && (!(retries
--)) );
877 AX_reg(context
) = DOS_ExtendedError
;
885 static int INT21_GetFileAttribute( SIGCONTEXT
* context
)
887 const char *unixName
;
889 unixName
= DOSFS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)), TRUE
);
890 if (!unixName
) return 0;
891 if (!FILE_Stat( unixName
, &CL_reg(context
), NULL
, NULL
, NULL
)) return 0;
893 dprintf_int( stddeb
, "INT21_GetFileAttributes(%s) = 0x%x\n",
894 unixName
, CX_reg(context
) );
899 extern void LOCAL_PrintHeap (WORD ds
);
901 /***********************************************************************
902 * DOS3Call (KERNEL.102)
904 void DOS3Call( SIGCONTEXT context
)
906 dprintf_int( stddeb
, "int21: AX=%04x BX=%04x CX=%04x DX=%04x "
907 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
908 AX_reg(&context
), BX_reg(&context
), CX_reg(&context
),
909 DX_reg(&context
), SI_reg(&context
), DI_reg(&context
),
910 DS_reg(&context
), ES_reg(&context
), EFL_reg(&context
));
912 if (AH_reg(&context
) == 0x59) /* Get extended error info */
914 AX_reg(&context
) = DOS_ExtendedError
;
915 BH_reg(&context
) = DOS_ErrorClass
;
916 BL_reg(&context
) = DOS_ErrorAction
;
917 CH_reg(&context
) = DOS_ErrorLocus
;
921 DOS_ERROR( 0, 0, 0, 0 );
922 RESET_CFLAG(&context
); /* Not sure if this is a good idea */
924 switch(AH_reg(&context
))
926 case 0x00: /* TERMINATE PROGRAM */
927 TASK_KillCurrentTask( 0 );
930 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
931 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
932 case 0x03: /* READ CHARACTER FROM STDAUX */
933 case 0x04: /* WRITE CHARACTER TO STDAUX */
934 case 0x05: /* WRITE CHARACTER TO PRINTER */
935 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
936 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
937 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
938 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
939 case 0x0a: /* BUFFERED INPUT */
940 case 0x0b: /* GET STDIN STATUS */
941 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
942 case 0x0f: /* OPEN FILE USING FCB */
943 case 0x10: /* CLOSE FILE USING FCB */
944 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
945 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
946 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
947 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
948 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
949 case 0x23: /* GET FILE SIZE FOR FCB */
950 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
951 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
952 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
953 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
954 case 0x29: /* PARSE FILENAME INTO FCB */
955 case 0x2e: /* SET VERIFY FLAG */
956 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
957 "SWITCHAR" - SET SWITCH CHARACTER
958 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
959 case 0x54: /* GET VERIFY FLAG */
960 INT_BARF( &context
, 0x21 );
963 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
967 case 0x6b: /* NULL FUNCTION */
968 AL_reg(&context
) = 0;
971 case 0x5c: /* "FLOCK" - RECORD LOCKING */
975 case 0x0d: /* DISK BUFFER FLUSH */
976 RESET_CFLAG(&context
); /* dos 6+ only */
979 case 0x0e: /* SELECT DEFAULT DRIVE */
980 DRIVE_SetCurrentDrive( DL_reg(&context
) );
981 AL_reg(&context
) = MAX_DOS_DRIVES
;
984 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
985 if (!INT21_FindFirstFCB(&context
))
987 AL_reg(&context
) = 0xff;
990 /* else fall through */
992 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
993 AL_reg(&context
) = INT21_FindNextFCB(&context
) ? 0x00 : 0xff;
996 case 0x13: /* DELETE FILE USING FCB */
997 DeleteFileFCB(&context
);
1000 case 0x17: /* RENAME FILE USING FCB */
1001 RenameFileFCB(&context
);
1004 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1005 AL_reg(&context
) = DRIVE_GetCurrentDrive();
1008 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1010 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1011 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(&context
),DX_reg(&context
));
1012 dprintf_int(stddeb
, "int21: Set DTA: %08lx\n", pTask
->dta
);
1016 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1017 DL_reg(&context
) = 0;
1018 if (!INT21_GetDriveAllocInfo(&context
)) AX_reg(&context
) = 0xffff;
1021 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1022 if (!INT21_GetDriveAllocInfo(&context
)) AX_reg(&context
) = 0xffff;
1025 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1026 GetDrivePB(&context
, DRIVE_GetCurrentDrive());
1029 case 0x25: /* SET INTERRUPT VECTOR */
1030 INT_SetHandler( AL_reg(&context
),
1031 PTR_SEG_OFF_TO_SEGPTR( DS_reg(&context
), DX_reg(&context
)));
1034 case 0x2a: /* GET SYSTEM DATE */
1035 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
) = 2;
1093 /* c: is Wine's bootdrive */
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 ES_reg(&context
) = DosHeapHandle
;
1109 BX_reg(&context
) = (int)&heap
->InDosFlag
- (int)heap
;
1112 case 0x35: /* GET INTERRUPT VECTOR */
1114 SEGPTR addr
= INT_GetHandler( AL_reg(&context
) );
1115 ES_reg(&context
) = SELECTOROF(addr
);
1116 BX_reg(&context
) = OFFSETOF(addr
);
1120 case 0x36: /* GET FREE DISK SPACE */
1121 if (!INT21_GetFreeDiskSpace(&context
)) AX_reg(&context
) = 0xffff;
1124 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1125 AX_reg(&context
) = 0x02; /* no country support available */
1126 SET_CFLAG(&context
);
1129 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1130 if (!CreateDirectory32A( PTR_SEG_OFF_TO_LIN( DS_reg(&context
),
1131 DX_reg(&context
) ), NULL
))
1133 AX_reg(&context
) = DOS_ExtendedError
;
1134 SET_CFLAG(&context
);
1138 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1139 if (!RemoveDirectory32A( PTR_SEG_OFF_TO_LIN( DS_reg(&context
),
1140 DX_reg(&context
) )))
1142 AX_reg(&context
) = DOS_ExtendedError
;
1143 SET_CFLAG(&context
);
1147 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1148 INT21_ChangeDir(&context
);
1151 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1152 AX_reg(&context
) = _lcreat( PTR_SEG_OFF_TO_LIN( DS_reg(&context
),
1153 DX_reg(&context
) ), CX_reg(&context
) );
1154 if (AX_reg(&context
) == (WORD
)HFILE_ERROR
)
1156 AX_reg(&context
) = DOS_ExtendedError
;
1157 SET_CFLAG(&context
);
1161 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1162 OpenExistingFile(&context
);
1165 case 0x3e: /* "CLOSE" - CLOSE FILE */
1166 if ((AX_reg(&context
) = _lclose( BX_reg(&context
) )) != 0)
1168 AX_reg(&context
) = DOS_ExtendedError
;
1169 SET_CFLAG(&context
);
1173 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1175 LONG result
= _hread( BX_reg(&context
),
1176 PTR_SEG_OFF_TO_SEGPTR( DS_reg(&context
),
1181 AX_reg(&context
) = DOS_ExtendedError
;
1182 SET_CFLAG(&context
);
1184 else AX_reg(&context
) = (WORD
)result
;
1188 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1190 LONG result
= _hwrite( BX_reg(&context
),
1191 PTR_SEG_OFF_TO_LIN( DS_reg(&context
),
1196 AX_reg(&context
) = DOS_ExtendedError
;
1197 SET_CFLAG(&context
);
1199 else AX_reg(&context
) = (WORD
)result
;
1203 case 0x41: /* "UNLINK" - DELETE FILE */
1204 if (!DeleteFile32A( PTR_SEG_OFF_TO_LIN( DS_reg(&context
),
1205 DX_reg(&context
) )))
1207 AX_reg(&context
) = DOS_ExtendedError
;
1208 SET_CFLAG(&context
);
1212 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1214 LONG status
= _llseek( BX_reg(&context
),
1215 MAKELONG(DX_reg(&context
),CX_reg(&context
)),
1217 if (status
== HFILE_ERROR
)
1219 AX_reg(&context
) = DOS_ExtendedError
;
1220 SET_CFLAG(&context
);
1223 AX_reg(&context
) = LOWORD(status
);
1224 DX_reg(&context
) = HIWORD(status
);
1228 case 0x43: /* FILE ATTRIBUTES */
1229 switch (AL_reg(&context
))
1232 if (!INT21_GetFileAttribute(&context
))
1234 AX_reg(&context
) = DOS_ExtendedError
;
1235 SET_CFLAG(&context
);
1239 RESET_CFLAG(&context
);
1244 case 0x44: /* IOCTL */
1245 switch (AL_reg(&context
))
1248 ioctlGetDeviceInfo(&context
);
1254 case 0x08: /* Check if drive is removable. */
1255 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(&context
) )))
1257 case DRIVE_CANNOTDETERMINE
:
1258 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1259 AX_reg(&context
) = ER_InvalidDrive
;
1260 SET_CFLAG(&context
);
1262 case DRIVE_REMOVABLE
:
1263 AX_reg(&context
) = 0; /* removable */
1266 AX_reg(&context
) = 1; /* not removable */
1271 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1272 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(&context
) )))
1274 case DRIVE_CANNOTDETERMINE
:
1275 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1276 AX_reg(&context
) = ER_InvalidDrive
;
1277 SET_CFLAG(&context
);
1280 DX_reg(&context
) = (1<<9) | (1<<12); /* remote */
1283 DX_reg(&context
) = 0; /* FIXME: use driver attr here */
1288 case 0x0a: /* check if handle (BX) is remote */
1289 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1292 DX_reg(&context
) = 0;
1295 case 0x0b: /* SET SHARING RETRY COUNT */
1296 if (!CX_reg(&context
))
1298 AX_reg(&context
) = 1;
1299 SET_CFLAG(&context
);
1302 sharing_pause
= CX_reg(&context
);
1303 if (!DX_reg(&context
))
1304 sharing_retries
= DX_reg(&context
);
1305 RESET_CFLAG(&context
);
1309 ioctlGenericBlkDevReq(&context
);
1312 case 0x0F: /* Set logical drive mapping */
1313 /* FIXME: Not implemented at the moment, always returns error
1315 INT_BARF( &context
, 0x21 );
1316 AX_reg(&context
) = 0x0001; /* invalid function */
1317 SET_CFLAG(&context
);
1321 INT_BARF( &context
, 0x21 );
1326 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1327 if ((AX_reg(&context
) = FILE_Dup(BX_reg(&context
))) == (WORD
)HFILE_ERROR
)
1329 AX_reg(&context
) = DOS_ExtendedError
;
1330 SET_CFLAG(&context
);
1334 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1335 if (FILE_Dup2( BX_reg(&context
), CX_reg(&context
) ) == HFILE_ERROR
)
1337 AX_reg(&context
) = DOS_ExtendedError
;
1338 SET_CFLAG(&context
);
1342 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1343 if (!INT21_GetCurrentDirectory(&context
))
1345 AX_reg(&context
) = DOS_ExtendedError
;
1346 SET_CFLAG(&context
);
1348 else AX_reg(&context
) = 0x0100;
1349 /* intlist: many Microsoft products for Windows rely on this */
1352 case 0x48: /* ALLOCATE MEMORY */
1353 case 0x49: /* FREE MEMORY */
1354 case 0x4a: /* RESIZE MEMORY BLOCK */
1355 INT_BARF( &context
, 0x21 );
1358 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1359 AX_reg(&context
) = WinExec( PTR_SEG_OFF_TO_LIN( DS_reg(&context
),
1362 if (AX_reg(&context
) < 32) SET_CFLAG(&context
);
1365 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1366 TASK_KillCurrentTask( AL_reg(&context
) );
1369 case 0x4d: /* GET RETURN CODE */
1370 AX_reg(&context
) = 0; /* normal exit */
1373 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1374 if (!INT21_FindFirst(&context
)) break;
1377 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1378 if (!INT21_FindNext(&context
))
1380 DOS_ERROR( ER_NoMoreFiles
, EC_MediaError
, SA_Abort
, EL_Disk
);
1381 AX_reg(&context
) = ER_NoMoreFiles
;
1382 SET_CFLAG(&context
);
1386 case 0x51: /* GET PSP ADDRESS */
1387 case 0x62: /* GET PSP ADDRESS */
1388 /* FIXME: should we return the original DOS PSP upon */
1389 /* Windows startup ? */
1390 BX_reg(&context
) = GetCurrentPDB();
1393 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1394 ES_reg(&context
) = 0x0;
1395 BX_reg(&context
) = 0x0;
1396 INT_BARF( &context
, 0x21 );
1399 case 0x56: /* "RENAME" - RENAME FILE */
1400 if (!INT21_RenameFile(&context
))
1402 AX_reg(&context
) = DOS_ExtendedError
;
1403 SET_CFLAG(&context
);
1407 case 0x57: /* FILE DATE AND TIME */
1408 switch (AL_reg(&context
))
1410 case 0x00: /* Get */
1411 if (!FILE_GetDateTime( BX_reg(&context
), &DX_reg(&context
),
1412 &CX_reg(&context
), TRUE
))
1414 AX_reg(&context
) = DOS_ExtendedError
;
1415 SET_CFLAG(&context
);
1419 case 0x01: /* Set */
1420 if (!FILE_SetDateTime( BX_reg(&context
), DX_reg(&context
),
1423 AX_reg(&context
) = DOS_ExtendedError
;
1424 SET_CFLAG(&context
);
1430 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1431 switch (AL_reg(&context
))
1434 AX_reg(&context
) = 1;
1437 AX_reg(&context
) = 0;
1443 RESET_CFLAG(&context
);
1446 case 0x5a: /* CREATE TEMPORARY FILE */
1447 if (!INT21_CreateTempFile(&context
))
1449 AX_reg(&context
) = DOS_ExtendedError
;
1450 SET_CFLAG(&context
);
1454 case 0x5b: /* CREATE NEW FILE */
1455 if ((AX_reg(&context
) = _lcreat_uniq( PTR_SEG_OFF_TO_LIN(DS_reg(&context
),DX_reg(&context
)), 0 )) == (WORD
)HFILE_ERROR
)
1457 AX_reg(&context
) = DOS_ExtendedError
;
1458 SET_CFLAG(&context
);
1462 case 0x5d: /* NETWORK */
1464 /* network software not installed */
1465 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1466 AX_reg(&context
) = DOS_ExtendedError
;
1467 SET_CFLAG(&context
);
1470 case 0x5f: /* NETWORK */
1471 switch (AL_reg(&context
))
1473 case 0x07: /* ENABLE DRIVE */
1474 if (!DRIVE_Enable( DL_reg(&context
) ))
1476 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1477 AX_reg(&context
) = DOS_ExtendedError
;
1478 SET_CFLAG(&context
);
1482 case 0x08: /* DISABLE DRIVE */
1483 if (!DRIVE_Disable( DL_reg(&context
) ))
1485 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1486 AX_reg(&context
) = DOS_ExtendedError
;
1487 SET_CFLAG(&context
);
1492 /* network software not installed */
1493 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1494 AX_reg(&context
) = DOS_ExtendedError
;
1495 SET_CFLAG(&context
);
1500 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1502 const char *truename
= DOSFS_GetDosTrueName( PTR_SEG_OFF_TO_LIN(DS_reg(&context
),SI_reg(&context
) ), FALSE
);
1505 AX_reg(&context
) = DOS_ExtendedError
;
1506 SET_CFLAG(&context
);
1510 lstrcpyn32A( PTR_SEG_OFF_TO_LIN( ES_reg(&context
),
1513 AX_reg(&context
) = 0;
1518 case 0x61: /* UNUSED */
1519 case 0x63: /* UNUSED */
1520 case 0x64: /* OS/2 DOS BOX */
1521 case 0x65: /* GET EXTENDED COUNTRY INFORMATION */
1522 INT_BARF( &context
, 0x21 );
1523 SET_CFLAG(&context
);
1526 case 0x66: /* GLOBAL CODE PAGE TABLE */
1527 switch (AL_reg(&context
))
1530 DX_reg(&context
) = BX_reg(&context
) = CodePage
;
1531 RESET_CFLAG(&context
);
1534 CodePage
= BX_reg(&context
);
1535 RESET_CFLAG(&context
);
1540 case 0x67: /* SET HANDLE COUNT */
1541 SetHandleCount( BX_reg(&context
) );
1542 if (DOS_ExtendedError
)
1544 AX_reg(&context
) = DOS_ExtendedError
;
1545 SET_CFLAG(&context
);
1549 case 0x68: /* "FFLUSH" - COMMIT FILE */
1550 case 0x6a: /* COMMIT FILE */
1551 if (!FlushFileBuffers( BX_reg(&context
) ))
1553 AX_reg(&context
) = DOS_ExtendedError
;
1554 SET_CFLAG(&context
);
1558 case 0x69: /* DISK SERIAL NUMBER */
1559 switch (AL_reg(&context
))
1562 if (!INT21_GetDiskSerialNumber(&context
))
1564 AX_reg(&context
) = DOS_ExtendedError
;
1565 SET_CFLAG(&context
);
1567 else AX_reg(&context
) = 0;
1570 if (!INT21_SetDiskSerialNumber(&context
))
1572 AX_reg(&context
) = DOS_ExtendedError
;
1573 SET_CFLAG(&context
);
1575 else AX_reg(&context
) = 1;
1580 case 0x6C: /* Extended Open/Create*/
1581 ExtendedOpenCreateFile(&context
);
1584 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
1585 case 0x71: /* MS-DOS 7 (Chicago) - LONG FILENAME FUNCTIONS */
1586 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
1587 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
1588 dprintf_int(stddeb
,"int21: windows95 function AX %04x\n",
1590 dprintf_int(stddeb
, " returning unimplemented\n");
1591 SET_CFLAG(&context
);
1592 AL_reg(&context
) = 0;
1595 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1596 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1600 INT_BARF( &context
, 0x21 );
1603 dprintf_int( stddeb
, "ret21: AX=%04x BX=%04x CX=%04x DX=%04x "
1604 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1605 AX_reg(&context
), BX_reg(&context
), CX_reg(&context
),
1606 DX_reg(&context
), SI_reg(&context
), DI_reg(&context
),
1607 DS_reg(&context
), ES_reg(&context
), EFL_reg(&context
));
1611 BOOL
INT21_Init(void)
1613 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
1615 fprintf( stderr
, "INT21_Init: Out of memory\n");
1618 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
1621 dpbsegptr
= PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
1622 heap
->InDosFlag
= 0;
1623 strcpy(heap
->biosdate
, "01/01/80");