Release 950430
[wine/multimedia.git] / miscemu / int21.c
blob44cb0cec2579bb65653bcfe4b3f0cdd5c4e2e51b
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 return;
297 ptr = PTR_SEG_OFF_TO_LIN (DS,DX);
298 if (BX == 0) {
299 *ptr = EOF;
300 Error (0,0,0);
301 AX = 1;
302 ResetCflag;
303 return;
304 } else {
305 size = read(BX, ptr, CX);
306 if (size == -1) {
307 errno_to_doserr();
308 AL = ExtendedError;
309 SetCflag;
310 return;
312 Error (0,0,0);
313 AX = size;
314 ResetCflag;
318 static void WriteFile(struct sigcontext_struct *context)
320 char *ptr;
321 int x,size;
323 ptr = PTR_SEG_OFF_TO_LIN (DS,DX);
325 if (BX == 0) {
326 Error (InvalidHandle, EC_Unknown, EL_Unknown);
327 EAX = InvalidHandle;
328 SetCflag;
329 return;
332 if (BX < 3) {
333 for (x = 0;x != CX;x++) {
334 dprintf_int(stddeb, "%c", *ptr++);
336 fflush(stddeb);
338 Error (0,0,0);
339 AL = CX;
340 ResetCflag;
341 } else {
342 size = write(BX, ptr , CX);
343 if (size == 0) {
344 Error (WriteFault, EC_Unknown, EL_Unknown);
345 AL = ExtendedError;
346 return;
349 if (size == -1) {
350 errno_to_doserr();
351 AL = ExtendedError;
352 SetCflag;
353 return;
355 Error (0,0,0);
356 AX = size;
357 ResetCflag;
361 static void SeekFile(struct sigcontext_struct *context)
363 off_t status, fileoffset;
365 switch (AL) {
366 case 1: fileoffset = SEEK_CUR;
367 break;
368 case 2: fileoffset = SEEK_END;
369 break;
370 default:
371 case 0: fileoffset = SEEK_SET;
372 break;
374 status = lseek(BX, (CX << 16) + DX, fileoffset);
375 if (status == -1) {
376 errno_to_doserr();
377 AL = ExtendedError; SetCflag;
378 return;
380 Error (0,0,0);
381 AX = (status & 0xffff);
382 DX = ((status >> 16) & 0xffff);
384 ResetCflag;
387 static void ioctlGetDeviceInfo(struct sigcontext_struct *context)
389 switch (BX) {
390 case 0:
391 case 1:
392 case 2:
393 DX = 0x80d0 + (1 << BX);
394 ResetCflag;
395 break;
397 default:
399 struct stat sbuf;
401 if (fstat(BX, &sbuf) < 0)
403 IntBarf(0x21, context);
404 DX = 0x50;
405 SetCflag;
406 return;
409 /* This isn't the right answer, but should be close enough. */
410 DX = 0x0943;
413 ResetCflag;
416 static void ioctlGenericBlkDevReq(struct sigcontext_struct *context)
418 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS, DX);
419 int drive;
421 if (BL == 0)
422 drive = DOS_GetDefaultDrive();
423 else
424 drive = BL - 1;
426 if (!DOS_ValidDrive(drive)) {
427 AX = 0x02;
428 SetCflag;
429 return;
432 if (CH != 0x08) {
433 IntBarf(0x21, context);
434 return;
436 switch (CL) {
437 case 0x60: /* get device parameters */
438 /* used by w4wgrp's winfile */
439 memset(dataptr, 0, 0x26);
440 dataptr[0] = 0x04;
441 dataptr[6] = 0; /* media type */
442 if (drive > 1)
444 dataptr[1] = 0x05; /* fixed disk */
445 setword(&dataptr[2], 0x01); /* non removable */
446 setword(&dataptr[4], 0x300); /* # of cylinders */
448 else
450 dataptr[1] = 0x07; /* block dev, floppy */
451 setword(&dataptr[2], 0x02); /* removable */
452 setword(&dataptr[4], 80); /* # of cylinders */
454 CreateBPB(drive, &dataptr[7]);
455 ResetCflag;
456 return;
457 default:
458 IntBarf(0x21, context);
462 static void GetSystemDate(struct sigcontext_struct *context)
464 struct tm *now;
465 time_t ltime;
467 ltime = time(NULL);
468 now = localtime(&ltime);
470 CX = now->tm_year + 1900;
471 DX = ((now->tm_mon + 1) << 8) | now->tm_mday;
472 AX = now->tm_wday;
475 static void GetSystemTime(struct sigcontext_struct *context)
477 struct tm *now;
478 struct timeval tv;
480 gettimeofday(&tv,NULL); /* Note use of gettimeofday(), instead of time() */
481 now = localtime(&tv.tv_sec);
483 CX = (now->tm_hour<<8) | now->tm_min;
484 DX = (now->tm_sec<<8) | tv.tv_usec/10000;
485 /* Note hundredths of seconds */
488 static void GetExtendedErrorInfo(struct sigcontext_struct *context)
490 AL = ExtendedError;
491 BX = (ErrorClass << 8) | Action;
492 CH = ErrorLocus << 8;
495 static void CreateFile(struct sigcontext_struct *context)
497 int handle;
499 if ((handle = open(DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX)),
500 O_CREAT | O_TRUNC | O_RDWR )) == -1) {
501 errno_to_doserr();
502 AL = ExtendedError;
503 SetCflag;
504 return;
506 Error (0,0,0);
507 EAX = (EAX & 0xffff0000) | handle;
508 ResetCflag;
511 void OpenExistingFile(struct sigcontext_struct *context)
513 int handle;
514 int mode;
515 int lock;
517 switch (AX & 0x0007)
519 case 0:
520 mode = O_RDONLY;
521 break;
523 case 1:
524 mode = O_WRONLY;
525 break;
527 default:
528 mode = O_RDWR;
529 break;
532 if ((handle = open(DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS,DX)),
533 mode)) == -1)
535 if( Options.allowReadOnly )
536 handle = open( DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS,DX)),
537 O_RDONLY );
538 if( handle == -1 )
540 errno_to_doserr();
541 AL = ExtendedError;
542 SetCflag;
543 return;
547 switch (AX & 0x0070)
549 case 0x00: /* compatability mode */
550 case 0x40: /* DENYNONE */
551 lock = -1;
552 break;
554 case 0x30: /* DENYREAD */
555 dprintf_int(stddeb,
556 "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
557 (char *)PTR_SEG_OFF_TO_LIN(DS,DX));
558 case 0x10: /* DENYALL */
559 lock = LOCK_EX;
560 break;
562 case 0x20: /* DENYWRITE */
563 lock = LOCK_SH;
564 break;
566 default:
567 lock = -1;
570 if (lock != -1)
573 int result,retries=sharing_retries;
575 result = flock(handle, lock | LOCK_NB);
576 if ( retries && (!result) )
578 int i;
579 for(i=0;i<32768*((int)sharing_pause);i++)
580 result++; /* stop the optimizer */
581 for(i=0;i<32768*((int)sharing_pause);i++)
582 result--;
585 while( (!result) && (!(retries--)) );
587 if(result)
589 errno_to_doserr();
590 EAX = (EAX & 0xffffff00) | ExtendedError;
591 close(handle);
592 SetCflag;
593 return;
598 Error (0,0,0);
599 EAX = (EAX & 0xffff0000) | handle;
600 ResetCflag;
603 static void CloseFile(struct sigcontext_struct *context)
605 if (close(BX) == -1) {
606 errno_to_doserr();
607 AL = ExtendedError;
608 SetCflag;
609 return;
611 Error (0,0,0);
612 AL = NoError;
613 ResetCflag;
616 static void RenameFile(struct sigcontext_struct *context)
618 char *newname, *oldname;
620 dprintf_int(stddeb,"int21: renaming %s to %s\n",
621 (char *)PTR_SEG_OFF_TO_LIN(DS,DX), (char *)PTR_SEG_OFF_TO_LIN(ES,DI) );
623 oldname = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX) );
624 newname = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(ES,DI) );
626 rename( oldname, newname);
627 ResetCflag;
631 static void MakeDir(struct sigcontext_struct *context)
633 char *dirname;
635 dprintf_int(stddeb,"int21: makedir %s\n", (char *)PTR_SEG_OFF_TO_LIN(DS,DX) );
637 if ((dirname = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX) ))== NULL) {
638 AL = CanNotMakeDir;
639 SetCflag;
640 return;
643 if (mkdir(dirname,0) == -1) {
644 AL = CanNotMakeDir;
645 SetCflag;
646 return;
648 ResetCflag;
651 static void ChangeDir(struct sigcontext_struct *context)
653 int drive;
654 char *dirname = PTR_SEG_OFF_TO_LIN(DS,DX);
655 drive = DOS_GetDefaultDrive();
656 dprintf_int(stddeb,"int21: changedir %s\n", dirname);
657 if (dirname != NULL && dirname[1] == ':') {
658 drive = toupper(dirname[0]) - 'A';
659 dirname += 2;
661 if (!DOS_ChangeDir(drive, dirname))
663 SetCflag;
664 AX=0x03;
668 static void RemoveDir(struct sigcontext_struct *context)
670 char *dirname;
672 dprintf_int(stddeb,"int21: removedir %s\n", (char *)PTR_SEG_OFF_TO_LIN(DS,DX) );
674 if ((dirname = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX) ))== NULL) {
675 AL = CanNotMakeDir;
676 SetCflag;
677 return;
681 if (strcmp(unixname,DosDrives[drive].CurrentDirectory)) {
682 AL = CanNotRemoveCwd;
683 SetCflag;
686 if (rmdir(dirname) == -1) {
687 AL = CanNotMakeDir;
688 SetCflag;
690 ResetCflag;
693 static void ExecProgram(struct sigcontext_struct *context)
695 execl("wine", DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX)) );
698 static void FindNext(struct sigcontext_struct *context)
700 struct dosdirent *dp;
701 struct tm *t;
702 BYTE *dta = GetCurrentDTA();
704 memcpy(&dp, dta+0x11, sizeof(dp));
706 do {
707 if ((dp = DOS_readdir(dp)) == NULL) {
708 Error(NoMoreFiles, EC_MediaError , EL_Disk);
709 AL = NoMoreFiles;
710 SetCflag;
711 return;
713 } /* while (*(dta + 0x0c) != dp->attribute);*/
714 while ( ( dp->search_attribute & dp->attribute) != dp->attribute);
716 *(dta + 0x15) = dp->attribute;
717 setword(&dta[0x0d], dp->entnum);
719 t = localtime(&(dp->filetime));
720 setword(&dta[0x16], (t->tm_hour << 11) + (t->tm_min << 5) +
721 (t->tm_sec / 2)); /* time */
722 setword(&dta[0x18], ((t->tm_year - 80) << 9) + (t->tm_mon << 5) +
723 (t->tm_mday)); /* date */
724 setdword(&dta[0x1a], dp->filesize);
725 strncpy(dta + 0x1e, dp->filename, 13);
727 AL = 0;
728 ResetCflag;
730 dprintf_int(stddeb, "int21: FindNext -- (%s) index=%d size=%ld\n", dp->filename, dp->entnum, dp->filesize);
731 return;
734 static void FindFirst(struct sigcontext_struct *context)
736 BYTE drive, *path = PTR_SEG_OFF_TO_LIN(DS, DX);
737 struct dosdirent *dp;
739 BYTE *dta = GetCurrentDTA();
741 dprintf_int(stddeb, "int21: FindFirst path = %s\n", path);
743 if ((*path)&&(path[1] == ':')) {
744 drive = (islower(*path) ? toupper(*path) : *path) - 'A';
746 if (!DOS_ValidDrive(drive)) {
747 Error(InvalidDrive, EC_MediaError , EL_Disk);
748 AL = InvalidDrive;
749 SetCflag;
750 return;
752 } else
753 drive = DOS_GetDefaultDrive();
755 *dta = drive;
756 memset(dta + 1 , '?', 11);
757 *(dta + 0x0c) = ECX & (FA_LABEL | FA_DIREC);
759 if (ECX & FA_LABEL) {
760 /* return volume label */
762 if (DOS_GetVolumeLabel(drive) != NULL)
763 strncpy(dta + 0x1e, DOS_GetVolumeLabel(drive), 8);
765 AL = 0;
766 ResetCflag;
767 return;
770 if ((dp = DOS_opendir(path)) == NULL) {
771 Error(PathNotFound, EC_MediaError, EL_Disk);
772 AL = FileNotFound;
773 SetCflag;
774 return;
777 dp->search_attribute = ECX & (FA_LABEL | FA_DIREC);
778 memcpy(dta + 0x11, &dp, sizeof(dp));
779 FindNext(context);
782 static void GetFileDateTime(struct sigcontext_struct *context)
784 struct stat filestat;
785 struct tm *now;
787 fstat( BX, &filestat );
788 now = localtime (&filestat.st_mtime);
790 CX = ((now->tm_hour * 0x2000) + (now->tm_min * 0x20) + now->tm_sec/2);
791 DX = ((now->tm_year * 0x200) + (now->tm_mon * 0x20) + now->tm_mday);
793 ResetCflag;
796 static void SetFileDateTime(struct sigcontext_struct *context)
798 char *filename;
799 struct utimbuf filetime;
801 /* FIXME: Argument isn't the name of the file in DS:DX,
802 but the file handle in BX */
803 filename = DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX) );
805 filetime.actime = 0L;
806 filetime.modtime = filetime.actime;
808 utime(filename, &filetime);
809 ResetCflag;
812 static void CreateTempFile(struct sigcontext_struct *context)
814 char temp[256];
815 int handle;
817 sprintf(temp,"%s\\win%d.tmp",TempDirectory,(int) getpid());
819 dprintf_int(stddeb,"CreateTempFile %s\n",temp);
821 handle = open(DOS_GetUnixFileName(temp), O_CREAT | O_TRUNC | O_RDWR);
823 if (handle == -1) {
824 AL = WriteProtected;
825 SetCflag;
826 return;
829 strcpy(PTR_SEG_OFF_TO_LIN(DS,DX), temp);
831 AX = handle;
832 ResetCflag;
835 static void CreateNewFile(struct sigcontext_struct *context)
837 int handle;
839 if ((handle = open(DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX) ), O_CREAT | O_EXCL | O_RDWR)) == -1) {
840 AL = WriteProtected;
841 SetCflag;
842 return;
845 AX = handle;
846 ResetCflag;
849 static void GetCurrentDirectory(struct sigcontext_struct *context)
851 int drive;
853 if (DL == 0)
854 drive = DOS_GetDefaultDrive();
855 else
856 drive = DL - 1;
858 if (!DOS_ValidDrive(drive)) {
859 AL = InvalidDrive;
860 SetCflag;
861 return;
864 strcpy(PTR_SEG_OFF_TO_LIN(DS,SI), DOS_GetCurrentDir(drive) );
865 ResetCflag;
868 static void GetDiskSerialNumber(struct sigcontext_struct *context)
870 int drive;
871 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS, DX);
872 DWORD serialnumber;
874 if (BL == 0)
875 drive = DOS_GetDefaultDrive();
876 else
877 drive = BL - 1;
879 if (!DOS_ValidDrive(drive)) {
880 AL =InvalidDrive;
881 SetCflag;
882 return;
885 DOS_GetSerialNumber(drive, &serialnumber);
887 setword(dataptr, 0);
888 setdword(&dataptr[2], serialnumber);
889 strncpy(dataptr + 6, DOS_GetVolumeLabel(drive), 8);
890 strncpy(dataptr + 0x11, "FAT16 ", 8);
892 AL = 0;
893 ResetCflag;
896 static void SetDiskSerialNumber(struct sigcontext_struct *context)
898 int drive;
899 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS, DX);
900 DWORD serialnumber;
902 if (BL == 0)
903 drive = DOS_GetDefaultDrive();
904 else
905 drive = BL - 1;
907 if (!DOS_ValidDrive(drive)) {
908 AL = InvalidDrive;
909 SetCflag;
910 return;
913 serialnumber = dataptr[1] + (dataptr[2] << 8) + (dataptr[3] << 16) +
914 (dataptr[4] << 24);
916 DOS_SetSerialNumber(drive, serialnumber);
917 AL = 1L;
918 ResetCflag;
921 static void DumpFCB(BYTE *fcb)
923 int x, y;
925 fcb -= 7;
927 for (y = 0; y !=2 ; y++) {
928 for (x = 0; x!=15;x++)
929 dprintf_int(stddeb, "%02x ", *fcb++);
930 dprintf_int(stddeb,"\n");
934 /* microsoft's programmers should be shot for using CP/M style int21
935 calls in Windows for Workgroup's winfile.exe */
937 static void FindFirstFCB(struct sigcontext_struct *context)
939 BYTE *fcb = PTR_SEG_OFF_TO_LIN(DS, DX);
940 struct fcb *standard_fcb;
941 struct fcb *output_fcb;
942 int drive;
943 char path[12];
945 BYTE *dta = GetCurrentDTA();
947 DumpFCB( fcb );
949 if ((*fcb) == 0xff)
951 standard_fcb = (struct fcb *)(fcb + 7);
952 output_fcb = (struct fcb *)(dta + 7);
953 *dta = 0xff;
955 else
957 standard_fcb = (struct fcb *)fcb;
958 output_fcb = (struct fcb *)dta;
961 if (standard_fcb->drive)
963 drive = standard_fcb->drive - 1;
964 if (!DOS_ValidDrive(drive))
966 Error (InvalidDrive, EC_MediaError, EL_Disk);
967 AL = 0xff;
968 return;
971 else
972 drive = DOS_GetDefaultDrive();
974 output_fcb->drive = drive;
976 if (*(fcb) == 0xff)
978 if (*(fcb+6) & FA_LABEL) /* return volume label */
980 *(dta+6) = FA_LABEL;
981 memset(&output_fcb->name, ' ', 11);
982 if (DOS_GetVolumeLabel(drive) != NULL)
984 strncpy(output_fcb->name, DOS_GetVolumeLabel(drive), 11);
985 AL = 0x00;
986 return;
991 strncpy(output_fcb->name, standard_fcb->name, 11);
992 if (*fcb == 0xff)
993 *(dta+6) = ( *(fcb+6) & (!FA_DIREC));
995 sprintf(path,"%c:*.*",drive+'A');
996 if ((output_fcb->directory = DOS_opendir(path))==NULL)
998 Error (PathNotFound, EC_MediaError, EL_Disk);
999 AL = 0xff;
1000 return;
1006 static void DeleteFileFCB(struct sigcontext_struct *context)
1008 BYTE *fcb = PTR_SEG_OFF_TO_LIN(DS, DX);
1009 int drive;
1010 struct dosdirent *dp;
1011 char temp[256], *ptr;
1013 DumpFCB( fcb );
1015 if (*fcb)
1016 drive = *fcb - 1;
1017 else
1018 drive = DOS_GetDefaultDrive();
1020 strcpy(temp, DOS_GetCurrentDir(drive));
1021 strcat(temp, "\\");
1022 strncat(temp, fcb + 1, 8);
1023 ChopOffWhiteSpace(temp);
1024 strncat(temp, fcb + 9, 3);
1025 ChopOffWhiteSpace(temp);
1027 if ((dp = DOS_opendir(temp)) == NULL) {
1028 Error(InvalidDrive, EC_MediaError , EL_Disk);
1029 AL = 0xffL;
1030 return;
1033 strcpy(temp, DOS_GetCurrentDir(drive) );
1034 strcat(temp, "\\");
1036 ptr = temp + strlen(temp);
1038 while (DOS_readdir(dp) != NULL)
1040 strcpy(ptr, dp->filename);
1041 dprintf_int(stddeb, "int21: delete file %s\n", temp);
1042 /* unlink(DOS_GetUnixFileName(temp)); */
1044 DOS_closedir(dp);
1045 AL = 0;
1048 static void RenameFileFCB(struct sigcontext_struct *context)
1050 BYTE *fcb = PTR_SEG_OFF_TO_LIN(DS, DX);
1051 int drive;
1052 struct dosdirent *dp;
1053 char temp[256], oldname[256], newname[256], *oldnameptr, *newnameptr;
1055 DumpFCB( fcb );
1057 if (*fcb)
1058 drive = *fcb - 1;
1059 else
1060 drive = DOS_GetDefaultDrive();
1062 strcpy(temp, DOS_GetCurrentDir(drive));
1063 strcat(temp, "\\");
1064 strncat(temp, fcb + 1, 8);
1065 ChopOffWhiteSpace(temp);
1066 strncat(temp, fcb + 9, 3);
1067 ChopOffWhiteSpace(temp);
1069 if ((dp = DOS_opendir(temp)) == NULL) {
1070 Error(InvalidDrive, EC_MediaError , EL_Disk);
1071 AL = 0xffL;
1072 return;
1075 strcpy(oldname, DOS_GetCurrentDir(drive) );
1076 strcat(oldname, "\\");
1077 oldnameptr = oldname + strlen(oldname);
1079 strcpy(newname, DOS_GetCurrentDir(drive) );
1080 strcat(newname, "\\");
1081 newnameptr = newname + strlen(newname);
1083 while (DOS_readdir(dp) != NULL)
1085 strcpy(oldnameptr, dp->filename);
1086 strcpy(newnameptr, fcb + 1);
1087 dprintf_int(stddeb, "int21: renamefile %s -> %s\n",
1088 oldname, newname);
1090 DOS_closedir(dp);
1091 AL = 0;
1096 static void fLock (struct sigcontext_struct * context)
1098 struct flock f;
1099 int result,retries=sharing_retries;
1101 f.l_start = MAKELONG(DX,CX);
1102 f.l_len = MAKELONG(DI,SI);
1103 f.l_whence = 0;
1104 f.l_pid = 0;
1106 switch ( AX & 0xff )
1108 case 0x00: /* LOCK */
1109 f.l_type = F_WRLCK;
1110 break;
1112 case 0x01: /* UNLOCK */
1113 f.l_type = F_UNLCK;
1114 break;
1116 default:
1117 EAX = (EAX & 0xffff0000) | 0x0001;
1118 SetCflag;
1119 return;
1123 result = fcntl(BX,F_SETLK,&f);
1124 if ( retries && (!result) )
1126 int i;
1127 for(i=0;i<32768*((int)sharing_pause);i++)
1128 result++; /* stop the optimizer */
1129 for(i=0;i<32768*((int)sharing_pause);i++)
1130 result--;
1133 while( (!result) && (!(retries--)) );
1135 if(result)
1137 errno_to_doserr();
1138 EAX = (EAX & 0xffffff00) | ExtendedError;
1139 SetCflag;
1140 return;
1143 Error (0,0,0);
1144 ResetCflag;
1148 static void GetFileAttribute (struct sigcontext_struct * context)
1150 char *filename = PTR_SEG_OFF_TO_LIN (DS,DX);
1151 struct stat s;
1152 int res,cx;
1154 res = stat(DOS_GetUnixFileName(filename), &s);
1155 if (res==-1)
1157 errno_to_doserr();
1158 EAX = (EAX & 0xffffff00) | ExtendedError;
1159 SetCflag;
1160 return;
1163 cx = 0;
1164 if (S_ISDIR(s.st_mode))
1165 cx|=0x10;
1166 if ((S_IWRITE & s.st_mode) != S_IWRITE)
1167 cx|=0x01;
1169 ECX = (ECX & 0xffff0000) | cx;
1170 ResetCflag;
1171 Error (0,0,0);
1176 /************************************************************************/
1178 int do_int21(struct sigcontext_struct * context)
1180 int drive;
1182 dprintf_int(stddeb,"int21: AX %04x, BX %04x, CX %04x, DX %04x, "
1183 "SI %04x, DI %04x, DS %04x, ES %04x\n",
1184 AX, BX, CX, DX, SI, DI, DS, ES);
1186 if (AH == 0x59)
1188 GetExtendedErrorInfo(context);
1189 return 1;
1191 else
1193 Error (0,0,0);
1194 switch(AH)
1196 case 0x00: /* TERMINATE PROGRAM */
1197 TASK_KillCurrentTask( 0 );
1198 break;
1200 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1201 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1202 case 0x03: /* READ CHARACTER FROM STDAUX */
1203 case 0x04: /* WRITE CHARACTER TO STDAUX */
1204 case 0x05: /* WRITE CHARACTER TO PRINTER */
1205 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1206 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
1207 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1208 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1209 case 0x0a: /* BUFFERED INPUT */
1210 case 0x0b: /* GET STDIN STATUS */
1211 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
1212 case 0x0f: /* OPEN FILE USING FCB */
1213 case 0x10: /* CLOSE FILE USING FCB */
1214 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1215 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1216 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1217 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1218 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1219 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1220 case 0x23: /* GET FILE SIZE FOR FCB */
1221 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1222 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1223 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1224 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1225 case 0x29: /* PARSE FILENAME INTO FCB */
1226 case 0x2e: /* SET VERIFY FLAG */
1227 IntBarf(0x21, context);
1228 break;
1230 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1231 case 0x1d:
1232 case 0x1e:
1233 case 0x20:
1234 case 0x2b: /* SET SYSTEM DATE */
1235 case 0x2d: /* SET SYSTEM TIME */
1236 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
1237 "SWITCHAR" - SET SWITCH CHARACTER
1238 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
1239 case 0x54: /* GET VERIFY FLAG */
1240 case 0x6b: /* NULL FUNCTION */
1241 IntBarf(0x21, context);
1242 EAX &= 0xff00;
1243 break;
1245 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1246 fLock(context);
1247 break;
1249 case 0x0d: /* DISK BUFFER FLUSH */
1250 ResetCflag; /* dos 6+ only */
1251 break;
1253 case 0x0e: /* SELECT DEFAULT DRIVE */
1254 if (!DOS_ValidDrive(DL)) {
1255 Error (InvalidDrive, EC_MediaError, EL_Disk);
1256 break;
1257 } else {
1258 DOS_SetDefaultDrive(DL);
1259 AX = MAX_DOS_DRIVES;
1260 Error(0,0,0);
1262 break;
1264 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1265 FindFirstFCB(context);
1266 break;
1268 case 0x13: /* DELETE FILE USING FCB */
1269 DeleteFileFCB(context);
1270 break;
1272 case 0x17: /* RENAME FILE USING FCB */
1273 RenameFileFCB(context);
1274 break;
1276 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1277 AL = DOS_GetDefaultDrive();
1278 Error (0,0,0);
1279 break;
1281 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1283 TDB *pTask = (TDB *)GlobalLock( GetCurrentTask() );
1284 pTask->dta = MAKELONG( DX, DS );
1286 break;
1288 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1289 GetDefDriveAllocInfo(context);
1290 break;
1292 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1293 GetDriveAllocInfo(context);
1294 break;
1296 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1297 GetDrivePB(context, DOS_GetDefaultDrive());
1298 break;
1300 case 0x25: /* SET INTERRUPT VECTOR */
1301 /* Ignore any attempt to set a segment vector */
1302 dprintf_int(stddeb,
1303 "int21: set interrupt vector %2x (%04x:%04x)\n",
1304 AL, DS, DX);
1305 break;
1307 case 0x2a: /* GET SYSTEM DATE */
1308 GetSystemDate(context);
1309 break;
1311 case 0x2c: /* GET SYSTEM TIME */
1312 GetSystemTime(context);
1313 break;
1315 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1317 TDB *pTask = (TDB *)GlobalLock( GetCurrentTask() );
1318 ES = SELECTOROF( pTask->dta );
1319 BX = OFFSETOF( pTask->dta );
1321 break;
1323 case 0x30: /* GET DOS VERSION */
1324 AX = DOSVERSION;
1325 BX = 0x0012; /* 0x123456 is Wine's serial # */
1326 CX = 0x3456;
1327 break;
1329 case 0x31: /* TERMINATE AND STAY RESIDENT */
1330 IntBarf(0x21, context);
1331 break;
1333 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1334 GetDrivePB(context, (DL == 0) ? (DOS_GetDefaultDrive()) : (DL-1));
1335 break;
1337 case 0x33: /* MULTIPLEXED */
1338 switch (AL) {
1339 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1340 if (!(AL))
1341 EDX &= 0xff00L;
1342 break;
1344 case 0x01: /* SET EXTENDED BREAK STATE */
1345 break;
1347 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1348 DL = 0;
1349 break;
1351 case 0x05: /* GET BOOT DRIVE */
1352 DL = 2;
1353 /* c: is Wine's bootdrive */
1354 break;
1356 case 0x06: /* GET TRUE VERSION NUMBER */
1357 EBX = DOSVERSION;
1358 EDX = 0x00;
1359 break;
1361 default:
1362 IntBarf(0x21, context);
1363 break;
1365 break;
1367 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1368 ES = DosHeapHandle;
1369 BX = (int)&heap->InDosFlag - (int)heap;
1370 break;
1372 case 0x35: /* GET INTERRUPT VECTOR */
1373 /* Return a NULL segment selector - this will bomb,
1374 if anyone ever tries to use it */
1375 dprintf_int(stddeb, "int21: get interrupt vector %2x\n",
1376 AX & 0xff);
1377 ES = 0;
1378 BX = 0;
1379 break;
1381 case 0x36: /* GET FREE DISK SPACE */
1382 GetFreeDiskSpace(context);
1383 break;
1385 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1386 AX = 0x02; /* no country support available */
1387 SetCflag;
1388 break;
1390 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1391 MakeDir(context);
1392 break;
1394 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1395 RemoveDir(context);
1396 break;
1398 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1399 ChangeDir(context);
1400 break;
1402 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1403 CreateFile(context);
1404 break;
1406 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1407 OpenExistingFile(context);
1408 break;
1410 case 0x3e: /* "CLOSE" - CLOSE FILE */
1411 CloseFile(context);
1412 break;
1414 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1415 ReadFile(context);
1416 break;
1418 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1419 WriteFile(context);
1420 break;
1422 case 0x41: /* "UNLINK" - DELETE FILE */
1423 if (unlink( DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS,DX)) ) == -1) {
1424 errno_to_doserr();
1425 AL = ExtendedError;
1426 SetCflag;
1427 break;
1429 Error(0,0,0);
1430 ResetCflag;
1431 break;
1433 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1434 SeekFile(context);
1435 break;
1437 case 0x43: /* FILE ATTRIBUTES */
1438 switch (AL)
1440 case 0x00:
1441 GetFileAttribute(context);
1442 break;
1443 case 0x01:
1444 ResetCflag;
1445 break;
1447 break;
1449 case 0x44: /* IOCTL */
1450 switch (AL)
1452 case 0x00:
1453 ioctlGetDeviceInfo(context);
1454 break;
1456 case 0x08: /* Check if drive is removable. */
1457 drive = BL ? (BL - 1) : DOS_GetDefaultDrive();
1458 if(!DOS_ValidDrive(drive))
1460 SetCflag;
1461 AX = 0x000F; /* Bad drive number */
1463 else
1465 if(drive > 1)
1466 EAX = (EAX & 0xFFFF0000) | 0x0001; /* not removable */
1467 else
1468 EAX = (EAX & 0xFFFF0000); /* removable */
1469 ResetCflag;
1471 break;
1473 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1474 drive = BL ? (BL - 1) : DOS_GetDefaultDrive();
1475 if(!DOS_ValidDrive(drive))
1477 SetCflag;
1478 AX = 0x000F; /* Bad drive number */
1480 else
1482 EDX = (EDX & 0xffff0000) | (1<<9) | (1<<12) | (1<<15);
1483 ResetCflag;
1485 break;
1487 case 0x0b: /* SET SHARING RETRY COUNT */
1488 if (!CX)
1490 EAX = (EAX & 0xffff0000) | 0x0001;
1491 SetCflag;
1492 break;
1494 sharing_pause = CX;
1495 if (!DX)
1496 sharing_retries = DX;
1497 ResetCflag;
1498 break;
1500 case 0x0d:
1501 ioctlGenericBlkDevReq(context);
1502 break;
1504 case 0x0F: /* Set logical drive mapping */
1505 /* FIXME: Not implemented at the moment, always returns error
1507 EAX = (EAX & 0xFFFF0000) | 0x0001; /* invalid function */
1508 SetCflag;
1509 break;
1511 default:
1512 IntBarf(0x21, context);
1513 break;
1515 break;
1517 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1518 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1519 AX = dup(BX);
1520 ResetCflag;
1521 break;
1523 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1524 GetCurrentDirectory(context);
1525 AX = 0x0100;
1526 /* intlist: many Microsoft products for Windows rely on this */
1527 break;
1529 case 0x48: /* ALLOCATE MEMORY */
1530 case 0x49: /* FREE MEMORY */
1531 case 0x4a: /* RESIZE MEMORY BLOCK */
1532 IntBarf(0x21, context);
1533 break;
1535 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1536 ExecProgram(context);
1537 break;
1539 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1540 TASK_KillCurrentTask( AL );
1541 break;
1543 case 0x4d: /* GET RETURN CODE */
1544 AL = NoError; /* normal exit */
1545 break;
1547 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1548 FindFirst(context);
1549 break;
1551 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1552 FindNext(context);
1553 break;
1555 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1556 ES = 0x0;
1557 BX = 0x0;
1558 IntBarf(0x21, context);
1559 break;
1561 case 0x56: /* "RENAME" - RENAME FILE */
1562 RenameFile(context);
1563 break;
1565 case 0x57: /* FILE DATE AND TIME */
1566 switch (AL)
1568 case 0x00:
1569 GetFileDateTime(context);
1570 break;
1571 case 0x01:
1572 SetFileDateTime(context);
1573 break;
1575 break;
1577 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1578 switch (AL)
1580 case 0x00:
1581 AL = 0x01L;
1582 break;
1583 case 0x02:
1584 EAX &= 0xff00L;
1585 break;
1586 case 0x01:
1587 case 0x03:
1588 break;
1590 ResetCflag;
1591 break;
1593 case 0x5a: /* CREATE TEMPORARY FILE */
1594 CreateTempFile(context);
1595 break;
1597 case 0x5b: /* CREATE NEW FILE */
1598 CreateNewFile(context);
1599 break;
1601 case 0x5d: /* NETWORK */
1602 case 0x5e:
1603 /* network software not installed */
1604 AL = NoNetwork;
1605 SetCflag;
1606 break;
1608 case 0x5f: /* NETWORK */
1609 switch (AL)
1611 case 0x07: /* ENABLE DRIVE */
1612 if (!DOS_EnableDrive(DL))
1614 Error(InvalidDrive, EC_MediaError , EL_Disk);
1615 AL = InvalidDrive;
1616 SetCflag;
1617 break;
1619 else
1621 ResetCflag;
1622 break;
1624 case 0x08: /* DISABLE DRIVE */
1625 if (!DOS_DisableDrive(DL))
1627 Error(InvalidDrive, EC_MediaError , EL_Disk);
1628 AL = InvalidDrive;
1629 SetCflag;
1630 break;
1632 else
1634 ResetCflag;
1635 break;
1637 default:
1638 /* network software not installed */
1639 AL = NoNetwork;
1640 SetCflag;
1641 break;
1643 break;
1645 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1646 strncpy(PTR_SEG_OFF_TO_LIN(ES,DI), PTR_SEG_OFF_TO_LIN(DS,SI), strlen(PTR_SEG_OFF_TO_LIN(DS,SI)) & 0x7f);
1647 ResetCflag;
1648 break;
1650 case 0x61: /* UNUSED */
1651 case 0x62: /* GET CURRENT PSP ADDRESS */
1652 case 0x63: /* UNUSED */
1653 case 0x64: /* OS/2 DOS BOX */
1654 case 0x65: /* GET EXTENDED COUNTRY INFORMATION */
1655 IntBarf(0x21, context);
1656 break;
1658 case 0x66: /* GLOBAL CODE PAGE TABLE */
1659 switch (AL) {
1660 case 0x01:
1661 BX = CodePage;
1662 DX = BX;
1663 ResetCflag;
1664 break;
1665 case 0x02:
1666 CodePage = BX;
1667 ResetCflag;
1668 break;
1670 break;
1672 case 0x67: /* SET HANDLE COUNT */
1673 ResetCflag;
1674 break;
1676 case 0x68: /* "FFLUSH" - COMMIT FILE */
1677 ResetCflag;
1678 break;
1680 case 0x69: /* DISK SERIAL NUMBER */
1681 switch (AL)
1683 case 0x00:
1684 GetDiskSerialNumber(context);
1685 break;
1686 case 0x01:
1687 SetDiskSerialNumber(context);
1688 break;
1690 break;
1692 case 0x6a: /* COMMIT FILE */
1693 ResetCflag;
1694 break;
1696 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1697 break;
1699 default:
1700 IntBarf(0x21, context);
1701 return 1;
1704 return 1;
1707 /**********************************************************************
1708 * DOS3Call
1710 void DOS3Call( struct sigcontext_struct context )
1712 do_int21( &context );
1715 void INT21_Init(void)
1717 if ((DosHeapHandle = GlobalAlloc(GMEM_FIXED,sizeof(struct DosHeap))) == 0)
1719 fprintf( stderr, "INT21_Init: Out of memory\n");
1720 exit(1);
1722 heap = (struct DosHeap *) GlobalLock(DosHeapHandle);
1724 dpb = &heap->dpb;
1725 dpbsegptr = MAKELONG( (int)&heap->dpb - (int)heap, DosHeapHandle );
1726 heap->InDosFlag = 0;
1727 strcpy(heap->biosdate, "01/01/80");