2 * DOS interrupt 21h handler
10 # include <sys/file.h>
15 #include <sys/types.h>
21 #include "winuser.h" /* SW_NORMAL */
22 #include "wine/winbase16.h"
32 #include "dosexe.h" /* for the MZ_SUPPORTED define */
36 #if defined(__svr4__) || defined(_SCO_DS)
37 /* SVR4 DOESNT do locking the same way must implement properly */
44 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
46 /* Define the drive parameter block, as used by int21/1F
47 * and int21/32. This table can be accessed through the
48 * global 'dpb' pointer, which points into the local dos
53 BYTE drive_num
; /* 0=A, etc. */
54 BYTE unit_num
; /* Drive's unit number (?) */
55 WORD sector_size
; /* Sector size in bytes */
56 BYTE high_sector
; /* Highest sector in a cluster */
57 BYTE shift
; /* Shift count (?) */
58 WORD reserved
; /* Number of reserved sectors at start */
59 BYTE num_FAT
; /* Number of FATs */
60 WORD dir_entries
; /* Number of root dir entries */
61 WORD first_data
; /* First data sector */
62 WORD high_cluster
; /* Highest cluster number */
63 WORD sectors_in_FAT
; /* Number of sectors per FAT */
64 WORD start_dir
; /* Starting sector of first dir */
65 DWORD driver_head
; /* Address of device driver header (?) */
66 BYTE media_ID
; /* Media ID */
67 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
68 DWORD next
; /* Pointer to next DPB in list */
69 WORD free_search
; /* Free cluster search start */
70 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
81 BYTE DummyDBCSLeadTable
[6];
83 static struct DosHeap
*heap
;
84 static WORD DosHeapHandle
;
86 WORD sharing_retries
= 3; /* number of retries at sharing violation */
87 WORD sharing_pause
= 1; /* pause between retries */
89 extern char TempDirectory
[];
91 static BOOL
INT21_CreateHeap(void)
93 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
95 WARN(int21
, "Out of memory\n");
98 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
99 dpbsegptr
= PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
101 strcpy(heap
->biosdate
, "01/01/80");
102 memset(heap
->DummyDBCSLeadTable
, 0, 6);
106 static BYTE
*GetCurrentDTA( CONTEXT
*context
)
108 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
110 /* FIXME: This assumes DTA was set correctly! */
111 return (BYTE
*)CTX_SEG_OFF_TO_LIN( context
, SELECTOROF(pTask
->dta
),
112 (DWORD
)OFFSETOF(pTask
->dta
) );
116 void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
117 /* limited == TRUE is used with INT 0x21/0x440d */
122 setword(&data
[3], 0);
124 setword(&data
[6], 240);
125 setword(&data
[8], 64000);
127 setword(&data
[0x0b], 40);
128 setword(&data
[0x0d], 56);
129 setword(&data
[0x0f], 2);
130 setword(&data
[0x11], 0);
132 setword(&data
[0x1f], 800);
134 setword(&data
[0x22], 1);
136 } else { /* 1.44mb */
139 setword(&data
[3], 0);
141 setword(&data
[6], 240);
142 setword(&data
[8], 2880);
144 setword(&data
[0x0b], 6);
145 setword(&data
[0x0d], 18);
146 setword(&data
[0x0f], 2);
147 setword(&data
[0x11], 0);
149 setword(&data
[0x1f], 80);
151 setword(&data
[0x22], 2);
156 static int INT21_GetFreeDiskSpace( CONTEXT
*context
)
158 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
159 char root
[] = "A:\\";
161 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
162 if (!GetDiskFreeSpaceA( root
, &cluster_sectors
, §or_bytes
,
163 &free_clusters
, &total_clusters
)) return 0;
164 AX_reg(context
) = cluster_sectors
;
165 BX_reg(context
) = free_clusters
;
166 CX_reg(context
) = sector_bytes
;
167 DX_reg(context
) = total_clusters
;
171 static int INT21_GetDriveAllocInfo( CONTEXT
*context
)
173 if (!INT21_GetFreeDiskSpace( context
)) return 0;
174 if (!heap
&& !INT21_CreateHeap()) return 0;
175 heap
->mediaID
= 0xf0;
176 DS_reg(context
) = DosHeapHandle
;
177 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
181 static void GetDrivePB( CONTEXT
*context
, int drive
)
183 if(!DRIVE_IsValid(drive
))
185 SetLastError( ERROR_INVALID_DRIVE
);
186 AX_reg(context
) = 0x00ff;
188 else if (heap
|| INT21_CreateHeap())
190 FIXME(int21
, "GetDrivePB not fully implemented.\n");
192 /* FIXME: I have no idea what a lot of this information should
193 * say or whether it even really matters since we're not allowing
194 * direct block access. However, some programs seem to depend on
195 * getting at least _something_ back from here. The 'next' pointer
196 * does worry me, though. Should we have a complete table of
197 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
199 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
200 heap
->dpb
.sector_size
= 512;
201 heap
->dpb
.high_sector
= 1;
202 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
203 heap
->dpb
.reserved
= 0;
204 heap
->dpb
.num_FAT
= 1;
205 heap
->dpb
.dir_entries
= 2;
206 heap
->dpb
.first_data
= 2;
207 heap
->dpb
.high_cluster
= 64000;
208 heap
->dpb
.sectors_in_FAT
= 1;
209 heap
->dpb
.start_dir
= 1;
210 heap
->dpb
.driver_head
= 0;
211 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
212 heap
->dpb
.access_flag
= 0;
214 heap
->dpb
.free_search
= 0;
215 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
217 AL_reg(context
) = 0x00;
218 DS_reg(context
) = SELECTOROF(dpbsegptr
);
219 BX_reg(context
) = OFFSETOF(dpbsegptr
);
224 static void ioctlGetDeviceInfo( CONTEXT
*context
)
227 const DOS_DEVICE
*dev
;
229 TRACE(int21
, "(%d)\n", BX_reg(context
));
231 RESET_CFLAG(context
);
234 if ((dev
= DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context
)) )))
236 DX_reg(context
) = dev
->flags
;
240 /* it seems to be a file */
241 curr_drive
= DRIVE_GetCurrentDrive();
242 DX_reg(context
) = 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0);
244 /* bits 0-5 are current drive
245 * bit 6 - file has NOT been written..FIXME: correct?
246 * bit 8 - generate int24 if no diskspace on write/ read past end of file
247 * bit 11 - media not removable
248 * bit 14 - don't set file date/time on closing
249 * bit 15 - file is remote
253 static BOOL
ioctlGenericBlkDevReq( CONTEXT
*context
)
255 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
256 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
258 if (!DRIVE_IsValid(drive
))
260 SetLastError( ERROR_FILE_NOT_FOUND
);
264 if (CH_reg(context
) != 0x08)
266 INT_BARF( context
, 0x21 );
270 switch (CL_reg(context
))
272 case 0x4a: /* lock logical volume */
273 TRACE(int21
,"lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
276 case 0x60: /* get device parameters */
277 /* used by w4wgrp's winfile */
278 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
280 dataptr
[6] = 0; /* media type */
283 dataptr
[1] = 0x05; /* fixed disk */
284 setword(&dataptr
[2], 0x01); /* non removable */
285 setword(&dataptr
[4], 0x300); /* # of cylinders */
289 dataptr
[1] = 0x07; /* block dev, floppy */
290 setword(&dataptr
[2], 0x02); /* removable */
291 setword(&dataptr
[4], 80); /* # of cylinders */
293 CreateBPB(drive
, &dataptr
[7], TRUE
);
294 RESET_CFLAG(context
);
297 case 0x41: /* write logical device track */
298 case 0x61: /* read logical device track */
300 BYTE drive
= BL_reg(context
) ?
301 BL_reg(context
) : DRIVE_GetCurrentDrive();
302 WORD head
= *(WORD
*)dataptr
+1;
303 WORD cyl
= *(WORD
*)dataptr
+3;
304 WORD sect
= *(WORD
*)dataptr
+5;
305 WORD nrsect
= *(WORD
*)dataptr
+7;
306 BYTE
*data
= (BYTE
*)dataptr
+9;
307 int (*raw_func
)(BYTE
, DWORD
, DWORD
, BYTE
*, BOOL
);
309 raw_func
= (CL_reg(context
) == 0x41) ?
310 DRIVE_RawWrite
: DRIVE_RawRead
;
312 if (raw_func(drive
, head
*cyl
*sect
, nrsect
, data
, FALSE
))
313 RESET_CFLAG(context
);
316 AX_reg(context
) = 0x1e; /* read fault */
321 case 0x66:/* get disk serial number */
323 char label
[12],fsname
[9],path
[4];
326 strcpy(path
,"x:\\");path
[0]=drive
+'A';
327 GetVolumeInformationA(
328 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
331 memcpy(dataptr
+2,&serial
,4);
332 memcpy(dataptr
+6,label
,11);
333 memcpy(dataptr
+17,fsname
,8);
338 TRACE(int21
,"logical volume %d unlocked.\n",drive
);
342 memset(dataptr
+1, '\0', dataptr
[0]-1);
343 dataptr
[1] = dataptr
[0];
344 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
345 dataptr
[3] = 0xFF; /* no physical drive */
349 INT_BARF( context
, 0x21 );
354 static void INT21_ParseFileNameIntoFCB( CONTEXT
*context
)
357 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
) );
359 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), EDI_reg(context
) );
360 char *buffer
, *s
, *d
;
362 AL_reg(context
) = 0xff; /* failed */
364 TRACE(int21
, "filename: '%s'\n", filename
);
366 buffer
= HeapAlloc( GetProcessHeap(), 0, strlen(filename
) + 1);
372 if ((*s
!= ' ') && (*s
!= '\r') && (*s
!= '\n'))
379 DOSFS_ToDosFCBFormat(buffer
, fcb
+ 1);
381 TRACE(int21
, "FCB: '%s'\n", ((CHAR
*)fcb
+ 1));
383 HeapFree( GetProcessHeap(), 0, buffer
);
386 ((strchr(filename
, '*')) || (strchr(filename
, '$'))) != 0;
388 /* point DS:SI to first unparsed character */
389 SI_reg(context
) += (int)s
- (int)filename
;
392 static void INT21_GetSystemDate( CONTEXT
*context
)
395 GetLocalTime( &systime
);
396 CX_reg(context
) = systime
.wYear
;
397 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
398 AX_reg(context
) = systime
.wDayOfWeek
;
401 static void INT21_GetSystemTime( CONTEXT
*context
)
404 GetLocalTime( &systime
);
405 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
406 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
409 /* Many calls translate a drive argument like this:
410 drive number (00h = default, 01h = A:, etc)
412 static char drivestring
[]="default";
414 char *INT21_DriveName(int drive
)
419 drivestring
[0]= (unsigned char)drive
+ '@';
425 static BOOL
INT21_CreateFile( CONTEXT
*context
)
427 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
428 EDX_reg(context
) ), CX_reg(context
) );
429 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
433 static void OpenExistingFile( CONTEXT
*context
)
435 AX_reg(context
) = _lopen16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
437 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
439 AX_reg(context
) = GetLastError();
444 static BOOL
INT21_ExtendedOpenCreateFile(CONTEXT
*context
)
446 BOOL bExtendedError
= FALSE
;
447 BYTE action
= DL_reg(context
);
449 /* Shuffle arguments to call OpenExistingFile */
450 AL_reg(context
) = BL_reg(context
);
451 DX_reg(context
) = SI_reg(context
);
452 /* BX,CX and DX should be preserved */
453 OpenExistingFile(context
);
455 if ((EFL_reg(context
) & 0x0001) == 0) /* File exists */
457 UINT16 uReturnCX
= 0;
459 /* Now decide what do do */
461 if ((action
& 0x07) == 0)
463 _lclose16( AX_reg(context
) );
464 AX_reg(context
) = 0x0050; /*File exists*/
466 WARN(int21
, "extended open/create: failed because file exists \n");
468 else if ((action
& 0x07) == 2)
470 /* Truncate it, but first check if opened for write */
471 if ((BL_reg(context
) & 0x0007)== 0)
473 _lclose16( AX_reg(context
) );
474 WARN(int21
, "extended open/create: failed, trunc on ro file\n");
475 AX_reg(context
) = 0x000C; /*Access code invalid*/
480 TRACE(int21
, "extended open/create: Closing before truncate\n");
481 if (_lclose16( AX_reg(context
) ))
483 WARN(int21
, "extended open/create: close before trunc failed\n");
484 AX_reg(context
) = 0x0019; /*Seek Error*/
488 /* Shuffle arguments to call CreateFile */
490 TRACE(int21
, "extended open/create: Truncating\n");
491 AL_reg(context
) = BL_reg(context
);
492 /* CX is still the same */
493 DX_reg(context
) = SI_reg(context
);
494 bExtendedError
= INT21_CreateFile(context
);
496 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
498 WARN(int21
, "extended open/create: trunc failed\n");
499 return bExtendedError
;
504 else uReturnCX
= 0x1;
506 CX_reg(context
) = uReturnCX
;
508 else /* file does not exist */
510 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
511 if ((action
& 0xF0)== 0)
515 WARN(int21
, "extended open/create: failed, file dosen't exist\n");
519 /* Shuffle arguments to call CreateFile */
520 TRACE(int21
, "extended open/create: Creating\n");
521 AL_reg(context
) = BL_reg(context
);
522 /* CX should still be the same */
523 DX_reg(context
) = SI_reg(context
);
524 bExtendedError
= INT21_CreateFile(context
);
525 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
527 WARN(int21
, "extended open/create: create failed\n");
528 return bExtendedError
;
534 return bExtendedError
;
538 static BOOL
INT21_ChangeDir( CONTEXT
*context
)
541 char *dirname
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
));
543 TRACE(int21
,"changedir %s\n", dirname
);
544 if (dirname
[0] && (dirname
[1] == ':'))
546 drive
= toupper(dirname
[0]) - 'A';
549 else drive
= DRIVE_GetCurrentDrive();
550 return DRIVE_Chdir( drive
, dirname
);
554 static int INT21_FindFirst( CONTEXT
*context
)
558 DOS_FULL_NAME full_name
;
559 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
561 path
= (const char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
562 dta
->unixPath
= NULL
;
563 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
565 AX_reg(context
) = GetLastError();
569 dta
->unixPath
= HEAP_strdupA( GetProcessHeap(), 0, full_name
.long_name
);
570 p
= strrchr( dta
->unixPath
, '/' );
573 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
574 * (doesn't matter as it is set below anyway)
576 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
578 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
579 dta
->unixPath
= NULL
;
580 SetLastError( ERROR_FILE_NOT_FOUND
);
581 AX_reg(context
) = ERROR_FILE_NOT_FOUND
;
585 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
586 : DRIVE_GetCurrentDrive();
588 dta
->search_attr
= CL_reg(context
);
593 static int INT21_FindNext( CONTEXT
*context
)
595 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
596 WIN32_FIND_DATAA entry
;
599 if (!dta
->unixPath
) return 0;
600 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
601 dta
->search_attr
, dta
->count
, &entry
)))
603 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
604 dta
->unixPath
= NULL
;
607 if ((int)dta
->count
+ count
> 0xffff)
609 WARN(int21
, "Too many directory entries in %s\n", dta
->unixPath
);
610 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
611 dta
->unixPath
= NULL
;
615 dta
->fileattr
= entry
.dwFileAttributes
;
616 dta
->filesize
= entry
.nFileSizeLow
;
617 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
618 &dta
->filedate
, &dta
->filetime
);
619 strcpy( dta
->filename
, entry
.cAlternateFileName
);
620 if (!memchr(dta
->mask
,'?',11)) {
621 /* wildcardless search, release resources in case no findnext will
622 * be issued, and as a workaround in case file creation messes up
623 * findnext, as sometimes happens with pkunzip */
624 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
625 dta
->unixPath
= NULL
;
631 static BOOL
INT21_CreateTempFile( CONTEXT
*context
)
633 static int counter
= 0;
634 char *name
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
) );
635 char *p
= name
+ strlen(name
);
637 /* despite what Ralf Brown says, some programs seem to call without
638 * ending backslash (DOS accepts that, so we accept it too) */
639 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
643 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
644 counter
= (counter
+ 1) % 1000;
646 if ((AX_reg(context
) = _lcreat16_uniq( name
, 0 )) != (WORD
)HFILE_ERROR16
)
648 TRACE(int21
, "created %s\n", name
);
651 if (GetLastError() != ERROR_FILE_EXISTS
) return FALSE
;
656 static BOOL
INT21_GetCurrentDirectory( CONTEXT
*context
)
658 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
659 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
) );
661 if (!DRIVE_IsValid(drive
))
663 SetLastError( ERROR_INVALID_DRIVE
);
666 lstrcpynA( ptr
, DRIVE_GetDosCwd(drive
), 64 );
667 AX_reg(context
) = 0x0100; /* success return code */
672 static void INT21_GetDBCSLeadTable( CONTEXT
*context
)
674 if (heap
|| INT21_CreateHeap())
675 { /* return an empty table just as DOS 4.0+ does */
676 DS_reg(context
) = DosHeapHandle
;
677 SI_reg(context
) = (int)&heap
->DummyDBCSLeadTable
- (int)heap
;
681 AX_reg(context
) = 0x1; /* error */
687 static int INT21_GetDiskSerialNumber( CONTEXT
*context
)
689 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
690 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
692 if (!DRIVE_IsValid(drive
))
694 SetLastError( ERROR_INVALID_DRIVE
);
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);
706 static int INT21_SetDiskSerialNumber( CONTEXT
*context
)
708 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
709 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
711 if (!DRIVE_IsValid(drive
))
713 SetLastError( ERROR_INVALID_DRIVE
);
717 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
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
), EDX_reg(context
));
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
);
749 static int INT21_FindNextFCB( CONTEXT
*context
)
751 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
753 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA(context
);
754 WIN32_FIND_DATAA entry
;
758 if (*fcb
== 0xff) /* extended FCB ? */
761 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
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
;
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
;
786 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
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] = '.';
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 ) );
811 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
812 MIN( strlen(entry
.cAlternateFileName
), 8 ) );
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",
838 MAKELONG(DX_reg(context
),CX_reg(context
)),
839 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
840 if (!LockFile(FILE_GetHandle(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
) = GetLastError();
848 case 0x01: /* UNLOCK */
849 TRACE(int21
,"unlock handle %d offset %ld length %ld\n",
851 MAKELONG(DX_reg(context
),CX_reg(context
)),
852 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
853 if (!UnlockFile(FILE_GetHandle(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
) = GetLastError();
861 AX_reg(context
) = 0x0001;
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
),EDX_reg(context
));
874 TRACE(int21
, "getting machine name to %p\n", dst
);
875 if (gethostname (dst
, 15))
877 WARN(int21
,"failed!\n");
878 SetLastError( ER_NoNetwork
);
881 int len
= strlen (dst
);
885 CH_reg(context
) = 1; /* Valid */
886 CL_reg(context
) = 1; /* NETbios number??? */
887 TRACE(int21
, "returning %s\n", debugstr_an (dst
, 16));
893 SetLastError( ER_NoNetwork
);
898 static void INT21_SetCurrentPSP(WORD psp
)
901 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
902 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
904 GlobalUnlock16( GetCurrentTask() );
905 if (pModule
->lpDosTask
)
906 pModule
->lpDosTask
->psp_seg
= psp
;
909 ERR(int21
, "Cannot change PSP for non-DOS task!\n");
912 static WORD
INT21_GetCurrentPSP()
915 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
916 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
918 GlobalUnlock16( GetCurrentTask() );
919 if (pModule
->lpDosTask
)
920 return pModule
->lpDosTask
->psp_seg
;
923 return GetCurrentPDB16();
927 SEGPTR
INT21_GetListOfLists()
929 static DOS_LISTOFLISTS
*LOL
;
930 static SEGPTR seg_LOL
;
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
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
;
985 /***********************************************************************
986 * INT21_GetExtendedError
988 static void INT21_GetExtendedError( CONTEXT
*context
)
990 BYTE
class, action
, locus
;
991 WORD error
= GetLastError();
996 class = action
= locus
= 0;
998 case ERROR_DIR_NOT_EMPTY
:
1003 case ERROR_ACCESS_DENIED
:
1004 class = EC_AccessDenied
;
1008 case ERROR_CANNOT_MAKE
:
1009 class = EC_AccessDenied
;
1013 case ERROR_DISK_FULL
:
1014 case ERROR_HANDLE_DISK_FULL
:
1015 class = EC_MediaError
;
1019 case ERROR_FILE_EXISTS
:
1020 case ERROR_ALREADY_EXISTS
:
1025 case ERROR_FILE_NOT_FOUND
:
1026 class = EC_NotFound
;
1030 case ER_GeneralFailure
:
1031 class = EC_SystemFailure
;
1035 case ERROR_INVALID_DRIVE
:
1036 class = EC_MediaError
;
1040 case ERROR_INVALID_HANDLE
:
1041 class = EC_ProgramError
;
1045 case ERROR_LOCK_VIOLATION
:
1046 class = EC_AccessDenied
;
1050 case ERROR_NO_MORE_FILES
:
1051 class = EC_MediaError
;
1056 class = EC_NotFound
;
1060 case ERROR_NOT_ENOUGH_MEMORY
:
1061 class = EC_OutOfResource
;
1065 case ERROR_PATH_NOT_FOUND
:
1066 class = EC_NotFound
;
1071 class = EC_NotFound
;
1075 case ERROR_SHARING_VIOLATION
:
1076 class = EC_Temporary
;
1080 case ERROR_TOO_MANY_OPEN_FILES
:
1081 class = EC_ProgramError
;
1086 FIXME( int21
, "Unknown error %d\n", error
);
1087 class = EC_SystemFailure
;
1092 TRACE( int21
, "GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1093 error
, class, action
, locus
);
1094 AX_reg(context
) = error
;
1095 BH_reg(context
) = class;
1096 BL_reg(context
) = action
;
1097 CH_reg(context
) = locus
;
1100 /***********************************************************************
1101 * DOS3Call (KERNEL.102)
1103 void WINAPI
DOS3Call( CONTEXT
*context
)
1105 BOOL bSetDOSExtendedError
= FALSE
;
1108 TRACE(int21
, "AX=%04x BX=%04x CX=%04x DX=%04x "
1109 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1110 AX_reg(context
), BX_reg(context
), CX_reg(context
), DX_reg(context
),
1111 SI_reg(context
), DI_reg(context
),
1112 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
1116 if (AH_reg(context
) == 0x59) /* Get extended error info */
1118 INT21_GetExtendedError( context
);
1122 if (AH_reg(context
) == 0x0C) /* Flush buffer and read standard input */
1124 TRACE(int21
, "FLUSH BUFFER AND READ STANDARD INPUT\n");
1125 /* no flush here yet */
1126 AH_reg(context
) = AL_reg(context
);
1129 if (AH_reg(context
)>=0x2f) {
1130 /* extended error is used by (at least) functions 0x2f to 0x62 */
1133 RESET_CFLAG(context
); /* Not sure if this is a good idea */
1135 switch(AH_reg(context
))
1137 case 0x03: /* READ CHARACTER FROM STDAUX */
1138 case 0x04: /* WRITE CHARACTER TO STDAUX */
1139 case 0x05: /* WRITE CHARACTER TO PRINTER */
1140 case 0x0f: /* OPEN FILE USING FCB */
1141 case 0x10: /* CLOSE FILE USING FCB */
1142 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1143 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1144 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1145 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1146 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1147 case 0x23: /* GET FILE SIZE FOR FCB */
1148 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1149 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1150 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1151 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1152 INT_BARF( context
, 0x21 );
1155 case 0x00: /* TERMINATE PROGRAM */
1156 TRACE(int21
,"TERMINATE PROGRAM\n");
1160 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1161 TRACE(int21
,"DIRECT CHARACTER INPUT WITH ECHO\n");
1162 AL_reg(context
) = CONSOLE_GetCharacter();
1163 /* FIXME: no echo */
1166 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1167 TRACE(int21
, "Write Character to Standard Output\n");
1168 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1171 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1172 if (DL_reg(context
) == 0xff) {
1173 static char scan
= 0;
1174 TRACE(int21
, "Direct Console Input\n");
1176 /* return pending scancode */
1177 AL_reg(context
) = scan
;
1178 FL_reg(context
) &= ~0x40; /* clear ZF */
1182 if (CONSOLE_CheckForKeystroke(&scan
,&ascii
)) {
1183 CONSOLE_GetKeystroke(&scan
,&ascii
);
1184 /* return ASCII code */
1185 AL_reg(context
) = ascii
;
1186 FL_reg(context
) &= ~0x40; /* clear ZF */
1187 /* return scan code on next call only if ascii==0 */
1188 if (ascii
) scan
= 0;
1190 /* nothing pending, clear everything */
1191 AL_reg(context
) = 0;
1192 FL_reg(context
) |= 0x40; /* set ZF */
1193 scan
= 0; /* just in case */
1197 TRACE(int21
, "Direct Console Output\n");
1198 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1202 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1203 TRACE(int21
,"DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1204 AL_reg(context
) = CONSOLE_GetCharacter();
1207 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1208 TRACE(int21
,"CHARACTER INPUT WITHOUT ECHO\n");
1209 AL_reg(context
) = CONSOLE_GetCharacter();
1212 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1213 TRACE(int21
,"WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1214 DS_reg(context
),DX_reg(context
) );
1216 LPSTR data
= CTX_SEG_OFF_TO_LIN(context
,DS_reg(context
),EDX_reg(context
));
1218 /* do NOT use strchr() to calculate the string length,
1219 as '\0' is valid string content, too !
1220 Maybe we should check for non-'$' strings, but DOS doesn't. */
1221 while (*p
!= '$') p
++;
1222 _hwrite16( 1, data
, (int)p
- (int)data
);
1223 AL_reg(context
) = '$'; /* yes, '$' (0x24) gets returned in AL */
1227 case 0x0a: /* BUFFERED INPUT */
1229 char *buffer
= ((char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1230 EDX_reg(context
) ));
1233 TRACE(int21
,"BUFFERED INPUT (size=%d)\n",buffer
[0]);
1235 TRACE(int21
,"Handle old chars in buffer!\n");
1236 res
=_lread16( 0, buffer
+2,buffer
[0]);
1238 if(buffer
[res
+1] == '\n')
1239 buffer
[res
+1] = '\r';
1243 case 0x0b: {/* GET STDIN STATUS */
1246 if (CONSOLE_CheckForKeystroke(&x1
,&x2
))
1247 AL_reg(context
) = 0xff;
1249 AL_reg(context
) = 0;
1252 case 0x2e: /* SET VERIFY FLAG */
1253 TRACE(int21
,"SET VERIFY FLAG ignored\n");
1254 /* we cannot change the behaviour anyway, so just ignore it */
1257 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1261 case 0x6b: /* NULL FUNCTION */
1262 AL_reg(context
) = 0;
1265 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1269 case 0x0d: /* DISK BUFFER FLUSH */
1270 TRACE(int21
,"DISK BUFFER FLUSH ignored\n");
1271 RESET_CFLAG(context
); /* dos 6+ only */
1274 case 0x0e: /* SELECT DEFAULT DRIVE */
1275 TRACE(int21
,"SELECT DEFAULT DRIVE %d\n", DL_reg(context
));
1276 DRIVE_SetCurrentDrive( DL_reg(context
) );
1277 AL_reg(context
) = MAX_DOS_DRIVES
;
1280 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1281 TRACE(int21
,"FIND FIRST MATCHING FILE USING FCB %p\n",
1282 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1283 if (!INT21_FindFirstFCB(context
))
1285 AL_reg(context
) = 0xff;
1288 /* else fall through */
1290 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1291 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
1294 case 0x13: /* DELETE FILE USING FCB */
1295 DeleteFileFCB(context
);
1298 case 0x17: /* RENAME FILE USING FCB */
1299 RenameFileFCB(context
);
1302 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1303 AL_reg(context
) = DRIVE_GetCurrentDrive();
1306 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1308 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1309 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(context
),DX_reg(context
));
1310 TRACE(int21
, "Set DTA: %08lx\n", pTask
->dta
);
1314 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1315 DL_reg(context
) = 0;
1316 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1319 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1320 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1323 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1324 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1327 case 0x25: /* SET INTERRUPT VECTOR */
1328 INT_CtxSetHandler( context
, AL_reg(context
),
1329 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1333 case 0x29: /* PARSE FILENAME INTO FCB */
1334 INT21_ParseFileNameIntoFCB(context
);
1337 case 0x2a: /* GET SYSTEM DATE */
1338 INT21_GetSystemDate(context
);
1341 case 0x2b: /* SET SYSTEM DATE */
1342 FIXME(int21
, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1343 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1344 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1347 case 0x2c: /* GET SYSTEM TIME */
1348 INT21_GetSystemTime(context
);
1351 case 0x2d: /* SET SYSTEM TIME */
1352 FIXME(int21
, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1353 CH_reg(context
), CL_reg(context
),
1354 DH_reg(context
), DL_reg(context
) );
1355 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1358 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1359 TRACE(int21
,"GET DISK TRANSFER AREA ADDRESS\n");
1361 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1362 ES_reg(context
) = SELECTOROF( pTask
->dta
);
1363 BX_reg(context
) = OFFSETOF( pTask
->dta
);
1367 case 0x30: /* GET DOS VERSION */
1368 TRACE(int21
,"GET DOS VERSION %s requested\n",
1369 (AL_reg(context
) == 0x00)?"OEM number":"version flag");
1370 AX_reg(context
) = (HIWORD(GetVersion16()) >> 8) |
1371 (HIWORD(GetVersion16()) << 8);
1373 AH_reg(context
) = 0x7;
1374 AL_reg(context
) = 0xA;
1377 BX_reg(context
) = 0x00FF; /* 0x123456 is Wine's serial # */
1378 CX_reg(context
) = 0x0000;
1381 case 0x31: /* TERMINATE AND STAY RESIDENT */
1382 FIXME(int21
,"TERMINATE AND STAY RESIDENT stub\n");
1385 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1386 TRACE(int21
,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1387 INT21_DriveName( DL_reg(context
)));
1388 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1391 case 0x33: /* MULTIPLEXED */
1392 switch (AL_reg(context
))
1394 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1395 TRACE(int21
,"GET CURRENT EXTENDED BREAK STATE\n");
1396 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1399 case 0x01: /* SET EXTENDED BREAK STATE */
1400 TRACE(int21
,"SET CURRENT EXTENDED BREAK STATE\n");
1401 DOSCONF_config
.brk_flag
= (DL_reg(context
) > 0);
1404 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1405 TRACE(int21
,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1406 /* ugly coding in order to stay reentrant */
1407 if (DL_reg(context
))
1409 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1410 DOSCONF_config
.brk_flag
= 1;
1414 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1415 DOSCONF_config
.brk_flag
= 0;
1419 case 0x05: /* GET BOOT DRIVE */
1420 TRACE(int21
,"GET BOOT DRIVE\n");
1421 DL_reg(context
) = 3;
1422 /* c: is Wine's bootdrive (a: is 1)*/
1425 case 0x06: /* GET TRUE VERSION NUMBER */
1426 TRACE(int21
,"GET TRUE VERSION NUMBER\n");
1427 BX_reg(context
) = (HIWORD(GetVersion16() >> 8)) |
1428 (HIWORD(GetVersion16() << 8));
1429 DX_reg(context
) = 0x00;
1433 INT_BARF( context
, 0x21 );
1438 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1439 TRACE(int21
,"GET ADDRESS OF INDOS FLAG\n");
1440 if (!heap
) INT21_CreateHeap();
1441 ES_reg(context
) = DosHeapHandle
;
1442 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1445 case 0x35: /* GET INTERRUPT VECTOR */
1446 TRACE(int21
,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
1448 FARPROC16 addr
= INT_CtxGetHandler( context
, AL_reg(context
) );
1449 ES_reg(context
) = SELECTOROF(addr
);
1450 BX_reg(context
) = OFFSETOF(addr
);
1454 case 0x36: /* GET FREE DISK SPACE */
1455 TRACE(int21
,"GET FREE DISK SPACE FOR DRIVE %s\n",
1456 INT21_DriveName( DL_reg(context
)));
1457 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1462 unsigned char switchchar
='/';
1463 switch (AL_reg(context
))
1465 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1466 TRACE(int21
,"SWITCHAR - GET SWITCH CHARACTER\n");
1467 AL_reg(context
) = 0x00; /* success*/
1468 DL_reg(context
) = switchchar
;
1470 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1471 TRACE(int21
,"SWITCHAR - SET SWITCH CHARACTER\n");
1472 switchchar
= DL_reg(context
);
1473 AL_reg(context
) = 0x00; /* success*/
1475 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1476 INT_BARF( context
, 0x21 );
1482 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1483 TRACE(int21
,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1485 AX_reg(context
) = 0x02; /* no country support available */
1489 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1490 TRACE(int21
,"MKDIR %s\n",
1491 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1492 bSetDOSExtendedError
= (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1493 EDX_reg(context
) ), NULL
));
1494 /* FIXME: CreateDirectory's LastErrors will clash with the ones
1495 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
1496 * denied), while CreateDirectory return several ones. remap some of
1499 if (bSetDOSExtendedError
) {
1500 switch (GetLastError()) {
1501 case ERROR_ALREADY_EXISTS
:
1502 case ERROR_FILENAME_EXCED_RANGE
:
1503 case ERROR_DISK_FULL
:
1504 SetLastError(ERROR_ACCESS_DENIED
);
1511 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1512 TRACE(int21
,"RMDIR %s\n",
1513 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1514 bSetDOSExtendedError
= (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1515 EDX_reg(context
) )));
1518 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1519 TRACE(int21
,"CHDIR %s\n",
1520 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1521 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1524 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1525 TRACE(int21
,"CREAT flag 0x%02x %s\n",CX_reg(context
),
1526 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1527 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1528 EDX_reg(context
) ), CX_reg(context
) );
1529 bSetDOSExtendedError
= (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
1532 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1533 TRACE(int21
,"OPEN mode 0x%02x %s\n",AL_reg(context
),
1534 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1535 OpenExistingFile(context
);
1538 case 0x3e: /* "CLOSE" - CLOSE FILE */
1539 TRACE(int21
,"CLOSE handle %d\n",BX_reg(context
));
1540 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1543 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1544 TRACE(int21
,"READ from %d to %04lX:%04X for %d byte\n",BX_reg(context
),
1545 DS_reg(context
),DX_reg(context
),CX_reg(context
) );
1549 result
= _hread16( BX_reg(context
),
1550 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1554 result
= WIN16_hread( BX_reg(context
),
1555 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1558 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1559 else AX_reg(context
) = (WORD
)result
;
1563 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1564 TRACE(int21
,"WRITE from %04lX:%04X to handle %d for %d byte\n",
1565 DS_reg(context
),DX_reg(context
),BX_reg(context
),CX_reg(context
) );
1567 LONG result
= _hwrite16( BX_reg(context
),
1568 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1571 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1572 else AX_reg(context
) = (WORD
)result
;
1576 case 0x41: /* "UNLINK" - DELETE FILE */
1577 TRACE(int21
,"UNLINK%s\n",
1578 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1579 bSetDOSExtendedError
= (!DeleteFileA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1580 EDX_reg(context
) )));
1583 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1584 TRACE(int21
,"LSEEK handle %d offset %ld from %s\n",
1585 BX_reg(context
), MAKELONG(DX_reg(context
),CX_reg(context
)),
1586 (AL_reg(context
)==0)?"start of file":(AL_reg(context
)==1)?
1587 "current file position":"end of file");
1589 LONG status
= _llseek16( BX_reg(context
),
1590 MAKELONG(DX_reg(context
),CX_reg(context
)),
1592 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1595 AX_reg(context
) = LOWORD(status
);
1596 DX_reg(context
) = HIWORD(status
);
1601 case 0x43: /* FILE ATTRIBUTES */
1602 switch (AL_reg(context
))
1605 TRACE(int21
,"GET FILE ATTRIBUTES for %s\n",
1606 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1607 AX_reg(context
) = (WORD
)GetFileAttributesA(
1608 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1610 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1611 else CX_reg(context
) = AX_reg(context
);
1615 TRACE(int21
,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context
),
1616 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1617 bSetDOSExtendedError
=
1618 (!SetFileAttributesA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1623 TRACE(int21
,"GET COMPRESSED FILE SIZE for %s stub\n",
1624 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1628 case 0x44: /* IOCTL */
1629 switch (AL_reg(context
))
1632 ioctlGetDeviceInfo(context
);
1638 const DOS_DEVICE
*dev
;
1639 if ((dev
= DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context
)) )) &&
1640 !strcasecmp( dev
->name
, "SCSIMGR$" ))
1642 ASPI_DOS_HandleInt(context
);
1646 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1647 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));*/
1648 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1650 FIXME(int21
,"program tried to write to block device control channel of drive %d:\n",drive
);
1651 /* for (i=0;i<CX_reg(context);i++)
1652 fprintf(stdnimp,"%02x ",dataptr[i]);
1653 fprintf(stdnimp,"\n");*/
1654 AX_reg(context
)=CX_reg(context
);
1657 case 0x08: /* Check if drive is removable. */
1658 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1659 INT21_DriveName( BL_reg(context
)));
1660 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1662 case DRIVE_CANNOTDETERMINE
:
1663 SetLastError( ERROR_INVALID_DRIVE
);
1664 AX_reg(context
) = ERROR_INVALID_DRIVE
;
1667 case DRIVE_REMOVABLE
:
1668 AX_reg(context
) = 0; /* removable */
1671 AX_reg(context
) = 1; /* not removable */
1676 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1677 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1678 INT21_DriveName( BL_reg(context
)));
1679 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1681 case DRIVE_CANNOTDETERMINE
:
1682 SetLastError( ERROR_INVALID_DRIVE
);
1683 AX_reg(context
) = ERROR_INVALID_DRIVE
;
1687 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1690 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1695 case 0x0a: /* check if handle (BX) is remote */
1696 TRACE(int21
,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context
));
1697 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1700 DX_reg(context
) = 0;
1703 case 0x0b: /* SET SHARING RETRY COUNT */
1704 TRACE(int21
,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1705 CX_reg(context
), DX_reg(context
));
1706 if (!CX_reg(context
))
1708 AX_reg(context
) = 1;
1712 sharing_pause
= CX_reg(context
);
1713 if (!DX_reg(context
))
1714 sharing_retries
= DX_reg(context
);
1715 RESET_CFLAG(context
);
1719 TRACE(int21
,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1720 INT21_DriveName( BL_reg(context
)));
1721 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1724 case 0x0e: /* get logical drive mapping */
1725 TRACE(int21
,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1726 INT21_DriveName( BL_reg(context
)));
1727 AL_reg(context
) = 0; /* drive has no mapping - FIXME: may be wrong*/
1730 case 0x0F: /* Set logical drive mapping */
1733 TRACE(int21
,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1734 INT21_DriveName( BL_reg(context
)));
1735 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1736 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1739 AX_reg(context
) = 0x000F; /* invalid drive */
1744 case 0xe0: /* Sun PC-NFS API */
1749 INT_BARF( context
, 0x21 );
1754 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1757 TRACE(int21
,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context
));
1758 if ((bSetDOSExtendedError
= !DuplicateHandle( GetCurrentProcess(),
1759 FILE_GetHandle(BX_reg(context
)),
1760 GetCurrentProcess(), &handle
,
1761 0, TRUE
, DUPLICATE_SAME_ACCESS
)))
1762 AX_reg(context
) = HFILE_ERROR16
;
1764 AX_reg(context
) = FILE_AllocDosHandle(handle
);
1768 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1769 TRACE(int21
,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1770 BX_reg(context
),CX_reg(context
));
1771 bSetDOSExtendedError
= (FILE_Dup2( BX_reg(context
), CX_reg(context
) ) == HFILE_ERROR16
);
1774 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1775 TRACE(int21
,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1776 INT21_DriveName( DL_reg(context
)));
1777 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1780 case 0x48: /* ALLOCATE MEMORY */
1781 TRACE(int21
,"ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
));
1786 mem
= DOSMEM_GetBlock(0,(DWORD
)BX_reg(context
)<<4,NULL
);
1788 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1792 mem
= (LPVOID
)GlobalDOSAlloc16(BX_reg(context
)<<4);
1794 AX_reg(context
) = (DWORD
)mem
&0xffff;
1799 AX_reg(context
) = 0x0008; /* insufficient memory */
1800 BX_reg(context
) = DOSMEM_Available(0)>>4;
1805 case 0x49: /* FREE MEMORY */
1806 TRACE(int21
,"FREE MEMORY segment %04lX\n", ES_reg(context
));
1810 ret
= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4));
1813 ret
= !GlobalDOSFree16(ES_reg(context
));
1814 /* If we don't reset ES_reg, we will fail in the relay code */
1815 ES_reg(context
)=ret
;
1819 TRACE(int21
,"FREE MEMORY failed\n");
1821 AX_reg(context
) = 0x0009; /* memory block address invalid */
1826 case 0x4a: /* RESIZE MEMORY BLOCK */
1827 TRACE(int21
,"RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context
), BX_reg(context
));
1828 if (!ISV86(context
))
1829 FIXME(int21
,"RESIZE MEMORY probably insufficient implementation. Expect crash soon\n");
1831 LPVOID
*mem
= DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4),
1832 BX_reg(context
)<<4,NULL
);
1834 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1837 AX_reg(context
) = 0x0008; /* insufficient memory */
1838 BX_reg(context
) = DOSMEM_Available(0)>>4; /* not quite right */
1843 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1844 TRACE(int21
,"EXEC %s\n",
1845 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
) ));
1846 AX_reg(context
) = WinExec16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1849 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1852 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1853 TRACE(int21
,"EXIT with return code %d\n",AL_reg(context
));
1854 ExitProcess( AL_reg(context
) );
1857 case 0x4d: /* GET RETURN CODE */
1858 TRACE(int21
,"GET RETURN CODE (ERRORLEVEL)\n");
1859 AX_reg(context
) = 0; /* normal exit */
1862 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1863 TRACE(int21
,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
1864 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1865 if (!INT21_FindFirst(context
)) break;
1868 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1869 TRACE(int21
,"FINDNEXT\n");
1870 if (!INT21_FindNext(context
))
1872 SetLastError( ERROR_NO_MORE_FILES
);
1873 AX_reg(context
) = ERROR_NO_MORE_FILES
;
1876 else AX_reg(context
) = 0; /* OK */
1878 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1879 TRACE(int21
, "SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1880 INT21_SetCurrentPSP(BX_reg(context
));
1882 case 0x51: /* GET PSP ADDRESS */
1883 TRACE(int21
,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1884 /* FIXME: should we return the original DOS PSP upon */
1885 /* Windows startup ? */
1886 BX_reg(context
) = INT21_GetCurrentPSP();
1888 case 0x62: /* GET PSP ADDRESS */
1889 TRACE(int21
,"GET CURRENT PSP ADDRESS\n");
1890 /* FIXME: should we return the original DOS PSP upon */
1891 /* Windows startup ? */
1892 BX_reg(context
) = INT21_GetCurrentPSP();
1895 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1896 TRACE(int21
,"SYSVARS - GET LIST OF LISTS\n");
1899 lol
= INT21_GetListOfLists();
1900 ES_reg(context
) = HIWORD(lol
);
1901 BX_reg(context
) = LOWORD(lol
);
1905 case 0x54: /* Get Verify Flag */
1906 TRACE(int21
,"Get Verify Flag - Not Supported\n");
1907 AL_reg(context
) = 0x00; /* pretend we can tell. 00h = off 01h = on */
1910 case 0x56: /* "RENAME" - RENAME FILE */
1911 TRACE(int21
,"RENAME %s to %s\n",
1912 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1913 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
)));
1914 bSetDOSExtendedError
=
1915 (!MoveFileA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1916 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
))));
1919 case 0x57: /* FILE DATE AND TIME */
1920 switch (AL_reg(context
))
1922 case 0x00: /* Get */
1925 TRACE(int21
,"GET FILE DATE AND TIME for handle %d\n",
1927 if (!GetFileTime( FILE_GetHandle(BX_reg(context
)), NULL
, NULL
, &filetime
))
1928 bSetDOSExtendedError
= TRUE
;
1929 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1934 case 0x01: /* Set */
1937 TRACE(int21
,"SET FILE DATE AND TIME for handle %d\n",
1939 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1941 bSetDOSExtendedError
=
1942 (!SetFileTime( FILE_GetHandle(BX_reg(context
)),
1943 NULL
, NULL
, &filetime
));
1949 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1950 TRACE(int21
,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1952 switch (AL_reg(context
))
1955 AX_reg(context
) = 1;
1958 AX_reg(context
) = 0;
1964 RESET_CFLAG(context
);
1967 case 0x5a: /* CREATE TEMPORARY FILE */
1968 TRACE(int21
,"CREATE TEMPORARY FILE\n");
1969 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1972 case 0x5b: /* CREATE NEW FILE */
1973 TRACE(int21
,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context
),
1974 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1975 bSetDOSExtendedError
= ((AX_reg(context
) =
1976 _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)), 0 ))
1977 == (WORD
)HFILE_ERROR16
);
1980 case 0x5d: /* NETWORK */
1981 FIXME(int21
,"Function 0x%04x not implemented.\n", AX_reg (context
));
1982 /* Fix the following while you're at it. */
1983 SetLastError( ER_NoNetwork
);
1984 bSetDOSExtendedError
= TRUE
;
1988 bSetDOSExtendedError
= INT21_networkfunc (context
);
1991 case 0x5f: /* NETWORK */
1992 switch (AL_reg(context
))
1994 case 0x07: /* ENABLE DRIVE */
1995 TRACE(int21
,"ENABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1996 if (!DRIVE_Enable( DL_reg(context
) ))
1998 SetLastError( ERROR_INVALID_DRIVE
);
1999 bSetDOSExtendedError
= TRUE
;
2003 case 0x08: /* DISABLE DRIVE */
2004 TRACE(int21
,"DISABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
2005 if (!DRIVE_Disable( DL_reg(context
) ))
2007 SetLastError( ERROR_INVALID_DRIVE
);
2008 bSetDOSExtendedError
= TRUE
;
2013 /* network software not installed */
2014 TRACE(int21
,"NETWORK function AX=%04x not implemented\n",AX_reg(context
));
2015 SetLastError( ER_NoNetwork
);
2016 bSetDOSExtendedError
= TRUE
;
2021 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
2022 TRACE(int21
,"TRUENAME %s\n",
2023 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),ESI_reg(context
)));
2025 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2026 ESI_reg(context
)), 128,
2027 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2028 EDI_reg(context
)),NULL
))
2029 bSetDOSExtendedError
= TRUE
;
2030 else AX_reg(context
) = 0;
2034 case 0x61: /* UNUSED */
2035 case 0x63: /* misc. language support */
2036 switch (AL_reg(context
)) {
2037 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
2038 INT21_GetDBCSLeadTable(context
);
2042 case 0x64: /* OS/2 DOS BOX */
2043 INT_BARF( context
, 0x21 );
2047 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
2048 extern WORD WINE_LanguageId
;
2049 BYTE
*dataptr
=CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
));
2050 TRACE(int21
,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
2051 BX_reg(context
), DX_reg(context
));
2052 switch (AL_reg(context
)) {
2054 TRACE(int21
,"\tget general internationalization info\n");
2056 *(WORD
*)(dataptr
+1) = 41;
2057 *(WORD
*)(dataptr
+3) = WINE_LanguageId
;
2058 *(WORD
*)(dataptr
+5) = CodePage
;
2059 *(DWORD
*)(dataptr
+0x19) = 0; /* FIXME: ptr to case map routine */
2062 TRACE(int21
,"\tget pointer to collating sequence table\n");
2064 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
2065 CX_reg(context
) = 258;/*FIXME: size of table?*/
2068 TRACE(int21
,"\tunimplemented function %d\n",AL_reg(context
));
2069 INT_BARF( context
, 0x21 );
2075 case 0x66: /* GLOBAL CODE PAGE TABLE */
2076 switch (AL_reg(context
))
2079 TRACE(int21
,"GET GLOBAL CODE PAGE TABLE\n");
2080 DX_reg(context
) = BX_reg(context
) = CodePage
;
2081 RESET_CFLAG(context
);
2084 TRACE(int21
,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2085 BX_reg(context
),DX_reg(context
));
2086 CodePage
= BX_reg(context
);
2087 RESET_CFLAG(context
);
2092 case 0x67: /* SET HANDLE COUNT */
2093 TRACE(int21
,"SET HANDLE COUNT to %d\n",BX_reg(context
) );
2094 SetHandleCount16( BX_reg(context
) );
2095 if (GetLastError()) bSetDOSExtendedError
= TRUE
;
2098 case 0x68: /* "FFLUSH" - COMMIT FILE */
2099 case 0x6a: /* COMMIT FILE */
2100 TRACE(int21
,"FFLUSH/COMMIT handle %d\n",BX_reg(context
));
2101 bSetDOSExtendedError
= (!FlushFileBuffers( FILE_GetHandle(BX_reg(context
)) ));
2104 case 0x69: /* DISK SERIAL NUMBER */
2105 switch (AL_reg(context
))
2108 TRACE(int21
,"GET DISK SERIAL NUMBER for drive %s\n",
2109 INT21_DriveName(BL_reg(context
)));
2110 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2111 else AX_reg(context
) = 0;
2115 TRACE(int21
,"SET DISK SERIAL NUMBER for drive %s\n",
2116 INT21_DriveName(BL_reg(context
)));
2117 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2118 else AX_reg(context
) = 1;
2123 case 0x6C: /* Extended Open/Create*/
2124 TRACE(int21
,"EXTENDED OPEN/CREATE %s\n",
2125 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDI_reg(context
)));
2126 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2129 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2130 if ((GetVersion()&0xC0000004)!=0xC0000004) {
2131 /* not supported on anything but Win95 */
2132 TRACE(int21
,"LONG FILENAME functions supported only by win95\n");
2134 AL_reg(context
) = 0;
2136 switch(AL_reg(context
))
2138 case 0x39: /* Create directory */
2139 TRACE(int21
,"LONG FILENAME - MAKE DIRECTORY %s\n",
2140 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2141 bSetDOSExtendedError
= (!CreateDirectoryA(
2142 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2143 EDX_reg(context
) ), NULL
));
2145 case 0x3a: /* Remove directory */
2146 TRACE(int21
,"LONG FILENAME - REMOVE DIRECTORY %s\n",
2147 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2148 bSetDOSExtendedError
= (!RemoveDirectoryA(
2149 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2150 EDX_reg(context
) )));
2152 case 0x43: /* Get/Set file attributes */
2153 TRACE(int21
,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2154 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2155 switch (BL_reg(context
))
2157 case 0x00: /* Get file attributes */
2158 TRACE(int21
,"\tretrieve attributes\n");
2159 CX_reg(context
) = (WORD
)GetFileAttributesA(
2160 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2162 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
2165 TRACE(int21
,"\tset attributes 0x%04x\n",CX_reg(context
));
2166 bSetDOSExtendedError
= (!SetFileAttributesA(
2167 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2169 CX_reg(context
) ) );
2172 FIXME(int21
, "Unimplemented long file name function:\n");
2173 INT_BARF( context
, 0x21 );
2175 AL_reg(context
) = 0;
2179 case 0x47: /* Get current directory */
2180 TRACE(int21
," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2181 INT21_DriveName(DL_reg(context
)));
2182 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
2185 case 0x4e: /* Find first file */
2186 TRACE(int21
," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2187 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2188 /* FIXME: use attributes in CX */
2189 if ((AX_reg(context
) = FindFirstFile16(
2190 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
2191 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2193 == INVALID_HANDLE_VALUE16
)
2194 bSetDOSExtendedError
= TRUE
;
2196 case 0x4f: /* Find next file */
2197 TRACE(int21
,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2199 if (!FindNextFile16( BX_reg(context
),
2200 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2202 bSetDOSExtendedError
= TRUE
;
2204 case 0xa1: /* Find close */
2205 TRACE(int21
,"LONG FILENAME - FINDCLOSE for handle %d\n",
2207 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
2210 TRACE(int21
,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2211 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2214 switch(CL_reg(context
))
2216 case 0x01: /*Get short filename or path */
2217 if (!GetShortPathNameA
2218 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2220 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2221 EDI_reg(context
)), 67))
2222 bSetDOSExtendedError
= TRUE
;
2223 else AX_reg(context
) = 0;
2225 case 0x02: /*Get canonical long filename or path */
2226 if (!GetFullPathNameA
2227 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2228 ESI_reg(context
)), 128,
2229 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2230 EDI_reg(context
)),NULL
))
2231 bSetDOSExtendedError
= TRUE
;
2232 else AX_reg(context
) = 0;
2235 FIXME(int21
, "Unimplemented long file name function:\n");
2236 INT_BARF( context
, 0x21 );
2238 AL_reg(context
) = 0;
2242 case 0x6c: /* Create or open file */
2243 TRACE(int21
,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
2244 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
)));
2245 /* translate Dos 7 action to Dos 6 action */
2246 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2249 case 0x3b: /* Change directory */
2250 TRACE(int21
,"LONG FILENAME - CHANGE DIRECTORY %s\n",
2251 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
2252 if (!SetCurrentDirectoryA(CTX_SEG_OFF_TO_LIN(context
,
2258 AL_reg(context
) = GetLastError();
2261 case 0x41: /* Delete file */
2262 TRACE(int21
,"LONG FILENAME - DELETE FILE %s\n",
2263 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
2264 if (!DeleteFileA(CTX_SEG_OFF_TO_LIN(context
,
2269 AL_reg(context
) = GetLastError();
2272 case 0x56: /* Move (rename) file */
2273 TRACE(int21
,"LONG FILENAME - RENAME FILE %s to %s stub\n",
2274 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)),
2275 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), EDI_reg(context
)));
2277 FIXME(int21
, "Unimplemented long file name function:\n");
2278 INT_BARF( context
, 0x21 );
2280 AL_reg(context
) = 0;
2285 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2286 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2287 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2288 TRACE(int21
,"windows95 function AX %04x\n",
2290 WARN(int21
, " returning unimplemented\n");
2292 AL_reg(context
) = 0;
2295 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2296 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2300 INT_BARF( context
, 0x21 );
2303 } /* END OF SWITCH */
2305 if( bSetDOSExtendedError
) /* set general error condition */
2307 AX_reg(context
) = GetLastError();
2311 if ((EFL_reg(context
) & 0x0001))
2312 TRACE(int21
, "failed, error 0x%04lx\n", GetLastError() );
2314 TRACE(int21
, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2315 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2316 AX_reg(context
), BX_reg(context
), CX_reg(context
),
2317 DX_reg(context
), SI_reg(context
), DI_reg(context
),
2318 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
2322 FARPROC16 WINAPI
GetSetKernelDOSProc16(FARPROC16 DosProc
)
2324 FIXME(int21
, "(DosProc=0x%08x): stub\n", (UINT
)DosProc
);