Recovery of release 990110 after disk crash.
[wine/multimedia.git] / msdos / int21.c
blob8315d74dfb9935156faf9c5c73e93d7610651547
1 /*
2 * DOS interrupt 21h handler
3 */
5 #include <time.h>
6 #include <fcntl.h>
7 #include <errno.h>
8 #include <stdlib.h>
9 #ifdef HAVE_SYS_FILE_H
10 # include <sys/file.h>
11 #endif
12 #include <string.h>
13 #include <sys/stat.h>
14 #include <sys/time.h>
15 #include <sys/types.h>
16 #include <unistd.h>
17 #include <utime.h>
18 #include <ctype.h>
19 #include "windows.h"
20 #include "drive.h"
21 #include "file.h"
22 #include "heap.h"
23 #include "msdos.h"
24 #include "ldt.h"
25 #include "task.h"
26 #include "options.h"
27 #include "miscemu.h"
28 #include "debug.h"
29 #include "console.h"
30 #if defined(__svr4__) || defined(_SCO_DS)
31 /* SVR4 DOESNT do locking the same way must implement properly */
32 #define LOCK_EX 0
33 #define LOCK_SH 1
34 #define LOCK_NB 8
35 #endif
38 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
40 /* Define the drive parameter block, as used by int21/1F
41 * and int21/32. This table can be accessed through the
42 * global 'dpb' pointer, which points into the local dos
43 * heap.
45 struct DPB
47 BYTE drive_num; /* 0=A, etc. */
48 BYTE unit_num; /* Drive's unit number (?) */
49 WORD sector_size; /* Sector size in bytes */
50 BYTE high_sector; /* Highest sector in a cluster */
51 BYTE shift; /* Shift count (?) */
52 WORD reserved; /* Number of reserved sectors at start */
53 BYTE num_FAT; /* Number of FATs */
54 WORD dir_entries; /* Number of root dir entries */
55 WORD first_data; /* First data sector */
56 WORD high_cluster; /* Highest cluster number */
57 WORD sectors_in_FAT; /* Number of sectors per FAT */
58 WORD start_dir; /* Starting sector of first dir */
59 DWORD driver_head; /* Address of device driver header (?) */
60 BYTE media_ID; /* Media ID */
61 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
62 DWORD next; /* Pointer to next DPB in list */
63 WORD free_search; /* Free cluster search start */
64 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
67 WORD CodePage = 437;
68 DWORD dpbsegptr;
70 struct DosHeap {
71 BYTE InDosFlag;
72 BYTE mediaID;
73 BYTE biosdate[8];
74 struct DPB dpb;
75 BYTE DummyDBCSLeadTable[6];
77 static struct DosHeap *heap;
78 static WORD DosHeapHandle;
80 WORD sharing_retries = 3; /* number of retries at sharing violation */
81 WORD sharing_pause = 1; /* pause between retries */
83 extern char TempDirectory[];
85 static BOOL32 INT21_CreateHeap(void)
87 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
89 WARN(int21, "Out of memory\n");
90 return FALSE;
92 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
93 dpbsegptr = PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
94 heap->InDosFlag = 0;
95 strcpy(heap->biosdate, "01/01/80");
96 memset(heap->DummyDBCSLeadTable, 0, 6);
97 return TRUE;
100 static BYTE *GetCurrentDTA( CONTEXT *context )
102 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
104 /* FIXME: This assumes DTA was set correctly! */
105 return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
106 (DWORD)OFFSETOF(pTask->dta) );
110 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
111 /* limited == TRUE is used with INT 0x21/0x440d */
113 if (drive > 1) {
114 setword(data, 512);
115 data[2] = 2;
116 setword(&data[3], 0);
117 data[5] = 2;
118 setword(&data[6], 240);
119 setword(&data[8], 64000);
120 data[0x0a] = 0xf8;
121 setword(&data[0x0b], 40);
122 setword(&data[0x0d], 56);
123 setword(&data[0x0f], 2);
124 setword(&data[0x11], 0);
125 if (!limited) {
126 setword(&data[0x1f], 800);
127 data[0x21] = 5;
128 setword(&data[0x22], 1);
130 } else { /* 1.44mb */
131 setword(data, 512);
132 data[2] = 2;
133 setword(&data[3], 0);
134 data[5] = 2;
135 setword(&data[6], 240);
136 setword(&data[8], 2880);
137 data[0x0a] = 0xf8;
138 setword(&data[0x0b], 6);
139 setword(&data[0x0d], 18);
140 setword(&data[0x0f], 2);
141 setword(&data[0x11], 0);
142 if (!limited) {
143 setword(&data[0x1f], 80);
144 data[0x21] = 7;
145 setword(&data[0x22], 2);
150 static int INT21_GetFreeDiskSpace( CONTEXT *context )
152 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
153 char root[] = "A:\\";
155 *root += DOS_GET_DRIVE( DL_reg(context) );
156 if (!GetDiskFreeSpace32A( root, &cluster_sectors, &sector_bytes,
157 &free_clusters, &total_clusters )) return 0;
158 AX_reg(context) = cluster_sectors;
159 BX_reg(context) = free_clusters;
160 CX_reg(context) = sector_bytes;
161 DX_reg(context) = total_clusters;
162 return 1;
165 static int INT21_GetDriveAllocInfo( CONTEXT *context )
167 if (!INT21_GetFreeDiskSpace( context )) return 0;
168 if (!heap && !INT21_CreateHeap()) return 0;
169 heap->mediaID = 0xf0;
170 DS_reg(context) = DosHeapHandle;
171 BX_reg(context) = (int)&heap->mediaID - (int)heap;
172 return 1;
175 static void GetDrivePB( CONTEXT *context, int drive )
177 if(!DRIVE_IsValid(drive))
179 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
180 AX_reg(context) = 0x00ff;
182 else if (heap || INT21_CreateHeap())
184 FIXME(int21, "GetDrivePB not fully implemented.\n");
186 /* FIXME: I have no idea what a lot of this information should
187 * say or whether it even really matters since we're not allowing
188 * direct block access. However, some programs seem to depend on
189 * getting at least _something_ back from here. The 'next' pointer
190 * does worry me, though. Should we have a complete table of
191 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
193 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
194 heap->dpb.sector_size = 512;
195 heap->dpb.high_sector = 1;
196 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
197 heap->dpb.reserved = 0;
198 heap->dpb.num_FAT = 1;
199 heap->dpb.dir_entries = 2;
200 heap->dpb.first_data = 2;
201 heap->dpb.high_cluster = 64000;
202 heap->dpb.sectors_in_FAT = 1;
203 heap->dpb.start_dir = 1;
204 heap->dpb.driver_head = 0;
205 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
206 heap->dpb.access_flag = 0;
207 heap->dpb.next = 0;
208 heap->dpb.free_search = 0;
209 heap->dpb.free_clusters = 0xFFFF; /* unknown */
211 AL_reg(context) = 0x00;
212 DS_reg(context) = SELECTOROF(dpbsegptr);
213 BX_reg(context) = OFFSETOF(dpbsegptr);
218 static void ioctlGetDeviceInfo( CONTEXT *context )
220 int curr_drive;
221 FILE_OBJECT *file;
223 TRACE(int21, "(%d)\n", BX_reg(context));
225 RESET_CFLAG(context);
227 /* DOS device ? */
228 if ((file = FILE_GetFile( HFILE16_TO_HFILE32(BX_reg(context)), 0, NULL )))
230 const DOS_DEVICE *dev = DOSFS_GetDevice( file->unix_name );
231 FILE_ReleaseFile( file );
232 if (dev)
234 DX_reg(context) = dev->flags;
235 return;
239 /* it seems to be a file */
240 curr_drive = DRIVE_GetCurrentDrive();
241 DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0);
242 /* no floppy */
243 /* bits 0-5 are current drive
244 * bit 6 - file has NOT been written..FIXME: correct?
245 * bit 8 - generate int24 if no diskspace on write/ read past end of file
246 * bit 11 - media not removable
247 * bit 14 - don't set file date/time on closing
248 * bit 15 - file is remote
252 static BOOL32 ioctlGenericBlkDevReq( CONTEXT *context )
254 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
255 int drive = DOS_GET_DRIVE( BL_reg(context) );
257 if (!DRIVE_IsValid(drive))
259 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
260 return TRUE;
263 if (CH_reg(context) != 0x08)
265 INT_BARF( context, 0x21 );
266 return FALSE;
269 switch (CL_reg(context))
271 case 0x4a: /* lock logical volume */
272 TRACE(int21,"lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
273 break;
275 case 0x60: /* get device parameters */
276 /* used by w4wgrp's winfile */
277 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
278 dataptr[0] = 0x04;
279 dataptr[6] = 0; /* media type */
280 if (drive > 1)
282 dataptr[1] = 0x05; /* fixed disk */
283 setword(&dataptr[2], 0x01); /* non removable */
284 setword(&dataptr[4], 0x300); /* # of cylinders */
286 else
288 dataptr[1] = 0x07; /* block dev, floppy */
289 setword(&dataptr[2], 0x02); /* removable */
290 setword(&dataptr[4], 80); /* # of cylinders */
292 CreateBPB(drive, &dataptr[7], TRUE);
293 RESET_CFLAG(context);
294 break;
296 case 0x41: /* write logical device track */
297 case 0x61: /* read logical device track */
299 BYTE drive = BL_reg(context) ?
300 BL_reg(context) : DRIVE_GetCurrentDrive();
301 WORD head = *(WORD *)dataptr+1;
302 WORD cyl = *(WORD *)dataptr+3;
303 WORD sect = *(WORD *)dataptr+5;
304 WORD nrsect = *(WORD *)dataptr+7;
305 BYTE *data = (BYTE **)dataptr+9;
306 int (*raw_func)(BYTE, DWORD, DWORD, BYTE *, BOOL32);
308 raw_func = (CL_reg(context) == 0x41) ?
309 DRIVE_RawWrite : DRIVE_RawRead;
311 if (raw_func(drive, head*cyl*sect, nrsect, data, FALSE))
312 RESET_CFLAG(context);
313 else
315 AX_reg(context) = 0x1e; /* read fault */
316 SET_CFLAG(context);
319 break;
320 case 0x66:/* get disk serial number */
322 char label[12],fsname[9],path[4];
323 DWORD serial;
325 strcpy(path,"x:\\");path[0]=drive+'A';
326 GetVolumeInformation32A(
327 path,label,12,&serial,NULL,NULL,fsname,9
329 *(WORD*)dataptr = 0;
330 memcpy(dataptr+2,&serial,4);
331 memcpy(dataptr+6,label ,11);
332 memcpy(dataptr+17,fsname,8);
334 break;
336 case 0x6a:
337 TRACE(int21,"logical volume %d unlocked.\n",drive);
338 break;
340 case 0x6f:
341 memset(dataptr+1, '\0', dataptr[0]-1);
342 dataptr[1] = dataptr[0];
343 dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
344 dataptr[3] = 0xFF; /* no physical drive */
345 break;
347 default:
348 INT_BARF( context, 0x21 );
350 return FALSE;
353 static void INT21_ParseFileNameIntoFCB( CONTEXT *context )
355 char *filename =
356 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context) );
357 char *fcb =
358 CTX_SEG_OFF_TO_LIN(context, ES_reg(context), EDI_reg(context) );
359 char *buffer, *s, *d;
361 AL_reg(context) = 0xff; /* failed */
363 TRACE(int21, "filename: '%s'\n", filename);
365 buffer = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + 1);
367 s = filename;
368 d = buffer;
369 while (*s)
371 if ((*s != ' ') && (*s != '\r') && (*s != '\n'))
372 *d++ = *s++;
373 else
374 break;
377 *d = '\0';
378 DOSFS_ToDosFCBFormat(buffer, fcb + 1);
379 *fcb = 0;
380 TRACE(int21, "FCB: '%s'\n", ((CHAR *)fcb + 1));
382 HeapFree( GetProcessHeap(), 0, buffer);
384 AL_reg(context) =
385 ((strchr(filename, '*')) || (strchr(filename, '$'))) != 0;
387 /* point DS:SI to first unparsed character */
388 SI_reg(context) += (int)s - (int)filename;
391 static void INT21_GetSystemDate( CONTEXT *context )
393 SYSTEMTIME systime;
394 GetLocalTime( &systime );
395 CX_reg(context) = systime.wYear;
396 DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
397 AX_reg(context) = systime.wDayOfWeek;
400 static void INT21_GetSystemTime( CONTEXT *context )
402 SYSTEMTIME systime;
403 GetLocalTime( &systime );
404 CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
405 DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
408 /* Many calls translate a drive argument like this:
409 drive number (00h = default, 01h = A:, etc)
411 static char drivestring[]="default";
413 char *INT21_DriveName(int drive)
416 if(drive >0)
418 drivestring[0]= (unsigned char)drive + '@';
419 drivestring[1]=':';
420 drivestring[2]=0;
422 return drivestring;
424 static BOOL32 INT21_CreateFile( CONTEXT *context )
426 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
427 EDX_reg(context) ), CX_reg(context) );
428 return (AX_reg(context) == (WORD)HFILE_ERROR16);
432 static void OpenExistingFile( CONTEXT *context )
434 AX_reg(context) = _lopen16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
435 AL_reg(context) );
436 if (AX_reg(context) == (WORD)HFILE_ERROR16)
438 AX_reg(context) = DOS_ExtendedError;
439 SET_CFLAG(context);
441 #if 0
443 int handle;
444 int mode;
445 int lock;
447 switch (AX_reg(context) & 0x0070)
449 case 0x00: /* compatability mode */
450 case 0x40: /* DENYNONE */
451 lock = -1;
452 break;
454 case 0x30: /* DENYREAD */
455 TRACE(int21, "(%s): DENYREAD changed to DENYALL\n",
456 (char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
457 case 0x10: /* DENYALL */
458 lock = LOCK_EX;
459 break;
461 case 0x20: /* DENYWRITE */
462 lock = LOCK_SH;
463 break;
465 default:
466 lock = -1;
469 if (lock != -1)
472 int result,retries=sharing_retries;
474 #if defined(__svr4__) || defined(_SCO_DS)
475 ERR(int21, "Should call flock and needs porting to lockf\n");
476 result = 0;
477 retries = 0;
478 #else
479 result = flock(handle, lock | LOCK_NB);
480 #endif
481 if ( retries && (!result) )
483 int i;
484 for(i=0;i<32768*((int)sharing_pause);i++)
485 result++; /* stop the optimizer */
486 for(i=0;i<32768*((int)sharing_pause);i++)
487 result--;
490 while( (!result) && (!(retries--)) );
492 if(result)
494 errno_to_doserr();
495 AX_reg(context) = DOS_ExtendedError;
496 close(handle);
497 SET_CFLAG(context);
498 return;
503 Error (0,0,0);
504 AX_reg(context) = handle;
505 RESET_CFLAG(context);
507 #endif
510 static void CloseFile( CONTEXT *context )
512 if ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0)
514 AX_reg(context) = DOS_ExtendedError;
515 SET_CFLAG(context);
519 static BOOL32 INT21_ExtendedOpenCreateFile(CONTEXT *context )
521 BOOL32 bExtendedError = FALSE;
522 BYTE action = DL_reg(context);
524 /* Shuffle arguments to call OpenExistingFile */
525 AL_reg(context) = BL_reg(context);
526 DX_reg(context) = SI_reg(context);
527 /* BX,CX and DX should be preserved */
528 OpenExistingFile(context);
530 if ((EFL_reg(context) & 0x0001) == 0) /* File exists */
532 UINT16 uReturnCX = 0;
534 /* Now decide what do do */
536 if ((action & 0x07) == 0)
538 BX_reg(context) = AX_reg(context);
539 CloseFile(context);
540 AX_reg(context) = 0x0050; /*File exists*/
541 SET_CFLAG(context);
542 WARN(int21, "extended open/create: failed because file exists \n");
544 else if ((action & 0x07) == 2)
546 /* Truncate it, but first check if opened for write */
547 if ((BL_reg(context) & 0x0007)== 0)
549 BX_reg(context) = AX_reg(context);
550 CloseFile(context);
551 WARN(int21, "extended open/create: failed, trunc on ro file\n");
552 AX_reg(context) = 0x000C; /*Access code invalid*/
553 SET_CFLAG(context);
555 else
557 /* Shuffle arguments to call CloseFile while
558 * preserving BX and DX */
560 TRACE(int21, "extended open/create: Closing before truncate\n");
561 BX_reg(context) = AX_reg(context);
562 CloseFile(context);
563 if (EFL_reg(context) & 0x0001)
565 WARN(int21, "extended open/create: close before trunc failed\n");
566 AX_reg(context) = 0x0019; /*Seek Error*/
567 CX_reg(context) = 0;
568 SET_CFLAG(context);
570 /* Shuffle arguments to call CreateFile */
572 TRACE(int21, "extended open/create: Truncating\n");
573 AL_reg(context) = BL_reg(context);
574 /* CX is still the same */
575 DX_reg(context) = SI_reg(context);
576 bExtendedError = INT21_CreateFile(context);
578 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
580 WARN(int21, "extended open/create: trunc failed\n");
581 return bExtendedError;
583 uReturnCX = 0x3;
586 else uReturnCX = 0x1;
588 CX_reg(context) = uReturnCX;
590 else /* file does not exist */
592 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
593 if ((action & 0xF0)== 0)
595 CX_reg(context) = 0;
596 SET_CFLAG(context);
597 WARN(int21, "extended open/create: failed, file dosen't exist\n");
599 else
601 /* Shuffle arguments to call CreateFile */
602 TRACE(int21, "extended open/create: Creating\n");
603 AL_reg(context) = BL_reg(context);
604 /* CX should still be the same */
605 DX_reg(context) = SI_reg(context);
606 bExtendedError = INT21_CreateFile(context);
607 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
609 WARN(int21, "extended open/create: create failed\n");
610 return bExtendedError;
612 CX_reg(context) = 2;
616 return bExtendedError;
620 static BOOL32 INT21_ChangeDir( CONTEXT *context )
622 int drive;
623 char *dirname = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));
625 TRACE(int21,"changedir %s\n", dirname);
626 if (dirname[0] && (dirname[1] == ':'))
628 drive = toupper(dirname[0]) - 'A';
629 dirname += 2;
631 else drive = DRIVE_GetCurrentDrive();
632 return DRIVE_Chdir( drive, dirname );
636 static int INT21_FindFirst( CONTEXT *context )
638 char *p;
639 const char *path;
640 DOS_FULL_NAME full_name;
641 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
643 path = (const char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
644 dta->unixPath = NULL;
645 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
647 AX_reg(context) = DOS_ExtendedError;
648 SET_CFLAG(context);
649 return 0;
651 dta->unixPath = HEAP_strdupA( GetProcessHeap(), 0, full_name.long_name );
652 p = strrchr( dta->unixPath, '/' );
653 *p = '\0';
655 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
656 * (doesn't matter as it is set below anyway)
658 if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
660 HeapFree( GetProcessHeap(), 0, dta->unixPath );
661 dta->unixPath = NULL;
662 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
663 AX_reg(context) = ER_FileNotFound;
664 SET_CFLAG(context);
665 return 0;
667 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
668 : DRIVE_GetCurrentDrive();
669 dta->count = 0;
670 dta->search_attr = CL_reg(context);
671 return 1;
675 static int INT21_FindNext( CONTEXT *context )
677 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
678 WIN32_FIND_DATA32A entry;
679 int count;
681 if (!dta->unixPath) return 0;
682 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
683 dta->search_attr, dta->count, &entry )))
685 HeapFree( GetProcessHeap(), 0, dta->unixPath );
686 dta->unixPath = NULL;
687 return 0;
689 if ((int)dta->count + count > 0xffff)
691 WARN(int21, "Too many directory entries in %s\n", dta->unixPath );
692 HeapFree( GetProcessHeap(), 0, dta->unixPath );
693 dta->unixPath = NULL;
694 return 0;
696 dta->count += count;
697 dta->fileattr = entry.dwFileAttributes;
698 dta->filesize = entry.nFileSizeLow;
699 FileTimeToDosDateTime( &entry.ftLastWriteTime,
700 &dta->filedate, &dta->filetime );
701 strcpy( dta->filename, entry.cAlternateFileName );
702 if (!memchr(dta->mask,'?',11)) {
703 /* wildcardless search, release resources in case no findnext will
704 * be issued, and as a workaround in case file creation messes up
705 * findnext, as sometimes happens with pkunzip */
706 HeapFree( GetProcessHeap(), 0, dta->unixPath );
707 dta->unixPath = NULL;
709 return 1;
713 static BOOL32 INT21_CreateTempFile( CONTEXT *context )
715 static int counter = 0;
716 char *name = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context) );
717 char *p = name + strlen(name);
719 /* despite what Ralf Brown says, some programs seem to call without
720 * ending backslash (DOS accepts that, so we accept it too) */
721 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
723 for (;;)
725 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
726 counter = (counter + 1) % 1000;
728 if ((AX_reg(context) = HFILE32_TO_HFILE16(_lcreat_uniq( name, 0 ))) != (WORD)HFILE_ERROR16)
730 TRACE(int21, "created %s\n", name );
731 return TRUE;
733 if (DOS_ExtendedError != ER_FileExists) return FALSE;
738 static BOOL32 INT21_GetCurrentDirectory( CONTEXT *context )
740 int drive = DOS_GET_DRIVE( DL_reg(context) );
741 char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context) );
743 if (!DRIVE_IsValid(drive))
745 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
746 return FALSE;
748 lstrcpyn32A( ptr, DRIVE_GetDosCwd(drive), 64 );
749 AX_reg(context) = 0x0100; /* success return code */
750 return TRUE;
754 static void INT21_GetDBCSLeadTable( CONTEXT *context )
756 if (heap || INT21_CreateHeap())
757 { /* return an empty table just as DOS 4.0+ does */
758 DS_reg(context) = DosHeapHandle;
759 SI_reg(context) = (int)&heap->DummyDBCSLeadTable - (int)heap;
761 else
763 AX_reg(context) = 0x1; /* error */
764 SET_CFLAG(context);
769 static int INT21_GetDiskSerialNumber( CONTEXT *context )
771 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
772 int drive = DOS_GET_DRIVE( BL_reg(context) );
774 if (!DRIVE_IsValid(drive))
776 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
777 return 0;
780 *(WORD *)dataptr = 0;
781 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
782 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
783 strncpy(dataptr + 0x11, "FAT16 ", 8);
784 return 1;
788 static int INT21_SetDiskSerialNumber( CONTEXT *context )
790 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
791 int drive = DOS_GET_DRIVE( BL_reg(context) );
793 if (!DRIVE_IsValid(drive))
795 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
796 return 0;
799 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
800 return 1;
804 /* microsoft's programmers should be shot for using CP/M style int21
805 calls in Windows for Workgroup's winfile.exe */
807 static int INT21_FindFirstFCB( CONTEXT *context )
809 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
810 FINDFILE_FCB *pFCB;
811 LPCSTR root, cwd;
812 int drive;
814 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
815 else pFCB = (FINDFILE_FCB *)fcb;
816 drive = DOS_GET_DRIVE( pFCB->drive );
817 if (!DRIVE_IsValid( drive )) return 0;
818 root = DRIVE_GetRoot( drive );
819 cwd = DRIVE_GetUnixCwd( drive );
820 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
821 strlen(root)+strlen(cwd)+2 );
822 if (!pFCB->unixPath) return 0;
823 strcpy( pFCB->unixPath, root );
824 strcat( pFCB->unixPath, "/" );
825 strcat( pFCB->unixPath, cwd );
826 pFCB->count = 0;
827 return 1;
831 static int INT21_FindNextFCB( CONTEXT *context )
833 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
834 FINDFILE_FCB *pFCB;
835 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA(context);
836 WIN32_FIND_DATA32A entry;
837 BYTE attr;
838 int count;
840 if (*fcb == 0xff) /* extended FCB ? */
842 attr = fcb[6];
843 pFCB = (FINDFILE_FCB *)(fcb + 7);
845 else
847 attr = 0;
848 pFCB = (FINDFILE_FCB *)fcb;
851 if (!pFCB->unixPath) return 0;
852 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
853 DOS_GET_DRIVE( pFCB->drive ), attr,
854 pFCB->count, &entry )))
856 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
857 pFCB->unixPath = NULL;
858 return 0;
860 pFCB->count += count;
862 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
863 *(BYTE *)pResult = 0xff;
864 (BYTE *)pResult +=6; /* leave reserved field behind */
865 *(BYTE *)pResult = entry.dwFileAttributes;
866 ((BYTE *)pResult)++;
868 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
869 ((BYTE *)pResult)++;
870 pResult->fileattr = entry.dwFileAttributes;
871 pResult->cluster = 0; /* what else? */
872 pResult->filesize = entry.nFileSizeLow;
873 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
874 FileTimeToDosDateTime( &entry.ftLastWriteTime,
875 &pResult->filedate, &pResult->filetime );
877 /* Convert file name to FCB format */
879 memset( pResult->filename, ' ', sizeof(pResult->filename) );
880 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
881 else if (!strcmp( entry.cAlternateFileName, ".." ))
882 pResult->filename[0] = pResult->filename[1] = '.';
883 else
885 char *p = strrchr( entry.cAlternateFileName, '.' );
886 if (p && p[1] && (p != entry.cAlternateFileName))
888 memcpy( pResult->filename, entry.cAlternateFileName,
889 MIN( (p - entry.cAlternateFileName), 8 ) );
890 memcpy( pResult->filename + 8, p + 1, MIN( strlen(p), 3 ) );
892 else
893 memcpy( pResult->filename, entry.cAlternateFileName,
894 MIN( strlen(entry.cAlternateFileName), 8 ) );
896 return 1;
900 static void DeleteFileFCB( CONTEXT *context )
902 FIXME(int21, "(%p): stub\n", context);
905 static void RenameFileFCB( CONTEXT *context )
907 FIXME(int21, "(%p): stub\n", context);
912 static void fLock( CONTEXT * context )
915 switch ( AX_reg(context) & 0xff )
917 case 0x00: /* LOCK */
918 TRACE(int21,"lock handle %d offset %ld length %ld\n",
919 BX_reg(context),
920 MAKELONG(DX_reg(context),CX_reg(context)),
921 MAKELONG(DI_reg(context),SI_reg(context))) ;
922 if (!LockFile(HFILE16_TO_HFILE32(BX_reg(context)),
923 MAKELONG(DX_reg(context),CX_reg(context)), 0,
924 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
925 AX_reg(context) = DOS_ExtendedError;
926 SET_CFLAG(context);
928 break;
930 case 0x01: /* UNLOCK */
931 TRACE(int21,"unlock handle %d offset %ld length %ld\n",
932 BX_reg(context),
933 MAKELONG(DX_reg(context),CX_reg(context)),
934 MAKELONG(DI_reg(context),SI_reg(context))) ;
935 if (!UnlockFile(HFILE16_TO_HFILE32(BX_reg(context)),
936 MAKELONG(DX_reg(context),CX_reg(context)), 0,
937 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
938 AX_reg(context) = DOS_ExtendedError;
939 SET_CFLAG(context);
941 return;
942 default:
943 AX_reg(context) = 0x0001;
944 SET_CFLAG(context);
945 return;
949 static BOOL32
950 INT21_networkfunc (CONTEXT *context)
952 switch (AL_reg(context)) {
953 case 0x00: /* Get machine name. */
955 char *dst = CTX_SEG_OFF_TO_LIN (context,DS_reg(context),EDX_reg(context));
956 TRACE(int21, "getting machine name to %p\n", dst);
957 if (gethostname (dst, 15))
959 WARN(int21,"failed!\n");
960 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
961 return TRUE;
962 } else {
963 int len = strlen (dst);
964 while (len < 15)
965 dst[len++] = ' ';
966 dst[15] = 0;
967 CH_reg(context) = 1; /* Valid */
968 CL_reg(context) = 1; /* NETbios number??? */
969 TRACE(int21, "returning %s\n", debugstr_an (dst, 16));
970 return FALSE;
974 default:
975 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
976 return TRUE;
980 static void INT21_SetCurrentPSP(WORD psp)
982 #ifdef MZ_SUPPORTED
983 TDB *pTask = hModule ? NULL : (TDB *)GlobalLock16( GetCurrentTask() );
984 NE_MODULE *pModule = (hModule || pTask) ? NE_GetPtr( hModule ? hModule : pTask->hModule ) : NULL;
986 GlobalUnlock16( GetCurrentTask() );
987 if (pModule->lpDosTask)
988 pModule->lpDosTask->psp_seg = psp;
989 else
990 #endif
991 ERR(int21, "Cannot change PSP for non-DOS task!\n");
994 static WORD INT21_GetCurrentPSP()
996 #ifdef MZ_SUPPORTED
997 TDB *pTask = hModule ? NULL : (TDB *)GlobalLock16( GetCurrentTask() );
998 NE_MODULE *pModule = (hModule || pTask) ? NE_GetPtr( hModule ? hModule : pTask->hModule ) : NULL;
1000 GlobalUnlock16( GetCurrentTask() );
1001 if (pModule->lpDosTask)
1002 return pModule->lpDosTask->psp_seg;
1003 else
1004 #endif
1005 return GetCurrentPDB();
1009 SEGPTR INT21_GetListOfLists()
1011 static DOS_LISTOFLISTS *LOL;
1012 static SEGPTR seg_LOL;
1015 Output of DOS 6.22:
1017 0133:0020 6A 13-33 01 CC 00 33 01 59 00 j.3...3.Y.
1018 0133:0030 70 00 00 00 72 02 00 02-6D 00 33 01 00 00 2E 05 p...r...m.3.....
1019 0133:0040 00 00 FC 04 00 00 03 08-92 21 11 E0 04 80 C6 0D .........!......
1020 0133:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..NUL ......
1021 0133:0060 00 4B BA C1 06 14 00 00-00 03 01 00 04 70 CE FF .K...........p..
1022 0133:0070 FF 00 00 00 00 00 00 00-00 01 00 00 0D 05 00 00 ................
1023 0133:0080 00 FF FF 00 00 00 00 FE-00 00 F8 03 FF 9F 70 02 ..............p.
1024 0133:0090 D0 44 C8 FD D4 44 C8 FD-D4 44 C8 FD D0 44 C8 FD .D...D...D...D..
1025 0133:00A0 D0 44 C8 FD D0 44 .D...D
1027 if (!LOL) {
1028 LOL = SEGPTR_ALLOC(sizeof(DOS_LISTOFLISTS));
1030 LOL->CX_Int21_5e01 = 0x0;
1031 LOL->LRU_count_FCB_cache = 0x0;
1032 LOL->LRU_count_FCB_open = 0x0;
1033 LOL->OEM_func_handler = -1; /* not available */
1034 LOL->INT21_offset = 0x0;
1035 LOL->sharing_retry_count = sharing_retries; /* default value: 3 */
1036 LOL->sharing_retry_delay = sharing_pause; /* default value: 1 */
1037 LOL->ptr_disk_buf = 0x0;
1038 LOL->offs_unread_CON = 0x0;
1039 LOL->seg_first_MCB = 0x0;
1040 LOL->ptr_first_DPB = 0x0;
1041 LOL->ptr_first_SysFileTable = 0x0;
1042 LOL->ptr_clock_dev_hdr = 0x0;
1043 LOL->ptr_CON_dev_hdr = 0x0;
1044 LOL->max_byte_per_sec = 512;
1045 LOL->ptr_disk_buf_info = 0x0;
1046 LOL->ptr_array_CDS = 0x0;
1047 LOL->ptr_sys_FCB = 0x0;
1048 LOL->nr_protect_FCB = 0x0;
1049 LOL->nr_block_dev = 0x0;
1050 LOL->nr_avail_drive_letters = 26; /* A - Z */
1051 LOL->nr_drives_JOINed = 0x0;
1052 LOL->ptr_spec_prg_names = 0x0;
1053 LOL->ptr_SETVER_prg_list = 0x0; /* no SETVER list */
1054 LOL->DOS_HIGH_A20_func_offs = 0x0;
1055 LOL->PSP_last_exec = 0x0;
1056 LOL->BUFFERS_val = 99; /* maximum: 99 */
1057 LOL->BUFFERS_nr_lookahead = 8; /* maximum: 8 */
1058 LOL->boot_drive = 3; /* C: */
1059 LOL->flag_DWORD_moves = 0x01; /* i386+ */
1060 LOL->size_extended_mem = 0xf000; /* very high value */
1062 if (!seg_LOL) seg_LOL = SEGPTR_GET(LOL);
1063 return seg_LOL+(WORD)&((DOS_LISTOFLISTS*)0)->ptr_first_DPB;
1066 /***********************************************************************
1067 * DOS3Call (KERNEL.102)
1069 void WINAPI DOS3Call( CONTEXT *context )
1071 BOOL32 bSetDOSExtendedError = FALSE;
1074 TRACE(int21, "AX=%04x BX=%04x CX=%04x DX=%04x "
1075 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1076 AX_reg(context), BX_reg(context), CX_reg(context), DX_reg(context),
1077 SI_reg(context), DI_reg(context),
1078 (WORD)DS_reg(context), (WORD)ES_reg(context),
1079 EFL_reg(context) );
1082 if (AH_reg(context) == 0x59) /* Get extended error info */
1084 TRACE(int21, "GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1085 DOS_ExtendedError, DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus);
1086 AX_reg(context) = DOS_ExtendedError;
1087 BH_reg(context) = DOS_ErrorClass;
1088 BL_reg(context) = DOS_ErrorAction;
1089 CH_reg(context) = DOS_ErrorLocus;
1090 return;
1093 if (AH_reg(context) == 0x0C) /* Flush buffer and read standard input */
1095 TRACE(int21, "FLUSH BUFFER AND READ STANDARD INPUT\n");
1096 /* no flush here yet */
1097 AH_reg(context) = AL_reg(context);
1100 DOS_ERROR( 0, 0, 0, 0 );
1101 RESET_CFLAG(context); /* Not sure if this is a good idea */
1103 switch(AH_reg(context))
1105 case 0x03: /* READ CHARACTER FROM STDAUX */
1106 case 0x04: /* WRITE CHARACTER TO STDAUX */
1107 case 0x05: /* WRITE CHARACTER TO PRINTER */
1108 case 0x0f: /* OPEN FILE USING FCB */
1109 case 0x10: /* CLOSE FILE USING FCB */
1110 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1111 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1112 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1113 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1114 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1115 case 0x23: /* GET FILE SIZE FOR FCB */
1116 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1117 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1118 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1119 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1120 case 0x54: /* GET VERIFY FLAG */
1121 INT_BARF( context, 0x21 );
1122 break;
1124 case 0x00: /* TERMINATE PROGRAM */
1125 TRACE(int21,"TERMINATE PROGRAM\n");
1126 ExitProcess( 0 );
1127 break;
1129 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1130 _lread16(1, (BYTE *)&context->Eax, 1);
1131 break;
1133 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1134 TRACE(int21, "Write Character to Standard Output\n");
1135 CONSOLE_Write(DL_reg(context), 0, 0, 0);
1136 break;
1138 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1139 TRACE(int21, "Direct Console Input/Output\n");
1140 CONSOLE_Write(DL_reg(context), 0, 0, 0);
1141 break;
1143 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1144 TRACE(int21,"DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1145 AL_reg(context) = CONSOLE_GetCharacter();
1146 break;
1148 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1149 TRACE(int21,"CHARACTER INPUT WITHOUT ECHO\n");
1150 AL_reg(context) = CONSOLE_GetCharacter();
1151 break;
1153 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1154 TRACE(int21,"WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1155 DS_reg(context),DX_reg(context) );
1157 LPSTR data = CTX_SEG_OFF_TO_LIN(context,DS_reg(context),EDX_reg(context));
1158 LONG length = strchr(data,'$')-data;
1159 _hwrite16( 1, data, length);
1160 AL_reg(context) = '$'; /* yes, '$' (0x24) gets returned in AL */
1162 break;
1164 case 0x0a: /* BUFFERED INPUT */
1166 char *buffer = ((char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1167 EDX_reg(context) ));
1168 int res;
1170 TRACE(int21,"BUFFERED INPUT (size=%d)\n",buffer[0]);
1171 if (buffer[1])
1172 TRACE(int21,"Handle old chars in buffer!\n");
1173 res=_lread16( 0, buffer+2,buffer[0]);
1174 buffer[1]=res;
1175 if(buffer[res+1] == '\n')
1176 buffer[res+1] = '\r';
1177 break;
1180 case 0x0b: /* GET STDIN STATUS */
1182 CHAR dummy;
1184 AL_reg(context) = CONSOLE_CheckForKeystroke(&dummy, &dummy);
1186 break;
1187 case 0x2e: /* SET VERIFY FLAG */
1188 TRACE(int21,"SET VERIFY FLAG ignored\n");
1189 /* we cannot change the behaviour anyway, so just ignore it */
1190 break;
1192 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1193 case 0x1d:
1194 case 0x1e:
1195 case 0x20:
1196 case 0x6b: /* NULL FUNCTION */
1197 AL_reg(context) = 0;
1198 break;
1200 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1201 fLock(context);
1202 break;
1204 case 0x0d: /* DISK BUFFER FLUSH */
1205 TRACE(int21,"DISK BUFFER FLUSH ignored\n");
1206 RESET_CFLAG(context); /* dos 6+ only */
1207 break;
1209 case 0x0e: /* SELECT DEFAULT DRIVE */
1210 TRACE(int21,"SELECT DEFAULT DRIVE %d\n", DL_reg(context));
1211 DRIVE_SetCurrentDrive( DL_reg(context) );
1212 AL_reg(context) = MAX_DOS_DRIVES;
1213 break;
1215 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1216 TRACE(int21,"FIND FIRST MATCHING FILE USING FCB %p\n",
1217 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1218 if (!INT21_FindFirstFCB(context))
1220 AL_reg(context) = 0xff;
1221 break;
1223 /* else fall through */
1225 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1226 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
1227 break;
1229 case 0x13: /* DELETE FILE USING FCB */
1230 DeleteFileFCB(context);
1231 break;
1233 case 0x17: /* RENAME FILE USING FCB */
1234 RenameFileFCB(context);
1235 break;
1237 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1238 AL_reg(context) = DRIVE_GetCurrentDrive();
1239 break;
1241 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1243 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1244 pTask->dta = PTR_SEG_OFF_TO_SEGPTR(DS_reg(context),DX_reg(context));
1245 TRACE(int21, "Set DTA: %08lx\n", pTask->dta);
1247 break;
1249 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1250 DL_reg(context) = 0;
1251 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1252 break;
1254 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1255 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1256 break;
1258 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1259 GetDrivePB(context, DRIVE_GetCurrentDrive());
1260 break;
1262 case 0x25: /* SET INTERRUPT VECTOR */
1263 INT_CtxSetHandler( context, AL_reg(context),
1264 (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1265 DX_reg(context)));
1266 break;
1268 case 0x29: /* PARSE FILENAME INTO FCB */
1269 INT21_ParseFileNameIntoFCB(context);
1270 break;
1272 case 0x2a: /* GET SYSTEM DATE */
1273 INT21_GetSystemDate(context);
1274 break;
1276 case 0x2b: /* SET SYSTEM DATE */
1277 FIXME(int21, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1278 DL_reg(context), DH_reg(context), CX_reg(context) );
1279 AL_reg(context) = 0; /* Let's pretend we succeeded */
1280 break;
1282 case 0x2c: /* GET SYSTEM TIME */
1283 INT21_GetSystemTime(context);
1284 break;
1286 case 0x2d: /* SET SYSTEM TIME */
1287 FIXME(int21, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1288 CH_reg(context), CL_reg(context),
1289 DH_reg(context), DL_reg(context) );
1290 AL_reg(context) = 0; /* Let's pretend we succeeded */
1291 break;
1293 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1294 TRACE(int21,"GET DISK TRANSFER AREA ADDRESS\n");
1296 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1297 ES_reg(context) = SELECTOROF( pTask->dta );
1298 BX_reg(context) = OFFSETOF( pTask->dta );
1300 break;
1302 case 0x30: /* GET DOS VERSION */
1303 TRACE(int21,"GET DOS VERSION %s requested\n",
1304 (AL_reg(context) == 0x00)?"OEM number":"version flag");
1305 AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
1306 (HIWORD(GetVersion16()) << 8);
1307 #if 0
1308 AH_reg(context) = 0x7;
1309 AL_reg(context) = 0xA;
1310 #endif
1312 BX_reg(context) = 0x00FF; /* 0x123456 is Wine's serial # */
1313 CX_reg(context) = 0x0000;
1314 break;
1316 case 0x31: /* TERMINATE AND STAY RESIDENT */
1317 FIXME(int21,"TERMINATE AND STAY RESIDENT stub\n");
1318 break;
1320 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1321 TRACE(int21,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1322 INT21_DriveName( DL_reg(context)));
1323 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
1324 break;
1326 case 0x33: /* MULTIPLEXED */
1327 switch (AL_reg(context))
1329 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1330 TRACE(int21,"GET CURRENT EXTENDED BREAK STATE\n");
1331 DL_reg(context) = DOSCONF_config.brk_flag;
1332 break;
1334 case 0x01: /* SET EXTENDED BREAK STATE */
1335 TRACE(int21,"SET CURRENT EXTENDED BREAK STATE\n");
1336 DOSCONF_config.brk_flag = (DL_reg(context) > 0);
1337 break;
1339 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1340 TRACE(int21,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1341 /* ugly coding in order to stay reentrant */
1342 if (DL_reg(context))
1344 DL_reg(context) = DOSCONF_config.brk_flag;
1345 DOSCONF_config.brk_flag = 1;
1347 else
1349 DL_reg(context) = DOSCONF_config.brk_flag;
1350 DOSCONF_config.brk_flag = 0;
1352 break;
1354 case 0x05: /* GET BOOT DRIVE */
1355 TRACE(int21,"GET BOOT DRIVE\n");
1356 DL_reg(context) = 3;
1357 /* c: is Wine's bootdrive (a: is 1)*/
1358 break;
1360 case 0x06: /* GET TRUE VERSION NUMBER */
1361 TRACE(int21,"GET TRUE VERSION NUMBER\n");
1362 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1363 (HIWORD(GetVersion16() << 8));
1364 DX_reg(context) = 0x00;
1365 break;
1367 default:
1368 INT_BARF( context, 0x21 );
1369 break;
1371 break;
1373 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1374 TRACE(int21,"GET ADDRESS OF INDOS FLAG\n");
1375 if (!heap) INT21_CreateHeap();
1376 ES_reg(context) = DosHeapHandle;
1377 BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1378 break;
1380 case 0x35: /* GET INTERRUPT VECTOR */
1381 TRACE(int21,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1383 FARPROC16 addr = INT_CtxGetHandler( context, AL_reg(context) );
1384 ES_reg(context) = SELECTOROF(addr);
1385 BX_reg(context) = OFFSETOF(addr);
1387 break;
1389 case 0x36: /* GET FREE DISK SPACE */
1390 TRACE(int21,"GET FREE DISK SPACE FOR DRIVE %s\n",
1391 INT21_DriveName( DL_reg(context)));
1392 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1393 break;
1395 case 0x37:
1397 unsigned char switchchar='/';
1398 switch (AL_reg(context))
1400 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1401 TRACE(int21,"SWITCHAR - GET SWITCH CHARACTER\n");
1402 AL_reg(context) = 0x00; /* success*/
1403 DL_reg(context) = switchchar;
1404 break;
1405 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1406 TRACE(int21,"SWITCHAR - SET SWITCH CHARACTER\n");
1407 switchchar = DL_reg(context);
1408 AL_reg(context) = 0x00; /* success*/
1409 break;
1410 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1411 INT_BARF( context, 0x21 );
1412 break;
1414 break;
1417 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1418 TRACE(int21,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1419 AL_reg(context));
1420 AX_reg(context) = 0x02; /* no country support available */
1421 SET_CFLAG(context);
1422 break;
1424 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1425 TRACE(int21,"MKDIR %s\n",
1426 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1427 bSetDOSExtendedError = (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1428 EDX_reg(context) ), NULL));
1429 break;
1431 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1432 TRACE(int21,"RMDIR %s\n",
1433 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1434 bSetDOSExtendedError = (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1435 EDX_reg(context) )));
1436 break;
1438 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1439 TRACE(int21,"CHDIR %s\n",
1440 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1441 bSetDOSExtendedError = !INT21_ChangeDir(context);
1442 break;
1444 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1445 TRACE(int21,"CREAT flag 0x%02x %s\n",CX_reg(context),
1446 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1447 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1448 EDX_reg(context) ), CX_reg(context) );
1449 bSetDOSExtendedError = (AX_reg(context) == (WORD)HFILE_ERROR16);
1450 break;
1452 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1453 TRACE(int21,"OPEN mode 0x%02x %s\n",AL_reg(context),
1454 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1455 OpenExistingFile(context);
1456 break;
1458 case 0x3e: /* "CLOSE" - CLOSE FILE */
1459 TRACE(int21,"CLOSE handle %d\n",BX_reg(context));
1460 if ((BX_reg(context)<5)||
1461 /* FIXME: need to improve on those handle conversion macros */
1462 (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_INPUT_HANDLE)))||
1463 (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_OUTPUT_HANDLE)))||
1464 (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_ERROR_HANDLE)))) {
1465 /* hack to make sure stdio isn't closed */
1466 FIXME(int21, "stdio handle closed, need proper conversion\n");
1467 DOS_ExtendedError = 0x06;
1468 bSetDOSExtendedError = TRUE;
1469 } else
1470 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1471 break;
1473 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1474 TRACE(int21,"READ from %d to %04lX:%04X for %d byte\n",BX_reg(context),
1475 DS_reg(context),DX_reg(context),CX_reg(context) );
1477 LONG result;
1478 if (ISV86(context))
1479 result = _hread16( BX_reg(context),
1480 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1481 EDX_reg(context) ),
1482 CX_reg(context) );
1483 else
1484 result = WIN16_hread( BX_reg(context),
1485 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1486 EDX_reg(context) ),
1487 CX_reg(context) );
1488 if (result == -1) bSetDOSExtendedError = TRUE;
1489 else AX_reg(context) = (WORD)result;
1491 break;
1493 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1494 TRACE(int21,"WRITE from %04lX:%04X to handle %d for %d byte\n",
1495 DS_reg(context),DX_reg(context),BX_reg(context),CX_reg(context) );
1497 LONG result = _hwrite16( BX_reg(context),
1498 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1499 EDX_reg(context) ),
1500 CX_reg(context) );
1501 if (result == -1) bSetDOSExtendedError = TRUE;
1502 else AX_reg(context) = (WORD)result;
1504 break;
1506 case 0x41: /* "UNLINK" - DELETE FILE */
1507 TRACE(int21,"UNLINK%s\n",
1508 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1509 bSetDOSExtendedError = (!DeleteFile32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1510 EDX_reg(context) )));
1511 break;
1513 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1514 TRACE(int21,"LSEEK handle %d offset %ld from %s\n",
1515 BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)),
1516 (AL_reg(context)==0)?"start of file":(AL_reg(context)==1)?
1517 "current file position":"end of file");
1519 LONG status = _llseek16( BX_reg(context),
1520 MAKELONG(DX_reg(context),CX_reg(context)),
1521 AL_reg(context) );
1522 if (status == -1) bSetDOSExtendedError = TRUE;
1523 else
1525 AX_reg(context) = LOWORD(status);
1526 DX_reg(context) = HIWORD(status);
1529 break;
1531 case 0x43: /* FILE ATTRIBUTES */
1532 switch (AL_reg(context))
1534 case 0x00:
1535 TRACE(int21,"GET FILE ATTRIBUTES for %s\n",
1536 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1537 AX_reg(context) = (WORD)GetFileAttributes32A(
1538 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1539 EDX_reg(context)));
1540 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1541 else CX_reg(context) = AX_reg(context);
1542 break;
1544 case 0x01:
1545 TRACE(int21,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context),
1546 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1547 bSetDOSExtendedError =
1548 (!SetFileAttributes32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1549 EDX_reg(context)),
1550 CX_reg(context) ));
1551 break;
1552 case 0x02:
1553 TRACE(int21,"GET COMPRESSED FILE SIZE for %s stub\n",
1554 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1556 break;
1558 case 0x44: /* IOCTL */
1559 switch (AL_reg(context))
1561 case 0x00:
1562 ioctlGetDeviceInfo(context);
1563 break;
1565 case 0x01:
1566 break;
1567 case 0x02:{
1568 FILE_OBJECT *file;
1569 file = FILE_GetFile(HFILE16_TO_HFILE32(BX_reg(context)),0,NULL);
1570 if (!strcasecmp(file->unix_name, "SCSIMGR$"))
1571 ASPI_DOS_HandleInt(context);
1572 FILE_ReleaseFile( file );
1573 break;
1575 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1576 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));*/
1577 int drive = DOS_GET_DRIVE(BL_reg(context));
1579 FIXME(int21,"program tried to write to block device control channel of drive %d:\n",drive);
1580 /* for (i=0;i<CX_reg(context);i++)
1581 fprintf(stdnimp,"%02x ",dataptr[i]);
1582 fprintf(stdnimp,"\n");*/
1583 AX_reg(context)=CX_reg(context);
1584 break;
1586 case 0x08: /* Check if drive is removable. */
1587 TRACE(int21,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1588 INT21_DriveName( BL_reg(context)));
1589 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1591 case DRIVE_CANNOTDETERMINE:
1592 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1593 AX_reg(context) = ER_InvalidDrive;
1594 SET_CFLAG(context);
1595 break;
1596 case DRIVE_REMOVABLE:
1597 AX_reg(context) = 0; /* removable */
1598 break;
1599 default:
1600 AX_reg(context) = 1; /* not removable */
1601 break;
1603 break;
1605 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1606 TRACE(int21,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1607 INT21_DriveName( BL_reg(context)));
1608 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1610 case DRIVE_CANNOTDETERMINE:
1611 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1612 AX_reg(context) = ER_InvalidDrive;
1613 SET_CFLAG(context);
1614 break;
1615 case DRIVE_REMOTE:
1616 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1617 break;
1618 default:
1619 DX_reg(context) = 0; /* FIXME: use driver attr here */
1620 break;
1622 break;
1624 case 0x0a: /* check if handle (BX) is remote */
1625 TRACE(int21,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context));
1626 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1627 * not set on close
1629 DX_reg(context) = 0;
1630 break;
1632 case 0x0b: /* SET SHARING RETRY COUNT */
1633 TRACE(int21,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1634 CX_reg(context), DX_reg(context));
1635 if (!CX_reg(context))
1637 AX_reg(context) = 1;
1638 SET_CFLAG(context);
1639 break;
1641 sharing_pause = CX_reg(context);
1642 if (!DX_reg(context))
1643 sharing_retries = DX_reg(context);
1644 RESET_CFLAG(context);
1645 break;
1647 case 0x0d:
1648 TRACE(int21,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1649 INT21_DriveName( BL_reg(context)));
1650 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1651 break;
1653 case 0x0e: /* get logical drive mapping */
1654 TRACE(int21,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1655 INT21_DriveName( BL_reg(context)));
1656 AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1657 break;
1659 case 0x0F: /* Set logical drive mapping */
1661 int drive;
1662 TRACE(int21,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1663 INT21_DriveName( BL_reg(context)));
1664 drive = DOS_GET_DRIVE ( BL_reg(context) );
1665 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1667 SET_CFLAG(context);
1668 AX_reg(context) = 0x000F; /* invalid drive */
1670 break;
1673 case 0xe0: /* Sun PC-NFS API */
1674 /* not installed */
1675 break;
1677 default:
1678 INT_BARF( context, 0x21 );
1679 break;
1681 break;
1683 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1685 HANDLE32 handle;
1686 TRACE(int21,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context));
1687 if ((bSetDOSExtendedError = !DuplicateHandle( GetCurrentProcess(),
1688 HFILE16_TO_HFILE32(BX_reg(context)),
1689 GetCurrentProcess(), &handle,
1690 0, TRUE, DUPLICATE_SAME_ACCESS )))
1691 AX_reg(context) = HFILE_ERROR16;
1692 else
1693 AX_reg(context) = HFILE32_TO_HFILE16(handle);
1694 break;
1697 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1698 TRACE(int21,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1699 BX_reg(context),CX_reg(context));
1700 bSetDOSExtendedError = (FILE_Dup2( HFILE16_TO_HFILE32(BX_reg(context)), HFILE16_TO_HFILE32(CX_reg(context)) ) == HFILE_ERROR32);
1701 break;
1703 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1704 TRACE(int21,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1705 INT21_DriveName( DL_reg(context)));
1706 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1707 break;
1709 case 0x48: /* ALLOCATE MEMORY */
1710 TRACE(int21,"ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context));
1712 LPVOID *mem;
1713 if (ISV86(context))
1715 mem= DOSMEM_GetBlock(0,(DWORD)BX_reg(context)<<4,NULL);
1716 if (mem)
1717 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1719 else
1721 mem = (LPVOID)GlobalDOSAlloc(BX_reg(context)<<4);
1722 if (mem)
1723 AX_reg(context) = (DWORD)mem&0xffff;
1725 if (!mem)
1727 SET_CFLAG(context);
1728 AX_reg(context) = 0x0008; /* insufficient memory */
1729 BX_reg(context) = DOSMEM_Available(0)>>4;
1732 break;
1734 case 0x49: /* FREE MEMORY */
1735 TRACE(int21,"FREE MEMORY segment %04lX\n", ES_reg(context));
1737 BOOL32 ret;
1738 if (ISV86(context))
1739 ret= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4));
1740 else
1742 ret = !GlobalDOSFree(ES_reg(context));
1743 /* If we don't reset ES_reg, we will fail in the relay code */
1744 ES_reg(context)=ret;
1746 if (!ret)
1748 TRACE(int21,"FREE MEMORY failed\n");
1749 SET_CFLAG(context);
1750 AX_reg(context) = 0x0009; /* memory block address invalid */
1753 break;
1755 case 0x4a: /* RESIZE MEMORY BLOCK */
1756 TRACE(int21,"RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context), BX_reg(context));
1757 if (!ISV86(context))
1758 FIXME(int21,"RESIZE MEMORY probably insufficent implementation. Expect crash soon\n");
1760 LPVOID *mem = DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4),
1761 BX_reg(context)<<4,NULL);
1762 if (mem)
1763 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1764 else {
1765 SET_CFLAG(context);
1766 AX_reg(context) = 0x0008; /* insufficient memory */
1767 BX_reg(context) = DOSMEM_Available(0)>>4; /* not quite right */
1770 break;
1772 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1773 TRACE(int21,"EXEC %s\n",
1774 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context) ));
1775 AX_reg(context) = WinExec16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1776 EDX_reg(context) ),
1777 SW_NORMAL );
1778 if (AX_reg(context) < 32) SET_CFLAG(context);
1779 break;
1781 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1782 TRACE(int21,"EXIT with return code %d\n",AL_reg(context));
1783 ExitProcess( AL_reg(context) );
1784 break;
1786 case 0x4d: /* GET RETURN CODE */
1787 TRACE(int21,"GET RETURN CODE (ERRORLEVEL)\n");
1788 AX_reg(context) = 0; /* normal exit */
1789 break;
1791 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1792 TRACE(int21,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
1793 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1794 if (!INT21_FindFirst(context)) break;
1795 /* fall through */
1797 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1798 TRACE(int21,"FINDNEXT\n");
1799 if (!INT21_FindNext(context))
1801 DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk );
1802 AX_reg(context) = ER_NoMoreFiles;
1803 SET_CFLAG(context);
1805 else AX_reg(context) = 0; /* OK */
1806 break;
1807 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1808 TRACE(int21, "SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1809 INT21_SetCurrentPSP(BX_reg(context));
1810 break;
1811 case 0x51: /* GET PSP ADDRESS */
1812 TRACE(int21,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1813 /* FIXME: should we return the original DOS PSP upon */
1814 /* Windows startup ? */
1815 BX_reg(context) = INT21_GetCurrentPSP();
1816 break;
1817 case 0x62: /* GET PSP ADDRESS */
1818 TRACE(int21,"GET CURRENT PSP ADDRESS\n");
1819 /* FIXME: should we return the original DOS PSP upon */
1820 /* Windows startup ? */
1821 BX_reg(context) = INT21_GetCurrentPSP();
1822 break;
1824 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1825 TRACE(int21,"SYSVARS - GET LIST OF LISTS\n");
1827 SEGPTR lol;
1828 lol = INT21_GetListOfLists();
1829 ES_reg(context) = HIWORD(lol);
1830 BX_reg(context) = LOWORD(lol);
1832 break;
1834 case 0x56: /* "RENAME" - RENAME FILE */
1835 TRACE(int21,"RENAME %s to %s\n",
1836 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1837 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context)));
1838 bSetDOSExtendedError =
1839 (!MoveFile32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1840 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context))));
1841 break;
1843 case 0x57: /* FILE DATE AND TIME */
1844 switch (AL_reg(context))
1846 case 0x00: /* Get */
1848 FILETIME filetime;
1849 TRACE(int21,"GET FILE DATE AND TIME for handle %d\n",
1850 BX_reg(context));
1851 if (!GetFileTime( HFILE16_TO_HFILE32(BX_reg(context)), NULL, NULL, &filetime ))
1852 bSetDOSExtendedError = TRUE;
1853 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1854 &CX_reg(context) );
1856 break;
1858 case 0x01: /* Set */
1860 FILETIME filetime;
1861 TRACE(int21,"SET FILE DATE AND TIME for handle %d\n",
1862 BX_reg(context));
1863 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1864 &filetime );
1865 bSetDOSExtendedError =
1866 (!SetFileTime( HFILE16_TO_HFILE32(BX_reg(context)),
1867 NULL, NULL, &filetime ));
1869 break;
1871 break;
1873 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1874 TRACE(int21,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1875 AL_reg(context));
1876 switch (AL_reg(context))
1878 case 0x00:
1879 AX_reg(context) = 1;
1880 break;
1881 case 0x02:
1882 AX_reg(context) = 0;
1883 break;
1884 case 0x01:
1885 case 0x03:
1886 break;
1888 RESET_CFLAG(context);
1889 break;
1891 case 0x5a: /* CREATE TEMPORARY FILE */
1892 TRACE(int21,"CREATE TEMPORARY FILE\n");
1893 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1894 break;
1896 case 0x5b: /* CREATE NEW FILE */
1897 TRACE(int21,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
1898 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1899 bSetDOSExtendedError = ((AX_reg(context) =
1900 HFILE32_TO_HFILE16(_lcreat_uniq( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)), 0 )))
1901 == (WORD)HFILE_ERROR16);
1902 break;
1904 case 0x5d: /* NETWORK */
1905 FIXME(int21,"Function 0x%04x not implemented.\n", AX_reg (context));
1906 /* Fix the following while you're at it. */
1907 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1908 bSetDOSExtendedError = TRUE;
1909 break;
1911 case 0x5e:
1912 bSetDOSExtendedError = INT21_networkfunc (context);
1913 break;
1915 case 0x5f: /* NETWORK */
1916 switch (AL_reg(context))
1918 case 0x07: /* ENABLE DRIVE */
1919 TRACE(int21,"ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1920 if (!DRIVE_Enable( DL_reg(context) ))
1922 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1923 bSetDOSExtendedError = TRUE;
1925 break;
1927 case 0x08: /* DISABLE DRIVE */
1928 TRACE(int21,"DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1929 if (!DRIVE_Disable( DL_reg(context) ))
1931 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1932 bSetDOSExtendedError = TRUE;
1934 break;
1936 default:
1937 /* network software not installed */
1938 TRACE(int21,"NETWORK function AX=%04x not implemented\n",AX_reg(context));
1939 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1940 bSetDOSExtendedError = TRUE;
1941 break;
1943 break;
1945 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1946 TRACE(int21,"TRUENAME %s\n",
1947 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),ESI_reg(context)));
1949 if (!GetFullPathName32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1950 ESI_reg(context)), 128,
1951 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
1952 EDI_reg(context)),NULL))
1953 bSetDOSExtendedError = TRUE;
1954 else AX_reg(context) = 0;
1956 break;
1958 case 0x61: /* UNUSED */
1959 case 0x63: /* misc. language support */
1960 switch (AL_reg(context)) {
1961 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1962 INT21_GetDBCSLeadTable(context);
1963 break;
1965 break;
1966 case 0x64: /* OS/2 DOS BOX */
1967 INT_BARF( context, 0x21 );
1968 SET_CFLAG(context);
1969 break;
1971 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1972 extern WORD WINE_LanguageId;
1973 BYTE *dataptr=CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context));
1974 TRACE(int21,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1975 BX_reg(context), DX_reg(context));
1976 switch (AL_reg(context)) {
1977 case 0x01:
1978 TRACE(int21,"\tget general internationalization info\n");
1979 dataptr[0] = 0x1;
1980 *(WORD*)(dataptr+1) = 41;
1981 *(WORD*)(dataptr+3) = WINE_LanguageId;
1982 *(WORD*)(dataptr+5) = CodePage;
1983 *(DWORD*)(dataptr+0x19) = 0; /* FIXME: ptr to case map routine */
1984 break;
1985 case 0x06:
1986 TRACE(int21,"\tget pointer to collating sequence table\n");
1987 dataptr[0] = 0x06;
1988 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
1989 CX_reg(context) = 258;/*FIXME: size of table?*/
1990 break;
1991 default:
1992 TRACE(int21,"\tunimplemented function %d\n",AL_reg(context));
1993 INT_BARF( context, 0x21 );
1994 SET_CFLAG(context);
1995 break;
1997 break;
1999 case 0x66: /* GLOBAL CODE PAGE TABLE */
2000 switch (AL_reg(context))
2002 case 0x01:
2003 TRACE(int21,"GET GLOBAL CODE PAGE TABLE\n");
2004 DX_reg(context) = BX_reg(context) = CodePage;
2005 RESET_CFLAG(context);
2006 break;
2007 case 0x02:
2008 TRACE(int21,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2009 BX_reg(context),DX_reg(context));
2010 CodePage = BX_reg(context);
2011 RESET_CFLAG(context);
2012 break;
2014 break;
2016 case 0x67: /* SET HANDLE COUNT */
2017 TRACE(int21,"SET HANDLE COUNT to %d\n",BX_reg(context) );
2018 SetHandleCount16( BX_reg(context) );
2019 if (DOS_ExtendedError) bSetDOSExtendedError = TRUE;
2020 break;
2022 case 0x68: /* "FFLUSH" - COMMIT FILE */
2023 case 0x6a: /* COMMIT FILE */
2024 TRACE(int21,"FFLUSH/COMMIT handle %d\n",BX_reg(context));
2025 bSetDOSExtendedError = (!FlushFileBuffers( HFILE16_TO_HFILE32(BX_reg(context)) ));
2026 break;
2028 case 0x69: /* DISK SERIAL NUMBER */
2029 switch (AL_reg(context))
2031 case 0x00:
2032 TRACE(int21,"GET DISK SERIAL NUMBER for drive %s\n",
2033 INT21_DriveName(BL_reg(context)));
2034 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2035 else AX_reg(context) = 0;
2036 break;
2038 case 0x01:
2039 TRACE(int21,"SET DISK SERIAL NUMBER for drive %s\n",
2040 INT21_DriveName(BL_reg(context)));
2041 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2042 else AX_reg(context) = 1;
2043 break;
2045 break;
2047 case 0x6C: /* Extended Open/Create*/
2048 TRACE(int21,"EXTENDED OPEN/CREATE %s\n",
2049 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDI_reg(context)));
2050 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2051 break;
2053 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2054 if ((GetVersion32()&0xC0000004)!=0xC0000004) {
2055 /* not supported on anything but Win95 */
2056 TRACE(int21,"LONG FILENAME functions supported only by win95\n");
2057 SET_CFLAG(context);
2058 AL_reg(context) = 0;
2059 } else
2060 switch(AL_reg(context))
2062 case 0x39: /* Create directory */
2063 TRACE(int21,"LONG FILENAME - MAKE DIRECTORY %s\n",
2064 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2065 bSetDOSExtendedError = (!CreateDirectory32A(
2066 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2067 EDX_reg(context) ), NULL));
2068 break;
2069 case 0x3a: /* Remove directory */
2070 TRACE(int21,"LONG FILENAME - REMOVE DIRECTORY %s\n",
2071 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2072 bSetDOSExtendedError = (!RemoveDirectory32A(
2073 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2074 EDX_reg(context) )));
2075 break;
2076 case 0x43: /* Get/Set file attributes */
2077 TRACE(int21,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2078 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2079 switch (BL_reg(context))
2081 case 0x00: /* Get file attributes */
2082 TRACE(int21,"\tretrieve attributes\n");
2083 CX_reg(context) = (WORD)GetFileAttributes32A(
2084 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2085 EDX_reg(context)));
2086 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
2087 break;
2088 case 0x01:
2089 TRACE(int21,"\tset attributes 0x%04x\n",CX_reg(context));
2090 bSetDOSExtendedError = (!SetFileAttributes32A(
2091 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2092 EDX_reg(context)),
2093 CX_reg(context) ) );
2094 break;
2095 default:
2096 FIXME(int21, "Unimplemented long file name function:\n");
2097 INT_BARF( context, 0x21 );
2098 SET_CFLAG(context);
2099 AL_reg(context) = 0;
2100 break;
2102 break;
2103 case 0x47: /* Get current directory */
2104 TRACE(int21," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2105 INT21_DriveName(DL_reg(context)));
2106 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
2107 break;
2109 case 0x4e: /* Find first file */
2110 TRACE(int21," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2111 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2112 /* FIXME: use attributes in CX */
2113 if ((AX_reg(context) = FindFirstFile16(
2114 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
2115 (WIN32_FIND_DATA32A *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2116 EDI_reg(context))))
2117 == INVALID_HANDLE_VALUE16)
2118 bSetDOSExtendedError = TRUE;
2119 break;
2120 case 0x4f: /* Find next file */
2121 TRACE(int21,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2122 BX_reg(context));
2123 if (!FindNextFile16( BX_reg(context),
2124 (WIN32_FIND_DATA32A *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2125 EDI_reg(context))))
2126 bSetDOSExtendedError = TRUE;
2127 break;
2128 case 0xa1: /* Find close */
2129 TRACE(int21,"LONG FILENAME - FINDCLOSE for handle %d\n",
2130 BX_reg(context));
2131 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
2132 break;
2133 case 0xa0:
2134 TRACE(int21,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2135 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2136 break;
2137 case 0x60:
2138 switch(CL_reg(context))
2140 case 0x01: /*Get short filename or path */
2141 if (!GetShortPathName32A
2142 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2143 ESI_reg(context)),
2144 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2145 EDI_reg(context)), 67))
2146 bSetDOSExtendedError = TRUE;
2147 else AX_reg(context) = 0;
2148 break;
2149 case 0x02: /*Get canonical long filename or path */
2150 if (!GetFullPathName32A
2151 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2152 ESI_reg(context)), 128,
2153 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2154 EDI_reg(context)),NULL))
2155 bSetDOSExtendedError = TRUE;
2156 else AX_reg(context) = 0;
2157 break;
2158 default:
2159 FIXME(int21, "Unimplemented long file name function:\n");
2160 INT_BARF( context, 0x21 );
2161 SET_CFLAG(context);
2162 AL_reg(context) = 0;
2163 break;
2165 break;
2166 case 0x6c: /* Create or open file */
2167 TRACE(int21,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
2168 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context)));
2169 /* translate Dos 7 action to Dos 6 action */
2170 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2171 break;
2173 case 0x3b: /* Change directory */
2174 TRACE(int21,"LONG FILENAME - CHANGE DIRECTORY %s\n",
2175 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
2176 if (!SetCurrentDirectory32A(CTX_SEG_OFF_TO_LIN(context,
2177 DS_reg(context),
2178 EDX_reg(context)
2181 SET_CFLAG(context);
2182 AL_reg(context) = DOS_ExtendedError;
2184 break;
2185 case 0x41: /* Delete file */
2186 TRACE(int21,"LONG FILENAME - DELETE FILE %s\n",
2187 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
2188 if (!DeleteFile32A(CTX_SEG_OFF_TO_LIN(context,
2189 DS_reg(context),
2190 EDX_reg(context))
2191 )) {
2192 SET_CFLAG(context);
2193 AL_reg(context) = DOS_ExtendedError;
2195 break;
2196 case 0x56: /* Move (rename) file */
2197 TRACE(int21,"LONG FILENAME - RENAME FILE %s to %s stub\n",
2198 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)),
2199 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context), EDI_reg(context)));
2200 default:
2201 FIXME(int21, "Unimplemented long file name function:\n");
2202 INT_BARF( context, 0x21 );
2203 SET_CFLAG(context);
2204 AL_reg(context) = 0;
2205 break;
2207 break;
2209 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2210 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2211 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2212 TRACE(int21,"windows95 function AX %04x\n",
2213 AX_reg(context));
2214 WARN(int21, " returning unimplemented\n");
2215 SET_CFLAG(context);
2216 AL_reg(context) = 0;
2217 break;
2219 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2220 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2221 break;
2223 default:
2224 INT_BARF( context, 0x21 );
2225 break;
2227 } /* END OF SWITCH */
2229 if( bSetDOSExtendedError ) /* set general error condition */
2231 AX_reg(context) = DOS_ExtendedError;
2232 SET_CFLAG(context);
2235 if ((EFL_reg(context) & 0x0001))
2236 TRACE(int21, "failed, errorcode 0x%02x class 0x%02x action 0x%02x locus %02x\n",
2237 DOS_ExtendedError, DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus);
2239 TRACE(int21, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2240 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2241 AX_reg(context), BX_reg(context), CX_reg(context),
2242 DX_reg(context), SI_reg(context), DI_reg(context),
2243 (WORD)DS_reg(context), (WORD)ES_reg(context),
2244 EFL_reg(context));
2247 FARPROC16 WINAPI GetSetKernelDOSProc(FARPROC16 DosProc)
2249 FIXME(int21, "(DosProc=0x%08x): stub\n", (UINT32)DosProc);
2250 return NULL;