2 * (c) 1993, 1994 Erik Bos
14 #include <sys/types.h>
23 #include "registers.h"
32 /* SVR4 DOESNTdo 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 static int Error(int e
, int class, int el
)
88 return DOS_ERROR( e
, class, SA_Abort
, el
);
92 BYTE
*GetCurrentDTA(void)
94 TDB
*pTask
= (TDB
*)GlobalLock( GetCurrentTask() );
95 return (BYTE
*)PTR_SEG_TO_LIN( pTask
->dta
);
99 void ChopOffWhiteSpace(char *string
)
103 for (length
= strlen(string
) ; length
; length
--)
104 if (string
[length
] == ' ')
105 string
[length
] = '\0';
108 static void CreateBPB(int drive
, BYTE
*data
)
113 setword(&data
[3], 0);
115 setword(&data
[6], 240);
116 setword(&data
[8], 64000);
118 setword(&data
[0x0b], 40);
119 setword(&data
[0x0d], 56);
120 setword(&data
[0x0f], 2);
121 setword(&data
[0x11], 0);
122 setword(&data
[0x1f], 800);
124 setword(&data
[0x22], 1);
125 } else { /* 1.44mb */
128 setword(&data
[3], 0);
130 setword(&data
[6], 240);
131 setword(&data
[8], 2880);
133 setword(&data
[0x0b], 6);
134 setword(&data
[0x0d], 18);
135 setword(&data
[0x0f], 2);
136 setword(&data
[0x11], 0);
137 setword(&data
[0x1f], 80);
139 setword(&data
[0x22], 2);
143 static void GetFreeDiskSpace(struct sigcontext_struct
*context
)
146 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
148 if (!DRIVE_IsValid(drive
))
150 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
151 AX_reg(context
) = 0xffff;
155 if (!DOS_GetFreeSpace(drive
, &size
, &available
)) {
156 DOS_ERROR( ER_GeneralFailure
, EC_MediaError
, SA_Abort
, EL_Disk
);
157 AX_reg(context
) = 0xffff;
161 AX_reg(context
) = (drive
< 2) ? 1 : 64; /* 64 for hard-disks, 1 for diskettes */
162 CX_reg(context
) = 512;
163 BX_reg(context
) = (available
/ (CX_reg(context
) * AX_reg(context
)));
164 DX_reg(context
) = (size
/ (CX_reg(context
) * AX_reg(context
)));
168 static void GetDriveAllocInfo(struct sigcontext_struct
*context
)
170 long size
, available
;
171 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
173 if (!DRIVE_IsValid(drive
))
176 CX_reg(context
) = 512;
178 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
182 if (!DOS_GetFreeSpace(drive
, &size
, &available
))
184 DOS_ERROR( ER_GeneralFailure
, EC_MediaError
, SA_Abort
, EL_Disk
);
185 AX_reg(context
) = 0xffff;
189 AX_reg(context
) = (drive
< 2) ? 1 : 64; /* 64 for hard-disks, 1 for diskettes */
190 CX_reg(context
) = 512;
191 DX_reg(context
) = (size
/ (CX_reg(context
) * AX_reg(context
)));
193 heap
->mediaID
= 0xf0;
195 DS_reg(context
) = DosHeapHandle
;
196 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
200 static void GetDrivePB(struct sigcontext_struct
*context
, int drive
)
202 if(!DRIVE_IsValid(drive
))
204 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
205 AX_reg(context
) = 0x00ff;
209 dprintf_int(stddeb
, "int21: GetDrivePB not fully implemented.\n");
211 /* FIXME: I have no idea what a lot of this information should
212 * say or whether it even really matters since we're not allowing
213 * direct block access. However, some programs seem to depend on
214 * getting at least _something_ back from here. The 'next' pointer
215 * does worry me, though. Should we have a complete table of
216 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
218 dpb
->drive_num
= dpb
->unit_num
= drive
; /* The same? */
219 dpb
->sector_size
= 512;
220 dpb
->high_sector
= 1;
221 dpb
->shift
= drive
< 2 ? 0 : 6; /* 6 for HD, 0 for floppy */
224 dpb
->dir_entries
= 2;
226 dpb
->high_cluster
= 64000;
227 dpb
->sectors_in_FAT
= 1;
229 dpb
->driver_head
= 0;
230 dpb
->media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
231 dpb
->access_flag
= 0;
233 dpb
->free_search
= 0;
234 dpb
->free_clusters
= 0xFFFF; /* unknown */
236 AL_reg(context
) = 0x00;
237 DS_reg(context
) = SELECTOROF(dpbsegptr
);
238 BX_reg(context
) = OFFSETOF(dpbsegptr
);
243 static void ioctlGetDeviceInfo(struct sigcontext_struct
*context
)
246 dprintf_int (stddeb
, "int21: ioctl (%d, GetDeviceInfo)\n", BX_reg(context
));
248 switch (BX_reg(context
))
252 DX_reg(context
) = 2; /* FIXME */
255 DX_reg(context
) = 0x80d0 | (1 << (BX_reg(context
) != 0));
256 RESET_CFLAG(context
);
263 if (fstat(BX_reg(context
), &sbuf
) < 0)
265 INT_BARF( context
, 0x21 );
270 DX_reg(context
) = 0x0943;
271 /* bits 0-5 are current drive
272 * bit 6 - file has NOT been written..FIXME: correct?
273 * bit 8 - generate int24 if no diskspace on write/ read past end of file
274 * bit 11 - media not removable
278 RESET_CFLAG(context
);
281 static void ioctlGenericBlkDevReq(struct sigcontext_struct
*context
)
283 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
284 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
286 if (!DRIVE_IsValid(drive
))
288 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
289 AX_reg(context
) = DOS_ExtendedError
;
294 if (CH_reg(context
) != 0x08)
296 INT_BARF( context
, 0x21 );
299 switch (CL_reg(context
)) {
300 case 0x60: /* get device parameters */
301 /* used by w4wgrp's winfile */
302 memset(dataptr
, 0, 0x26);
304 dataptr
[6] = 0; /* media type */
307 dataptr
[1] = 0x05; /* fixed disk */
308 setword(&dataptr
[2], 0x01); /* non removable */
309 setword(&dataptr
[4], 0x300); /* # of cylinders */
313 dataptr
[1] = 0x07; /* block dev, floppy */
314 setword(&dataptr
[2], 0x02); /* removable */
315 setword(&dataptr
[4], 80); /* # of cylinders */
317 CreateBPB(drive
, &dataptr
[7]);
318 RESET_CFLAG(context
);
321 INT_BARF( context
, 0x21 );
325 static void GetSystemDate(struct sigcontext_struct
*context
)
331 now
= localtime(<ime
);
333 CX_reg(context
) = now
->tm_year
+ 1900;
334 DX_reg(context
) = ((now
->tm_mon
+ 1) << 8) | now
->tm_mday
;
335 AX_reg(context
) = now
->tm_wday
;
338 static void INT21_GetSystemTime(struct sigcontext_struct
*context
)
344 gettimeofday(&tv
,NULL
); /* Note use of gettimeofday(), instead of time() */
346 now
= localtime(&seconds
);
348 CX_reg(context
) = (now
->tm_hour
<<8) | now
->tm_min
;
349 DX_reg(context
) = (now
->tm_sec
<<8) | tv
.tv_usec
/10000;
350 /* Note hundredths of seconds */
353 static void CreateFile(struct sigcontext_struct
*context
)
355 AX_reg(context
) = _lcreat( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
356 DX_reg(context
) ), CX_reg(context
) );
357 if (AX_reg(context
) == (WORD
)HFILE_ERROR
)
359 AX_reg(context
) = DOS_ExtendedError
;
365 void OpenExistingFile(struct sigcontext_struct
*context
)
367 AX_reg(context
) = _lopen( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
369 if (AX_reg(context
) == (WORD
)HFILE_ERROR
)
371 AX_reg(context
) = DOS_ExtendedError
;
379 dprintf_int (stddeb
, "int21: open (%s, %d) = %d\n",
380 DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context
),
381 DX_reg(context
))), mode
, handle
);
383 switch (AX_reg(context
) & 0x0070)
385 case 0x00: /* compatability mode */
386 case 0x40: /* DENYNONE */
390 case 0x30: /* DENYREAD */
392 "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
393 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)));
394 case 0x10: /* DENYALL */
398 case 0x20: /* DENYWRITE */
409 int result
,retries
=sharing_retries
;
412 printf("Should call flock and needs porting to lockf\n");
416 result
= flock(handle
, lock
| LOCK_NB
);
418 if ( retries
&& (!result
) )
421 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
422 result
++; /* stop the optimizer */
423 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
427 while( (!result
) && (!(retries
--)) );
432 AX_reg(context
) = ExtendedError
;
441 AX_reg(context
) = handle
;
442 RESET_CFLAG(context
);
446 static void CloseFile(struct sigcontext_struct
*context
)
448 if ((AX_reg(context
) = _lclose( BX_reg(context
) )) != 0)
450 AX_reg(context
) = DOS_ExtendedError
;
455 void ExtendedOpenCreateFile(struct sigcontext_struct
*context
)
457 dprintf_int(stddeb
, "int21: extended open/create: file= %s \n",
458 DOSFS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context
),SI_reg(context
)),FALSE
));
459 /* Shuffle arguments to call OpenExistingFile */
460 AL_reg(context
) = BL_reg(context
);
461 DX_reg(context
) = SI_reg(context
);
462 /* BX,CX and DX should be preserved */
463 OpenExistingFile(context
);
464 if ((EFL_reg(context
) & 0x0001)==0)
466 dprintf_int(stddeb
, "int21: extended open/create %s exists \n",
467 DOSFS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context
),SI_reg(context
)),TRUE
));
468 /* Now decide what do do */
469 if ((DL_reg(context
) & 0x0007)== 0)
471 BX_reg(context
) = AX_reg(context
);
473 AX_reg(context
) = 0x0050;/*File exists*/
476 dprintf_int(stddeb
, "int21: extended open/create: failed because file exixts \n");
479 if ((DL_reg(context
) & 0x0007)== 2) {
480 /* Truncate it, but first check if opend for write */
481 if ((BL_reg(context
) & 0x0007)== 0) {
482 BX_reg(context
) = AX_reg(context
);
484 dprintf_int(stddeb
, "int21: extended open/create: failed, trunc on ro file");
485 AX_reg(context
) = 0x000C;/*Access code invalid*/
490 /* Shuffle arguments to call CloseFile */
491 dprintf_int(stddeb
, "int21: extended open/create: Closing before truncate\n");
492 BX_reg(context
) = AX_reg(context
);
493 /* BX and DX should be preserved */
495 if (EFL_reg(context
) & 0x0001) {
496 dprintf_int(stddeb
, "int21: extended open/create: close before trunc failed");
497 AX_reg(context
) = 0x0019;/*Seek Error*/
501 /* Shuffle arguments to call CreateFile */
502 dprintf_int(stddeb
, "int21: extended open/create: Truncating\n");
503 AL_reg(context
) = BL_reg(context
);
504 /* CX is still the same */
505 DX_reg(context
) = SI_reg(context
);
507 if (EFL_reg(context
) & 0x0001) { /*no file open, flags set */
508 dprintf_int(stddeb
, "int21: extended open/create: truncfailed");
517 else /* file does not exist */
519 dprintf_int(stddeb
, "int21: extended open/create %s dosen't exists \n",
520 DOSFS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS_reg(context
),SI_reg(context
)),FALSE
));
521 if ((DL_reg(context
) & 0x00F0)== 0) {
524 dprintf_int(stddeb
, "int21: extended open/create: failed, file dosen't exist\n");
527 /* Shuffle arguments to call CreateFile */
528 dprintf_int(stddeb
, "int21: extended open/create: Creating\n");
529 AL_reg(context
) = BL_reg(context
);
530 /* CX should still be the same */
531 DX_reg(context
) = SI_reg(context
);
533 if (EFL_reg(context
) & 0x0001) { /*no file open, flags set */
534 dprintf_int(stddeb
, "int21: extended open/create: create failed\n");
543 static int INT21_RenameFile(struct sigcontext_struct
*context
)
545 const char *newname
, *oldname
;
548 /* FIXME: should not rename over an existing file */
549 dprintf_int(stddeb
,"int21: renaming %s to %s\n",
550 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
551 (char *)PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
)));
553 oldname
= DOSFS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
554 DX_reg(context
)), TRUE
);
555 if (!oldname
) return 0;
556 buffer
= xstrdup( oldname
);
557 newname
= DOSFS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(ES_reg(context
),
558 DI_reg(context
)), FALSE
);
565 if (rename( buffer
, newname
) == -1)
576 static void INT21_ChangeDir(struct sigcontext_struct
*context
)
579 char *dirname
= PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
));
581 dprintf_int(stddeb
,"int21: changedir %s\n", dirname
);
582 if (dirname
[1] == ':')
584 drive
= toupper(dirname
[0]) - 'A';
587 else drive
= DRIVE_GetCurrentDrive();
588 if (!DRIVE_Chdir( drive
, dirname
))
590 AX_reg(context
) = DOS_ExtendedError
;
596 static int INT21_FindFirst(struct sigcontext_struct
*context
)
598 const char *path
, *unixPath
, *mask
;
600 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
602 path
= (const char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
603 dta
->unixPath
= NULL
;
604 if (!(unixPath
= DOSFS_GetUnixFileName( path
, FALSE
)))
606 AX_reg(context
) = DOS_ExtendedError
;
610 dta
->unixPath
= xstrdup( unixPath
);
611 p
= strrchr( dta
->unixPath
, '/' );
613 if (!(mask
= DOSFS_ToDosFCBFormat( p
+ 1 )))
615 free( dta
->unixPath
);
616 dta
->unixPath
= NULL
;
617 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
618 AX_reg(context
) = ER_FileNotFound
;
622 memcpy( dta
->mask
, mask
, sizeof(dta
->mask
) );
623 dta
->drive
= (path
[1] == ':') ? toupper(path
[0]) - 'A'
624 : DRIVE_GetCurrentDrive();
626 dta
->search_attr
= CL_reg(context
);
631 static int INT21_FindNext(struct sigcontext_struct
*context
)
633 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
637 if (!dta
->unixPath
) return 0;
638 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, dta
->drive
,
639 dta
->search_attr
, dta
->count
, &entry
)))
641 free( dta
->unixPath
);
642 dta
->unixPath
= NULL
;
645 if ((int)dta
->count
+ count
> 0xffff)
647 fprintf( stderr
, "Too many directory entries in %s\n", dta
->unixPath
);
648 free( dta
->unixPath
);
649 dta
->unixPath
= NULL
;
653 dta
->fileattr
= entry
.attr
;
654 dta
->filetime
= entry
.time
;
655 dta
->filedate
= entry
.date
;
656 dta
->filesize
= entry
.size
;
657 strcpy( dta
->filename
, DOSFS_ToDosDTAFormat( entry
.name
) );
662 static int INT21_SetFileDateTime(struct sigcontext_struct
*context
)
664 fprintf( stderr
, "INT21_SetFileDateTime: not implemented yet.\n" );
668 struct utimbuf filetime
;
670 /* FIXME: Argument isn't the name of the file in DS:DX,
671 but the file handle in BX */
672 filename
= DOSFS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
673 DX_reg(context
)),TRUE
);
675 filetime
.actime
= 0L;
676 filetime
.modtime
= filetime
.actime
;
678 utime(filename
, &filetime
);
679 RESET_CFLAG(context
);
684 static int INT21_CreateTempFile(struct sigcontext_struct
*context
)
686 static int counter
= 0;
687 char *name
= PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
) );
688 char *p
= name
+ strlen(name
);
692 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
693 counter
= (counter
+ 1) % 1000;
695 if ((AX_reg(context
) = _lcreat_uniq( name
, 0 )) != (WORD
)HFILE_ERROR
)
697 dprintf_int( stddeb
, "INT21_CreateTempFile: created %s\n", name
);
700 if (DOS_ExtendedError
!= ER_FileExists
) return 0;
705 static int INT21_GetCurrentDirectory(struct sigcontext_struct
*context
)
707 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
708 char *ptr
= (char *)PTR_SEG_OFF_TO_LIN( DS_reg(context
), SI_reg(context
) );
710 if (!DRIVE_IsValid(drive
))
712 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
716 lstrcpyn( ptr
, DRIVE_GetDosCwd(drive
), 64 );
717 if (!ptr
[0]) strcpy( ptr
, "\\" );
722 static int INT21_GetDiskSerialNumber(struct sigcontext_struct
*context
)
724 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
725 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
727 if (!DRIVE_IsValid(drive
))
729 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
733 *(WORD
*)dataptr
= 0;
734 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
735 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
736 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
741 static int INT21_SetDiskSerialNumber(struct sigcontext_struct
*context
)
743 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
744 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
746 if (!DRIVE_IsValid(drive
))
748 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
752 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
757 static void DumpFCB(BYTE
*fcb
)
763 for (y
= 0; y
!=2 ; y
++) {
764 for (x
= 0; x
!=15;x
++)
765 dprintf_int(stddeb
, "%02x ", *fcb
++);
766 dprintf_int(stddeb
,"\n");
770 /* microsoft's programmers should be shot for using CP/M style int21
771 calls in Windows for Workgroup's winfile.exe */
773 static void FindFirstFCB(struct sigcontext_struct
*context
)
775 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
776 struct fcb
*standard_fcb
;
777 struct fcb
*output_fcb
;
781 BYTE
*dta
= GetCurrentDTA();
787 standard_fcb
= (struct fcb
*)(fcb
+ 7);
788 output_fcb
= (struct fcb
*)(dta
+ 7);
793 standard_fcb
= (struct fcb
*)fcb
;
794 output_fcb
= (struct fcb
*)dta
;
797 if (standard_fcb
->drive
)
799 drive
= standard_fcb
->drive
- 1;
800 if (!DRIVE_IsValid(drive
))
802 DOS_ERROR(ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
803 AX_reg(context
) = 0xff;
808 drive
= DRIVE_GetCurrentDrive();
810 output_fcb
->drive
= drive
;
814 if (*(fcb
+6) & FA_LABEL
) /* return volume label */
817 memset(&output_fcb
->name
, ' ', 11);
818 memcpy(output_fcb
->name
, DRIVE_GetLabel(drive
), 11);
819 AX_reg(context
) = 0x00;
824 strncpy(output_fcb
->name
, standard_fcb
->name
, 11);
826 *(dta
+6) = ( *(fcb
+6) & (!FA_DIRECTORY
));
829 sprintf(path
,"%c:*.*",drive
+'A');
830 if ((output_fcb
->directory
= DOS_opendir(path
))==NULL
)
832 Error (PathNotFound
, EC_MediaError
, EL_Disk
);
833 AX_reg(context
) = 0xff;
840 static void DeleteFileFCB(struct sigcontext_struct
*context
)
842 fprintf( stderr
, "DeleteFileFCB: not implemented yet\n" );
844 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
845 struct dosdirent
*dp
;
846 char temp
[256], *ptr
;
847 int drive
= DOS_GET_DRIVE( *fcb
);
852 strcpy(temp
+1, DRIVE_GetDosCwd(drive
));
854 strncat(temp
, fcb
+ 1, 8);
855 ChopOffWhiteSpace(temp
);
856 strncat(temp
, fcb
+ 9, 3);
857 ChopOffWhiteSpace(temp
);
859 if ((dp
= DOS_opendir(temp
)) == NULL
) {
860 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
861 AX_reg(context
) = 0xff;
866 strcpy(temp
+1, DRIVE_GetDosCwd(drive
) );
869 ptr
= temp
+ strlen(temp
);
871 while (DOS_readdir(dp
) != NULL
)
873 strcpy(ptr
, dp
->filename
);
874 dprintf_int(stddeb
, "int21: delete file %s\n", temp
);
875 /* unlink(DOS_GetUnixFileName(temp)); */
882 static void RenameFileFCB(struct sigcontext_struct
*context
)
884 fprintf( stderr
, "RenameFileFCB: not implemented yet\n" );
886 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
887 struct dosdirent
*dp
;
888 char temp
[256], oldname
[256], newname
[256], *oldnameptr
, *newnameptr
;
889 int drive
= DOS_GET_DRIVE( *fcb
);
894 strcpy(temp
+1, DRIVE_GetDosCwd(drive
) );
896 strncat(temp
, fcb
+ 1, 8);
897 ChopOffWhiteSpace(temp
);
898 strncat(temp
, fcb
+ 9, 3);
899 ChopOffWhiteSpace(temp
);
901 if ((dp
= DOS_opendir(temp
)) == NULL
) {
902 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
903 AX_reg(context
) = 0xff;
908 strcpy(oldname
+1, DRIVE_GetDosCwd(drive
) );
909 strcat(oldname
, "\\");
910 strcpy( newname
, oldname
);
911 oldnameptr
= oldname
+ strlen(oldname
);
912 newnameptr
= newname
+ strlen(newname
);
914 while (DOS_readdir(dp
) != NULL
)
916 strcpy(oldnameptr
, dp
->filename
);
917 strcpy(newnameptr
, fcb
+ 1);
918 dprintf_int(stddeb
, "int21: renamefile %s -> %s\n",
928 static void fLock (struct sigcontext_struct
* context
)
932 int result
,retries
=sharing_retries
;
934 f
.l_start
= MAKELONG(DX_reg(context
),CX_reg(context
));
935 f
.l_len
= MAKELONG(DI_reg(context
),SI_reg(context
));
939 switch ( AX_reg(context
) & 0xff )
941 case 0x00: /* LOCK */
945 case 0x01: /* UNLOCK */
950 AX_reg(context
) = 0x0001;
956 result
= fcntl(BX_reg(context
),F_SETLK
,&f
);
957 if ( retries
&& (!result
) )
960 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
961 result
++; /* stop the optimizer */
962 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
966 while( (!result
) && (!(retries
--)) );
971 AX_reg(context
) = DOS_ExtendedError
;
979 static int INT21_GetFileAttribute (struct sigcontext_struct
* context
)
981 const char *unixName
;
983 unixName
= DOSFS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)), TRUE
);
984 if (!unixName
) return 0;
985 if (!FILE_Stat( unixName
, &CL_reg(context
), NULL
, NULL
, NULL
)) return 0;
987 dprintf_int( stddeb
, "INT21_GetFileAttributes(%s) = 0x%x\n",
988 unixName
, CX_reg(context
) );
993 extern void LOCAL_PrintHeap (WORD ds
);
995 /***********************************************************************
996 * DOS3Call (KERNEL.102)
998 void DOS3Call( struct sigcontext_struct context
)
1000 dprintf_int( stddeb
, "int21: AX=%04x BX=%04x CX=%04x DX=%04x "
1001 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1002 AX_reg(&context
), BX_reg(&context
), CX_reg(&context
),
1003 DX_reg(&context
), SI_reg(&context
), DI_reg(&context
),
1004 DS_reg(&context
), ES_reg(&context
), EFL_reg(&context
));
1006 if (AH_reg(&context
) == 0x59) /* Get extended error info */
1008 AX_reg(&context
) = DOS_ExtendedError
;
1009 BH_reg(&context
) = DOS_ErrorClass
;
1010 BL_reg(&context
) = DOS_ErrorAction
;
1011 CH_reg(&context
) = DOS_ErrorLocus
;
1015 DOS_ERROR( 0, 0, 0, 0 );
1016 RESET_CFLAG(&context
); /* Not sure if this is a good idea */
1018 switch(AH_reg(&context
))
1020 case 0x00: /* TERMINATE PROGRAM */
1021 TASK_KillCurrentTask( 0 );
1024 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1025 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1026 case 0x03: /* READ CHARACTER FROM STDAUX */
1027 case 0x04: /* WRITE CHARACTER TO STDAUX */
1028 case 0x05: /* WRITE CHARACTER TO PRINTER */
1029 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1030 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
1031 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1032 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1033 case 0x0a: /* BUFFERED INPUT */
1034 case 0x0b: /* GET STDIN STATUS */
1035 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
1036 case 0x0f: /* OPEN FILE USING FCB */
1037 case 0x10: /* CLOSE FILE USING FCB */
1038 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1039 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1040 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1041 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1042 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1043 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1044 case 0x23: /* GET FILE SIZE FOR FCB */
1045 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1046 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1047 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1048 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1049 case 0x29: /* PARSE FILENAME INTO FCB */
1050 case 0x2e: /* SET VERIFY FLAG */
1051 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
1052 "SWITCHAR" - SET SWITCH CHARACTER
1053 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
1054 case 0x54: /* GET VERIFY FLAG */
1055 INT_BARF( &context
, 0x21 );
1058 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1062 case 0x6b: /* NULL FUNCTION */
1063 AL_reg(&context
) = 0;
1066 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1070 case 0x0d: /* DISK BUFFER FLUSH */
1071 RESET_CFLAG(&context
); /* dos 6+ only */
1074 case 0x0e: /* SELECT DEFAULT DRIVE */
1075 DRIVE_SetCurrentDrive( DL_reg(&context
) );
1076 AL_reg(&context
) = MAX_DOS_DRIVES
;
1079 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1080 FindFirstFCB(&context
);
1083 case 0x13: /* DELETE FILE USING FCB */
1084 DeleteFileFCB(&context
);
1087 case 0x17: /* RENAME FILE USING FCB */
1088 RenameFileFCB(&context
);
1091 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1092 AL_reg(&context
) = DRIVE_GetCurrentDrive();
1095 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1097 TDB
*pTask
= (TDB
*)GlobalLock( GetCurrentTask() );
1098 pTask
->dta
= MAKELONG( DX_reg(&context
), DS_reg(&context
) );
1099 dprintf_int(stddeb
, "int21: Set DTA: %08lx\n", pTask
->dta
);
1103 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1104 DL_reg(&context
) = 0;
1105 GetDriveAllocInfo(&context
);
1108 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1109 GetDriveAllocInfo(&context
);
1112 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1113 GetDrivePB(&context
, DRIVE_GetCurrentDrive());
1116 case 0x25: /* SET INTERRUPT VECTOR */
1117 INT_SetHandler( AL_reg(&context
),
1118 MAKELONG( DX_reg(&context
), DS_reg(&context
) ) );
1121 case 0x2a: /* GET SYSTEM DATE */
1122 GetSystemDate(&context
);
1125 case 0x2b: /* SET SYSTEM DATE */
1126 fprintf( stdnimp
, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1127 DL_reg(&context
), DH_reg(&context
), CX_reg(&context
) );
1128 AL_reg(&context
) = 0; /* Let's pretend we succeeded */
1131 case 0x2c: /* GET SYSTEM TIME */
1132 INT21_GetSystemTime(&context
);
1135 case 0x2d: /* SET SYSTEM TIME */
1136 fprintf( stdnimp
, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1137 CH_reg(&context
), CL_reg(&context
),
1138 DH_reg(&context
), DL_reg(&context
) );
1139 AL_reg(&context
) = 0; /* Let's pretend we succeeded */
1142 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1144 TDB
*pTask
= (TDB
*)GlobalLock( GetCurrentTask() );
1145 ES_reg(&context
) = SELECTOROF( pTask
->dta
);
1146 BX_reg(&context
) = OFFSETOF( pTask
->dta
);
1150 case 0x30: /* GET DOS VERSION */
1151 AX_reg(&context
) = DOSVERSION
;
1152 BX_reg(&context
) = 0x0012; /* 0x123456 is Wine's serial # */
1153 CX_reg(&context
) = 0x3456;
1156 case 0x31: /* TERMINATE AND STAY RESIDENT */
1157 INT_BARF( &context
, 0x21 );
1160 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1161 GetDrivePB(&context
, DOS_GET_DRIVE( DL_reg(&context
) ) );
1164 case 0x33: /* MULTIPLEXED */
1165 switch (AL_reg(&context
))
1167 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1168 DL_reg(&context
) = 0;
1171 case 0x01: /* SET EXTENDED BREAK STATE */
1174 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1175 DL_reg(&context
) = 0;
1178 case 0x05: /* GET BOOT DRIVE */
1179 DL_reg(&context
) = 2;
1180 /* c: is Wine's bootdrive */
1183 case 0x06: /* GET TRUE VERSION NUMBER */
1184 BX_reg(&context
) = DOSVERSION
;
1185 DX_reg(&context
) = 0x00;
1189 INT_BARF( &context
, 0x21 );
1194 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1195 ES_reg(&context
) = DosHeapHandle
;
1196 BX_reg(&context
) = (int)&heap
->InDosFlag
- (int)heap
;
1199 case 0x35: /* GET INTERRUPT VECTOR */
1201 SEGPTR addr
= INT_GetHandler( AL_reg(&context
) );
1202 ES_reg(&context
) = SELECTOROF(addr
);
1203 BX_reg(&context
) = OFFSETOF(addr
);
1207 case 0x36: /* GET FREE DISK SPACE */
1208 GetFreeDiskSpace(&context
);
1211 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1212 AX_reg(&context
) = 0x02; /* no country support available */
1213 SET_CFLAG(&context
);
1216 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1217 if (!FILE_MakeDir( PTR_SEG_OFF_TO_LIN( DS_reg(&context
),
1218 DX_reg(&context
) )))
1220 AX_reg(&context
) = DOS_ExtendedError
;
1221 SET_CFLAG(&context
);
1225 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1226 if (!FILE_RemoveDir( PTR_SEG_OFF_TO_LIN( DS_reg(&context
),
1227 DX_reg(&context
) )))
1229 AX_reg(&context
) = DOS_ExtendedError
;
1230 SET_CFLAG(&context
);
1234 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1235 INT21_ChangeDir(&context
);
1238 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1239 AX_reg(&context
) = _lcreat( PTR_SEG_OFF_TO_LIN( DS_reg(&context
),
1240 DX_reg(&context
) ), CX_reg(&context
) );
1241 if (AX_reg(&context
) == (WORD
)HFILE_ERROR
)
1243 AX_reg(&context
) = DOS_ExtendedError
;
1244 SET_CFLAG(&context
);
1248 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1249 OpenExistingFile(&context
);
1252 case 0x3e: /* "CLOSE" - CLOSE FILE */
1253 if ((AX_reg(&context
) = _lclose( BX_reg(&context
) )) != 0)
1255 AX_reg(&context
) = DOS_ExtendedError
;
1256 SET_CFLAG(&context
);
1260 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1261 if ((AX_reg(&context
) = _lread( BX_reg(&context
),
1262 PTR_SEG_OFF_TO_LIN( DS_reg(&context
),DX_reg(&context
) ),
1263 CX_reg(&context
))) == (WORD
)HFILE_ERROR
)
1265 AX_reg(&context
) = DOS_ExtendedError
;
1266 SET_CFLAG(&context
);
1270 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1271 if ((AX_reg(&context
) = _lwrite( BX_reg(&context
),
1272 PTR_SEG_OFF_TO_LIN( DS_reg(&context
),DX_reg(&context
) ),
1273 CX_reg(&context
))) == (WORD
)HFILE_ERROR
)
1275 AX_reg(&context
) = DOS_ExtendedError
;
1276 SET_CFLAG(&context
);
1280 case 0x41: /* "UNLINK" - DELETE FILE */
1281 if (!FILE_Unlink( PTR_SEG_OFF_TO_LIN( DS_reg(&context
),
1282 DX_reg(&context
) )))
1284 AX_reg(&context
) = DOS_ExtendedError
;
1285 SET_CFLAG(&context
);
1289 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1291 LONG status
= _llseek( BX_reg(&context
),
1292 MAKELONG(DX_reg(&context
),CX_reg(&context
)),
1294 if (status
== HFILE_ERROR
)
1296 AX_reg(&context
) = DOS_ExtendedError
;
1297 SET_CFLAG(&context
);
1300 AX_reg(&context
) = LOWORD(status
);
1301 DX_reg(&context
) = HIWORD(status
);
1305 case 0x43: /* FILE ATTRIBUTES */
1306 switch (AL_reg(&context
))
1309 if (!INT21_GetFileAttribute(&context
))
1311 AX_reg(&context
) = DOS_ExtendedError
;
1312 SET_CFLAG(&context
);
1316 RESET_CFLAG(&context
);
1321 case 0x44: /* IOCTL */
1322 switch (AL_reg(&context
))
1325 ioctlGetDeviceInfo(&context
);
1331 case 0x08: /* Check if drive is removable. */
1332 switch(GetDriveType( DOS_GET_DRIVE( BL_reg(&context
) )))
1334 case DRIVE_CANNOTDETERMINE
:
1335 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1336 AX_reg(&context
) = ER_InvalidDrive
;
1337 SET_CFLAG(&context
);
1339 case DRIVE_REMOVABLE
:
1340 AX_reg(&context
) = 0; /* removable */
1343 AX_reg(&context
) = 1; /* not removable */
1348 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1349 switch(GetDriveType( DOS_GET_DRIVE( BL_reg(&context
) )))
1351 case DRIVE_CANNOTDETERMINE
:
1352 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1353 AX_reg(&context
) = ER_InvalidDrive
;
1354 SET_CFLAG(&context
);
1357 DX_reg(&context
) = (1<<9) | (1<<12); /* remote */
1360 DX_reg(&context
) = 0; /* FIXME: use driver attr here */
1365 case 0x0a: /* check if handle (BX) is remote */
1366 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1369 DX_reg(&context
) = 0;
1372 case 0x0b: /* SET SHARING RETRY COUNT */
1373 if (!CX_reg(&context
))
1375 AX_reg(&context
) = 1;
1376 SET_CFLAG(&context
);
1379 sharing_pause
= CX_reg(&context
);
1380 if (!DX_reg(&context
))
1381 sharing_retries
= DX_reg(&context
);
1382 RESET_CFLAG(&context
);
1386 ioctlGenericBlkDevReq(&context
);
1389 case 0x0F: /* Set logical drive mapping */
1390 /* FIXME: Not implemented at the moment, always returns error
1392 INT_BARF( &context
, 0x21 );
1393 AX_reg(&context
) = 0x0001; /* invalid function */
1394 SET_CFLAG(&context
);
1398 INT_BARF( &context
, 0x21 );
1403 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1404 if ((AX_reg(&context
) = FILE_Dup(BX_reg(&context
))) == (WORD
)HFILE_ERROR
)
1406 AX_reg(&context
) = DOS_ExtendedError
;
1407 SET_CFLAG(&context
);
1411 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1412 if (FILE_Dup2( BX_reg(&context
), CX_reg(&context
) ) == HFILE_ERROR
)
1414 AX_reg(&context
) = DOS_ExtendedError
;
1415 SET_CFLAG(&context
);
1419 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1420 if (!INT21_GetCurrentDirectory(&context
))
1422 AX_reg(&context
) = DOS_ExtendedError
;
1423 SET_CFLAG(&context
);
1425 else AX_reg(&context
) = 0x0100;
1426 /* intlist: many Microsoft products for Windows rely on this */
1429 case 0x48: /* ALLOCATE MEMORY */
1430 case 0x49: /* FREE MEMORY */
1431 case 0x4a: /* RESIZE MEMORY BLOCK */
1432 INT_BARF( &context
, 0x21 );
1435 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1436 WinExec( PTR_SEG_OFF_TO_LIN( DS_reg(&context
), DX_reg(&context
) ),
1440 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1441 TASK_KillCurrentTask( AL_reg(&context
) );
1444 case 0x4d: /* GET RETURN CODE */
1445 AX_reg(&context
) = 0; /* normal exit */
1448 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1449 if (!INT21_FindFirst(&context
)) break;
1452 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1453 if (!INT21_FindNext(&context
))
1455 DOS_ERROR( ER_NoMoreFiles
, EC_MediaError
, SA_Abort
, EL_Disk
);
1456 AX_reg(&context
) = ER_NoMoreFiles
;
1457 SET_CFLAG(&context
);
1461 case 0x51: /* GET PSP ADDRESS */
1462 case 0x62: /* GET PSP ADDRESS */
1463 /* FIXME: should we return the original DOS PSP upon */
1464 /* Windows startup ? */
1465 BX_reg(&context
) = GetCurrentPDB();
1468 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1469 ES_reg(&context
) = 0x0;
1470 BX_reg(&context
) = 0x0;
1471 INT_BARF( &context
, 0x21 );
1474 case 0x56: /* "RENAME" - RENAME FILE */
1475 if (!INT21_RenameFile(&context
))
1477 AX_reg(&context
) = DOS_ExtendedError
;
1478 SET_CFLAG(&context
);
1482 case 0x57: /* FILE DATE AND TIME */
1483 switch (AL_reg(&context
))
1486 if (!FILE_Fstat( BX_reg(&context
), NULL
, NULL
,
1487 &DX_reg(&context
), &CX_reg(&context
) ))
1489 AX_reg(&context
) = DOS_ExtendedError
;
1490 SET_CFLAG(&context
);
1494 if (!INT21_SetFileDateTime(&context
))
1496 AX_reg(&context
) = DOS_ExtendedError
;
1497 SET_CFLAG(&context
);
1503 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1504 switch (AL_reg(&context
))
1507 AX_reg(&context
) = 1;
1510 AX_reg(&context
) = 0;
1516 RESET_CFLAG(&context
);
1519 case 0x5a: /* CREATE TEMPORARY FILE */
1520 if (!INT21_CreateTempFile(&context
))
1522 AX_reg(&context
) = DOS_ExtendedError
;
1523 SET_CFLAG(&context
);
1527 case 0x5b: /* CREATE NEW FILE */
1528 if ((AX_reg(&context
) = _lcreat_uniq( PTR_SEG_OFF_TO_LIN(DS_reg(&context
),DX_reg(&context
)), 0 )) == (WORD
)HFILE_ERROR
)
1530 AX_reg(&context
) = DOS_ExtendedError
;
1531 SET_CFLAG(&context
);
1535 case 0x5d: /* NETWORK */
1537 /* network software not installed */
1538 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1539 AX_reg(&context
) = DOS_ExtendedError
;
1540 SET_CFLAG(&context
);
1543 case 0x5f: /* NETWORK */
1544 switch (AL_reg(&context
))
1546 case 0x07: /* ENABLE DRIVE */
1547 if (!DRIVE_Enable( DL_reg(&context
) ))
1549 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1550 AX_reg(&context
) = DOS_ExtendedError
;
1551 SET_CFLAG(&context
);
1555 case 0x08: /* DISABLE DRIVE */
1556 if (!DRIVE_Disable( DL_reg(&context
) ))
1558 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1559 AX_reg(&context
) = DOS_ExtendedError
;
1560 SET_CFLAG(&context
);
1565 /* network software not installed */
1566 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1567 AX_reg(&context
) = DOS_ExtendedError
;
1568 SET_CFLAG(&context
);
1573 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1575 const char *truename
= DOSFS_GetDosTrueName( PTR_SEG_OFF_TO_LIN(DS_reg(&context
),SI_reg(&context
) ), FALSE
);
1578 AX_reg(&context
) = DOS_ExtendedError
;
1579 SET_CFLAG(&context
);
1583 lstrcpyn(PTR_SEG_OFF_TO_LIN(ES_reg(&context
),DI_reg(&context
)),
1585 AX_reg(&context
) = 0;
1590 case 0x61: /* UNUSED */
1591 case 0x63: /* UNUSED */
1592 case 0x64: /* OS/2 DOS BOX */
1593 case 0x65: /* GET EXTENDED COUNTRY INFORMATION */
1594 INT_BARF( &context
, 0x21 );
1597 case 0x66: /* GLOBAL CODE PAGE TABLE */
1598 switch (AL_reg(&context
))
1601 DX_reg(&context
) = BX_reg(&context
) = CodePage
;
1602 RESET_CFLAG(&context
);
1605 CodePage
= BX_reg(&context
);
1606 RESET_CFLAG(&context
);
1611 case 0x67: /* SET HANDLE COUNT */
1612 SetHandleCount( BX_reg(&context
) );
1613 if (DOS_ExtendedError
)
1615 AX_reg(&context
) = DOS_ExtendedError
;
1616 SET_CFLAG(&context
);
1620 case 0x68: /* "FFLUSH" - COMMIT FILE */
1621 case 0x6a: /* COMMIT FILE */
1622 if (fsync( FILE_GetUnixHandle( BX_reg(&context
) )) == -1)
1625 AX_reg(&context
) = DOS_ExtendedError
;
1626 SET_CFLAG(&context
);
1630 case 0x69: /* DISK SERIAL NUMBER */
1631 switch (AL_reg(&context
))
1634 if (!INT21_GetDiskSerialNumber(&context
))
1636 AX_reg(&context
) = DOS_ExtendedError
;
1637 SET_CFLAG(&context
);
1639 else AX_reg(&context
) = 0;
1642 if (!INT21_SetDiskSerialNumber(&context
))
1644 AX_reg(&context
) = DOS_ExtendedError
;
1645 SET_CFLAG(&context
);
1647 else AX_reg(&context
) = 1;
1652 case 0x6C: /* Extended Open/Create*/
1653 ExtendedOpenCreateFile(&context
);
1656 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
1657 case 0x71: /* MS-DOS 7 (Chicago) - LONG FILENAME FUNCTIONS */
1658 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
1659 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
1660 dprintf_int(stddeb
,"int21: windows95 function AX %04x\n",
1662 dprintf_int(stddeb
, " returning unimplemented\n");
1663 SET_CFLAG(&context
);
1664 AL_reg(&context
) = 0;
1667 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1668 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1672 INT_BARF( &context
, 0x21 );
1675 dprintf_int( stddeb
, "ret21: AX=%04x BX=%04x CX=%04x DX=%04x "
1676 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1677 AX_reg(&context
), BX_reg(&context
), CX_reg(&context
),
1678 DX_reg(&context
), SI_reg(&context
), DI_reg(&context
),
1679 DS_reg(&context
), ES_reg(&context
), EFL_reg(&context
));
1683 void INT21_Init(void)
1685 if ((DosHeapHandle
= GlobalAlloc(GMEM_FIXED
,sizeof(struct DosHeap
))) == 0)
1687 fprintf( stderr
, "INT21_Init: Out of memory\n");
1690 heap
= (struct DosHeap
*) GlobalLock(DosHeapHandle
);
1693 dpbsegptr
= MAKELONG( (int)&heap
->dpb
- (int)heap
, DosHeapHandle
);
1694 heap
->InDosFlag
= 0;
1695 strcpy(heap
->biosdate
, "01/01/80");