2 * DOS interrupt 21h handler
14 #include <sys/types.h>
28 #if defined(__svr4__) || defined(_SCO_DS)
29 /* SVR4 DOESNT do locking the same way must implement properly */
36 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
38 /* Define the drive parameter block, as used by int21/1F
39 * and int21/32. This table can be accessed through the
40 * global 'dpb' pointer, which points into the local dos
45 BYTE drive_num
; /* 0=A, etc. */
46 BYTE unit_num
; /* Drive's unit number (?) */
47 WORD sector_size
; /* Sector size in bytes */
48 BYTE high_sector
; /* Highest sector in a cluster */
49 BYTE shift
; /* Shift count (?) */
50 WORD reserved
; /* Number of reserved sectors at start */
51 BYTE num_FAT
; /* Number of FATs */
52 WORD dir_entries
; /* Number of root dir entries */
53 WORD first_data
; /* First data sector */
54 WORD high_cluster
; /* Highest cluster number */
55 WORD sectors_in_FAT
; /* Number of sectors per FAT */
56 WORD start_dir
; /* Starting sector of first dir */
57 DWORD driver_head
; /* Address of device driver header (?) */
58 BYTE media_ID
; /* Media ID */
59 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
60 DWORD next
; /* Pointer to next DPB in list */
61 WORD free_search
; /* Free cluster search start */
62 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
74 static struct DosHeap
*heap
;
75 static WORD DosHeapHandle
;
77 WORD sharing_retries
= 3; /* number of retries at sharing violation */
78 WORD sharing_pause
= 1; /* pause between retries */
80 extern char TempDirectory
[];
82 static BOOL32
INT21_CreateHeap(void)
84 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
86 fprintf( stderr
, "INT21_Init: Out of memory\n");
89 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
90 dpbsegptr
= PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
92 strcpy(heap
->biosdate
, "01/01/80");
96 static BYTE
*GetCurrentDTA(void)
98 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
99 return (BYTE
*)PTR_SEG_TO_LIN( pTask
->dta
);
103 void CreateBPB(int drive
, BYTE
*data
)
108 setword(&data
[3], 0);
110 setword(&data
[6], 240);
111 setword(&data
[8], 64000);
113 setword(&data
[0x0b], 40);
114 setword(&data
[0x0d], 56);
115 setword(&data
[0x0f], 2);
116 setword(&data
[0x11], 0);
117 setword(&data
[0x1f], 800);
119 setword(&data
[0x22], 1);
120 } else { /* 1.44mb */
123 setword(&data
[3], 0);
125 setword(&data
[6], 240);
126 setword(&data
[8], 2880);
128 setword(&data
[0x0b], 6);
129 setword(&data
[0x0d], 18);
130 setword(&data
[0x0f], 2);
131 setword(&data
[0x11], 0);
132 setword(&data
[0x1f], 80);
134 setword(&data
[0x22], 2);
138 static int INT21_GetFreeDiskSpace( CONTEXT
*context
)
140 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
141 char root
[] = "A:\\";
143 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
144 if (!GetDiskFreeSpace32A( root
, &cluster_sectors
, §or_bytes
,
145 &free_clusters
, &total_clusters
)) return 0;
146 AX_reg(context
) = cluster_sectors
;
147 BX_reg(context
) = free_clusters
;
148 CX_reg(context
) = sector_bytes
;
149 DX_reg(context
) = total_clusters
;
153 static int INT21_GetDriveAllocInfo( CONTEXT
*context
)
155 if (!INT21_GetFreeDiskSpace( context
)) return 0;
156 if (!heap
&& !INT21_CreateHeap()) return 0;
157 heap
->mediaID
= 0xf0;
158 DS_reg(context
) = DosHeapHandle
;
159 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
163 static void GetDrivePB( CONTEXT
*context
, int drive
)
165 if(!DRIVE_IsValid(drive
))
167 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
168 AX_reg(context
) = 0x00ff;
170 else if (heap
|| INT21_CreateHeap())
172 dprintf_fixme(int, "int21: GetDrivePB not fully implemented.\n");
174 /* FIXME: I have no idea what a lot of this information should
175 * say or whether it even really matters since we're not allowing
176 * direct block access. However, some programs seem to depend on
177 * getting at least _something_ back from here. The 'next' pointer
178 * does worry me, though. Should we have a complete table of
179 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
181 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
182 heap
->dpb
.sector_size
= 512;
183 heap
->dpb
.high_sector
= 1;
184 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
185 heap
->dpb
.reserved
= 0;
186 heap
->dpb
.num_FAT
= 1;
187 heap
->dpb
.dir_entries
= 2;
188 heap
->dpb
.first_data
= 2;
189 heap
->dpb
.high_cluster
= 64000;
190 heap
->dpb
.sectors_in_FAT
= 1;
191 heap
->dpb
.start_dir
= 1;
192 heap
->dpb
.driver_head
= 0;
193 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
194 heap
->dpb
.access_flag
= 0;
196 heap
->dpb
.free_search
= 0;
197 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
199 AL_reg(context
) = 0x00;
200 DS_reg(context
) = SELECTOROF(dpbsegptr
);
201 BX_reg(context
) = OFFSETOF(dpbsegptr
);
206 static void ioctlGetDeviceInfo( CONTEXT
*context
)
209 dprintf_info(int, "int21: ioctl (%d, GetDeviceInfo)\n", BX_reg(context
));
211 curr_drive
= DRIVE_GetCurrentDrive();
212 DX_reg(context
) = 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0); /* no floppy */
213 /* bits 0-5 are current drive
214 * bit 6 - file has NOT been written..FIXME: correct?
215 * bit 8 - generate int24 if no diskspace on write/ read past end of file
216 * bit 11 - media not removable
218 RESET_CFLAG(context
);
221 static BOOL32
ioctlGenericBlkDevReq( CONTEXT
*context
)
223 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
224 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
226 if (!DRIVE_IsValid(drive
))
228 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
232 if (CH_reg(context
) != 0x08)
234 INT_BARF( context
, 0x21 );
238 switch (CL_reg(context
))
240 case 0x4a: /* lock logical volume */
241 dprintf_info(int,"int21: lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
244 case 0x60: /* get device parameters */
245 /* used by w4wgrp's winfile */
246 memset(dataptr
, 0, 0x26);
248 dataptr
[6] = 0; /* media type */
251 dataptr
[1] = 0x05; /* fixed disk */
252 setword(&dataptr
[2], 0x01); /* non removable */
253 setword(&dataptr
[4], 0x300); /* # of cylinders */
257 dataptr
[1] = 0x07; /* block dev, floppy */
258 setword(&dataptr
[2], 0x02); /* removable */
259 setword(&dataptr
[4], 80); /* # of cylinders */
261 CreateBPB(drive
, &dataptr
[7]);
262 RESET_CFLAG(context
);
265 case 0x66:/* get disk serial number */
267 char label
[12],fsname
[9],path
[4];
270 strcpy(path
,"x:\\");path
[0]=drive
+'A';
271 GetVolumeInformation32A(
272 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
275 memcpy(dataptr
+2,&serial
,4);
276 memcpy(dataptr
+6,label
,11);
277 memcpy(dataptr
+17,fsname
,8);
282 dprintf_info(int,"int21: logical volume %d unlocked.\n",drive
);
286 INT_BARF( context
, 0x21 );
291 static void INT21_GetSystemDate( CONTEXT
*context
)
294 GetLocalTime( &systime
);
295 CX_reg(context
) = systime
.wYear
;
296 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
297 AX_reg(context
) = systime
.wDayOfWeek
;
300 static void INT21_GetSystemTime( CONTEXT
*context
)
303 GetLocalTime( &systime
);
304 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
305 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
308 static BOOL32
INT21_CreateFile( CONTEXT
*context
)
310 AX_reg(context
) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
311 DX_reg(context
) ), CX_reg(context
) );
312 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
316 static void OpenExistingFile( CONTEXT
*context
)
318 AX_reg(context
) = _lopen16( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
320 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
322 AX_reg(context
) = DOS_ExtendedError
;
331 switch (AX_reg(context
) & 0x0070)
333 case 0x00: /* compatability mode */
334 case 0x40: /* DENYNONE */
338 case 0x30: /* DENYREAD */
340 "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
341 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)));
342 case 0x10: /* DENYALL */
346 case 0x20: /* DENYWRITE */
357 int result
,retries
=sharing_retries
;
359 #if defined(__svr4__) || defined(_SCO_DS)
360 printf("Should call flock and needs porting to lockf\n");
364 result
= flock(handle
, lock
| LOCK_NB
);
366 if ( retries
&& (!result
) )
369 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
370 result
++; /* stop the optimizer */
371 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
375 while( (!result
) && (!(retries
--)) );
380 AX_reg(context
) = DOS_ExtendedError
;
389 AX_reg(context
) = handle
;
390 RESET_CFLAG(context
);
395 static void CloseFile( CONTEXT
*context
)
397 if ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0)
399 AX_reg(context
) = DOS_ExtendedError
;
404 static BOOL32
INT21_ExtendedOpenCreateFile(CONTEXT
*context
)
406 BOOL32 bExtendedError
= FALSE
;
407 BYTE action
= DL_reg(context
);
409 /* Shuffle arguments to call OpenExistingFile */
410 AL_reg(context
) = BL_reg(context
);
411 DX_reg(context
) = SI_reg(context
);
412 /* BX,CX and DX should be preserved */
413 OpenExistingFile(context
);
415 if ((EFL_reg(context
) & 0x0001) == 0) /* File exists */
417 UINT16 uReturnCX
= 0;
419 /* Now decide what do do */
421 if ((action
& 0x07) == 0)
423 BX_reg(context
) = AX_reg(context
);
425 AX_reg(context
) = 0x0050; /*File exists*/
427 dprintf_warn(int, "int21: extended open/create: failed because file exists \n");
429 else if ((action
& 0x07) == 2)
431 /* Truncate it, but first check if opened for write */
432 if ((BL_reg(context
) & 0x0007)== 0)
434 BX_reg(context
) = AX_reg(context
);
436 dprintf_warn(int, "int21: extended open/create: failed, trunc on ro file\n");
437 AX_reg(context
) = 0x000C; /*Access code invalid*/
442 /* Shuffle arguments to call CloseFile while
443 * preserving BX and DX */
445 dprintf_info(int, "int21: extended open/create: Closing before truncate\n");
446 BX_reg(context
) = AX_reg(context
);
448 if (EFL_reg(context
) & 0x0001)
450 dprintf_warn(int, "int21: extended open/create: close before trunc failed\n");
451 AX_reg(context
) = 0x0019; /*Seek Error*/
455 /* Shuffle arguments to call CreateFile */
457 dprintf_info(int, "int21: extended open/create: Truncating\n");
458 AL_reg(context
) = BL_reg(context
);
459 /* CX is still the same */
460 DX_reg(context
) = SI_reg(context
);
461 bExtendedError
= INT21_CreateFile(context
);
463 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
465 dprintf_warn(int, "int21: extended open/create: trunc failed\n");
466 return bExtendedError
;
471 else uReturnCX
= 0x1;
473 CX_reg(context
) = uReturnCX
;
475 else /* file does not exist */
477 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
478 if ((action
& 0xF0)== 0)
482 dprintf_warn(int, "int21: extended open/create: failed, file dosen't exist\n");
486 /* Shuffle arguments to call CreateFile */
487 dprintf_info(int, "int21: extended open/create: Creating\n");
488 AL_reg(context
) = BL_reg(context
);
489 /* CX should still be the same */
490 DX_reg(context
) = SI_reg(context
);
491 bExtendedError
= INT21_CreateFile(context
);
492 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
494 dprintf_warn(int, "int21: extended open/create: create failed\n");
495 return bExtendedError
;
501 return bExtendedError
;
505 static BOOL32
INT21_ChangeDir( CONTEXT
*context
)
508 char *dirname
= PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
));
510 dprintf_info(int,"int21: changedir %s\n", dirname
);
511 if (dirname
[0] && (dirname
[1] == ':'))
513 drive
= toupper(dirname
[0]) - 'A';
516 else drive
= DRIVE_GetCurrentDrive();
517 return DRIVE_Chdir( drive
, dirname
);
521 static int INT21_FindFirst( CONTEXT
*context
)
525 DOS_FULL_NAME full_name
;
526 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
528 path
= (const char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
529 dta
->unixPath
= NULL
;
530 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
532 AX_reg(context
) = DOS_ExtendedError
;
536 dta
->unixPath
= HEAP_strdupA( GetProcessHeap(), 0, full_name
.long_name
);
537 p
= strrchr( dta
->unixPath
, '/' );
540 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
541 * (doesn't matter as it is set below anyway)
543 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
545 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
546 dta
->unixPath
= NULL
;
547 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
548 AX_reg(context
) = ER_FileNotFound
;
552 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
553 : DRIVE_GetCurrentDrive();
555 dta
->search_attr
= CL_reg(context
);
560 static int INT21_FindNext( CONTEXT
*context
)
562 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
563 WIN32_FIND_DATA32A entry
;
566 if (!dta
->unixPath
) return 0;
567 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
568 dta
->search_attr
, dta
->count
, &entry
)))
570 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
571 dta
->unixPath
= NULL
;
574 if ((int)dta
->count
+ count
> 0xffff)
576 fprintf( stderr
, "Too many directory entries in %s\n", dta
->unixPath
);
577 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
578 dta
->unixPath
= NULL
;
582 dta
->fileattr
= entry
.dwFileAttributes
;
583 dta
->filesize
= entry
.nFileSizeLow
;
584 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
585 &dta
->filedate
, &dta
->filetime
);
586 strcpy( dta
->filename
, entry
.cAlternateFileName
);
591 static BOOL32
INT21_CreateTempFile( CONTEXT
*context
)
593 static int counter
= 0;
594 char *name
= PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
) );
595 char *p
= name
+ strlen(name
);
597 /* despite what Ralf Brown says, some programs seem to call without
598 * ending backslash (DOS accepts that, so we accept it too) */
599 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
603 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
604 counter
= (counter
+ 1) % 1000;
606 if ((AX_reg(context
) = _lcreat_uniq( name
, 0 )) != (WORD
)HFILE_ERROR16
)
608 dprintf_info(int, "INT21_CreateTempFile: created %s\n", name
);
611 if (DOS_ExtendedError
!= ER_FileExists
) return FALSE
;
616 static BOOL32
INT21_GetCurrentDirectory( CONTEXT
*context
)
618 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
619 char *ptr
= (char *)PTR_SEG_OFF_TO_LIN( DS_reg(context
), SI_reg(context
) );
621 if (!DRIVE_IsValid(drive
))
623 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
626 lstrcpyn32A( ptr
, DRIVE_GetDosCwd(drive
), 64 );
627 AX_reg(context
) = 0x0100; /* success return code */
632 static int INT21_GetDiskSerialNumber( CONTEXT
*context
)
634 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
635 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
637 if (!DRIVE_IsValid(drive
))
639 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
643 *(WORD
*)dataptr
= 0;
644 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
645 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
646 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
651 static int INT21_SetDiskSerialNumber( CONTEXT
*context
)
653 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
654 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
656 if (!DRIVE_IsValid(drive
))
658 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
662 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
667 /* microsoft's programmers should be shot for using CP/M style int21
668 calls in Windows for Workgroup's winfile.exe */
670 static int INT21_FindFirstFCB( CONTEXT
*context
)
672 BYTE
*fcb
= (BYTE
*)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
677 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
678 else pFCB
= (FINDFILE_FCB
*)fcb
;
679 drive
= DOS_GET_DRIVE( pFCB
->drive
);
680 root
= DRIVE_GetRoot( drive
);
681 cwd
= DRIVE_GetUnixCwd( drive
);
682 pFCB
->unixPath
= HeapAlloc( GetProcessHeap(), 0,
683 strlen(root
)+strlen(cwd
)+2 );
684 if (!pFCB
->unixPath
) return 0;
685 strcpy( pFCB
->unixPath
, root
);
686 strcat( pFCB
->unixPath
, "/" );
687 strcat( pFCB
->unixPath
, cwd
);
693 static int INT21_FindNextFCB( CONTEXT
*context
)
695 BYTE
*fcb
= (BYTE
*)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
697 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA();
698 WIN32_FIND_DATA32A entry
;
702 if (*fcb
== 0xff) /* extended FCB ? */
705 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
710 pFCB
= (FINDFILE_FCB
*)fcb
;
713 if (!pFCB
->unixPath
) return 0;
714 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
715 DOS_GET_DRIVE( pFCB
->drive
), attr
,
716 pFCB
->count
, &entry
)))
718 HeapFree( GetProcessHeap(), 0, pFCB
->unixPath
);
719 pFCB
->unixPath
= NULL
;
722 pFCB
->count
+= count
;
724 if (*fcb
== 0xff) { /* place extended FCB header before pResult if called with extended FCB */
725 *(BYTE
*)pResult
= 0xff;
726 (BYTE
*)pResult
+=6; /* leave reserved field behind */
727 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
730 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
732 pResult
->fileattr
= entry
.dwFileAttributes
;
733 pResult
->cluster
= 0; /* what else? */
734 pResult
->filesize
= entry
.nFileSizeLow
;
735 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
736 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
737 &pResult
->filedate
, &pResult
->filetime
);
739 /* Convert file name to FCB format */
741 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
742 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
743 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
744 pResult
->filename
[0] = pResult
->filename
[1] = '.';
747 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
748 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
750 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
751 MIN( (p
- entry
.cAlternateFileName
), 8 ) );
752 memcpy( pResult
->filename
+ 8, p
+ 1, MIN( strlen(p
), 3 ) );
755 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
756 MIN( strlen(entry
.cAlternateFileName
), 8 ) );
762 static void DeleteFileFCB( CONTEXT
*context
)
764 fprintf( stderr
, "DeleteFileFCB: not implemented yet\n" );
767 static void RenameFileFCB( CONTEXT
*context
)
769 fprintf( stderr
, "RenameFileFCB: not implemented yet\n" );
774 static void fLock( CONTEXT
* context
)
777 switch ( AX_reg(context
) & 0xff )
779 case 0x00: /* LOCK */
780 if (!LockFile(BX_reg(context
),
781 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
782 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
783 AX_reg(context
) = DOS_ExtendedError
;
788 case 0x01: /* UNLOCK */
789 if (!UnlockFile(BX_reg(context
),
790 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
791 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
792 AX_reg(context
) = DOS_ExtendedError
;
797 AX_reg(context
) = 0x0001;
804 extern void LOCAL_PrintHeap (WORD ds
);
806 /***********************************************************************
807 * DOS3Call (KERNEL.102)
809 void WINAPI
DOS3Call( CONTEXT
*context
)
811 BOOL32 bSetDOSExtendedError
= FALSE
;
813 dprintf_info(int, "int21: AX=%04x BX=%04x CX=%04x DX=%04x "
814 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
815 AX_reg(context
), BX_reg(context
), CX_reg(context
),
816 DX_reg(context
), SI_reg(context
), DI_reg(context
),
817 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
820 if (AH_reg(context
) == 0x59) /* Get extended error info */
822 AX_reg(context
) = DOS_ExtendedError
;
823 BH_reg(context
) = DOS_ErrorClass
;
824 BL_reg(context
) = DOS_ErrorAction
;
825 CH_reg(context
) = DOS_ErrorLocus
;
829 DOS_ERROR( 0, 0, 0, 0 );
830 RESET_CFLAG(context
); /* Not sure if this is a good idea */
832 switch(AH_reg(context
))
834 case 0x00: /* TERMINATE PROGRAM */
835 TASK_KillCurrentTask( 0 );
838 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
839 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
840 case 0x03: /* READ CHARACTER FROM STDAUX */
841 case 0x04: /* WRITE CHARACTER TO STDAUX */
842 case 0x05: /* WRITE CHARACTER TO PRINTER */
843 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
844 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
845 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
846 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
847 case 0x0a: /* BUFFERED INPUT */
848 case 0x0b: /* GET STDIN STATUS */
849 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
850 case 0x0f: /* OPEN FILE USING FCB */
851 case 0x10: /* CLOSE FILE USING FCB */
852 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
853 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
854 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
855 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
856 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
857 case 0x23: /* GET FILE SIZE FOR FCB */
858 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
859 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
860 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
861 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
862 case 0x29: /* PARSE FILENAME INTO FCB */
863 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
864 "SWITCHAR" - SET SWITCH CHARACTER
865 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
866 case 0x54: /* GET VERIFY FLAG */
867 INT_BARF( context
, 0x21 );
869 case 0x2e: /* SET VERIFY FLAG */
870 /* we cannot change the behaviour anyway, so just ignore it */
873 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
877 case 0x6b: /* NULL FUNCTION */
881 case 0x5c: /* "FLOCK" - RECORD LOCKING */
885 case 0x0d: /* DISK BUFFER FLUSH */
886 RESET_CFLAG(context
); /* dos 6+ only */
889 case 0x0e: /* SELECT DEFAULT DRIVE */
890 DRIVE_SetCurrentDrive( DL_reg(context
) );
891 AL_reg(context
) = MAX_DOS_DRIVES
;
894 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
895 if (!INT21_FindFirstFCB(context
))
897 AL_reg(context
) = 0xff;
900 /* else fall through */
902 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
903 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
906 case 0x13: /* DELETE FILE USING FCB */
907 DeleteFileFCB(context
);
910 case 0x17: /* RENAME FILE USING FCB */
911 RenameFileFCB(context
);
914 case 0x19: /* GET CURRENT DEFAULT DRIVE */
915 AL_reg(context
) = DRIVE_GetCurrentDrive();
918 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
920 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
921 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(context
),DX_reg(context
));
922 dprintf_info(int, "int21: Set DTA: %08lx\n", pTask
->dta
);
926 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
928 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
931 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
932 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
935 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
936 GetDrivePB(context
, DRIVE_GetCurrentDrive());
939 case 0x25: /* SET INTERRUPT VECTOR */
940 INT_SetHandler( AL_reg(context
),
941 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
945 case 0x2a: /* GET SYSTEM DATE */
946 INT21_GetSystemDate(context
);
949 case 0x2b: /* SET SYSTEM DATE */
950 fprintf( stdnimp
, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
951 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
952 AL_reg(context
) = 0; /* Let's pretend we succeeded */
955 case 0x2c: /* GET SYSTEM TIME */
956 INT21_GetSystemTime(context
);
959 case 0x2d: /* SET SYSTEM TIME */
960 fprintf( stdnimp
, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
961 CH_reg(context
), CL_reg(context
),
962 DH_reg(context
), DL_reg(context
) );
963 AL_reg(context
) = 0; /* Let's pretend we succeeded */
966 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
968 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
969 ES_reg(context
) = SELECTOROF( pTask
->dta
);
970 BX_reg(context
) = OFFSETOF( pTask
->dta
);
974 case 0x30: /* GET DOS VERSION */
975 AX_reg(context
) = (HIWORD(GetVersion16()) >> 8) |
976 (HIWORD(GetVersion16()) << 8);
977 BX_reg(context
) = 0x0012; /* 0x123456 is Wine's serial # */
978 CX_reg(context
) = 0x3456;
981 case 0x31: /* TERMINATE AND STAY RESIDENT */
982 INT_BARF( context
, 0x21 );
985 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
986 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
989 case 0x33: /* MULTIPLEXED */
990 switch (AL_reg(context
))
992 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
996 case 0x01: /* SET EXTENDED BREAK STATE */
999 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1000 DL_reg(context
) = 0;
1003 case 0x05: /* GET BOOT DRIVE */
1004 DL_reg(context
) = 3;
1005 /* c: is Wine's bootdrive (a: is 1)*/
1008 case 0x06: /* GET TRUE VERSION NUMBER */
1009 BX_reg(context
) = (HIWORD(GetVersion16() >> 8)) |
1010 (HIWORD(GetVersion16() << 8));
1011 DX_reg(context
) = 0x00;
1015 INT_BARF( context
, 0x21 );
1020 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1021 if (!heap
) INT21_CreateHeap();
1022 ES_reg(context
) = DosHeapHandle
;
1023 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1026 case 0x35: /* GET INTERRUPT VECTOR */
1028 FARPROC16 addr
= INT_GetHandler( AL_reg(context
) );
1029 ES_reg(context
) = SELECTOROF(addr
);
1030 BX_reg(context
) = OFFSETOF(addr
);
1034 case 0x36: /* GET FREE DISK SPACE */
1035 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1038 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1039 AX_reg(context
) = 0x02; /* no country support available */
1043 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1044 bSetDOSExtendedError
= (!CreateDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1045 DX_reg(context
) ), NULL
));
1048 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1049 bSetDOSExtendedError
= (!RemoveDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1050 DX_reg(context
) )));
1053 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1054 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1057 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1058 AX_reg(context
) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1059 DX_reg(context
) ), CX_reg(context
) );
1060 bSetDOSExtendedError
= (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
1063 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1064 OpenExistingFile(context
);
1067 case 0x3e: /* "CLOSE" - CLOSE FILE */
1068 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1071 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1073 LONG result
= WIN16_hread( BX_reg(context
),
1074 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1077 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1078 else AX_reg(context
) = (WORD
)result
;
1082 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1084 LONG result
= _hwrite16( BX_reg(context
),
1085 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1088 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1089 else AX_reg(context
) = (WORD
)result
;
1093 case 0x41: /* "UNLINK" - DELETE FILE */
1094 bSetDOSExtendedError
= (!DeleteFile32A( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1095 DX_reg(context
) )));
1098 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1100 LONG status
= _llseek16( BX_reg(context
),
1101 MAKELONG(DX_reg(context
),CX_reg(context
)),
1103 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1106 AX_reg(context
) = LOWORD(status
);
1107 DX_reg(context
) = HIWORD(status
);
1112 case 0x43: /* FILE ATTRIBUTES */
1113 switch (AL_reg(context
))
1116 AX_reg(context
) = (WORD
)GetFileAttributes32A(
1117 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1119 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1120 else CX_reg(context
) = AX_reg(context
);
1124 bSetDOSExtendedError
=
1125 (!SetFileAttributes32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1132 case 0x44: /* IOCTL */
1133 switch (AL_reg(context
))
1136 ioctlGetDeviceInfo(context
);
1141 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1142 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
));
1144 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1146 fprintf(stdnimp
,"int21: program tried to write to block device control channel of drive %d:\n",drive
);
1147 for (i
=0;i
<CX_reg(context
);i
++)
1148 fprintf(stdnimp
,"%02x ",dataptr
[i
]);
1149 fprintf(stdnimp
,"\n");
1150 AX_reg(context
)=CX_reg(context
);
1153 case 0x08: /* Check if drive is removable. */
1154 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1156 case DRIVE_CANNOTDETERMINE
:
1157 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1158 AX_reg(context
) = ER_InvalidDrive
;
1161 case DRIVE_REMOVABLE
:
1162 AX_reg(context
) = 0; /* removable */
1165 AX_reg(context
) = 1; /* not removable */
1170 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1171 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1173 case DRIVE_CANNOTDETERMINE
:
1174 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1175 AX_reg(context
) = ER_InvalidDrive
;
1179 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1182 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1187 case 0x0a: /* check if handle (BX) is remote */
1188 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1191 DX_reg(context
) = 0;
1194 case 0x0b: /* SET SHARING RETRY COUNT */
1195 if (!CX_reg(context
))
1197 AX_reg(context
) = 1;
1201 sharing_pause
= CX_reg(context
);
1202 if (!DX_reg(context
))
1203 sharing_retries
= DX_reg(context
);
1204 RESET_CFLAG(context
);
1208 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1211 case 0x0e: /* get logical drive mapping */
1212 AL_reg(context
) = 0; /* drive has no mapping - FIXME: may be wrong*/
1215 case 0x0F: /* Set logical drive mapping */
1218 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1219 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1222 AX_reg(context
) = 0x000F; /* invalid drive */
1228 INT_BARF( context
, 0x21 );
1233 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1234 bSetDOSExtendedError
= ((AX_reg(context
) = FILE_Dup(BX_reg(context
))) == (WORD
)HFILE_ERROR16
);
1237 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1238 bSetDOSExtendedError
= (FILE_Dup2( BX_reg(context
), CX_reg(context
) ) == HFILE_ERROR32
);
1241 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1242 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1245 case 0x48: /* ALLOCATE MEMORY */
1246 case 0x49: /* FREE MEMORY */
1247 case 0x4a: /* RESIZE MEMORY BLOCK */
1248 INT_BARF( context
, 0x21 );
1251 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1252 AX_reg(context
) = WinExec16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1255 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1258 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1259 TASK_KillCurrentTask( AL_reg(context
) );
1262 case 0x4d: /* GET RETURN CODE */
1263 AX_reg(context
) = 0; /* normal exit */
1266 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1267 if (!INT21_FindFirst(context
)) break;
1270 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1271 if (!INT21_FindNext(context
))
1273 DOS_ERROR( ER_NoMoreFiles
, EC_MediaError
, SA_Abort
, EL_Disk
);
1274 AX_reg(context
) = ER_NoMoreFiles
;
1277 else AX_reg(context
) = 0; /* OK */
1280 case 0x51: /* GET PSP ADDRESS */
1281 case 0x62: /* GET PSP ADDRESS */
1282 /* FIXME: should we return the original DOS PSP upon */
1283 /* Windows startup ? */
1284 BX_reg(context
) = GetCurrentPDB();
1287 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1288 ES_reg(context
) = 0x0;
1289 BX_reg(context
) = 0x0;
1290 INT_BARF( context
, 0x21 );
1293 case 0x56: /* "RENAME" - RENAME FILE */
1294 bSetDOSExtendedError
=
1295 (!MoveFile32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
1296 PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
))));
1299 case 0x57: /* FILE DATE AND TIME */
1300 switch (AL_reg(context
))
1302 case 0x00: /* Get */
1305 if (!GetFileTime( BX_reg(context
), NULL
, NULL
, &filetime
))
1306 bSetDOSExtendedError
= TRUE
;
1307 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1312 case 0x01: /* Set */
1315 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1317 bSetDOSExtendedError
=
1318 (!SetFileTime( BX_reg(context
), NULL
, NULL
, &filetime
));
1324 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1325 switch (AL_reg(context
))
1328 AX_reg(context
) = 1;
1331 AX_reg(context
) = 0;
1337 RESET_CFLAG(context
);
1340 case 0x5a: /* CREATE TEMPORARY FILE */
1341 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1344 case 0x5b: /* CREATE NEW FILE */
1345 bSetDOSExtendedError
= ((AX_reg(context
) =
1346 _lcreat_uniq( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)), 0 ))
1347 == (WORD
)HFILE_ERROR16
);
1350 case 0x5d: /* NETWORK */
1352 /* network software not installed */
1353 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1354 bSetDOSExtendedError
= TRUE
;
1357 case 0x5f: /* NETWORK */
1358 switch (AL_reg(context
))
1360 case 0x07: /* ENABLE DRIVE */
1361 if (!DRIVE_Enable( DL_reg(context
) ))
1363 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1364 bSetDOSExtendedError
= TRUE
;
1368 case 0x08: /* DISABLE DRIVE */
1369 if (!DRIVE_Disable( DL_reg(context
) ))
1371 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1372 bSetDOSExtendedError
= TRUE
;
1377 /* network software not installed */
1378 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1379 bSetDOSExtendedError
= TRUE
;
1384 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1386 if (!GetFullPathName32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1387 SI_reg(context
)), 128,
1388 PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1389 DI_reg(context
)),NULL
))
1390 bSetDOSExtendedError
= TRUE
;
1391 else AX_reg(context
) = 0;
1395 case 0x61: /* UNUSED */
1396 case 0x63: /* UNUSED */
1397 case 0x64: /* OS/2 DOS BOX */
1398 INT_BARF( context
, 0x21 );
1402 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1403 extern WORD WINE_LanguageId
;
1404 BYTE
*dataptr
=PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
));;
1405 switch (AL_reg(context
)) {
1408 *(WORD
*)(dataptr
+1) = 41;
1409 *(WORD
*)(dataptr
+3) = WINE_LanguageId
;
1410 *(WORD
*)(dataptr
+5) = CodePage
;
1414 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
1415 CX_reg(context
) = 258;/*FIXME: size of table?*/
1418 INT_BARF( context
, 0x21 );
1424 case 0x66: /* GLOBAL CODE PAGE TABLE */
1425 switch (AL_reg(context
))
1428 DX_reg(context
) = BX_reg(context
) = CodePage
;
1429 RESET_CFLAG(context
);
1432 CodePage
= BX_reg(context
);
1433 RESET_CFLAG(context
);
1438 case 0x67: /* SET HANDLE COUNT */
1439 SetHandleCount16( BX_reg(context
) );
1440 if (DOS_ExtendedError
) bSetDOSExtendedError
= TRUE
;
1443 case 0x68: /* "FFLUSH" - COMMIT FILE */
1444 case 0x6a: /* COMMIT FILE */
1445 bSetDOSExtendedError
= (!FlushFileBuffers( BX_reg(context
) ));
1448 case 0x69: /* DISK SERIAL NUMBER */
1449 switch (AL_reg(context
))
1452 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1453 else AX_reg(context
) = 0;
1457 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1458 else AX_reg(context
) = 1;
1463 case 0x6C: /* Extended Open/Create*/
1464 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
1467 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1468 switch(AL_reg(context
))
1470 case 0x39: /* Create directory */
1471 bSetDOSExtendedError
= (!CreateDirectory32A(
1472 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1473 DX_reg(context
) ), NULL
));
1475 case 0x3a: /* Remove directory */
1476 bSetDOSExtendedError
= (!RemoveDirectory32A(
1477 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1478 DX_reg(context
) )));
1480 case 0x43: /* Get/Set file attributes */
1481 switch (BL_reg(context
))
1483 case 0x00: /* Get file attributes */
1484 CX_reg(context
) = (WORD
)GetFileAttributes32A(
1485 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1487 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1490 bSetDOSExtendedError
= (!SetFileAttributes32A(
1491 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1493 CX_reg(context
) ) );
1497 "Unimplemented int21 long file name function:\n");
1498 INT_BARF( context
, 0x21 );
1500 AL_reg(context
) = 0;
1504 case 0x47: /* Get current directory */
1505 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1508 case 0x4e: /* Find first file */
1509 /* FIXME: use attributes in CX */
1510 if ((AX_reg(context
) = FindFirstFile16(
1511 PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
1512 (WIN32_FIND_DATA32A
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1514 == INVALID_HANDLE_VALUE16
)
1515 bSetDOSExtendedError
= TRUE
;
1517 case 0x4f: /* Find next file */
1518 if (!FindNextFile16( BX_reg(context
),
1519 (WIN32_FIND_DATA32A
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1521 bSetDOSExtendedError
= TRUE
;
1523 case 0xa1: /* Find close */
1524 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
1529 switch(CL_reg(context
))
1531 case 0x02: /*Get canonical long filename or path */
1532 if (!GetFullPathName32A
1533 ( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1534 SI_reg(context
)), 128,
1535 PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1536 DI_reg(context
)),NULL
))
1537 bSetDOSExtendedError
= TRUE
;
1538 else AX_reg(context
) = 0;
1542 "Unimplemented int21 long file name function:\n");
1543 INT_BARF( context
, 0x21 );
1545 AL_reg(context
) = 0;
1549 case 0x6c: /* Create or open file */
1550 /* translate Dos 7 action to Dos 6 action */
1551 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
1554 case 0x3b: /* Change directory */
1555 if (!SetCurrentDirectory32A(PTR_SEG_OFF_TO_LIN(
1561 AL_reg(context
) = DOS_ExtendedError
;
1564 case 0x41: /* Delete file */
1565 if (!DeleteFile32A(PTR_SEG_OFF_TO_LIN(
1570 AL_reg(context
) = DOS_ExtendedError
;
1573 case 0x56: /* Move (rename) file */
1575 fprintf( stderr
, "Unimplemented int21 long file name function:\n");
1576 INT_BARF( context
, 0x21 );
1578 AL_reg(context
) = 0;
1583 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
1584 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
1585 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
1586 dprintf_info(int,"int21: windows95 function AX %04x\n",
1588 dprintf_warn(int, " returning unimplemented\n");
1590 AL_reg(context
) = 0;
1593 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1594 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1598 INT_BARF( context
, 0x21 );
1601 } /* END OF SWITCH */
1603 if( bSetDOSExtendedError
) /* set general error condition */
1605 AX_reg(context
) = DOS_ExtendedError
;
1609 dprintf_info(int, "ret21: AX=%04x BX=%04x CX=%04x DX=%04x "
1610 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1611 AX_reg(context
), BX_reg(context
), CX_reg(context
),
1612 DX_reg(context
), SI_reg(context
), DI_reg(context
),
1613 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
1617 FARPROC16 WINAPI
GetSetKernelDOSProc(FARPROC16 DosProc
)
1619 fprintf(stderr
, "GetSetKernelDOSProc(DosProc: %08x);\n", (UINT32
)DosProc
);