- Added a global label for elf-dll linking and a long with the resource
[wine.git] / msdos / int21.c
blobcc5ec8a73a3bf287e47ead8ebc2bd477c5238902
1 /*
2 * DOS interrupt 21h handler
3 */
5 #include <time.h>
6 #include <fcntl.h>
7 #include <errno.h>
8 #include <stdlib.h>
9 #include <sys/file.h>
10 #include <string.h>
11 #include <sys/stat.h>
12 #include <sys/time.h>
13 #include <sys/types.h>
14 #include <unistd.h>
15 #include <utime.h>
16 #include <ctype.h>
17 #include "windows.h"
18 #include "drive.h"
19 #include "file.h"
20 #include "heap.h"
21 #include "msdos.h"
22 #include "ldt.h"
23 #include "task.h"
24 #include "options.h"
25 #include "miscemu.h"
26 #include "debug.h"
27 #include "console.h"
28 #if defined(__svr4__) || defined(_SCO_DS)
29 /* SVR4 DOESNT do locking the same way must implement properly */
30 #define LOCK_EX 0
31 #define LOCK_SH 1
32 #define LOCK_NB 8
33 #endif
36 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
38 /* Define the drive parameter block, as used by int21/1F
39 * and int21/32. This table can be accessed through the
40 * global 'dpb' pointer, which points into the local dos
41 * heap.
43 struct DPB
45 BYTE drive_num; /* 0=A, etc. */
46 BYTE unit_num; /* Drive's unit number (?) */
47 WORD sector_size; /* Sector size in bytes */
48 BYTE high_sector; /* Highest sector in a cluster */
49 BYTE shift; /* Shift count (?) */
50 WORD reserved; /* Number of reserved sectors at start */
51 BYTE num_FAT; /* Number of FATs */
52 WORD dir_entries; /* Number of root dir entries */
53 WORD first_data; /* First data sector */
54 WORD high_cluster; /* Highest cluster number */
55 WORD sectors_in_FAT; /* Number of sectors per FAT */
56 WORD start_dir; /* Starting sector of first dir */
57 DWORD driver_head; /* Address of device driver header (?) */
58 BYTE media_ID; /* Media ID */
59 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
60 DWORD next; /* Pointer to next DPB in list */
61 WORD free_search; /* Free cluster search start */
62 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
65 WORD CodePage = 437;
66 DWORD dpbsegptr;
68 struct DosHeap {
69 BYTE InDosFlag;
70 BYTE mediaID;
71 BYTE biosdate[8];
72 struct DPB dpb;
73 BYTE DummyDBCSLeadTable[6];
75 static struct DosHeap *heap;
76 static WORD DosHeapHandle;
78 WORD sharing_retries = 3; /* number of retries at sharing violation */
79 WORD sharing_pause = 1; /* pause between retries */
81 extern char TempDirectory[];
83 static BOOL32 INT21_CreateHeap(void)
85 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
87 WARN(int21, "Out of memory\n");
88 return FALSE;
90 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
91 dpbsegptr = PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
92 heap->InDosFlag = 0;
93 strcpy(heap->biosdate, "01/01/80");
94 memset(heap->DummyDBCSLeadTable, 0, 6);
95 return TRUE;
98 static BYTE *GetCurrentDTA( CONTEXT *context )
100 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
102 /* FIXME: This assumes DTA was set correctly! */
103 return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
104 (DWORD)OFFSETOF(pTask->dta) );
108 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
109 /* limited == TRUE is used with INT 0x21/0x440d */
111 if (drive > 1) {
112 setword(data, 512);
113 data[2] = 2;
114 setword(&data[3], 0);
115 data[5] = 2;
116 setword(&data[6], 240);
117 setword(&data[8], 64000);
118 data[0x0a] = 0xf8;
119 setword(&data[0x0b], 40);
120 setword(&data[0x0d], 56);
121 setword(&data[0x0f], 2);
122 setword(&data[0x11], 0);
123 if (!limited) {
124 setword(&data[0x1f], 800);
125 data[0x21] = 5;
126 setword(&data[0x22], 1);
128 } else { /* 1.44mb */
129 setword(data, 512);
130 data[2] = 2;
131 setword(&data[3], 0);
132 data[5] = 2;
133 setword(&data[6], 240);
134 setword(&data[8], 2880);
135 data[0x0a] = 0xf8;
136 setword(&data[0x0b], 6);
137 setword(&data[0x0d], 18);
138 setword(&data[0x0f], 2);
139 setword(&data[0x11], 0);
140 if (!limited) {
141 setword(&data[0x1f], 80);
142 data[0x21] = 7;
143 setword(&data[0x22], 2);
148 static int INT21_GetFreeDiskSpace( CONTEXT *context )
150 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
151 char root[] = "A:\\";
153 *root += DOS_GET_DRIVE( DL_reg(context) );
154 if (!GetDiskFreeSpace32A( root, &cluster_sectors, &sector_bytes,
155 &free_clusters, &total_clusters )) return 0;
156 AX_reg(context) = cluster_sectors;
157 BX_reg(context) = free_clusters;
158 CX_reg(context) = sector_bytes;
159 DX_reg(context) = total_clusters;
160 return 1;
163 static int INT21_GetDriveAllocInfo( CONTEXT *context )
165 if (!INT21_GetFreeDiskSpace( context )) return 0;
166 if (!heap && !INT21_CreateHeap()) return 0;
167 heap->mediaID = 0xf0;
168 DS_reg(context) = DosHeapHandle;
169 BX_reg(context) = (int)&heap->mediaID - (int)heap;
170 return 1;
173 static void GetDrivePB( CONTEXT *context, int drive )
175 if(!DRIVE_IsValid(drive))
177 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
178 AX_reg(context) = 0x00ff;
180 else if (heap || INT21_CreateHeap())
182 FIXME(int21, "GetDrivePB not fully implemented.\n");
184 /* FIXME: I have no idea what a lot of this information should
185 * say or whether it even really matters since we're not allowing
186 * direct block access. However, some programs seem to depend on
187 * getting at least _something_ back from here. The 'next' pointer
188 * does worry me, though. Should we have a complete table of
189 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
191 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
192 heap->dpb.sector_size = 512;
193 heap->dpb.high_sector = 1;
194 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
195 heap->dpb.reserved = 0;
196 heap->dpb.num_FAT = 1;
197 heap->dpb.dir_entries = 2;
198 heap->dpb.first_data = 2;
199 heap->dpb.high_cluster = 64000;
200 heap->dpb.sectors_in_FAT = 1;
201 heap->dpb.start_dir = 1;
202 heap->dpb.driver_head = 0;
203 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
204 heap->dpb.access_flag = 0;
205 heap->dpb.next = 0;
206 heap->dpb.free_search = 0;
207 heap->dpb.free_clusters = 0xFFFF; /* unknown */
209 AL_reg(context) = 0x00;
210 DS_reg(context) = SELECTOROF(dpbsegptr);
211 BX_reg(context) = OFFSETOF(dpbsegptr);
216 static void ioctlGetDeviceInfo( CONTEXT *context )
218 int curr_drive;
219 FILE_OBJECT *file;
221 TRACE(int21, "(%d)\n", BX_reg(context));
223 RESET_CFLAG(context);
225 /* DOS device ? */
226 if ((file = FILE_GetFile( HFILE16_TO_HFILE32(BX_reg(context)) )))
228 const DOS_DEVICE *dev = DOSFS_GetDevice( file->unix_name );
229 FILE_ReleaseFile( file );
230 if (dev)
232 DX_reg(context) = dev->flags;
233 return;
237 /* it seems to be a file */
238 curr_drive = DRIVE_GetCurrentDrive();
239 DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0);
240 /* no floppy */
241 /* bits 0-5 are current drive
242 * bit 6 - file has NOT been written..FIXME: correct?
243 * bit 8 - generate int24 if no diskspace on write/ read past end of file
244 * bit 11 - media not removable
245 * bit 14 - don't set file date/time on closing
246 * bit 15 - file is remote
250 static BOOL32 ioctlGenericBlkDevReq( CONTEXT *context )
252 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
253 int drive = DOS_GET_DRIVE( BL_reg(context) );
255 if (!DRIVE_IsValid(drive))
257 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
258 return TRUE;
261 if (CH_reg(context) != 0x08)
263 INT_BARF( context, 0x21 );
264 return FALSE;
267 switch (CL_reg(context))
269 case 0x4a: /* lock logical volume */
270 TRACE(int21,"lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
271 break;
273 case 0x60: /* get device parameters */
274 /* used by w4wgrp's winfile */
275 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
276 dataptr[0] = 0x04;
277 dataptr[6] = 0; /* media type */
278 if (drive > 1)
280 dataptr[1] = 0x05; /* fixed disk */
281 setword(&dataptr[2], 0x01); /* non removable */
282 setword(&dataptr[4], 0x300); /* # of cylinders */
284 else
286 dataptr[1] = 0x07; /* block dev, floppy */
287 setword(&dataptr[2], 0x02); /* removable */
288 setword(&dataptr[4], 80); /* # of cylinders */
290 CreateBPB(drive, &dataptr[7], TRUE);
291 RESET_CFLAG(context);
292 break;
294 case 0x66:/* get disk serial number */
296 char label[12],fsname[9],path[4];
297 DWORD serial;
299 strcpy(path,"x:\\");path[0]=drive+'A';
300 GetVolumeInformation32A(
301 path,label,12,&serial,NULL,NULL,fsname,9
303 *(WORD*)dataptr = 0;
304 memcpy(dataptr+2,&serial,4);
305 memcpy(dataptr+6,label ,11);
306 memcpy(dataptr+17,fsname,8);
308 break;
310 case 0x6a:
311 TRACE(int21,"logical volume %d unlocked.\n",drive);
312 break;
314 case 0x6f:
315 memset(dataptr+1, '\0', dataptr[0]-1);
316 dataptr[1] = dataptr[0];
317 dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
318 dataptr[3] = 0xFF; /* no physical drive */
319 break;
321 default:
322 INT_BARF( context, 0x21 );
324 return FALSE;
327 static void INT21_ParseFileNameIntoFCB( CONTEXT *context )
329 char *filename =
330 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), SI_reg(context) );
331 char *fcb =
332 CTX_SEG_OFF_TO_LIN(context, ES_reg(context), DI_reg(context) );
333 char *buffer, *s, *d;
335 AL_reg(context) = 0xff; /* failed */
337 TRACE(int21, "filename: '%s'\n", filename);
339 buffer = HeapAlloc( GetProcessHeap(), 0, strlen(filename) );
341 s = filename;
342 d = buffer;
343 while (*s)
345 if ((*s != ' ') && (*s != '\r') && (*s != '\n'))
346 *d++ = *s++;
347 else
348 break;
351 *d = '\0';
352 DOSFS_ToDosFCBFormat(buffer, fcb + 1);
353 *fcb = 0;
354 TRACE(int21, "FCB: '%s'\n", ((CHAR *)fcb + 1));
356 HeapFree( GetProcessHeap(), 0, buffer);
358 AL_reg(context) =
359 ((strchr(filename, '*')) || (strchr(filename, '$'))) != 0;
361 /* point DS:SI to first unparsed character */
362 SI_reg(context) += (int)s - (int)filename;
365 static void INT21_GetSystemDate( CONTEXT *context )
367 SYSTEMTIME systime;
368 GetLocalTime( &systime );
369 CX_reg(context) = systime.wYear;
370 DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
371 AX_reg(context) = systime.wDayOfWeek;
374 static void INT21_GetSystemTime( CONTEXT *context )
376 SYSTEMTIME systime;
377 GetLocalTime( &systime );
378 CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
379 DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
382 /* Many calls translate a drive argument like this:
383 drive number (00h = default, 01h = A:, etc)
385 static char drivestring[]="default";
387 char *INT21_DriveName(int drive)
390 if(drive >0)
392 drivestring[0]= (unsigned char)drive + '@';
393 drivestring[1]=':';
394 drivestring[2]=0;
396 return drivestring;
398 static BOOL32 INT21_CreateFile( CONTEXT *context )
400 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
401 EDX_reg(context) ), CX_reg(context) );
402 return (AX_reg(context) == (WORD)HFILE_ERROR16);
406 static void OpenExistingFile( CONTEXT *context )
408 AX_reg(context) = _lopen16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
409 AL_reg(context) );
410 if (AX_reg(context) == (WORD)HFILE_ERROR16)
412 AX_reg(context) = DOS_ExtendedError;
413 SET_CFLAG(context);
415 #if 0
417 int handle;
418 int mode;
419 int lock;
421 switch (AX_reg(context) & 0x0070)
423 case 0x00: /* compatability mode */
424 case 0x40: /* DENYNONE */
425 lock = -1;
426 break;
428 case 0x30: /* DENYREAD */
429 TRACE(int21, "(%s): DENYREAD changed to DENYALL\n",
430 (char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
431 case 0x10: /* DENYALL */
432 lock = LOCK_EX;
433 break;
435 case 0x20: /* DENYWRITE */
436 lock = LOCK_SH;
437 break;
439 default:
440 lock = -1;
443 if (lock != -1)
446 int result,retries=sharing_retries;
448 #if defined(__svr4__) || defined(_SCO_DS)
449 ERR(int21, "Should call flock and needs porting to lockf\n");
450 result = 0;
451 retries = 0;
452 #else
453 result = flock(handle, lock | LOCK_NB);
454 #endif
455 if ( retries && (!result) )
457 int i;
458 for(i=0;i<32768*((int)sharing_pause);i++)
459 result++; /* stop the optimizer */
460 for(i=0;i<32768*((int)sharing_pause);i++)
461 result--;
464 while( (!result) && (!(retries--)) );
466 if(result)
468 errno_to_doserr();
469 AX_reg(context) = DOS_ExtendedError;
470 close(handle);
471 SET_CFLAG(context);
472 return;
477 Error (0,0,0);
478 AX_reg(context) = handle;
479 RESET_CFLAG(context);
481 #endif
484 static void CloseFile( CONTEXT *context )
486 if ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0)
488 AX_reg(context) = DOS_ExtendedError;
489 SET_CFLAG(context);
493 static BOOL32 INT21_ExtendedOpenCreateFile(CONTEXT *context )
495 BOOL32 bExtendedError = FALSE;
496 BYTE action = DL_reg(context);
498 /* Shuffle arguments to call OpenExistingFile */
499 AL_reg(context) = BL_reg(context);
500 DX_reg(context) = SI_reg(context);
501 /* BX,CX and DX should be preserved */
502 OpenExistingFile(context);
504 if ((EFL_reg(context) & 0x0001) == 0) /* File exists */
506 UINT16 uReturnCX = 0;
508 /* Now decide what do do */
510 if ((action & 0x07) == 0)
512 BX_reg(context) = AX_reg(context);
513 CloseFile(context);
514 AX_reg(context) = 0x0050; /*File exists*/
515 SET_CFLAG(context);
516 WARN(int21, "extended open/create: failed because file exists \n");
518 else if ((action & 0x07) == 2)
520 /* Truncate it, but first check if opened for write */
521 if ((BL_reg(context) & 0x0007)== 0)
523 BX_reg(context) = AX_reg(context);
524 CloseFile(context);
525 WARN(int21, "extended open/create: failed, trunc on ro file\n");
526 AX_reg(context) = 0x000C; /*Access code invalid*/
527 SET_CFLAG(context);
529 else
531 /* Shuffle arguments to call CloseFile while
532 * preserving BX and DX */
534 TRACE(int21, "extended open/create: Closing before truncate\n");
535 BX_reg(context) = AX_reg(context);
536 CloseFile(context);
537 if (EFL_reg(context) & 0x0001)
539 WARN(int21, "extended open/create: close before trunc failed\n");
540 AX_reg(context) = 0x0019; /*Seek Error*/
541 CX_reg(context) = 0;
542 SET_CFLAG(context);
544 /* Shuffle arguments to call CreateFile */
546 TRACE(int21, "extended open/create: Truncating\n");
547 AL_reg(context) = BL_reg(context);
548 /* CX is still the same */
549 DX_reg(context) = SI_reg(context);
550 bExtendedError = INT21_CreateFile(context);
552 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
554 WARN(int21, "extended open/create: trunc failed\n");
555 return bExtendedError;
557 uReturnCX = 0x3;
560 else uReturnCX = 0x1;
562 CX_reg(context) = uReturnCX;
564 else /* file does not exist */
566 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
567 if ((action & 0xF0)== 0)
569 CX_reg(context) = 0;
570 SET_CFLAG(context);
571 WARN(int21, "extended open/create: failed, file dosen't exist\n");
573 else
575 /* Shuffle arguments to call CreateFile */
576 TRACE(int21, "extended open/create: Creating\n");
577 AL_reg(context) = BL_reg(context);
578 /* CX should still be the same */
579 DX_reg(context) = SI_reg(context);
580 bExtendedError = INT21_CreateFile(context);
581 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
583 WARN(int21, "extended open/create: create failed\n");
584 return bExtendedError;
586 CX_reg(context) = 2;
590 return bExtendedError;
594 static BOOL32 INT21_ChangeDir( CONTEXT *context )
596 int drive;
597 char *dirname = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));
599 TRACE(int21,"changedir %s\n", dirname);
600 if (dirname[0] && (dirname[1] == ':'))
602 drive = toupper(dirname[0]) - 'A';
603 dirname += 2;
605 else drive = DRIVE_GetCurrentDrive();
606 return DRIVE_Chdir( drive, dirname );
610 static int INT21_FindFirst( CONTEXT *context )
612 char *p;
613 const char *path;
614 DOS_FULL_NAME full_name;
615 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
617 path = (const char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
618 dta->unixPath = NULL;
619 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
621 AX_reg(context) = DOS_ExtendedError;
622 SET_CFLAG(context);
623 return 0;
625 dta->unixPath = HEAP_strdupA( GetProcessHeap(), 0, full_name.long_name );
626 p = strrchr( dta->unixPath, '/' );
627 *p = '\0';
629 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
630 * (doesn't matter as it is set below anyway)
632 if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
634 HeapFree( GetProcessHeap(), 0, dta->unixPath );
635 dta->unixPath = NULL;
636 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
637 AX_reg(context) = ER_FileNotFound;
638 SET_CFLAG(context);
639 return 0;
641 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
642 : DRIVE_GetCurrentDrive();
643 dta->count = 0;
644 dta->search_attr = CL_reg(context);
645 return 1;
649 static int INT21_FindNext( CONTEXT *context )
651 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
652 WIN32_FIND_DATA32A entry;
653 int count;
655 if (!dta->unixPath) return 0;
656 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
657 dta->search_attr, dta->count, &entry )))
659 HeapFree( GetProcessHeap(), 0, dta->unixPath );
660 dta->unixPath = NULL;
661 return 0;
663 if ((int)dta->count + count > 0xffff)
665 WARN(int21, "Too many directory entries in %s\n", dta->unixPath );
666 HeapFree( GetProcessHeap(), 0, dta->unixPath );
667 dta->unixPath = NULL;
668 return 0;
670 dta->count += count;
671 dta->fileattr = entry.dwFileAttributes;
672 dta->filesize = entry.nFileSizeLow;
673 FileTimeToDosDateTime( &entry.ftLastWriteTime,
674 &dta->filedate, &dta->filetime );
675 strcpy( dta->filename, entry.cAlternateFileName );
676 if (!memchr(dta->mask,'?',11)) {
677 /* wildcardless search, release resources in case no findnext will
678 * be issued, and as a workaround in case file creation messes up
679 * findnext, as sometimes happens with pkunzip */
680 HeapFree( GetProcessHeap(), 0, dta->unixPath );
681 dta->unixPath = NULL;
683 return 1;
687 static BOOL32 INT21_CreateTempFile( CONTEXT *context )
689 static int counter = 0;
690 char *name = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context) );
691 char *p = name + strlen(name);
693 /* despite what Ralf Brown says, some programs seem to call without
694 * ending backslash (DOS accepts that, so we accept it too) */
695 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
697 for (;;)
699 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
700 counter = (counter + 1) % 1000;
702 if ((AX_reg(context) = HFILE32_TO_HFILE16(_lcreat_uniq( name, 0 ))) != (WORD)HFILE_ERROR16)
704 TRACE(int21, "created %s\n", name );
705 return TRUE;
707 if (DOS_ExtendedError != ER_FileExists) return FALSE;
712 static BOOL32 INT21_GetCurrentDirectory( CONTEXT *context )
714 int drive = DOS_GET_DRIVE( DL_reg(context) );
715 char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context) );
717 if (!DRIVE_IsValid(drive))
719 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
720 return FALSE;
722 lstrcpyn32A( ptr, DRIVE_GetDosCwd(drive), 64 );
723 AX_reg(context) = 0x0100; /* success return code */
724 return TRUE;
728 static void INT21_GetDBCSLeadTable( CONTEXT *context )
730 if (heap || INT21_CreateHeap())
731 { /* return an empty table just as DOS 4.0+ does */
732 DS_reg(context) = DosHeapHandle;
733 SI_reg(context) = (int)&heap->DummyDBCSLeadTable - (int)heap;
735 else
737 AX_reg(context) = 0x1; /* error */
738 SET_CFLAG(context);
743 static int INT21_GetDiskSerialNumber( CONTEXT *context )
745 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
746 int drive = DOS_GET_DRIVE( BL_reg(context) );
748 if (!DRIVE_IsValid(drive))
750 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
751 return 0;
754 *(WORD *)dataptr = 0;
755 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
756 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
757 strncpy(dataptr + 0x11, "FAT16 ", 8);
758 return 1;
762 static int INT21_SetDiskSerialNumber( CONTEXT *context )
764 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
765 int drive = DOS_GET_DRIVE( BL_reg(context) );
767 if (!DRIVE_IsValid(drive))
769 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
770 return 0;
773 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
774 return 1;
778 /* microsoft's programmers should be shot for using CP/M style int21
779 calls in Windows for Workgroup's winfile.exe */
781 static int INT21_FindFirstFCB( CONTEXT *context )
783 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
784 FINDFILE_FCB *pFCB;
785 LPCSTR root, cwd;
786 int drive;
788 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
789 else pFCB = (FINDFILE_FCB *)fcb;
790 drive = DOS_GET_DRIVE( pFCB->drive );
791 if (!DRIVE_IsValid( drive )) return 0;
792 root = DRIVE_GetRoot( drive );
793 cwd = DRIVE_GetUnixCwd( drive );
794 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
795 strlen(root)+strlen(cwd)+2 );
796 if (!pFCB->unixPath) return 0;
797 strcpy( pFCB->unixPath, root );
798 strcat( pFCB->unixPath, "/" );
799 strcat( pFCB->unixPath, cwd );
800 pFCB->count = 0;
801 return 1;
805 static int INT21_FindNextFCB( CONTEXT *context )
807 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
808 FINDFILE_FCB *pFCB;
809 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA(context);
810 WIN32_FIND_DATA32A entry;
811 BYTE attr;
812 int count;
814 if (*fcb == 0xff) /* extended FCB ? */
816 attr = fcb[6];
817 pFCB = (FINDFILE_FCB *)(fcb + 7);
819 else
821 attr = 0;
822 pFCB = (FINDFILE_FCB *)fcb;
825 if (!pFCB->unixPath) return 0;
826 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
827 DOS_GET_DRIVE( pFCB->drive ), attr,
828 pFCB->count, &entry )))
830 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
831 pFCB->unixPath = NULL;
832 return 0;
834 pFCB->count += count;
836 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
837 *(BYTE *)pResult = 0xff;
838 (BYTE *)pResult +=6; /* leave reserved field behind */
839 *(BYTE *)pResult = entry.dwFileAttributes;
840 ((BYTE *)pResult)++;
842 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
843 ((BYTE *)pResult)++;
844 pResult->fileattr = entry.dwFileAttributes;
845 pResult->cluster = 0; /* what else? */
846 pResult->filesize = entry.nFileSizeLow;
847 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
848 FileTimeToDosDateTime( &entry.ftLastWriteTime,
849 &pResult->filedate, &pResult->filetime );
851 /* Convert file name to FCB format */
853 memset( pResult->filename, ' ', sizeof(pResult->filename) );
854 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
855 else if (!strcmp( entry.cAlternateFileName, ".." ))
856 pResult->filename[0] = pResult->filename[1] = '.';
857 else
859 char *p = strrchr( entry.cAlternateFileName, '.' );
860 if (p && p[1] && (p != entry.cAlternateFileName))
862 memcpy( pResult->filename, entry.cAlternateFileName,
863 MIN( (p - entry.cAlternateFileName), 8 ) );
864 memcpy( pResult->filename + 8, p + 1, MIN( strlen(p), 3 ) );
866 else
867 memcpy( pResult->filename, entry.cAlternateFileName,
868 MIN( strlen(entry.cAlternateFileName), 8 ) );
870 return 1;
874 static void DeleteFileFCB( CONTEXT *context )
876 FIXME(int21, "(%p): stub\n", context);
879 static void RenameFileFCB( CONTEXT *context )
881 FIXME(int21, "(%p): stub\n", context);
886 static void fLock( CONTEXT * context )
889 switch ( AX_reg(context) & 0xff )
891 case 0x00: /* LOCK */
892 TRACE(int21,"lock handle %d offset %ld length %ld\n",
893 BX_reg(context),
894 MAKELONG(DX_reg(context),CX_reg(context)),
895 MAKELONG(DI_reg(context),SI_reg(context))) ;
896 if (!LockFile(HFILE16_TO_HFILE32(BX_reg(context)),
897 MAKELONG(DX_reg(context),CX_reg(context)), 0,
898 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
899 AX_reg(context) = DOS_ExtendedError;
900 SET_CFLAG(context);
902 break;
904 case 0x01: /* UNLOCK */
905 TRACE(int21,"unlock handle %d offset %ld length %ld\n",
906 BX_reg(context),
907 MAKELONG(DX_reg(context),CX_reg(context)),
908 MAKELONG(DI_reg(context),SI_reg(context))) ;
909 if (!UnlockFile(HFILE16_TO_HFILE32(BX_reg(context)),
910 MAKELONG(DX_reg(context),CX_reg(context)), 0,
911 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
912 AX_reg(context) = DOS_ExtendedError;
913 SET_CFLAG(context);
915 return;
916 default:
917 AX_reg(context) = 0x0001;
918 SET_CFLAG(context);
919 return;
923 static BOOL32
924 INT21_networkfunc (CONTEXT *context)
926 switch (AL_reg(context)) {
927 case 0x00: /* Get machine name. */
929 char *dst = CTX_SEG_OFF_TO_LIN (context,DS_reg(context),EDX_reg(context));
930 TRACE(int21, "getting machine name to %p\n", dst);
931 if (gethostname (dst, 15))
933 WARN(int21,"failed!\n");
934 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
935 return TRUE;
936 } else {
937 int len = strlen (dst);
938 while (len < 15)
939 dst[len++] = ' ';
940 dst[15] = 0;
941 CH_reg(context) = 1; /* Valid */
942 CL_reg(context) = 1; /* NETbios number??? */
943 TRACE(int21, "returning %s\n", debugstr_an (dst, 16));
944 return FALSE;
948 default:
949 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
950 return TRUE;
954 static void INT21_SetCurrentPSP(WORD psp)
956 #ifdef MZ_SUPPORTED
957 TDB *pTask = hModule ? NULL : (TDB *)GlobalLock16( GetCurrentTask() );
958 NE_MODULE *pModule = (hModule || pTask) ? NE_GetPtr( hModule ? hModule : pTask->hModule ) : NULL;
960 GlobalUnlock16( GetCurrentTask() );
961 if (pModule->lpDosTask)
962 pModule->lpDosTask->psp_seg = psp;
963 else
964 #endif
965 ERR(int21, "Cannot change PSP for non-DOS task!\n");
968 static WORD INT21_GetCurrentPSP()
970 #ifdef MZ_SUPPORTED
971 TDB *pTask = hModule ? NULL : (TDB *)GlobalLock16( GetCurrentTask() );
972 NE_MODULE *pModule = (hModule || pTask) ? NE_GetPtr( hModule ? hModule : pTask->hModule ) : NULL;
974 GlobalUnlock16( GetCurrentTask() );
975 if (pModule->lpDosTask)
976 return pModule->lpDosTask->psp_seg;
977 else
978 #endif
979 return GetCurrentPDB();
983 SEGPTR INT21_GetListOfLists()
985 static DOS_LISTOFLISTS *LOL;
986 static SEGPTR seg_LOL;
989 Output of DOS 6.22:
991 0133:0020 6A 13-33 01 CC 00 33 01 59 00 j.3...3.Y.
992 0133:0030 70 00 00 00 72 02 00 02-6D 00 33 01 00 00 2E 05 p...r...m.3.....
993 0133:0040 00 00 FC 04 00 00 03 08-92 21 11 E0 04 80 C6 0D .........!......
994 0133:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..NUL ......
995 0133:0060 00 4B BA C1 06 14 00 00-00 03 01 00 04 70 CE FF .K...........p..
996 0133:0070 FF 00 00 00 00 00 00 00-00 01 00 00 0D 05 00 00 ................
997 0133:0080 00 FF FF 00 00 00 00 FE-00 00 F8 03 FF 9F 70 02 ..............p.
998 0133:0090 D0 44 C8 FD D4 44 C8 FD-D4 44 C8 FD D0 44 C8 FD .D...D...D...D..
999 0133:00A0 D0 44 C8 FD D0 44 .D...D
1001 if (!LOL) {
1002 LOL = SEGPTR_ALLOC(sizeof(DOS_LISTOFLISTS));
1004 LOL->CX_Int21_5e01 = 0x0;
1005 LOL->LRU_count_FCB_cache = 0x0;
1006 LOL->LRU_count_FCB_open = 0x0;
1007 LOL->OEM_func_handler = -1; /* not available */
1008 LOL->INT21_offset = 0x0;
1009 LOL->sharing_retry_count = sharing_retries; /* default value: 3 */
1010 LOL->sharing_retry_delay = sharing_pause; /* default value: 1 */
1011 LOL->ptr_disk_buf = 0x0;
1012 LOL->offs_unread_CON = 0x0;
1013 LOL->seg_first_MCB = 0x0;
1014 LOL->ptr_first_DPB = 0x0;
1015 LOL->ptr_first_SysFileTable = 0x0;
1016 LOL->ptr_clock_dev_hdr = 0x0;
1017 LOL->ptr_CON_dev_hdr = 0x0;
1018 LOL->max_byte_per_sec = 512;
1019 LOL->ptr_disk_buf_info = 0x0;
1020 LOL->ptr_array_CDS = 0x0;
1021 LOL->ptr_sys_FCB = 0x0;
1022 LOL->nr_protect_FCB = 0x0;
1023 LOL->nr_block_dev = 0x0;
1024 LOL->nr_avail_drive_letters = 26; /* A - Z */
1025 LOL->nr_drives_JOINed = 0x0;
1026 LOL->ptr_spec_prg_names = 0x0;
1027 LOL->ptr_SETVER_prg_list = 0x0; /* no SETVER list */
1028 LOL->DOS_HIGH_A20_func_offs = 0x0;
1029 LOL->PSP_last_exec = 0x0;
1030 LOL->BUFFERS_val = 99; /* maximum: 99 */
1031 LOL->BUFFERS_nr_lookahead = 8; /* maximum: 8 */
1032 LOL->boot_drive = 3; /* C: */
1033 LOL->flag_DWORD_moves = 0x01; /* i386+ */
1034 LOL->size_extended_mem = 0xf000; /* very high value */
1036 if (!seg_LOL) seg_LOL = SEGPTR_GET(LOL);
1037 return seg_LOL+(WORD)&((DOS_LISTOFLISTS*)0)->ptr_first_DPB;
1040 /***********************************************************************
1041 * DOS3Call (KERNEL.102)
1043 void WINAPI DOS3Call( CONTEXT *context )
1045 BOOL32 bSetDOSExtendedError = FALSE;
1048 TRACE(int21, "AX=%04x BX=%04x CX=%04x DX=%04x "
1049 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1050 AX_reg(context), BX_reg(context), CX_reg(context), DX_reg(context),
1051 SI_reg(context), DI_reg(context),
1052 (WORD)DS_reg(context), (WORD)ES_reg(context),
1053 EFL_reg(context) );
1056 if (AH_reg(context) == 0x59) /* Get extended error info */
1058 TRACE(int21, "GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1059 DOS_ExtendedError, DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus);
1060 AX_reg(context) = DOS_ExtendedError;
1061 BH_reg(context) = DOS_ErrorClass;
1062 BL_reg(context) = DOS_ErrorAction;
1063 CH_reg(context) = DOS_ErrorLocus;
1064 return;
1067 if (AH_reg(context) == 0x0C) /* Flush buffer and read standard input */
1069 TRACE(int21, "FLUSH BUFFER AND READ STANDARD INPUT\n");
1070 /* no flush here yet */
1071 AH_reg(context) = AL_reg(context);
1074 DOS_ERROR( 0, 0, 0, 0 );
1075 RESET_CFLAG(context); /* Not sure if this is a good idea */
1077 switch(AH_reg(context))
1079 case 0x00: /* TERMINATE PROGRAM */
1080 TRACE(int21,"TERMINATE PROGRAM\n");
1081 ExitProcess( 0 );
1082 break;
1084 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1085 case 0x03: /* READ CHARACTER FROM STDAUX */
1086 case 0x04: /* WRITE CHARACTER TO STDAUX */
1087 case 0x05: /* WRITE CHARACTER TO PRINTER */
1088 case 0x0b: /* GET STDIN STATUS */
1089 case 0x0f: /* OPEN FILE USING FCB */
1090 case 0x10: /* CLOSE FILE USING FCB */
1091 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1092 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1093 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1094 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1095 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1096 case 0x23: /* GET FILE SIZE FOR FCB */
1097 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1098 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1099 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1100 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1101 case 0x54: /* GET VERIFY FLAG */
1102 INT_BARF( context, 0x21 );
1103 break;
1105 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1106 TRACE(int21, "Write Character to Standard Output\n");
1107 CONSOLE_Write(DL_reg(context), 0, 0, 0);
1108 break;
1110 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1111 TRACE(int21, "Direct Console Input/Output\n");
1112 CONSOLE_Write(DL_reg(context), 0, 0, 0);
1113 break;
1115 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1116 TRACE(int21,"DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1117 AL_reg(context) = CONSOLE_GetCharacter();
1118 break;
1120 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1121 TRACE(int21,"CHARACTER INPUT WITHOUT ECHO\n");
1122 AL_reg(context) = CONSOLE_GetCharacter();
1123 break;
1125 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1126 TRACE(int21,"WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1127 DS_reg(context),DX_reg(context) );
1129 LPSTR data = CTX_SEG_OFF_TO_LIN(context,DS_reg(context),EDX_reg(context));
1130 LONG length = strchr(data,'$')-data;
1131 _hwrite16( 1, data, length);
1132 AL_reg(context) = '$'; /* yes, '$' (0x24) gets returned in AL */
1134 break;
1136 case 0x0a: /* BUFFERED INPUT */
1138 char *buffer = ((char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1139 EDX_reg(context) ));
1140 int res;
1142 TRACE(int21,"BUFFERED INPUT (size=%d)\n",buffer[0]);
1143 if (buffer[1])
1144 TRACE(int21,"Handle old chars in buffer!\n");
1145 res=_lread16( 0, buffer+2,buffer[0]);
1146 buffer[1]=res;
1147 if(buffer[res+1] == '\n')
1148 buffer[res+1] = '\r';
1149 break;
1152 case 0x2e: /* SET VERIFY FLAG */
1153 TRACE(int21,"SET VERIFY FLAG ignored\n");
1154 /* we cannot change the behaviour anyway, so just ignore it */
1155 break;
1157 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1158 case 0x1d:
1159 case 0x1e:
1160 case 0x20:
1161 case 0x6b: /* NULL FUNCTION */
1162 AL_reg(context) = 0;
1163 break;
1165 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1166 fLock(context);
1167 break;
1169 case 0x0d: /* DISK BUFFER FLUSH */
1170 TRACE(int21,"DISK BUFFER FLUSH ignored\n");
1171 RESET_CFLAG(context); /* dos 6+ only */
1172 break;
1174 case 0x0e: /* SELECT DEFAULT DRIVE */
1175 TRACE(int21,"SELECT DEFAULT DRIVE %d\n", DL_reg(context));
1176 DRIVE_SetCurrentDrive( DL_reg(context) );
1177 AL_reg(context) = MAX_DOS_DRIVES;
1178 break;
1180 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1181 TRACE(int21,"FIND FIRST MATCHING FILE USING FCB %p\n",
1182 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1183 if (!INT21_FindFirstFCB(context))
1185 AL_reg(context) = 0xff;
1186 break;
1188 /* else fall through */
1190 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1191 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
1192 break;
1194 case 0x13: /* DELETE FILE USING FCB */
1195 DeleteFileFCB(context);
1196 break;
1198 case 0x17: /* RENAME FILE USING FCB */
1199 RenameFileFCB(context);
1200 break;
1202 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1203 AL_reg(context) = DRIVE_GetCurrentDrive();
1204 break;
1206 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1208 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1209 pTask->dta = PTR_SEG_OFF_TO_SEGPTR(DS_reg(context),DX_reg(context));
1210 TRACE(int21, "Set DTA: %08lx\n", pTask->dta);
1212 break;
1214 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1215 DL_reg(context) = 0;
1216 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1217 break;
1219 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1220 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1221 break;
1223 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1224 GetDrivePB(context, DRIVE_GetCurrentDrive());
1225 break;
1227 case 0x25: /* SET INTERRUPT VECTOR */
1228 INT_CtxSetHandler( context, AL_reg(context),
1229 (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1230 DX_reg(context)));
1231 break;
1233 case 0x29: /* PARSE FILENAME INTO FCB */
1234 INT21_ParseFileNameIntoFCB(context);
1235 break;
1237 case 0x2a: /* GET SYSTEM DATE */
1238 INT21_GetSystemDate(context);
1239 break;
1241 case 0x2b: /* SET SYSTEM DATE */
1242 FIXME(int21, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1243 DL_reg(context), DH_reg(context), CX_reg(context) );
1244 AL_reg(context) = 0; /* Let's pretend we succeeded */
1245 break;
1247 case 0x2c: /* GET SYSTEM TIME */
1248 INT21_GetSystemTime(context);
1249 break;
1251 case 0x2d: /* SET SYSTEM TIME */
1252 FIXME(int21, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1253 CH_reg(context), CL_reg(context),
1254 DH_reg(context), DL_reg(context) );
1255 AL_reg(context) = 0; /* Let's pretend we succeeded */
1256 break;
1258 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1259 TRACE(int21,"GET DISK TRANSFER AREA ADDRESS\n");
1261 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1262 ES_reg(context) = SELECTOROF( pTask->dta );
1263 BX_reg(context) = OFFSETOF( pTask->dta );
1265 break;
1267 case 0x30: /* GET DOS VERSION */
1268 TRACE(int21,"GET DOS VERSION %s requested\n",
1269 (AL_reg(context) == 0x00)?"OEM number":"version flag");
1270 AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
1271 (HIWORD(GetVersion16()) << 8);
1272 #if 0
1273 AH_reg(context) = 0x7;
1274 AL_reg(context) = 0xA;
1275 #endif
1277 BX_reg(context) = 0x00FF; /* 0x123456 is Wine's serial # */
1278 CX_reg(context) = 0x0000;
1279 break;
1281 case 0x31: /* TERMINATE AND STAY RESIDENT */
1282 FIXME(int21,"TERMINATE AND STAY RESIDENT stub\n");
1283 break;
1285 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1286 TRACE(int21,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1287 INT21_DriveName( DL_reg(context)));
1288 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
1289 break;
1291 case 0x33: /* MULTIPLEXED */
1292 switch (AL_reg(context))
1294 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1295 TRACE(int21,"GET CURRENT EXTENDED BREAK STATE stub\n");
1296 DL_reg(context) = 0;
1297 break;
1299 case 0x01: /* SET EXTENDED BREAK STATE */
1300 TRACE(int21,"SET CURRENT EXTENDED BREAK STATE stub\n");
1301 break;
1303 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1304 TRACE(int21,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE stub\n");
1305 DL_reg(context) = 0;
1306 break;
1308 case 0x05: /* GET BOOT DRIVE */
1309 TRACE(int21,"GET BOOT DRIVE\n");
1310 DL_reg(context) = 3;
1311 /* c: is Wine's bootdrive (a: is 1)*/
1312 break;
1314 case 0x06: /* GET TRUE VERSION NUMBER */
1315 TRACE(int21,"GET TRUE VERSION NUMBER\n");
1316 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1317 (HIWORD(GetVersion16() << 8));
1318 DX_reg(context) = 0x00;
1319 break;
1321 default:
1322 INT_BARF( context, 0x21 );
1323 break;
1325 break;
1327 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1328 TRACE(int21,"GET ADDRESS OF INDOS FLAG\n");
1329 if (!heap) INT21_CreateHeap();
1330 ES_reg(context) = DosHeapHandle;
1331 BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1332 break;
1334 case 0x35: /* GET INTERRUPT VECTOR */
1335 TRACE(int21,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1337 FARPROC16 addr = INT_CtxGetHandler( context, AL_reg(context) );
1338 ES_reg(context) = SELECTOROF(addr);
1339 BX_reg(context) = OFFSETOF(addr);
1341 break;
1343 case 0x36: /* GET FREE DISK SPACE */
1344 TRACE(int21,"GET FREE DISK SPACE FOR DRIVE %s\n",
1345 INT21_DriveName( DL_reg(context)));
1346 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1347 break;
1349 case 0x37:
1351 unsigned char switchchar='/';
1352 switch (AL_reg(context))
1354 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1355 TRACE(int21,"SWITCHAR - GET SWITCH CHARACTER\n");
1356 AL_reg(context) = 0x00; /* success*/
1357 DL_reg(context) = switchchar;
1358 break;
1359 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1360 TRACE(int21,"SWITCHAR - SET SWITCH CHARACTER\n");
1361 switchchar = DL_reg(context);
1362 AL_reg(context) = 0x00; /* success*/
1363 break;
1364 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1365 INT_BARF( context, 0x21 );
1366 break;
1368 break;
1371 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1372 TRACE(int21,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1373 AL_reg(context));
1374 AX_reg(context) = 0x02; /* no country support available */
1375 SET_CFLAG(context);
1376 break;
1378 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1379 TRACE(int21,"MKDIR %s\n",
1380 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1381 bSetDOSExtendedError = (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1382 EDX_reg(context) ), NULL));
1383 break;
1385 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1386 TRACE(int21,"RMDIR %s\n",
1387 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1388 bSetDOSExtendedError = (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1389 EDX_reg(context) )));
1390 break;
1392 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1393 TRACE(int21,"CHDIR %s\n",
1394 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1395 bSetDOSExtendedError = !INT21_ChangeDir(context);
1396 break;
1398 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1399 TRACE(int21,"CREAT flag 0x%02x %s\n",CX_reg(context),
1400 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1401 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1402 EDX_reg(context) ), CX_reg(context) );
1403 bSetDOSExtendedError = (AX_reg(context) == (WORD)HFILE_ERROR16);
1404 break;
1406 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1407 TRACE(int21,"OPEN mode 0x%02x %s\n",AL_reg(context),
1408 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1409 OpenExistingFile(context);
1410 break;
1412 case 0x3e: /* "CLOSE" - CLOSE FILE */
1413 TRACE(int21,"CLOSE handle %d\n",BX_reg(context));
1414 if ((BX_reg(context)<5)||
1415 /* FIXME: need to improve on those handle conversion macros */
1416 (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_INPUT_HANDLE)))||
1417 (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_OUTPUT_HANDLE)))||
1418 (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_ERROR_HANDLE)))) {
1419 /* hack to make sure stdio isn't closed */
1420 FIXME(int21, "stdio handle closed, need proper conversion\n");
1421 DOS_ExtendedError = 0x06;
1422 bSetDOSExtendedError = TRUE;
1423 } else
1424 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1425 break;
1427 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1428 TRACE(int21,"READ from %d to %04lX:%04X for %d byte\n",BX_reg(context),
1429 DS_reg(context),DX_reg(context),CX_reg(context) );
1431 LONG result;
1432 if (ISV86(context))
1433 result = _hread16( BX_reg(context),
1434 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1435 EDX_reg(context) ),
1436 CX_reg(context) );
1437 else
1438 result = WIN16_hread( BX_reg(context),
1439 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1440 EDX_reg(context) ),
1441 CX_reg(context) );
1442 if (result == -1) bSetDOSExtendedError = TRUE;
1443 else AX_reg(context) = (WORD)result;
1445 break;
1447 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1448 TRACE(int21,"WRITE from %04lX:%04X to handle %d for %d byte\n",
1449 DS_reg(context),DX_reg(context),BX_reg(context),CX_reg(context) );
1451 LONG result = _hwrite16( BX_reg(context),
1452 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1453 EDX_reg(context) ),
1454 CX_reg(context) );
1455 if (result == -1) bSetDOSExtendedError = TRUE;
1456 else AX_reg(context) = (WORD)result;
1458 break;
1460 case 0x41: /* "UNLINK" - DELETE FILE */
1461 TRACE(int21,"UNLINK%s\n",
1462 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1463 bSetDOSExtendedError = (!DeleteFile32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1464 EDX_reg(context) )));
1465 break;
1467 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1468 TRACE(int21,"LSEEK handle %d offset %ld from %s\n",
1469 BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)),
1470 (AL_reg(context)==0)?"start of file":(AL_reg(context)==1)?
1471 "current file position":"end of file");
1473 LONG status = _llseek16( BX_reg(context),
1474 MAKELONG(DX_reg(context),CX_reg(context)),
1475 AL_reg(context) );
1476 if (status == -1) bSetDOSExtendedError = TRUE;
1477 else
1479 AX_reg(context) = LOWORD(status);
1480 DX_reg(context) = HIWORD(status);
1483 break;
1485 case 0x43: /* FILE ATTRIBUTES */
1486 switch (AL_reg(context))
1488 case 0x00:
1489 TRACE(int21,"GET FILE ATTRIBUTES for %s\n",
1490 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1491 AX_reg(context) = (WORD)GetFileAttributes32A(
1492 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1493 EDX_reg(context)));
1494 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1495 else CX_reg(context) = AX_reg(context);
1496 break;
1498 case 0x01:
1499 TRACE(int21,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context),
1500 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1501 bSetDOSExtendedError =
1502 (!SetFileAttributes32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1503 EDX_reg(context)),
1504 CX_reg(context) ));
1505 break;
1506 case 0x02:
1507 TRACE(int21,"GET COMPRESSED FILE SIZE for %s stub\n",
1508 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1510 break;
1512 case 0x44: /* IOCTL */
1513 switch (AL_reg(context))
1515 case 0x00:
1516 ioctlGetDeviceInfo(context);
1517 break;
1519 case 0x01:
1520 break;
1521 case 0x02:{
1522 FILE_OBJECT *file;
1523 file = FILE_GetFile(HFILE16_TO_HFILE32(BX_reg(context)));
1524 if (!strcasecmp(file->unix_name, "SCSIMGR$"))
1525 ASPI_DOS_HandleInt(context);
1526 FILE_ReleaseFile( file );
1527 break;
1529 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1530 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));*/
1531 int drive = DOS_GET_DRIVE(BL_reg(context));
1533 FIXME(int21,"program tried to write to block device control channel of drive %d:\n",drive);
1534 /* for (i=0;i<CX_reg(context);i++)
1535 fprintf(stdnimp,"%02x ",dataptr[i]);
1536 fprintf(stdnimp,"\n");*/
1537 AX_reg(context)=CX_reg(context);
1538 break;
1540 case 0x08: /* Check if drive is removable. */
1541 TRACE(int21,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1542 INT21_DriveName( BL_reg(context)));
1543 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1545 case DRIVE_CANNOTDETERMINE:
1546 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1547 AX_reg(context) = ER_InvalidDrive;
1548 SET_CFLAG(context);
1549 break;
1550 case DRIVE_REMOVABLE:
1551 AX_reg(context) = 0; /* removable */
1552 break;
1553 default:
1554 AX_reg(context) = 1; /* not removable */
1555 break;
1557 break;
1559 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1560 TRACE(int21,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1561 INT21_DriveName( BL_reg(context)));
1562 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1564 case DRIVE_CANNOTDETERMINE:
1565 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1566 AX_reg(context) = ER_InvalidDrive;
1567 SET_CFLAG(context);
1568 break;
1569 case DRIVE_REMOTE:
1570 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1571 break;
1572 default:
1573 DX_reg(context) = 0; /* FIXME: use driver attr here */
1574 break;
1576 break;
1578 case 0x0a: /* check if handle (BX) is remote */
1579 TRACE(int21,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context));
1580 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1581 * not set on close
1583 DX_reg(context) = 0;
1584 break;
1586 case 0x0b: /* SET SHARING RETRY COUNT */
1587 TRACE(int21,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1588 CX_reg(context), DX_reg(context));
1589 if (!CX_reg(context))
1591 AX_reg(context) = 1;
1592 SET_CFLAG(context);
1593 break;
1595 sharing_pause = CX_reg(context);
1596 if (!DX_reg(context))
1597 sharing_retries = DX_reg(context);
1598 RESET_CFLAG(context);
1599 break;
1601 case 0x0d:
1602 TRACE(int21,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1603 INT21_DriveName( BL_reg(context)));
1604 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1605 break;
1607 case 0x0e: /* get logical drive mapping */
1608 TRACE(int21,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1609 INT21_DriveName( BL_reg(context)));
1610 AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1611 break;
1613 case 0x0F: /* Set logical drive mapping */
1615 int drive;
1616 TRACE(int21,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1617 INT21_DriveName( BL_reg(context)));
1618 drive = DOS_GET_DRIVE ( BL_reg(context) );
1619 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1621 SET_CFLAG(context);
1622 AX_reg(context) = 0x000F; /* invalid drive */
1624 break;
1627 case 0xe0: /* Sun PC-NFS API */
1628 /* not installed */
1629 break;
1631 default:
1632 INT_BARF( context, 0x21 );
1633 break;
1635 break;
1637 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1638 TRACE(int21,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context));
1639 bSetDOSExtendedError = ((AX_reg(context) = HFILE32_TO_HFILE16(FILE_Dup(HFILE16_TO_HFILE32(BX_reg(context))))) == (WORD)HFILE_ERROR16);
1640 break;
1642 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1643 TRACE(int21,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1644 BX_reg(context),CX_reg(context));
1645 bSetDOSExtendedError = (FILE_Dup2( HFILE16_TO_HFILE32(BX_reg(context)), HFILE16_TO_HFILE32(CX_reg(context)) ) == HFILE_ERROR32);
1646 break;
1648 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1649 TRACE(int21,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1650 INT21_DriveName( DL_reg(context)));
1651 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1652 break;
1654 case 0x48: /* ALLOCATE MEMORY */
1655 TRACE(int21,"ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context));
1657 LPVOID *mem;
1658 if (ISV86(context))
1660 mem= DOSMEM_GetBlock(0,(DWORD)BX_reg(context)<<4,NULL);
1661 if (mem)
1662 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1664 else
1666 mem = (LPVOID)GlobalDOSAlloc(BX_reg(context)<<4);
1667 if (mem)
1668 AX_reg(context) = (DWORD)mem&0xffff;
1670 if (!mem)
1672 SET_CFLAG(context);
1673 AX_reg(context) = 0x0008; /* insufficient memory */
1674 BX_reg(context) = DOSMEM_Available(0)>>4;
1677 break;
1679 case 0x49: /* FREE MEMORY */
1680 TRACE(int21,"FREE MEMORY segment %04lX\n", ES_reg(context));
1682 BOOL32 ret;
1683 if (ISV86(context))
1684 ret= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4));
1685 else
1687 ret = !GlobalDOSFree(ES_reg(context));
1688 /* If we don't reset ES_reg, we will fail in the relay code */
1689 ES_reg(context)=ret;
1691 if (!ret)
1693 TRACE(int21,"FREE MEMORY failed\n");
1694 SET_CFLAG(context);
1695 AX_reg(context) = 0x0009; /* memory block address invalid */
1698 break;
1700 case 0x4a: /* RESIZE MEMORY BLOCK */
1701 TRACE(int21,"RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context), BX_reg(context));
1702 if (!ISV86(context))
1703 FIXME(int21,"RESIZE MEMORY probably insufficent implementation. Expect crash soon\n");
1705 LPVOID *mem = DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4),
1706 BX_reg(context)<<4,NULL);
1707 if (mem)
1708 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1709 else {
1710 SET_CFLAG(context);
1711 AX_reg(context) = 0x0008; /* insufficient memory */
1712 BX_reg(context) = DOSMEM_Available(0)>>4; /* not quite right */
1715 break;
1717 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1718 TRACE(int21,"EXEC %s\n",
1719 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context) ));
1720 AX_reg(context) = WinExec16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1721 EDX_reg(context) ),
1722 SW_NORMAL );
1723 if (AX_reg(context) < 32) SET_CFLAG(context);
1724 break;
1726 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1727 TRACE(int21,"EXIT with return code %d\n",AL_reg(context));
1728 ExitProcess( AL_reg(context) );
1729 break;
1731 case 0x4d: /* GET RETURN CODE */
1732 TRACE(int21,"GET RETURN CODE (ERRORLEVEL)\n");
1733 AX_reg(context) = 0; /* normal exit */
1734 break;
1736 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1737 TRACE(int21,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
1738 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1739 if (!INT21_FindFirst(context)) break;
1740 /* fall through */
1742 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1743 TRACE(int21,"FINDNEXT\n");
1744 if (!INT21_FindNext(context))
1746 DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk );
1747 AX_reg(context) = ER_NoMoreFiles;
1748 SET_CFLAG(context);
1750 else AX_reg(context) = 0; /* OK */
1751 break;
1752 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1753 TRACE(int21, "SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1754 INT21_SetCurrentPSP(BX_reg(context));
1755 break;
1756 case 0x51: /* GET PSP ADDRESS */
1757 TRACE(int21,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1758 /* FIXME: should we return the original DOS PSP upon */
1759 /* Windows startup ? */
1760 BX_reg(context) = INT21_GetCurrentPSP();
1761 break;
1762 case 0x62: /* GET PSP ADDRESS */
1763 TRACE(int21,"GET CURRENT PSP ADDRESS\n");
1764 /* FIXME: should we return the original DOS PSP upon */
1765 /* Windows startup ? */
1766 BX_reg(context) = INT21_GetCurrentPSP();
1767 break;
1769 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1770 TRACE(int21,"SYSVARS - GET LIST OF LISTS\n");
1772 SEGPTR lol;
1773 lol = INT21_GetListOfLists();
1774 ES_reg(context) = HIWORD(lol);
1775 BX_reg(context) = LOWORD(lol);
1777 break;
1779 case 0x56: /* "RENAME" - RENAME FILE */
1780 TRACE(int21,"RENAME %s to %s\n",
1781 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1782 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context)));
1783 bSetDOSExtendedError =
1784 (!MoveFile32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1785 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context))));
1786 break;
1788 case 0x57: /* FILE DATE AND TIME */
1789 switch (AL_reg(context))
1791 case 0x00: /* Get */
1793 FILETIME filetime;
1794 TRACE(int21,"GET FILE DATE AND TIME for handle %d\n",
1795 BX_reg(context));
1796 if (!GetFileTime( HFILE16_TO_HFILE32(BX_reg(context)), NULL, NULL, &filetime ))
1797 bSetDOSExtendedError = TRUE;
1798 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1799 &CX_reg(context) );
1801 break;
1803 case 0x01: /* Set */
1805 FILETIME filetime;
1806 TRACE(int21,"SET FILE DATE AND TIME for handle %d\n",
1807 BX_reg(context));
1808 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1809 &filetime );
1810 bSetDOSExtendedError =
1811 (!SetFileTime( HFILE16_TO_HFILE32(BX_reg(context)),
1812 NULL, NULL, &filetime ));
1814 break;
1816 break;
1818 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1819 TRACE(int21,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1820 AL_reg(context));
1821 switch (AL_reg(context))
1823 case 0x00:
1824 AX_reg(context) = 1;
1825 break;
1826 case 0x02:
1827 AX_reg(context) = 0;
1828 break;
1829 case 0x01:
1830 case 0x03:
1831 break;
1833 RESET_CFLAG(context);
1834 break;
1836 case 0x5a: /* CREATE TEMPORARY FILE */
1837 TRACE(int21,"CREATE TEMPORARY FILE\n");
1838 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1839 break;
1841 case 0x5b: /* CREATE NEW FILE */
1842 TRACE(int21,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
1843 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1844 bSetDOSExtendedError = ((AX_reg(context) =
1845 HFILE32_TO_HFILE16(_lcreat_uniq( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)), 0 )))
1846 == (WORD)HFILE_ERROR16);
1847 break;
1849 case 0x5d: /* NETWORK */
1850 FIXME(int21,"Function 0x%04x not implemented.\n", AX_reg (context));
1851 /* Fix the following while you're at it. */
1852 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1853 bSetDOSExtendedError = TRUE;
1854 break;
1856 case 0x5e:
1857 bSetDOSExtendedError = INT21_networkfunc (context);
1858 break;
1860 case 0x5f: /* NETWORK */
1861 switch (AL_reg(context))
1863 case 0x07: /* ENABLE DRIVE */
1864 TRACE(int21,"ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1865 if (!DRIVE_Enable( DL_reg(context) ))
1867 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1868 bSetDOSExtendedError = TRUE;
1870 break;
1872 case 0x08: /* DISABLE DRIVE */
1873 TRACE(int21,"DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1874 if (!DRIVE_Disable( DL_reg(context) ))
1876 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1877 bSetDOSExtendedError = TRUE;
1879 break;
1881 default:
1882 /* network software not installed */
1883 TRACE(int21,"NETWORK function AX=%04x not implemented\n",AX_reg(context));
1884 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1885 bSetDOSExtendedError = TRUE;
1886 break;
1888 break;
1890 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1891 TRACE(int21,"TRUENAME %s\n",
1892 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),ESI_reg(context)));
1894 if (!GetFullPathName32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1895 ESI_reg(context)), 128,
1896 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
1897 EDI_reg(context)),NULL))
1898 bSetDOSExtendedError = TRUE;
1899 else AX_reg(context) = 0;
1901 break;
1903 case 0x61: /* UNUSED */
1904 case 0x63: /* misc. language support */
1905 switch (AL_reg(context)) {
1906 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1907 INT21_GetDBCSLeadTable(context);
1908 break;
1910 break;
1911 case 0x64: /* OS/2 DOS BOX */
1912 INT_BARF( context, 0x21 );
1913 SET_CFLAG(context);
1914 break;
1916 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1917 extern WORD WINE_LanguageId;
1918 BYTE *dataptr=CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context));
1919 TRACE(int21,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1920 BX_reg(context), DX_reg(context));
1921 switch (AL_reg(context)) {
1922 case 0x01:
1923 TRACE(int21,"\tget general internationalization info\n");
1924 dataptr[0] = 0x1;
1925 *(WORD*)(dataptr+1) = 41;
1926 *(WORD*)(dataptr+3) = WINE_LanguageId;
1927 *(WORD*)(dataptr+5) = CodePage;
1928 *(DWORD*)(dataptr+0x19) = 0; /* FIXME: ptr to case map routine */
1929 break;
1930 case 0x06:
1931 TRACE(int21,"\tget pointer to collating sequence table\n");
1932 dataptr[0] = 0x06;
1933 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
1934 CX_reg(context) = 258;/*FIXME: size of table?*/
1935 break;
1936 default:
1937 TRACE(int21,"\tunimplemented function %d\n",AL_reg(context));
1938 INT_BARF( context, 0x21 );
1939 SET_CFLAG(context);
1940 break;
1942 break;
1944 case 0x66: /* GLOBAL CODE PAGE TABLE */
1945 switch (AL_reg(context))
1947 case 0x01:
1948 TRACE(int21,"GET GLOBAL CODE PAGE TABLE\n");
1949 DX_reg(context) = BX_reg(context) = CodePage;
1950 RESET_CFLAG(context);
1951 break;
1952 case 0x02:
1953 TRACE(int21,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
1954 BX_reg(context),DX_reg(context));
1955 CodePage = BX_reg(context);
1956 RESET_CFLAG(context);
1957 break;
1959 break;
1961 case 0x67: /* SET HANDLE COUNT */
1962 TRACE(int21,"SET HANDLE COUNT to %d\n",BX_reg(context) );
1963 SetHandleCount16( BX_reg(context) );
1964 if (DOS_ExtendedError) bSetDOSExtendedError = TRUE;
1965 break;
1967 case 0x68: /* "FFLUSH" - COMMIT FILE */
1968 case 0x6a: /* COMMIT FILE */
1969 TRACE(int21,"FFLUSH/COMMIT handle %d\n",BX_reg(context));
1970 bSetDOSExtendedError = (!FlushFileBuffers( HFILE16_TO_HFILE32(BX_reg(context)) ));
1971 break;
1973 case 0x69: /* DISK SERIAL NUMBER */
1974 switch (AL_reg(context))
1976 case 0x00:
1977 TRACE(int21,"GET DISK SERIAL NUMBER for drive %s\n",
1978 INT21_DriveName(BL_reg(context)));
1979 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1980 else AX_reg(context) = 0;
1981 break;
1983 case 0x01:
1984 TRACE(int21,"SET DISK SERIAL NUMBER for drive %s\n",
1985 INT21_DriveName(BL_reg(context)));
1986 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1987 else AX_reg(context) = 1;
1988 break;
1990 break;
1992 case 0x6C: /* Extended Open/Create*/
1993 TRACE(int21,"EXTENDED OPEN/CREATE %s\n",
1994 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDI_reg(context)));
1995 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
1996 break;
1998 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1999 if ((GetVersion32()&0xC0000004)!=0xC0000004) {
2000 /* not supported on anything but Win95 */
2001 TRACE(int21,"LONG FILENAME functions supported only by win95\n");
2002 SET_CFLAG(context);
2003 AL_reg(context) = 0;
2004 } else
2005 switch(AL_reg(context))
2007 case 0x39: /* Create directory */
2008 TRACE(int21,"LONG FILENAME - MAKE DIRECTORY %s\n",
2009 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2010 bSetDOSExtendedError = (!CreateDirectory32A(
2011 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2012 EDX_reg(context) ), NULL));
2013 break;
2014 case 0x3a: /* Remove directory */
2015 TRACE(int21,"LONG FILENAME - REMOVE DIRECTORY %s\n",
2016 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2017 bSetDOSExtendedError = (!RemoveDirectory32A(
2018 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2019 EDX_reg(context) )));
2020 break;
2021 case 0x43: /* Get/Set file attributes */
2022 TRACE(int21,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2023 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2024 switch (BL_reg(context))
2026 case 0x00: /* Get file attributes */
2027 TRACE(int21,"\tretrieve attributes\n");
2028 CX_reg(context) = (WORD)GetFileAttributes32A(
2029 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2030 EDX_reg(context)));
2031 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
2032 break;
2033 case 0x01:
2034 TRACE(int21,"\tset attributes 0x%04x\n",CX_reg(context));
2035 bSetDOSExtendedError = (!SetFileAttributes32A(
2036 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2037 EDX_reg(context)),
2038 CX_reg(context) ) );
2039 break;
2040 default:
2041 FIXME(int21, "Unimplemented long file name function:\n");
2042 INT_BARF( context, 0x21 );
2043 SET_CFLAG(context);
2044 AL_reg(context) = 0;
2045 break;
2047 break;
2048 case 0x47: /* Get current directory */
2049 TRACE(int21," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2050 INT21_DriveName(DL_reg(context)));
2051 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
2052 break;
2054 case 0x4e: /* Find first file */
2055 TRACE(int21," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2056 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2057 /* FIXME: use attributes in CX */
2058 if ((AX_reg(context) = FindFirstFile16(
2059 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
2060 (WIN32_FIND_DATA32A *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2061 EDI_reg(context))))
2062 == INVALID_HANDLE_VALUE16)
2063 bSetDOSExtendedError = TRUE;
2064 break;
2065 case 0x4f: /* Find next file */
2066 TRACE(int21,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2067 BX_reg(context));
2068 if (!FindNextFile16( BX_reg(context),
2069 (WIN32_FIND_DATA32A *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2070 EDI_reg(context))))
2071 bSetDOSExtendedError = TRUE;
2072 break;
2073 case 0xa1: /* Find close */
2074 TRACE(int21,"LONG FILENAME - FINDCLOSE for handle %d\n",
2075 BX_reg(context));
2076 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
2077 break;
2078 case 0xa0:
2079 TRACE(int21,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2080 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2081 break;
2082 case 0x60:
2083 switch(CL_reg(context))
2085 case 0x01: /*Get short filename or path */
2086 if (!GetShortPathName32A
2087 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2088 ESI_reg(context)),
2089 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2090 EDI_reg(context)), 67))
2091 bSetDOSExtendedError = TRUE;
2092 else AX_reg(context) = 0;
2093 break;
2094 case 0x02: /*Get canonical long filename or path */
2095 if (!GetFullPathName32A
2096 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2097 ESI_reg(context)), 128,
2098 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2099 EDI_reg(context)),NULL))
2100 bSetDOSExtendedError = TRUE;
2101 else AX_reg(context) = 0;
2102 break;
2103 default:
2104 FIXME(int21, "Unimplemented long file name function:\n");
2105 INT_BARF( context, 0x21 );
2106 SET_CFLAG(context);
2107 AL_reg(context) = 0;
2108 break;
2110 break;
2111 case 0x6c: /* Create or open file */
2112 TRACE(int21,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
2113 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context)));
2114 /* translate Dos 7 action to Dos 6 action */
2115 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2116 break;
2118 case 0x3b: /* Change directory */
2119 TRACE(int21,"LONG FILENAME - CHANGE DIRECTORY %s\n",
2120 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
2121 if (!SetCurrentDirectory32A(CTX_SEG_OFF_TO_LIN(context,
2122 DS_reg(context),
2123 EDX_reg(context)
2126 SET_CFLAG(context);
2127 AL_reg(context) = DOS_ExtendedError;
2129 break;
2130 case 0x41: /* Delete file */
2131 TRACE(int21,"LONG FILENAME - DELETE FILE %s\n",
2132 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
2133 if (!DeleteFile32A(CTX_SEG_OFF_TO_LIN(context,
2134 DS_reg(context),
2135 EDX_reg(context))
2136 )) {
2137 SET_CFLAG(context);
2138 AL_reg(context) = DOS_ExtendedError;
2140 break;
2141 case 0x56: /* Move (rename) file */
2142 TRACE(int21,"LONG FILENAME - RENAME FILE %s to %s stub\n",
2143 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)),
2144 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context), EDI_reg(context)));
2145 default:
2146 FIXME(int21, "Unimplemented long file name function:\n");
2147 INT_BARF( context, 0x21 );
2148 SET_CFLAG(context);
2149 AL_reg(context) = 0;
2150 break;
2152 break;
2154 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2155 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2156 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2157 TRACE(int21,"windows95 function AX %04x\n",
2158 AX_reg(context));
2159 WARN(int21, " returning unimplemented\n");
2160 SET_CFLAG(context);
2161 AL_reg(context) = 0;
2162 break;
2164 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2165 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2166 break;
2168 default:
2169 INT_BARF( context, 0x21 );
2170 break;
2172 } /* END OF SWITCH */
2174 if( bSetDOSExtendedError ) /* set general error condition */
2176 AX_reg(context) = DOS_ExtendedError;
2177 SET_CFLAG(context);
2180 if ((EFL_reg(context) & 0x0001))
2181 TRACE(int21, "failed, errorcode 0x%02x class 0x%02x action 0x%02x locus %02x\n",
2182 DOS_ExtendedError, DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus);
2184 TRACE(int21, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2185 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2186 AX_reg(context), BX_reg(context), CX_reg(context),
2187 DX_reg(context), SI_reg(context), DI_reg(context),
2188 (WORD)DS_reg(context), (WORD)ES_reg(context),
2189 EFL_reg(context));
2192 FARPROC16 WINAPI GetSetKernelDOSProc(FARPROC16 DosProc)
2194 FIXME(int21, "(DosProc=0x%08x): stub\n", (UINT32)DosProc);
2195 return NULL;