2 * DOS interrupt 21h handler
14 #include <sys/types.h>
29 #if defined(__svr4__) || defined(_SCO_DS)
30 /* SVR4 DOESNT do locking the same way must implement properly */
37 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
39 /* Define the drive parameter block, as used by int21/1F
40 * and int21/32. This table can be accessed through the
41 * global 'dpb' pointer, which points into the local dos
46 BYTE drive_num
; /* 0=A, etc. */
47 BYTE unit_num
; /* Drive's unit number (?) */
48 WORD sector_size
; /* Sector size in bytes */
49 BYTE high_sector
; /* Highest sector in a cluster */
50 BYTE shift
; /* Shift count (?) */
51 WORD reserved
; /* Number of reserved sectors at start */
52 BYTE num_FAT
; /* Number of FATs */
53 WORD dir_entries
; /* Number of root dir entries */
54 WORD first_data
; /* First data sector */
55 WORD high_cluster
; /* Highest cluster number */
56 WORD sectors_in_FAT
; /* Number of sectors per FAT */
57 WORD start_dir
; /* Starting sector of first dir */
58 DWORD driver_head
; /* Address of device driver header (?) */
59 BYTE media_ID
; /* Media ID */
60 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
61 DWORD next
; /* Pointer to next DPB in list */
62 WORD free_search
; /* Free cluster search start */
63 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
75 static struct DosHeap
*heap
;
76 static WORD DosHeapHandle
;
78 WORD sharing_retries
= 3; /* number of retries at sharing violation */
79 WORD sharing_pause
= 1; /* pause between retries */
81 extern char TempDirectory
[];
83 static BOOL32
INT21_CreateHeap(void)
85 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
87 fprintf( stderr
, "INT21_Init: Out of memory\n");
90 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
91 dpbsegptr
= PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
93 strcpy(heap
->biosdate
, "01/01/80");
97 static BYTE
*GetCurrentDTA(void)
99 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
100 return (BYTE
*)PTR_SEG_TO_LIN( pTask
->dta
);
104 void CreateBPB(int drive
, BYTE
*data
)
109 setword(&data
[3], 0);
111 setword(&data
[6], 240);
112 setword(&data
[8], 64000);
114 setword(&data
[0x0b], 40);
115 setword(&data
[0x0d], 56);
116 setword(&data
[0x0f], 2);
117 setword(&data
[0x11], 0);
118 setword(&data
[0x1f], 800);
120 setword(&data
[0x22], 1);
121 } else { /* 1.44mb */
124 setword(&data
[3], 0);
126 setword(&data
[6], 240);
127 setword(&data
[8], 2880);
129 setword(&data
[0x0b], 6);
130 setword(&data
[0x0d], 18);
131 setword(&data
[0x0f], 2);
132 setword(&data
[0x11], 0);
133 setword(&data
[0x1f], 80);
135 setword(&data
[0x22], 2);
139 static int INT21_GetFreeDiskSpace( CONTEXT
*context
)
141 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
142 char root
[] = "A:\\";
144 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
145 if (!GetDiskFreeSpace32A( root
, &cluster_sectors
, §or_bytes
,
146 &free_clusters
, &total_clusters
)) return 0;
147 AX_reg(context
) = cluster_sectors
;
148 BX_reg(context
) = free_clusters
;
149 CX_reg(context
) = sector_bytes
;
150 DX_reg(context
) = total_clusters
;
154 static int INT21_GetDriveAllocInfo( CONTEXT
*context
)
156 if (!INT21_GetFreeDiskSpace( context
)) return 0;
157 if (!heap
&& !INT21_CreateHeap()) return 0;
158 heap
->mediaID
= 0xf0;
159 DS_reg(context
) = DosHeapHandle
;
160 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
164 static void GetDrivePB( CONTEXT
*context
, int drive
)
166 if(!DRIVE_IsValid(drive
))
168 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
169 AX_reg(context
) = 0x00ff;
171 else if (heap
|| INT21_CreateHeap())
173 dprintf_int(stddeb
, "int21: GetDrivePB not fully implemented.\n");
175 /* FIXME: I have no idea what a lot of this information should
176 * say or whether it even really matters since we're not allowing
177 * direct block access. However, some programs seem to depend on
178 * getting at least _something_ back from here. The 'next' pointer
179 * does worry me, though. Should we have a complete table of
180 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
182 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
183 heap
->dpb
.sector_size
= 512;
184 heap
->dpb
.high_sector
= 1;
185 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
186 heap
->dpb
.reserved
= 0;
187 heap
->dpb
.num_FAT
= 1;
188 heap
->dpb
.dir_entries
= 2;
189 heap
->dpb
.first_data
= 2;
190 heap
->dpb
.high_cluster
= 64000;
191 heap
->dpb
.sectors_in_FAT
= 1;
192 heap
->dpb
.start_dir
= 1;
193 heap
->dpb
.driver_head
= 0;
194 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
195 heap
->dpb
.access_flag
= 0;
197 heap
->dpb
.free_search
= 0;
198 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
200 AL_reg(context
) = 0x00;
201 DS_reg(context
) = SELECTOROF(dpbsegptr
);
202 BX_reg(context
) = OFFSETOF(dpbsegptr
);
207 static void ioctlGetDeviceInfo( CONTEXT
*context
)
210 dprintf_int (stddeb
, "int21: ioctl (%d, GetDeviceInfo)\n", BX_reg(context
));
212 curr_drive
= DRIVE_GetCurrentDrive();
213 DX_reg(context
) = 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0); /* no floppy */
214 /* bits 0-5 are current drive
215 * bit 6 - file has NOT been written..FIXME: correct?
216 * bit 8 - generate int24 if no diskspace on write/ read past end of file
217 * bit 11 - media not removable
219 RESET_CFLAG(context
);
222 static BOOL32
ioctlGenericBlkDevReq( CONTEXT
*context
)
224 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
225 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
227 if (!DRIVE_IsValid(drive
))
229 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
233 if (CH_reg(context
) != 0x08)
235 INT_BARF( context
, 0x21 );
239 switch (CL_reg(context
))
241 case 0x4a: /* lock logical volume */
242 dprintf_int(stddeb
,"int21: lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
245 case 0x60: /* get device parameters */
246 /* used by w4wgrp's winfile */
247 memset(dataptr
, 0, 0x26);
249 dataptr
[6] = 0; /* media type */
252 dataptr
[1] = 0x05; /* fixed disk */
253 setword(&dataptr
[2], 0x01); /* non removable */
254 setword(&dataptr
[4], 0x300); /* # of cylinders */
258 dataptr
[1] = 0x07; /* block dev, floppy */
259 setword(&dataptr
[2], 0x02); /* removable */
260 setword(&dataptr
[4], 80); /* # of cylinders */
262 CreateBPB(drive
, &dataptr
[7]);
263 RESET_CFLAG(context
);
266 case 0x66:/* get disk serial number */
268 char label
[12],fsname
[9],path
[4];
271 strcpy(path
,"x:\\");path
[0]=drive
+'A';
272 GetVolumeInformation32A(
273 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
276 memcpy(dataptr
+2,&serial
,4);
277 memcpy(dataptr
+6,label
,11);
278 memcpy(dataptr
+17,fsname
,8);
283 dprintf_int(stddeb
,"int21: logical volume %d unlocked.\n",drive
);
287 INT_BARF( context
, 0x21 );
292 static void INT21_GetSystemDate( CONTEXT
*context
)
295 GetLocalTime( &systime
);
296 CX_reg(context
) = systime
.wYear
;
297 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
298 AX_reg(context
) = systime
.wDayOfWeek
;
301 static void INT21_GetSystemTime( CONTEXT
*context
)
304 GetLocalTime( &systime
);
305 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
306 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
309 static BOOL32
INT21_CreateFile( CONTEXT
*context
)
311 AX_reg(context
) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
312 DX_reg(context
) ), CX_reg(context
) );
313 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
317 static void OpenExistingFile( CONTEXT
*context
)
319 AX_reg(context
) = _lopen16( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
321 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
323 AX_reg(context
) = DOS_ExtendedError
;
332 switch (AX_reg(context
) & 0x0070)
334 case 0x00: /* compatability mode */
335 case 0x40: /* DENYNONE */
339 case 0x30: /* DENYREAD */
341 "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
342 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)));
343 case 0x10: /* DENYALL */
347 case 0x20: /* DENYWRITE */
358 int result
,retries
=sharing_retries
;
360 #if defined(__svr4__) || defined(_SCO_DS)
361 printf("Should call flock and needs porting to lockf\n");
365 result
= flock(handle
, lock
| LOCK_NB
);
367 if ( retries
&& (!result
) )
370 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
371 result
++; /* stop the optimizer */
372 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
376 while( (!result
) && (!(retries
--)) );
381 AX_reg(context
) = DOS_ExtendedError
;
390 AX_reg(context
) = handle
;
391 RESET_CFLAG(context
);
396 static void CloseFile( CONTEXT
*context
)
398 if ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0)
400 AX_reg(context
) = DOS_ExtendedError
;
405 static BOOL32
INT21_ExtendedOpenCreateFile(CONTEXT
*context
)
407 BOOL32 bExtendedError
= FALSE
;
408 BYTE action
= DL_reg(context
);
410 /* Shuffle arguments to call OpenExistingFile */
411 AL_reg(context
) = BL_reg(context
);
412 DX_reg(context
) = SI_reg(context
);
413 /* BX,CX and DX should be preserved */
414 OpenExistingFile(context
);
416 if ((EFL_reg(context
) & 0x0001) == 0) /* File exists */
418 UINT16 uReturnCX
= 0;
420 /* Now decide what do do */
422 if ((action
& 0x07) == 0)
424 BX_reg(context
) = AX_reg(context
);
426 AX_reg(context
) = 0x0050; /*File exists*/
428 dprintf_int(stddeb
, "int21: extended open/create: failed because file exists \n");
430 else if ((action
& 0x07) == 2)
432 /* Truncate it, but first check if opened for write */
433 if ((BL_reg(context
) & 0x0007)== 0)
435 BX_reg(context
) = AX_reg(context
);
437 dprintf_int(stddeb
, "int21: extended open/create: failed, trunc on ro file");
438 AX_reg(context
) = 0x000C; /*Access code invalid*/
443 /* Shuffle arguments to call CloseFile while
444 * preserving BX and DX */
446 dprintf_int(stddeb
, "int21: extended open/create: Closing before truncate\n");
447 BX_reg(context
) = AX_reg(context
);
449 if (EFL_reg(context
) & 0x0001)
451 dprintf_int(stddeb
, "int21: extended open/create: close before trunc failed");
452 AX_reg(context
) = 0x0019; /*Seek Error*/
456 /* Shuffle arguments to call CreateFile */
458 dprintf_int(stddeb
, "int21: extended open/create: Truncating\n");
459 AL_reg(context
) = BL_reg(context
);
460 /* CX is still the same */
461 DX_reg(context
) = SI_reg(context
);
462 bExtendedError
= INT21_CreateFile(context
);
464 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
466 dprintf_int(stddeb
, "int21: extended open/create: trunc failed");
467 return bExtendedError
;
472 else uReturnCX
= 0x1;
474 CX_reg(context
) = uReturnCX
;
476 else /* file does not exist */
478 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
479 if ((action
& 0xF0)== 0)
483 dprintf_int(stddeb
, "int21: extended open/create: failed, file dosen't exist\n");
487 /* Shuffle arguments to call CreateFile */
488 dprintf_int(stddeb
, "int21: extended open/create: Creating\n");
489 AL_reg(context
) = BL_reg(context
);
490 /* CX should still be the same */
491 DX_reg(context
) = SI_reg(context
);
492 bExtendedError
= INT21_CreateFile(context
);
493 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
495 dprintf_int(stddeb
, "int21: extended open/create: create failed\n");
496 return bExtendedError
;
502 return bExtendedError
;
506 static BOOL32
INT21_ChangeDir( CONTEXT
*context
)
509 char *dirname
= PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
));
511 dprintf_int(stddeb
,"int21: changedir %s\n", dirname
);
512 if (dirname
[0] && (dirname
[1] == ':'))
514 drive
= toupper(dirname
[0]) - 'A';
517 else drive
= DRIVE_GetCurrentDrive();
518 return DRIVE_Chdir( drive
, dirname
);
522 static int INT21_FindFirst( CONTEXT
*context
)
526 DOS_FULL_NAME full_name
;
527 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
529 path
= (const char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
530 dta
->unixPath
= NULL
;
531 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
533 AX_reg(context
) = DOS_ExtendedError
;
537 dta
->unixPath
= HEAP_strdupA( GetProcessHeap(), 0, full_name
.long_name
);
538 p
= strrchr( dta
->unixPath
, '/' );
541 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
542 * (doesn't matter as it is set below anyway)
544 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
546 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
547 dta
->unixPath
= NULL
;
548 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
549 AX_reg(context
) = ER_FileNotFound
;
553 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
554 : DRIVE_GetCurrentDrive();
556 dta
->search_attr
= CL_reg(context
);
561 static int INT21_FindNext( CONTEXT
*context
)
563 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
564 WIN32_FIND_DATA32A entry
;
567 if (!dta
->unixPath
) return 0;
568 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
569 dta
->search_attr
, dta
->count
, &entry
)))
571 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
572 dta
->unixPath
= NULL
;
575 if ((int)dta
->count
+ count
> 0xffff)
577 fprintf( stderr
, "Too many directory entries in %s\n", dta
->unixPath
);
578 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
579 dta
->unixPath
= NULL
;
583 dta
->fileattr
= entry
.dwFileAttributes
;
584 dta
->filesize
= entry
.nFileSizeLow
;
585 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
586 &dta
->filedate
, &dta
->filetime
);
587 strcpy( dta
->filename
, entry
.cAlternateFileName
);
592 static BOOL32
INT21_CreateTempFile( CONTEXT
*context
)
594 static int counter
= 0;
595 char *name
= PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
) );
596 char *p
= name
+ strlen(name
);
598 /* despite what Ralf Brown says, some programs seem to call without
599 * ending backslash (DOS accepts that, so we accept it too) */
600 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
604 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
605 counter
= (counter
+ 1) % 1000;
607 if ((AX_reg(context
) = _lcreat_uniq( name
, 0 )) != (WORD
)HFILE_ERROR16
)
609 dprintf_int( stddeb
, "INT21_CreateTempFile: created %s\n", name
);
612 if (DOS_ExtendedError
!= ER_FileExists
) return FALSE
;
617 static BOOL32
INT21_GetCurrentDirectory( CONTEXT
*context
)
619 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
620 char *ptr
= (char *)PTR_SEG_OFF_TO_LIN( DS_reg(context
), SI_reg(context
) );
622 if (!DRIVE_IsValid(drive
))
624 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
627 lstrcpyn32A( ptr
, DRIVE_GetDosCwd(drive
), 64 );
628 AX_reg(context
) = 0x0100; /* success return code */
633 static int INT21_GetDiskSerialNumber( CONTEXT
*context
)
635 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
636 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
638 if (!DRIVE_IsValid(drive
))
640 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
644 *(WORD
*)dataptr
= 0;
645 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
646 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
647 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
652 static int INT21_SetDiskSerialNumber( CONTEXT
*context
)
654 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
655 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
657 if (!DRIVE_IsValid(drive
))
659 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
663 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
668 /* microsoft's programmers should be shot for using CP/M style int21
669 calls in Windows for Workgroup's winfile.exe */
671 static int INT21_FindFirstFCB( CONTEXT
*context
)
673 BYTE
*fcb
= (BYTE
*)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
678 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
679 else pFCB
= (FINDFILE_FCB
*)fcb
;
680 drive
= DOS_GET_DRIVE( pFCB
->drive
);
681 root
= DRIVE_GetRoot( drive
);
682 cwd
= DRIVE_GetUnixCwd( drive
);
683 pFCB
->unixPath
= HeapAlloc( GetProcessHeap(), 0,
684 strlen(root
)+strlen(cwd
)+2 );
685 if (!pFCB
->unixPath
) return 0;
686 strcpy( pFCB
->unixPath
, root
);
687 strcat( pFCB
->unixPath
, "/" );
688 strcat( pFCB
->unixPath
, cwd
);
694 static int INT21_FindNextFCB( CONTEXT
*context
)
696 BYTE
*fcb
= (BYTE
*)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
698 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA();
699 WIN32_FIND_DATA32A entry
;
703 if (*fcb
== 0xff) /* extended FCB ? */
706 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
711 pFCB
= (FINDFILE_FCB
*)fcb
;
714 if (!pFCB
->unixPath
) return 0;
715 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
716 DOS_GET_DRIVE( pFCB
->drive
), attr
,
717 pFCB
->count
, &entry
)))
719 HeapFree( GetProcessHeap(), 0, pFCB
->unixPath
);
720 pFCB
->unixPath
= NULL
;
723 pFCB
->count
+= count
;
725 if (*fcb
== 0xff) { /* place extended FCB header before pResult if called with extended FCB */
726 *(BYTE
*)pResult
= 0xff;
727 (BYTE
*)pResult
+=6; /* leave reserved field behind */
728 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
731 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
733 pResult
->fileattr
= entry
.dwFileAttributes
;
734 pResult
->cluster
= 0; /* what else? */
735 pResult
->filesize
= entry
.nFileSizeLow
;
736 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
737 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
738 &pResult
->filedate
, &pResult
->filetime
);
740 /* Convert file name to FCB format */
742 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
743 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
744 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
745 pResult
->filename
[0] = pResult
->filename
[1] = '.';
748 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
749 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
751 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
752 MIN( (p
- entry
.cAlternateFileName
), 8 ) );
753 memcpy( pResult
->filename
+ 8, p
+ 1, MIN( strlen(p
), 3 ) );
756 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
757 MIN( strlen(entry
.cAlternateFileName
), 8 ) );
763 static void DeleteFileFCB( CONTEXT
*context
)
765 fprintf( stderr
, "DeleteFileFCB: not implemented yet\n" );
768 static void RenameFileFCB( CONTEXT
*context
)
770 fprintf( stderr
, "RenameFileFCB: not implemented yet\n" );
775 static void fLock( CONTEXT
* context
)
778 switch ( AX_reg(context
) & 0xff )
780 case 0x00: /* LOCK */
781 if (!LockFile(BX_reg(context
),
782 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
783 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
784 AX_reg(context
) = DOS_ExtendedError
;
789 case 0x01: /* UNLOCK */
790 if (!UnlockFile(BX_reg(context
),
791 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
792 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
793 AX_reg(context
) = DOS_ExtendedError
;
798 AX_reg(context
) = 0x0001;
805 extern void LOCAL_PrintHeap (WORD ds
);
807 /***********************************************************************
808 * DOS3Call (KERNEL.102)
810 void WINAPI
DOS3Call( CONTEXT
*context
)
812 BOOL32 bSetDOSExtendedError
= FALSE
;
814 dprintf_int( stddeb
, "int21: AX=%04x BX=%04x CX=%04x DX=%04x "
815 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
816 AX_reg(context
), BX_reg(context
), CX_reg(context
),
817 DX_reg(context
), SI_reg(context
), DI_reg(context
),
818 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
821 if (AH_reg(context
) == 0x59) /* Get extended error info */
823 AX_reg(context
) = DOS_ExtendedError
;
824 BH_reg(context
) = DOS_ErrorClass
;
825 BL_reg(context
) = DOS_ErrorAction
;
826 CH_reg(context
) = DOS_ErrorLocus
;
830 DOS_ERROR( 0, 0, 0, 0 );
831 RESET_CFLAG(context
); /* Not sure if this is a good idea */
833 switch(AH_reg(context
))
835 case 0x00: /* TERMINATE PROGRAM */
836 TASK_KillCurrentTask( 0 );
839 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
840 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
841 case 0x03: /* READ CHARACTER FROM STDAUX */
842 case 0x04: /* WRITE CHARACTER TO STDAUX */
843 case 0x05: /* WRITE CHARACTER TO PRINTER */
844 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
845 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
846 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
847 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
848 case 0x0a: /* BUFFERED INPUT */
849 case 0x0b: /* GET STDIN STATUS */
850 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
851 case 0x0f: /* OPEN FILE USING FCB */
852 case 0x10: /* CLOSE FILE USING FCB */
853 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
854 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
855 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
856 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
857 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
858 case 0x23: /* GET FILE SIZE FOR FCB */
859 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
860 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
861 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
862 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
863 case 0x29: /* PARSE FILENAME INTO FCB */
864 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
865 "SWITCHAR" - SET SWITCH CHARACTER
866 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
867 case 0x54: /* GET VERIFY FLAG */
868 INT_BARF( context
, 0x21 );
870 case 0x2e: /* SET VERIFY FLAG */
871 /* we cannot change the behaviour anyway, so just ignore it */
874 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
878 case 0x6b: /* NULL FUNCTION */
882 case 0x5c: /* "FLOCK" - RECORD LOCKING */
886 case 0x0d: /* DISK BUFFER FLUSH */
887 RESET_CFLAG(context
); /* dos 6+ only */
890 case 0x0e: /* SELECT DEFAULT DRIVE */
891 DRIVE_SetCurrentDrive( DL_reg(context
) );
892 AL_reg(context
) = MAX_DOS_DRIVES
;
895 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
896 if (!INT21_FindFirstFCB(context
))
898 AL_reg(context
) = 0xff;
901 /* else fall through */
903 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
904 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
907 case 0x13: /* DELETE FILE USING FCB */
908 DeleteFileFCB(context
);
911 case 0x17: /* RENAME FILE USING FCB */
912 RenameFileFCB(context
);
915 case 0x19: /* GET CURRENT DEFAULT DRIVE */
916 AL_reg(context
) = DRIVE_GetCurrentDrive();
919 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
921 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
922 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(context
),DX_reg(context
));
923 dprintf_int(stddeb
, "int21: Set DTA: %08lx\n", pTask
->dta
);
927 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
929 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
932 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
933 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
936 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
937 GetDrivePB(context
, DRIVE_GetCurrentDrive());
940 case 0x25: /* SET INTERRUPT VECTOR */
941 INT_SetHandler( AL_reg(context
),
942 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
946 case 0x2a: /* GET SYSTEM DATE */
947 INT21_GetSystemDate(context
);
950 case 0x2b: /* SET SYSTEM DATE */
951 fprintf( stdnimp
, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
952 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
953 AL_reg(context
) = 0; /* Let's pretend we succeeded */
956 case 0x2c: /* GET SYSTEM TIME */
957 INT21_GetSystemTime(context
);
960 case 0x2d: /* SET SYSTEM TIME */
961 fprintf( stdnimp
, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
962 CH_reg(context
), CL_reg(context
),
963 DH_reg(context
), DL_reg(context
) );
964 AL_reg(context
) = 0; /* Let's pretend we succeeded */
967 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
969 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
970 ES_reg(context
) = SELECTOROF( pTask
->dta
);
971 BX_reg(context
) = OFFSETOF( pTask
->dta
);
975 case 0x30: /* GET DOS VERSION */
976 AX_reg(context
) = (HIWORD(GetVersion16()) >> 8) |
977 (HIWORD(GetVersion16()) << 8);
978 BX_reg(context
) = 0x0012; /* 0x123456 is Wine's serial # */
979 CX_reg(context
) = 0x3456;
982 case 0x31: /* TERMINATE AND STAY RESIDENT */
983 INT_BARF( context
, 0x21 );
986 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
987 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
990 case 0x33: /* MULTIPLEXED */
991 switch (AL_reg(context
))
993 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
997 case 0x01: /* SET EXTENDED BREAK STATE */
1000 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1001 DL_reg(context
) = 0;
1004 case 0x05: /* GET BOOT DRIVE */
1005 DL_reg(context
) = 3;
1006 /* c: is Wine's bootdrive (a: is 1)*/
1009 case 0x06: /* GET TRUE VERSION NUMBER */
1010 BX_reg(context
) = (HIWORD(GetVersion16() >> 8)) |
1011 (HIWORD(GetVersion16() << 8));
1012 DX_reg(context
) = 0x00;
1016 INT_BARF( context
, 0x21 );
1021 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1022 if (!heap
) INT21_CreateHeap();
1023 ES_reg(context
) = DosHeapHandle
;
1024 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1027 case 0x35: /* GET INTERRUPT VECTOR */
1029 FARPROC16 addr
= INT_GetHandler( AL_reg(context
) );
1030 ES_reg(context
) = SELECTOROF(addr
);
1031 BX_reg(context
) = OFFSETOF(addr
);
1035 case 0x36: /* GET FREE DISK SPACE */
1036 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1039 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1040 AX_reg(context
) = 0x02; /* no country support available */
1044 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1045 bSetDOSExtendedError
= (!CreateDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1046 DX_reg(context
) ), NULL
));
1049 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1050 bSetDOSExtendedError
= (!RemoveDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1051 DX_reg(context
) )));
1054 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1055 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1058 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1059 AX_reg(context
) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1060 DX_reg(context
) ), CX_reg(context
) );
1061 bSetDOSExtendedError
= (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
1064 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1065 OpenExistingFile(context
);
1068 case 0x3e: /* "CLOSE" - CLOSE FILE */
1069 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1072 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1074 LONG result
= WIN16_hread( BX_reg(context
),
1075 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1078 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1079 else AX_reg(context
) = (WORD
)result
;
1083 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1085 LONG result
= _hwrite16( BX_reg(context
),
1086 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1089 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1090 else AX_reg(context
) = (WORD
)result
;
1094 case 0x41: /* "UNLINK" - DELETE FILE */
1095 bSetDOSExtendedError
= (!DeleteFile32A( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1096 DX_reg(context
) )));
1099 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1101 LONG status
= _llseek16( BX_reg(context
),
1102 MAKELONG(DX_reg(context
),CX_reg(context
)),
1104 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1107 AX_reg(context
) = LOWORD(status
);
1108 DX_reg(context
) = HIWORD(status
);
1113 case 0x43: /* FILE ATTRIBUTES */
1114 switch (AL_reg(context
))
1117 AX_reg(context
) = (WORD
)GetFileAttributes32A(
1118 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1120 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1121 else CX_reg(context
) = AX_reg(context
);
1125 bSetDOSExtendedError
=
1126 (!SetFileAttributes32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1133 case 0x44: /* IOCTL */
1134 switch (AL_reg(context
))
1137 ioctlGetDeviceInfo(context
);
1142 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1143 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
));
1145 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1147 fprintf(stdnimp
,"int21: program tried to write to block device control channel of drive %d:\n",drive
);
1148 for (i
=0;i
<CX_reg(context
);i
++)
1149 fprintf(stdnimp
,"%02x ",dataptr
[i
]);
1150 fprintf(stdnimp
,"\n");
1151 AX_reg(context
)=CX_reg(context
);
1154 case 0x08: /* Check if drive is removable. */
1155 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1157 case DRIVE_CANNOTDETERMINE
:
1158 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1159 AX_reg(context
) = ER_InvalidDrive
;
1162 case DRIVE_REMOVABLE
:
1163 AX_reg(context
) = 0; /* removable */
1166 AX_reg(context
) = 1; /* not removable */
1171 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1172 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1174 case DRIVE_CANNOTDETERMINE
:
1175 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1176 AX_reg(context
) = ER_InvalidDrive
;
1180 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1183 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1188 case 0x0a: /* check if handle (BX) is remote */
1189 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1192 DX_reg(context
) = 0;
1195 case 0x0b: /* SET SHARING RETRY COUNT */
1196 if (!CX_reg(context
))
1198 AX_reg(context
) = 1;
1202 sharing_pause
= CX_reg(context
);
1203 if (!DX_reg(context
))
1204 sharing_retries
= DX_reg(context
);
1205 RESET_CFLAG(context
);
1209 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1212 case 0x0e: /* get logical drive mapping */
1213 AL_reg(context
) = 0; /* drive has no mapping - FIXME: may be wrong*/
1216 case 0x0F: /* Set logical drive mapping */
1219 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1220 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1223 AX_reg(context
) = 0x000F; /* invalid drive */
1229 INT_BARF( context
, 0x21 );
1234 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1235 bSetDOSExtendedError
= ((AX_reg(context
) = FILE_Dup(BX_reg(context
))) == (WORD
)HFILE_ERROR16
);
1238 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1239 bSetDOSExtendedError
= (FILE_Dup2( BX_reg(context
), CX_reg(context
) ) == HFILE_ERROR32
);
1242 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1243 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1246 case 0x48: /* ALLOCATE MEMORY */
1247 case 0x49: /* FREE MEMORY */
1248 case 0x4a: /* RESIZE MEMORY BLOCK */
1249 INT_BARF( context
, 0x21 );
1252 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1253 AX_reg(context
) = WinExec16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1256 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1259 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1260 TASK_KillCurrentTask( AL_reg(context
) );
1263 case 0x4d: /* GET RETURN CODE */
1264 AX_reg(context
) = 0; /* normal exit */
1267 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1268 if (!INT21_FindFirst(context
)) break;
1271 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1272 if (!INT21_FindNext(context
))
1274 DOS_ERROR( ER_NoMoreFiles
, EC_MediaError
, SA_Abort
, EL_Disk
);
1275 AX_reg(context
) = ER_NoMoreFiles
;
1278 else AX_reg(context
) = 0; /* OK */
1281 case 0x51: /* GET PSP ADDRESS */
1282 case 0x62: /* GET PSP ADDRESS */
1283 /* FIXME: should we return the original DOS PSP upon */
1284 /* Windows startup ? */
1285 BX_reg(context
) = GetCurrentPDB();
1288 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1289 ES_reg(context
) = 0x0;
1290 BX_reg(context
) = 0x0;
1291 INT_BARF( context
, 0x21 );
1294 case 0x56: /* "RENAME" - RENAME FILE */
1295 bSetDOSExtendedError
=
1296 (!MoveFile32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
1297 PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
))));
1300 case 0x57: /* FILE DATE AND TIME */
1301 switch (AL_reg(context
))
1303 case 0x00: /* Get */
1306 if (!GetFileTime( BX_reg(context
), NULL
, NULL
, &filetime
))
1307 bSetDOSExtendedError
= TRUE
;
1308 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1313 case 0x01: /* Set */
1316 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1318 bSetDOSExtendedError
=
1319 (!SetFileTime( BX_reg(context
), NULL
, NULL
, &filetime
));
1325 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1326 switch (AL_reg(context
))
1329 AX_reg(context
) = 1;
1332 AX_reg(context
) = 0;
1338 RESET_CFLAG(context
);
1341 case 0x5a: /* CREATE TEMPORARY FILE */
1342 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1345 case 0x5b: /* CREATE NEW FILE */
1346 bSetDOSExtendedError
= ((AX_reg(context
) =
1347 _lcreat_uniq( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)), 0 ))
1348 == (WORD
)HFILE_ERROR16
);
1351 case 0x5d: /* NETWORK */
1353 /* network software not installed */
1354 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1355 bSetDOSExtendedError
= TRUE
;
1358 case 0x5f: /* NETWORK */
1359 switch (AL_reg(context
))
1361 case 0x07: /* ENABLE DRIVE */
1362 if (!DRIVE_Enable( DL_reg(context
) ))
1364 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1365 bSetDOSExtendedError
= TRUE
;
1369 case 0x08: /* DISABLE DRIVE */
1370 if (!DRIVE_Disable( DL_reg(context
) ))
1372 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1373 bSetDOSExtendedError
= TRUE
;
1378 /* network software not installed */
1379 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1380 bSetDOSExtendedError
= TRUE
;
1385 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1387 if (!GetFullPathName32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1388 SI_reg(context
)), 128,
1389 PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1390 DI_reg(context
)),NULL
))
1391 bSetDOSExtendedError
= TRUE
;
1392 else AX_reg(context
) = 0;
1396 case 0x61: /* UNUSED */
1397 case 0x63: /* UNUSED */
1398 case 0x64: /* OS/2 DOS BOX */
1399 INT_BARF( context
, 0x21 );
1403 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1404 extern WORD WINE_LanguageId
;
1405 BYTE
*dataptr
=PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
));;
1406 switch (AL_reg(context
)) {
1409 *(WORD
*)(dataptr
+1) = 41;
1410 *(WORD
*)(dataptr
+3) = WINE_LanguageId
;
1411 *(WORD
*)(dataptr
+5) = CodePage
;
1415 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
1416 CX_reg(context
) = 258;/*FIXME: size of table?*/
1419 INT_BARF( context
, 0x21 );
1425 case 0x66: /* GLOBAL CODE PAGE TABLE */
1426 switch (AL_reg(context
))
1429 DX_reg(context
) = BX_reg(context
) = CodePage
;
1430 RESET_CFLAG(context
);
1433 CodePage
= BX_reg(context
);
1434 RESET_CFLAG(context
);
1439 case 0x67: /* SET HANDLE COUNT */
1440 SetHandleCount16( BX_reg(context
) );
1441 if (DOS_ExtendedError
) bSetDOSExtendedError
= TRUE
;
1444 case 0x68: /* "FFLUSH" - COMMIT FILE */
1445 case 0x6a: /* COMMIT FILE */
1446 bSetDOSExtendedError
= (!FlushFileBuffers( BX_reg(context
) ));
1449 case 0x69: /* DISK SERIAL NUMBER */
1450 switch (AL_reg(context
))
1453 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1454 else AX_reg(context
) = 0;
1458 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1459 else AX_reg(context
) = 1;
1464 case 0x6C: /* Extended Open/Create*/
1465 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
1468 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1469 switch(AL_reg(context
))
1471 case 0x39: /* Create directory */
1472 bSetDOSExtendedError
= (!CreateDirectory32A(
1473 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1474 DX_reg(context
) ), NULL
));
1476 case 0x3a: /* Remove directory */
1477 bSetDOSExtendedError
= (!RemoveDirectory32A(
1478 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1479 DX_reg(context
) )));
1481 case 0x43: /* Get/Set file attributes */
1482 switch (BL_reg(context
))
1484 case 0x00: /* Get file attributes */
1485 CX_reg(context
) = (WORD
)GetFileAttributes32A(
1486 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1488 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1491 bSetDOSExtendedError
= (!SetFileAttributes32A(
1492 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1494 CX_reg(context
) ) );
1498 "Unimplemented int21 long file name function:\n");
1499 INT_BARF( context
, 0x21 );
1501 AL_reg(context
) = 0;
1505 case 0x47: /* Get current directory */
1506 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1509 case 0x4e: /* Find first file */
1510 /* FIXME: use attributes in CX */
1511 if ((AX_reg(context
) = FindFirstFile16(
1512 PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
1513 (WIN32_FIND_DATA32A
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1515 == INVALID_HANDLE_VALUE16
)
1516 bSetDOSExtendedError
= TRUE
;
1518 case 0x4f: /* Find next file */
1519 if (!FindNextFile16( BX_reg(context
),
1520 (WIN32_FIND_DATA32A
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1522 bSetDOSExtendedError
= TRUE
;
1524 case 0xa1: /* Find close */
1525 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
1530 switch(CL_reg(context
))
1532 case 0x02: /*Get canonical long filename or path */
1533 if (!GetFullPathName32A
1534 ( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1535 SI_reg(context
)), 128,
1536 PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1537 DI_reg(context
)),NULL
))
1538 bSetDOSExtendedError
= TRUE
;
1539 else AX_reg(context
) = 0;
1543 "Unimplemented int21 long file name function:\n");
1544 INT_BARF( context
, 0x21 );
1546 AL_reg(context
) = 0;
1550 case 0x6c: /* Create or open file */
1551 /* translate Dos 7 action to Dos 6 action */
1552 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
1555 case 0x3b: /* Change directory */
1556 if (!SetCurrentDirectory32A(PTR_SEG_OFF_TO_LIN(
1562 AL_reg(context
) = DOS_ExtendedError
;
1565 case 0x41: /* Delete file */
1566 if (!DeleteFile32A(PTR_SEG_OFF_TO_LIN(
1571 AL_reg(context
) = DOS_ExtendedError
;
1574 case 0x56: /* Move (rename) file */
1576 fprintf( stderr
, "Unimplemented int21 long file name function:\n");
1577 INT_BARF( context
, 0x21 );
1579 AL_reg(context
) = 0;
1584 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
1585 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
1586 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
1587 dprintf_int(stddeb
,"int21: windows95 function AX %04x\n",
1589 dprintf_int(stddeb
, " returning unimplemented\n");
1591 AL_reg(context
) = 0;
1594 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1595 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1599 INT_BARF( context
, 0x21 );
1602 } /* END OF SWITCH */
1604 if( bSetDOSExtendedError
) /* set general error condition */
1606 AX_reg(context
) = DOS_ExtendedError
;
1610 dprintf_int( stddeb
, "ret21: AX=%04x BX=%04x CX=%04x DX=%04x "
1611 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1612 AX_reg(context
), BX_reg(context
), CX_reg(context
),
1613 DX_reg(context
), SI_reg(context
), DI_reg(context
),
1614 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
1618 FARPROC16 WINAPI
GetSetKernelDOSProc(FARPROC16 DosProc
)
1620 fprintf(stderr
, "GetSetKernelDOSProc(DosProc: %08x);\n", (UINT32
)DosProc
);