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, void *, 0x%x) = 0x%x\n",
307 BX_reg(context), CX_reg(context), size);
310 AX_reg(context) = ExtendedError;
315 AX_reg(context) = size;
316 RESET_CFLAG(context);
320 static void WriteFile(struct sigcontext_struct *context)
325 ptr = PTR_SEG_OFF_TO_LIN (DS_reg(context),DX_reg(context));
327 if (BX_reg(context) == 0) {
328 Error (InvalidHandle, EC_Unknown, EL_Unknown);
329 EAX_reg(context) = InvalidHandle;
334 if (BX_reg(context) < 3) {
335 for (x = 0;x != CX_reg(context);x++) {
336 dprintf_int(stddeb, "%c", *ptr++);
341 AX_reg(context) = CX_reg(context);
342 RESET_CFLAG(context);
344 /* well, this function already handles everything we need */
345 size = _lwrite(BX_reg(context),ptr,CX_reg(context));
346 if (size == -1) { /* HFILE_ERROR == -1 */
348 AX_reg(context) = ExtendedError;
353 AX_reg(context) = size;
354 RESET_CFLAG(context);
358 static void SeekFile(struct sigcontext_struct *context)
360 off_t status, fileoffset;
362 switch (AL_reg(context))
364 case 1: fileoffset = SEEK_CUR;
366 case 2: fileoffset = SEEK_END;
369 case 0: fileoffset = SEEK_SET;
372 status = lseek(BX_reg(context), (CX_reg(context) << 16) + DX_reg(context), fileoffset);
374 dprintf_int (stddeb, "int21: seek (%d, 0x%x, %d) = 0x%lx\n",
375 BX_reg(context), (CX_reg(context) << 16) + DX_reg(context), AL_reg(context), status);
380 AX_reg(context) = ExtendedError;
385 AX_reg(context) = LOWORD(status);
386 DX_reg(context) = HIWORD(status);
387 RESET_CFLAG(context);
390 static void ioctlGetDeviceInfo(struct sigcontext_struct *context)
393 dprintf_int (stddeb, "int21: ioctl (%d, GetDeviceInfo)\n", BX_reg(context));
395 switch (BX_reg(context))
400 DX_reg(context) = 0x80d0 | (1 << (BX_reg(context) != 0));
401 RESET_CFLAG(context);
408 if (fstat(BX_reg(context), &sbuf) < 0)
410 INT_BARF( context, 0x21 );
415 DX_reg(context) = 0x0943;
416 /* bits 0-5 are current drive
417 * bit 6 - file has NOT been written..FIXME: correct?
418 * bit 8 - generate int24 if no diskspace on write/ read past end of file
419 * bit 11 - media not removable
423 RESET_CFLAG(context);
426 static void ioctlGenericBlkDevReq(struct sigcontext_struct *context)
428 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
431 if (BL_reg(context) == 0) drive = DOS_GetDefaultDrive();
432 else drive = BL_reg(context) - 1;
434 if (!DOS_ValidDrive(drive))
436 Error( FileNotFound, EC_NotFound, EL_Disk );
437 AX_reg(context) = FileNotFound;
442 if (CH_reg(context) != 0x08)
444 INT_BARF( context, 0x21 );
447 switch (CL_reg(context)) {
448 case 0x60: /* get device parameters */
449 /* used by w4wgrp's winfile */
450 memset(dataptr, 0, 0x26);
452 dataptr[6] = 0; /* media type */
455 dataptr[1] = 0x05; /* fixed disk */
456 setword(&dataptr[2], 0x01); /* non removable */
457 setword(&dataptr[4], 0x300); /* # of cylinders */
461 dataptr[1] = 0x07; /* block dev, floppy */
462 setword(&dataptr[2], 0x02); /* removable */
463 setword(&dataptr[4], 80); /* # of cylinders */
465 CreateBPB(drive, &dataptr[7]);
466 RESET_CFLAG(context);
469 INT_BARF( context, 0x21 );
473 static void GetSystemDate(struct sigcontext_struct *context)
479 now = localtime(<ime);
481 CX_reg(context) = now->tm_year + 1900;
482 DX_reg(context) = ((now->tm_mon + 1) << 8) | now->tm_mday;
483 AX_reg(context) = now->tm_wday;
486 static void GetSystemTime(struct sigcontext_struct *context)
491 gettimeofday(&tv,NULL); /* Note use of gettimeofday(), instead of time() */
492 now = localtime(&tv.tv_sec);
494 CX_reg(context) = (now->tm_hour<<8) | now->tm_min;
495 DX_reg(context) = (now->tm_sec<<8) | tv.tv_usec/10000;
496 /* Note hundredths of seconds */
499 static void GetExtendedErrorInfo(struct sigcontext_struct *context)
501 AX_reg(context) = ExtendedError;
502 BX_reg(context) = (ErrorClass << 8) | Action;
503 CH_reg(context) = ErrorLocus;
506 static void CreateFile(struct sigcontext_struct *context)
509 handle = open(DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context),
511 O_CREAT | O_TRUNC | O_RDWR, 0666 );
514 AX_reg(context) = ExtendedError;
519 AX_reg(context) = handle;
520 RESET_CFLAG(context);
523 void OpenExistingFile(struct sigcontext_struct *context)
529 switch (AX_reg(context) & 0x0007)
544 if ((handle = open(DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context))),
547 if( Options.allowReadOnly )
548 handle = open( DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context))),
552 dprintf_int (stddeb, "int21: open (%s, %d) = -1\n",
553 DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context))), mode);
555 AX_reg(context) = ExtendedError;
561 dprintf_int (stddeb, "int21: open (%s, %d) = %d\n",
562 DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context),
563 DX_reg(context))), mode, handle);
565 switch (AX_reg(context) & 0x0070)
567 case 0x00: /* compatability mode */
568 case 0x40: /* DENYNONE */
572 case 0x30: /* DENYREAD */
574 "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
575 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)));
576 case 0x10: /* DENYALL */
580 case 0x20: /* DENYWRITE */
591 int result,retries=sharing_retries;
593 result = flock(handle, lock | LOCK_NB);
594 if ( retries && (!result) )
597 for(i=0;i<32768*((int)sharing_pause);i++)
598 result++; /* stop the optimizer */
599 for(i=0;i<32768*((int)sharing_pause);i++)
603 while( (!result) && (!(retries--)) );
608 AX_reg(context) = ExtendedError;
617 AX_reg(context) = handle;
618 RESET_CFLAG(context);
621 static void CloseFile(struct sigcontext_struct *context)
623 dprintf_int (stddeb, "int21: close (%d)\n", BX_reg(context));
625 if (close(BX_reg(context)) == -1)
628 AX_reg(context) = ExtendedError;
633 AX_reg(context) = NoError;
634 RESET_CFLAG(context);
637 static void RenameFile(struct sigcontext_struct *context)
639 char *newname, *oldname;
641 /* FIXME: should not rename over an existing file */
642 dprintf_int(stddeb,"int21: renaming %s to %s\n",
643 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)),
644 (char *)PTR_SEG_OFF_TO_LIN(ES_reg(context),DI_reg(context)));
646 oldname = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context),
648 newname = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(ES_reg(context),
651 rename( oldname, newname);
652 RESET_CFLAG(context);
656 static void MakeDir(struct sigcontext_struct *context)
660 dprintf_int(stddeb,"int21: makedir %s\n", (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)) );
662 if ((dirname = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context),
663 DX_reg(context)) ))== NULL) {
664 Error( CanNotMakeDir, EC_AccessDenied, EL_Disk );
665 AX_reg(context) = CanNotMakeDir;
670 if (mkdir(dirname,0) == -1)
672 Error( CanNotMakeDir, EC_AccessDenied, EL_Disk );
673 AX_reg(context) = CanNotMakeDir;
677 RESET_CFLAG(context);
680 static void ChangeDir(struct sigcontext_struct *context)
683 char *dirname = PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context));
684 drive = DOS_GetDefaultDrive();
685 dprintf_int(stddeb,"int21: changedir %s\n", dirname);
686 if (dirname != NULL && dirname[1] == ':') {
687 drive = toupper(dirname[0]) - 'A';
690 if (!DOS_ChangeDir(drive, dirname))
693 AX_reg(context)=0x03;
697 static void RemoveDir(struct sigcontext_struct *context)
701 dprintf_int(stddeb,"int21: removedir %s\n", (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)) );
703 if ((dirname = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)) ))== NULL) {
704 Error( PathNotFound, EC_NotFound, EL_Disk );
705 AX_reg(context) = PathNotFound;
711 if (strcmp(unixname,DosDrives[drive].CurrentDirectory)) {
712 AL = CanNotRemoveCwd;
716 if (rmdir(dirname) == -1) {
717 Error( AccessDenied, EC_AccessDenied, EL_Disk );
718 AX_reg(context) = AccessDenied;
722 RESET_CFLAG(context);
725 static void FindNext(struct sigcontext_struct *context)
727 struct dosdirent *dp;
729 BYTE *dta = GetCurrentDTA();
731 memcpy(&dp, dta+0x11, sizeof(dp));
733 dprintf_int(stddeb, "int21: FindNext, dta %p, dp %p\n", dta, dp);
735 if ((dp = DOS_readdir(dp)) == NULL) {
736 Error(NoMoreFiles, EC_MediaError , EL_Disk);
737 AX_reg(context) = NoMoreFiles;
741 } /* while (*(dta + 0x0c) != dp->attribute);*/
742 while ( ( dp->search_attribute & dp->attribute) != dp->attribute);
744 *(dta + 0x15) = dp->attribute;
745 setword(&dta[0x0d], dp->entnum);
747 t = localtime(&(dp->filetime));
748 setword(&dta[0x16], (t->tm_hour << 11) + (t->tm_min << 5) +
749 (t->tm_sec / 2)); /* time */
750 setword(&dta[0x18], ((t->tm_year - 80) << 9) + (t->tm_mon << 5) +
751 (t->tm_mday)); /* date */
752 setdword(&dta[0x1a], dp->filesize);
753 strncpy(dta + 0x1e, dp->filename, 13);
756 RESET_CFLAG(context);
758 dprintf_int(stddeb, "int21: FindNext -- (%s) index=%d size=%ld\n", dp->filename, dp->entnum, dp->filesize);
762 static void FindFirst(struct sigcontext_struct *context)
764 BYTE drive, *path = PTR_SEG_OFF_TO_LIN(DS_reg(context),
766 struct dosdirent *dp;
768 BYTE *dta = GetCurrentDTA();
770 dprintf_int(stddeb, "int21: FindFirst path = %s\n", path);
772 if ((*path)&&(path[1] == ':')) {
773 drive = (islower(*path) ? toupper(*path) : *path) - 'A';
775 if (!DOS_ValidDrive(drive)) {
776 Error(InvalidDrive, EC_MediaError , EL_Disk);
777 AX_reg(context) = InvalidDrive;
782 drive = DOS_GetDefaultDrive();
785 memset(dta + 1 , '?', 11);
786 *(dta + 0x0c) = ECX_reg(context) & (FA_LABEL | FA_DIREC);
788 if ((dp = DOS_opendir(path)) == NULL) {
789 Error(PathNotFound, EC_MediaError, EL_Disk);
790 AX_reg(context) = FileNotFound;
795 dp->search_attribute = ECX_reg(context) & (FA_LABEL | FA_DIREC);
796 memcpy(dta + 0x11, &dp, sizeof(dp));
800 static void GetFileDateTime(struct sigcontext_struct *context)
802 struct stat filestat;
805 fstat( BX_reg(context), &filestat );
806 now = localtime (&filestat.st_mtime);
808 CX_reg(context) = ((now->tm_hour * 0x2000) + (now->tm_min * 0x20) + now->tm_sec/2);
809 DX_reg(context) = (((now->tm_year + 1900 - 1980) * 0x200) +
810 (now->tm_mon * 0x20) + now->tm_mday);
812 RESET_CFLAG(context);
815 static void SetFileDateTime(struct sigcontext_struct *context)
818 struct utimbuf filetime;
820 /* FIXME: Argument isn't the name of the file in DS:DX,
821 but the file handle in BX */
822 filename = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context),
825 filetime.actime = 0L;
826 filetime.modtime = filetime.actime;
828 utime(filename, &filetime);
829 RESET_CFLAG(context);
832 static void CreateTempFile(struct sigcontext_struct *context)
837 sprintf(temp,"%s\\win%d.tmp",TempDirectory,(int) getpid());
839 dprintf_int(stddeb,"CreateTempFile %s\n",temp);
841 handle = open(DOS_GetUnixFileName(temp), O_CREAT | O_TRUNC | O_RDWR, 0666);
844 Error( WriteProtected, EC_AccessDenied, EL_Disk );
845 AX_reg(context) = WriteProtected;
850 strcpy(PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)), temp);
852 AX_reg(context) = handle;
853 RESET_CFLAG(context);
856 static void CreateNewFile(struct sigcontext_struct *context)
860 if ((handle = open(DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)) ),
861 O_CREAT | O_EXCL | O_RDWR, 0666)) == -1)
863 Error( WriteProtected, EC_AccessDenied, EL_Disk );
864 AX_reg(context) = WriteProtected;
869 AX_reg(context) = handle;
870 RESET_CFLAG(context);
873 static void GetCurrentDirectory(struct sigcontext_struct *context)
877 if (DL_reg(context) == 0) drive = DOS_GetDefaultDrive();
878 else drive = DL_reg(context) - 1;
880 if (!DOS_ValidDrive(drive))
882 Error( InvalidDrive, EC_NotFound, EL_Disk );
883 AX_reg(context) = InvalidDrive;
888 strcpy(PTR_SEG_OFF_TO_LIN(DS_reg(context),SI_reg(context)),
889 DOS_GetCurrentDir(drive) );
890 RESET_CFLAG(context);
893 static void GetDiskSerialNumber(struct sigcontext_struct *context)
896 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
899 if (BL_reg(context) == 0) drive = DOS_GetDefaultDrive();
900 else drive = BL_reg(context) - 1;
902 if (!DOS_ValidDrive(drive))
904 Error( InvalidDrive, EC_NotFound, EL_Disk );
905 AX_reg(context) = InvalidDrive;
910 DOS_GetSerialNumber(drive, &serialnumber);
913 setdword(&dataptr[2], serialnumber);
914 strncpy(dataptr + 6, DOS_GetVolumeLabel(drive), 8);
915 strncpy(dataptr + 0x11, "FAT16 ", 8);
918 RESET_CFLAG(context);
921 static void SetDiskSerialNumber(struct sigcontext_struct *context)
924 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
927 if (BL_reg(context) == 0) drive = DOS_GetDefaultDrive();
928 else drive = BL_reg(context) - 1;
930 if (!DOS_ValidDrive(drive))
932 Error( InvalidDrive, EC_NotFound, EL_Disk );
933 AX_reg(context) = InvalidDrive;
938 serialnumber = dataptr[1] + (dataptr[2] << 8) + (dataptr[3] << 16) +
941 DOS_SetSerialNumber(drive, serialnumber);
943 RESET_CFLAG(context);
946 static void DumpFCB(BYTE *fcb)
952 for (y = 0; y !=2 ; y++) {
953 for (x = 0; x!=15;x++)
954 dprintf_int(stddeb, "%02x ", *fcb++);
955 dprintf_int(stddeb,"\n");
959 /* microsoft's programmers should be shot for using CP/M style int21
960 calls in Windows for Workgroup's winfile.exe */
962 static void FindFirstFCB(struct sigcontext_struct *context)
964 BYTE *fcb = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
965 struct fcb *standard_fcb;
966 struct fcb *output_fcb;
970 BYTE *dta = GetCurrentDTA();
976 standard_fcb = (struct fcb *)(fcb + 7);
977 output_fcb = (struct fcb *)(dta + 7);
982 standard_fcb = (struct fcb *)fcb;
983 output_fcb = (struct fcb *)dta;
986 if (standard_fcb->drive)
988 drive = standard_fcb->drive - 1;
989 if (!DOS_ValidDrive(drive))
991 Error (InvalidDrive, EC_MediaError, EL_Disk);
992 AX_reg(context) = 0xff;
997 drive = DOS_GetDefaultDrive();
999 output_fcb->drive = drive;
1003 if (*(fcb+6) & FA_LABEL) /* return volume label */
1005 *(dta+6) = FA_LABEL;
1006 memset(&output_fcb->name, ' ', 11);
1007 if (DOS_GetVolumeLabel(drive) != NULL)
1009 strncpy(output_fcb->name, DOS_GetVolumeLabel(drive), 11);
1010 AX_reg(context) = 0x00;
1016 strncpy(output_fcb->name, standard_fcb->name, 11);
1018 *(dta+6) = ( *(fcb+6) & (!FA_DIREC));
1020 sprintf(path,"%c:*.*",drive+'A');
1021 if ((output_fcb->directory = DOS_opendir(path))==NULL)
1023 Error (PathNotFound, EC_MediaError, EL_Disk);
1024 AX_reg(context) = 0xff;
1031 static void DeleteFileFCB(struct sigcontext_struct *context)
1033 BYTE *fcb = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
1035 struct dosdirent *dp;
1036 char temp[256], *ptr;
1043 drive = DOS_GetDefaultDrive();
1045 strcpy(temp, DOS_GetCurrentDir(drive));
1047 strncat(temp, fcb + 1, 8);
1048 ChopOffWhiteSpace(temp);
1049 strncat(temp, fcb + 9, 3);
1050 ChopOffWhiteSpace(temp);
1052 if ((dp = DOS_opendir(temp)) == NULL) {
1053 Error(InvalidDrive, EC_MediaError , EL_Disk);
1054 AX_reg(context) = 0xff;
1058 strcpy(temp, DOS_GetCurrentDir(drive) );
1061 ptr = temp + strlen(temp);
1063 while (DOS_readdir(dp) != NULL)
1065 strcpy(ptr, dp->filename);
1066 dprintf_int(stddeb, "int21: delete file %s\n", temp);
1067 /* unlink(DOS_GetUnixFileName(temp)); */
1070 AX_reg(context) = 0;
1073 static void RenameFileFCB(struct sigcontext_struct *context)
1075 BYTE *fcb = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
1077 struct dosdirent *dp;
1078 char temp[256], oldname[256], newname[256], *oldnameptr, *newnameptr;
1085 drive = DOS_GetDefaultDrive();
1087 strcpy(temp, DOS_GetCurrentDir(drive));
1089 strncat(temp, fcb + 1, 8);
1090 ChopOffWhiteSpace(temp);
1091 strncat(temp, fcb + 9, 3);
1092 ChopOffWhiteSpace(temp);
1094 if ((dp = DOS_opendir(temp)) == NULL) {
1095 Error(InvalidDrive, EC_MediaError , EL_Disk);
1096 AX_reg(context) = 0xff;
1100 strcpy(oldname, DOS_GetCurrentDir(drive) );
1101 strcat(oldname, "\\");
1102 oldnameptr = oldname + strlen(oldname);
1104 strcpy(newname, DOS_GetCurrentDir(drive) );
1105 strcat(newname, "\\");
1106 newnameptr = newname + strlen(newname);
1108 while (DOS_readdir(dp) != NULL)
1110 strcpy(oldnameptr, dp->filename);
1111 strcpy(newnameptr, fcb + 1);
1112 dprintf_int(stddeb, "int21: renamefile %s -> %s\n",
1116 AX_reg(context) = 0;
1121 static void fLock (struct sigcontext_struct * context)
1124 int result,retries=sharing_retries;
1126 f.l_start = MAKELONG(DX_reg(context),CX_reg(context));
1127 f.l_len = MAKELONG(DI_reg(context),SI_reg(context));
1131 switch ( AX_reg(context) & 0xff )
1133 case 0x00: /* LOCK */
1137 case 0x01: /* UNLOCK */
1142 AX_reg(context) = 0x0001;
1148 result = fcntl(BX_reg(context),F_SETLK,&f);
1149 if ( retries && (!result) )
1152 for(i=0;i<32768*((int)sharing_pause);i++)
1153 result++; /* stop the optimizer */
1154 for(i=0;i<32768*((int)sharing_pause);i++)
1158 while( (!result) && (!(retries--)) );
1163 AX_reg(context) = ExtendedError;
1169 RESET_CFLAG(context);
1173 static void GetFileAttribute (struct sigcontext_struct * context)
1175 char *filename = PTR_SEG_OFF_TO_LIN (DS_reg(context),DX_reg(context));
1179 res = stat(DOS_GetUnixFileName(filename), &s);
1183 AX_reg(context) = ExtendedError;
1188 CX_reg(context) = 0;
1189 if (S_ISDIR(s.st_mode))
1190 CX_reg(context) |= 0x10;
1191 if ((S_IWRITE & s.st_mode) != S_IWRITE)
1192 CX_reg(context) |= 0x01;
1194 dprintf_int (stddeb, "int21: GetFileAttributes (%s) = 0x%x\n",
1195 filename, CX_reg(context) );
1197 RESET_CFLAG(context);
1202 extern void LOCAL_PrintHeap (WORD ds);
1204 /***********************************************************************
1205 * DOS3Call (KERNEL.102)
1207 void DOS3Call( struct sigcontext_struct context )
1211 if (AH_reg(&context) == 0x59)
1213 GetExtendedErrorInfo(&context);
1219 switch(AH_reg(&context))
1221 case 0x00: /* TERMINATE PROGRAM */
1222 TASK_KillCurrentTask( 0 );
1225 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1226 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1227 case 0x03: /* READ CHARACTER FROM STDAUX */
1228 case 0x04: /* WRITE CHARACTER TO STDAUX */
1229 case 0x05: /* WRITE CHARACTER TO PRINTER */
1230 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1231 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
1232 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1233 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1234 case 0x0a: /* BUFFERED INPUT */
1235 case 0x0b: /* GET STDIN STATUS */
1236 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
1237 case 0x0f: /* OPEN FILE USING FCB */
1238 case 0x10: /* CLOSE FILE USING FCB */
1239 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1240 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1241 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1242 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1243 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1244 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1245 case 0x23: /* GET FILE SIZE FOR FCB */
1246 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1247 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1248 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1249 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1250 case 0x29: /* PARSE FILENAME INTO FCB */
1251 case 0x2e: /* SET VERIFY FLAG */
1252 INT_BARF( &context, 0x21 );
1255 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
1256 "SWITCHAR" - SET SWITCH CHARACTER
1257 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
1258 case 0x54: /* GET VERIFY FLAG */
1259 INT_BARF( &context, 0x21 );
1262 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1266 case 0x6b: /* NULL FUNCTION */
1267 AL_reg(&context) = 0;
1270 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1274 case 0x0d: /* DISK BUFFER FLUSH */
1275 RESET_CFLAG(&context); /* dos 6+ only */
1278 case 0x0e: /* SELECT DEFAULT DRIVE */
1279 if (!DOS_ValidDrive(DL_reg(&context)))
1280 Error (InvalidDrive, EC_MediaError, EL_Disk);
1283 DOS_SetDefaultDrive(DL_reg(&context));
1286 AL_reg(&context) = MAX_DOS_DRIVES;
1289 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1290 FindFirstFCB(&context);
1293 case 0x13: /* DELETE FILE USING FCB */
1294 DeleteFileFCB(&context);
1297 case 0x17: /* RENAME FILE USING FCB */
1298 RenameFileFCB(&context);
1301 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1302 AL_reg(&context) = DOS_GetDefaultDrive();
1306 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1308 TDB *pTask = (TDB *)GlobalLock( GetCurrentTask() );
1309 pTask->dta = MAKELONG( DX_reg(&context), DS_reg(&context) );
1310 dprintf_int(stddeb, "int21: Set DTA: %08lx\n", pTask->dta);
1314 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1315 DL_reg(&context) = 0;
1316 GetDriveAllocInfo(&context);
1319 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1320 GetDriveAllocInfo(&context);
1323 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1324 GetDrivePB(&context, DOS_GetDefaultDrive());
1327 case 0x25: /* SET INTERRUPT VECTOR */
1328 INT_SetHandler( AL_reg(&context),
1329 MAKELONG( DX_reg(&context), DS_reg(&context) ) );
1332 case 0x2a: /* GET SYSTEM DATE */
1333 GetSystemDate(&context);
1336 case 0x2b: /* SET SYSTEM DATE */
1337 fprintf( stdnimp, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1338 DL_reg(&context), DH_reg(&context), CX_reg(&context) );
1339 AL_reg(&context) = 0; /* Let's pretend we succeeded */
1342 case 0x2c: /* GET SYSTEM TIME */
1343 GetSystemTime(&context);
1346 case 0x2d: /* SET SYSTEM TIME */
1347 fprintf( stdnimp, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1348 CH_reg(&context), CL_reg(&context),
1349 DH_reg(&context), DL_reg(&context) );
1350 AL_reg(&context) = 0; /* Let's pretend we succeeded */
1353 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1355 TDB *pTask = (TDB *)GlobalLock( GetCurrentTask() );
1356 ES_reg(&context) = SELECTOROF( pTask->dta );
1357 BX_reg(&context) = OFFSETOF( pTask->dta );
1361 case 0x30: /* GET DOS VERSION */
1362 AX_reg(&context) = DOSVERSION;
1363 BX_reg(&context) = 0x0012; /* 0x123456 is Wine's serial # */
1364 CX_reg(&context) = 0x3456;
1367 case 0x31: /* TERMINATE AND STAY RESIDENT */
1368 INT_BARF( &context, 0x21 );
1371 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1372 GetDrivePB(&context, (DL_reg(&context) == 0) ?
1373 (DOS_GetDefaultDrive()) : (DL_reg(&context)-1));
1376 case 0x33: /* MULTIPLEXED */
1377 switch (AL_reg(&context))
1379 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1380 DL_reg(&context) = 0;
1383 case 0x01: /* SET EXTENDED BREAK STATE */
1386 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1387 DL_reg(&context) = 0;
1390 case 0x05: /* GET BOOT DRIVE */
1391 DL_reg(&context) = 2;
1392 /* c: is Wine's bootdrive */
1395 case 0x06: /* GET TRUE VERSION NUMBER */
1396 BX_reg(&context) = DOSVERSION;
1397 DX_reg(&context) = 0x00;
1401 INT_BARF( &context, 0x21 );
1406 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1407 ES_reg(&context) = DosHeapHandle;
1408 BX_reg(&context) = (int)&heap->InDosFlag - (int)heap;
1411 case 0x35: /* GET INTERRUPT VECTOR */
1413 SEGPTR addr = INT_GetHandler( AL_reg(&context) );
1414 ES_reg(&context) = SELECTOROF(addr);
1415 BX_reg(&context) = OFFSETOF(addr);
1419 case 0x36: /* GET FREE DISK SPACE */
1420 GetFreeDiskSpace(&context);
1423 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1424 AX_reg(&context) = 0x02; /* no country support available */
1425 SET_CFLAG(&context);
1428 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1432 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1433 RemoveDir(&context);
1436 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1437 ChangeDir(&context);
1440 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1441 CreateFile(&context);
1444 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1445 OpenExistingFile(&context);
1448 case 0x3e: /* "CLOSE" - CLOSE FILE */
1449 CloseFile(&context);
1452 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1456 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1457 WriteFile(&context);
1460 case 0x41: /* "UNLINK" - DELETE FILE */
1461 if (unlink( DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(&context),DX_reg(&context))) ) == -1) {
1463 AX_reg(&context) = ExtendedError;
1464 SET_CFLAG(&context);
1468 RESET_CFLAG(&context);
1471 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1475 case 0x43: /* FILE ATTRIBUTES */
1476 switch (AL_reg(&context))
1479 GetFileAttribute(&context);
1482 RESET_CFLAG(&context);
1487 case 0x44: /* IOCTL */
1488 switch (AL_reg(&context))
1491 ioctlGetDeviceInfo(&context);
1494 case 0x08: /* Check if drive is removable. */
1495 drive = BL_reg(&context) ? (BL_reg(&context) - 1)
1496 : DOS_GetDefaultDrive();
1497 if(!DOS_ValidDrive(drive))
1499 Error( InvalidDrive, EC_NotFound, EL_Disk );
1500 AX_reg(&context) = InvalidDrive;
1501 SET_CFLAG(&context);
1506 AX_reg(&context) = 1; /* not removable */
1508 AX_reg(&context) = 0; /* removable */
1509 RESET_CFLAG(&context);
1513 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1514 drive = BL_reg(&context) ? (BL_reg(&context) - 1)
1515 : DOS_GetDefaultDrive();
1516 if(!DOS_ValidDrive(drive))
1518 Error( InvalidDrive, EC_NotFound, EL_Disk );
1519 AX_reg(&context) = InvalidDrive;
1520 SET_CFLAG(&context);
1524 DX_reg(&context) = (1<<9) | (1<<12) | (1<<15);
1525 RESET_CFLAG(&context);
1528 case 0x0a: /* check if handle (BX) is remote */
1529 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1532 DX_reg(&context) = 0;
1533 RESET_CFLAG(&context);
1535 case 0x0b: /* SET SHARING RETRY COUNT */
1536 if (!CX_reg(&context))
1538 AX_reg(&context) = 1;
1539 SET_CFLAG(&context);
1542 sharing_pause = CX_reg(&context);
1543 if (!DX_reg(&context))
1544 sharing_retries = DX_reg(&context);
1545 RESET_CFLAG(&context);
1549 ioctlGenericBlkDevReq(&context);
1552 case 0x0F: /* Set logical drive mapping */
1553 /* FIXME: Not implemented at the moment, always returns error
1555 AX_reg(&context) = 0x0001; /* invalid function */
1556 SET_CFLAG(&context);
1560 INT_BARF( &context, 0x21 );
1565 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1566 if ((AX_reg(&context) = dup(BX_reg(&context))) == 0xffff)
1569 AX_reg(&context) = ExtendedError;
1570 SET_CFLAG(&context);
1572 else RESET_CFLAG(&context);
1575 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1576 if (dup2( BX_reg(&context), CX_reg(&context) ) == -1)
1579 AX_reg(&context) = ExtendedError;
1580 SET_CFLAG(&context);
1582 else RESET_CFLAG(&context);
1585 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1586 GetCurrentDirectory(&context);
1587 AX_reg(&context) = 0x0100;
1588 /* intlist: many Microsoft products for Windows rely on this */
1591 case 0x48: /* ALLOCATE MEMORY */
1592 case 0x49: /* FREE MEMORY */
1593 case 0x4a: /* RESIZE MEMORY BLOCK */
1594 INT_BARF( &context, 0x21 );
1597 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1598 WinExec( PTR_SEG_OFF_TO_LIN(DS_reg(&context),DX_reg(&context)),
1602 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1603 TASK_KillCurrentTask( AL_reg(&context) );
1606 case 0x4d: /* GET RETURN CODE */
1607 AX_reg(&context) = NoError; /* normal exit */
1610 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1611 FindFirst(&context);
1614 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1618 case 0x51: /* GET PSP ADDRESS */
1619 case 0x62: /* GET PSP ADDRESS */
1620 /* FIXME: should we return the original DOS PSP upon */
1621 /* Windows startup ? */
1622 BX_reg(&context) = GetCurrentPDB();
1625 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1626 ES_reg(&context) = 0x0;
1627 BX_reg(&context) = 0x0;
1628 INT_BARF( &context, 0x21 );
1631 case 0x56: /* "RENAME" - RENAME FILE */
1632 RenameFile(&context);
1635 case 0x57: /* FILE DATE AND TIME */
1636 switch (AL_reg(&context))
1639 GetFileDateTime(&context);
1642 SetFileDateTime(&context);
1647 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1648 switch (AL_reg(&context))
1651 AX_reg(&context) = 1;
1654 AX_reg(&context) = 0;
1660 RESET_CFLAG(&context);
1663 case 0x5a: /* CREATE TEMPORARY FILE */
1664 CreateTempFile(&context);
1667 case 0x5b: /* CREATE NEW FILE */
1668 CreateNewFile(&context);
1671 case 0x5d: /* NETWORK */
1673 /* network software not installed */
1674 AX_reg(&context) = NoNetwork;
1675 SET_CFLAG(&context);
1678 case 0x5f: /* NETWORK */
1679 switch (AL_reg(&context))
1681 case 0x07: /* ENABLE DRIVE */
1682 if (!DOS_EnableDrive(DL_reg(&context)))
1684 Error(InvalidDrive, EC_MediaError , EL_Disk);
1685 AX_reg(&context) = InvalidDrive;
1686 SET_CFLAG(&context);
1691 RESET_CFLAG(&context);
1694 case 0x08: /* DISABLE DRIVE */
1695 if (!DOS_DisableDrive(DL_reg(&context)))
1697 Error(InvalidDrive, EC_MediaError , EL_Disk);
1698 AX_reg(&context) = InvalidDrive;
1699 SET_CFLAG(&context);
1704 RESET_CFLAG(&context);
1708 /* network software not installed */
1709 AX_reg(&context) = NoNetwork;
1710 SET_CFLAG(&context);
1715 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1716 strncpy(PTR_SEG_OFF_TO_LIN(ES_reg(&context),DI_reg(&context)),
1717 PTR_SEG_OFF_TO_LIN(DS_reg(&context),SI_reg(&context)),
1718 strlen(PTR_SEG_OFF_TO_LIN(DS_reg(&context),SI_reg(&context))) & 0x7f);
1719 RESET_CFLAG(&context);
1722 case 0x61: /* UNUSED */
1723 case 0x63: /* UNUSED */
1724 case 0x64: /* OS/2 DOS BOX */
1725 case 0x65: /* GET EXTENDED COUNTRY INFORMATION */
1726 INT_BARF( &context, 0x21 );
1729 case 0x66: /* GLOBAL CODE PAGE TABLE */
1730 switch (AL_reg(&context))
1733 DX_reg(&context) = BX_reg(&context) = CodePage;
1734 RESET_CFLAG(&context);
1737 CodePage = BX_reg(&context);
1738 RESET_CFLAG(&context);
1743 case 0x67: /* SET HANDLE COUNT */
1744 RESET_CFLAG(&context);
1747 case 0x68: /* "FFLUSH" - COMMIT FILE */
1748 case 0x6a: /* COMMIT FILE */
1749 fsync( BX_reg(&context) );
1750 RESET_CFLAG(&context);
1753 case 0x69: /* DISK SERIAL NUMBER */
1754 switch (AL_reg(&context))
1757 GetDiskSerialNumber(&context);
1760 SetDiskSerialNumber(&context);
1765 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1769 INT_BARF( &context, 0x21 );
1773 dprintf_int(stddeb,"ret21: AX %04x, BX %04x, CX %04x, DX %04x, "
1774 "SI %04x, DI %04x, DS %04x, ES %04x EFL %08lx\n",
1775 AX_reg(&context), BX_reg(&context), CX_reg(&context),
1776 DX_reg(&context), SI_reg(&context), DI_reg(&context),
1777 DS_reg(&context), ES_reg(&context), EFL_reg(&context));
1781 void INT21_Init(void)
1783 if ((DosHeapHandle = GlobalAlloc(GMEM_FIXED,sizeof(struct DosHeap))) == 0)
1785 fprintf( stderr, "INT21_Init: Out of memory\n");
1788 heap = (struct DosHeap *) GlobalLock(DosHeapHandle);
1791 dpbsegptr = MAKELONG( (int)&heap->dpb - (int)heap, DosHeapHandle );
1792 heap->InDosFlag = 0;
1793 strcpy(heap->biosdate, "01/01/80");