Release 950606
[wine/gsoc_dplay.git] / miscemu / int21.c
blobf0af67be3d0d82c0bd54f01be56b30f0b12eef0d
1 /*
2 * (c) 1993, 1994 Erik Bos
3 */
5 #include <time.h>
6 #include <fcntl.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <sys/file.h>
11 #include <string.h>
12 #include <sys/stat.h>
13 #include <sys/time.h>
14 #include <sys/types.h>
15 #include <unistd.h>
16 #include <utime.h>
17 #include <ctype.h>
18 #include "dos_fs.h"
19 #include "windows.h"
20 #include "msdos.h"
21 #include "registers.h"
22 #include "ldt.h"
23 #include "task.h"
24 #include "options.h"
25 #include "miscemu.h"
26 #include "stddebug.h"
27 /* #define DEBUG_INT */
28 #include "debug.h"
30 /* Define the drive parameter block, as used by int21/1F
31 * and int21/32. This table can be accessed through the
32 * global 'dpb' pointer, which points into the local dos
33 * heap.
35 struct DPB
37 BYTE drive_num; /* 0=A, etc. */
38 BYTE unit_num; /* Drive's unit number (?) */
39 WORD sector_size; /* Sector size in bytes */
40 BYTE high_sector; /* Highest sector in a cluster */
41 BYTE shift; /* Shift count (?) */
42 WORD reserved; /* Number of reserved sectors at start */
43 BYTE num_FAT; /* Number of FATs */
44 WORD dir_entries; /* Number of root dir entries */
45 WORD first_data; /* First data sector */
46 WORD high_cluster; /* Highest cluster number */
47 WORD sectors_in_FAT; /* Number of sectors per FAT */
48 WORD start_dir; /* Starting sector of first dir */
49 DWORD driver_head; /* Address of device driver header (?) */
50 BYTE media_ID; /* Media ID */
51 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
52 DWORD next; /* Pointer to next DPB in list */
53 WORD free_search; /* Free cluster search start */
54 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
57 WORD ExtendedError, CodePage = 437;
58 BYTE ErrorClass, Action, ErrorLocus;
59 struct DPB *dpb;
60 DWORD dpbsegptr;
62 struct DosHeap {
63 BYTE InDosFlag;
64 BYTE mediaID;
65 BYTE biosdate[8];
66 struct DPB dpb;
68 static struct DosHeap *heap;
69 static WORD DosHeapHandle;
71 WORD sharing_retries = 3; /* number of retries at sharing violation */
72 WORD sharing_pause = 1; /* pause between retries */
74 extern char TempDirectory[];
76 static int Error(int e, int class, int el)
78 ErrorClass = class;
79 Action = SA_Ask4Retry;
80 ErrorLocus = el;
81 ExtendedError = e;
83 return e;
86 void errno_to_doserr(void)
88 switch (errno) {
89 case EAGAIN:
90 Error (ShareViolation, EC_Temporary, EL_Unknown);
91 break;
92 case EBADF:
93 Error (InvalidHandle, EC_AppError, EL_Unknown);
94 break;
95 case ENOSPC:
96 Error (DiskFull, EC_MediaError, EL_Disk);
97 break;
98 case EACCES:
99 case EPERM:
100 case EROFS:
101 Error (WriteProtected, EC_AccessDenied, EL_Unknown);
102 break;
103 case EBUSY:
104 Error (LockViolation, EC_AccessDenied, EL_Unknown);
105 break;
106 case ENOENT:
107 Error (FileNotFound, EC_NotFound, EL_Unknown);
108 break;
109 case EISDIR:
110 Error (CanNotMakeDir, EC_AccessDenied, EL_Unknown);
111 break;
112 case ENFILE:
113 case EMFILE:
114 Error (NoMoreFiles, EC_MediaError, EL_Unknown);
115 break;
116 case EEXIST:
117 Error (FileExists, EC_Exists, EL_Disk);
118 break;
119 default:
120 dprintf_int(stddeb, "int21: unknown errno %d!\n", errno);
121 Error (GeneralFailure, EC_SystemFailure, EL_Unknown);
122 break;
126 BYTE *GetCurrentDTA(void)
128 TDB *pTask = (TDB *)GlobalLock( GetCurrentTask() );
129 return (BYTE *)PTR_SEG_TO_LIN( pTask->dta );
133 void ChopOffWhiteSpace(char *string)
135 int length;
137 for (length = strlen(string) ; length ; length--)
138 if (string[length] == ' ')
139 string[length] = '\0';
142 static void CreateBPB(int drive, BYTE *data)
144 if (drive > 1) {
145 setword(data, 512);
146 data[2] = 2;
147 setword(&data[3], 0);
148 data[5] = 2;
149 setword(&data[6], 240);
150 setword(&data[8], 64000);
151 data[0x0a] = 0xf8;
152 setword(&data[0x0b], 40);
153 setword(&data[0x0d], 56);
154 setword(&data[0x0f], 2);
155 setword(&data[0x11], 0);
156 setword(&data[0x1f], 800);
157 data[0x21] = 5;
158 setword(&data[0x22], 1);
159 } else { /* 1.44mb */
160 setword(data, 512);
161 data[2] = 2;
162 setword(&data[3], 0);
163 data[5] = 2;
164 setword(&data[6], 240);
165 setword(&data[8], 2880);
166 data[0x0a] = 0xf8;
167 setword(&data[0x0b], 6);
168 setword(&data[0x0d], 18);
169 setword(&data[0x0f], 2);
170 setword(&data[0x11], 0);
171 setword(&data[0x1f], 80);
172 data[0x21] = 7;
173 setword(&data[0x22], 2);
177 static void GetFreeDiskSpace(struct sigcontext_struct *context)
179 int drive;
180 long size,available;
182 if (DL == 0)
183 drive = DOS_GetDefaultDrive();
184 else
185 drive = DL - 1;
187 if (!DOS_ValidDrive(drive)) {
188 Error(InvalidDrive, EC_MediaError , EL_Disk);
189 AX = 0xffff;
190 return;
193 if (!DOS_GetFreeSpace(drive, &size, &available)) {
194 Error(GeneralFailure, EC_MediaError , EL_Disk);
195 AX = 0xffff;
196 return;
199 AX = 4;
200 CX = 512;
202 BX = (available / (CX * AX));
203 DX = (size / (CX * AX));
204 Error (0,0,0);
207 static void GetDriveAllocInfo(struct sigcontext_struct *context)
209 long size, available;
211 if (!DOS_ValidDrive(DL)) {
212 AX = 4;
213 CX = 512;
214 DX = 0;
215 Error (InvalidDrive, EC_MediaError, EL_Disk);
216 return;
219 if (!DOS_GetFreeSpace(DL, &size, &available)) {
220 Error(GeneralFailure, EC_MediaError , EL_Disk);
221 AX = 0xffff;
222 return;
225 EAX = 4;
226 ECX = 512;
227 EDX = (size / (CX * AX));
229 heap->mediaID = 0xf0;
231 DS = DosHeapHandle;
232 BX = (int)&heap->mediaID - (int)heap;
233 Error (0,0,0);
236 static void GetDefDriveAllocInfo(struct sigcontext_struct *context)
238 DX = DOS_GetDefaultDrive();
239 GetDriveAllocInfo(context);
242 static void GetDrivePB(struct sigcontext_struct *context, int drive)
244 if(!DOS_ValidDrive(drive))
246 Error (InvalidDrive, EC_MediaError, EL_Disk);
247 AX = 0x00ff;
249 else
251 dprintf_int(stddeb, "int21: GetDrivePB not fully implemented.\n");
253 /* FIXME: I have no idea what a lot of this information should
254 * say or whether it even really matters since we're not allowing
255 * direct block access. However, some programs seem to depend on
256 * getting at least _something_ back from here. The 'next' pointer
257 * does worry me, though. Should we have a complete table of
258 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
260 dpb->drive_num = dpb->unit_num = drive; /* The same? */
261 dpb->sector_size = 512;
262 dpb->high_sector = 1;
263 dpb->shift = 0;
264 dpb->reserved = 0;
265 dpb->num_FAT = 1;
266 dpb->dir_entries = 2;
267 dpb->first_data = 2;
268 dpb->high_cluster = 1023;
269 dpb->sectors_in_FAT = 1;
270 dpb->start_dir = 1;
271 dpb->driver_head = 0;
272 dpb->media_ID = (drive > 1) ? 0xF8 : 0xF0;
273 dpb->access_flag = 0;
274 dpb->next = 0;
275 dpb->free_search = 0;
276 dpb->free_clusters = 0xFFFF; /* unknown */
278 AL = 0x00;
279 DS = SELECTOROF(dpbsegptr);
280 BX = OFFSETOF(dpbsegptr);
284 static void ReadFile(struct sigcontext_struct *context)
286 char *ptr;
287 int size;
289 /* can't read from stdout / stderr */
290 if ((BX == 1) || (BX == 2)) {
291 Error (InvalidHandle, EL_Unknown, EC_Unknown);
292 AX = InvalidHandle;
293 SetCflag;
294 dprintf_int(stddeb,
295 "int21: read (%d, void *, 0x%x) = EBADF\n", BX, CX);
296 return;
299 ptr = PTR_SEG_OFF_TO_LIN (DS,DX);
300 if (BX == 0) {
301 *ptr = EOF;
302 Error (0,0,0);
303 AX = 1;
304 ResetCflag;
305 dprintf_int(stddeb,
306 "int21: read (%d, void *, 0x%x) = EOF\n", BX, CX);
307 return;
308 } else {
309 size = read(BX, ptr, CX);
310 dprintf_int(stddeb,
311 "int21: read (%d, void *, 0x%x) = 0x%x\n",
312 BX, CX, size);
313 if (size == -1) {
314 errno_to_doserr();
315 AL = ExtendedError;
316 SetCflag;
317 return;
319 Error (0,0,0);
320 AX = size;
321 ResetCflag;
325 static void WriteFile(struct sigcontext_struct *context)
327 char *ptr;
328 int x,size;
330 ptr = PTR_SEG_OFF_TO_LIN (DS,DX);
332 if (BX == 0) {
333 Error (InvalidHandle, EC_Unknown, EL_Unknown);
334 EAX = InvalidHandle;
335 SetCflag;
336 return;
339 if (BX < 3) {
340 for (x = 0;x != CX;x++) {
341 dprintf_int(stddeb, "%c", *ptr++);
343 fflush(stddeb);
345 Error (0,0,0);
346 AL = CX;
347 ResetCflag;
348 } else {
349 size = write(BX, ptr , CX);
350 if (size == 0) {
351 Error (WriteFault, EC_Unknown, EL_Unknown);
352 AL = ExtendedError;
353 return;
356 if (size == -1) {
357 errno_to_doserr();
358 AL = ExtendedError;
359 SetCflag;
360 return;
362 Error (0,0,0);
363 AX = size;
364 ResetCflag;
368 static void SeekFile(struct sigcontext_struct *context)
370 off_t status, fileoffset;
372 switch (AL) {
373 case 1: fileoffset = SEEK_CUR;
374 break;
375 case 2: fileoffset = SEEK_END;
376 break;
377 default:
378 case 0: fileoffset = SEEK_SET;
379 break;
381 status = lseek(BX, (CX << 16) + DX, fileoffset);
383 dprintf_int (stddeb, "int21: seek (%d, 0x%x, %d) = 0x%lx\n",
384 BX, (CX << 16) + DX, AL, status);
386 if (status == -1) {
387 errno_to_doserr();
388 AL = ExtendedError; SetCflag;
389 return;
391 Error (0,0,0);
392 AX = (status & 0xffff);
393 DX = ((status >> 16) & 0xffff);
395 ResetCflag;
398 static void ioctlGetDeviceInfo(struct sigcontext_struct *context)
401 dprintf_int (stddeb, "int21: ioctl (%d, GetDeviceInfo)\n", BX);
403 switch (BX) {
404 case 0:
405 case 1:
406 case 2:
407 DX = 0x80d0 + (1 << BX);
408 ResetCflag;
409 break;
411 default:
413 struct stat sbuf;
415 if (fstat(BX, &sbuf) < 0)
417 IntBarf(0x21, context);
418 DX = 0x50;
419 SetCflag;
420 return;
423 /* This isn't the right answer, but should be close enough. */
424 DX = 0x0943;
427 ResetCflag;
430 static void ioctlGenericBlkDevReq(struct sigcontext_struct *context)
432 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS, DX);
433 int drive;
435 if (BL == 0)
436 drive = DOS_GetDefaultDrive();
437 else
438 drive = BL - 1;
440 if (!DOS_ValidDrive(drive)) {
441 AX = 0x02;
442 SetCflag;
443 return;
446 if (CH != 0x08) {
447 IntBarf(0x21, context);
448 return;
450 switch (CL) {
451 case 0x60: /* get device parameters */
452 /* used by w4wgrp's winfile */
453 memset(dataptr, 0, 0x26);
454 dataptr[0] = 0x04;
455 dataptr[6] = 0; /* media type */
456 if (drive > 1)
458 dataptr[1] = 0x05; /* fixed disk */
459 setword(&dataptr[2], 0x01); /* non removable */
460 setword(&dataptr[4], 0x300); /* # of cylinders */
462 else
464 dataptr[1] = 0x07; /* block dev, floppy */
465 setword(&dataptr[2], 0x02); /* removable */
466 setword(&dataptr[4], 80); /* # of cylinders */
468 CreateBPB(drive, &dataptr[7]);
469 ResetCflag;
470 return;
471 default:
472 IntBarf(0x21, context);
476 static void GetSystemDate(struct sigcontext_struct *context)
478 struct tm *now;
479 time_t ltime;
481 ltime = time(NULL);
482 now = localtime(&ltime);
484 CX = now->tm_year + 1900 - 1980;
485 DX = ((now->tm_mon + 1) << 8) | now->tm_mday;
486 AX = now->tm_wday;
489 static void GetSystemTime(struct sigcontext_struct *context)
491 struct tm *now;
492 struct timeval tv;
494 gettimeofday(&tv,NULL); /* Note use of gettimeofday(), instead of time() */
495 now = localtime(&tv.tv_sec);
497 CX = (now->tm_hour<<8) | now->tm_min;
498 DX = (now->tm_sec<<8) | tv.tv_usec/10000;
499 /* Note hundredths of seconds */
502 static void GetExtendedErrorInfo(struct sigcontext_struct *context)
504 AL = ExtendedError;
505 BX = (ErrorClass << 8) | Action;
506 CH = ErrorLocus << 8;
509 static void CreateFile(struct sigcontext_struct *context)
511 int handle;
513 if ((handle = open(DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX)),
514 O_CREAT | O_TRUNC | O_RDWR )) == -1) {
515 errno_to_doserr();
516 AL = ExtendedError;
517 SetCflag;
518 return;
520 Error (0,0,0);
521 EAX = (EAX & 0xffff0000) | handle;
522 ResetCflag;
525 void OpenExistingFile(struct sigcontext_struct *context)
527 int handle;
528 int mode;
529 int lock;
531 switch (AX & 0x0007)
533 case 0:
534 mode = O_RDONLY;
535 break;
537 case 1:
538 mode = O_WRONLY;
539 break;
541 default:
542 mode = O_RDWR;
543 break;
546 if ((handle = open(DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS,DX)),
547 mode)) == -1)
549 if( Options.allowReadOnly )
550 handle = open( DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS,DX)),
551 O_RDONLY );
552 if( handle == -1 )
554 dprintf_int (stddeb, "int21: open (%s, %d) = -1\n",
555 DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS,DX)), mode);
556 errno_to_doserr();
557 AL = ExtendedError;
558 SetCflag;
559 return;
563 dprintf_int (stddeb, "int21: open (%s, %d) = %d\n",
564 DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS,DX)), mode, handle);
566 switch (AX & 0x0070)
568 case 0x00: /* compatability mode */
569 case 0x40: /* DENYNONE */
570 lock = -1;
571 break;
573 case 0x30: /* DENYREAD */
574 dprintf_int(stddeb,
575 "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
576 (char *)PTR_SEG_OFF_TO_LIN(DS,DX));
577 case 0x10: /* DENYALL */
578 lock = LOCK_EX;
579 break;
581 case 0x20: /* DENYWRITE */
582 lock = LOCK_SH;
583 break;
585 default:
586 lock = -1;
589 if (lock != -1)
592 int result,retries=sharing_retries;
594 result = flock(handle, lock | LOCK_NB);
595 if ( retries && (!result) )
597 int i;
598 for(i=0;i<32768*((int)sharing_pause);i++)
599 result++; /* stop the optimizer */
600 for(i=0;i<32768*((int)sharing_pause);i++)
601 result--;
604 while( (!result) && (!(retries--)) );
606 if(result)
608 errno_to_doserr();
609 EAX = (EAX & 0xffffff00) | ExtendedError;
610 close(handle);
611 SetCflag;
612 return;
617 Error (0,0,0);
618 EAX = (EAX & 0xffff0000) | handle;
619 ResetCflag;
622 static void CloseFile(struct sigcontext_struct *context)
624 dprintf_int (stddeb, "int21: close (%d)\n", BX);
626 if (close(BX) == -1) {
627 errno_to_doserr();
628 AL = ExtendedError;
629 SetCflag;
630 return;
632 Error (0,0,0);
633 AL = NoError;
634 ResetCflag;
637 static void RenameFile(struct sigcontext_struct *context)
639 char *newname, *oldname;
641 dprintf_int(stddeb,"int21: renaming %s to %s\n",
642 (char *)PTR_SEG_OFF_TO_LIN(DS,DX), (char *)PTR_SEG_OFF_TO_LIN(ES,DI) );
644 oldname = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX) );
645 newname = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(ES,DI) );
647 rename( oldname, newname);
648 ResetCflag;
652 static void MakeDir(struct sigcontext_struct *context)
654 char *dirname;
656 dprintf_int(stddeb,"int21: makedir %s\n", (char *)PTR_SEG_OFF_TO_LIN(DS,DX) );
658 if ((dirname = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX) ))== NULL) {
659 AL = CanNotMakeDir;
660 SetCflag;
661 return;
664 if (mkdir(dirname,0) == -1) {
665 AL = CanNotMakeDir;
666 SetCflag;
667 return;
669 ResetCflag;
672 static void ChangeDir(struct sigcontext_struct *context)
674 int drive;
675 char *dirname = PTR_SEG_OFF_TO_LIN(DS,DX);
676 drive = DOS_GetDefaultDrive();
677 dprintf_int(stddeb,"int21: changedir %s\n", dirname);
678 if (dirname != NULL && dirname[1] == ':') {
679 drive = toupper(dirname[0]) - 'A';
680 dirname += 2;
682 if (!DOS_ChangeDir(drive, dirname))
684 SetCflag;
685 AX=0x03;
689 static void RemoveDir(struct sigcontext_struct *context)
691 char *dirname;
693 dprintf_int(stddeb,"int21: removedir %s\n", (char *)PTR_SEG_OFF_TO_LIN(DS,DX) );
695 if ((dirname = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX) ))== NULL) {
696 AL = CanNotMakeDir;
697 SetCflag;
698 return;
702 if (strcmp(unixname,DosDrives[drive].CurrentDirectory)) {
703 AL = CanNotRemoveCwd;
704 SetCflag;
707 if (rmdir(dirname) == -1) {
708 AL = CanNotMakeDir;
709 SetCflag;
711 ResetCflag;
714 static void ExecProgram(struct sigcontext_struct *context)
716 execl("wine", DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX)) );
719 static void FindNext(struct sigcontext_struct *context)
721 struct dosdirent *dp;
722 struct tm *t;
723 BYTE *dta = GetCurrentDTA();
725 memcpy(&dp, dta+0x11, sizeof(dp));
727 do {
728 if ((dp = DOS_readdir(dp)) == NULL) {
729 Error(NoMoreFiles, EC_MediaError , EL_Disk);
730 AL = NoMoreFiles;
731 SetCflag;
732 return;
734 } /* while (*(dta + 0x0c) != dp->attribute);*/
735 while ( ( dp->search_attribute & dp->attribute) != dp->attribute);
737 *(dta + 0x15) = dp->attribute;
738 setword(&dta[0x0d], dp->entnum);
740 t = localtime(&(dp->filetime));
741 setword(&dta[0x16], (t->tm_hour << 11) + (t->tm_min << 5) +
742 (t->tm_sec / 2)); /* time */
743 setword(&dta[0x18], ((t->tm_year - 80) << 9) + (t->tm_mon << 5) +
744 (t->tm_mday)); /* date */
745 setdword(&dta[0x1a], dp->filesize);
746 strncpy(dta + 0x1e, dp->filename, 13);
748 AL = 0;
749 ResetCflag;
751 dprintf_int(stddeb, "int21: FindNext -- (%s) index=%d size=%ld\n", dp->filename, dp->entnum, dp->filesize);
752 return;
755 static void FindFirst(struct sigcontext_struct *context)
757 BYTE drive, *path = PTR_SEG_OFF_TO_LIN(DS, DX);
758 struct dosdirent *dp;
760 BYTE *dta = GetCurrentDTA();
762 dprintf_int(stddeb, "int21: FindFirst path = %s\n", path);
764 if ((*path)&&(path[1] == ':')) {
765 drive = (islower(*path) ? toupper(*path) : *path) - 'A';
767 if (!DOS_ValidDrive(drive)) {
768 Error(InvalidDrive, EC_MediaError , EL_Disk);
769 AL = InvalidDrive;
770 SetCflag;
771 return;
773 } else
774 drive = DOS_GetDefaultDrive();
776 *dta = drive;
777 memset(dta + 1 , '?', 11);
778 *(dta + 0x0c) = ECX & (FA_LABEL | FA_DIREC);
780 if (ECX & FA_LABEL) {
781 /* return volume label */
783 if (DOS_GetVolumeLabel(drive) != NULL)
784 strncpy(dta + 0x1e, DOS_GetVolumeLabel(drive), 8);
786 AL = 0;
787 ResetCflag;
788 return;
791 if ((dp = DOS_opendir(path)) == NULL) {
792 Error(PathNotFound, EC_MediaError, EL_Disk);
793 AL = FileNotFound;
794 SetCflag;
795 return;
798 dp->search_attribute = ECX & (FA_LABEL | FA_DIREC);
799 memcpy(dta + 0x11, &dp, sizeof(dp));
800 FindNext(context);
803 static void GetFileDateTime(struct sigcontext_struct *context)
805 struct stat filestat;
806 struct tm *now;
808 fstat( BX, &filestat );
809 now = localtime (&filestat.st_mtime);
811 CX = ((now->tm_hour * 0x2000) + (now->tm_min * 0x20) + now->tm_sec/2);
812 DX = ((now->tm_year * 0x200) + (now->tm_mon * 0x20) + now->tm_mday);
814 ResetCflag;
817 static void SetFileDateTime(struct sigcontext_struct *context)
819 char *filename;
820 struct utimbuf filetime;
822 /* FIXME: Argument isn't the name of the file in DS:DX,
823 but the file handle in BX */
824 filename = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX) );
826 filetime.actime = 0L;
827 filetime.modtime = filetime.actime;
829 utime(filename, &filetime);
830 ResetCflag;
833 static void CreateTempFile(struct sigcontext_struct *context)
835 char temp[256];
836 int handle;
838 sprintf(temp,"%s\\win%d.tmp",TempDirectory,(int) getpid());
840 dprintf_int(stddeb,"CreateTempFile %s\n",temp);
842 handle = open(DOS_GetUnixFileName(temp), O_CREAT | O_TRUNC | O_RDWR);
844 if (handle == -1) {
845 AL = WriteProtected;
846 SetCflag;
847 return;
850 strcpy(PTR_SEG_OFF_TO_LIN(DS,DX), temp);
852 AX = handle;
853 ResetCflag;
856 static void CreateNewFile(struct sigcontext_struct *context)
858 int handle;
860 if ((handle = open(DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX) ), O_CREAT | O_EXCL | O_RDWR)) == -1) {
861 AL = WriteProtected;
862 SetCflag;
863 return;
866 AX = handle;
867 ResetCflag;
870 static void GetCurrentDirectory(struct sigcontext_struct *context)
872 int drive;
874 if (DL == 0)
875 drive = DOS_GetDefaultDrive();
876 else
877 drive = DL - 1;
879 if (!DOS_ValidDrive(drive)) {
880 AL = InvalidDrive;
881 SetCflag;
882 return;
885 strcpy(PTR_SEG_OFF_TO_LIN(DS,SI), DOS_GetCurrentDir(drive) );
886 ResetCflag;
889 static void GetDiskSerialNumber(struct sigcontext_struct *context)
891 int drive;
892 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS, DX);
893 DWORD serialnumber;
895 if (BL == 0)
896 drive = DOS_GetDefaultDrive();
897 else
898 drive = BL - 1;
900 if (!DOS_ValidDrive(drive)) {
901 AL =InvalidDrive;
902 SetCflag;
903 return;
906 DOS_GetSerialNumber(drive, &serialnumber);
908 setword(dataptr, 0);
909 setdword(&dataptr[2], serialnumber);
910 strncpy(dataptr + 6, DOS_GetVolumeLabel(drive), 8);
911 strncpy(dataptr + 0x11, "FAT16 ", 8);
913 AL = 0;
914 ResetCflag;
917 static void SetDiskSerialNumber(struct sigcontext_struct *context)
919 int drive;
920 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS, DX);
921 DWORD serialnumber;
923 if (BL == 0)
924 drive = DOS_GetDefaultDrive();
925 else
926 drive = BL - 1;
928 if (!DOS_ValidDrive(drive)) {
929 AL = InvalidDrive;
930 SetCflag;
931 return;
934 serialnumber = dataptr[1] + (dataptr[2] << 8) + (dataptr[3] << 16) +
935 (dataptr[4] << 24);
937 DOS_SetSerialNumber(drive, serialnumber);
938 AL = 1L;
939 ResetCflag;
942 static void DumpFCB(BYTE *fcb)
944 int x, y;
946 fcb -= 7;
948 for (y = 0; y !=2 ; y++) {
949 for (x = 0; x!=15;x++)
950 dprintf_int(stddeb, "%02x ", *fcb++);
951 dprintf_int(stddeb,"\n");
955 /* microsoft's programmers should be shot for using CP/M style int21
956 calls in Windows for Workgroup's winfile.exe */
958 static void FindFirstFCB(struct sigcontext_struct *context)
960 BYTE *fcb = PTR_SEG_OFF_TO_LIN(DS, DX);
961 struct fcb *standard_fcb;
962 struct fcb *output_fcb;
963 int drive;
964 char path[12];
966 BYTE *dta = GetCurrentDTA();
968 DumpFCB( fcb );
970 if ((*fcb) == 0xff)
972 standard_fcb = (struct fcb *)(fcb + 7);
973 output_fcb = (struct fcb *)(dta + 7);
974 *dta = 0xff;
976 else
978 standard_fcb = (struct fcb *)fcb;
979 output_fcb = (struct fcb *)dta;
982 if (standard_fcb->drive)
984 drive = standard_fcb->drive - 1;
985 if (!DOS_ValidDrive(drive))
987 Error (InvalidDrive, EC_MediaError, EL_Disk);
988 AL = 0xff;
989 return;
992 else
993 drive = DOS_GetDefaultDrive();
995 output_fcb->drive = drive;
997 if (*(fcb) == 0xff)
999 if (*(fcb+6) & FA_LABEL) /* return volume label */
1001 *(dta+6) = FA_LABEL;
1002 memset(&output_fcb->name, ' ', 11);
1003 if (DOS_GetVolumeLabel(drive) != NULL)
1005 strncpy(output_fcb->name, DOS_GetVolumeLabel(drive), 11);
1006 AL = 0x00;
1007 return;
1012 strncpy(output_fcb->name, standard_fcb->name, 11);
1013 if (*fcb == 0xff)
1014 *(dta+6) = ( *(fcb+6) & (!FA_DIREC));
1016 sprintf(path,"%c:*.*",drive+'A');
1017 if ((output_fcb->directory = DOS_opendir(path))==NULL)
1019 Error (PathNotFound, EC_MediaError, EL_Disk);
1020 AL = 0xff;
1021 return;
1027 static void DeleteFileFCB(struct sigcontext_struct *context)
1029 BYTE *fcb = PTR_SEG_OFF_TO_LIN(DS, DX);
1030 int drive;
1031 struct dosdirent *dp;
1032 char temp[256], *ptr;
1034 DumpFCB( fcb );
1036 if (*fcb)
1037 drive = *fcb - 1;
1038 else
1039 drive = DOS_GetDefaultDrive();
1041 strcpy(temp, DOS_GetCurrentDir(drive));
1042 strcat(temp, "\\");
1043 strncat(temp, fcb + 1, 8);
1044 ChopOffWhiteSpace(temp);
1045 strncat(temp, fcb + 9, 3);
1046 ChopOffWhiteSpace(temp);
1048 if ((dp = DOS_opendir(temp)) == NULL) {
1049 Error(InvalidDrive, EC_MediaError , EL_Disk);
1050 AL = 0xffL;
1051 return;
1054 strcpy(temp, DOS_GetCurrentDir(drive) );
1055 strcat(temp, "\\");
1057 ptr = temp + strlen(temp);
1059 while (DOS_readdir(dp) != NULL)
1061 strcpy(ptr, dp->filename);
1062 dprintf_int(stddeb, "int21: delete file %s\n", temp);
1063 /* unlink(DOS_GetUnixFileName(temp)); */
1065 DOS_closedir(dp);
1066 AL = 0;
1069 static void RenameFileFCB(struct sigcontext_struct *context)
1071 BYTE *fcb = PTR_SEG_OFF_TO_LIN(DS, DX);
1072 int drive;
1073 struct dosdirent *dp;
1074 char temp[256], oldname[256], newname[256], *oldnameptr, *newnameptr;
1076 DumpFCB( fcb );
1078 if (*fcb)
1079 drive = *fcb - 1;
1080 else
1081 drive = DOS_GetDefaultDrive();
1083 strcpy(temp, DOS_GetCurrentDir(drive));
1084 strcat(temp, "\\");
1085 strncat(temp, fcb + 1, 8);
1086 ChopOffWhiteSpace(temp);
1087 strncat(temp, fcb + 9, 3);
1088 ChopOffWhiteSpace(temp);
1090 if ((dp = DOS_opendir(temp)) == NULL) {
1091 Error(InvalidDrive, EC_MediaError , EL_Disk);
1092 AL = 0xffL;
1093 return;
1096 strcpy(oldname, DOS_GetCurrentDir(drive) );
1097 strcat(oldname, "\\");
1098 oldnameptr = oldname + strlen(oldname);
1100 strcpy(newname, DOS_GetCurrentDir(drive) );
1101 strcat(newname, "\\");
1102 newnameptr = newname + strlen(newname);
1104 while (DOS_readdir(dp) != NULL)
1106 strcpy(oldnameptr, dp->filename);
1107 strcpy(newnameptr, fcb + 1);
1108 dprintf_int(stddeb, "int21: renamefile %s -> %s\n",
1109 oldname, newname);
1111 DOS_closedir(dp);
1112 AL = 0;
1117 static void fLock (struct sigcontext_struct * context)
1119 struct flock f;
1120 int result,retries=sharing_retries;
1122 f.l_start = MAKELONG(DX,CX);
1123 f.l_len = MAKELONG(DI,SI);
1124 f.l_whence = 0;
1125 f.l_pid = 0;
1127 switch ( AX & 0xff )
1129 case 0x00: /* LOCK */
1130 f.l_type = F_WRLCK;
1131 break;
1133 case 0x01: /* UNLOCK */
1134 f.l_type = F_UNLCK;
1135 break;
1137 default:
1138 EAX = (EAX & 0xffff0000) | 0x0001;
1139 SetCflag;
1140 return;
1144 result = fcntl(BX,F_SETLK,&f);
1145 if ( retries && (!result) )
1147 int i;
1148 for(i=0;i<32768*((int)sharing_pause);i++)
1149 result++; /* stop the optimizer */
1150 for(i=0;i<32768*((int)sharing_pause);i++)
1151 result--;
1154 while( (!result) && (!(retries--)) );
1156 if(result)
1158 errno_to_doserr();
1159 EAX = (EAX & 0xffffff00) | ExtendedError;
1160 SetCflag;
1161 return;
1164 Error (0,0,0);
1165 ResetCflag;
1169 static void GetFileAttribute (struct sigcontext_struct * context)
1171 char *filename = PTR_SEG_OFF_TO_LIN (DS,DX);
1172 struct stat s;
1173 int res,cx;
1175 res = stat(DOS_GetUnixFileName(filename), &s);
1176 if (res==-1)
1178 errno_to_doserr();
1179 EAX = (EAX & 0xffffff00) | ExtendedError;
1180 SetCflag;
1181 return;
1184 cx = 0;
1185 if (S_ISDIR(s.st_mode))
1186 cx|=0x10;
1187 if ((S_IWRITE & s.st_mode) != S_IWRITE)
1188 cx|=0x01;
1190 dprintf_int (stddeb, "int21: GetFileAttributes (%s) = 0x%x\n",
1191 filename, cx);
1193 ECX = (ECX & 0xffff0000) | cx;
1194 ResetCflag;
1195 Error (0,0,0);
1199 extern void LOCAL_PrintHeap (WORD ds);
1201 /************************************************************************/
1203 int do_int21(struct sigcontext_struct * context)
1205 int drive;
1207 dprintf_int(stddeb,"int21: AX %04x, BX %04x, CX %04x, DX %04x, "
1208 "SI %04x, DI %04x, DS %04x, ES %04x\n",
1209 AX, BX, CX, DX, SI, DI, DS, ES);
1211 if (AH == 0x59)
1213 GetExtendedErrorInfo(context);
1214 return 1;
1216 else
1218 Error (0,0,0);
1219 switch(AH)
1221 case 0x00: /* TERMINATE PROGRAM */
1222 TASK_KillCurrentTask( 0 );
1223 break;
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 IntBarf(0x21, context);
1253 break;
1255 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1256 case 0x1d:
1257 case 0x1e:
1258 case 0x20:
1259 case 0x2b: /* SET SYSTEM DATE */
1260 case 0x2d: /* SET SYSTEM TIME */
1261 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
1262 "SWITCHAR" - SET SWITCH CHARACTER
1263 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
1264 case 0x54: /* GET VERIFY FLAG */
1265 case 0x6b: /* NULL FUNCTION */
1266 IntBarf(0x21, context);
1267 EAX &= 0xff00;
1268 break;
1270 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1271 fLock(context);
1272 break;
1274 case 0x0d: /* DISK BUFFER FLUSH */
1275 ResetCflag; /* dos 6+ only */
1276 break;
1278 case 0x0e: /* SELECT DEFAULT DRIVE */
1279 if (!DOS_ValidDrive(DL)) {
1280 Error (InvalidDrive, EC_MediaError, EL_Disk);
1281 break;
1282 } else {
1283 DOS_SetDefaultDrive(DL);
1284 AX = MAX_DOS_DRIVES;
1285 Error(0,0,0);
1287 break;
1289 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1290 FindFirstFCB(context);
1291 break;
1293 case 0x13: /* DELETE FILE USING FCB */
1294 DeleteFileFCB(context);
1295 break;
1297 case 0x17: /* RENAME FILE USING FCB */
1298 RenameFileFCB(context);
1299 break;
1301 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1302 AL = DOS_GetDefaultDrive();
1303 Error (0,0,0);
1304 break;
1306 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1308 TDB *pTask = (TDB *)GlobalLock( GetCurrentTask() );
1309 pTask->dta = MAKELONG( DX, DS );
1310 dprintf_int(stddeb, "int21: Set DTA: %08lx\n", pTask->dta);
1312 break;
1314 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1315 GetDefDriveAllocInfo(context);
1316 break;
1318 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1319 GetDriveAllocInfo(context);
1320 break;
1322 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1323 GetDrivePB(context, DOS_GetDefaultDrive());
1324 break;
1326 case 0x25: /* SET INTERRUPT VECTOR */
1327 INT_SetHandler( AL, MAKELONG( DX, DS ) );
1328 break;
1330 case 0x2a: /* GET SYSTEM DATE */
1331 GetSystemDate(context);
1332 break;
1334 case 0x2c: /* GET SYSTEM TIME */
1335 GetSystemTime(context);
1336 break;
1338 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1340 TDB *pTask = (TDB *)GlobalLock( GetCurrentTask() );
1341 ES = SELECTOROF( pTask->dta );
1342 BX = OFFSETOF( pTask->dta );
1344 break;
1346 case 0x30: /* GET DOS VERSION */
1347 AX = DOSVERSION;
1348 BX = 0x0012; /* 0x123456 is Wine's serial # */
1349 CX = 0x3456;
1350 break;
1352 case 0x31: /* TERMINATE AND STAY RESIDENT */
1353 IntBarf(0x21, context);
1354 break;
1356 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1357 GetDrivePB(context, (DL == 0) ? (DOS_GetDefaultDrive()) : (DL-1));
1358 break;
1360 case 0x33: /* MULTIPLEXED */
1361 switch (AL) {
1362 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1363 if (!(AL))
1364 EDX &= 0xff00L;
1365 break;
1367 case 0x01: /* SET EXTENDED BREAK STATE */
1368 break;
1370 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1371 DL = 0;
1372 break;
1374 case 0x05: /* GET BOOT DRIVE */
1375 DL = 2;
1376 /* c: is Wine's bootdrive */
1377 break;
1379 case 0x06: /* GET TRUE VERSION NUMBER */
1380 EBX = DOSVERSION;
1381 EDX = 0x00;
1382 break;
1384 default:
1385 IntBarf(0x21, context);
1386 break;
1388 break;
1390 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1391 ES = DosHeapHandle;
1392 BX = (int)&heap->InDosFlag - (int)heap;
1393 break;
1395 case 0x35: /* GET INTERRUPT VECTOR */
1397 SEGPTR addr = INT_GetHandler( AL );
1398 ES = SELECTOROF(addr);
1399 BX = OFFSETOF(addr);
1401 break;
1403 case 0x36: /* GET FREE DISK SPACE */
1404 GetFreeDiskSpace(context);
1405 break;
1407 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1408 AX = 0x02; /* no country support available */
1409 SetCflag;
1410 break;
1412 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1413 MakeDir(context);
1414 break;
1416 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1417 RemoveDir(context);
1418 break;
1420 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1421 ChangeDir(context);
1422 break;
1424 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1425 CreateFile(context);
1426 break;
1428 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1429 OpenExistingFile(context);
1430 break;
1432 case 0x3e: /* "CLOSE" - CLOSE FILE */
1433 CloseFile(context);
1434 break;
1436 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1437 ReadFile(context);
1438 break;
1440 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1441 WriteFile(context);
1442 break;
1444 case 0x41: /* "UNLINK" - DELETE FILE */
1445 if (unlink( DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX)) ) == -1) {
1446 errno_to_doserr();
1447 AL = ExtendedError;
1448 SetCflag;
1449 break;
1451 Error(0,0,0);
1452 ResetCflag;
1453 break;
1455 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1456 SeekFile(context);
1457 break;
1459 case 0x43: /* FILE ATTRIBUTES */
1460 switch (AL)
1462 case 0x00:
1463 GetFileAttribute(context);
1464 break;
1465 case 0x01:
1466 ResetCflag;
1467 break;
1469 break;
1471 case 0x44: /* IOCTL */
1472 switch (AL)
1474 case 0x00:
1475 ioctlGetDeviceInfo(context);
1476 break;
1478 case 0x08: /* Check if drive is removable. */
1479 drive = BL ? (BL - 1) : DOS_GetDefaultDrive();
1480 if(!DOS_ValidDrive(drive))
1482 SetCflag;
1483 AX = 0x000F; /* Bad drive number */
1485 else
1487 if(drive > 1)
1488 EAX = (EAX & 0xFFFF0000) | 0x0001; /* not removable */
1489 else
1490 EAX = (EAX & 0xFFFF0000); /* removable */
1491 ResetCflag;
1493 break;
1495 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1496 drive = BL ? (BL - 1) : DOS_GetDefaultDrive();
1497 if(!DOS_ValidDrive(drive))
1499 SetCflag;
1500 AX = 0x000F; /* Bad drive number */
1502 else
1504 EDX = (EDX & 0xffff0000) | (1<<9) | (1<<12) | (1<<15);
1505 ResetCflag;
1507 break;
1509 case 0x0b: /* SET SHARING RETRY COUNT */
1510 if (!CX)
1512 EAX = (EAX & 0xffff0000) | 0x0001;
1513 SetCflag;
1514 break;
1516 sharing_pause = CX;
1517 if (!DX)
1518 sharing_retries = DX;
1519 ResetCflag;
1520 break;
1522 case 0x0d:
1523 ioctlGenericBlkDevReq(context);
1524 break;
1526 case 0x0F: /* Set logical drive mapping */
1527 /* FIXME: Not implemented at the moment, always returns error
1529 EAX = (EAX & 0xFFFF0000) | 0x0001; /* invalid function */
1530 SetCflag;
1531 break;
1533 default:
1534 IntBarf(0x21, context);
1535 break;
1537 break;
1539 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1540 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1541 AX = dup(BX);
1542 ResetCflag;
1543 break;
1545 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1546 GetCurrentDirectory(context);
1547 AX = 0x0100;
1548 /* intlist: many Microsoft products for Windows rely on this */
1549 break;
1551 case 0x48: /* ALLOCATE MEMORY */
1552 case 0x49: /* FREE MEMORY */
1553 case 0x4a: /* RESIZE MEMORY BLOCK */
1554 IntBarf(0x21, context);
1555 break;
1557 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1558 ExecProgram(context);
1559 break;
1561 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1562 TASK_KillCurrentTask( AL );
1563 break;
1565 case 0x4d: /* GET RETURN CODE */
1566 AL = NoError; /* normal exit */
1567 break;
1569 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1570 FindFirst(context);
1571 break;
1573 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1574 FindNext(context);
1575 break;
1577 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1578 ES = 0x0;
1579 BX = 0x0;
1580 IntBarf(0x21, context);
1581 break;
1583 case 0x56: /* "RENAME" - RENAME FILE */
1584 RenameFile(context);
1585 break;
1587 case 0x57: /* FILE DATE AND TIME */
1588 switch (AL)
1590 case 0x00:
1591 GetFileDateTime(context);
1592 break;
1593 case 0x01:
1594 SetFileDateTime(context);
1595 break;
1597 break;
1599 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1600 switch (AL)
1602 case 0x00:
1603 AL = 0x01L;
1604 break;
1605 case 0x02:
1606 EAX &= 0xff00L;
1607 break;
1608 case 0x01:
1609 case 0x03:
1610 break;
1612 ResetCflag;
1613 break;
1615 case 0x5a: /* CREATE TEMPORARY FILE */
1616 CreateTempFile(context);
1617 break;
1619 case 0x5b: /* CREATE NEW FILE */
1620 CreateNewFile(context);
1621 break;
1623 case 0x5d: /* NETWORK */
1624 case 0x5e:
1625 /* network software not installed */
1626 AL = NoNetwork;
1627 SetCflag;
1628 break;
1630 case 0x5f: /* NETWORK */
1631 switch (AL)
1633 case 0x07: /* ENABLE DRIVE */
1634 if (!DOS_EnableDrive(DL))
1636 Error(InvalidDrive, EC_MediaError , EL_Disk);
1637 AL = InvalidDrive;
1638 SetCflag;
1639 break;
1641 else
1643 ResetCflag;
1644 break;
1646 case 0x08: /* DISABLE DRIVE */
1647 if (!DOS_DisableDrive(DL))
1649 Error(InvalidDrive, EC_MediaError , EL_Disk);
1650 AL = InvalidDrive;
1651 SetCflag;
1652 break;
1654 else
1656 ResetCflag;
1657 break;
1659 default:
1660 /* network software not installed */
1661 AL = NoNetwork;
1662 SetCflag;
1663 break;
1665 break;
1667 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1668 strncpy(PTR_SEG_OFF_TO_LIN(ES,DI), PTR_SEG_OFF_TO_LIN(DS,SI), strlen(PTR_SEG_OFF_TO_LIN(DS,SI)) & 0x7f);
1669 ResetCflag;
1670 break;
1672 case 0x61: /* UNUSED */
1673 case 0x62: /* GET CURRENT PSP ADDRESS */
1674 case 0x63: /* UNUSED */
1675 case 0x64: /* OS/2 DOS BOX */
1676 case 0x65: /* GET EXTENDED COUNTRY INFORMATION */
1677 IntBarf(0x21, context);
1678 break;
1680 case 0x66: /* GLOBAL CODE PAGE TABLE */
1681 switch (AL) {
1682 case 0x01:
1683 BX = CodePage;
1684 DX = BX;
1685 ResetCflag;
1686 break;
1687 case 0x02:
1688 CodePage = BX;
1689 ResetCflag;
1690 break;
1692 break;
1694 case 0x67: /* SET HANDLE COUNT */
1695 ResetCflag;
1696 break;
1698 case 0x68: /* "FFLUSH" - COMMIT FILE */
1699 ResetCflag;
1700 break;
1702 case 0x69: /* DISK SERIAL NUMBER */
1703 switch (AL)
1705 case 0x00:
1706 GetDiskSerialNumber(context);
1707 break;
1708 case 0x01:
1709 SetDiskSerialNumber(context);
1710 break;
1712 break;
1714 case 0x6a: /* COMMIT FILE */
1715 ResetCflag;
1716 break;
1718 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1719 break;
1721 default:
1722 IntBarf(0x21, context);
1723 return 1;
1726 dprintf_int(stddeb,"ret21: AX %04x, BX %04x, CX %04x, DX %04x, "
1727 "SI %04x, DI %04x, DS %04x, ES %04x EFL %08lx\n",
1728 AX, BX, CX, DX, SI, DI, DS, ES, EFL);
1730 return 1;
1734 /***********************************************************************
1735 * DOS3Call (KERNEL.102)
1737 void DOS3Call( struct sigcontext_struct context )
1739 do_int21( &context );
1742 void INT21_Init(void)
1744 if ((DosHeapHandle = GlobalAlloc(GMEM_FIXED,sizeof(struct DosHeap))) == 0)
1746 fprintf( stderr, "INT21_Init: Out of memory\n");
1747 exit(1);
1749 heap = (struct DosHeap *) GlobalLock(DosHeapHandle);
1751 dpb = &heap->dpb;
1752 dpbsegptr = MAKELONG( (int)&heap->dpb - (int)heap, DosHeapHandle );
1753 heap->InDosFlag = 0;
1754 strcpy(heap->biosdate, "01/01/80");