2 * (c) 1993, 1994 Erik Bos
14 #include <sys/types.h>
18 #include "prototypes.h"
23 #include "registers.h"
26 /* #define DEBUG_INT */
27 /* #undef DEBUG_INT */
30 WORD ExtendedError
, CodePage
= 437;
31 BYTE ErrorClass
, Action
, ErrorLocus
;
39 static struct DosHeap
*heap
;
41 WORD sharing_retries
= 3; /* number of retries at sharing violation */
42 WORD sharing_pause
= 1; /* pause between retries */
44 extern char TempDirectory
[];
45 void IntBarf(int i
, struct sigcontext_struct
*context
);
47 static int Error(int e
, int class, int el
)
50 Action
= SA_Ask4Retry
;
57 void errno_to_doserr(void)
61 Error (ShareViolation
, EC_Temporary
, EL_Unknown
);
64 Error (InvalidHandle
, EC_AppError
, EL_Unknown
);
67 Error (DiskFull
, EC_MediaError
, EL_Disk
);
72 Error (WriteProtected
, EC_AccessDenied
, EL_Unknown
);
75 Error (LockViolation
, EC_AccessDenied
, EL_Unknown
);
78 Error (FileNotFound
, EC_NotFound
, EL_Unknown
);
81 Error (CanNotMakeDir
, EC_AccessDenied
, EL_Unknown
);
85 Error (NoMoreFiles
, EC_MediaError
, EL_Unknown
);
88 Error (FileExists
, EC_Exists
, EL_Disk
);
91 fprintf(stderr
, "int21: unknown errno %d!\n", errno
);
92 Error (GeneralFailure
, EC_SystemFailure
, EL_Unknown
);
98 static void Barf(struct sigcontext_struct *context)
100 fprintf(stdnimp, "int21: unknown/not implemented parameters:\n");
101 fprintf(stdnimp, "int21: AX %04x, BX %04x, CX %04x, DX %04x, "
102 "SI %04x, DI %04x, DS %04x, ES %04x\n",
103 AX, BX, CX, DX, SI, DI, DS, ES);
107 void ChopOffWhiteSpace(char *string
)
111 for (length
= strlen(string
) ; length
; length
--)
112 if (string
[length
] == ' ')
113 string
[length
] = '\0';
116 static void CreateBPB(int drive
, BYTE
*data
)
121 setword(&data
[3], 0);
123 setword(&data
[6], 240);
124 setword(&data
[8], 64000);
126 setword(&data
[0x0b], 40);
127 setword(&data
[0x0d], 56);
128 setword(&data
[0x0f], 2);
129 setword(&data
[0x11], 0);
130 setword(&data
[0x1f], 800);
132 setword(&data
[0x22], 1);
133 } else { /* 1.44mb */
136 setword(&data
[3], 0);
138 setword(&data
[6], 240);
139 setword(&data
[8], 2880);
141 setword(&data
[0x0b], 6);
142 setword(&data
[0x0d], 18);
143 setword(&data
[0x0f], 2);
144 setword(&data
[0x11], 0);
145 setword(&data
[0x1f], 80);
147 setword(&data
[0x22], 2);
151 static void GetFreeDiskSpace(struct sigcontext_struct
*context
)
157 drive
= DOS_GetDefaultDrive();
161 if (!DOS_ValidDrive(drive
)) {
162 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
167 if (!DOS_GetFreeSpace(drive
, &size
, &available
)) {
168 Error(GeneralFailure
, EC_MediaError
, EL_Disk
);
176 BX
= (available
/ (CX
* AX
));
177 DX
= (size
/ (CX
* AX
));
181 static void GetDriveAllocInfo(struct sigcontext_struct
*context
)
184 long size
, available
;
187 if (!DOS_ValidDrive(DL
)) {
191 Error (InvalidDrive
, EC_MediaError
, EL_Disk
);
195 if (!DOS_GetFreeSpace(DL
, &size
, &available
)) {
196 Error(GeneralFailure
, EC_MediaError
, EL_Disk
);
203 EDX
= (size
/ (CX
* AX
));
207 DS
= segment(mediaID
);
208 BX
= offset(mediaID
);
212 static void GetDefDriveAllocInfo(struct sigcontext_struct
*context
)
214 DX
= DOS_GetDefaultDrive();
215 GetDriveAllocInfo(context
);
218 static void GetDrivePB(struct sigcontext_struct
*context
)
220 Error (InvalidDrive
, EC_MediaError
, EL_Disk
);
222 /* I'm sorry but I only got networked drives :-) */
225 static void ReadFile(struct sigcontext_struct
*context
)
230 /* can't read from stdout / stderr */
231 if ((BX
== 1) || (BX
== 2)) {
232 Error (InvalidHandle
, EL_Unknown
, EC_Unknown
);
238 ptr
= SAFEMAKEPTR (DS
,DX
);
246 size
= read(BX
, ptr
, CX
);
259 static void WriteFile(struct sigcontext_struct
*context
)
264 ptr
= SAFEMAKEPTR (DS
,DX
);
267 Error (InvalidHandle
, EC_Unknown
, EL_Unknown
);
274 for (x
= 0;x
!= CX
;x
++) {
275 dprintf_int(stddeb
, "%c", *ptr
++);
283 size
= write(BX
, ptr
, CX
);
285 Error (WriteFault
, EC_Unknown
, EL_Unknown
);
302 static void SeekFile(struct sigcontext_struct
*context
)
304 off_t status
, fileoffset
;
307 case 1: fileoffset
= SEEK_CUR
;
309 case 2: fileoffset
= SEEK_END
;
312 case 0: fileoffset
= SEEK_SET
;
315 status
= lseek(BX
, (CX
<< 16) + DX
, fileoffset
);
318 AL
= ExtendedError
; SetCflag
;
322 AX
= (status
& 0xffff);
323 DX
= ((status
>> 16) & 0xffff);
328 static void ioctlGetDeviceInfo(struct sigcontext_struct
*context
)
341 if (fstat(BX
, &sbuf
) < 0)
343 IntBarf(0x21, context
);
349 /* This isn't the right answer, but should be close enough. */
356 static void ioctlGenericBlkDevReq(struct sigcontext_struct
*context
)
358 BYTE
*dataptr
= SAFEMAKEPTR(DS
, DX
);
362 drive
= DOS_GetDefaultDrive();
366 if (!DOS_ValidDrive(drive
)) {
373 IntBarf(0x21, context
);
377 case 0x60: /* get device parameters */
378 /* used by w4wgrp's winfile */
379 memset(dataptr
, 0, 0x26);
381 dataptr
[6] = 0; /* media type */
384 dataptr
[1] = 0x05; /* fixed disk */
385 setword(&dataptr
[2], 0x01); /* non removable */
386 setword(&dataptr
[4], 0x300); /* # of cylinders */
390 dataptr
[1] = 0x07; /* block dev, floppy */
391 setword(&dataptr
[2], 0x02); /* removable */
392 setword(&dataptr
[4], 80); /* # of cylinders */
394 CreateBPB(drive
, &dataptr
[7]);
398 IntBarf(0x21, context
);
402 static void GetSystemDate(struct sigcontext_struct
*context
)
408 now
= localtime(<ime
);
410 CX
= now
->tm_year
+ 1900;
411 DX
= ((now
->tm_mon
+ 1) << 8) | now
->tm_mday
;
415 static void GetSystemTime(struct sigcontext_struct
*context
)
420 gettimeofday(&tv
,NULL
); /* Note use of gettimeofday(), instead of time() */
421 now
= localtime(&tv
.tv_sec
);
423 CX
= (now
->tm_hour
<<8) | now
->tm_min
;
424 DX
= (now
->tm_sec
<<8) | tv
.tv_usec
/10000;
425 /* Note hundredths of seconds */
428 static void GetExtendedErrorInfo(struct sigcontext_struct
*context
)
431 BX
= (ErrorClass
<< 8) | Action
;
432 CH
= ErrorLocus
<< 8;
435 static void CreateFile(struct sigcontext_struct
*context
)
439 if ((handle
= open(GetUnixFileName( SAFEMAKEPTR(DS
,DX
)),
440 O_CREAT
| O_TRUNC
| O_RDWR
)) == -1) {
447 EAX
= (EAX
& 0xffff0000) | handle
;
451 void OpenExistingFile(struct sigcontext_struct
*context
)
472 if ((handle
= open(GetUnixFileName(SAFEMAKEPTR(DS
,DX
)), mode
)) == -1) {
481 case 0x00: /* compatability mode */
482 case 0x40: /* DENYNONE */
486 case 0x30: /* DENYREAD */
488 "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
490 case 0x10: /* DENYALL */
494 case 0x20: /* DENYWRITE */
505 int result
,retries
=sharing_retries
;
507 result
= flock(handle
, lock
| LOCK_NB
);
508 if ( retries
&& (!result
) )
511 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
512 result
++; /* stop the optimizer */
513 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
517 while( (!result
) && (!(retries
--)) );
522 EAX
= (EAX
& 0xffffff00) | ExtendedError
;
531 EAX
= (EAX
& 0xffff0000) | handle
;
535 static void CloseFile(struct sigcontext_struct
*context
)
537 if (close(BX
) == -1) {
548 static void RenameFile(struct sigcontext_struct
*context
)
550 char *newname
, *oldname
;
552 dprintf_int(stddeb
,"int21: renaming %s to %s\n",
553 SAFEMAKEPTR(DS
,DX
), SAFEMAKEPTR(ES
,DI
) );
555 oldname
= GetUnixFileName( SAFEMAKEPTR(DS
,DX
) );
556 newname
= GetUnixFileName( SAFEMAKEPTR(ES
,DI
) );
558 rename( oldname
, newname
);
563 static void MakeDir(struct sigcontext_struct
*context
)
567 dprintf_int(stddeb
,"int21: makedir %s\n", SAFEMAKEPTR(DS
,DX
) );
569 if ((dirname
= GetUnixFileName( SAFEMAKEPTR(DS
,DX
) ))== NULL
) {
575 if (mkdir(dirname
,0) == -1) {
583 static void ChangeDir(struct sigcontext_struct
*context
)
586 char *dirname
= SAFEMAKEPTR(DS
,DX
);
587 drive
= DOS_GetDefaultDrive();
588 dprintf_int(stddeb
,"int21: changedir %s\n", dirname
);
589 if (dirname
!= NULL
&& dirname
[1] == ':') {
590 drive
= toupper(dirname
[0]) - 'A';
593 if (!DOS_ChangeDir(drive
, dirname
))
600 static void RemoveDir(struct sigcontext_struct
*context
)
604 dprintf_int(stddeb
,"int21: removedir %s\n", SAFEMAKEPTR(DS
,DX
) );
606 if ((dirname
= GetUnixFileName( SAFEMAKEPTR(DS
,DX
) ))== NULL
) {
613 if (strcmp(unixname,DosDrives[drive].CurrentDirectory)) {
614 AL = CanNotRemoveCwd;
618 if (rmdir(dirname
) == -1) {
625 static void ExecProgram(struct sigcontext_struct
*context
)
627 execl("wine", GetUnixFileName( SAFEMAKEPTR(DS
,DX
)) );
630 static void FindNext(struct sigcontext_struct
*context
)
632 struct dosdirent
*dp
;
634 memcpy(&dp
, dta
+0x0d, sizeof(dp
));
637 if ((dp
= DOS_readdir(dp
)) == NULL
) {
638 Error(NoMoreFiles
, EC_MediaError
, EL_Disk
);
643 } /* while (*(dta + 0x0c) != dp->attribute);*/
644 while ( ( dp
->search_attribute
& dp
->attribute
) != dp
->attribute
);
646 *(dta
+ 0x15) = dp
->attribute
;
647 setword(&dta
[0x16], 0x1234); /* time */
648 setword(&dta
[0x18], 0x1234); /* date */
649 setdword(&dta
[0x1a], dp
->filesize
);
650 strncpy(dta
+ 0x1e, dp
->filename
, 13);
657 static void FindFirst(struct sigcontext_struct
*context
)
659 BYTE drive
, *path
= SAFEMAKEPTR(DS
, DX
);
660 struct dosdirent
*dp
;
662 if ((*path
)&&(path
[1] == ':')) {
663 drive
= (islower(*path
) ? toupper(*path
) : *path
) - 'A';
665 if (!DOS_ValidDrive(drive
)) {
666 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
672 drive
= DOS_GetDefaultDrive();
675 memset(dta
+ 1 , '?', 11);
676 *(dta
+ 0x0c) = ECX
& (FA_LABEL
| FA_DIREC
);
678 if (ECX
& FA_LABEL
) {
679 /* return volume label */
681 if (DOS_GetVolumeLabel(drive
) != NULL
)
682 strncpy(dta
+ 0x1e, DOS_GetVolumeLabel(drive
), 8);
689 if ((dp
= DOS_opendir(path
)) == NULL
) {
690 Error(PathNotFound
, EC_MediaError
, EL_Disk
);
696 dp
->search_attribute
= ECX
& (FA_LABEL
| FA_DIREC
);
697 memcpy(dta
+ 0x0d, &dp
, sizeof(dp
));
701 static void GetFileDateTime(struct sigcontext_struct
*context
)
704 struct stat filestat
;
707 if ((filename
= GetUnixFileName( SAFEMAKEPTR(DS
,DX
) ))== NULL
) {
712 stat(filename
, &filestat
);
714 now
= localtime (&filestat
.st_mtime
);
716 CX
= ((now
->tm_hour
* 0x2000) + (now
->tm_min
* 0x20) + now
->tm_sec
/2);
717 DX
= ((now
->tm_year
* 0x200) + (now
->tm_mon
* 0x20) + now
->tm_mday
);
722 static void SetFileDateTime(struct sigcontext_struct
*context
)
725 struct utimbuf filetime
;
727 filename
= GetUnixFileName( SAFEMAKEPTR(DS
,DX
) );
729 filetime
.actime
= 0L;
730 filetime
.modtime
= filetime
.actime
;
732 utime(filename
, &filetime
);
736 static void CreateTempFile(struct sigcontext_struct
*context
)
741 sprintf(temp
,"%s\\win%d.tmp",TempDirectory
,(int) getpid());
743 dprintf_int(stddeb
,"CreateTempFile %s\n",temp
);
745 handle
= open(GetUnixFileName(temp
), O_CREAT
| O_TRUNC
| O_RDWR
);
753 strcpy(SAFEMAKEPTR(DS
,DX
), temp
);
759 static void CreateNewFile(struct sigcontext_struct
*context
)
763 if ((handle
= open(GetUnixFileName( SAFEMAKEPTR(DS
,DX
) ), O_CREAT
| O_EXCL
| O_RDWR
)) == -1) {
773 static void GetCurrentDirectory(struct sigcontext_struct
*context
)
778 drive
= DOS_GetDefaultDrive();
782 if (!DOS_ValidDrive(drive
)) {
788 strcpy(SAFEMAKEPTR(DS
,SI
), DOS_GetCurrentDir(drive
) );
792 static void GetDiskSerialNumber(struct sigcontext_struct
*context
)
795 BYTE
*dataptr
= SAFEMAKEPTR(DS
, DX
);
799 drive
= DOS_GetDefaultDrive();
803 if (!DOS_ValidDrive(drive
)) {
809 DOS_GetSerialNumber(drive
, &serialnumber
);
812 setdword(&dataptr
[2], serialnumber
);
813 strncpy(dataptr
+ 6, DOS_GetVolumeLabel(drive
), 8);
814 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
820 static void SetDiskSerialNumber(struct sigcontext_struct
*context
)
823 BYTE
*dataptr
= SAFEMAKEPTR(DS
, DX
);
827 drive
= DOS_GetDefaultDrive();
831 if (!DOS_ValidDrive(drive
)) {
837 serialnumber
= dataptr
[1] + (dataptr
[2] << 8) + (dataptr
[3] << 16) +
840 DOS_SetSerialNumber(drive
, serialnumber
);
845 static void DumpFCB(BYTE
*fcb
)
851 for (y
= 0; y
!=2 ; y
++) {
852 for (x
= 0; x
!=15;x
++)
853 dprintf_int(stddeb
, "%02x ", *fcb
++);
854 dprintf_int(stddeb
,"\n");
858 /* microsoft's programmers should be shot for using CP/M style int21
859 calls in Windows for Workgroup's winfile.exe */
861 static void FindFirstFCB(struct sigcontext_struct
*context
)
863 BYTE
*fcb
= SAFEMAKEPTR(DS
, DX
);
864 struct fcb
*standard_fcb
;
865 struct fcb
*output_fcb
;
873 standard_fcb
= (struct fcb
*)(fcb
+ 7);
874 output_fcb
= (struct fcb
*)(dta
+ 7);
879 standard_fcb
= (struct fcb
*)fcb
;
880 output_fcb
= (struct fcb
*)dta
;
883 if (standard_fcb
->drive
)
885 drive
= standard_fcb
->drive
- 1;
886 if (!DOS_ValidDrive(drive
))
888 Error (InvalidDrive
, EC_MediaError
, EL_Disk
);
894 drive
= DOS_GetDefaultDrive();
896 output_fcb
->drive
= drive
;
900 if (*(fcb
+6) & FA_LABEL
) /* return volume label */
903 memset(&output_fcb
->name
, ' ', 11);
904 if (DOS_GetVolumeLabel(drive
) != NULL
)
906 strncpy(output_fcb
->name
, DOS_GetVolumeLabel(drive
), 11);
913 strncpy(output_fcb
->name
, standard_fcb
->name
, 11);
915 *(dta
+6) = ( *(fcb
+6) & (!FA_DIREC
));
917 sprintf(path
,"%c:*.*",drive
+'A');
918 if ((output_fcb
->directory
= DOS_opendir(path
))==NULL
)
920 Error (PathNotFound
, EC_MediaError
, EL_Disk
);
928 static void DeleteFileFCB(struct sigcontext_struct
*context
)
930 BYTE
*fcb
= SAFEMAKEPTR(DS
, DX
);
932 struct dosdirent
*dp
;
933 char temp
[256], *ptr
;
940 drive
= DOS_GetDefaultDrive();
942 strcpy(temp
, DOS_GetCurrentDir(drive
));
944 strncat(temp
, fcb
+ 1, 8);
945 ChopOffWhiteSpace(temp
);
946 strncat(temp
, fcb
+ 9, 3);
947 ChopOffWhiteSpace(temp
);
949 if ((dp
= DOS_opendir(temp
)) == NULL
) {
950 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
955 strcpy(temp
, DOS_GetCurrentDir(drive
) );
958 ptr
= temp
+ strlen(temp
);
960 while (DOS_readdir(dp
) != NULL
)
962 strcpy(ptr
, dp
->filename
);
963 dprintf_int(stddeb
, "int21: delete file %s\n", temp
);
964 /* unlink(GetUnixFileName(temp)); */
970 static void RenameFileFCB(struct sigcontext_struct
*context
)
972 BYTE
*fcb
= SAFEMAKEPTR(DS
, DX
);
974 struct dosdirent
*dp
;
975 char temp
[256], oldname
[256], newname
[256], *oldnameptr
, *newnameptr
;
982 drive
= DOS_GetDefaultDrive();
984 strcpy(temp
, DOS_GetCurrentDir(drive
));
986 strncat(temp
, fcb
+ 1, 8);
987 ChopOffWhiteSpace(temp
);
988 strncat(temp
, fcb
+ 9, 3);
989 ChopOffWhiteSpace(temp
);
991 if ((dp
= DOS_opendir(temp
)) == NULL
) {
992 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
997 strcpy(oldname
, DOS_GetCurrentDir(drive
) );
998 strcat(oldname
, "\\");
999 oldnameptr
= oldname
+ strlen(oldname
);
1001 strcpy(newname
, DOS_GetCurrentDir(drive
) );
1002 strcat(newname
, "\\");
1003 newnameptr
= newname
+ strlen(newname
);
1005 while (DOS_readdir(dp
) != NULL
)
1007 strcpy(oldnameptr
, dp
->filename
);
1008 strcpy(newnameptr
, fcb
+ 1);
1009 dprintf_int(stddeb
, "int21: renamefile %s -> %s\n",
1018 static void fLock (struct sigcontext_struct
* context
)
1021 int result
,retries
=sharing_retries
;
1023 f
.l_start
= MAKELONG(DX
,CX
);
1024 f
.l_len
= MAKELONG(DI
,SI
);
1028 switch ( AX
& 0xff )
1030 case 0x00: /* LOCK */
1034 case 0x01: /* UNLOCK */
1039 EAX
= (EAX
& 0xffff0000) | 0x0001;
1045 result
= fcntl(BX
,F_SETLK
,&f
);
1046 if ( retries
&& (!result
) )
1049 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
1050 result
++; /* stop the optimizer */
1051 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
1055 while( (!result
) && (!(retries
--)) );
1060 EAX
= (EAX
& 0xffffff00) | ExtendedError
;
1070 static void GetFileAttribute (struct sigcontext_struct
* context
)
1072 char *filename
= SAFEMAKEPTR (DS
,DX
);
1076 res
= stat(GetUnixFileName(filename
), &s
);
1080 EAX
= (EAX
& 0xffffff00) | ExtendedError
;
1086 if (S_ISDIR(s
.st_mode
))
1088 if ((S_IWRITE
& s
.st_mode
) != S_IWRITE
)
1091 ECX
= (ECX
& 0xffff0000) | cx
;
1098 /************************************************************************/
1100 int do_int21(struct sigcontext_struct
* context
)
1102 if (Options
.relay_debug
)
1104 fprintf(stddeb
,"int21: AX %04x, BX %04x, CX %04x, DX %04x, "
1105 "SI %04x, DI %04x, DS %04x, ES %04x\n",
1106 AX
, BX
, CX
, DX
, SI
, DI
, DS
, ES
);
1111 GetExtendedErrorInfo(context
);
1119 case 0x00: /* TERMINATE PROGRAM */
1122 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1123 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1124 case 0x03: /* READ CHARACTER FROM STDAUX */
1125 case 0x04: /* WRITE CHARACTER TO STDAUX */
1126 case 0x05: /* WRITE CHARACTER TO PRINTER */
1127 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1128 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
1129 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1130 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1131 case 0x0a: /* BUFFERED INPUT */
1132 case 0x0b: /* GET STDIN STATUS */
1133 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
1134 case 0x0f: /* OPEN FILE USING FCB */
1135 case 0x10: /* CLOSE FILE USING FCB */
1136 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1137 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1138 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1139 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1140 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1141 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1142 case 0x23: /* GET FILE SIZE FOR FCB */
1143 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1144 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1145 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1146 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1147 case 0x29: /* PARSE FILENAME INTO FCB */
1148 case 0x2e: /* SET VERIFY FLAG */
1149 IntBarf(0x21, context
);
1152 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1156 case 0x2b: /* SET SYSTEM DATE */
1157 case 0x2d: /* SET SYSTEM TIME */
1158 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
1159 "SWITCHAR" - SET SWITCH CHARACTER
1160 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
1161 case 0x54: /* GET VERIFY FLAG */
1162 case 0x6b: /* NULL FUNCTION */
1163 IntBarf(0x21, context
);
1167 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1171 case 0x0d: /* DISK BUFFER FLUSH */
1172 ResetCflag
; /* dos 6+ only */
1175 case 0x0e: /* SELECT DEFAULT DRIVE */
1176 if (!DOS_ValidDrive(DL
)) {
1177 Error (InvalidDrive
, EC_MediaError
, EL_Disk
);
1180 DOS_SetDefaultDrive(DL
);
1181 AX
= MAX_DOS_DRIVES
;
1186 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1187 FindFirstFCB(context
);
1190 case 0x13: /* DELETE FILE USING FCB */
1191 DeleteFileFCB(context
);
1194 case 0x17: /* RENAME FILE USING FCB */
1195 RenameFileFCB(context
);
1198 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1199 AL
= DOS_GetDefaultDrive();
1203 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1204 dta
= SAFEMAKEPTR(DS
, DX
);
1207 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1208 GetDefDriveAllocInfo(context
);
1211 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1212 GetDriveAllocInfo(context
);
1215 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1216 GetDrivePB(context
);
1219 case 0x25: /* SET INTERRUPT VECTOR */
1220 /* Ignore any attempt to set a segment vector */
1221 dprintf_int(stdnimp
,
1222 "int21: set interrupt vector %2x (%04x:%04x)\n",
1226 case 0x2a: /* GET SYSTEM DATE */
1227 GetSystemDate(context
);
1230 case 0x2c: /* GET SYSTEM TIME */
1231 GetSystemTime(context
);
1234 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1239 case 0x30: /* GET DOS VERSION */
1241 BX
= 0x0012; /* 0x123456 is Wine's serial # */
1245 case 0x31: /* TERMINATE AND STAY RESIDENT */
1246 IntBarf(0x21, context
);
1249 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1250 GetDrivePB(context
);
1253 case 0x33: /* MULTIPLEXED */
1255 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1260 case 0x01: /* SET EXTENDED BREAK STATE */
1263 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1267 case 0x05: /* GET BOOT DRIVE */
1269 /* c: is Wine's bootdrive */
1272 case 0x06: /* GET TRUE VERSION NUMBER */
1278 IntBarf(0x21, context
);
1283 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1284 ES
= segment(heap
->InDosFlag
);
1285 BX
= offset(heap
->InDosFlag
);
1288 case 0x35: /* GET INTERRUPT VECTOR */
1289 /* Return a NULL segment selector - this will bomb,
1290 if anyone ever tries to use it */
1291 dprintf_int(stdnimp
, "int21: get interrupt vector %2x\n",
1297 case 0x36: /* GET FREE DISK SPACE */
1298 GetFreeDiskSpace(context
);
1301 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1302 AX
= 0x02; /* no country support available */
1306 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1310 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1314 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1318 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1319 CreateFile(context
);
1322 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1323 OpenExistingFile(context
);
1326 case 0x3e: /* "CLOSE" - CLOSE FILE */
1330 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1334 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1338 case 0x41: /* "UNLINK" - DELETE FILE */
1339 if (unlink( GetUnixFileName( SAFEMAKEPTR(DS
,DX
)) ) == -1) {
1349 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1353 case 0x43: /* FILE ATTRIBUTES */
1357 GetFileAttribute(context
);
1365 case 0x44: /* IOCTL */
1369 ioctlGetDeviceInfo(context
);
1372 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1373 EDX
= (EDX
& 0xffff0000) | (1<<9) | (1<<12) | (1<<15);
1377 case 0x0b: /* SET SHARING RETRY COUNT */
1380 EAX
= (EAX
& 0xffff0000) | 0x0001;
1386 sharing_retries
= DX
;
1391 ioctlGenericBlkDevReq(context
);
1395 IntBarf(0x21, context
);
1400 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1401 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1406 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1407 GetCurrentDirectory(context
);
1409 /* intlist: many Microsoft products for Windows rely on this */
1412 case 0x48: /* ALLOCATE MEMORY */
1413 case 0x49: /* FREE MEMORY */
1414 case 0x4a: /* RESIZE MEMORY BLOCK */
1415 IntBarf(0x21, context
);
1418 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1419 ExecProgram(context
);
1422 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1426 case 0x4d: /* GET RETURN CODE */
1427 AL
= NoError
; /* normal exit */
1430 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1434 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1438 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1441 IntBarf(0x21, context
);
1444 case 0x56: /* "RENAME" - RENAME FILE */
1445 RenameFile(context
);
1448 case 0x57: /* FILE DATE AND TIME */
1452 GetFileDateTime(context
);
1455 SetFileDateTime(context
);
1460 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1476 case 0x5a: /* CREATE TEMPORARY FILE */
1477 CreateTempFile(context
);
1480 case 0x5b: /* CREATE NEW FILE */
1481 CreateNewFile(context
);
1484 case 0x5d: /* NETWORK */
1486 /* network software not installed */
1491 case 0x5f: /* NETWORK */
1494 case 0x07: /* ENABLE DRIVE */
1495 if (!DOS_EnableDrive(DL
))
1497 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
1507 case 0x08: /* DISABLE DRIVE */
1508 if (!DOS_DisableDrive(DL
))
1510 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
1521 /* network software not installed */
1528 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1529 strncpy(SAFEMAKEPTR(ES
,DI
), SAFEMAKEPTR(DS
,SI
), strlen(SAFEMAKEPTR(DS
,SI
)) & 0x7f);
1533 case 0x61: /* UNUSED */
1534 case 0x62: /* GET CURRENT PSP ADDRESS */
1535 case 0x63: /* UNUSED */
1536 case 0x64: /* OS/2 DOS BOX */
1537 case 0x65: /* GET EXTENDED COUNTRY INFORMATION */
1538 IntBarf(0x21, context
);
1541 case 0x66: /* GLOBAL CODE PAGE TABLE */
1555 case 0x67: /* SET HANDLE COUNT */
1559 case 0x68: /* "FFLUSH" - COMMIT FILE */
1563 case 0x69: /* DISK SERIAL NUMBER */
1567 GetDiskSerialNumber(context
);
1570 SetDiskSerialNumber(context
);
1575 case 0x6a: /* COMMIT FILE */
1579 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1583 IntBarf(0x21, context
);
1590 /**********************************************************************
1595 do_int21((struct sigcontext_struct
*) _CONTEXT
);
1596 ReturnFromRegisterFunc();
1599 void INT21_Init(void)
1604 if ((handle
= GlobalAlloc(GMEM_FIXED
,sizeof(struct DosHeap
))) == 0)
1605 myerror("out of memory");
1607 heap
= (struct DosHeap
*) GlobalLock(handle
);
1608 HEAP_Init(&DosHeapDesc
, heap
, sizeof(struct DosHeap
));
1611 heap
->InDosFlag
= 0;
1612 strcpy(heap
->biosdate
, "01/01/80");