2 * (c) 1993, 1994 Erik Bos
14 #include <sys/types.h>
21 #include "registers.h"
29 /* Define the drive parameter block, as used by int21/1F
30 * and int21/32. This table can be accessed through the
31 * global 'dpb' pointer, which points into the local dos
36 BYTE drive_num
; /* 0=A, etc. */
37 BYTE unit_num
; /* Drive's unit number (?) */
38 WORD sector_size
; /* Sector size in bytes */
39 BYTE high_sector
; /* Highest sector in a cluster */
40 BYTE shift
; /* Shift count (?) */
41 WORD reserved
; /* Number of reserved sectors at start */
42 BYTE num_FAT
; /* Number of FATs */
43 WORD dir_entries
; /* Number of root dir entries */
44 WORD first_data
; /* First data sector */
45 WORD high_cluster
; /* Highest cluster number */
46 WORD sectors_in_FAT
; /* Number of sectors per FAT */
47 WORD start_dir
; /* Starting sector of first dir */
48 DWORD driver_head
; /* Address of device driver header (?) */
49 BYTE media_ID
; /* Media ID */
50 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
51 DWORD next
; /* Pointer to next DPB in list */
52 WORD free_search
; /* Free cluster search start */
53 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
56 WORD ExtendedError
, CodePage
= 437;
57 BYTE ErrorClass
, Action
, ErrorLocus
;
67 static struct DosHeap
*heap
;
68 static WORD DosHeapHandle
;
70 WORD sharing_retries
= 3; /* number of retries at sharing violation */
71 WORD sharing_pause
= 1; /* pause between retries */
73 extern char TempDirectory
[];
75 static int Error(int e
, int class, int el
)
78 Action
= SA_Ask4Retry
;
85 void errno_to_doserr(void)
89 Error (ShareViolation
, EC_Temporary
, EL_Unknown
);
92 Error (InvalidHandle
, EC_AppError
, EL_Unknown
);
95 Error (DiskFull
, EC_MediaError
, EL_Disk
);
100 Error (WriteProtected
, EC_AccessDenied
, EL_Unknown
);
103 Error (LockViolation
, EC_AccessDenied
, EL_Unknown
);
106 Error (FileNotFound
, EC_NotFound
, EL_Unknown
);
109 Error (CanNotMakeDir
, EC_AccessDenied
, EL_Unknown
);
113 Error (NoMoreFiles
, EC_MediaError
, EL_Unknown
);
116 Error (FileExists
, EC_Exists
, EL_Disk
);
119 dprintf_int(stddeb
, "int21: unknown errno %d!\n", errno
);
120 Error (GeneralFailure
, EC_SystemFailure
, EL_Unknown
);
125 BYTE
*GetCurrentDTA(void)
127 TDB
*pTask
= (TDB
*)GlobalLock( GetCurrentTask() );
128 return (BYTE
*)PTR_SEG_TO_LIN( pTask
->dta
);
132 void ChopOffWhiteSpace(char *string
)
136 for (length
= strlen(string
) ; length
; length
--)
137 if (string
[length
] == ' ')
138 string
[length
] = '\0';
141 static void CreateBPB(int drive
, BYTE
*data
)
146 setword(&data
[3], 0);
148 setword(&data
[6], 240);
149 setword(&data
[8], 64000);
151 setword(&data
[0x0b], 40);
152 setword(&data
[0x0d], 56);
153 setword(&data
[0x0f], 2);
154 setword(&data
[0x11], 0);
155 setword(&data
[0x1f], 800);
157 setword(&data
[0x22], 1);
158 } else { /* 1.44mb */
161 setword(&data
[3], 0);
163 setword(&data
[6], 240);
164 setword(&data
[8], 2880);
166 setword(&data
[0x0b], 6);
167 setword(&data
[0x0d], 18);
168 setword(&data
[0x0f], 2);
169 setword(&data
[0x11], 0);
170 setword(&data
[0x1f], 80);
172 setword(&data
[0x22], 2);
176 static void GetFreeDiskSpace(struct sigcontext_struct
*context
)
181 if (DL_reg(context
) == 0) drive
= DOS_GetDefaultDrive();
182 else drive
= DL_reg(context
) - 1;
184 if (!DOS_ValidDrive(drive
)) {
185 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
186 AX_reg(context
) = 0xffff;
190 if (!DOS_GetFreeSpace(drive
, &size
, &available
)) {
191 Error(GeneralFailure
, EC_MediaError
, EL_Disk
);
192 AX_reg(context
) = 0xffff;
196 AX_reg(context
) = (drive
< 2) ? 1 : 64; /* 64 for hard-disks, 1 for diskettes */
197 CX_reg(context
) = 512;
199 BX_reg(context
) = (available
/ (CX_reg(context
) * AX_reg(context
)));
200 DX_reg(context
) = (size
/ (CX_reg(context
) * AX_reg(context
)));
204 static void GetDriveAllocInfo(struct sigcontext_struct
*context
)
207 long size
, available
;
209 if (DL_reg(context
) == 0) drive
= DOS_GetDefaultDrive();
210 else drive
= DL_reg(context
) - 1;
212 if (!DOS_ValidDrive(drive
))
215 CX_reg(context
) = 512;
217 Error (InvalidDrive
, EC_MediaError
, EL_Disk
);
221 if (!DOS_GetFreeSpace(drive
, &size
, &available
)) {
222 Error(GeneralFailure
, EC_MediaError
, EL_Disk
);
223 AX_reg(context
) = 0xffff;
227 AX_reg(context
) = (drive
< 2) ? 1 : 64; /* 64 for hard-disks, 1 for diskettes */
228 CX_reg(context
) = 512;
229 DX_reg(context
) = (size
/ (CX_reg(context
) * AX_reg(context
)));
231 heap
->mediaID
= 0xf0;
233 DS_reg(context
) = DosHeapHandle
;
234 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
238 static void GetDrivePB(struct sigcontext_struct
*context
, int drive
)
240 if(!DOS_ValidDrive(drive
))
242 Error (InvalidDrive
, EC_MediaError
, EL_Disk
);
243 AX_reg(context
) = 0x00ff;
247 dprintf_int(stddeb
, "int21: GetDrivePB not fully implemented.\n");
249 /* FIXME: I have no idea what a lot of this information should
250 * say or whether it even really matters since we're not allowing
251 * direct block access. However, some programs seem to depend on
252 * getting at least _something_ back from here. The 'next' pointer
253 * does worry me, though. Should we have a complete table of
254 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
256 dpb
->drive_num
= dpb
->unit_num
= drive
; /* The same? */
257 dpb
->sector_size
= 512;
258 dpb
->high_sector
= 1;
259 dpb
->shift
= drive
< 2 ? 0 : 6; /* 6 for HD, 0 for floppy */
262 dpb
->dir_entries
= 2;
264 dpb
->high_cluster
= 64000;
265 dpb
->sectors_in_FAT
= 1;
267 dpb
->driver_head
= 0;
268 dpb
->media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
269 dpb
->access_flag
= 0;
271 dpb
->free_search
= 0;
272 dpb
->free_clusters
= 0xFFFF; /* unknown */
274 AL_reg(context
) = 0x00;
275 DS_reg(context
) = SELECTOROF(dpbsegptr
);
276 BX_reg(context
) = OFFSETOF(dpbsegptr
);
280 static void ReadFile(struct sigcontext_struct
*context
)
285 /* can't read from stdout / stderr */
286 if ((BX_reg(context
) == 1) || (BX_reg(context
) == 2)) {
287 Error (InvalidHandle
, EL_Unknown
, EC_Unknown
);
288 AX_reg(context
) = InvalidHandle
;
290 dprintf_int(stddeb
, "int21: read (%d, void *, 0x%x) = EBADF\n",
291 BX_reg(context
), CX_reg(context
));
295 ptr
= PTR_SEG_OFF_TO_LIN (DS_reg(context
),DX_reg(context
));
296 if (BX_reg(context
) == 0) {
300 RESET_CFLAG(context
);
301 dprintf_int(stddeb
, "int21: read (%d, void *, 0x%x) = EOF\n",
302 BX_reg(context
), CX_reg(context
));
305 size
= read(BX_reg(context
), ptr
, CX_reg(context
));
306 dprintf_int(stddeb
,"int21: read(%d, %04x:%04x, 0x%x) = 0x%x\n",
307 BX_reg(context
), DS_reg(context
), DX_reg(context
),
308 CX_reg(context
), size
);
311 AX_reg(context
) = ExtendedError
;
316 AX_reg(context
) = size
;
317 RESET_CFLAG(context
);
321 static void WriteFile(struct sigcontext_struct
*context
)
326 ptr
= PTR_SEG_OFF_TO_LIN (DS_reg(context
),DX_reg(context
));
328 if (BX_reg(context
) == 0) {
329 Error (InvalidHandle
, EC_Unknown
, EL_Unknown
);
330 EAX_reg(context
) = InvalidHandle
;
335 if (BX_reg(context
) < 3) {
336 for (x
= 0;x
!= CX_reg(context
);x
++) {
337 dprintf_int(stddeb
, "%c", *ptr
++);
342 AX_reg(context
) = CX_reg(context
);
343 RESET_CFLAG(context
);
345 /* well, this function already handles everything we need */
346 size
= _lwrite(BX_reg(context
),ptr
,CX_reg(context
));
347 if (size
== -1) { /* HFILE_ERROR == -1 */
349 AX_reg(context
) = ExtendedError
;
354 AX_reg(context
) = size
;
355 RESET_CFLAG(context
);
359 static void SeekFile(struct sigcontext_struct
*context
)
361 off_t status
, fileoffset
;
363 switch (AL_reg(context
))
365 case 1: fileoffset
= SEEK_CUR
;
367 case 2: fileoffset
= SEEK_END
;
370 case 0: fileoffset
= SEEK_SET
;
373 status
= lseek(BX_reg(context
), (CX_reg(context
) << 16) + DX_reg(context
), fileoffset
);
375 dprintf_int (stddeb
, "int21: seek (%d, 0x%x, %d) = 0x%lx\n",
376 BX_reg(context
), (CX_reg(context
) << 16) + DX_reg(context
), AL_reg(context
), status
);
381 AX_reg(context
) = ExtendedError
;
386 AX_reg(context
) = LOWORD(status
);
387 DX_reg(context
) = HIWORD(status
);
388 RESET_CFLAG(context
);
391 static void ioctlGetDeviceInfo(struct sigcontext_struct
*context
)
394 dprintf_int (stddeb
, "int21: ioctl (%d, GetDeviceInfo)\n", BX_reg(context
));
396 switch (BX_reg(context
))
401 DX_reg(context
) = 0x80d0 | (1 << (BX_reg(context
) != 0));
402 RESET_CFLAG(context
);
409 if (fstat(BX_reg(context
), &sbuf
) < 0)
411 INT_BARF( context
, 0x21 );
416 DX_reg(context
) = 0x0943;
417 /* bits 0-5 are current drive
418 * bit 6 - file has NOT been written..FIXME: correct?
419 * bit 8 - generate int24 if no diskspace on write/ read past end of file
420 * bit 11 - media not removable
424 RESET_CFLAG(context
);
427 static void ioctlGenericBlkDevReq(struct sigcontext_struct
*context
)
429 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
432 if (BL_reg(context
) == 0) drive
= DOS_GetDefaultDrive();
433 else drive
= BL_reg(context
) - 1;
435 if (!DOS_ValidDrive(drive
))
437 Error( FileNotFound
, EC_NotFound
, EL_Disk
);
438 AX_reg(context
) = FileNotFound
;
443 if (CH_reg(context
) != 0x08)
445 INT_BARF( context
, 0x21 );
448 switch (CL_reg(context
)) {
449 case 0x60: /* get device parameters */
450 /* used by w4wgrp's winfile */
451 memset(dataptr
, 0, 0x26);
453 dataptr
[6] = 0; /* media type */
456 dataptr
[1] = 0x05; /* fixed disk */
457 setword(&dataptr
[2], 0x01); /* non removable */
458 setword(&dataptr
[4], 0x300); /* # of cylinders */
462 dataptr
[1] = 0x07; /* block dev, floppy */
463 setword(&dataptr
[2], 0x02); /* removable */
464 setword(&dataptr
[4], 80); /* # of cylinders */
466 CreateBPB(drive
, &dataptr
[7]);
467 RESET_CFLAG(context
);
470 INT_BARF( context
, 0x21 );
474 static void GetSystemDate(struct sigcontext_struct
*context
)
480 now
= localtime(<ime
);
482 CX_reg(context
) = now
->tm_year
+ 1900;
483 DX_reg(context
) = ((now
->tm_mon
+ 1) << 8) | now
->tm_mday
;
484 AX_reg(context
) = now
->tm_wday
;
487 static void GetSystemTime(struct sigcontext_struct
*context
)
492 gettimeofday(&tv
,NULL
); /* Note use of gettimeofday(), instead of time() */
493 now
= localtime(&tv
.tv_sec
);
495 CX_reg(context
) = (now
->tm_hour
<<8) | now
->tm_min
;
496 DX_reg(context
) = (now
->tm_sec
<<8) | tv
.tv_usec
/10000;
497 /* Note hundredths of seconds */
500 static void GetExtendedErrorInfo(struct sigcontext_struct
*context
)
502 AX_reg(context
) = ExtendedError
;
503 BX_reg(context
) = (ErrorClass
<< 8) | Action
;
504 CH_reg(context
) = ErrorLocus
;
507 static void CreateFile(struct sigcontext_struct
*context
)
510 handle
= open(DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
512 O_CREAT
| O_TRUNC
| O_RDWR
, 0666 );
515 AX_reg(context
) = ExtendedError
;
520 AX_reg(context
) = handle
;
521 RESET_CFLAG(context
);
524 void OpenExistingFile(struct sigcontext_struct
*context
)
530 switch (AX_reg(context
) & 0x0007)
545 if ((handle
= open(DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
))),
548 if( Options
.allowReadOnly
)
549 handle
= open( DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
))),
553 dprintf_int (stddeb
, "int21: open (%s, %d) = -1\n",
554 DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
))), mode
);
556 AX_reg(context
) = ExtendedError
;
562 dprintf_int (stddeb
, "int21: open (%s, %d) = %d\n",
563 DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context
),
564 DX_reg(context
))), mode
, handle
);
566 switch (AX_reg(context
) & 0x0070)
568 case 0x00: /* compatability mode */
569 case 0x40: /* DENYNONE */
573 case 0x30: /* DENYREAD */
575 "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
576 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)));
577 case 0x10: /* DENYALL */
581 case 0x20: /* DENYWRITE */
592 int result
,retries
=sharing_retries
;
594 result
= flock(handle
, lock
| LOCK_NB
);
595 if ( retries
&& (!result
) )
598 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
599 result
++; /* stop the optimizer */
600 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
604 while( (!result
) && (!(retries
--)) );
609 AX_reg(context
) = ExtendedError
;
618 AX_reg(context
) = handle
;
619 RESET_CFLAG(context
);
622 static void CloseFile(struct sigcontext_struct
*context
)
624 dprintf_int (stddeb
, "int21: close (%d)\n", BX_reg(context
));
626 if (_lclose( BX_reg(context
) ))
629 AX_reg(context
) = ExtendedError
;
634 AX_reg(context
) = NoError
;
635 RESET_CFLAG(context
);
638 static void RenameFile(struct sigcontext_struct
*context
)
640 char *newname
, *oldname
;
642 /* FIXME: should not rename over an existing file */
643 dprintf_int(stddeb
,"int21: renaming %s to %s\n",
644 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
645 (char *)PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
)));
647 oldname
= DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
649 newname
= DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(ES_reg(context
),
652 rename( oldname
, newname
);
653 RESET_CFLAG(context
);
657 static void MakeDir(struct sigcontext_struct
*context
)
661 dprintf_int(stddeb
,"int21: makedir %s\n", (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)) );
663 if ((dirname
= DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
664 DX_reg(context
)) ))== NULL
) {
665 Error( CanNotMakeDir
, EC_AccessDenied
, EL_Disk
);
666 AX_reg(context
) = CanNotMakeDir
;
671 if (mkdir(dirname
,0) == -1)
673 Error( CanNotMakeDir
, EC_AccessDenied
, EL_Disk
);
674 AX_reg(context
) = CanNotMakeDir
;
678 RESET_CFLAG(context
);
681 static void ChangeDir(struct sigcontext_struct
*context
)
684 char *dirname
= PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
));
685 drive
= DOS_GetDefaultDrive();
686 dprintf_int(stddeb
,"int21: changedir %s\n", dirname
);
687 if (dirname
!= NULL
&& dirname
[1] == ':') {
688 drive
= toupper(dirname
[0]) - 'A';
691 if (!DOS_ChangeDir(drive
, dirname
))
694 AX_reg(context
)=0x03;
698 static void RemoveDir(struct sigcontext_struct
*context
)
702 dprintf_int(stddeb
,"int21: removedir %s\n", (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)) );
704 if ((dirname
= DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)) ))== NULL
) {
705 Error( PathNotFound
, EC_NotFound
, EL_Disk
);
706 AX_reg(context
) = PathNotFound
;
712 if (strcmp(unixname,DosDrives[drive].CurrentDirectory)) {
713 AL = CanNotRemoveCwd;
717 if (rmdir(dirname
) == -1) {
718 Error( AccessDenied
, EC_AccessDenied
, EL_Disk
);
719 AX_reg(context
) = AccessDenied
;
723 RESET_CFLAG(context
);
726 static void FindNext(struct sigcontext_struct
*context
)
728 struct dosdirent
*dp
;
730 BYTE
*dta
= GetCurrentDTA();
732 memcpy(&dp
, dta
+0x11, sizeof(dp
));
734 dprintf_int(stddeb
, "int21: FindNext, dta %p, dp %p\n", dta
, dp
);
736 if ((dp
= DOS_readdir(dp
)) == NULL
) {
737 Error(NoMoreFiles
, EC_MediaError
, EL_Disk
);
738 AX_reg(context
) = NoMoreFiles
;
742 } /* while (*(dta + 0x0c) != dp->attribute);*/
743 while ( ( dp
->search_attribute
& dp
->attribute
) != dp
->attribute
);
745 *(dta
+ 0x15) = dp
->attribute
;
746 setword(&dta
[0x0d], dp
->entnum
);
748 t
= localtime(&(dp
->filetime
));
749 setword(&dta
[0x16], (t
->tm_hour
<< 11) + (t
->tm_min
<< 5) +
750 (t
->tm_sec
/ 2)); /* time */
751 setword(&dta
[0x18], ((t
->tm_year
- 80) << 9) + (t
->tm_mon
<< 5) +
752 (t
->tm_mday
)); /* date */
753 setdword(&dta
[0x1a], dp
->filesize
);
754 strncpy(dta
+ 0x1e, dp
->filename
, 13);
757 RESET_CFLAG(context
);
759 dprintf_int(stddeb
, "int21: FindNext -- (%s) index=%d size=%ld\n", dp
->filename
, dp
->entnum
, dp
->filesize
);
763 static void FindFirst(struct sigcontext_struct
*context
)
765 BYTE drive
, *path
= PTR_SEG_OFF_TO_LIN(DS_reg(context
),
767 struct dosdirent
*dp
;
769 BYTE
*dta
= GetCurrentDTA();
771 dprintf_int(stddeb
, "int21: FindFirst path = %s\n", path
);
773 if ((*path
)&&(path
[1] == ':')) {
774 drive
= (islower(*path
) ? toupper(*path
) : *path
) - 'A';
776 if (!DOS_ValidDrive(drive
)) {
777 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
778 AX_reg(context
) = InvalidDrive
;
783 drive
= DOS_GetDefaultDrive();
786 memset(dta
+ 1 , '?', 11);
787 *(dta
+ 0x0c) = ECX_reg(context
) & (FA_LABEL
| FA_DIREC
);
789 if ((dp
= DOS_opendir(path
)) == NULL
) {
790 Error(PathNotFound
, EC_MediaError
, EL_Disk
);
791 AX_reg(context
) = FileNotFound
;
796 dp
->search_attribute
= ECX_reg(context
) & (FA_LABEL
| FA_DIREC
);
797 memcpy(dta
+ 0x11, &dp
, sizeof(dp
));
801 static void GetFileDateTime(struct sigcontext_struct
*context
)
803 struct stat filestat
;
806 fstat( BX_reg(context
), &filestat
);
807 now
= localtime (&filestat
.st_mtime
);
809 CX_reg(context
) = ((now
->tm_hour
* 0x2000) + (now
->tm_min
* 0x20) + now
->tm_sec
/2);
810 DX_reg(context
) = (((now
->tm_year
+ 1900 - 1980) * 0x200) +
811 (now
->tm_mon
* 0x20) + now
->tm_mday
);
813 RESET_CFLAG(context
);
816 static void SetFileDateTime(struct sigcontext_struct
*context
)
819 struct utimbuf filetime
;
821 /* FIXME: Argument isn't the name of the file in DS:DX,
822 but the file handle in BX */
823 filename
= DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
826 filetime
.actime
= 0L;
827 filetime
.modtime
= filetime
.actime
;
829 utime(filename
, &filetime
);
830 RESET_CFLAG(context
);
833 static void CreateTempFile(struct sigcontext_struct
*context
)
838 sprintf(temp
,"%s\\win%d.tmp",TempDirectory
,(int) getpid());
840 dprintf_int(stddeb
,"CreateTempFile %s\n",temp
);
842 handle
= open(DOS_GetUnixFileName(temp
), O_CREAT
| O_TRUNC
| O_RDWR
, 0666);
845 Error( WriteProtected
, EC_AccessDenied
, EL_Disk
);
846 AX_reg(context
) = WriteProtected
;
851 strcpy(PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)), temp
);
853 AX_reg(context
) = handle
;
854 RESET_CFLAG(context
);
857 static void CreateNewFile(struct sigcontext_struct
*context
)
861 if ((handle
= open(DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)) ),
862 O_CREAT
| O_EXCL
| O_RDWR
, 0666)) == -1)
864 Error( WriteProtected
, EC_AccessDenied
, EL_Disk
);
865 AX_reg(context
) = WriteProtected
;
870 AX_reg(context
) = handle
;
871 RESET_CFLAG(context
);
874 static void GetCurrentDirectory(struct sigcontext_struct
*context
)
878 if (DL_reg(context
) == 0) drive
= DOS_GetDefaultDrive();
879 else drive
= DL_reg(context
) - 1;
881 if (!DOS_ValidDrive(drive
))
883 Error( InvalidDrive
, EC_NotFound
, EL_Disk
);
884 AX_reg(context
) = InvalidDrive
;
889 strcpy(PTR_SEG_OFF_TO_LIN(DS_reg(context
),SI_reg(context
)),
890 DOS_GetCurrentDir(drive
) );
891 RESET_CFLAG(context
);
894 static void GetDiskSerialNumber(struct sigcontext_struct
*context
)
897 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
900 if (BL_reg(context
) == 0) drive
= DOS_GetDefaultDrive();
901 else drive
= BL_reg(context
) - 1;
903 if (!DOS_ValidDrive(drive
))
905 Error( InvalidDrive
, EC_NotFound
, EL_Disk
);
906 AX_reg(context
) = InvalidDrive
;
911 DOS_GetSerialNumber(drive
, &serialnumber
);
914 setdword(&dataptr
[2], serialnumber
);
915 strncpy(dataptr
+ 6, DOS_GetVolumeLabel(drive
), 8);
916 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
919 RESET_CFLAG(context
);
922 static void SetDiskSerialNumber(struct sigcontext_struct
*context
)
925 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
928 if (BL_reg(context
) == 0) drive
= DOS_GetDefaultDrive();
929 else drive
= BL_reg(context
) - 1;
931 if (!DOS_ValidDrive(drive
))
933 Error( InvalidDrive
, EC_NotFound
, EL_Disk
);
934 AX_reg(context
) = InvalidDrive
;
939 serialnumber
= dataptr
[1] + (dataptr
[2] << 8) + (dataptr
[3] << 16) +
942 DOS_SetSerialNumber(drive
, serialnumber
);
944 RESET_CFLAG(context
);
947 static void DumpFCB(BYTE
*fcb
)
953 for (y
= 0; y
!=2 ; y
++) {
954 for (x
= 0; x
!=15;x
++)
955 dprintf_int(stddeb
, "%02x ", *fcb
++);
956 dprintf_int(stddeb
,"\n");
960 /* microsoft's programmers should be shot for using CP/M style int21
961 calls in Windows for Workgroup's winfile.exe */
963 static void FindFirstFCB(struct sigcontext_struct
*context
)
965 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
966 struct fcb
*standard_fcb
;
967 struct fcb
*output_fcb
;
971 BYTE
*dta
= GetCurrentDTA();
977 standard_fcb
= (struct fcb
*)(fcb
+ 7);
978 output_fcb
= (struct fcb
*)(dta
+ 7);
983 standard_fcb
= (struct fcb
*)fcb
;
984 output_fcb
= (struct fcb
*)dta
;
987 if (standard_fcb
->drive
)
989 drive
= standard_fcb
->drive
- 1;
990 if (!DOS_ValidDrive(drive
))
992 Error (InvalidDrive
, EC_MediaError
, EL_Disk
);
993 AX_reg(context
) = 0xff;
998 drive
= DOS_GetDefaultDrive();
1000 output_fcb
->drive
= drive
;
1004 if (*(fcb
+6) & FA_LABEL
) /* return volume label */
1006 *(dta
+6) = FA_LABEL
;
1007 memset(&output_fcb
->name
, ' ', 11);
1008 if (DOS_GetVolumeLabel(drive
) != NULL
)
1010 strncpy(output_fcb
->name
, DOS_GetVolumeLabel(drive
), 11);
1011 AX_reg(context
) = 0x00;
1017 strncpy(output_fcb
->name
, standard_fcb
->name
, 11);
1019 *(dta
+6) = ( *(fcb
+6) & (!FA_DIREC
));
1021 sprintf(path
,"%c:*.*",drive
+'A');
1022 if ((output_fcb
->directory
= DOS_opendir(path
))==NULL
)
1024 Error (PathNotFound
, EC_MediaError
, EL_Disk
);
1025 AX_reg(context
) = 0xff;
1032 static void DeleteFileFCB(struct sigcontext_struct
*context
)
1034 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
1036 struct dosdirent
*dp
;
1037 char temp
[256], *ptr
;
1044 drive
= DOS_GetDefaultDrive();
1046 strcpy(temp
, DOS_GetCurrentDir(drive
));
1048 strncat(temp
, fcb
+ 1, 8);
1049 ChopOffWhiteSpace(temp
);
1050 strncat(temp
, fcb
+ 9, 3);
1051 ChopOffWhiteSpace(temp
);
1053 if ((dp
= DOS_opendir(temp
)) == NULL
) {
1054 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
1055 AX_reg(context
) = 0xff;
1059 strcpy(temp
, DOS_GetCurrentDir(drive
) );
1062 ptr
= temp
+ strlen(temp
);
1064 while (DOS_readdir(dp
) != NULL
)
1066 strcpy(ptr
, dp
->filename
);
1067 dprintf_int(stddeb
, "int21: delete file %s\n", temp
);
1068 /* unlink(DOS_GetUnixFileName(temp)); */
1071 AX_reg(context
) = 0;
1074 static void RenameFileFCB(struct sigcontext_struct
*context
)
1076 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
1078 struct dosdirent
*dp
;
1079 char temp
[256], oldname
[256], newname
[256], *oldnameptr
, *newnameptr
;
1086 drive
= DOS_GetDefaultDrive();
1088 strcpy(temp
, DOS_GetCurrentDir(drive
));
1090 strncat(temp
, fcb
+ 1, 8);
1091 ChopOffWhiteSpace(temp
);
1092 strncat(temp
, fcb
+ 9, 3);
1093 ChopOffWhiteSpace(temp
);
1095 if ((dp
= DOS_opendir(temp
)) == NULL
) {
1096 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
1097 AX_reg(context
) = 0xff;
1101 strcpy(oldname
, DOS_GetCurrentDir(drive
) );
1102 strcat(oldname
, "\\");
1103 oldnameptr
= oldname
+ strlen(oldname
);
1105 strcpy(newname
, DOS_GetCurrentDir(drive
) );
1106 strcat(newname
, "\\");
1107 newnameptr
= newname
+ strlen(newname
);
1109 while (DOS_readdir(dp
) != NULL
)
1111 strcpy(oldnameptr
, dp
->filename
);
1112 strcpy(newnameptr
, fcb
+ 1);
1113 dprintf_int(stddeb
, "int21: renamefile %s -> %s\n",
1117 AX_reg(context
) = 0;
1122 static void fLock (struct sigcontext_struct
* context
)
1125 int result
,retries
=sharing_retries
;
1127 f
.l_start
= MAKELONG(DX_reg(context
),CX_reg(context
));
1128 f
.l_len
= MAKELONG(DI_reg(context
),SI_reg(context
));
1132 switch ( AX_reg(context
) & 0xff )
1134 case 0x00: /* LOCK */
1138 case 0x01: /* UNLOCK */
1143 AX_reg(context
) = 0x0001;
1149 result
= fcntl(BX_reg(context
),F_SETLK
,&f
);
1150 if ( retries
&& (!result
) )
1153 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
1154 result
++; /* stop the optimizer */
1155 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
1159 while( (!result
) && (!(retries
--)) );
1164 AX_reg(context
) = ExtendedError
;
1170 RESET_CFLAG(context
);
1174 static void GetFileAttribute (struct sigcontext_struct
* context
)
1176 char *filename
= PTR_SEG_OFF_TO_LIN (DS_reg(context
),DX_reg(context
));
1180 res
= stat(DOS_GetUnixFileName(filename
), &s
);
1184 AX_reg(context
) = ExtendedError
;
1189 CX_reg(context
) = 0;
1190 if (S_ISDIR(s
.st_mode
))
1191 CX_reg(context
) |= 0x10;
1192 if ((S_IWRITE
& s
.st_mode
) != S_IWRITE
)
1193 CX_reg(context
) |= 0x01;
1195 dprintf_int (stddeb
, "int21: GetFileAttributes (%s) = 0x%x\n",
1196 filename
, CX_reg(context
) );
1198 RESET_CFLAG(context
);
1203 extern void LOCAL_PrintHeap (WORD ds
);
1205 /***********************************************************************
1206 * DOS3Call (KERNEL.102)
1208 void DOS3Call( struct sigcontext_struct context
)
1212 if (AH_reg(&context
) == 0x59)
1214 GetExtendedErrorInfo(&context
);
1220 switch(AH_reg(&context
))
1222 case 0x00: /* TERMINATE PROGRAM */
1223 TASK_KillCurrentTask( 0 );
1226 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1227 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1228 case 0x03: /* READ CHARACTER FROM STDAUX */
1229 case 0x04: /* WRITE CHARACTER TO STDAUX */
1230 case 0x05: /* WRITE CHARACTER TO PRINTER */
1231 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1232 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
1233 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1234 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1235 case 0x0a: /* BUFFERED INPUT */
1236 case 0x0b: /* GET STDIN STATUS */
1237 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
1238 case 0x0f: /* OPEN FILE USING FCB */
1239 case 0x10: /* CLOSE FILE USING FCB */
1240 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1241 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1242 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1243 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1244 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1245 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1246 case 0x23: /* GET FILE SIZE FOR FCB */
1247 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1248 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1249 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1250 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1251 case 0x29: /* PARSE FILENAME INTO FCB */
1252 case 0x2e: /* SET VERIFY FLAG */
1253 INT_BARF( &context
, 0x21 );
1256 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
1257 "SWITCHAR" - SET SWITCH CHARACTER
1258 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
1259 case 0x54: /* GET VERIFY FLAG */
1260 INT_BARF( &context
, 0x21 );
1263 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1267 case 0x6b: /* NULL FUNCTION */
1268 AL_reg(&context
) = 0;
1271 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1275 case 0x0d: /* DISK BUFFER FLUSH */
1276 RESET_CFLAG(&context
); /* dos 6+ only */
1279 case 0x0e: /* SELECT DEFAULT DRIVE */
1280 if (!DOS_ValidDrive(DL_reg(&context
)))
1281 Error (InvalidDrive
, EC_MediaError
, EL_Disk
);
1284 DOS_SetDefaultDrive(DL_reg(&context
));
1287 AL_reg(&context
) = MAX_DOS_DRIVES
;
1290 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1291 FindFirstFCB(&context
);
1294 case 0x13: /* DELETE FILE USING FCB */
1295 DeleteFileFCB(&context
);
1298 case 0x17: /* RENAME FILE USING FCB */
1299 RenameFileFCB(&context
);
1302 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1303 AL_reg(&context
) = DOS_GetDefaultDrive();
1307 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1309 TDB
*pTask
= (TDB
*)GlobalLock( GetCurrentTask() );
1310 pTask
->dta
= MAKELONG( DX_reg(&context
), DS_reg(&context
) );
1311 dprintf_int(stddeb
, "int21: Set DTA: %08lx\n", pTask
->dta
);
1315 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1316 DL_reg(&context
) = 0;
1317 GetDriveAllocInfo(&context
);
1320 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1321 GetDriveAllocInfo(&context
);
1324 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1325 GetDrivePB(&context
, DOS_GetDefaultDrive());
1328 case 0x25: /* SET INTERRUPT VECTOR */
1329 INT_SetHandler( AL_reg(&context
),
1330 MAKELONG( DX_reg(&context
), DS_reg(&context
) ) );
1333 case 0x2a: /* GET SYSTEM DATE */
1334 GetSystemDate(&context
);
1337 case 0x2b: /* SET SYSTEM DATE */
1338 fprintf( stdnimp
, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1339 DL_reg(&context
), DH_reg(&context
), CX_reg(&context
) );
1340 AL_reg(&context
) = 0; /* Let's pretend we succeeded */
1343 case 0x2c: /* GET SYSTEM TIME */
1344 GetSystemTime(&context
);
1347 case 0x2d: /* SET SYSTEM TIME */
1348 fprintf( stdnimp
, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1349 CH_reg(&context
), CL_reg(&context
),
1350 DH_reg(&context
), DL_reg(&context
) );
1351 AL_reg(&context
) = 0; /* Let's pretend we succeeded */
1354 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1356 TDB
*pTask
= (TDB
*)GlobalLock( GetCurrentTask() );
1357 ES_reg(&context
) = SELECTOROF( pTask
->dta
);
1358 BX_reg(&context
) = OFFSETOF( pTask
->dta
);
1362 case 0x30: /* GET DOS VERSION */
1363 AX_reg(&context
) = DOSVERSION
;
1364 BX_reg(&context
) = 0x0012; /* 0x123456 is Wine's serial # */
1365 CX_reg(&context
) = 0x3456;
1368 case 0x31: /* TERMINATE AND STAY RESIDENT */
1369 INT_BARF( &context
, 0x21 );
1372 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1373 GetDrivePB(&context
, (DL_reg(&context
) == 0) ?
1374 (DOS_GetDefaultDrive()) : (DL_reg(&context
)-1));
1377 case 0x33: /* MULTIPLEXED */
1378 switch (AL_reg(&context
))
1380 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1381 DL_reg(&context
) = 0;
1384 case 0x01: /* SET EXTENDED BREAK STATE */
1387 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1388 DL_reg(&context
) = 0;
1391 case 0x05: /* GET BOOT DRIVE */
1392 DL_reg(&context
) = 2;
1393 /* c: is Wine's bootdrive */
1396 case 0x06: /* GET TRUE VERSION NUMBER */
1397 BX_reg(&context
) = DOSVERSION
;
1398 DX_reg(&context
) = 0x00;
1402 INT_BARF( &context
, 0x21 );
1407 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1408 ES_reg(&context
) = DosHeapHandle
;
1409 BX_reg(&context
) = (int)&heap
->InDosFlag
- (int)heap
;
1412 case 0x35: /* GET INTERRUPT VECTOR */
1414 SEGPTR addr
= INT_GetHandler( AL_reg(&context
) );
1415 ES_reg(&context
) = SELECTOROF(addr
);
1416 BX_reg(&context
) = OFFSETOF(addr
);
1420 case 0x36: /* GET FREE DISK SPACE */
1421 GetFreeDiskSpace(&context
);
1424 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1425 AX_reg(&context
) = 0x02; /* no country support available */
1426 SET_CFLAG(&context
);
1429 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1433 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1434 RemoveDir(&context
);
1437 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1438 ChangeDir(&context
);
1441 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1442 CreateFile(&context
);
1445 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1446 OpenExistingFile(&context
);
1449 case 0x3e: /* "CLOSE" - CLOSE FILE */
1450 CloseFile(&context
);
1453 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1457 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1458 WriteFile(&context
);
1461 case 0x41: /* "UNLINK" - DELETE FILE */
1462 if (unlink( DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(&context
),DX_reg(&context
))) ) == -1) {
1464 AX_reg(&context
) = ExtendedError
;
1465 SET_CFLAG(&context
);
1469 RESET_CFLAG(&context
);
1472 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1476 case 0x43: /* FILE ATTRIBUTES */
1477 switch (AL_reg(&context
))
1480 GetFileAttribute(&context
);
1483 RESET_CFLAG(&context
);
1488 case 0x44: /* IOCTL */
1489 switch (AL_reg(&context
))
1492 ioctlGetDeviceInfo(&context
);
1495 case 0x08: /* Check if drive is removable. */
1496 drive
= BL_reg(&context
) ? (BL_reg(&context
) - 1)
1497 : DOS_GetDefaultDrive();
1498 if(!DOS_ValidDrive(drive
))
1500 Error( InvalidDrive
, EC_NotFound
, EL_Disk
);
1501 AX_reg(&context
) = InvalidDrive
;
1502 SET_CFLAG(&context
);
1507 AX_reg(&context
) = 1; /* not removable */
1509 AX_reg(&context
) = 0; /* removable */
1510 RESET_CFLAG(&context
);
1514 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1515 drive
= BL_reg(&context
) ? (BL_reg(&context
) - 1)
1516 : DOS_GetDefaultDrive();
1517 if(!DOS_ValidDrive(drive
))
1519 Error( InvalidDrive
, EC_NotFound
, EL_Disk
);
1520 AX_reg(&context
) = InvalidDrive
;
1521 SET_CFLAG(&context
);
1525 DX_reg(&context
) = (1<<9) | (1<<12) | (1<<15);
1526 RESET_CFLAG(&context
);
1529 case 0x0a: /* check if handle (BX) is remote */
1530 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1533 DX_reg(&context
) = 0;
1534 RESET_CFLAG(&context
);
1536 case 0x0b: /* SET SHARING RETRY COUNT */
1537 if (!CX_reg(&context
))
1539 AX_reg(&context
) = 1;
1540 SET_CFLAG(&context
);
1543 sharing_pause
= CX_reg(&context
);
1544 if (!DX_reg(&context
))
1545 sharing_retries
= DX_reg(&context
);
1546 RESET_CFLAG(&context
);
1550 ioctlGenericBlkDevReq(&context
);
1553 case 0x0F: /* Set logical drive mapping */
1554 /* FIXME: Not implemented at the moment, always returns error
1556 AX_reg(&context
) = 0x0001; /* invalid function */
1557 SET_CFLAG(&context
);
1561 INT_BARF( &context
, 0x21 );
1566 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1567 if ((AX_reg(&context
) = dup(BX_reg(&context
))) == 0xffff)
1570 AX_reg(&context
) = ExtendedError
;
1571 SET_CFLAG(&context
);
1573 else RESET_CFLAG(&context
);
1576 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1577 if (dup2( BX_reg(&context
), CX_reg(&context
) ) == -1)
1580 AX_reg(&context
) = ExtendedError
;
1581 SET_CFLAG(&context
);
1583 else RESET_CFLAG(&context
);
1586 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1587 GetCurrentDirectory(&context
);
1588 AX_reg(&context
) = 0x0100;
1589 /* intlist: many Microsoft products for Windows rely on this */
1592 case 0x48: /* ALLOCATE MEMORY */
1593 case 0x49: /* FREE MEMORY */
1594 case 0x4a: /* RESIZE MEMORY BLOCK */
1595 INT_BARF( &context
, 0x21 );
1598 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1599 WinExec( PTR_SEG_OFF_TO_LIN(DS_reg(&context
),DX_reg(&context
)),
1603 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1604 TASK_KillCurrentTask( AL_reg(&context
) );
1607 case 0x4d: /* GET RETURN CODE */
1608 AX_reg(&context
) = NoError
; /* normal exit */
1611 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1612 FindFirst(&context
);
1615 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1619 case 0x51: /* GET PSP ADDRESS */
1620 case 0x62: /* GET PSP ADDRESS */
1621 /* FIXME: should we return the original DOS PSP upon */
1622 /* Windows startup ? */
1623 BX_reg(&context
) = GetCurrentPDB();
1626 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1627 ES_reg(&context
) = 0x0;
1628 BX_reg(&context
) = 0x0;
1629 INT_BARF( &context
, 0x21 );
1632 case 0x56: /* "RENAME" - RENAME FILE */
1633 RenameFile(&context
);
1636 case 0x57: /* FILE DATE AND TIME */
1637 switch (AL_reg(&context
))
1640 GetFileDateTime(&context
);
1643 SetFileDateTime(&context
);
1648 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1649 switch (AL_reg(&context
))
1652 AX_reg(&context
) = 1;
1655 AX_reg(&context
) = 0;
1661 RESET_CFLAG(&context
);
1664 case 0x5a: /* CREATE TEMPORARY FILE */
1665 CreateTempFile(&context
);
1668 case 0x5b: /* CREATE NEW FILE */
1669 CreateNewFile(&context
);
1672 case 0x5d: /* NETWORK */
1674 /* network software not installed */
1675 AX_reg(&context
) = NoNetwork
;
1676 SET_CFLAG(&context
);
1679 case 0x5f: /* NETWORK */
1680 switch (AL_reg(&context
))
1682 case 0x07: /* ENABLE DRIVE */
1683 if (!DOS_EnableDrive(DL_reg(&context
)))
1685 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
1686 AX_reg(&context
) = InvalidDrive
;
1687 SET_CFLAG(&context
);
1692 RESET_CFLAG(&context
);
1695 case 0x08: /* DISABLE DRIVE */
1696 if (!DOS_DisableDrive(DL_reg(&context
)))
1698 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
1699 AX_reg(&context
) = InvalidDrive
;
1700 SET_CFLAG(&context
);
1705 RESET_CFLAG(&context
);
1709 /* network software not installed */
1710 AX_reg(&context
) = NoNetwork
;
1711 SET_CFLAG(&context
);
1716 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1717 strncpy(PTR_SEG_OFF_TO_LIN(ES_reg(&context
),DI_reg(&context
)),
1718 PTR_SEG_OFF_TO_LIN(DS_reg(&context
),SI_reg(&context
)),
1719 strlen(PTR_SEG_OFF_TO_LIN(DS_reg(&context
),SI_reg(&context
))) & 0x7f);
1720 RESET_CFLAG(&context
);
1723 case 0x61: /* UNUSED */
1724 case 0x63: /* UNUSED */
1725 case 0x64: /* OS/2 DOS BOX */
1726 case 0x65: /* GET EXTENDED COUNTRY INFORMATION */
1727 INT_BARF( &context
, 0x21 );
1730 case 0x66: /* GLOBAL CODE PAGE TABLE */
1731 switch (AL_reg(&context
))
1734 DX_reg(&context
) = BX_reg(&context
) = CodePage
;
1735 RESET_CFLAG(&context
);
1738 CodePage
= BX_reg(&context
);
1739 RESET_CFLAG(&context
);
1744 case 0x67: /* SET HANDLE COUNT */
1745 RESET_CFLAG(&context
);
1748 case 0x68: /* "FFLUSH" - COMMIT FILE */
1749 case 0x6a: /* COMMIT FILE */
1750 fsync( BX_reg(&context
) );
1751 RESET_CFLAG(&context
);
1754 case 0x69: /* DISK SERIAL NUMBER */
1755 switch (AL_reg(&context
))
1758 GetDiskSerialNumber(&context
);
1761 SetDiskSerialNumber(&context
);
1766 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1769 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1773 INT_BARF( &context
, 0x21 );
1777 dprintf_int(stddeb
,"ret21: AX %04x, BX %04x, CX %04x, DX %04x, "
1778 "SI %04x, DI %04x, DS %04x, ES %04x EFL %08lx\n",
1779 AX_reg(&context
), BX_reg(&context
), CX_reg(&context
),
1780 DX_reg(&context
), SI_reg(&context
), DI_reg(&context
),
1781 DS_reg(&context
), ES_reg(&context
), EFL_reg(&context
));
1785 void INT21_Init(void)
1787 if ((DosHeapHandle
= GlobalAlloc(GMEM_FIXED
,sizeof(struct DosHeap
))) == 0)
1789 fprintf( stderr
, "INT21_Init: Out of memory\n");
1792 heap
= (struct DosHeap
*) GlobalLock(DosHeapHandle
);
1795 dpbsegptr
= MAKELONG( (int)&heap
->dpb
- (int)heap
, DosHeapHandle
);
1796 heap
->InDosFlag
= 0;
1797 strcpy(heap
->biosdate
, "01/01/80");