2 * DOS interrupt 21h handler
14 #include <sys/types.h>
30 #if defined(__svr4__) || defined(_SCO_DS)
31 /* SVR4 DOESNT do locking the same way must implement properly */
38 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
40 /* Define the drive parameter block, as used by int21/1F
41 * and int21/32. This table can be accessed through the
42 * global 'dpb' pointer, which points into the local dos
47 BYTE drive_num
; /* 0=A, etc. */
48 BYTE unit_num
; /* Drive's unit number (?) */
49 WORD sector_size
; /* Sector size in bytes */
50 BYTE high_sector
; /* Highest sector in a cluster */
51 BYTE shift
; /* Shift count (?) */
52 WORD reserved
; /* Number of reserved sectors at start */
53 BYTE num_FAT
; /* Number of FATs */
54 WORD dir_entries
; /* Number of root dir entries */
55 WORD first_data
; /* First data sector */
56 WORD high_cluster
; /* Highest cluster number */
57 WORD sectors_in_FAT
; /* Number of sectors per FAT */
58 WORD start_dir
; /* Starting sector of first dir */
59 DWORD driver_head
; /* Address of device driver header (?) */
60 BYTE media_ID
; /* Media ID */
61 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
62 DWORD next
; /* Pointer to next DPB in list */
63 WORD free_search
; /* Free cluster search start */
64 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
76 static struct DosHeap
*heap
;
77 static WORD DosHeapHandle
;
79 WORD sharing_retries
= 3; /* number of retries at sharing violation */
80 WORD sharing_pause
= 1; /* pause between retries */
82 extern char TempDirectory
[];
84 static BOOL32
INT21_CreateHeap(void)
86 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
88 fprintf( stderr
, "INT21_Init: Out of memory\n");
91 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
92 dpbsegptr
= PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
94 strcpy(heap
->biosdate
, "01/01/80");
98 BYTE
*GetCurrentDTA(void)
100 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
101 return (BYTE
*)PTR_SEG_TO_LIN( pTask
->dta
);
105 void ChopOffWhiteSpace(char *string
)
109 for (length
= strlen(string
) ; length
; length
--)
110 if (string
[length
] == ' ')
111 string
[length
] = '\0';
114 void CreateBPB(int drive
, BYTE
*data
)
119 setword(&data
[3], 0);
121 setword(&data
[6], 240);
122 setword(&data
[8], 64000);
124 setword(&data
[0x0b], 40);
125 setword(&data
[0x0d], 56);
126 setword(&data
[0x0f], 2);
127 setword(&data
[0x11], 0);
128 setword(&data
[0x1f], 800);
130 setword(&data
[0x22], 1);
131 } else { /* 1.44mb */
134 setword(&data
[3], 0);
136 setword(&data
[6], 240);
137 setword(&data
[8], 2880);
139 setword(&data
[0x0b], 6);
140 setword(&data
[0x0d], 18);
141 setword(&data
[0x0f], 2);
142 setword(&data
[0x11], 0);
143 setword(&data
[0x1f], 80);
145 setword(&data
[0x22], 2);
149 static int INT21_GetFreeDiskSpace( CONTEXT
*context
)
151 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
152 char root
[] = "A:\\";
154 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
155 if (!GetDiskFreeSpace32A( root
, &cluster_sectors
, §or_bytes
,
156 &free_clusters
, &total_clusters
)) return 0;
157 AX_reg(context
) = cluster_sectors
;
158 BX_reg(context
) = free_clusters
;
159 CX_reg(context
) = sector_bytes
;
160 DX_reg(context
) = total_clusters
;
164 static int INT21_GetDriveAllocInfo( CONTEXT
*context
)
166 if (!INT21_GetFreeDiskSpace( context
)) return 0;
167 if (!heap
&& !INT21_CreateHeap()) return 0;
168 heap
->mediaID
= 0xf0;
169 DS_reg(context
) = DosHeapHandle
;
170 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
174 static void GetDrivePB( CONTEXT
*context
, int drive
)
176 if(!DRIVE_IsValid(drive
))
178 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
179 AX_reg(context
) = 0x00ff;
181 else if (heap
|| INT21_CreateHeap())
183 dprintf_int(stddeb
, "int21: GetDrivePB not fully implemented.\n");
185 /* FIXME: I have no idea what a lot of this information should
186 * say or whether it even really matters since we're not allowing
187 * direct block access. However, some programs seem to depend on
188 * getting at least _something_ back from here. The 'next' pointer
189 * does worry me, though. Should we have a complete table of
190 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
192 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
193 heap
->dpb
.sector_size
= 512;
194 heap
->dpb
.high_sector
= 1;
195 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
196 heap
->dpb
.reserved
= 0;
197 heap
->dpb
.num_FAT
= 1;
198 heap
->dpb
.dir_entries
= 2;
199 heap
->dpb
.first_data
= 2;
200 heap
->dpb
.high_cluster
= 64000;
201 heap
->dpb
.sectors_in_FAT
= 1;
202 heap
->dpb
.start_dir
= 1;
203 heap
->dpb
.driver_head
= 0;
204 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
205 heap
->dpb
.access_flag
= 0;
207 heap
->dpb
.free_search
= 0;
208 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
210 AL_reg(context
) = 0x00;
211 DS_reg(context
) = SELECTOROF(dpbsegptr
);
212 BX_reg(context
) = OFFSETOF(dpbsegptr
);
217 static void ioctlGetDeviceInfo( CONTEXT
*context
)
220 dprintf_int (stddeb
, "int21: ioctl (%d, GetDeviceInfo)\n", BX_reg(context
));
222 curr_drive
= DRIVE_GetCurrentDrive();
223 DX_reg(context
) = 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0); /* no floppy */
224 /* bits 0-5 are current drive
225 * bit 6 - file has NOT been written..FIXME: correct?
226 * bit 8 - generate int24 if no diskspace on write/ read past end of file
227 * bit 11 - media not removable
229 RESET_CFLAG(context
);
232 static BOOL32
ioctlGenericBlkDevReq( CONTEXT
*context
)
234 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
235 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
237 if (!DRIVE_IsValid(drive
))
239 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
243 if (CH_reg(context
) != 0x08)
245 INT_BARF( context
, 0x21 );
249 switch (CL_reg(context
))
251 case 0x4a: /* lock logical volume */
252 dprintf_int(stddeb
,"int21: lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
255 case 0x60: /* get device parameters */
256 /* used by w4wgrp's winfile */
257 memset(dataptr
, 0, 0x26);
259 dataptr
[6] = 0; /* media type */
262 dataptr
[1] = 0x05; /* fixed disk */
263 setword(&dataptr
[2], 0x01); /* non removable */
264 setword(&dataptr
[4], 0x300); /* # of cylinders */
268 dataptr
[1] = 0x07; /* block dev, floppy */
269 setword(&dataptr
[2], 0x02); /* removable */
270 setword(&dataptr
[4], 80); /* # of cylinders */
272 CreateBPB(drive
, &dataptr
[7]);
273 RESET_CFLAG(context
);
276 case 0x66:/* get disk serial number */
278 char label
[12],fsname
[9],path
[4];
281 strcpy(path
,"x:\\");path
[0]=drive
+'A';
282 GetVolumeInformation32A(
283 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
286 memcpy(dataptr
+2,&serial
,4);
287 memcpy(dataptr
+6,label
,11);
288 memcpy(dataptr
+17,fsname
,8);
293 dprintf_int(stddeb
,"int21: logical volume %d unlocked.\n",drive
);
297 INT_BARF( context
, 0x21 );
302 static void INT21_GetSystemDate( CONTEXT
*context
)
305 GetLocalTime( &systime
);
306 CX_reg(context
) = systime
.wYear
;
307 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
308 AX_reg(context
) = systime
.wDayOfWeek
;
311 static void INT21_GetSystemTime( CONTEXT
*context
)
314 GetLocalTime( &systime
);
315 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
316 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
319 static BOOL32
INT21_CreateFile( CONTEXT
*context
)
321 AX_reg(context
) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
322 DX_reg(context
) ), CX_reg(context
) );
323 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
327 void OpenExistingFile( CONTEXT
*context
)
329 AX_reg(context
) = _lopen16( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
331 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
333 AX_reg(context
) = DOS_ExtendedError
;
342 switch (AX_reg(context
) & 0x0070)
344 case 0x00: /* compatability mode */
345 case 0x40: /* DENYNONE */
349 case 0x30: /* DENYREAD */
351 "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
352 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)));
353 case 0x10: /* DENYALL */
357 case 0x20: /* DENYWRITE */
368 int result
,retries
=sharing_retries
;
370 #if defined(__svr4__) || defined(_SCO_DS)
371 printf("Should call flock and needs porting to lockf\n");
375 result
= flock(handle
, lock
| LOCK_NB
);
377 if ( retries
&& (!result
) )
380 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
381 result
++; /* stop the optimizer */
382 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
386 while( (!result
) && (!(retries
--)) );
391 AX_reg(context
) = DOS_ExtendedError
;
400 AX_reg(context
) = handle
;
401 RESET_CFLAG(context
);
406 static void CloseFile( CONTEXT
*context
)
408 if ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0)
410 AX_reg(context
) = DOS_ExtendedError
;
415 static BOOL32
INT21_ExtendedOpenCreateFile(CONTEXT
*context
)
417 BOOL32 bExtendedError
= FALSE
;
418 BYTE action
= DL_reg(context
);
420 /* Shuffle arguments to call OpenExistingFile */
421 AL_reg(context
) = BL_reg(context
);
422 DX_reg(context
) = SI_reg(context
);
423 /* BX,CX and DX should be preserved */
424 OpenExistingFile(context
);
426 if ((EFL_reg(context
) & 0x0001) == 0) /* File exists */
428 UINT16 uReturnCX
= 0;
430 /* Now decide what do do */
432 if ((action
& 0x07) == 0)
434 BX_reg(context
) = AX_reg(context
);
436 AX_reg(context
) = 0x0050; /*File exists*/
438 dprintf_int(stddeb
, "int21: extended open/create: failed because file exists \n");
440 else if ((action
& 0x07) == 2)
442 /* Truncate it, but first check if opened for write */
443 if ((BL_reg(context
) & 0x0007)== 0)
445 BX_reg(context
) = AX_reg(context
);
447 dprintf_int(stddeb
, "int21: extended open/create: failed, trunc on ro file");
448 AX_reg(context
) = 0x000C; /*Access code invalid*/
453 /* Shuffle arguments to call CloseFile while
454 * preserving BX and DX */
456 dprintf_int(stddeb
, "int21: extended open/create: Closing before truncate\n");
457 BX_reg(context
) = AX_reg(context
);
459 if (EFL_reg(context
) & 0x0001)
461 dprintf_int(stddeb
, "int21: extended open/create: close before trunc failed");
462 AX_reg(context
) = 0x0019; /*Seek Error*/
466 /* Shuffle arguments to call CreateFile */
468 dprintf_int(stddeb
, "int21: extended open/create: Truncating\n");
469 AL_reg(context
) = BL_reg(context
);
470 /* CX is still the same */
471 DX_reg(context
) = SI_reg(context
);
472 bExtendedError
= INT21_CreateFile(context
);
474 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
476 dprintf_int(stddeb
, "int21: extended open/create: trunc failed");
477 return bExtendedError
;
482 else uReturnCX
= 0x1;
484 CX_reg(context
) = uReturnCX
;
486 else /* file does not exist */
488 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
489 if ((action
& 0xF0)== 0)
493 dprintf_int(stddeb
, "int21: extended open/create: failed, file dosen't exist\n");
497 /* Shuffle arguments to call CreateFile */
498 dprintf_int(stddeb
, "int21: extended open/create: Creating\n");
499 AL_reg(context
) = BL_reg(context
);
500 /* CX should still be the same */
501 DX_reg(context
) = SI_reg(context
);
502 bExtendedError
= INT21_CreateFile(context
);
503 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
505 dprintf_int(stddeb
, "int21: extended open/create: create failed\n");
506 return bExtendedError
;
512 return bExtendedError
;
516 static BOOL32
INT21_ChangeDir( CONTEXT
*context
)
519 char *dirname
= PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
));
521 dprintf_int(stddeb
,"int21: changedir %s\n", dirname
);
522 if (dirname
[0] && (dirname
[1] == ':'))
524 drive
= toupper(dirname
[0]) - 'A';
527 else drive
= DRIVE_GetCurrentDrive();
528 return DRIVE_Chdir( drive
, dirname
);
532 static int INT21_FindFirst( CONTEXT
*context
)
536 DOS_FULL_NAME full_name
;
537 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
539 path
= (const char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
540 dta
->unixPath
= NULL
;
541 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
543 AX_reg(context
) = DOS_ExtendedError
;
547 dta
->unixPath
= xstrdup( full_name
.long_name
);
548 p
= strrchr( dta
->unixPath
, '/' );
551 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
552 * (doesn't matter as it is set below anyway)
554 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
556 free( dta
->unixPath
);
557 dta
->unixPath
= NULL
;
558 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
559 AX_reg(context
) = ER_FileNotFound
;
563 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
564 : DRIVE_GetCurrentDrive();
566 dta
->search_attr
= CL_reg(context
);
571 static int INT21_FindNext( CONTEXT
*context
)
573 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
574 WIN32_FIND_DATA32A entry
;
577 if (!dta
->unixPath
) return 0;
578 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
579 dta
->search_attr
, dta
->count
, &entry
)))
581 free( dta
->unixPath
);
582 dta
->unixPath
= NULL
;
585 if ((int)dta
->count
+ count
> 0xffff)
587 fprintf( stderr
, "Too many directory entries in %s\n", dta
->unixPath
);
588 free( dta
->unixPath
);
589 dta
->unixPath
= NULL
;
593 dta
->fileattr
= entry
.dwFileAttributes
;
594 dta
->filesize
= entry
.nFileSizeLow
;
595 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
596 &dta
->filedate
, &dta
->filetime
);
597 strcpy( dta
->filename
, entry
.cAlternateFileName
);
602 static BOOL32
INT21_CreateTempFile( CONTEXT
*context
)
604 static int counter
= 0;
605 char *name
= PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
) );
606 char *p
= name
+ strlen(name
);
610 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
611 counter
= (counter
+ 1) % 1000;
613 if ((AX_reg(context
) = _lcreat_uniq( name
, 0 )) != (WORD
)HFILE_ERROR16
)
615 dprintf_int( stddeb
, "INT21_CreateTempFile: created %s\n", name
);
618 if (DOS_ExtendedError
!= ER_FileExists
) return FALSE
;
623 static BOOL32
INT21_GetCurrentDirectory( CONTEXT
*context
)
625 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
626 char *ptr
= (char *)PTR_SEG_OFF_TO_LIN( DS_reg(context
), SI_reg(context
) );
628 if (!DRIVE_IsValid(drive
))
630 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
633 lstrcpyn32A( ptr
, DRIVE_GetDosCwd(drive
), 64 );
634 AX_reg(context
) = 0x0100; /* success return code */
639 static int INT21_GetDiskSerialNumber( CONTEXT
*context
)
641 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
642 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
644 if (!DRIVE_IsValid(drive
))
646 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
650 *(WORD
*)dataptr
= 0;
651 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
652 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
653 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
658 static int INT21_SetDiskSerialNumber( CONTEXT
*context
)
660 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
661 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
663 if (!DRIVE_IsValid(drive
))
665 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
669 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
674 /* microsoft's programmers should be shot for using CP/M style int21
675 calls in Windows for Workgroup's winfile.exe */
677 static int INT21_FindFirstFCB( CONTEXT
*context
)
679 BYTE
*fcb
= (BYTE
*)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
684 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
685 else pFCB
= (FINDFILE_FCB
*)fcb
;
686 drive
= DOS_GET_DRIVE( pFCB
->drive
);
687 root
= DRIVE_GetRoot( drive
);
688 cwd
= DRIVE_GetUnixCwd( drive
);
689 pFCB
->unixPath
= HeapAlloc( SystemHeap
, 0, strlen(root
)+strlen(cwd
)+2 );
690 if (!pFCB
->unixPath
) return 0;
691 strcpy( pFCB
->unixPath
, root
);
692 strcat( pFCB
->unixPath
, "/" );
693 strcat( pFCB
->unixPath
, cwd
);
699 static int INT21_FindNextFCB( CONTEXT
*context
)
701 BYTE
*fcb
= (BYTE
*)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
703 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA();
704 WIN32_FIND_DATA32A entry
;
711 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
716 pFCB
= (FINDFILE_FCB
*)fcb
;
719 if (!pFCB
->unixPath
) return 0;
720 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
721 DOS_GET_DRIVE( pFCB
->drive
), attr
,
722 pFCB
->count
, &entry
)))
724 HeapFree( SystemHeap
, 0, pFCB
->unixPath
);
725 pFCB
->unixPath
= NULL
;
728 pFCB
->count
+= count
;
730 pResult
->fileattr
= entry
.dwFileAttributes
;
731 pResult
->cluster
= 0; /* what else? */
732 pResult
->filesize
= entry
.nFileSizeLow
;
733 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
734 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
735 &pResult
->filedate
, &pResult
->filetime
);
737 /* Convert file name to FCB format */
739 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
740 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
741 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
742 pResult
->filename
[0] = pResult
->filename
[1] = '.';
745 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
746 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
748 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
749 MIN( (p
- entry
.cAlternateFileName
), 8 ) );
750 memcpy( pResult
->filename
+ 8, p
+ 1, MIN( strlen(p
), 3 ) );
753 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
754 MIN( strlen(entry
.cAlternateFileName
), 8 ) );
760 static void DeleteFileFCB( CONTEXT
*context
)
762 fprintf( stderr
, "DeleteFileFCB: not implemented yet\n" );
764 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
765 struct dosdirent
*dp
;
766 char temp
[256], *ptr
;
767 int drive
= DOS_GET_DRIVE( *fcb
);
772 strcpy(temp
+1, DRIVE_GetDosCwd(drive
));
774 strncat(temp
, fcb
+ 1, 8);
775 ChopOffWhiteSpace(temp
);
776 strncat(temp
, fcb
+ 9, 3);
777 ChopOffWhiteSpace(temp
);
779 if ((dp
= DOS_opendir(temp
)) == NULL
) {
780 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
781 AX_reg(context
) = 0xff;
786 strcpy(temp
+1, DRIVE_GetDosCwd(drive
) );
789 ptr
= temp
+ strlen(temp
);
791 while (DOS_readdir(dp
) != NULL
)
793 strcpy(ptr
, dp
->filename
);
794 dprintf_int(stddeb
, "int21: delete file %s\n", temp
);
795 /* unlink(DOS_GetUnixFileName(temp)); */
802 static void RenameFileFCB( CONTEXT
*context
)
804 fprintf( stderr
, "RenameFileFCB: not implemented yet\n" );
806 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
807 struct dosdirent
*dp
;
808 char temp
[256], oldname
[256], newname
[256], *oldnameptr
, *newnameptr
;
809 int drive
= DOS_GET_DRIVE( *fcb
);
814 strcpy(temp
+1, DRIVE_GetDosCwd(drive
) );
816 strncat(temp
, fcb
+ 1, 8);
817 ChopOffWhiteSpace(temp
);
818 strncat(temp
, fcb
+ 9, 3);
819 ChopOffWhiteSpace(temp
);
821 if ((dp
= DOS_opendir(temp
)) == NULL
) {
822 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
823 AX_reg(context
) = 0xff;
828 strcpy(oldname
+1, DRIVE_GetDosCwd(drive
) );
829 strcat(oldname
, "\\");
830 strcpy( newname
, oldname
);
831 oldnameptr
= oldname
+ strlen(oldname
);
832 newnameptr
= newname
+ strlen(newname
);
834 while (DOS_readdir(dp
) != NULL
)
836 strcpy(oldnameptr
, dp
->filename
);
837 strcpy(newnameptr
, fcb
+ 1);
838 dprintf_int(stddeb
, "int21: renamefile %s -> %s\n",
848 static void fLock( CONTEXT
* context
)
851 switch ( AX_reg(context
) & 0xff )
853 case 0x00: /* LOCK */
854 if (!LockFile(BX_reg(context
),
855 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
856 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
857 AX_reg(context
) = DOS_ExtendedError
;
862 case 0x01: /* UNLOCK */
863 if (!UnlockFile(BX_reg(context
),
864 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
865 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
866 AX_reg(context
) = DOS_ExtendedError
;
871 AX_reg(context
) = 0x0001;
878 extern void LOCAL_PrintHeap (WORD ds
);
880 /***********************************************************************
881 * DOS3Call (KERNEL.102)
883 void DOS3Call( CONTEXT
*context
)
885 BOOL32 bSetDOSExtendedError
= FALSE
;
887 dprintf_int( stddeb
, "int21: AX=%04x BX=%04x CX=%04x DX=%04x "
888 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
889 AX_reg(context
), BX_reg(context
), CX_reg(context
),
890 DX_reg(context
), SI_reg(context
), DI_reg(context
),
891 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
894 if (AH_reg(context
) == 0x59) /* Get extended error info */
896 AX_reg(context
) = DOS_ExtendedError
;
897 BH_reg(context
) = DOS_ErrorClass
;
898 BL_reg(context
) = DOS_ErrorAction
;
899 CH_reg(context
) = DOS_ErrorLocus
;
903 DOS_ERROR( 0, 0, 0, 0 );
904 RESET_CFLAG(context
); /* Not sure if this is a good idea */
906 switch(AH_reg(context
))
908 case 0x00: /* TERMINATE PROGRAM */
909 TASK_KillCurrentTask( 0 );
912 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
913 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
914 case 0x03: /* READ CHARACTER FROM STDAUX */
915 case 0x04: /* WRITE CHARACTER TO STDAUX */
916 case 0x05: /* WRITE CHARACTER TO PRINTER */
917 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
918 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
919 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
920 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
921 case 0x0a: /* BUFFERED INPUT */
922 case 0x0b: /* GET STDIN STATUS */
923 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
924 case 0x0f: /* OPEN FILE USING FCB */
925 case 0x10: /* CLOSE FILE USING FCB */
926 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
927 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
928 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
929 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
930 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
931 case 0x23: /* GET FILE SIZE FOR FCB */
932 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
933 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
934 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
935 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
936 case 0x29: /* PARSE FILENAME INTO FCB */
937 case 0x2e: /* SET VERIFY FLAG */
938 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
939 "SWITCHAR" - SET SWITCH CHARACTER
940 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
941 case 0x54: /* GET VERIFY FLAG */
942 INT_BARF( context
, 0x21 );
945 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
949 case 0x6b: /* NULL FUNCTION */
953 case 0x5c: /* "FLOCK" - RECORD LOCKING */
957 case 0x0d: /* DISK BUFFER FLUSH */
958 RESET_CFLAG(context
); /* dos 6+ only */
961 case 0x0e: /* SELECT DEFAULT DRIVE */
962 DRIVE_SetCurrentDrive( DL_reg(context
) );
963 AL_reg(context
) = MAX_DOS_DRIVES
;
966 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
967 if (!INT21_FindFirstFCB(context
))
969 AL_reg(context
) = 0xff;
972 /* else fall through */
974 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
975 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
978 case 0x13: /* DELETE FILE USING FCB */
979 DeleteFileFCB(context
);
982 case 0x17: /* RENAME FILE USING FCB */
983 RenameFileFCB(context
);
986 case 0x19: /* GET CURRENT DEFAULT DRIVE */
987 AL_reg(context
) = DRIVE_GetCurrentDrive();
990 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
992 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
993 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(context
),DX_reg(context
));
994 dprintf_int(stddeb
, "int21: Set DTA: %08lx\n", pTask
->dta
);
998 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1000 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1003 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1004 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1007 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1008 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1011 case 0x25: /* SET INTERRUPT VECTOR */
1012 INT_SetHandler( AL_reg(context
),
1013 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1017 case 0x2a: /* GET SYSTEM DATE */
1018 INT21_GetSystemDate(context
);
1021 case 0x2b: /* SET SYSTEM DATE */
1022 fprintf( stdnimp
, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1023 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1024 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1027 case 0x2c: /* GET SYSTEM TIME */
1028 INT21_GetSystemTime(context
);
1031 case 0x2d: /* SET SYSTEM TIME */
1032 fprintf( stdnimp
, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1033 CH_reg(context
), CL_reg(context
),
1034 DH_reg(context
), DL_reg(context
) );
1035 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1038 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1040 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1041 ES_reg(context
) = SELECTOROF( pTask
->dta
);
1042 BX_reg(context
) = OFFSETOF( pTask
->dta
);
1046 case 0x30: /* GET DOS VERSION */
1047 AX_reg(context
) = DOSVERSION
;
1048 BX_reg(context
) = 0x0012; /* 0x123456 is Wine's serial # */
1049 CX_reg(context
) = 0x3456;
1052 case 0x31: /* TERMINATE AND STAY RESIDENT */
1053 INT_BARF( context
, 0x21 );
1056 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1057 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1060 case 0x33: /* MULTIPLEXED */
1061 switch (AL_reg(context
))
1063 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1064 DL_reg(context
) = 0;
1067 case 0x01: /* SET EXTENDED BREAK STATE */
1070 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1071 DL_reg(context
) = 0;
1074 case 0x05: /* GET BOOT DRIVE */
1075 DL_reg(context
) = 3;
1076 /* c: is Wine's bootdrive (a: is 1)*/
1079 case 0x06: /* GET TRUE VERSION NUMBER */
1080 BX_reg(context
) = DOSVERSION
;
1081 DX_reg(context
) = 0x00;
1085 INT_BARF( context
, 0x21 );
1090 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1091 if (!heap
) INT21_CreateHeap();
1092 ES_reg(context
) = DosHeapHandle
;
1093 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1096 case 0x35: /* GET INTERRUPT VECTOR */
1098 FARPROC16 addr
= INT_GetHandler( AL_reg(context
) );
1099 ES_reg(context
) = SELECTOROF(addr
);
1100 BX_reg(context
) = OFFSETOF(addr
);
1104 case 0x36: /* GET FREE DISK SPACE */
1105 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1108 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1109 AX_reg(context
) = 0x02; /* no country support available */
1113 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1114 bSetDOSExtendedError
= (!CreateDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1115 DX_reg(context
) ), NULL
));
1118 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1119 bSetDOSExtendedError
= (!RemoveDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1120 DX_reg(context
) )));
1123 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1124 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1127 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1128 AX_reg(context
) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1129 DX_reg(context
) ), CX_reg(context
) );
1130 bSetDOSExtendedError
= (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
1133 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1134 OpenExistingFile(context
);
1137 case 0x3e: /* "CLOSE" - CLOSE FILE */
1138 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1141 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1143 LONG result
= WIN16_hread( BX_reg(context
),
1144 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1147 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1148 else AX_reg(context
) = (WORD
)result
;
1152 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1154 LONG result
= _hwrite16( BX_reg(context
),
1155 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1158 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1159 else AX_reg(context
) = (WORD
)result
;
1163 case 0x41: /* "UNLINK" - DELETE FILE */
1164 bSetDOSExtendedError
= (!DeleteFile32A( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1165 DX_reg(context
) )));
1168 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1170 LONG status
= _llseek16( BX_reg(context
),
1171 MAKELONG(DX_reg(context
),CX_reg(context
)),
1173 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1176 AX_reg(context
) = LOWORD(status
);
1177 DX_reg(context
) = HIWORD(status
);
1182 case 0x43: /* FILE ATTRIBUTES */
1183 switch (AL_reg(context
))
1186 AX_reg(context
) = (WORD
)GetFileAttributes32A(
1187 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1189 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1190 else CX_reg(context
) = AX_reg(context
);
1194 bSetDOSExtendedError
=
1195 (!SetFileAttributes32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1202 case 0x44: /* IOCTL */
1203 switch (AL_reg(context
))
1206 ioctlGetDeviceInfo(context
);
1211 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1212 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
));
1214 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1216 fprintf(stdnimp
,"int21: program tried to write to block device control channel of drive %d:\n",drive
);
1217 for (i
=0;i
<CX_reg(context
);i
++)
1218 fprintf(stdnimp
,"%02x ",dataptr
[i
]);
1219 fprintf(stdnimp
,"\n");
1220 AX_reg(context
)=CX_reg(context
);
1223 case 0x08: /* Check if drive is removable. */
1224 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1226 case DRIVE_CANNOTDETERMINE
:
1227 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1228 AX_reg(context
) = ER_InvalidDrive
;
1231 case DRIVE_REMOVABLE
:
1232 AX_reg(context
) = 0; /* removable */
1235 AX_reg(context
) = 1; /* not removable */
1240 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1241 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1243 case DRIVE_CANNOTDETERMINE
:
1244 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1245 AX_reg(context
) = ER_InvalidDrive
;
1249 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1252 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1257 case 0x0a: /* check if handle (BX) is remote */
1258 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1261 DX_reg(context
) = 0;
1264 case 0x0b: /* SET SHARING RETRY COUNT */
1265 if (!CX_reg(context
))
1267 AX_reg(context
) = 1;
1271 sharing_pause
= CX_reg(context
);
1272 if (!DX_reg(context
))
1273 sharing_retries
= DX_reg(context
);
1274 RESET_CFLAG(context
);
1278 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1281 case 0x0e: /* get logical drive mapping */
1282 AL_reg(context
) = 0; /* drive has no mapping */
1285 case 0x0F: /* Set logical drive mapping */
1286 /* FIXME: Not implemented at the moment, always returns error
1288 INT_BARF( context
, 0x21 );
1289 AX_reg(context
) = 0x0001; /* invalid function */
1294 INT_BARF( context
, 0x21 );
1299 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1300 bSetDOSExtendedError
= ((AX_reg(context
) = FILE_Dup(BX_reg(context
))) == (WORD
)HFILE_ERROR16
);
1303 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1304 bSetDOSExtendedError
= (FILE_Dup2( BX_reg(context
), CX_reg(context
) ) == HFILE_ERROR32
);
1307 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1308 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1311 case 0x48: /* ALLOCATE MEMORY */
1312 case 0x49: /* FREE MEMORY */
1313 case 0x4a: /* RESIZE MEMORY BLOCK */
1314 INT_BARF( context
, 0x21 );
1317 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1318 AX_reg(context
) = WinExec16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1321 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1324 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1325 TASK_KillCurrentTask( AL_reg(context
) );
1328 case 0x4d: /* GET RETURN CODE */
1329 AX_reg(context
) = 0; /* normal exit */
1332 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1333 if (!INT21_FindFirst(context
)) break;
1336 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1337 if (!INT21_FindNext(context
))
1339 DOS_ERROR( ER_NoMoreFiles
, EC_MediaError
, SA_Abort
, EL_Disk
);
1340 AX_reg(context
) = ER_NoMoreFiles
;
1345 case 0x51: /* GET PSP ADDRESS */
1346 case 0x62: /* GET PSP ADDRESS */
1347 /* FIXME: should we return the original DOS PSP upon */
1348 /* Windows startup ? */
1349 BX_reg(context
) = GetCurrentPDB();
1352 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1353 ES_reg(context
) = 0x0;
1354 BX_reg(context
) = 0x0;
1355 INT_BARF( context
, 0x21 );
1358 case 0x56: /* "RENAME" - RENAME FILE */
1359 bSetDOSExtendedError
=
1360 (!MoveFile32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
1361 PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
))));
1364 case 0x57: /* FILE DATE AND TIME */
1365 switch (AL_reg(context
))
1367 case 0x00: /* Get */
1370 if (!GetFileTime( BX_reg(context
), NULL
, NULL
, &filetime
))
1371 bSetDOSExtendedError
= TRUE
;
1372 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1377 case 0x01: /* Set */
1380 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1382 bSetDOSExtendedError
=
1383 (!SetFileTime( BX_reg(context
), NULL
, NULL
, &filetime
));
1389 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1390 switch (AL_reg(context
))
1393 AX_reg(context
) = 1;
1396 AX_reg(context
) = 0;
1402 RESET_CFLAG(context
);
1405 case 0x5a: /* CREATE TEMPORARY FILE */
1406 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1409 case 0x5b: /* CREATE NEW FILE */
1410 bSetDOSExtendedError
= ((AX_reg(context
) =
1411 _lcreat_uniq( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)), 0 ))
1412 == (WORD
)HFILE_ERROR16
);
1415 case 0x5d: /* NETWORK */
1417 /* network software not installed */
1418 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1419 bSetDOSExtendedError
= TRUE
;
1422 case 0x5f: /* NETWORK */
1423 switch (AL_reg(context
))
1425 case 0x07: /* ENABLE DRIVE */
1426 if (!DRIVE_Enable( DL_reg(context
) ))
1428 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1429 bSetDOSExtendedError
= TRUE
;
1433 case 0x08: /* DISABLE DRIVE */
1434 if (!DRIVE_Disable( DL_reg(context
) ))
1436 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1437 bSetDOSExtendedError
= TRUE
;
1442 /* network software not installed */
1443 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1444 bSetDOSExtendedError
= TRUE
;
1449 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1451 if (!GetFullPathName32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1452 SI_reg(context
)), 128,
1453 PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1454 DI_reg(context
)),NULL
))
1455 bSetDOSExtendedError
= TRUE
;
1456 else AX_reg(context
) = 0;
1460 case 0x61: /* UNUSED */
1461 case 0x63: /* UNUSED */
1462 case 0x64: /* OS/2 DOS BOX */
1463 INT_BARF( context
, 0x21 );
1467 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1468 extern WORD WINE_LanguageId
;
1469 BYTE
*dataptr
=PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
));;
1470 switch (AL_reg(context
)) {
1473 *(WORD
*)(dataptr
+1) = 41;
1474 *(WORD
*)(dataptr
+3) = WINE_LanguageId
;
1475 *(WORD
*)(dataptr
+5) = CodePage
;
1479 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
1480 CX_reg(context
) = 258;/*FIXME: size of table?*/
1483 INT_BARF( context
, 0x21 );
1489 case 0x66: /* GLOBAL CODE PAGE TABLE */
1490 switch (AL_reg(context
))
1493 DX_reg(context
) = BX_reg(context
) = CodePage
;
1494 RESET_CFLAG(context
);
1497 CodePage
= BX_reg(context
);
1498 RESET_CFLAG(context
);
1503 case 0x67: /* SET HANDLE COUNT */
1504 SetHandleCount16( BX_reg(context
) );
1505 if (DOS_ExtendedError
) bSetDOSExtendedError
= TRUE
;
1508 case 0x68: /* "FFLUSH" - COMMIT FILE */
1509 case 0x6a: /* COMMIT FILE */
1510 bSetDOSExtendedError
= (!FlushFileBuffers( BX_reg(context
) ));
1513 case 0x69: /* DISK SERIAL NUMBER */
1514 switch (AL_reg(context
))
1517 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1518 else AX_reg(context
) = 0;
1522 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1523 else AX_reg(context
) = 1;
1528 case 0x6C: /* Extended Open/Create*/
1529 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
1532 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1533 switch(AL_reg(context
))
1535 case 0x39: /* Create directory */
1536 bSetDOSExtendedError
= (!CreateDirectory32A(
1537 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1538 DX_reg(context
) ), NULL
));
1540 case 0x3a: /* Remove directory */
1541 bSetDOSExtendedError
= (!RemoveDirectory32A(
1542 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1543 DX_reg(context
) )));
1545 case 0x43: /* Get/Set file attributes */
1546 switch (BL_reg(context
))
1548 case 0x00: /* Get file attributes */
1549 CX_reg(context
) = (WORD
)GetFileAttributes32A(
1550 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1552 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1555 bSetDOSExtendedError
= (!SetFileAttributes32A(
1556 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1558 CX_reg(context
) ) );
1562 "Unimplemented int21 long file name function:\n");
1563 INT_BARF( context
, 0x21 );
1565 AL_reg(context
) = 0;
1569 case 0x47: /* Get current directory */
1570 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1573 case 0x4e: /* Find first file */
1574 /* FIXME: use attributes in CX */
1575 if ((AX_reg(context
) = FindFirstFile16(
1576 PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
1577 (WIN32_FIND_DATA32A
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1579 == INVALID_HANDLE_VALUE16
)
1580 bSetDOSExtendedError
= TRUE
;
1582 case 0x4f: /* Find next file */
1583 if (!FindNextFile16( BX_reg(context
),
1584 (WIN32_FIND_DATA32A
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1586 bSetDOSExtendedError
= TRUE
;
1588 case 0xa1: /* Find close */
1589 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
1594 switch(CL_reg(context
))
1596 case 0x02: /*Get canonical long filename or path */
1597 if (!GetFullPathName32A
1598 ( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1599 SI_reg(context
)), 128,
1600 PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1601 DI_reg(context
)),NULL
))
1602 bSetDOSExtendedError
= TRUE
;
1603 else AX_reg(context
) = 0;
1607 "Unimplemented int21 long file name function:\n");
1608 INT_BARF( context
, 0x21 );
1610 AL_reg(context
) = 0;
1614 case 0x6c: /* Create or open file */
1615 /* translate Dos 7 action to Dos 6 action */
1616 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
1619 case 0x3b: /* Change directory */
1620 if (!SetCurrentDirectory32A(PTR_SEG_OFF_TO_LIN(
1626 AL_reg(context
) = DOS_ExtendedError
;
1629 case 0x41: /* Delete file */
1630 case 0x56: /* Move (rename) file */
1632 fprintf( stderr
, "Unimplemented int21 long file name function:\n");
1633 INT_BARF( context
, 0x21 );
1635 AL_reg(context
) = 0;
1640 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
1641 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
1642 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
1643 dprintf_int(stddeb
,"int21: windows95 function AX %04x\n",
1645 dprintf_int(stddeb
, " returning unimplemented\n");
1647 AL_reg(context
) = 0;
1650 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1651 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1655 INT_BARF( context
, 0x21 );
1658 } /* END OF SWITCH */
1660 if( bSetDOSExtendedError
) /* set general error condition */
1662 AX_reg(context
) = DOS_ExtendedError
;
1666 dprintf_int( stddeb
, "ret21: AX=%04x BX=%04x CX=%04x DX=%04x "
1667 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1668 AX_reg(context
), BX_reg(context
), CX_reg(context
),
1669 DX_reg(context
), SI_reg(context
), DI_reg(context
),
1670 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),