Release 980201
[wine/multimedia.git] / msdos / int21.c
blob0fa7a21f975e2e8aa0720764e399e3db43d19682
1 /*
2 * DOS interrupt 21h handler
3 */
5 #include <time.h>
6 #include <fcntl.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <sys/file.h>
11 #include <string.h>
12 #include <sys/stat.h>
13 #include <sys/time.h>
14 #include <sys/types.h>
15 #include <unistd.h>
16 #include <utime.h>
17 #include <ctype.h>
18 #include "windows.h"
19 #include "drive.h"
20 #include "file.h"
21 #include "heap.h"
22 #include "msdos.h"
23 #include "ldt.h"
24 #include "task.h"
25 #include "options.h"
26 #include "miscemu.h"
27 #include "stddebug.h"
28 #include "debug.h"
29 #if defined(__svr4__) || defined(_SCO_DS)
30 /* SVR4 DOESNT do locking the same way must implement properly */
31 #define LOCK_EX 0
32 #define LOCK_SH 1
33 #define LOCK_NB 8
34 #endif
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
42 * heap.
44 struct DPB
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) */
66 WORD CodePage = 437;
67 DWORD dpbsegptr;
69 struct DosHeap {
70 BYTE InDosFlag;
71 BYTE mediaID;
72 BYTE biosdate[8];
73 struct DPB dpb;
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");
88 return FALSE;
90 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
91 dpbsegptr = PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
92 heap->InDosFlag = 0;
93 strcpy(heap->biosdate, "01/01/80");
94 return TRUE;
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)
106 if (drive > 1) {
107 setword(data, 512);
108 data[2] = 2;
109 setword(&data[3], 0);
110 data[5] = 2;
111 setword(&data[6], 240);
112 setword(&data[8], 64000);
113 data[0x0a] = 0xf8;
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);
119 data[0x21] = 5;
120 setword(&data[0x22], 1);
121 } else { /* 1.44mb */
122 setword(data, 512);
123 data[2] = 2;
124 setword(&data[3], 0);
125 data[5] = 2;
126 setword(&data[6], 240);
127 setword(&data[8], 2880);
128 data[0x0a] = 0xf8;
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);
134 data[0x21] = 7;
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, &sector_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;
151 return 1;
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;
161 return 1;
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;
196 heap->dpb.next = 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 )
209 int curr_drive;
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 );
230 return TRUE;
233 if (CH_reg(context) != 0x08)
235 INT_BARF( context, 0x21 );
236 return FALSE;
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));
243 break;
245 case 0x60: /* get device parameters */
246 /* used by w4wgrp's winfile */
247 memset(dataptr, 0, 0x26);
248 dataptr[0] = 0x04;
249 dataptr[6] = 0; /* media type */
250 if (drive > 1)
252 dataptr[1] = 0x05; /* fixed disk */
253 setword(&dataptr[2], 0x01); /* non removable */
254 setword(&dataptr[4], 0x300); /* # of cylinders */
256 else
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);
264 break;
266 case 0x66:/* get disk serial number */
268 char label[12],fsname[9],path[4];
269 DWORD serial;
271 strcpy(path,"x:\\");path[0]=drive+'A';
272 GetVolumeInformation32A(
273 path,label,12,&serial,NULL,NULL,fsname,9
275 *(WORD*)dataptr = 0;
276 memcpy(dataptr+2,&serial,4);
277 memcpy(dataptr+6,label ,11);
278 memcpy(dataptr+17,fsname,8);
280 break;
282 case 0x6a:
283 dprintf_int(stddeb,"int21: logical volume %d unlocked.\n",drive);
284 break;
286 default:
287 INT_BARF( context, 0x21 );
289 return FALSE;
292 static void INT21_GetSystemDate( CONTEXT *context )
294 SYSTEMTIME systime;
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 )
303 SYSTEMTIME systime;
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)),
320 AL_reg(context) );
321 if (AX_reg(context) == (WORD)HFILE_ERROR16)
323 AX_reg(context) = DOS_ExtendedError;
324 SET_CFLAG(context);
326 #if 0
328 int handle;
329 int mode;
330 int lock;
332 switch (AX_reg(context) & 0x0070)
334 case 0x00: /* compatability mode */
335 case 0x40: /* DENYNONE */
336 lock = -1;
337 break;
339 case 0x30: /* DENYREAD */
340 dprintf_int(stddeb,
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 */
344 lock = LOCK_EX;
345 break;
347 case 0x20: /* DENYWRITE */
348 lock = LOCK_SH;
349 break;
351 default:
352 lock = -1;
355 if (lock != -1)
358 int result,retries=sharing_retries;
360 #if defined(__svr4__) || defined(_SCO_DS)
361 printf("Should call flock and needs porting to lockf\n");
362 result = 0;
363 retries = 0;
364 #else
365 result = flock(handle, lock | LOCK_NB);
366 #endif
367 if ( retries && (!result) )
369 int i;
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++)
373 result--;
376 while( (!result) && (!(retries--)) );
378 if(result)
380 errno_to_doserr();
381 AX_reg(context) = DOS_ExtendedError;
382 close(handle);
383 SET_CFLAG(context);
384 return;
389 Error (0,0,0);
390 AX_reg(context) = handle;
391 RESET_CFLAG(context);
393 #endif
396 static void CloseFile( CONTEXT *context )
398 if ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0)
400 AX_reg(context) = DOS_ExtendedError;
401 SET_CFLAG(context);
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);
425 CloseFile(context);
426 AX_reg(context) = 0x0050; /*File exists*/
427 SET_CFLAG(context);
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);
436 CloseFile(context);
437 dprintf_int(stddeb, "int21: extended open/create: failed, trunc on ro file");
438 AX_reg(context) = 0x000C; /*Access code invalid*/
439 SET_CFLAG(context);
441 else
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);
448 CloseFile(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*/
453 CX_reg(context) = 0;
454 SET_CFLAG(context);
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;
469 uReturnCX = 0x3;
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)
481 CX_reg(context) = 0;
482 SET_CFLAG(context);
483 dprintf_int(stddeb, "int21: extended open/create: failed, file dosen't exist\n");
485 else
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;
498 CX_reg(context) = 2;
502 return bExtendedError;
506 static BOOL32 INT21_ChangeDir( CONTEXT *context )
508 int drive;
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';
515 dirname += 2;
517 else drive = DRIVE_GetCurrentDrive();
518 return DRIVE_Chdir( drive, dirname );
522 static int INT21_FindFirst( CONTEXT *context )
524 char *p;
525 const char *path;
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;
534 SET_CFLAG(context);
535 return 0;
537 dta->unixPath = HEAP_strdupA( GetProcessHeap(), 0, full_name.long_name );
538 p = strrchr( dta->unixPath, '/' );
539 *p = '\0';
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;
550 SET_CFLAG(context);
551 return 0;
553 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
554 : DRIVE_GetCurrentDrive();
555 dta->count = 0;
556 dta->search_attr = CL_reg(context);
557 return 1;
561 static int INT21_FindNext( CONTEXT *context )
563 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA();
564 WIN32_FIND_DATA32A entry;
565 int count;
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;
573 return 0;
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;
580 return 0;
582 dta->count += count;
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 );
588 return 1;
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++ = '\\';
602 for (;;)
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 );
610 return TRUE;
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 );
625 return FALSE;
627 lstrcpyn32A( ptr, DRIVE_GetDosCwd(drive), 64 );
628 AX_reg(context) = 0x0100; /* success return code */
629 return TRUE;
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 );
641 return 0;
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);
648 return 1;
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 );
660 return 0;
663 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
664 return 1;
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));
674 FINDFILE_FCB *pFCB;
675 LPCSTR root, cwd;
676 int drive;
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 );
689 pFCB->count = 0;
690 return 1;
694 static int INT21_FindNextFCB( CONTEXT *context )
696 BYTE *fcb = (BYTE *)PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
697 FINDFILE_FCB *pFCB;
698 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA();
699 WIN32_FIND_DATA32A entry;
700 BYTE attr;
701 int count;
703 if (*fcb == 0xff) /* extended FCB ? */
705 attr = fcb[6];
706 pFCB = (FINDFILE_FCB *)(fcb + 7);
708 else
710 attr = 0;
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;
721 return 0;
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;
729 ((BYTE *)pResult)++;
731 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
732 ((BYTE *)pResult)++;
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] = '.';
746 else
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 ) );
755 else
756 memcpy( pResult->filename, entry.cAlternateFileName,
757 MIN( strlen(entry.cAlternateFileName), 8 ) );
759 return 1;
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;
785 SET_CFLAG(context);
787 break;
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;
794 SET_CFLAG(context);
796 return;
797 default:
798 AX_reg(context) = 0x0001;
799 SET_CFLAG(context);
800 return;
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),
819 EFL_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;
827 return;
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 );
837 break;
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 );
869 break;
870 case 0x2e: /* SET VERIFY FLAG */
871 /* we cannot change the behaviour anyway, so just ignore it */
872 break;
874 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
875 case 0x1d:
876 case 0x1e:
877 case 0x20:
878 case 0x6b: /* NULL FUNCTION */
879 AL_reg(context) = 0;
880 break;
882 case 0x5c: /* "FLOCK" - RECORD LOCKING */
883 fLock(context);
884 break;
886 case 0x0d: /* DISK BUFFER FLUSH */
887 RESET_CFLAG(context); /* dos 6+ only */
888 break;
890 case 0x0e: /* SELECT DEFAULT DRIVE */
891 DRIVE_SetCurrentDrive( DL_reg(context) );
892 AL_reg(context) = MAX_DOS_DRIVES;
893 break;
895 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
896 if (!INT21_FindFirstFCB(context))
898 AL_reg(context) = 0xff;
899 break;
901 /* else fall through */
903 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
904 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
905 break;
907 case 0x13: /* DELETE FILE USING FCB */
908 DeleteFileFCB(context);
909 break;
911 case 0x17: /* RENAME FILE USING FCB */
912 RenameFileFCB(context);
913 break;
915 case 0x19: /* GET CURRENT DEFAULT DRIVE */
916 AL_reg(context) = DRIVE_GetCurrentDrive();
917 break;
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);
925 break;
927 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
928 DL_reg(context) = 0;
929 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
930 break;
932 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
933 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
934 break;
936 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
937 GetDrivePB(context, DRIVE_GetCurrentDrive());
938 break;
940 case 0x25: /* SET INTERRUPT VECTOR */
941 INT_SetHandler( AL_reg(context),
942 (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
943 DX_reg(context)));
944 break;
946 case 0x2a: /* GET SYSTEM DATE */
947 INT21_GetSystemDate(context);
948 break;
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 */
954 break;
956 case 0x2c: /* GET SYSTEM TIME */
957 INT21_GetSystemTime(context);
958 break;
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 */
965 break;
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 );
973 break;
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;
980 break;
982 case 0x31: /* TERMINATE AND STAY RESIDENT */
983 INT_BARF( context, 0x21 );
984 break;
986 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
987 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
988 break;
990 case 0x33: /* MULTIPLEXED */
991 switch (AL_reg(context))
993 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
994 DL_reg(context) = 0;
995 break;
997 case 0x01: /* SET EXTENDED BREAK STATE */
998 break;
1000 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1001 DL_reg(context) = 0;
1002 break;
1004 case 0x05: /* GET BOOT DRIVE */
1005 DL_reg(context) = 3;
1006 /* c: is Wine's bootdrive (a: is 1)*/
1007 break;
1009 case 0x06: /* GET TRUE VERSION NUMBER */
1010 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1011 (HIWORD(GetVersion16() << 8));
1012 DX_reg(context) = 0x00;
1013 break;
1015 default:
1016 INT_BARF( context, 0x21 );
1017 break;
1019 break;
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;
1025 break;
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);
1033 break;
1035 case 0x36: /* GET FREE DISK SPACE */
1036 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1037 break;
1039 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1040 AX_reg(context) = 0x02; /* no country support available */
1041 SET_CFLAG(context);
1042 break;
1044 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1045 bSetDOSExtendedError = (!CreateDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1046 DX_reg(context) ), NULL));
1047 break;
1049 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1050 bSetDOSExtendedError = (!RemoveDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1051 DX_reg(context) )));
1052 break;
1054 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1055 bSetDOSExtendedError = !INT21_ChangeDir(context);
1056 break;
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);
1062 break;
1064 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1065 OpenExistingFile(context);
1066 break;
1068 case 0x3e: /* "CLOSE" - CLOSE FILE */
1069 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1070 break;
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),
1076 DX_reg(context) ),
1077 CX_reg(context) );
1078 if (result == -1) bSetDOSExtendedError = TRUE;
1079 else AX_reg(context) = (WORD)result;
1081 break;
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),
1087 DX_reg(context) ),
1088 CX_reg(context) );
1089 if (result == -1) bSetDOSExtendedError = TRUE;
1090 else AX_reg(context) = (WORD)result;
1092 break;
1094 case 0x41: /* "UNLINK" - DELETE FILE */
1095 bSetDOSExtendedError = (!DeleteFile32A( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1096 DX_reg(context) )));
1097 break;
1099 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1101 LONG status = _llseek16( BX_reg(context),
1102 MAKELONG(DX_reg(context),CX_reg(context)),
1103 AL_reg(context) );
1104 if (status == -1) bSetDOSExtendedError = TRUE;
1105 else
1107 AX_reg(context) = LOWORD(status);
1108 DX_reg(context) = HIWORD(status);
1111 break;
1113 case 0x43: /* FILE ATTRIBUTES */
1114 switch (AL_reg(context))
1116 case 0x00:
1117 AX_reg(context) = (WORD)GetFileAttributes32A(
1118 PTR_SEG_OFF_TO_LIN(DS_reg(context),
1119 DX_reg(context)));
1120 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1121 else CX_reg(context) = AX_reg(context);
1122 break;
1124 case 0x01:
1125 bSetDOSExtendedError =
1126 (!SetFileAttributes32A( PTR_SEG_OFF_TO_LIN(DS_reg(context),
1127 DX_reg(context)),
1128 CX_reg(context) ));
1129 break;
1131 break;
1133 case 0x44: /* IOCTL */
1134 switch (AL_reg(context))
1136 case 0x00:
1137 ioctlGetDeviceInfo(context);
1138 break;
1140 case 0x01:
1141 break;
1142 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1143 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context));
1144 int i;
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);
1152 break;
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;
1160 SET_CFLAG(context);
1161 break;
1162 case DRIVE_REMOVABLE:
1163 AX_reg(context) = 0; /* removable */
1164 break;
1165 default:
1166 AX_reg(context) = 1; /* not removable */
1167 break;
1169 break;
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;
1177 SET_CFLAG(context);
1178 break;
1179 case DRIVE_REMOTE:
1180 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1181 break;
1182 default:
1183 DX_reg(context) = 0; /* FIXME: use driver attr here */
1184 break;
1186 break;
1188 case 0x0a: /* check if handle (BX) is remote */
1189 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1190 * not set on close
1192 DX_reg(context) = 0;
1193 break;
1195 case 0x0b: /* SET SHARING RETRY COUNT */
1196 if (!CX_reg(context))
1198 AX_reg(context) = 1;
1199 SET_CFLAG(context);
1200 break;
1202 sharing_pause = CX_reg(context);
1203 if (!DX_reg(context))
1204 sharing_retries = DX_reg(context);
1205 RESET_CFLAG(context);
1206 break;
1208 case 0x0d:
1209 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1210 break;
1212 case 0x0e: /* get logical drive mapping */
1213 AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1214 break;
1216 case 0x0F: /* Set logical drive mapping */
1218 int drive;
1219 drive = DOS_GET_DRIVE ( BL_reg(context) );
1220 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1222 SET_CFLAG(context);
1223 AX_reg(context) = 0x000F; /* invalid drive */
1225 break;
1228 default:
1229 INT_BARF( context, 0x21 );
1230 break;
1232 break;
1234 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1235 bSetDOSExtendedError = ((AX_reg(context) = FILE_Dup(BX_reg(context))) == (WORD)HFILE_ERROR16);
1236 break;
1238 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1239 bSetDOSExtendedError = (FILE_Dup2( BX_reg(context), CX_reg(context) ) == HFILE_ERROR32);
1240 break;
1242 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1243 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1244 break;
1246 case 0x48: /* ALLOCATE MEMORY */
1247 case 0x49: /* FREE MEMORY */
1248 case 0x4a: /* RESIZE MEMORY BLOCK */
1249 INT_BARF( context, 0x21 );
1250 break;
1252 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1253 AX_reg(context) = WinExec16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1254 DX_reg(context) ),
1255 SW_NORMAL );
1256 if (AX_reg(context) < 32) SET_CFLAG(context);
1257 break;
1259 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1260 TASK_KillCurrentTask( AL_reg(context) );
1261 break;
1263 case 0x4d: /* GET RETURN CODE */
1264 AX_reg(context) = 0; /* normal exit */
1265 break;
1267 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1268 if (!INT21_FindFirst(context)) break;
1269 /* fall through */
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;
1276 SET_CFLAG(context);
1278 else AX_reg(context) = 0; /* OK */
1279 break;
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();
1286 break;
1288 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1289 ES_reg(context) = 0x0;
1290 BX_reg(context) = 0x0;
1291 INT_BARF( context, 0x21 );
1292 break;
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))));
1298 break;
1300 case 0x57: /* FILE DATE AND TIME */
1301 switch (AL_reg(context))
1303 case 0x00: /* Get */
1305 FILETIME filetime;
1306 if (!GetFileTime( BX_reg(context), NULL, NULL, &filetime ))
1307 bSetDOSExtendedError = TRUE;
1308 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1309 &CX_reg(context) );
1311 break;
1313 case 0x01: /* Set */
1315 FILETIME filetime;
1316 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1317 &filetime );
1318 bSetDOSExtendedError =
1319 (!SetFileTime( BX_reg(context), NULL, NULL, &filetime ));
1321 break;
1323 break;
1325 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1326 switch (AL_reg(context))
1328 case 0x00:
1329 AX_reg(context) = 1;
1330 break;
1331 case 0x02:
1332 AX_reg(context) = 0;
1333 break;
1334 case 0x01:
1335 case 0x03:
1336 break;
1338 RESET_CFLAG(context);
1339 break;
1341 case 0x5a: /* CREATE TEMPORARY FILE */
1342 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1343 break;
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);
1349 break;
1351 case 0x5d: /* NETWORK */
1352 case 0x5e:
1353 /* network software not installed */
1354 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1355 bSetDOSExtendedError = TRUE;
1356 break;
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;
1367 break;
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;
1375 break;
1377 default:
1378 /* network software not installed */
1379 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1380 bSetDOSExtendedError = TRUE;
1381 break;
1383 break;
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;
1394 break;
1396 case 0x61: /* UNUSED */
1397 case 0x63: /* UNUSED */
1398 case 0x64: /* OS/2 DOS BOX */
1399 INT_BARF( context, 0x21 );
1400 SET_CFLAG(context);
1401 break;
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)) {
1407 case 0x01:
1408 dataptr[0] = 0x1;
1409 *(WORD*)(dataptr+1) = 41;
1410 *(WORD*)(dataptr+3) = WINE_LanguageId;
1411 *(WORD*)(dataptr+5) = CodePage;
1412 break;
1413 case 0x06:
1414 dataptr[0] = 0x06;
1415 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
1416 CX_reg(context) = 258;/*FIXME: size of table?*/
1417 break;
1418 default:
1419 INT_BARF( context, 0x21 );
1420 SET_CFLAG(context);
1421 break;
1423 break;
1425 case 0x66: /* GLOBAL CODE PAGE TABLE */
1426 switch (AL_reg(context))
1428 case 0x01:
1429 DX_reg(context) = BX_reg(context) = CodePage;
1430 RESET_CFLAG(context);
1431 break;
1432 case 0x02:
1433 CodePage = BX_reg(context);
1434 RESET_CFLAG(context);
1435 break;
1437 break;
1439 case 0x67: /* SET HANDLE COUNT */
1440 SetHandleCount16( BX_reg(context) );
1441 if (DOS_ExtendedError) bSetDOSExtendedError = TRUE;
1442 break;
1444 case 0x68: /* "FFLUSH" - COMMIT FILE */
1445 case 0x6a: /* COMMIT FILE */
1446 bSetDOSExtendedError = (!FlushFileBuffers( BX_reg(context) ));
1447 break;
1449 case 0x69: /* DISK SERIAL NUMBER */
1450 switch (AL_reg(context))
1452 case 0x00:
1453 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1454 else AX_reg(context) = 0;
1455 break;
1457 case 0x01:
1458 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1459 else AX_reg(context) = 1;
1460 break;
1462 break;
1464 case 0x6C: /* Extended Open/Create*/
1465 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
1466 break;
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));
1475 break;
1476 case 0x3a: /* Remove directory */
1477 bSetDOSExtendedError = (!RemoveDirectory32A(
1478 PTR_SEG_OFF_TO_LIN( DS_reg(context),
1479 DX_reg(context) )));
1480 break;
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),
1487 DX_reg(context)));
1488 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1489 break;
1490 case 0x01:
1491 bSetDOSExtendedError = (!SetFileAttributes32A(
1492 PTR_SEG_OFF_TO_LIN(DS_reg(context),
1493 DX_reg(context)),
1494 CX_reg(context) ) );
1495 break;
1496 default:
1497 fprintf( stderr,
1498 "Unimplemented int21 long file name function:\n");
1499 INT_BARF( context, 0x21 );
1500 SET_CFLAG(context);
1501 AL_reg(context) = 0;
1502 break;
1504 break;
1505 case 0x47: /* Get current directory */
1506 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1507 break;
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),
1514 DI_reg(context))))
1515 == INVALID_HANDLE_VALUE16)
1516 bSetDOSExtendedError = TRUE;
1517 break;
1518 case 0x4f: /* Find next file */
1519 if (!FindNextFile16( BX_reg(context),
1520 (WIN32_FIND_DATA32A *)PTR_SEG_OFF_TO_LIN(ES_reg(context),
1521 DI_reg(context))))
1522 bSetDOSExtendedError = TRUE;
1523 break;
1524 case 0xa1: /* Find close */
1525 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
1526 break;
1527 case 0xa0:
1528 break;
1529 case 0x60:
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;
1540 break;
1541 default:
1542 fprintf( stderr,
1543 "Unimplemented int21 long file name function:\n");
1544 INT_BARF( context, 0x21 );
1545 SET_CFLAG(context);
1546 AL_reg(context) = 0;
1547 break;
1549 break;
1550 case 0x6c: /* Create or open file */
1551 /* translate Dos 7 action to Dos 6 action */
1552 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
1553 break;
1555 case 0x3b: /* Change directory */
1556 if (!SetCurrentDirectory32A(PTR_SEG_OFF_TO_LIN(
1557 DS_reg(context),
1558 DX_reg(context)
1561 SET_CFLAG(context);
1562 AL_reg(context) = DOS_ExtendedError;
1564 break;
1565 case 0x41: /* Delete file */
1566 if (!DeleteFile32A(PTR_SEG_OFF_TO_LIN(
1567 DS_reg(context),
1568 DX_reg(context))
1569 )) {
1570 SET_CFLAG(context);
1571 AL_reg(context) = DOS_ExtendedError;
1573 break;
1574 case 0x56: /* Move (rename) file */
1575 default:
1576 fprintf( stderr, "Unimplemented int21 long file name function:\n");
1577 INT_BARF( context, 0x21 );
1578 SET_CFLAG(context);
1579 AL_reg(context) = 0;
1580 break;
1582 break;
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",
1588 AX_reg(context));
1589 dprintf_int(stddeb, " returning unimplemented\n");
1590 SET_CFLAG(context);
1591 AL_reg(context) = 0;
1592 break;
1594 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1595 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1596 break;
1598 default:
1599 INT_BARF( context, 0x21 );
1600 break;
1602 } /* END OF SWITCH */
1604 if( bSetDOSExtendedError ) /* set general error condition */
1606 AX_reg(context) = DOS_ExtendedError;
1607 SET_CFLAG(context);
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),
1615 EFL_reg(context));
1618 FARPROC16 WINAPI GetSetKernelDOSProc(FARPROC16 DosProc)
1620 fprintf(stderr, "GetSetKernelDOSProc(DosProc: %08x);\n", (UINT32)DosProc);
1621 return NULL;