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(struct sigcontext_struct
*context
)
139 DWORD size
, available
;
140 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
142 if (!DRIVE_GetFreeSpace(drive
, &size
, &available
)) return 0;
144 CX_reg(context
) = 512; /* bytes per sector */
147 AX_reg(context
) = 1; /* sectors per cluster */
148 while (AX_reg(context
) * 65530 < size
) AX_reg(context
) *= 2;
149 BX_reg(context
) = available
/ AX_reg(context
); /* free clusters */
150 DX_reg(context
) = size
/ AX_reg(context
); /* total clusters */
154 static int INT21_GetDriveAllocInfo(struct sigcontext_struct
*context
)
156 if (!INT21_GetFreeDiskSpace( context
)) return 0;
157 heap
->mediaID
= 0xf0;
158 DS_reg(context
) = DosHeapHandle
;
159 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
163 static void GetDrivePB(struct sigcontext_struct
*context
, int drive
)
165 if(!DRIVE_IsValid(drive
))
167 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
168 AX_reg(context
) = 0x00ff;
172 dprintf_int(stddeb
, "int21: GetDrivePB not fully implemented.\n");
174 /* FIXME: I have no idea what a lot of this information should
175 * say or whether it even really matters since we're not allowing
176 * direct block access. However, some programs seem to depend on
177 * getting at least _something_ back from here. The 'next' pointer
178 * does worry me, though. Should we have a complete table of
179 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
181 dpb
->drive_num
= dpb
->unit_num
= drive
; /* The same? */
182 dpb
->sector_size
= 512;
183 dpb
->high_sector
= 1;
184 dpb
->shift
= drive
< 2 ? 0 : 6; /* 6 for HD, 0 for floppy */
187 dpb
->dir_entries
= 2;
189 dpb
->high_cluster
= 64000;
190 dpb
->sectors_in_FAT
= 1;
192 dpb
->driver_head
= 0;
193 dpb
->media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
194 dpb
->access_flag
= 0;
196 dpb
->free_search
= 0;
197 dpb
->free_clusters
= 0xFFFF; /* unknown */
199 AL_reg(context
) = 0x00;
200 DS_reg(context
) = SELECTOROF(dpbsegptr
);
201 BX_reg(context
) = OFFSETOF(dpbsegptr
);
206 static void ioctlGetDeviceInfo(struct sigcontext_struct
*context
)
208 dprintf_int (stddeb
, "int21: ioctl (%d, GetDeviceInfo)\n", BX_reg(context
));
210 DX_reg(context
) = 0x0942;
211 /* bits 0-5 are current drive
212 * bit 6 - file has NOT been written..FIXME: correct?
213 * bit 8 - generate int24 if no diskspace on write/ read past end of file
214 * bit 11 - media not removable
216 RESET_CFLAG(context
);
219 static void ioctlGenericBlkDevReq(struct sigcontext_struct
*context
)
221 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
222 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
224 if (!DRIVE_IsValid(drive
))
226 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
227 AX_reg(context
) = DOS_ExtendedError
;
232 if (CH_reg(context
) != 0x08)
234 INT_BARF( context
, 0x21 );
237 switch (CL_reg(context
)) {
238 case 0x60: /* get device parameters */
239 /* used by w4wgrp's winfile */
240 memset(dataptr
, 0, 0x26);
242 dataptr
[6] = 0; /* media type */
245 dataptr
[1] = 0x05; /* fixed disk */
246 setword(&dataptr
[2], 0x01); /* non removable */
247 setword(&dataptr
[4], 0x300); /* # of cylinders */
251 dataptr
[1] = 0x07; /* block dev, floppy */
252 setword(&dataptr
[2], 0x02); /* removable */
253 setword(&dataptr
[4], 80); /* # of cylinders */
255 CreateBPB(drive
, &dataptr
[7]);
256 RESET_CFLAG(context
);
259 INT_BARF( context
, 0x21 );
263 static void GetSystemDate(struct sigcontext_struct
*context
)
269 now
= localtime(<ime
);
271 CX_reg(context
) = now
->tm_year
+ 1900;
272 DX_reg(context
) = ((now
->tm_mon
+ 1) << 8) | now
->tm_mday
;
273 AX_reg(context
) = now
->tm_wday
;
276 static void INT21_GetSystemTime(struct sigcontext_struct
*context
)
282 gettimeofday(&tv
,NULL
); /* Note use of gettimeofday(), instead of time() */
284 now
= localtime(&seconds
);
286 CX_reg(context
) = (now
->tm_hour
<<8) | now
->tm_min
;
287 DX_reg(context
) = (now
->tm_sec
<<8) | tv
.tv_usec
/10000;
288 /* Note hundredths of seconds */
291 static void CreateFile(struct sigcontext_struct
*context
)
293 AX_reg(context
) = _lcreat( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
294 DX_reg(context
) ), CX_reg(context
) );
295 if (AX_reg(context
) == (WORD
)HFILE_ERROR
)
297 AX_reg(context
) = DOS_ExtendedError
;
303 void OpenExistingFile(struct sigcontext_struct
*context
)
305 AX_reg(context
) = _lopen( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
307 if (AX_reg(context
) == (WORD
)HFILE_ERROR
)
309 AX_reg(context
) = DOS_ExtendedError
;
317 dprintf_int (stddeb
, "int21: open (%s, %d) = %d\n",
318 DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context
),
319 DX_reg(context
))), mode
, handle
);
321 switch (AX_reg(context
) & 0x0070)
323 case 0x00: /* compatability mode */
324 case 0x40: /* DENYNONE */
328 case 0x30: /* DENYREAD */
330 "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
331 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)));
332 case 0x10: /* DENYALL */
336 case 0x20: /* DENYWRITE */
347 int result
,retries
=sharing_retries
;
349 #if defined(__svr4__) || defined(_SCO_DS)
350 printf("Should call flock and needs porting to lockf\n");
354 result
= flock(handle
, lock
| LOCK_NB
);
356 if ( retries
&& (!result
) )
359 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
360 result
++; /* stop the optimizer */
361 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
365 while( (!result
) && (!(retries
--)) );
370 AX_reg(context
) = ExtendedError
;
379 AX_reg(context
) = handle
;
380 RESET_CFLAG(context
);
384 static void CloseFile(struct sigcontext_struct
*context
)
386 if ((AX_reg(context
) = _lclose( BX_reg(context
) )) != 0)
388 AX_reg(context
) = DOS_ExtendedError
;
393 void ExtendedOpenCreateFile(struct sigcontext_struct
*context
)
395 BYTE action
=DL_reg(context
);
396 dprintf_int(stddeb
, "int21: extended open/create: file= %s \n",
397 DOSFS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context
),SI_reg(context
)),FALSE
));
398 /* Shuffle arguments to call OpenExistingFile */
399 AL_reg(context
) = BL_reg(context
);
400 DX_reg(context
) = SI_reg(context
);
401 /* BX,CX and DX should be preserved */
402 OpenExistingFile(context
);
403 if ((EFL_reg(context
) & 0x0001)==0)
405 dprintf_int(stddeb
, "int21: extended open/create %s exists \n",
406 DOSFS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context
),SI_reg(context
)),TRUE
));
407 /* Now decide what do do */
408 if ((action
& 0x07)== 0)
410 BX_reg(context
) = AX_reg(context
);
412 AX_reg(context
) = 0x0050;/*File exists*/
415 dprintf_int(stddeb
, "int21: extended open/create: failed because file exixts \n");
418 if ((action
& 0x07)== 2) {
419 /* Truncate it, but first check if opend for write */
420 if ((BL_reg(context
) & 0x0007)== 0) {
421 BX_reg(context
) = AX_reg(context
);
423 dprintf_int(stddeb
, "int21: extended open/create: failed, trunc on ro file");
424 AX_reg(context
) = 0x000C;/*Access code invalid*/
429 /* Shuffle arguments to call CloseFile */
430 dprintf_int(stddeb
, "int21: extended open/create: Closing before truncate\n");
431 BX_reg(context
) = AX_reg(context
);
432 /* BX and DX should be preserved */
434 if (EFL_reg(context
) & 0x0001) {
435 dprintf_int(stddeb
, "int21: extended open/create: close before trunc failed");
436 AX_reg(context
) = 0x0019;/*Seek Error*/
440 /* Shuffle arguments to call CreateFile */
441 dprintf_int(stddeb
, "int21: extended open/create: Truncating\n");
442 AL_reg(context
) = BL_reg(context
);
443 /* CX is still the same */
444 DX_reg(context
) = SI_reg(context
);
446 if (EFL_reg(context
) & 0x0001) { /*no file open, flags set */
447 dprintf_int(stddeb
, "int21: extended open/create: truncfailed");
456 else /* file does not exist */
458 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
459 dprintf_int(stddeb
, "int21: extended open/create %s dosen't exists \n",
460 DOSFS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context
),SI_reg(context
)),FALSE
));
461 if ((action
& 0xF0)== 0) {
464 dprintf_int(stddeb
, "int21: extended open/create: failed, file dosen't exist\n");
467 /* Shuffle arguments to call CreateFile */
468 dprintf_int(stddeb
, "int21: extended open/create: Creating\n");
469 AL_reg(context
) = BL_reg(context
);
470 /* CX should still be the same */
471 DX_reg(context
) = SI_reg(context
);
473 if (EFL_reg(context
) & 0x0001) { /*no file open, flags set */
474 dprintf_int(stddeb
, "int21: extended open/create: create failed\n");
483 static int INT21_RenameFile(struct sigcontext_struct
*context
)
485 const char *newname
, *oldname
;
488 /* FIXME: should not rename over an existing file */
489 dprintf_int(stddeb
,"int21: renaming %s to %s\n",
490 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
491 (char *)PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
)));
493 oldname
= DOSFS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
494 DX_reg(context
)), TRUE
);
495 if (!oldname
) return 0;
496 buffer
= xstrdup( oldname
);
497 newname
= DOSFS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(ES_reg(context
),
498 DI_reg(context
)), FALSE
);
505 if (rename( buffer
, newname
) == -1)
516 static void INT21_ChangeDir(struct sigcontext_struct
*context
)
519 char *dirname
= PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
));
521 dprintf_int(stddeb
,"int21: changedir %s\n", dirname
);
522 if (dirname
[0] && (dirname
[1] == ':'))
524 drive
= toupper(dirname
[0]) - 'A';
527 else drive
= DRIVE_GetCurrentDrive();
528 if (!DRIVE_Chdir( drive
, dirname
))
530 AX_reg(context
) = DOS_ExtendedError
;
536 static int INT21_FindFirst(struct sigcontext_struct
*context
)
538 const char *path
, *unixPath
, *mask
;
540 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
542 path
= (const char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
543 dta
->unixPath
= NULL
;
544 if (!(unixPath
= DOSFS_GetUnixFileName( path
, FALSE
)))
546 AX_reg(context
) = DOS_ExtendedError
;
550 dta
->unixPath
= xstrdup( unixPath
);
551 p
= strrchr( dta
->unixPath
, '/' );
553 if (!(mask
= DOSFS_ToDosFCBFormat( p
+ 1 )))
555 free( dta
->unixPath
);
556 dta
->unixPath
= NULL
;
557 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
558 AX_reg(context
) = ER_FileNotFound
;
562 memcpy( dta
->mask
, mask
, sizeof(dta
->mask
) );
563 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
564 : DRIVE_GetCurrentDrive();
566 dta
->search_attr
= CL_reg(context
);
571 static int INT21_FindNext(struct sigcontext_struct
*context
)
573 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
577 if (!dta
->unixPath
) return 0;
578 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, dta
->drive
,
579 dta
->search_attr
, dta
->count
, &entry
)))
581 free( dta
->unixPath
);
582 dta
->unixPath
= NULL
;
585 if ((int)dta
->count
+ count
> 0xffff)
587 fprintf( stderr
, "Too many directory entries in %s\n", dta
->unixPath
);
588 free( dta
->unixPath
);
589 dta
->unixPath
= NULL
;
593 dta
->fileattr
= entry
.attr
;
594 dta
->filetime
= entry
.time
;
595 dta
->filedate
= entry
.date
;
596 dta
->filesize
= entry
.size
;
597 strcpy( dta
->filename
, DOSFS_ToDosDTAFormat( entry
.name
) );
602 static int INT21_CreateTempFile(struct sigcontext_struct
*context
)
604 static int counter
= 0;
605 char *name
= PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
) );
606 char *p
= name
+ strlen(name
);
610 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
611 counter
= (counter
+ 1) % 1000;
613 if ((AX_reg(context
) = _lcreat_uniq( name
, 0 )) != (WORD
)HFILE_ERROR
)
615 dprintf_int( stddeb
, "INT21_CreateTempFile: created %s\n", name
);
618 if (DOS_ExtendedError
!= ER_FileExists
) return 0;
623 static int INT21_GetCurrentDirectory(struct sigcontext_struct
*context
)
625 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
626 char *ptr
= (char *)PTR_SEG_OFF_TO_LIN( DS_reg(context
), SI_reg(context
) );
628 if (!DRIVE_IsValid(drive
))
630 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
634 lstrcpyn32A( ptr
, DRIVE_GetDosCwd(drive
), 64 );
635 if (!ptr
[0]) strcpy( ptr
, "\\" );
640 static int INT21_GetDiskSerialNumber(struct sigcontext_struct
*context
)
642 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
643 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
645 if (!DRIVE_IsValid(drive
))
647 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
651 *(WORD
*)dataptr
= 0;
652 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
653 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
654 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
659 static int INT21_SetDiskSerialNumber(struct sigcontext_struct
*context
)
661 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
662 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
664 if (!DRIVE_IsValid(drive
))
666 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
670 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
675 /* microsoft's programmers should be shot for using CP/M style int21
676 calls in Windows for Workgroup's winfile.exe */
678 static int INT21_FindFirstFCB( struct sigcontext_struct
*context
)
680 BYTE
*fcb
= (BYTE
*)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
683 char buffer
[] = "A:.";
684 const char *unixPath
;
689 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
694 pFCB
= (FINDFILE_FCB
*)fcb
;
697 buffer
[0] += DOS_GET_DRIVE( pFCB
->drive
);
698 pFCB
->unixPath
= NULL
;
699 if (!(unixPath
= DOSFS_GetUnixFileName( buffer
, TRUE
))) return 0;
700 pFCB
->unixPath
= xstrdup( unixPath
);
706 static int INT21_FindNextFCB( struct sigcontext_struct
*context
)
708 BYTE
*fcb
= (BYTE
*)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
710 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA();
718 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
723 pFCB
= (FINDFILE_FCB
*)fcb
;
726 if (!pFCB
->unixPath
) return 0;
727 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
,
728 DOS_GET_DRIVE( pFCB
->drive
), attr
,
729 pFCB
->count
, &entry
)))
731 free( pFCB
->unixPath
);
732 pFCB
->unixPath
= NULL
;
735 pFCB
->count
+= count
;
737 memcpy( pResult
->filename
, entry
.name
, sizeof(pResult
->filename
) );
738 pResult
->fileattr
= entry
.attr
;
739 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
740 pResult
->filetime
= entry
.time
;
741 pResult
->filedate
= entry
.date
;
742 pResult
->cluster
= 0; /* what else? */
743 pResult
->filesize
= entry
.size
;
748 static void DeleteFileFCB(struct sigcontext_struct
*context
)
750 fprintf( stderr
, "DeleteFileFCB: not implemented yet\n" );
752 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
753 struct dosdirent
*dp
;
754 char temp
[256], *ptr
;
755 int drive
= DOS_GET_DRIVE( *fcb
);
760 strcpy(temp
+1, DRIVE_GetDosCwd(drive
));
762 strncat(temp
, fcb
+ 1, 8);
763 ChopOffWhiteSpace(temp
);
764 strncat(temp
, fcb
+ 9, 3);
765 ChopOffWhiteSpace(temp
);
767 if ((dp
= DOS_opendir(temp
)) == NULL
) {
768 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
769 AX_reg(context
) = 0xff;
774 strcpy(temp
+1, DRIVE_GetDosCwd(drive
) );
777 ptr
= temp
+ strlen(temp
);
779 while (DOS_readdir(dp
) != NULL
)
781 strcpy(ptr
, dp
->filename
);
782 dprintf_int(stddeb
, "int21: delete file %s\n", temp
);
783 /* unlink(DOS_GetUnixFileName(temp)); */
790 static void RenameFileFCB(struct sigcontext_struct
*context
)
792 fprintf( stderr
, "RenameFileFCB: not implemented yet\n" );
794 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
795 struct dosdirent
*dp
;
796 char temp
[256], oldname
[256], newname
[256], *oldnameptr
, *newnameptr
;
797 int drive
= DOS_GET_DRIVE( *fcb
);
802 strcpy(temp
+1, DRIVE_GetDosCwd(drive
) );
804 strncat(temp
, fcb
+ 1, 8);
805 ChopOffWhiteSpace(temp
);
806 strncat(temp
, fcb
+ 9, 3);
807 ChopOffWhiteSpace(temp
);
809 if ((dp
= DOS_opendir(temp
)) == NULL
) {
810 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
811 AX_reg(context
) = 0xff;
816 strcpy(oldname
+1, DRIVE_GetDosCwd(drive
) );
817 strcat(oldname
, "\\");
818 strcpy( newname
, oldname
);
819 oldnameptr
= oldname
+ strlen(oldname
);
820 newnameptr
= newname
+ strlen(newname
);
822 while (DOS_readdir(dp
) != NULL
)
824 strcpy(oldnameptr
, dp
->filename
);
825 strcpy(newnameptr
, fcb
+ 1);
826 dprintf_int(stddeb
, "int21: renamefile %s -> %s\n",
836 static void fLock (struct sigcontext_struct
* context
)
840 int result
,retries
=sharing_retries
;
842 f
.l_start
= MAKELONG(DX_reg(context
),CX_reg(context
));
843 f
.l_len
= MAKELONG(DI_reg(context
),SI_reg(context
));
847 switch ( AX_reg(context
) & 0xff )
849 case 0x00: /* LOCK */
853 case 0x01: /* UNLOCK */
858 AX_reg(context
) = 0x0001;
864 result
= fcntl(BX_reg(context
),F_SETLK
,&f
);
865 if ( retries
&& (!result
) )
868 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
869 result
++; /* stop the optimizer */
870 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
874 while( (!result
) && (!(retries
--)) );
879 AX_reg(context
) = DOS_ExtendedError
;
887 static int INT21_GetFileAttribute (struct sigcontext_struct
* context
)
889 const char *unixName
;
891 unixName
= DOSFS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)), TRUE
);
892 if (!unixName
) return 0;
893 if (!FILE_Stat( unixName
, &CL_reg(context
), NULL
, NULL
, NULL
)) return 0;
895 dprintf_int( stddeb
, "INT21_GetFileAttributes(%s) = 0x%x\n",
896 unixName
, CX_reg(context
) );
901 extern void LOCAL_PrintHeap (WORD ds
);
903 /***********************************************************************
904 * DOS3Call (KERNEL.102)
906 void DOS3Call( struct sigcontext_struct context
)
908 dprintf_int( stddeb
, "int21: AX=%04x BX=%04x CX=%04x DX=%04x "
909 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
910 AX_reg(&context
), BX_reg(&context
), CX_reg(&context
),
911 DX_reg(&context
), SI_reg(&context
), DI_reg(&context
),
912 DS_reg(&context
), ES_reg(&context
), EFL_reg(&context
));
914 if (AH_reg(&context
) == 0x59) /* Get extended error info */
916 AX_reg(&context
) = DOS_ExtendedError
;
917 BH_reg(&context
) = DOS_ErrorClass
;
918 BL_reg(&context
) = DOS_ErrorAction
;
919 CH_reg(&context
) = DOS_ErrorLocus
;
923 DOS_ERROR( 0, 0, 0, 0 );
924 RESET_CFLAG(&context
); /* Not sure if this is a good idea */
926 switch(AH_reg(&context
))
928 case 0x00: /* TERMINATE PROGRAM */
929 TASK_KillCurrentTask( 0 );
932 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
933 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
934 case 0x03: /* READ CHARACTER FROM STDAUX */
935 case 0x04: /* WRITE CHARACTER TO STDAUX */
936 case 0x05: /* WRITE CHARACTER TO PRINTER */
937 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
938 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
939 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
940 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
941 case 0x0a: /* BUFFERED INPUT */
942 case 0x0b: /* GET STDIN STATUS */
943 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
944 case 0x0f: /* OPEN FILE USING FCB */
945 case 0x10: /* CLOSE FILE USING FCB */
946 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
947 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
948 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
949 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
950 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
951 case 0x23: /* GET FILE SIZE FOR FCB */
952 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
953 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
954 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
955 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
956 case 0x29: /* PARSE FILENAME INTO FCB */
957 case 0x2e: /* SET VERIFY FLAG */
958 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
959 "SWITCHAR" - SET SWITCH CHARACTER
960 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
961 case 0x54: /* GET VERIFY FLAG */
962 INT_BARF( &context
, 0x21 );
965 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
969 case 0x6b: /* NULL FUNCTION */
970 AL_reg(&context
) = 0;
973 case 0x5c: /* "FLOCK" - RECORD LOCKING */
977 case 0x0d: /* DISK BUFFER FLUSH */
978 RESET_CFLAG(&context
); /* dos 6+ only */
981 case 0x0e: /* SELECT DEFAULT DRIVE */
982 DRIVE_SetCurrentDrive( DL_reg(&context
) );
983 AL_reg(&context
) = MAX_DOS_DRIVES
;
986 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
987 if (!INT21_FindFirstFCB(&context
))
989 AL_reg(&context
) = 0xff;
992 /* else fall through */
994 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
995 AL_reg(&context
) = INT21_FindNextFCB(&context
) ? 0x00 : 0xff;
998 case 0x13: /* DELETE FILE USING FCB */
999 DeleteFileFCB(&context
);
1002 case 0x17: /* RENAME FILE USING FCB */
1003 RenameFileFCB(&context
);
1006 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1007 AL_reg(&context
) = DRIVE_GetCurrentDrive();
1010 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1012 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1013 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(&context
),DX_reg(&context
));
1014 dprintf_int(stddeb
, "int21: Set DTA: %08lx\n", pTask
->dta
);
1018 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1019 DL_reg(&context
) = 0;
1020 if (!INT21_GetDriveAllocInfo(&context
)) AX_reg(&context
) = 0xffff;
1023 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1024 if (!INT21_GetDriveAllocInfo(&context
)) AX_reg(&context
) = 0xffff;
1027 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1028 GetDrivePB(&context
, DRIVE_GetCurrentDrive());
1031 case 0x25: /* SET INTERRUPT VECTOR */
1032 INT_SetHandler( AL_reg(&context
),
1033 PTR_SEG_OFF_TO_SEGPTR( DS_reg(&context
), DX_reg(&context
)));
1036 case 0x2a: /* GET SYSTEM DATE */
1037 GetSystemDate(&context
);
1040 case 0x2b: /* SET SYSTEM DATE */
1041 fprintf( stdnimp
, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1042 DL_reg(&context
), DH_reg(&context
), CX_reg(&context
) );
1043 AL_reg(&context
) = 0; /* Let's pretend we succeeded */
1046 case 0x2c: /* GET SYSTEM TIME */
1047 INT21_GetSystemTime(&context
);
1050 case 0x2d: /* SET SYSTEM TIME */
1051 fprintf( stdnimp
, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1052 CH_reg(&context
), CL_reg(&context
),
1053 DH_reg(&context
), DL_reg(&context
) );
1054 AL_reg(&context
) = 0; /* Let's pretend we succeeded */
1057 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1059 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1060 ES_reg(&context
) = SELECTOROF( pTask
->dta
);
1061 BX_reg(&context
) = OFFSETOF( pTask
->dta
);
1065 case 0x30: /* GET DOS VERSION */
1066 AX_reg(&context
) = DOSVERSION
;
1067 BX_reg(&context
) = 0x0012; /* 0x123456 is Wine's serial # */
1068 CX_reg(&context
) = 0x3456;
1071 case 0x31: /* TERMINATE AND STAY RESIDENT */
1072 INT_BARF( &context
, 0x21 );
1075 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1076 GetDrivePB(&context
, DOS_GET_DRIVE( DL_reg(&context
) ) );
1079 case 0x33: /* MULTIPLEXED */
1080 switch (AL_reg(&context
))
1082 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1083 DL_reg(&context
) = 0;
1086 case 0x01: /* SET EXTENDED BREAK STATE */
1089 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1090 DL_reg(&context
) = 0;
1093 case 0x05: /* GET BOOT DRIVE */
1094 DL_reg(&context
) = 2;
1095 /* c: is Wine's bootdrive */
1098 case 0x06: /* GET TRUE VERSION NUMBER */
1099 BX_reg(&context
) = DOSVERSION
;
1100 DX_reg(&context
) = 0x00;
1104 INT_BARF( &context
, 0x21 );
1109 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1110 ES_reg(&context
) = DosHeapHandle
;
1111 BX_reg(&context
) = (int)&heap
->InDosFlag
- (int)heap
;
1114 case 0x35: /* GET INTERRUPT VECTOR */
1116 SEGPTR addr
= INT_GetHandler( AL_reg(&context
) );
1117 ES_reg(&context
) = SELECTOROF(addr
);
1118 BX_reg(&context
) = OFFSETOF(addr
);
1122 case 0x36: /* GET FREE DISK SPACE */
1123 if (!INT21_GetFreeDiskSpace(&context
)) AX_reg(&context
) = 0xffff;
1126 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1127 AX_reg(&context
) = 0x02; /* no country support available */
1128 SET_CFLAG(&context
);
1131 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1132 if (!FILE_MakeDir( PTR_SEG_OFF_TO_LIN( DS_reg(&context
),
1133 DX_reg(&context
) )))
1135 AX_reg(&context
) = DOS_ExtendedError
;
1136 SET_CFLAG(&context
);
1140 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1141 if (!FILE_RemoveDir( PTR_SEG_OFF_TO_LIN( DS_reg(&context
),
1142 DX_reg(&context
) )))
1144 AX_reg(&context
) = DOS_ExtendedError
;
1145 SET_CFLAG(&context
);
1149 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1150 INT21_ChangeDir(&context
);
1153 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1154 AX_reg(&context
) = _lcreat( PTR_SEG_OFF_TO_LIN( DS_reg(&context
),
1155 DX_reg(&context
) ), CX_reg(&context
) );
1156 if (AX_reg(&context
) == (WORD
)HFILE_ERROR
)
1158 AX_reg(&context
) = DOS_ExtendedError
;
1159 SET_CFLAG(&context
);
1163 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1164 OpenExistingFile(&context
);
1167 case 0x3e: /* "CLOSE" - CLOSE FILE */
1168 if ((AX_reg(&context
) = _lclose( BX_reg(&context
) )) != 0)
1170 AX_reg(&context
) = DOS_ExtendedError
;
1171 SET_CFLAG(&context
);
1175 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1177 LONG result
= _hread( BX_reg(&context
),
1178 PTR_SEG_OFF_TO_SEGPTR( DS_reg(&context
),
1183 AX_reg(&context
) = DOS_ExtendedError
;
1184 SET_CFLAG(&context
);
1186 else AX_reg(&context
) = (WORD
)result
;
1190 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1192 LONG result
= _hwrite( BX_reg(&context
),
1193 PTR_SEG_OFF_TO_LIN( DS_reg(&context
),
1198 AX_reg(&context
) = DOS_ExtendedError
;
1199 SET_CFLAG(&context
);
1201 else AX_reg(&context
) = (WORD
)result
;
1205 case 0x41: /* "UNLINK" - DELETE FILE */
1206 if (!FILE_Unlink( PTR_SEG_OFF_TO_LIN( DS_reg(&context
),
1207 DX_reg(&context
) )))
1209 AX_reg(&context
) = DOS_ExtendedError
;
1210 SET_CFLAG(&context
);
1214 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1216 LONG status
= _llseek( BX_reg(&context
),
1217 MAKELONG(DX_reg(&context
),CX_reg(&context
)),
1219 if (status
== HFILE_ERROR
)
1221 AX_reg(&context
) = DOS_ExtendedError
;
1222 SET_CFLAG(&context
);
1225 AX_reg(&context
) = LOWORD(status
);
1226 DX_reg(&context
) = HIWORD(status
);
1230 case 0x43: /* FILE ATTRIBUTES */
1231 switch (AL_reg(&context
))
1234 if (!INT21_GetFileAttribute(&context
))
1236 AX_reg(&context
) = DOS_ExtendedError
;
1237 SET_CFLAG(&context
);
1241 RESET_CFLAG(&context
);
1246 case 0x44: /* IOCTL */
1247 switch (AL_reg(&context
))
1250 ioctlGetDeviceInfo(&context
);
1256 case 0x08: /* Check if drive is removable. */
1257 switch(GetDriveType( DOS_GET_DRIVE( BL_reg(&context
) )))
1259 case DRIVE_CANNOTDETERMINE
:
1260 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1261 AX_reg(&context
) = ER_InvalidDrive
;
1262 SET_CFLAG(&context
);
1264 case DRIVE_REMOVABLE
:
1265 AX_reg(&context
) = 0; /* removable */
1268 AX_reg(&context
) = 1; /* not removable */
1273 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1274 switch(GetDriveType( DOS_GET_DRIVE( BL_reg(&context
) )))
1276 case DRIVE_CANNOTDETERMINE
:
1277 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1278 AX_reg(&context
) = ER_InvalidDrive
;
1279 SET_CFLAG(&context
);
1282 DX_reg(&context
) = (1<<9) | (1<<12); /* remote */
1285 DX_reg(&context
) = 0; /* FIXME: use driver attr here */
1290 case 0x0a: /* check if handle (BX) is remote */
1291 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1294 DX_reg(&context
) = 0;
1297 case 0x0b: /* SET SHARING RETRY COUNT */
1298 if (!CX_reg(&context
))
1300 AX_reg(&context
) = 1;
1301 SET_CFLAG(&context
);
1304 sharing_pause
= CX_reg(&context
);
1305 if (!DX_reg(&context
))
1306 sharing_retries
= DX_reg(&context
);
1307 RESET_CFLAG(&context
);
1311 ioctlGenericBlkDevReq(&context
);
1314 case 0x0F: /* Set logical drive mapping */
1315 /* FIXME: Not implemented at the moment, always returns error
1317 INT_BARF( &context
, 0x21 );
1318 AX_reg(&context
) = 0x0001; /* invalid function */
1319 SET_CFLAG(&context
);
1323 INT_BARF( &context
, 0x21 );
1328 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1329 if ((AX_reg(&context
) = FILE_Dup(BX_reg(&context
))) == (WORD
)HFILE_ERROR
)
1331 AX_reg(&context
) = DOS_ExtendedError
;
1332 SET_CFLAG(&context
);
1336 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1337 if (FILE_Dup2( BX_reg(&context
), CX_reg(&context
) ) == HFILE_ERROR
)
1339 AX_reg(&context
) = DOS_ExtendedError
;
1340 SET_CFLAG(&context
);
1344 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1345 if (!INT21_GetCurrentDirectory(&context
))
1347 AX_reg(&context
) = DOS_ExtendedError
;
1348 SET_CFLAG(&context
);
1350 else AX_reg(&context
) = 0x0100;
1351 /* intlist: many Microsoft products for Windows rely on this */
1354 case 0x48: /* ALLOCATE MEMORY */
1355 case 0x49: /* FREE MEMORY */
1356 case 0x4a: /* RESIZE MEMORY BLOCK */
1357 INT_BARF( &context
, 0x21 );
1360 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1361 AX_reg(&context
) = WinExec( PTR_SEG_OFF_TO_LIN( DS_reg(&context
),
1364 if (AX_reg(&context
) < 32) SET_CFLAG(&context
);
1367 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1368 TASK_KillCurrentTask( AL_reg(&context
) );
1371 case 0x4d: /* GET RETURN CODE */
1372 AX_reg(&context
) = 0; /* normal exit */
1375 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1376 if (!INT21_FindFirst(&context
)) break;
1379 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1380 if (!INT21_FindNext(&context
))
1382 DOS_ERROR( ER_NoMoreFiles
, EC_MediaError
, SA_Abort
, EL_Disk
);
1383 AX_reg(&context
) = ER_NoMoreFiles
;
1384 SET_CFLAG(&context
);
1388 case 0x51: /* GET PSP ADDRESS */
1389 case 0x62: /* GET PSP ADDRESS */
1390 /* FIXME: should we return the original DOS PSP upon */
1391 /* Windows startup ? */
1392 BX_reg(&context
) = GetCurrentPDB();
1395 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1396 ES_reg(&context
) = 0x0;
1397 BX_reg(&context
) = 0x0;
1398 INT_BARF( &context
, 0x21 );
1401 case 0x56: /* "RENAME" - RENAME FILE */
1402 if (!INT21_RenameFile(&context
))
1404 AX_reg(&context
) = DOS_ExtendedError
;
1405 SET_CFLAG(&context
);
1409 case 0x57: /* FILE DATE AND TIME */
1410 switch (AL_reg(&context
))
1412 case 0x00: /* Get */
1413 if (!FILE_GetDateTime( BX_reg(&context
), &DX_reg(&context
),
1414 &CX_reg(&context
), TRUE
))
1416 AX_reg(&context
) = DOS_ExtendedError
;
1417 SET_CFLAG(&context
);
1421 case 0x01: /* Set */
1422 if (!FILE_SetDateTime( BX_reg(&context
), DX_reg(&context
),
1425 AX_reg(&context
) = DOS_ExtendedError
;
1426 SET_CFLAG(&context
);
1432 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1433 switch (AL_reg(&context
))
1436 AX_reg(&context
) = 1;
1439 AX_reg(&context
) = 0;
1445 RESET_CFLAG(&context
);
1448 case 0x5a: /* CREATE TEMPORARY FILE */
1449 if (!INT21_CreateTempFile(&context
))
1451 AX_reg(&context
) = DOS_ExtendedError
;
1452 SET_CFLAG(&context
);
1456 case 0x5b: /* CREATE NEW FILE */
1457 if ((AX_reg(&context
) = _lcreat_uniq( PTR_SEG_OFF_TO_LIN(DS_reg(&context
),DX_reg(&context
)), 0 )) == (WORD
)HFILE_ERROR
)
1459 AX_reg(&context
) = DOS_ExtendedError
;
1460 SET_CFLAG(&context
);
1464 case 0x5d: /* NETWORK */
1466 /* network software not installed */
1467 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1468 AX_reg(&context
) = DOS_ExtendedError
;
1469 SET_CFLAG(&context
);
1472 case 0x5f: /* NETWORK */
1473 switch (AL_reg(&context
))
1475 case 0x07: /* ENABLE DRIVE */
1476 if (!DRIVE_Enable( DL_reg(&context
) ))
1478 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1479 AX_reg(&context
) = DOS_ExtendedError
;
1480 SET_CFLAG(&context
);
1484 case 0x08: /* DISABLE DRIVE */
1485 if (!DRIVE_Disable( DL_reg(&context
) ))
1487 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1488 AX_reg(&context
) = DOS_ExtendedError
;
1489 SET_CFLAG(&context
);
1494 /* network software not installed */
1495 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1496 AX_reg(&context
) = DOS_ExtendedError
;
1497 SET_CFLAG(&context
);
1502 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1504 const char *truename
= DOSFS_GetDosTrueName( PTR_SEG_OFF_TO_LIN(DS_reg(&context
),SI_reg(&context
) ), FALSE
);
1507 AX_reg(&context
) = DOS_ExtendedError
;
1508 SET_CFLAG(&context
);
1512 lstrcpyn32A( PTR_SEG_OFF_TO_LIN( ES_reg(&context
),
1515 AX_reg(&context
) = 0;
1520 case 0x61: /* UNUSED */
1521 case 0x63: /* UNUSED */
1522 case 0x64: /* OS/2 DOS BOX */
1523 case 0x65: /* GET EXTENDED COUNTRY INFORMATION */
1524 INT_BARF( &context
, 0x21 );
1525 SET_CFLAG(&context
);
1528 case 0x66: /* GLOBAL CODE PAGE TABLE */
1529 switch (AL_reg(&context
))
1532 DX_reg(&context
) = BX_reg(&context
) = CodePage
;
1533 RESET_CFLAG(&context
);
1536 CodePage
= BX_reg(&context
);
1537 RESET_CFLAG(&context
);
1542 case 0x67: /* SET HANDLE COUNT */
1543 SetHandleCount( BX_reg(&context
) );
1544 if (DOS_ExtendedError
)
1546 AX_reg(&context
) = DOS_ExtendedError
;
1547 SET_CFLAG(&context
);
1551 case 0x68: /* "FFLUSH" - COMMIT FILE */
1552 case 0x6a: /* COMMIT FILE */
1553 if (!FILE_Sync( BX_reg(&context
) ))
1555 AX_reg(&context
) = DOS_ExtendedError
;
1556 SET_CFLAG(&context
);
1560 case 0x69: /* DISK SERIAL NUMBER */
1561 switch (AL_reg(&context
))
1564 if (!INT21_GetDiskSerialNumber(&context
))
1566 AX_reg(&context
) = DOS_ExtendedError
;
1567 SET_CFLAG(&context
);
1569 else AX_reg(&context
) = 0;
1572 if (!INT21_SetDiskSerialNumber(&context
))
1574 AX_reg(&context
) = DOS_ExtendedError
;
1575 SET_CFLAG(&context
);
1577 else AX_reg(&context
) = 1;
1582 case 0x6C: /* Extended Open/Create*/
1583 ExtendedOpenCreateFile(&context
);
1586 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
1587 case 0x71: /* MS-DOS 7 (Chicago) - LONG FILENAME FUNCTIONS */
1588 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
1589 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
1590 dprintf_int(stddeb
,"int21: windows95 function AX %04x\n",
1592 dprintf_int(stddeb
, " returning unimplemented\n");
1593 SET_CFLAG(&context
);
1594 AL_reg(&context
) = 0;
1597 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1598 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1602 INT_BARF( &context
, 0x21 );
1605 dprintf_int( stddeb
, "ret21: AX=%04x BX=%04x CX=%04x DX=%04x "
1606 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1607 AX_reg(&context
), BX_reg(&context
), CX_reg(&context
),
1608 DX_reg(&context
), SI_reg(&context
), DI_reg(&context
),
1609 DS_reg(&context
), ES_reg(&context
), EFL_reg(&context
));
1613 BOOL
INT21_Init(void)
1615 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
1617 fprintf( stderr
, "INT21_Init: Out of memory\n");
1620 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
1623 dpbsegptr
= PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
1624 heap
->InDosFlag
= 0;
1625 strcpy(heap
->biosdate
, "01/01/80");