Added a lost entry for last release.
[wine/multimedia.git] / msdos / int21.c
blob6acefe3c604c40a4b74db952f762d3319e9d63db
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 #if defined(__svr4__) || defined(_SCO_DS)
28 /* SVR4 DOESNT do locking the same way must implement properly */
29 #define LOCK_EX 0
30 #define LOCK_SH 1
31 #define LOCK_NB 8
32 #endif
35 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
37 /* Define the drive parameter block, as used by int21/1F
38 * and int21/32. This table can be accessed through the
39 * global 'dpb' pointer, which points into the local dos
40 * heap.
42 struct DPB
44 BYTE drive_num; /* 0=A, etc. */
45 BYTE unit_num; /* Drive's unit number (?) */
46 WORD sector_size; /* Sector size in bytes */
47 BYTE high_sector; /* Highest sector in a cluster */
48 BYTE shift; /* Shift count (?) */
49 WORD reserved; /* Number of reserved sectors at start */
50 BYTE num_FAT; /* Number of FATs */
51 WORD dir_entries; /* Number of root dir entries */
52 WORD first_data; /* First data sector */
53 WORD high_cluster; /* Highest cluster number */
54 WORD sectors_in_FAT; /* Number of sectors per FAT */
55 WORD start_dir; /* Starting sector of first dir */
56 DWORD driver_head; /* Address of device driver header (?) */
57 BYTE media_ID; /* Media ID */
58 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
59 DWORD next; /* Pointer to next DPB in list */
60 WORD free_search; /* Free cluster search start */
61 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
64 WORD CodePage = 437;
65 DWORD dpbsegptr;
67 struct DosHeap {
68 BYTE InDosFlag;
69 BYTE mediaID;
70 BYTE biosdate[8];
71 struct DPB dpb;
73 static struct DosHeap *heap;
74 static WORD DosHeapHandle;
76 WORD sharing_retries = 3; /* number of retries at sharing violation */
77 WORD sharing_pause = 1; /* pause between retries */
79 extern char TempDirectory[];
81 static BOOL32 INT21_CreateHeap(void)
83 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
85 WARN(int21, "Out of memory\n");
86 return FALSE;
88 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
89 dpbsegptr = PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
90 heap->InDosFlag = 0;
91 strcpy(heap->biosdate, "01/01/80");
92 return TRUE;
95 static BYTE *GetCurrentDTA( CONTEXT *context )
97 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
99 /* FIXME: This assumes DTA was set correctly! */
100 return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
101 OFFSETOF(pTask->dta) );
105 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
106 /* limited == TRUE is used with INT 0x21/0x440d */
108 if (drive > 1) {
109 setword(data, 512);
110 data[2] = 2;
111 setword(&data[3], 0);
112 data[5] = 2;
113 setword(&data[6], 240);
114 setword(&data[8], 64000);
115 data[0x0a] = 0xf8;
116 setword(&data[0x0b], 40);
117 setword(&data[0x0d], 56);
118 setword(&data[0x0f], 2);
119 setword(&data[0x11], 0);
120 if (!limited) {
121 setword(&data[0x1f], 800);
122 data[0x21] = 5;
123 setword(&data[0x22], 1);
125 } else { /* 1.44mb */
126 setword(data, 512);
127 data[2] = 2;
128 setword(&data[3], 0);
129 data[5] = 2;
130 setword(&data[6], 240);
131 setword(&data[8], 2880);
132 data[0x0a] = 0xf8;
133 setword(&data[0x0b], 6);
134 setword(&data[0x0d], 18);
135 setword(&data[0x0f], 2);
136 setword(&data[0x11], 0);
137 if (!limited) {
138 setword(&data[0x1f], 80);
139 data[0x21] = 7;
140 setword(&data[0x22], 2);
145 static int INT21_GetFreeDiskSpace( CONTEXT *context )
147 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
148 char root[] = "A:\\";
150 *root += DOS_GET_DRIVE( DL_reg(context) );
151 if (!GetDiskFreeSpace32A( root, &cluster_sectors, &sector_bytes,
152 &free_clusters, &total_clusters )) return 0;
153 AX_reg(context) = cluster_sectors;
154 BX_reg(context) = free_clusters;
155 CX_reg(context) = sector_bytes;
156 DX_reg(context) = total_clusters;
157 return 1;
160 static int INT21_GetDriveAllocInfo( CONTEXT *context )
162 if (!INT21_GetFreeDiskSpace( context )) return 0;
163 if (!heap && !INT21_CreateHeap()) return 0;
164 heap->mediaID = 0xf0;
165 DS_reg(context) = DosHeapHandle;
166 BX_reg(context) = (int)&heap->mediaID - (int)heap;
167 return 1;
170 static void GetDrivePB( CONTEXT *context, int drive )
172 if(!DRIVE_IsValid(drive))
174 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
175 AX_reg(context) = 0x00ff;
177 else if (heap || INT21_CreateHeap())
179 FIXME(int21, "GetDrivePB not fully implemented.\n");
181 /* FIXME: I have no idea what a lot of this information should
182 * say or whether it even really matters since we're not allowing
183 * direct block access. However, some programs seem to depend on
184 * getting at least _something_ back from here. The 'next' pointer
185 * does worry me, though. Should we have a complete table of
186 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
188 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
189 heap->dpb.sector_size = 512;
190 heap->dpb.high_sector = 1;
191 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
192 heap->dpb.reserved = 0;
193 heap->dpb.num_FAT = 1;
194 heap->dpb.dir_entries = 2;
195 heap->dpb.first_data = 2;
196 heap->dpb.high_cluster = 64000;
197 heap->dpb.sectors_in_FAT = 1;
198 heap->dpb.start_dir = 1;
199 heap->dpb.driver_head = 0;
200 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
201 heap->dpb.access_flag = 0;
202 heap->dpb.next = 0;
203 heap->dpb.free_search = 0;
204 heap->dpb.free_clusters = 0xFFFF; /* unknown */
206 AL_reg(context) = 0x00;
207 DS_reg(context) = SELECTOROF(dpbsegptr);
208 BX_reg(context) = OFFSETOF(dpbsegptr);
213 static void ioctlGetDeviceInfo( CONTEXT *context )
215 int curr_drive;
216 FILE_OBJECT *file;
218 TRACE(int21, "(%d)\n", BX_reg(context));
220 RESET_CFLAG(context);
222 /* DOS device ? */
223 if ((file = FILE_GetFile( HFILE16_TO_HFILE32(BX_reg(context)) )))
225 const DOS_DEVICE *dev = DOSFS_GetDevice( file->unix_name );
226 FILE_ReleaseFile( file );
227 if (dev)
229 DX_reg(context) = dev->flags;
230 return;
234 /* it seems to be a file */
235 curr_drive = DRIVE_GetCurrentDrive();
236 DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0);
237 /* no floppy */
238 /* bits 0-5 are current drive
239 * bit 6 - file has NOT been written..FIXME: correct?
240 * bit 8 - generate int24 if no diskspace on write/ read past end of file
241 * bit 11 - media not removable
242 * bit 14 - don't set file date/time on closing
243 * bit 15 - file is remote
247 static BOOL32 ioctlGenericBlkDevReq( CONTEXT *context )
249 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
250 int drive = DOS_GET_DRIVE( BL_reg(context) );
252 if (!DRIVE_IsValid(drive))
254 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
255 return TRUE;
258 if (CH_reg(context) != 0x08)
260 INT_BARF( context, 0x21 );
261 return FALSE;
264 switch (CL_reg(context))
266 case 0x4a: /* lock logical volume */
267 TRACE(int21,"lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
268 break;
270 case 0x60: /* get device parameters */
271 /* used by w4wgrp's winfile */
272 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
273 dataptr[0] = 0x04;
274 dataptr[6] = 0; /* media type */
275 if (drive > 1)
277 dataptr[1] = 0x05; /* fixed disk */
278 setword(&dataptr[2], 0x01); /* non removable */
279 setword(&dataptr[4], 0x300); /* # of cylinders */
281 else
283 dataptr[1] = 0x07; /* block dev, floppy */
284 setword(&dataptr[2], 0x02); /* removable */
285 setword(&dataptr[4], 80); /* # of cylinders */
287 CreateBPB(drive, &dataptr[7], TRUE);
288 RESET_CFLAG(context);
289 break;
291 case 0x66:/* get disk serial number */
293 char label[12],fsname[9],path[4];
294 DWORD serial;
296 strcpy(path,"x:\\");path[0]=drive+'A';
297 GetVolumeInformation32A(
298 path,label,12,&serial,NULL,NULL,fsname,9
300 *(WORD*)dataptr = 0;
301 memcpy(dataptr+2,&serial,4);
302 memcpy(dataptr+6,label ,11);
303 memcpy(dataptr+17,fsname,8);
305 break;
307 case 0x6a:
308 TRACE(int21,"logical volume %d unlocked.\n",drive);
309 break;
311 case 0x6f:
312 memset(dataptr+1, '\0', dataptr[0]-1);
313 dataptr[1] = dataptr[0];
314 dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
315 dataptr[3] = 0xFF; /* no physical drive */
316 break;
318 default:
319 INT_BARF( context, 0x21 );
321 return FALSE;
324 static void INT21_GetSystemDate( CONTEXT *context )
326 SYSTEMTIME systime;
327 GetLocalTime( &systime );
328 CX_reg(context) = systime.wYear;
329 DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
330 AX_reg(context) = systime.wDayOfWeek;
333 static void INT21_GetSystemTime( CONTEXT *context )
335 SYSTEMTIME systime;
336 GetLocalTime( &systime );
337 CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
338 DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
341 /* Many calls translate a drive argument like this:
342 drive number (00h = default, 01h = A:, etc)
344 static char drivestring[]="default";
346 char *INT21_DriveName(int drive)
349 if(drive >0)
351 drivestring[0]= (unsigned char)drive + '@';
352 drivestring[1]=':';
353 drivestring[2]=0;
355 return drivestring;
357 static BOOL32 INT21_CreateFile( CONTEXT *context )
359 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
360 DX_reg(context) ), CX_reg(context) );
361 return (AX_reg(context) == (WORD)HFILE_ERROR16);
365 static void OpenExistingFile( CONTEXT *context )
367 AX_reg(context) = _lopen16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)),
368 AL_reg(context) );
369 if (AX_reg(context) == (WORD)HFILE_ERROR16)
371 AX_reg(context) = DOS_ExtendedError;
372 SET_CFLAG(context);
374 #if 0
376 int handle;
377 int mode;
378 int lock;
380 switch (AX_reg(context) & 0x0070)
382 case 0x00: /* compatability mode */
383 case 0x40: /* DENYNONE */
384 lock = -1;
385 break;
387 case 0x30: /* DENYREAD */
388 TRACE(int21, "(%s): DENYREAD changed to DENYALL\n",
389 (char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
390 case 0x10: /* DENYALL */
391 lock = LOCK_EX;
392 break;
394 case 0x20: /* DENYWRITE */
395 lock = LOCK_SH;
396 break;
398 default:
399 lock = -1;
402 if (lock != -1)
405 int result,retries=sharing_retries;
407 #if defined(__svr4__) || defined(_SCO_DS)
408 ERR(int21, "Should call flock and needs porting to lockf\n");
409 result = 0;
410 retries = 0;
411 #else
412 result = flock(handle, lock | LOCK_NB);
413 #endif
414 if ( retries && (!result) )
416 int i;
417 for(i=0;i<32768*((int)sharing_pause);i++)
418 result++; /* stop the optimizer */
419 for(i=0;i<32768*((int)sharing_pause);i++)
420 result--;
423 while( (!result) && (!(retries--)) );
425 if(result)
427 errno_to_doserr();
428 AX_reg(context) = DOS_ExtendedError;
429 close(handle);
430 SET_CFLAG(context);
431 return;
436 Error (0,0,0);
437 AX_reg(context) = handle;
438 RESET_CFLAG(context);
440 #endif
443 static void CloseFile( CONTEXT *context )
445 if ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0)
447 AX_reg(context) = DOS_ExtendedError;
448 SET_CFLAG(context);
452 static BOOL32 INT21_ExtendedOpenCreateFile(CONTEXT *context )
454 BOOL32 bExtendedError = FALSE;
455 BYTE action = DL_reg(context);
457 /* Shuffle arguments to call OpenExistingFile */
458 AL_reg(context) = BL_reg(context);
459 DX_reg(context) = SI_reg(context);
460 /* BX,CX and DX should be preserved */
461 OpenExistingFile(context);
463 if ((EFL_reg(context) & 0x0001) == 0) /* File exists */
465 UINT16 uReturnCX = 0;
467 /* Now decide what do do */
469 if ((action & 0x07) == 0)
471 BX_reg(context) = AX_reg(context);
472 CloseFile(context);
473 AX_reg(context) = 0x0050; /*File exists*/
474 SET_CFLAG(context);
475 WARN(int21, "extended open/create: failed because file exists \n");
477 else if ((action & 0x07) == 2)
479 /* Truncate it, but first check if opened for write */
480 if ((BL_reg(context) & 0x0007)== 0)
482 BX_reg(context) = AX_reg(context);
483 CloseFile(context);
484 WARN(int21, "extended open/create: failed, trunc on ro file\n");
485 AX_reg(context) = 0x000C; /*Access code invalid*/
486 SET_CFLAG(context);
488 else
490 /* Shuffle arguments to call CloseFile while
491 * preserving BX and DX */
493 TRACE(int21, "extended open/create: Closing before truncate\n");
494 BX_reg(context) = AX_reg(context);
495 CloseFile(context);
496 if (EFL_reg(context) & 0x0001)
498 WARN(int21, "extended open/create: close before trunc failed\n");
499 AX_reg(context) = 0x0019; /*Seek Error*/
500 CX_reg(context) = 0;
501 SET_CFLAG(context);
503 /* Shuffle arguments to call CreateFile */
505 TRACE(int21, "extended open/create: Truncating\n");
506 AL_reg(context) = BL_reg(context);
507 /* CX is still the same */
508 DX_reg(context) = SI_reg(context);
509 bExtendedError = INT21_CreateFile(context);
511 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
513 WARN(int21, "extended open/create: trunc failed\n");
514 return bExtendedError;
516 uReturnCX = 0x3;
519 else uReturnCX = 0x1;
521 CX_reg(context) = uReturnCX;
523 else /* file does not exist */
525 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
526 if ((action & 0xF0)== 0)
528 CX_reg(context) = 0;
529 SET_CFLAG(context);
530 WARN(int21, "extended open/create: failed, file dosen't exist\n");
532 else
534 /* Shuffle arguments to call CreateFile */
535 TRACE(int21, "extended open/create: Creating\n");
536 AL_reg(context) = BL_reg(context);
537 /* CX should still be the same */
538 DX_reg(context) = SI_reg(context);
539 bExtendedError = INT21_CreateFile(context);
540 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
542 WARN(int21, "extended open/create: create failed\n");
543 return bExtendedError;
545 CX_reg(context) = 2;
549 return bExtendedError;
553 static BOOL32 INT21_ChangeDir( CONTEXT *context )
555 int drive;
556 char *dirname = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context));
558 TRACE(int21,"changedir %s\n", dirname);
559 if (dirname[0] && (dirname[1] == ':'))
561 drive = toupper(dirname[0]) - 'A';
562 dirname += 2;
564 else drive = DRIVE_GetCurrentDrive();
565 return DRIVE_Chdir( drive, dirname );
569 static int INT21_FindFirst( CONTEXT *context )
571 char *p;
572 const char *path;
573 DOS_FULL_NAME full_name;
574 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
576 path = (const char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
577 dta->unixPath = NULL;
578 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
580 AX_reg(context) = DOS_ExtendedError;
581 SET_CFLAG(context);
582 return 0;
584 dta->unixPath = HEAP_strdupA( GetProcessHeap(), 0, full_name.long_name );
585 p = strrchr( dta->unixPath, '/' );
586 *p = '\0';
588 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
589 * (doesn't matter as it is set below anyway)
591 if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
593 HeapFree( GetProcessHeap(), 0, dta->unixPath );
594 dta->unixPath = NULL;
595 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
596 AX_reg(context) = ER_FileNotFound;
597 SET_CFLAG(context);
598 return 0;
600 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
601 : DRIVE_GetCurrentDrive();
602 dta->count = 0;
603 dta->search_attr = CL_reg(context);
604 return 1;
608 static int INT21_FindNext( CONTEXT *context )
610 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
611 WIN32_FIND_DATA32A entry;
612 int count;
614 if (!dta->unixPath) return 0;
615 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
616 dta->search_attr, dta->count, &entry )))
618 HeapFree( GetProcessHeap(), 0, dta->unixPath );
619 dta->unixPath = NULL;
620 return 0;
622 if ((int)dta->count + count > 0xffff)
624 WARN(int21, "Too many directory entries in %s\n", dta->unixPath );
625 HeapFree( GetProcessHeap(), 0, dta->unixPath );
626 dta->unixPath = NULL;
627 return 0;
629 dta->count += count;
630 dta->fileattr = entry.dwFileAttributes;
631 dta->filesize = entry.nFileSizeLow;
632 FileTimeToDosDateTime( &entry.ftLastWriteTime,
633 &dta->filedate, &dta->filetime );
634 strcpy( dta->filename, entry.cAlternateFileName );
635 if (!memchr(dta->mask,'?',11)) {
636 /* wildcardless search, release resources in case no findnext will
637 * be issued, and as a workaround in case file creation messes up
638 * findnext, as sometimes happens with pkunzip */
639 HeapFree( GetProcessHeap(), 0, dta->unixPath );
640 dta->unixPath = NULL;
642 return 1;
646 static BOOL32 INT21_CreateTempFile( CONTEXT *context )
648 static int counter = 0;
649 char *name = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context) );
650 char *p = name + strlen(name);
652 /* despite what Ralf Brown says, some programs seem to call without
653 * ending backslash (DOS accepts that, so we accept it too) */
654 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
656 for (;;)
658 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
659 counter = (counter + 1) % 1000;
661 if ((AX_reg(context) = HFILE32_TO_HFILE16(_lcreat_uniq( name, 0 ))) != (WORD)HFILE_ERROR16)
663 TRACE(int21, "created %s\n", name );
664 return TRUE;
666 if (DOS_ExtendedError != ER_FileExists) return FALSE;
671 static BOOL32 INT21_GetCurrentDirectory( CONTEXT *context )
673 int drive = DOS_GET_DRIVE( DL_reg(context) );
674 char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), SI_reg(context) );
676 if (!DRIVE_IsValid(drive))
678 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
679 return FALSE;
681 lstrcpyn32A( ptr, DRIVE_GetDosCwd(drive), 64 );
682 AX_reg(context) = 0x0100; /* success return code */
683 return TRUE;
687 static int INT21_GetDiskSerialNumber( CONTEXT *context )
689 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
690 int drive = DOS_GET_DRIVE( BL_reg(context) );
692 if (!DRIVE_IsValid(drive))
694 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
695 return 0;
698 *(WORD *)dataptr = 0;
699 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
700 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
701 strncpy(dataptr + 0x11, "FAT16 ", 8);
702 return 1;
706 static int INT21_SetDiskSerialNumber( CONTEXT *context )
708 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
709 int drive = DOS_GET_DRIVE( BL_reg(context) );
711 if (!DRIVE_IsValid(drive))
713 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
714 return 0;
717 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
718 return 1;
722 /* microsoft's programmers should be shot for using CP/M style int21
723 calls in Windows for Workgroup's winfile.exe */
725 static int INT21_FindFirstFCB( CONTEXT *context )
727 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
728 FINDFILE_FCB *pFCB;
729 LPCSTR root, cwd;
730 int drive;
732 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
733 else pFCB = (FINDFILE_FCB *)fcb;
734 drive = DOS_GET_DRIVE( pFCB->drive );
735 if (!DRIVE_IsValid( drive )) return 0;
736 root = DRIVE_GetRoot( drive );
737 cwd = DRIVE_GetUnixCwd( drive );
738 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
739 strlen(root)+strlen(cwd)+2 );
740 if (!pFCB->unixPath) return 0;
741 strcpy( pFCB->unixPath, root );
742 strcat( pFCB->unixPath, "/" );
743 strcat( pFCB->unixPath, cwd );
744 pFCB->count = 0;
745 return 1;
749 static int INT21_FindNextFCB( CONTEXT *context )
751 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
752 FINDFILE_FCB *pFCB;
753 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA(context);
754 WIN32_FIND_DATA32A entry;
755 BYTE attr;
756 int count;
758 if (*fcb == 0xff) /* extended FCB ? */
760 attr = fcb[6];
761 pFCB = (FINDFILE_FCB *)(fcb + 7);
763 else
765 attr = 0;
766 pFCB = (FINDFILE_FCB *)fcb;
769 if (!pFCB->unixPath) return 0;
770 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
771 DOS_GET_DRIVE( pFCB->drive ), attr,
772 pFCB->count, &entry )))
774 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
775 pFCB->unixPath = NULL;
776 return 0;
778 pFCB->count += count;
780 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
781 *(BYTE *)pResult = 0xff;
782 (BYTE *)pResult +=6; /* leave reserved field behind */
783 *(BYTE *)pResult = entry.dwFileAttributes;
784 ((BYTE *)pResult)++;
786 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
787 ((BYTE *)pResult)++;
788 pResult->fileattr = entry.dwFileAttributes;
789 pResult->cluster = 0; /* what else? */
790 pResult->filesize = entry.nFileSizeLow;
791 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
792 FileTimeToDosDateTime( &entry.ftLastWriteTime,
793 &pResult->filedate, &pResult->filetime );
795 /* Convert file name to FCB format */
797 memset( pResult->filename, ' ', sizeof(pResult->filename) );
798 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
799 else if (!strcmp( entry.cAlternateFileName, ".." ))
800 pResult->filename[0] = pResult->filename[1] = '.';
801 else
803 char *p = strrchr( entry.cAlternateFileName, '.' );
804 if (p && p[1] && (p != entry.cAlternateFileName))
806 memcpy( pResult->filename, entry.cAlternateFileName,
807 MIN( (p - entry.cAlternateFileName), 8 ) );
808 memcpy( pResult->filename + 8, p + 1, MIN( strlen(p), 3 ) );
810 else
811 memcpy( pResult->filename, entry.cAlternateFileName,
812 MIN( strlen(entry.cAlternateFileName), 8 ) );
814 return 1;
818 static void DeleteFileFCB( CONTEXT *context )
820 FIXME(int21, "(%p): stub\n", context);
823 static void RenameFileFCB( CONTEXT *context )
825 FIXME(int21, "(%p): stub\n", context);
830 static void fLock( CONTEXT * context )
833 switch ( AX_reg(context) & 0xff )
835 case 0x00: /* LOCK */
836 TRACE(int21,"lock handle %d offset %ld length %ld\n",
837 BX_reg(context),
838 MAKELONG(DX_reg(context),CX_reg(context)),
839 MAKELONG(DI_reg(context),SI_reg(context))) ;
840 if (!LockFile(HFILE16_TO_HFILE32(BX_reg(context)),
841 MAKELONG(DX_reg(context),CX_reg(context)), 0,
842 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
843 AX_reg(context) = DOS_ExtendedError;
844 SET_CFLAG(context);
846 break;
848 case 0x01: /* UNLOCK */
849 TRACE(int21,"unlock handle %d offset %ld length %ld\n",
850 BX_reg(context),
851 MAKELONG(DX_reg(context),CX_reg(context)),
852 MAKELONG(DI_reg(context),SI_reg(context))) ;
853 if (!UnlockFile(HFILE16_TO_HFILE32(BX_reg(context)),
854 MAKELONG(DX_reg(context),CX_reg(context)), 0,
855 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
856 AX_reg(context) = DOS_ExtendedError;
857 SET_CFLAG(context);
859 return;
860 default:
861 AX_reg(context) = 0x0001;
862 SET_CFLAG(context);
863 return;
867 static BOOL32
868 INT21_networkfunc (CONTEXT *context)
870 switch (AL_reg(context)) {
871 case 0x00: /* Get machine name. */
873 char *dst = CTX_SEG_OFF_TO_LIN (context,DS_reg(context),DX_reg(context));
874 TRACE(int21, "getting machine name to %p\n", dst);
875 if (gethostname (dst, 15))
877 WARN(int21,"failed!\n");
878 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
879 return TRUE;
880 } else {
881 int len = strlen (dst);
882 while (len < 15)
883 dst[len++] = ' ';
884 dst[15] = 0;
885 CH_reg(context) = 1; /* Valid */
886 CL_reg(context) = 1; /* NETbios number??? */
887 TRACE(int21, "returning %s\n", debugstr_an (dst, 16));
888 return FALSE;
892 default:
893 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
894 return TRUE;
898 static void INT21_SetCurrentPSP(WORD psp)
900 #ifdef MZ_SUPPORTED
901 TDB *pTask = hModule ? NULL : (TDB *)GlobalLock16( GetCurrentTask() );
902 NE_MODULE *pModule = (hModule || pTask) ? NE_GetPtr( hModule ? hModule : pTask->hModule ) : NULL;
904 GlobalUnlock16( GetCurrentTask() );
905 if (pModule->lpDosTask)
906 pModule->lpDosTask->psp_seg = psp;
907 else
908 #endif
909 ERR(int21, "Cannot change PSP for non-DOS task!\n");
912 static WORD INT21_GetCurrentPSP()
914 #ifdef MZ_SUPPORTED
915 TDB *pTask = hModule ? NULL : (TDB *)GlobalLock16( GetCurrentTask() );
916 NE_MODULE *pModule = (hModule || pTask) ? NE_GetPtr( hModule ? hModule : pTask->hModule ) : NULL;
918 GlobalUnlock16( GetCurrentTask() );
919 if (pModule->lpDosTask)
920 return pModule->lpDosTask->psp_seg;
921 else
922 #endif
923 return GetCurrentPDB();
927 SEGPTR INT21_GetListOfLists()
929 static DOS_LISTOFLISTS *LOL;
930 static SEGPTR seg_LOL;
933 Output of DOS 6.22:
935 0133:0020 6A 13-33 01 CC 00 33 01 59 00 j.3...3.Y.
936 0133:0030 70 00 00 00 72 02 00 02-6D 00 33 01 00 00 2E 05 p...r...m.3.....
937 0133:0040 00 00 FC 04 00 00 03 08-92 21 11 E0 04 80 C6 0D .........!......
938 0133:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..NUL ......
939 0133:0060 00 4B BA C1 06 14 00 00-00 03 01 00 04 70 CE FF .K...........p..
940 0133:0070 FF 00 00 00 00 00 00 00-00 01 00 00 0D 05 00 00 ................
941 0133:0080 00 FF FF 00 00 00 00 FE-00 00 F8 03 FF 9F 70 02 ..............p.
942 0133:0090 D0 44 C8 FD D4 44 C8 FD-D4 44 C8 FD D0 44 C8 FD .D...D...D...D..
943 0133:00A0 D0 44 C8 FD D0 44 .D...D
945 if (!LOL) {
946 LOL = SEGPTR_ALLOC(sizeof(DOS_LISTOFLISTS));
948 LOL->CX_Int21_5e01 = 0x0;
949 LOL->LRU_count_FCB_cache = 0x0;
950 LOL->LRU_count_FCB_open = 0x0;
951 LOL->OEM_func_handler = -1; /* not available */
952 LOL->INT21_offset = 0x0;
953 LOL->sharing_retry_count = sharing_retries; /* default value: 3 */
954 LOL->sharing_retry_delay = sharing_pause; /* default value: 1 */
955 LOL->ptr_disk_buf = 0x0;
956 LOL->offs_unread_CON = 0x0;
957 LOL->seg_first_MCB = 0x0;
958 LOL->ptr_first_DPB = 0x0;
959 LOL->ptr_first_SysFileTable = 0x0;
960 LOL->ptr_clock_dev_hdr = 0x0;
961 LOL->ptr_CON_dev_hdr = 0x0;
962 LOL->max_byte_per_sec = 512;
963 LOL->ptr_disk_buf_info = 0x0;
964 LOL->ptr_array_CDS = 0x0;
965 LOL->ptr_sys_FCB = 0x0;
966 LOL->nr_protect_FCB = 0x0;
967 LOL->nr_block_dev = 0x0;
968 LOL->nr_avail_drive_letters = 26; /* A - Z */
969 LOL->nr_drives_JOINed = 0x0;
970 LOL->ptr_spec_prg_names = 0x0;
971 LOL->ptr_SETVER_prg_list = 0x0; /* no SETVER list */
972 LOL->DOS_HIGH_A20_func_offs = 0x0;
973 LOL->PSP_last_exec = 0x0;
974 LOL->BUFFERS_val = 99; /* maximum: 99 */
975 LOL->BUFFERS_nr_lookahead = 8; /* maximum: 8 */
976 LOL->boot_drive = 3; /* C: */
977 LOL->flag_DWORD_moves = 0x01; /* i386+ */
978 LOL->size_extended_mem = 0xf000; /* very high value */
980 if (!seg_LOL) seg_LOL = SEGPTR_GET(LOL);
981 return seg_LOL+(WORD)&((DOS_LISTOFLISTS*)0)->ptr_first_DPB;
984 /***********************************************************************
985 * DOS3Call (KERNEL.102)
987 void WINAPI DOS3Call( CONTEXT *context )
989 BOOL32 bSetDOSExtendedError = FALSE;
991 #if 0
992 TRACE(int21, "AX=%04x BX=%04x CX=%04x DX=%04x "
993 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
994 AX_reg(context), BX_reg(context), CX_reg(context), DX_reg(context),
995 SI_reg(context), DI_reg(context),
996 (WORD)DS_reg(context), (WORD)ES_reg(context),
997 EFL_reg(context) );
998 #endif
1000 if (AH_reg(context) == 0x59) /* Get extended error info */
1002 TRACE(int21, "GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1003 DOS_ExtendedError, DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus);
1004 AX_reg(context) = DOS_ExtendedError;
1005 BH_reg(context) = DOS_ErrorClass;
1006 BL_reg(context) = DOS_ErrorAction;
1007 CH_reg(context) = DOS_ErrorLocus;
1008 return;
1011 if (AH_reg(context) == 0x0C) /* Flush buffer and read standard input */
1013 TRACE(int21, "FLUSH BUFFER AND READ STANDARD INPUT\n");
1014 /* no flush here yet */
1015 AH_reg(context) = AL_reg(context);
1018 DOS_ERROR( 0, 0, 0, 0 );
1019 RESET_CFLAG(context); /* Not sure if this is a good idea */
1021 switch(AH_reg(context))
1023 case 0x00: /* TERMINATE PROGRAM */
1024 TRACE(int21,"TERMINATE PROGRAM\n");
1025 ExitProcess( 0 );
1026 break;
1028 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1029 case 0x03: /* READ CHARACTER FROM STDAUX */
1030 case 0x04: /* WRITE CHARACTER TO STDAUX */
1031 case 0x05: /* WRITE CHARACTER TO PRINTER */
1032 case 0x0b: /* GET STDIN STATUS */
1033 case 0x0f: /* OPEN FILE USING FCB */
1034 case 0x10: /* CLOSE FILE USING FCB */
1035 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1036 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1037 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1038 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1039 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1040 case 0x23: /* GET FILE SIZE FOR FCB */
1041 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1042 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1043 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1044 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1045 case 0x29: /* PARSE FILENAME INTO FCB */
1046 case 0x54: /* GET VERIFY FLAG */
1047 INT_BARF( context, 0x21 );
1048 break;
1050 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1051 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1052 _lwrite16( 1, &DL_reg(context), 1);
1053 break;
1055 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1056 TRACE(int21,"DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1057 _lread16( 0, &AL_reg(context), 1);
1058 break;
1060 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1061 TRACE(int21,"CHARACTER INPUT WITHOUT ECHO\n");
1062 _lread16( 0, &AL_reg(context), 1);
1063 break;
1065 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1066 TRACE(int21,"WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1067 DS_reg(context),DX_reg(context) );
1069 LPSTR data = CTX_SEG_OFF_TO_LIN(context,DS_reg(context),DX_reg(context));
1070 LONG length = strchr(data,'$')-data;
1071 _hwrite16( 1, data, length);
1073 break;
1075 case 0x0a: /* BUFFERED INPUT */
1077 char *buffer = ((char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1078 DX_reg(context) ));
1079 int res;
1081 TRACE(int21,"BUFFERED INPUT (size=%d)\n",buffer[0]);
1082 if (buffer[1])
1083 TRACE(int21,"Handle old chars in buffer!\n");
1084 res=_lread16( 0, buffer+2,buffer[0]);
1085 buffer[1]=res;
1086 if(buffer[res+1] == '\n')
1087 buffer[res+1] = '\r';
1088 break;
1091 case 0x2e: /* SET VERIFY FLAG */
1092 TRACE(int21,"SET VERIFY FLAG ignored\n");
1093 /* we cannot change the behaviour anyway, so just ignore it */
1094 break;
1096 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1097 case 0x1d:
1098 case 0x1e:
1099 case 0x20:
1100 case 0x6b: /* NULL FUNCTION */
1101 AL_reg(context) = 0;
1102 break;
1104 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1105 fLock(context);
1106 break;
1108 case 0x0d: /* DISK BUFFER FLUSH */
1109 TRACE(int21,"DISK BUFFER FLUSH ignored\n");
1110 RESET_CFLAG(context); /* dos 6+ only */
1111 break;
1113 case 0x0e: /* SELECT DEFAULT DRIVE */
1114 TRACE(int21,"SELECT DEFAULT DRIVE %d\n", DL_reg(context));
1115 DRIVE_SetCurrentDrive( DL_reg(context) );
1116 AL_reg(context) = MAX_DOS_DRIVES;
1117 break;
1119 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1120 TRACE(int21,"FIND FIRST MATCHING FILE USING FCB %p\n",
1121 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1122 if (!INT21_FindFirstFCB(context))
1124 AL_reg(context) = 0xff;
1125 break;
1127 /* else fall through */
1129 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1130 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
1131 break;
1133 case 0x13: /* DELETE FILE USING FCB */
1134 DeleteFileFCB(context);
1135 break;
1137 case 0x17: /* RENAME FILE USING FCB */
1138 RenameFileFCB(context);
1139 break;
1141 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1142 AL_reg(context) = DRIVE_GetCurrentDrive();
1143 break;
1145 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1147 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1148 pTask->dta = PTR_SEG_OFF_TO_SEGPTR(DS_reg(context),DX_reg(context));
1149 TRACE(int21, "Set DTA: %08lx\n", pTask->dta);
1151 break;
1153 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1154 DL_reg(context) = 0;
1155 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1156 break;
1158 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1159 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1160 break;
1162 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1163 GetDrivePB(context, DRIVE_GetCurrentDrive());
1164 break;
1166 case 0x25: /* SET INTERRUPT VECTOR */
1167 INT_CtxSetHandler( context, AL_reg(context),
1168 (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1169 DX_reg(context)));
1170 break;
1172 case 0x2a: /* GET SYSTEM DATE */
1173 INT21_GetSystemDate(context);
1174 break;
1176 case 0x2b: /* SET SYSTEM DATE */
1177 FIXME(int21, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1178 DL_reg(context), DH_reg(context), CX_reg(context) );
1179 AL_reg(context) = 0; /* Let's pretend we succeeded */
1180 break;
1182 case 0x2c: /* GET SYSTEM TIME */
1183 INT21_GetSystemTime(context);
1184 break;
1186 case 0x2d: /* SET SYSTEM TIME */
1187 FIXME(int21, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1188 CH_reg(context), CL_reg(context),
1189 DH_reg(context), DL_reg(context) );
1190 AL_reg(context) = 0; /* Let's pretend we succeeded */
1191 break;
1193 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1194 TRACE(int21,"GET DISK TRANSFER AREA ADDRESS\n");
1196 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1197 ES_reg(context) = SELECTOROF( pTask->dta );
1198 BX_reg(context) = OFFSETOF( pTask->dta );
1200 break;
1202 case 0x30: /* GET DOS VERSION */
1203 TRACE(int21,"GET DOS VERSION %s requested\n",
1204 (AL_reg(context) == 0x00)?"OEM number":"version flag");
1205 AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
1206 (HIWORD(GetVersion16()) << 8);
1207 #if 0
1208 AH_reg(context) = 0x7;
1209 AL_reg(context) = 0xA;
1210 #endif
1212 BX_reg(context) = 0x00FF; /* 0x123456 is Wine's serial # */
1213 CX_reg(context) = 0x0000;
1214 break;
1216 case 0x31: /* TERMINATE AND STAY RESIDENT */
1217 TRACE(int21,"TERMINATE AND STAY RESIDENT stub\n");
1218 INT_BARF( context, 0x21 );
1219 break;
1221 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1222 TRACE(int21,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1223 INT21_DriveName( DL_reg(context)));
1224 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
1225 break;
1227 case 0x33: /* MULTIPLEXED */
1228 switch (AL_reg(context))
1230 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1231 TRACE(int21,"GET CURRENT EXTENDED BREAK STATE stub\n");
1232 DL_reg(context) = 0;
1233 break;
1235 case 0x01: /* SET EXTENDED BREAK STATE */
1236 TRACE(int21,"SET CURRENT EXTENDED BREAK STATE stub\n");
1237 break;
1239 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1240 TRACE(int21,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE stub\n");
1241 DL_reg(context) = 0;
1242 break;
1244 case 0x05: /* GET BOOT DRIVE */
1245 TRACE(int21,"GET BOOT DRIVE\n");
1246 DL_reg(context) = 3;
1247 /* c: is Wine's bootdrive (a: is 1)*/
1248 break;
1250 case 0x06: /* GET TRUE VERSION NUMBER */
1251 TRACE(int21,"GET TRUE VERSION NUMBER\n");
1252 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1253 (HIWORD(GetVersion16() << 8));
1254 DX_reg(context) = 0x00;
1255 break;
1257 default:
1258 INT_BARF( context, 0x21 );
1259 break;
1261 break;
1263 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1264 TRACE(int21,"GET ADDRESS OF INDOS FLAG\n");
1265 if (!heap) INT21_CreateHeap();
1266 ES_reg(context) = DosHeapHandle;
1267 BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1268 break;
1270 case 0x35: /* GET INTERRUPT VECTOR */
1271 TRACE(int21,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1273 FARPROC16 addr = INT_CtxGetHandler( context, AL_reg(context) );
1274 ES_reg(context) = SELECTOROF(addr);
1275 BX_reg(context) = OFFSETOF(addr);
1277 break;
1279 case 0x36: /* GET FREE DISK SPACE */
1280 TRACE(int21,"GET FREE DISK SPACE FOR DRIVE %s\n",
1281 INT21_DriveName( DL_reg(context)));
1282 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1283 break;
1285 case 0x37:
1287 unsigned char switchchar='/';
1288 switch (AL_reg(context))
1290 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1291 TRACE(int21,"SWITCHAR - GET SWITCH CHARACTER\n");
1292 AL_reg(context) = 0x00; /* success*/
1293 DL_reg(context) = switchchar;
1294 break;
1295 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1296 TRACE(int21,"SWITCHAR - SET SWITCH CHARACTER\n");
1297 switchchar = DL_reg(context);
1298 AL_reg(context) = 0x00; /* success*/
1299 break;
1300 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1301 INT_BARF( context, 0x21 );
1302 break;
1304 break;
1307 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1308 TRACE(int21,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1309 AL_reg(context));
1310 AX_reg(context) = 0x02; /* no country support available */
1311 SET_CFLAG(context);
1312 break;
1314 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1315 TRACE(int21,"MKDIR %s\n",
1316 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1317 bSetDOSExtendedError = (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1318 DX_reg(context) ), NULL));
1319 break;
1321 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1322 TRACE(int21,"RMDIR %s\n",
1323 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1324 bSetDOSExtendedError = (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1325 DX_reg(context) )));
1326 break;
1328 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1329 TRACE(int21,"CHDIR %s\n",
1330 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1331 bSetDOSExtendedError = !INT21_ChangeDir(context);
1332 break;
1334 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1335 TRACE(int21,"CREAT flag 0x%02x %s\n",CX_reg(context),
1336 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1337 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1338 DX_reg(context) ), CX_reg(context) );
1339 bSetDOSExtendedError = (AX_reg(context) == (WORD)HFILE_ERROR16);
1340 break;
1342 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1343 TRACE(int21,"OPEN mode 0x%02x %s\n",AL_reg(context),
1344 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1345 OpenExistingFile(context);
1346 break;
1348 case 0x3e: /* "CLOSE" - CLOSE FILE */
1349 TRACE(int21,"CLOSE handle %d\n",BX_reg(context));
1350 if ((BX_reg(context)<5)||
1351 /* FIXME: need to improve on those handle conversion macros */
1352 (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_INPUT_HANDLE)))||
1353 (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_OUTPUT_HANDLE)))||
1354 (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_ERROR_HANDLE)))) {
1355 /* hack to make sure stdio isn't closed */
1356 FIXME(int21, "stdio handle closed, need proper conversion\n");
1357 DOS_ExtendedError = 0x06;
1358 bSetDOSExtendedError = TRUE;
1359 } else
1360 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1361 break;
1363 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1364 TRACE(int21,"READ from %d to %04lX:%04X for %d byte\n",BX_reg(context),
1365 DS_reg(context),DX_reg(context),CX_reg(context) );
1367 LONG result;
1368 if (ISV86(context))
1369 result = _hread16( BX_reg(context),
1370 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1371 DX_reg(context) ),
1372 CX_reg(context) );
1373 else
1374 result = WIN16_hread( BX_reg(context),
1375 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1376 DX_reg(context) ),
1377 CX_reg(context) );
1378 if (result == -1) bSetDOSExtendedError = TRUE;
1379 else AX_reg(context) = (WORD)result;
1381 break;
1383 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1384 TRACE(int21,"WRITE from %04lX:%04X to handle %d for %d byte\n",
1385 DS_reg(context),DX_reg(context),BX_reg(context),CX_reg(context) );
1387 LONG result = _hwrite16( BX_reg(context),
1388 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1389 DX_reg(context) ),
1390 CX_reg(context) );
1391 if (result == -1) bSetDOSExtendedError = TRUE;
1392 else AX_reg(context) = (WORD)result;
1394 break;
1396 case 0x41: /* "UNLINK" - DELETE FILE */
1397 TRACE(int21,"UNLINK%s\n",
1398 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1399 bSetDOSExtendedError = (!DeleteFile32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1400 DX_reg(context) )));
1401 break;
1403 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1404 TRACE(int21,"LSEEK handle %d offset %ld from %s\n",
1405 BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)),
1406 (AL_reg(context)==0)?"start of file":(AL_reg(context)==1)?
1407 "current file position":"end of file");
1409 LONG status = _llseek16( BX_reg(context),
1410 MAKELONG(DX_reg(context),CX_reg(context)),
1411 AL_reg(context) );
1412 if (status == -1) bSetDOSExtendedError = TRUE;
1413 else
1415 AX_reg(context) = LOWORD(status);
1416 DX_reg(context) = HIWORD(status);
1419 break;
1421 case 0x43: /* FILE ATTRIBUTES */
1422 switch (AL_reg(context))
1424 case 0x00:
1425 TRACE(int21,"GET FILE ATTRIBUTES for %s\n",
1426 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1427 AX_reg(context) = (WORD)GetFileAttributes32A(
1428 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1429 DX_reg(context)));
1430 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1431 else CX_reg(context) = AX_reg(context);
1432 break;
1434 case 0x01:
1435 TRACE(int21,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context),
1436 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1437 bSetDOSExtendedError =
1438 (!SetFileAttributes32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1439 DX_reg(context)),
1440 CX_reg(context) ));
1441 break;
1442 case 0x02:
1443 TRACE(int21,"GET COMPRESSED FILE SIZE for %s stub\n",
1444 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1446 break;
1448 case 0x44: /* IOCTL */
1449 switch (AL_reg(context))
1451 case 0x00:
1452 ioctlGetDeviceInfo(context);
1453 break;
1455 case 0x01:
1456 break;
1457 case 0x02:{
1458 FILE_OBJECT *file;
1459 file = FILE_GetFile(HFILE16_TO_HFILE32(BX_reg(context)));
1460 if (!strcasecmp(file->unix_name, "SCSIMGR$"))
1461 ASPI_DOS_HandleInt(context);
1462 FILE_ReleaseFile( file );
1463 break;
1465 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1466 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context));*/
1467 int drive = DOS_GET_DRIVE(BL_reg(context));
1469 FIXME(int21,"program tried to write to block device control channel of drive %d:\n",drive);
1470 /* for (i=0;i<CX_reg(context);i++)
1471 fprintf(stdnimp,"%02x ",dataptr[i]);
1472 fprintf(stdnimp,"\n");*/
1473 AX_reg(context)=CX_reg(context);
1474 break;
1476 case 0x08: /* Check if drive is removable. */
1477 TRACE(int21,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1478 INT21_DriveName( BL_reg(context)));
1479 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1481 case DRIVE_CANNOTDETERMINE:
1482 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1483 AX_reg(context) = ER_InvalidDrive;
1484 SET_CFLAG(context);
1485 break;
1486 case DRIVE_REMOVABLE:
1487 AX_reg(context) = 0; /* removable */
1488 break;
1489 default:
1490 AX_reg(context) = 1; /* not removable */
1491 break;
1493 break;
1495 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1496 TRACE(int21,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1497 INT21_DriveName( BL_reg(context)));
1498 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1500 case DRIVE_CANNOTDETERMINE:
1501 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1502 AX_reg(context) = ER_InvalidDrive;
1503 SET_CFLAG(context);
1504 break;
1505 case DRIVE_REMOTE:
1506 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1507 break;
1508 default:
1509 DX_reg(context) = 0; /* FIXME: use driver attr here */
1510 break;
1512 break;
1514 case 0x0a: /* check if handle (BX) is remote */
1515 TRACE(int21,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context));
1516 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1517 * not set on close
1519 DX_reg(context) = 0;
1520 break;
1522 case 0x0b: /* SET SHARING RETRY COUNT */
1523 TRACE(int21,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1524 CX_reg(context), DX_reg(context));
1525 if (!CX_reg(context))
1527 AX_reg(context) = 1;
1528 SET_CFLAG(context);
1529 break;
1531 sharing_pause = CX_reg(context);
1532 if (!DX_reg(context))
1533 sharing_retries = DX_reg(context);
1534 RESET_CFLAG(context);
1535 break;
1537 case 0x0d:
1538 TRACE(int21,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1539 INT21_DriveName( BL_reg(context)));
1540 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1541 break;
1543 case 0x0e: /* get logical drive mapping */
1544 TRACE(int21,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1545 INT21_DriveName( BL_reg(context)));
1546 AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1547 break;
1549 case 0x0F: /* Set logical drive mapping */
1551 int drive;
1552 TRACE(int21,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1553 INT21_DriveName( BL_reg(context)));
1554 drive = DOS_GET_DRIVE ( BL_reg(context) );
1555 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1557 SET_CFLAG(context);
1558 AX_reg(context) = 0x000F; /* invalid drive */
1560 break;
1563 case 0xe0: /* Sun PC-NFS API */
1564 /* not installed */
1565 break;
1567 default:
1568 INT_BARF( context, 0x21 );
1569 break;
1571 break;
1573 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1574 TRACE(int21,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context));
1575 bSetDOSExtendedError = ((AX_reg(context) = HFILE32_TO_HFILE16(FILE_Dup(HFILE16_TO_HFILE32(BX_reg(context))))) == (WORD)HFILE_ERROR16);
1576 break;
1578 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1579 TRACE(int21,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1580 BX_reg(context),CX_reg(context));
1581 bSetDOSExtendedError = (FILE_Dup2( HFILE16_TO_HFILE32(BX_reg(context)), HFILE16_TO_HFILE32(CX_reg(context)) ) == HFILE_ERROR32);
1582 break;
1584 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1585 TRACE(int21,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1586 INT21_DriveName( DL_reg(context)));
1587 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1588 break;
1590 case 0x48: /* ALLOCATE MEMORY */
1591 TRACE(int21,"ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context));
1593 LPVOID *mem;
1594 if (ISV86(context))
1596 mem= DOSMEM_GetBlock(0,(DWORD)BX_reg(context)<<4,NULL);
1597 if (mem)
1598 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1600 else
1602 mem = (LPVOID)GlobalDOSAlloc(BX_reg(context)<<4);
1603 if (mem)
1604 AX_reg(context) = (DWORD)mem&0xffff;
1606 if (!mem)
1608 SET_CFLAG(context);
1609 AX_reg(context) = 0x0008; /* insufficient memory */
1610 BX_reg(context) = DOSMEM_Available(0)>>4;
1613 break;
1615 case 0x49: /* FREE MEMORY */
1616 TRACE(int21,"FREE MEMORY segment %04lX\n", ES_reg(context));
1618 BOOL32 ret;
1619 if (ISV86(context))
1620 ret= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4));
1621 else
1623 ret = !GlobalDOSFree(ES_reg(context));
1624 /* If we don't reset ES_reg, we will fail in the relay code */
1625 ES_reg(context)=ret;
1627 if (!ret)
1629 TRACE(int21,"FREE MEMORY failed\n");
1630 SET_CFLAG(context);
1631 AX_reg(context) = 0x0009; /* memory block address invalid */
1634 break;
1636 case 0x4a: /* RESIZE MEMORY BLOCK */
1637 TRACE(int21,"RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context), BX_reg(context));
1638 if (!ISV86(context))
1639 FIXME(int21,"RESIZE MEMORY probably insufficent implementation. Expect crash soon\n");
1641 LPVOID *mem = DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4),
1642 BX_reg(context)<<4,NULL);
1643 if (mem)
1644 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1645 else {
1646 SET_CFLAG(context);
1647 AX_reg(context) = 0x0008; /* insufficient memory */
1648 BX_reg(context) = DOSMEM_Available(0)>>4; /* not quite right */
1651 break;
1653 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1654 TRACE(int21,"EXEC %s\n",
1655 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context) ));
1656 AX_reg(context) = WinExec16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1657 DX_reg(context) ),
1658 SW_NORMAL );
1659 if (AX_reg(context) < 32) SET_CFLAG(context);
1660 break;
1662 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1663 TRACE(int21,"EXIT with return code %d\n",AL_reg(context));
1664 ExitProcess( AL_reg(context) );
1665 break;
1667 case 0x4d: /* GET RETURN CODE */
1668 TRACE(int21,"GET RETURN CODE (ERRORLEVEL)\n");
1669 AX_reg(context) = 0; /* normal exit */
1670 break;
1672 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1673 TRACE(int21,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
1674 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1675 if (!INT21_FindFirst(context)) break;
1676 /* fall through */
1678 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1679 TRACE(int21,"FINDNEXT\n");
1680 if (!INT21_FindNext(context))
1682 DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk );
1683 AX_reg(context) = ER_NoMoreFiles;
1684 SET_CFLAG(context);
1686 else AX_reg(context) = 0; /* OK */
1687 break;
1688 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1689 TRACE(int21, "SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1690 INT21_SetCurrentPSP(BX_reg(context));
1691 break;
1692 case 0x51: /* GET PSP ADDRESS */
1693 TRACE(int21,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1694 /* FIXME: should we return the original DOS PSP upon */
1695 /* Windows startup ? */
1696 BX_reg(context) = INT21_GetCurrentPSP();
1697 break;
1698 case 0x62: /* GET PSP ADDRESS */
1699 TRACE(int21,"GET CURRENT PSP ADDRESS\n");
1700 /* FIXME: should we return the original DOS PSP upon */
1701 /* Windows startup ? */
1702 BX_reg(context) = INT21_GetCurrentPSP();
1703 break;
1705 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1706 TRACE(int21,"SYSVARS - GET LIST OF LISTS\n");
1708 SEGPTR lol;
1709 lol = INT21_GetListOfLists();
1710 ES_reg(context) = HIWORD(lol);
1711 BX_reg(context) = LOWORD(lol);
1713 break;
1715 case 0x56: /* "RENAME" - RENAME FILE */
1716 TRACE(int21,"RENAME %s to %s\n",
1717 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)),
1718 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),DI_reg(context)));
1719 bSetDOSExtendedError =
1720 (!MoveFile32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)),
1721 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),DI_reg(context))));
1722 break;
1724 case 0x57: /* FILE DATE AND TIME */
1725 switch (AL_reg(context))
1727 case 0x00: /* Get */
1729 FILETIME filetime;
1730 TRACE(int21,"GET FILE DATE AND TIME for handle %d\n",
1731 BX_reg(context));
1732 if (!GetFileTime( HFILE16_TO_HFILE32(BX_reg(context)), NULL, NULL, &filetime ))
1733 bSetDOSExtendedError = TRUE;
1734 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1735 &CX_reg(context) );
1737 break;
1739 case 0x01: /* Set */
1741 FILETIME filetime;
1742 TRACE(int21,"SET FILE DATE AND TIME for handle %d\n",
1743 BX_reg(context));
1744 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1745 &filetime );
1746 bSetDOSExtendedError =
1747 (!SetFileTime( BX_reg(context), NULL, NULL, &filetime ));
1749 break;
1751 break;
1753 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1754 TRACE(int21,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1755 AL_reg(context));
1756 switch (AL_reg(context))
1758 case 0x00:
1759 AX_reg(context) = 1;
1760 break;
1761 case 0x02:
1762 AX_reg(context) = 0;
1763 break;
1764 case 0x01:
1765 case 0x03:
1766 break;
1768 RESET_CFLAG(context);
1769 break;
1771 case 0x5a: /* CREATE TEMPORARY FILE */
1772 TRACE(int21,"CREATE TEMPORARY FILE\n");
1773 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1774 break;
1776 case 0x5b: /* CREATE NEW FILE */
1777 TRACE(int21,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
1778 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1779 bSetDOSExtendedError = ((AX_reg(context) =
1780 HFILE32_TO_HFILE16(_lcreat_uniq( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)), 0 )))
1781 == (WORD)HFILE_ERROR16);
1782 break;
1784 case 0x5d: /* NETWORK */
1785 FIXME(int21,"Function 0x%04x not implemented.\n", AX_reg (context));
1786 /* Fix the following while you're at it. */
1787 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1788 bSetDOSExtendedError = TRUE;
1789 break;
1791 case 0x5e:
1792 bSetDOSExtendedError = INT21_networkfunc (context);
1793 break;
1795 case 0x5f: /* NETWORK */
1796 switch (AL_reg(context))
1798 case 0x07: /* ENABLE DRIVE */
1799 TRACE(int21,"ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1800 if (!DRIVE_Enable( DL_reg(context) ))
1802 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1803 bSetDOSExtendedError = TRUE;
1805 break;
1807 case 0x08: /* DISABLE DRIVE */
1808 TRACE(int21,"DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1809 if (!DRIVE_Disable( DL_reg(context) ))
1811 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1812 bSetDOSExtendedError = TRUE;
1814 break;
1816 default:
1817 /* network software not installed */
1818 TRACE(int21,"NETWORK function AX=%04x not implemented\n",AX_reg(context));
1819 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1820 bSetDOSExtendedError = TRUE;
1821 break;
1823 break;
1825 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1826 TRACE(int21,"TRUENAME %s\n",
1827 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),SI_reg(context)));
1829 if (!GetFullPathName32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1830 SI_reg(context)), 128,
1831 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
1832 DI_reg(context)),NULL))
1833 bSetDOSExtendedError = TRUE;
1834 else AX_reg(context) = 0;
1836 break;
1838 case 0x61: /* UNUSED */
1839 case 0x63: /* UNUSED */
1840 case 0x64: /* OS/2 DOS BOX */
1841 INT_BARF( context, 0x21 );
1842 SET_CFLAG(context);
1843 break;
1845 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1846 extern WORD WINE_LanguageId;
1847 BYTE *dataptr=CTX_SEG_OFF_TO_LIN(context, ES_reg(context),DI_reg(context));
1848 TRACE(int21,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1849 BX_reg(context), DX_reg(context));
1850 switch (AL_reg(context)) {
1851 case 0x01:
1852 TRACE(int21,"\tget general internationalization info\n");
1853 dataptr[0] = 0x1;
1854 *(WORD*)(dataptr+1) = 41;
1855 *(WORD*)(dataptr+3) = WINE_LanguageId;
1856 *(WORD*)(dataptr+5) = CodePage;
1857 *(DWORD*)(dataptr+0x19) = 0; /* FIXME: ptr to case map routine */
1858 break;
1859 case 0x06:
1860 TRACE(int21,"\tget pointer to collating sequence table\n");
1861 dataptr[0] = 0x06;
1862 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
1863 CX_reg(context) = 258;/*FIXME: size of table?*/
1864 break;
1865 default:
1866 TRACE(int21,"\tunimplemented function %d\n",AL_reg(context));
1867 INT_BARF( context, 0x21 );
1868 SET_CFLAG(context);
1869 break;
1871 break;
1873 case 0x66: /* GLOBAL CODE PAGE TABLE */
1874 switch (AL_reg(context))
1876 case 0x01:
1877 TRACE(int21,"GET GLOBAL CODE PAGE TABLE\n");
1878 DX_reg(context) = BX_reg(context) = CodePage;
1879 RESET_CFLAG(context);
1880 break;
1881 case 0x02:
1882 TRACE(int21,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
1883 BX_reg(context),DX_reg(context));
1884 CodePage = BX_reg(context);
1885 RESET_CFLAG(context);
1886 break;
1888 break;
1890 case 0x67: /* SET HANDLE COUNT */
1891 TRACE(int21,"SET HANDLE COUNT to %d\n",BX_reg(context) );
1892 SetHandleCount16( BX_reg(context) );
1893 if (DOS_ExtendedError) bSetDOSExtendedError = TRUE;
1894 break;
1896 case 0x68: /* "FFLUSH" - COMMIT FILE */
1897 case 0x6a: /* COMMIT FILE */
1898 TRACE(int21,"FFLUSH/COMMIT handle %d\n",BX_reg(context));
1899 bSetDOSExtendedError = (!FlushFileBuffers( HFILE16_TO_HFILE32(BX_reg(context)) ));
1900 break;
1902 case 0x69: /* DISK SERIAL NUMBER */
1903 switch (AL_reg(context))
1905 case 0x00:
1906 TRACE(int21,"GET DISK SERIAL NUMBER for drive %s\n",
1907 INT21_DriveName(BL_reg(context)));
1908 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1909 else AX_reg(context) = 0;
1910 break;
1912 case 0x01:
1913 TRACE(int21,"SET DISK SERIAL NUMBER for drive %s\n",
1914 INT21_DriveName(BL_reg(context)));
1915 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1916 else AX_reg(context) = 1;
1917 break;
1919 break;
1921 case 0x6C: /* Extended Open/Create*/
1922 TRACE(int21,"EXTENDED OPEN/CREATE %s\n",
1923 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DI_reg(context)));
1924 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
1925 break;
1927 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1928 if ((GetVersion32()&0xC0000004)!=0xC0000004) {
1929 /* not supported on anything but Win95 */
1930 TRACE(int21,"LONG FILENAME functions supported only by win95\n");
1931 SET_CFLAG(context);
1932 AL_reg(context) = 0;
1933 } else
1934 switch(AL_reg(context))
1936 case 0x39: /* Create directory */
1937 TRACE(int21,"LONG FILENAME - MAKE DIRECTORY %s\n",
1938 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
1939 bSetDOSExtendedError = (!CreateDirectory32A(
1940 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1941 DX_reg(context) ), NULL));
1942 break;
1943 case 0x3a: /* Remove directory */
1944 TRACE(int21,"LONG FILENAME - REMOVE DIRECTORY %s\n",
1945 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
1946 bSetDOSExtendedError = (!RemoveDirectory32A(
1947 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1948 DX_reg(context) )));
1949 break;
1950 case 0x43: /* Get/Set file attributes */
1951 TRACE(int21,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
1952 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
1953 switch (BL_reg(context))
1955 case 0x00: /* Get file attributes */
1956 TRACE(int21,"\tretrieve attributes\n");
1957 CX_reg(context) = (WORD)GetFileAttributes32A(
1958 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1959 DX_reg(context)));
1960 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1961 break;
1962 case 0x01:
1963 TRACE(int21,"\tset attributes 0x%04x\n",CX_reg(context));
1964 bSetDOSExtendedError = (!SetFileAttributes32A(
1965 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1966 DX_reg(context)),
1967 CX_reg(context) ) );
1968 break;
1969 default:
1970 FIXME(int21, "Unimplemented long file name function:\n");
1971 INT_BARF( context, 0x21 );
1972 SET_CFLAG(context);
1973 AL_reg(context) = 0;
1974 break;
1976 break;
1977 case 0x47: /* Get current directory */
1978 TRACE(int21," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
1979 INT21_DriveName(DL_reg(context)));
1980 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1981 break;
1983 case 0x4e: /* Find first file */
1984 TRACE(int21," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
1985 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
1986 /* FIXME: use attributes in CX */
1987 if ((AX_reg(context) = FindFirstFile16(
1988 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)),
1989 (WIN32_FIND_DATA32A *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
1990 DI_reg(context))))
1991 == INVALID_HANDLE_VALUE16)
1992 bSetDOSExtendedError = TRUE;
1993 break;
1994 case 0x4f: /* Find next file */
1995 TRACE(int21,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
1996 BX_reg(context));
1997 if (!FindNextFile16( BX_reg(context),
1998 (WIN32_FIND_DATA32A *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
1999 DI_reg(context))))
2000 bSetDOSExtendedError = TRUE;
2001 break;
2002 case 0xa1: /* Find close */
2003 TRACE(int21,"LONG FILENAME - FINDCLOSE for handle %d\n",
2004 BX_reg(context));
2005 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
2006 break;
2007 case 0xa0:
2008 TRACE(int21,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2009 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
2010 break;
2011 case 0x60:
2012 switch(CL_reg(context))
2014 case 0x01: /*Get short filename or path */
2015 if (!GetShortPathName32A
2016 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2017 SI_reg(context)),
2018 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2019 DI_reg(context)), 67))
2020 bSetDOSExtendedError = TRUE;
2021 else AX_reg(context) = 0;
2022 break;
2023 case 0x02: /*Get canonical long filename or path */
2024 if (!GetFullPathName32A
2025 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2026 SI_reg(context)), 128,
2027 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2028 DI_reg(context)),NULL))
2029 bSetDOSExtendedError = TRUE;
2030 else AX_reg(context) = 0;
2031 break;
2032 default:
2033 FIXME(int21, "Unimplemented long file name function:\n");
2034 INT_BARF( context, 0x21 );
2035 SET_CFLAG(context);
2036 AL_reg(context) = 0;
2037 break;
2039 break;
2040 case 0x6c: /* Create or open file */
2041 TRACE(int21,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
2042 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), SI_reg(context)));
2043 /* translate Dos 7 action to Dos 6 action */
2044 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2045 break;
2047 case 0x3b: /* Change directory */
2048 TRACE(int21,"LONG FILENAME - CHANGE DIRECTORY %s\n",
2049 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
2050 if (!SetCurrentDirectory32A(CTX_SEG_OFF_TO_LIN(context,
2051 DS_reg(context),
2052 DX_reg(context)
2055 SET_CFLAG(context);
2056 AL_reg(context) = DOS_ExtendedError;
2058 break;
2059 case 0x41: /* Delete file */
2060 TRACE(int21,"LONG FILENAME - DELETE FILE %s\n",
2061 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
2062 if (!DeleteFile32A(CTX_SEG_OFF_TO_LIN(context,
2063 DS_reg(context),
2064 DX_reg(context))
2065 )) {
2066 SET_CFLAG(context);
2067 AL_reg(context) = DOS_ExtendedError;
2069 break;
2070 case 0x56: /* Move (rename) file */
2071 TRACE(int21,"LONG FILENAME - RENAME FILE %s to %s stub\n",
2072 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)),
2073 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context), DI_reg(context)));
2074 default:
2075 FIXME(int21, "Unimplemented long file name function:\n");
2076 INT_BARF( context, 0x21 );
2077 SET_CFLAG(context);
2078 AL_reg(context) = 0;
2079 break;
2081 break;
2083 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2084 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2085 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2086 TRACE(int21,"windows95 function AX %04x\n",
2087 AX_reg(context));
2088 WARN(int21, " returning unimplemented\n");
2089 SET_CFLAG(context);
2090 AL_reg(context) = 0;
2091 break;
2093 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2094 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2095 break;
2097 default:
2098 INT_BARF( context, 0x21 );
2099 break;
2101 } /* END OF SWITCH */
2103 if( bSetDOSExtendedError ) /* set general error condition */
2105 AX_reg(context) = DOS_ExtendedError;
2106 SET_CFLAG(context);
2109 if ((EFL_reg(context) & 0x0001))
2110 TRACE(int21, "failed, errorcode 0x%02x class 0x%02x action 0x%02x locus %02x\n",
2111 DOS_ExtendedError, DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus);
2113 TRACE(int21, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2114 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2115 AX_reg(context), BX_reg(context), CX_reg(context),
2116 DX_reg(context), SI_reg(context), DI_reg(context),
2117 (WORD)DS_reg(context), (WORD)ES_reg(context),
2118 EFL_reg(context));
2121 FARPROC16 WINAPI GetSetKernelDOSProc(FARPROC16 DosProc)
2123 FIXME(int21, "(DosProc=0x%08x): stub\n", (UINT32)DosProc);
2124 return NULL;