Release 980913
[wine/multimedia.git] / msdos / int21.c
bloba17b6302c7d28587bf3d75f10add21dae88ea58b
1 /*
2 * DOS interrupt 21h handler
3 */
5 #include <time.h>
6 #include <fcntl.h>
7 #include <errno.h>
8 #include <stdlib.h>
9 #include <sys/file.h>
10 #include <string.h>
11 #include <sys/stat.h>
12 #include <sys/time.h>
13 #include <sys/types.h>
14 #include <unistd.h>
15 #include <utime.h>
16 #include <ctype.h>
17 #include "windows.h"
18 #include "drive.h"
19 #include "file.h"
20 #include "heap.h"
21 #include "msdos.h"
22 #include "ldt.h"
23 #include "task.h"
24 #include "options.h"
25 #include "miscemu.h"
26 #include "debug.h"
27 #if defined(__svr4__) || defined(_SCO_DS)
28 /* SVR4 DOESNT do locking the same way must implement properly */
29 #define LOCK_EX 0
30 #define LOCK_SH 1
31 #define LOCK_NB 8
32 #endif
35 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
37 /* Define the drive parameter block, as used by int21/1F
38 * and int21/32. This table can be accessed through the
39 * global 'dpb' pointer, which points into the local dos
40 * heap.
42 struct DPB
44 BYTE drive_num; /* 0=A, etc. */
45 BYTE unit_num; /* Drive's unit number (?) */
46 WORD sector_size; /* Sector size in bytes */
47 BYTE high_sector; /* Highest sector in a cluster */
48 BYTE shift; /* Shift count (?) */
49 WORD reserved; /* Number of reserved sectors at start */
50 BYTE num_FAT; /* Number of FATs */
51 WORD dir_entries; /* Number of root dir entries */
52 WORD first_data; /* First data sector */
53 WORD high_cluster; /* Highest cluster number */
54 WORD sectors_in_FAT; /* Number of sectors per FAT */
55 WORD start_dir; /* Starting sector of first dir */
56 DWORD driver_head; /* Address of device driver header (?) */
57 BYTE media_ID; /* Media ID */
58 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
59 DWORD next; /* Pointer to next DPB in list */
60 WORD free_search; /* Free cluster search start */
61 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
64 WORD CodePage = 437;
65 DWORD dpbsegptr;
67 struct DosHeap {
68 BYTE InDosFlag;
69 BYTE mediaID;
70 BYTE biosdate[8];
71 struct DPB dpb;
73 static struct DosHeap *heap;
74 static WORD DosHeapHandle;
76 WORD sharing_retries = 3; /* number of retries at sharing violation */
77 WORD sharing_pause = 1; /* pause between retries */
79 extern char TempDirectory[];
81 static BOOL32 INT21_CreateHeap(void)
83 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
85 WARN(int21, "Out of memory\n");
86 return FALSE;
88 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
89 dpbsegptr = PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
90 heap->InDosFlag = 0;
91 strcpy(heap->biosdate, "01/01/80");
92 return TRUE;
95 static BYTE *GetCurrentDTA( CONTEXT *context )
97 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
99 /* FIXME: This assumes DTA was set correctly! */
100 return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
101 OFFSETOF(pTask->dta) );
105 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
106 /* limited == TRUE is used with INT 0x21/0x440d */
108 if (drive > 1) {
109 setword(data, 512);
110 data[2] = 2;
111 setword(&data[3], 0);
112 data[5] = 2;
113 setword(&data[6], 240);
114 setword(&data[8], 64000);
115 data[0x0a] = 0xf8;
116 setword(&data[0x0b], 40);
117 setword(&data[0x0d], 56);
118 setword(&data[0x0f], 2);
119 setword(&data[0x11], 0);
120 if (!limited) {
121 setword(&data[0x1f], 800);
122 data[0x21] = 5;
123 setword(&data[0x22], 1);
125 } else { /* 1.44mb */
126 setword(data, 512);
127 data[2] = 2;
128 setword(&data[3], 0);
129 data[5] = 2;
130 setword(&data[6], 240);
131 setword(&data[8], 2880);
132 data[0x0a] = 0xf8;
133 setword(&data[0x0b], 6);
134 setword(&data[0x0d], 18);
135 setword(&data[0x0f], 2);
136 setword(&data[0x11], 0);
137 if (!limited) {
138 setword(&data[0x1f], 80);
139 data[0x21] = 7;
140 setword(&data[0x22], 2);
145 static int INT21_GetFreeDiskSpace( CONTEXT *context )
147 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
148 char root[] = "A:\\";
150 *root += DOS_GET_DRIVE( DL_reg(context) );
151 if (!GetDiskFreeSpace32A( root, &cluster_sectors, &sector_bytes,
152 &free_clusters, &total_clusters )) return 0;
153 AX_reg(context) = cluster_sectors;
154 BX_reg(context) = free_clusters;
155 CX_reg(context) = sector_bytes;
156 DX_reg(context) = total_clusters;
157 return 1;
160 static int INT21_GetDriveAllocInfo( CONTEXT *context )
162 if (!INT21_GetFreeDiskSpace( context )) return 0;
163 if (!heap && !INT21_CreateHeap()) return 0;
164 heap->mediaID = 0xf0;
165 DS_reg(context) = DosHeapHandle;
166 BX_reg(context) = (int)&heap->mediaID - (int)heap;
167 return 1;
170 static void GetDrivePB( CONTEXT *context, int drive )
172 if(!DRIVE_IsValid(drive))
174 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
175 AX_reg(context) = 0x00ff;
177 else if (heap || INT21_CreateHeap())
179 FIXME(int21, "GetDrivePB not fully implemented.\n");
181 /* FIXME: I have no idea what a lot of this information should
182 * say or whether it even really matters since we're not allowing
183 * direct block access. However, some programs seem to depend on
184 * getting at least _something_ back from here. The 'next' pointer
185 * does worry me, though. Should we have a complete table of
186 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
188 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
189 heap->dpb.sector_size = 512;
190 heap->dpb.high_sector = 1;
191 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
192 heap->dpb.reserved = 0;
193 heap->dpb.num_FAT = 1;
194 heap->dpb.dir_entries = 2;
195 heap->dpb.first_data = 2;
196 heap->dpb.high_cluster = 64000;
197 heap->dpb.sectors_in_FAT = 1;
198 heap->dpb.start_dir = 1;
199 heap->dpb.driver_head = 0;
200 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
201 heap->dpb.access_flag = 0;
202 heap->dpb.next = 0;
203 heap->dpb.free_search = 0;
204 heap->dpb.free_clusters = 0xFFFF; /* unknown */
206 AL_reg(context) = 0x00;
207 DS_reg(context) = SELECTOROF(dpbsegptr);
208 BX_reg(context) = OFFSETOF(dpbsegptr);
213 static void ioctlGetDeviceInfo( CONTEXT *context )
215 int curr_drive;
216 FILE_OBJECT *file;
218 TRACE(int21, "(%d)\n", BX_reg(context));
220 RESET_CFLAG(context);
222 /* DOS device ? */
223 if ((file = FILE_GetFile( HFILE16_TO_HFILE32(BX_reg(context)) )))
225 const DOS_DEVICE *dev = DOSFS_GetDevice( file->unix_name );
226 FILE_ReleaseFile( file );
227 if (dev)
229 DX_reg(context) = dev->flags;
230 return;
234 /* it seems to be a file */
235 curr_drive = DRIVE_GetCurrentDrive();
236 DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0);
237 /* no floppy */
238 /* bits 0-5 are current drive
239 * bit 6 - file has NOT been written..FIXME: correct?
240 * bit 8 - generate int24 if no diskspace on write/ read past end of file
241 * bit 11 - media not removable
242 * bit 14 - don't set file date/time on closing
243 * bit 15 - file is remote
247 static BOOL32 ioctlGenericBlkDevReq( CONTEXT *context )
249 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
250 int drive = DOS_GET_DRIVE( BL_reg(context) );
252 if (!DRIVE_IsValid(drive))
254 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
255 return TRUE;
258 if (CH_reg(context) != 0x08)
260 INT_BARF( context, 0x21 );
261 return FALSE;
264 switch (CL_reg(context))
266 case 0x4a: /* lock logical volume */
267 TRACE(int21,"lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
268 break;
270 case 0x60: /* get device parameters */
271 /* used by w4wgrp's winfile */
272 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
273 dataptr[0] = 0x04;
274 dataptr[6] = 0; /* media type */
275 if (drive > 1)
277 dataptr[1] = 0x05; /* fixed disk */
278 setword(&dataptr[2], 0x01); /* non removable */
279 setword(&dataptr[4], 0x300); /* # of cylinders */
281 else
283 dataptr[1] = 0x07; /* block dev, floppy */
284 setword(&dataptr[2], 0x02); /* removable */
285 setword(&dataptr[4], 80); /* # of cylinders */
287 CreateBPB(drive, &dataptr[7], TRUE);
288 RESET_CFLAG(context);
289 break;
291 case 0x66:/* get disk serial number */
293 char label[12],fsname[9],path[4];
294 DWORD serial;
296 strcpy(path,"x:\\");path[0]=drive+'A';
297 GetVolumeInformation32A(
298 path,label,12,&serial,NULL,NULL,fsname,9
300 *(WORD*)dataptr = 0;
301 memcpy(dataptr+2,&serial,4);
302 memcpy(dataptr+6,label ,11);
303 memcpy(dataptr+17,fsname,8);
305 break;
307 case 0x6a:
308 TRACE(int21,"logical volume %d unlocked.\n",drive);
309 break;
311 case 0x6f:
312 memset(dataptr+1, '\0', dataptr[0]-1);
313 dataptr[1] = dataptr[0];
314 dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
315 dataptr[3] = 0xFF; /* no physical drive */
316 break;
318 default:
319 INT_BARF( context, 0x21 );
321 return FALSE;
324 static void INT21_GetSystemDate( CONTEXT *context )
326 SYSTEMTIME systime;
327 GetLocalTime( &systime );
328 CX_reg(context) = systime.wYear;
329 DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
330 AX_reg(context) = systime.wDayOfWeek;
333 static void INT21_GetSystemTime( CONTEXT *context )
335 SYSTEMTIME systime;
336 GetLocalTime( &systime );
337 CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
338 DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
341 /* Many calls translate a drive argument like this:
342 drive number (00h = default, 01h = A:, etc)
344 static char drivestring[]="default";
346 char *INT21_DriveName(int drive)
349 if(drive >0)
351 drivestring[0]= (unsigned char)drive + '@';
352 drivestring[1]=':';
353 drivestring[2]=0;
355 return drivestring;
357 static BOOL32 INT21_CreateFile( CONTEXT *context )
359 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
360 DX_reg(context) ), CX_reg(context) );
361 return (AX_reg(context) == (WORD)HFILE_ERROR16);
365 static void OpenExistingFile( CONTEXT *context )
367 AX_reg(context) = _lopen16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)),
368 AL_reg(context) );
369 if (AX_reg(context) == (WORD)HFILE_ERROR16)
371 AX_reg(context) = DOS_ExtendedError;
372 SET_CFLAG(context);
374 #if 0
376 int handle;
377 int mode;
378 int lock;
380 switch (AX_reg(context) & 0x0070)
382 case 0x00: /* compatability mode */
383 case 0x40: /* DENYNONE */
384 lock = -1;
385 break;
387 case 0x30: /* DENYREAD */
388 TRACE(int21, "(%s): DENYREAD changed to DENYALL\n",
389 (char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
390 case 0x10: /* DENYALL */
391 lock = LOCK_EX;
392 break;
394 case 0x20: /* DENYWRITE */
395 lock = LOCK_SH;
396 break;
398 default:
399 lock = -1;
402 if (lock != -1)
405 int result,retries=sharing_retries;
407 #if defined(__svr4__) || defined(_SCO_DS)
408 ERR(int21, "Should call flock and needs porting to lockf\n");
409 result = 0;
410 retries = 0;
411 #else
412 result = flock(handle, lock | LOCK_NB);
413 #endif
414 if ( retries && (!result) )
416 int i;
417 for(i=0;i<32768*((int)sharing_pause);i++)
418 result++; /* stop the optimizer */
419 for(i=0;i<32768*((int)sharing_pause);i++)
420 result--;
423 while( (!result) && (!(retries--)) );
425 if(result)
427 errno_to_doserr();
428 AX_reg(context) = DOS_ExtendedError;
429 close(handle);
430 SET_CFLAG(context);
431 return;
436 Error (0,0,0);
437 AX_reg(context) = handle;
438 RESET_CFLAG(context);
440 #endif
443 static void CloseFile( CONTEXT *context )
445 if ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0)
447 AX_reg(context) = DOS_ExtendedError;
448 SET_CFLAG(context);
452 static BOOL32 INT21_ExtendedOpenCreateFile(CONTEXT *context )
454 BOOL32 bExtendedError = FALSE;
455 BYTE action = DL_reg(context);
457 /* Shuffle arguments to call OpenExistingFile */
458 AL_reg(context) = BL_reg(context);
459 DX_reg(context) = SI_reg(context);
460 /* BX,CX and DX should be preserved */
461 OpenExistingFile(context);
463 if ((EFL_reg(context) & 0x0001) == 0) /* File exists */
465 UINT16 uReturnCX = 0;
467 /* Now decide what do do */
469 if ((action & 0x07) == 0)
471 BX_reg(context) = AX_reg(context);
472 CloseFile(context);
473 AX_reg(context) = 0x0050; /*File exists*/
474 SET_CFLAG(context);
475 WARN(int21, "extended open/create: failed because file exists \n");
477 else if ((action & 0x07) == 2)
479 /* Truncate it, but first check if opened for write */
480 if ((BL_reg(context) & 0x0007)== 0)
482 BX_reg(context) = AX_reg(context);
483 CloseFile(context);
484 WARN(int21, "extended open/create: failed, trunc on ro file\n");
485 AX_reg(context) = 0x000C; /*Access code invalid*/
486 SET_CFLAG(context);
488 else
490 /* Shuffle arguments to call CloseFile while
491 * preserving BX and DX */
493 TRACE(int21, "extended open/create: Closing before truncate\n");
494 BX_reg(context) = AX_reg(context);
495 CloseFile(context);
496 if (EFL_reg(context) & 0x0001)
498 WARN(int21, "extended open/create: close before trunc failed\n");
499 AX_reg(context) = 0x0019; /*Seek Error*/
500 CX_reg(context) = 0;
501 SET_CFLAG(context);
503 /* Shuffle arguments to call CreateFile */
505 TRACE(int21, "extended open/create: Truncating\n");
506 AL_reg(context) = BL_reg(context);
507 /* CX is still the same */
508 DX_reg(context) = SI_reg(context);
509 bExtendedError = INT21_CreateFile(context);
511 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
513 WARN(int21, "extended open/create: trunc failed\n");
514 return bExtendedError;
516 uReturnCX = 0x3;
519 else uReturnCX = 0x1;
521 CX_reg(context) = uReturnCX;
523 else /* file does not exist */
525 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
526 if ((action & 0xF0)== 0)
528 CX_reg(context) = 0;
529 SET_CFLAG(context);
530 WARN(int21, "extended open/create: failed, file dosen't exist\n");
532 else
534 /* Shuffle arguments to call CreateFile */
535 TRACE(int21, "extended open/create: Creating\n");
536 AL_reg(context) = BL_reg(context);
537 /* CX should still be the same */
538 DX_reg(context) = SI_reg(context);
539 bExtendedError = INT21_CreateFile(context);
540 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
542 WARN(int21, "extended open/create: create failed\n");
543 return bExtendedError;
545 CX_reg(context) = 2;
549 return bExtendedError;
553 static BOOL32 INT21_ChangeDir( CONTEXT *context )
555 int drive;
556 char *dirname = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context));
558 TRACE(int21,"changedir %s\n", dirname);
559 if (dirname[0] && (dirname[1] == ':'))
561 drive = toupper(dirname[0]) - 'A';
562 dirname += 2;
564 else drive = DRIVE_GetCurrentDrive();
565 return DRIVE_Chdir( drive, dirname );
569 static int INT21_FindFirst( CONTEXT *context )
571 char *p;
572 const char *path;
573 DOS_FULL_NAME full_name;
574 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
576 path = (const char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
577 dta->unixPath = NULL;
578 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
580 AX_reg(context) = DOS_ExtendedError;
581 SET_CFLAG(context);
582 return 0;
584 dta->unixPath = HEAP_strdupA( GetProcessHeap(), 0, full_name.long_name );
585 p = strrchr( dta->unixPath, '/' );
586 *p = '\0';
588 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
589 * (doesn't matter as it is set below anyway)
591 if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
593 HeapFree( GetProcessHeap(), 0, dta->unixPath );
594 dta->unixPath = NULL;
595 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
596 AX_reg(context) = ER_FileNotFound;
597 SET_CFLAG(context);
598 return 0;
600 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
601 : DRIVE_GetCurrentDrive();
602 dta->count = 0;
603 dta->search_attr = CL_reg(context);
604 return 1;
608 static int INT21_FindNext( CONTEXT *context )
610 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
611 WIN32_FIND_DATA32A entry;
612 int count;
614 if (!dta->unixPath) return 0;
615 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
616 dta->search_attr, dta->count, &entry )))
618 HeapFree( GetProcessHeap(), 0, dta->unixPath );
619 dta->unixPath = NULL;
620 return 0;
622 if ((int)dta->count + count > 0xffff)
624 WARN(int21, "Too many directory entries in %s\n", dta->unixPath );
625 HeapFree( GetProcessHeap(), 0, dta->unixPath );
626 dta->unixPath = NULL;
627 return 0;
629 dta->count += count;
630 dta->fileattr = entry.dwFileAttributes;
631 dta->filesize = entry.nFileSizeLow;
632 FileTimeToDosDateTime( &entry.ftLastWriteTime,
633 &dta->filedate, &dta->filetime );
634 strcpy( dta->filename, entry.cAlternateFileName );
635 if (!memchr(dta->mask,'?',11)) {
636 /* wildcardless search, release resources in case no findnext will
637 * be issued, and as a workaround in case file creation messes up
638 * findnext, as sometimes happens with pkunzip */
639 HeapFree( GetProcessHeap(), 0, dta->unixPath );
640 dta->unixPath = NULL;
642 return 1;
646 static BOOL32 INT21_CreateTempFile( CONTEXT *context )
648 static int counter = 0;
649 char *name = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context) );
650 char *p = name + strlen(name);
652 /* despite what Ralf Brown says, some programs seem to call without
653 * ending backslash (DOS accepts that, so we accept it too) */
654 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
656 for (;;)
658 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
659 counter = (counter + 1) % 1000;
661 if ((AX_reg(context) = HFILE32_TO_HFILE16(_lcreat_uniq( name, 0 ))) != (WORD)HFILE_ERROR16)
663 TRACE(int21, "created %s\n", name );
664 return TRUE;
666 if (DOS_ExtendedError != ER_FileExists) return FALSE;
671 static BOOL32 INT21_GetCurrentDirectory( CONTEXT *context )
673 int drive = DOS_GET_DRIVE( DL_reg(context) );
674 char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), SI_reg(context) );
676 if (!DRIVE_IsValid(drive))
678 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
679 return FALSE;
681 lstrcpyn32A( ptr, DRIVE_GetDosCwd(drive), 64 );
682 AX_reg(context) = 0x0100; /* success return code */
683 return TRUE;
687 static int INT21_GetDiskSerialNumber( CONTEXT *context )
689 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
690 int drive = DOS_GET_DRIVE( BL_reg(context) );
692 if (!DRIVE_IsValid(drive))
694 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
695 return 0;
698 *(WORD *)dataptr = 0;
699 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
700 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
701 strncpy(dataptr + 0x11, "FAT16 ", 8);
702 return 1;
706 static int INT21_SetDiskSerialNumber( CONTEXT *context )
708 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
709 int drive = DOS_GET_DRIVE( BL_reg(context) );
711 if (!DRIVE_IsValid(drive))
713 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
714 return 0;
717 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
718 return 1;
722 /* microsoft's programmers should be shot for using CP/M style int21
723 calls in Windows for Workgroup's winfile.exe */
725 static int INT21_FindFirstFCB( CONTEXT *context )
727 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
728 FINDFILE_FCB *pFCB;
729 LPCSTR root, cwd;
730 int drive;
732 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
733 else pFCB = (FINDFILE_FCB *)fcb;
734 drive = DOS_GET_DRIVE( pFCB->drive );
735 if (!DRIVE_IsValid( drive )) return 0;
736 root = DRIVE_GetRoot( drive );
737 cwd = DRIVE_GetUnixCwd( drive );
738 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
739 strlen(root)+strlen(cwd)+2 );
740 if (!pFCB->unixPath) return 0;
741 strcpy( pFCB->unixPath, root );
742 strcat( pFCB->unixPath, "/" );
743 strcat( pFCB->unixPath, cwd );
744 pFCB->count = 0;
745 return 1;
749 static int INT21_FindNextFCB( CONTEXT *context )
751 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
752 FINDFILE_FCB *pFCB;
753 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA(context);
754 WIN32_FIND_DATA32A entry;
755 BYTE attr;
756 int count;
758 if (*fcb == 0xff) /* extended FCB ? */
760 attr = fcb[6];
761 pFCB = (FINDFILE_FCB *)(fcb + 7);
763 else
765 attr = 0;
766 pFCB = (FINDFILE_FCB *)fcb;
769 if (!pFCB->unixPath) return 0;
770 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
771 DOS_GET_DRIVE( pFCB->drive ), attr,
772 pFCB->count, &entry )))
774 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
775 pFCB->unixPath = NULL;
776 return 0;
778 pFCB->count += count;
780 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
781 *(BYTE *)pResult = 0xff;
782 (BYTE *)pResult +=6; /* leave reserved field behind */
783 *(BYTE *)pResult = entry.dwFileAttributes;
784 ((BYTE *)pResult)++;
786 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
787 ((BYTE *)pResult)++;
788 pResult->fileattr = entry.dwFileAttributes;
789 pResult->cluster = 0; /* what else? */
790 pResult->filesize = entry.nFileSizeLow;
791 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
792 FileTimeToDosDateTime( &entry.ftLastWriteTime,
793 &pResult->filedate, &pResult->filetime );
795 /* Convert file name to FCB format */
797 memset( pResult->filename, ' ', sizeof(pResult->filename) );
798 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
799 else if (!strcmp( entry.cAlternateFileName, ".." ))
800 pResult->filename[0] = pResult->filename[1] = '.';
801 else
803 char *p = strrchr( entry.cAlternateFileName, '.' );
804 if (p && p[1] && (p != entry.cAlternateFileName))
806 memcpy( pResult->filename, entry.cAlternateFileName,
807 MIN( (p - entry.cAlternateFileName), 8 ) );
808 memcpy( pResult->filename + 8, p + 1, MIN( strlen(p), 3 ) );
810 else
811 memcpy( pResult->filename, entry.cAlternateFileName,
812 MIN( strlen(entry.cAlternateFileName), 8 ) );
814 return 1;
818 static void DeleteFileFCB( CONTEXT *context )
820 FIXME(int21, "(%p): not implemented yet\n", context);
823 static void RenameFileFCB( CONTEXT *context )
825 FIXME(int21, "(%p): not implemented yet\n", context);
830 static void fLock( CONTEXT * context )
833 switch ( AX_reg(context) & 0xff )
835 case 0x00: /* LOCK */
836 TRACE(int21,"lock handle %d offset %ld length %ld\n",
837 BX_reg(context),
838 MAKELONG(DX_reg(context),CX_reg(context)),
839 MAKELONG(DI_reg(context),SI_reg(context))) ;
840 if (!LockFile(HFILE16_TO_HFILE32(BX_reg(context)),
841 MAKELONG(DX_reg(context),CX_reg(context)), 0,
842 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
843 AX_reg(context) = DOS_ExtendedError;
844 SET_CFLAG(context);
846 break;
848 case 0x01: /* UNLOCK */
849 TRACE(int21,"unlock handle %d offset %ld length %ld\n",
850 BX_reg(context),
851 MAKELONG(DX_reg(context),CX_reg(context)),
852 MAKELONG(DI_reg(context),SI_reg(context))) ;
853 if (!UnlockFile(HFILE16_TO_HFILE32(BX_reg(context)),
854 MAKELONG(DX_reg(context),CX_reg(context)), 0,
855 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
856 AX_reg(context) = DOS_ExtendedError;
857 SET_CFLAG(context);
859 return;
860 default:
861 AX_reg(context) = 0x0001;
862 SET_CFLAG(context);
863 return;
867 static BOOL32
868 INT21_networkfunc (CONTEXT *context)
870 switch (AL_reg(context)) {
871 case 0x00: /* Get machine name. */
873 char *dst = CTX_SEG_OFF_TO_LIN (context,DS_reg(context),DX_reg(context));
874 TRACE(int21, "getting machine name to %p\n", dst);
875 if (gethostname (dst, 15))
877 WARN(int21,"failed!\n");
878 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
879 return TRUE;
880 } else {
881 int len = strlen (dst);
882 while (len < 15)
883 dst[len++] = ' ';
884 dst[15] = 0;
885 CH_reg(context) = 1; /* Valid */
886 CL_reg(context) = 1; /* NETbios number??? */
887 TRACE(int21, "returning %s\n", debugstr_an (dst, 16));
888 return FALSE;
892 default:
893 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
894 return TRUE;
898 static void INT21_SetCurrentPSP(CONTEXT *context)
900 /* FIXME - What is this MZ stuff and what if it isn't supported?? */
901 #ifdef MZ_SUPPORTED
902 TDB *pTask = hModule ? NULL : (TDB *)GlobalLock16( GetCurrentTask() );
903 NE_MODULE *pModule = (hModule || pTask) ? NE_GetPtr( hModule ? hModule : pTask->hModule ) : NULL;
905 GlobalUnlock16( GetCurrentTask() );
906 if (pModule->lpDosTask)
907 pModule->lpDosTask->psp_seg = BX_reg(context);
908 #else
909 FIXME(int21, "MZ Not Supported.\n");
910 #endif
913 static WORD INT21_GetCurrentPSP()
915 #ifdef MZ_SUPPORTED
916 TDB *pTask = hModule ? NULL : (TDB *)GlobalLock16( GetCurrentTask() );
917 NE_MODULE *pModule = (hModule || pTask) ? NE_GetPtr( hModule ? hModule : pTask->hModule ) : NULL;
919 GlobalUnlock16( GetCurrentTask() );
920 if (pModule->lpDosTask)
921 return pModule->lpDosTask->psp_seg;
922 else
923 #endif
924 return GetCurrentPDB();
928 SEGPTR INT21_GetListOfLists()
930 static DOS_LISTOFLISTS *LOL;
931 static SEGPTR seg_LOL;
934 Output of DOS 6.22:
936 0133:0020 6A 13-33 01 CC 00 33 01 59 00 j.3...3.Y.
937 0133:0030 70 00 00 00 72 02 00 02-6D 00 33 01 00 00 2E 05 p...r...m.3.....
938 0133:0040 00 00 FC 04 00 00 03 08-92 21 11 E0 04 80 C6 0D .........!......
939 0133:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..NUL ......
940 0133:0060 00 4B BA C1 06 14 00 00-00 03 01 00 04 70 CE FF .K...........p..
941 0133:0070 FF 00 00 00 00 00 00 00-00 01 00 00 0D 05 00 00 ................
942 0133:0080 00 FF FF 00 00 00 00 FE-00 00 F8 03 FF 9F 70 02 ..............p.
943 0133:0090 D0 44 C8 FD D4 44 C8 FD-D4 44 C8 FD D0 44 C8 FD .D...D...D...D..
944 0133:00A0 D0 44 C8 FD D0 44 .D...D
946 if (!LOL) {
947 LOL = SEGPTR_ALLOC(sizeof(DOS_LISTOFLISTS));
949 LOL->CX_Int21_5e01 = 0x0;
950 LOL->LRU_count_FCB_cache = 0x0;
951 LOL->LRU_count_FCB_open = 0x0;
952 LOL->OEM_func_handler = -1; /* not available */
953 LOL->INT21_offset = 0x0;
954 LOL->sharing_retry_count = sharing_retries; /* default value: 3 */
955 LOL->sharing_retry_delay = sharing_pause; /* default value: 1 */
956 LOL->ptr_disk_buf = 0x0;
957 LOL->offs_unread_CON = 0x0;
958 LOL->seg_first_MCB = 0x0;
959 LOL->ptr_first_DPB = 0x0;
960 LOL->ptr_first_SysFileTable = 0x0;
961 LOL->ptr_clock_dev_hdr = 0x0;
962 LOL->ptr_CON_dev_hdr = 0x0;
963 LOL->max_byte_per_sec = 512;
964 LOL->ptr_disk_buf_info = 0x0;
965 LOL->ptr_array_CDS = 0x0;
966 LOL->ptr_sys_FCB = 0x0;
967 LOL->nr_protect_FCB = 0x0;
968 LOL->nr_block_dev = 0x0;
969 LOL->nr_avail_drive_letters = 26; /* A - Z */
970 LOL->nr_drives_JOINed = 0x0;
971 LOL->ptr_spec_prg_names = 0x0;
972 LOL->ptr_SETVER_prg_list = 0x0; /* no SETVER list */
973 LOL->DOS_HIGH_A20_func_offs = 0x0;
974 LOL->PSP_last_exec = 0x0;
975 LOL->BUFFERS_val = 99; /* maximum: 99 */
976 LOL->BUFFERS_nr_lookahead = 8; /* maximum: 8 */
977 LOL->boot_drive = 3; /* C: */
978 LOL->flag_DWORD_moves = 0x01; /* i386+ */
979 LOL->size_extended_mem = 0xf000; /* very high value */
981 if (!seg_LOL) seg_LOL = SEGPTR_GET(LOL);
982 return seg_LOL+(WORD)&((DOS_LISTOFLISTS*)0)->ptr_first_DPB;
985 /***********************************************************************
986 * DOS3Call (KERNEL.102)
988 void WINAPI DOS3Call( CONTEXT *context )
990 BOOL32 bSetDOSExtendedError = FALSE;
992 #if 0
993 TRACE(int21, "AX=%04x BX=%04x CX=%04x DX=%04x "
994 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
995 AX_reg(context), BX_reg(context), CX_reg(context), DX_reg(context),
996 SI_reg(context), DI_reg(context),
997 (WORD)DS_reg(context), (WORD)ES_reg(context),
998 EFL_reg(context) );
999 #endif
1001 if (AH_reg(context) == 0x59) /* Get extended error info */
1003 TRACE(int21, "GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1004 DOS_ExtendedError, DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus);
1005 AX_reg(context) = DOS_ExtendedError;
1006 BH_reg(context) = DOS_ErrorClass;
1007 BL_reg(context) = DOS_ErrorAction;
1008 CH_reg(context) = DOS_ErrorLocus;
1009 return;
1012 if (AH_reg(context) == 0x0C) /* Flush buffer and read standard input */
1014 TRACE(int21, "FLUSH BUFFER AND READ STANDARD INPUT\n");
1015 /* no flush here yet */
1016 AH_reg(context) = AL_reg(context);
1019 DOS_ERROR( 0, 0, 0, 0 );
1020 RESET_CFLAG(context); /* Not sure if this is a good idea */
1022 switch(AH_reg(context))
1024 case 0x00: /* TERMINATE PROGRAM */
1025 TRACE(int21,"TERMINATE PROGRAM\n");
1026 ExitProcess( 0 );
1027 break;
1029 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1030 case 0x03: /* READ CHARACTER FROM STDAUX */
1031 case 0x04: /* WRITE CHARACTER TO STDAUX */
1032 case 0x05: /* WRITE CHARACTER TO PRINTER */
1033 case 0x0b: /* GET STDIN STATUS */
1034 case 0x0f: /* OPEN FILE USING FCB */
1035 case 0x10: /* CLOSE FILE USING FCB */
1036 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1037 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1038 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1039 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1040 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1041 case 0x23: /* GET FILE SIZE FOR FCB */
1042 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1043 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1044 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1045 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1046 case 0x29: /* PARSE FILENAME INTO FCB */
1047 case 0x54: /* GET VERIFY FLAG */
1048 INT_BARF( context, 0x21 );
1049 break;
1051 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1052 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1053 _lwrite16( 1, &DL_reg(context), 1);
1054 break;
1056 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1057 TRACE(int21,"DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1058 _lread16( 0, &AL_reg(context), 1);
1059 break;
1061 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1062 TRACE(int21,"CHARACTER INPUT WITHOUT ECHO\n");
1063 _lread16( 0, &AL_reg(context), 1);
1064 break;
1066 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1067 TRACE(int21,"WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1068 DS_reg(context),DX_reg(context) );
1070 LPSTR data = CTX_SEG_OFF_TO_LIN(context,DS_reg(context),DX_reg(context));
1071 LONG length = strchr(data,'$')-data;
1072 _hwrite16( 1, data, length);
1074 break;
1076 case 0x0a: /* BUFFERED INPUT */
1078 char *buffer = ((char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1079 DX_reg(context) ));
1080 int res;
1082 TRACE(int21,"BUFFERED INPUT\n");
1083 if (buffer[1])
1084 TRACE(int21,"Handle old chars in buffer!\n");
1085 res=_lread16( 0, buffer+2,buffer[0]);
1086 buffer[1]=res;
1087 if(buffer[res+1] == '\n')
1088 buffer[res+1] = '\r';
1089 break;
1092 case 0x2e: /* SET VERIFY FLAG */
1093 TRACE(int21,"SET VERIFY FLAG ignored\n");
1094 /* we cannot change the behaviour anyway, so just ignore it */
1095 break;
1097 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1098 case 0x1d:
1099 case 0x1e:
1100 case 0x20:
1101 case 0x6b: /* NULL FUNCTION */
1102 AL_reg(context) = 0;
1103 break;
1105 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1106 fLock(context);
1107 break;
1109 case 0x0d: /* DISK BUFFER FLUSH */
1110 TRACE(int21,"DISK BUFFER FLUSH ignored\n");
1111 RESET_CFLAG(context); /* dos 6+ only */
1112 break;
1114 case 0x0e: /* SELECT DEFAULT DRIVE */
1115 TRACE(int21,"SELECT DEFAULT DRIVE %d\n", DL_reg(context));
1116 DRIVE_SetCurrentDrive( DL_reg(context) );
1117 AL_reg(context) = MAX_DOS_DRIVES;
1118 break;
1120 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1121 TRACE(int21,"FIND FIRST MATCHING FILE USING FCB %p\n",
1122 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1123 if (!INT21_FindFirstFCB(context))
1125 AL_reg(context) = 0xff;
1126 break;
1128 /* else fall through */
1130 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1131 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
1132 break;
1134 case 0x13: /* DELETE FILE USING FCB */
1135 DeleteFileFCB(context);
1136 break;
1138 case 0x17: /* RENAME FILE USING FCB */
1139 RenameFileFCB(context);
1140 break;
1142 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1143 AL_reg(context) = DRIVE_GetCurrentDrive();
1144 break;
1146 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1148 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1149 pTask->dta = PTR_SEG_OFF_TO_SEGPTR(DS_reg(context),DX_reg(context));
1150 TRACE(int21, "Set DTA: %08lx\n", pTask->dta);
1152 break;
1154 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1155 DL_reg(context) = 0;
1156 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1157 break;
1159 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1160 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1161 break;
1163 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1164 GetDrivePB(context, DRIVE_GetCurrentDrive());
1165 break;
1167 case 0x25: /* SET INTERRUPT VECTOR */
1168 INT_SetHandler( AL_reg(context),
1169 (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1170 DX_reg(context)));
1171 break;
1173 case 0x2a: /* GET SYSTEM DATE */
1174 INT21_GetSystemDate(context);
1175 break;
1177 case 0x2b: /* SET SYSTEM DATE */
1178 FIXME(int21, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1179 DL_reg(context), DH_reg(context), CX_reg(context) );
1180 AL_reg(context) = 0; /* Let's pretend we succeeded */
1181 break;
1183 case 0x2c: /* GET SYSTEM TIME */
1184 INT21_GetSystemTime(context);
1185 break;
1187 case 0x2d: /* SET SYSTEM TIME */
1188 FIXME(int21, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1189 CH_reg(context), CL_reg(context),
1190 DH_reg(context), DL_reg(context) );
1191 AL_reg(context) = 0; /* Let's pretend we succeeded */
1192 break;
1194 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1195 TRACE(int21,"GET DISK TRANSFER AREA ADDRESS\n");
1197 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1198 ES_reg(context) = SELECTOROF( pTask->dta );
1199 BX_reg(context) = OFFSETOF( pTask->dta );
1201 break;
1203 case 0x30: /* GET DOS VERSION */
1204 TRACE(int21,"GET DOS VERSION %s requested\n",
1205 (AL_reg(context) == 0x00)?"OEM number":"version flag");
1206 AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
1207 (HIWORD(GetVersion16()) << 8);
1208 #if 0
1209 AH_reg(context) = 0x7;
1210 AL_reg(context) = 0xA;
1211 #endif
1213 BX_reg(context) = 0x00FF; /* 0x123456 is Wine's serial # */
1214 CX_reg(context) = 0x0000;
1215 break;
1217 case 0x31: /* TERMINATE AND STAY RESIDENT */
1218 TRACE(int21,"TERMINATE AND STAY RESIDENT stub\n");
1219 INT_BARF( context, 0x21 );
1220 break;
1222 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1223 TRACE(int21,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1224 INT21_DriveName( DL_reg(context)));
1225 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
1226 break;
1228 case 0x33: /* MULTIPLEXED */
1229 switch (AL_reg(context))
1231 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1232 TRACE(int21,"GET CURRENT EXTENDED BREAK STATE stub\n");
1233 DL_reg(context) = 0;
1234 break;
1236 case 0x01: /* SET EXTENDED BREAK STATE */
1237 TRACE(int21,"SET CURRENT EXTENDED BREAK STATE stub\n");
1238 break;
1240 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1241 TRACE(int21,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE stub\n");
1242 DL_reg(context) = 0;
1243 break;
1245 case 0x05: /* GET BOOT DRIVE */
1246 TRACE(int21,"GET BOOT DRIVE\n");
1247 DL_reg(context) = 3;
1248 /* c: is Wine's bootdrive (a: is 1)*/
1249 break;
1251 case 0x06: /* GET TRUE VERSION NUMBER */
1252 TRACE(int21,"GET TRUE VERSION NUMBER\n");
1253 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1254 (HIWORD(GetVersion16() << 8));
1255 DX_reg(context) = 0x00;
1256 break;
1258 default:
1259 INT_BARF( context, 0x21 );
1260 break;
1262 break;
1264 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1265 TRACE(int21,"GET ADDRESS OF INDOS FLAG\n");
1266 if (!heap) INT21_CreateHeap();
1267 ES_reg(context) = DosHeapHandle;
1268 BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1269 break;
1271 case 0x35: /* GET INTERRUPT VECTOR */
1272 TRACE(int21,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1274 FARPROC16 addr = INT_GetHandler( AL_reg(context) );
1275 ES_reg(context) = SELECTOROF(addr);
1276 BX_reg(context) = OFFSETOF(addr);
1278 break;
1280 case 0x36: /* GET FREE DISK SPACE */
1281 TRACE(int21,"GET FREE DISK SPACE FOR DRIVE %s\n",
1282 INT21_DriveName( DL_reg(context)));
1283 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1284 break;
1286 case 0x37:
1288 unsigned char switchchar='/';
1289 switch (AL_reg(context))
1291 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1292 TRACE(int21,"SWITCHAR - GET SWITCH CHARACTER\n");
1293 AL_reg(context) = 0x00; /* success*/
1294 DL_reg(context) = switchchar;
1295 break;
1296 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1297 TRACE(int21,"SWITCHAR - SET SWITCH CHARACTER\n");
1298 switchchar = DL_reg(context);
1299 AL_reg(context) = 0x00; /* success*/
1300 break;
1301 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1302 INT_BARF( context, 0x21 );
1303 break;
1305 break;
1308 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1309 TRACE(int21,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1310 AL_reg(context));
1311 AX_reg(context) = 0x02; /* no country support available */
1312 SET_CFLAG(context);
1313 break;
1315 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1316 TRACE(int21,"MKDIR %s\n",
1317 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1318 bSetDOSExtendedError = (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1319 DX_reg(context) ), NULL));
1320 break;
1322 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1323 TRACE(int21,"RMDIR %s\n",
1324 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1325 bSetDOSExtendedError = (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1326 DX_reg(context) )));
1327 break;
1329 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1330 TRACE(int21,"CHDIR %s\n",
1331 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1332 bSetDOSExtendedError = !INT21_ChangeDir(context);
1333 break;
1335 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1336 TRACE(int21,"CREAT flag 0x%02x %s\n",CX_reg(context),
1337 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1338 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1339 DX_reg(context) ), CX_reg(context) );
1340 bSetDOSExtendedError = (AX_reg(context) == (WORD)HFILE_ERROR16);
1341 break;
1343 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1344 TRACE(int21,"OPEN mode 0x%02x %s\n",AL_reg(context),
1345 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1346 OpenExistingFile(context);
1347 break;
1349 case 0x3e: /* "CLOSE" - CLOSE FILE */
1350 TRACE(int21,"CLOSE handle %d\n",BX_reg(context));
1351 if (BX_reg(context)<5) {
1352 /* hack to make sure stdio isn't closed */
1353 DOS_ExtendedError = 0x06;
1354 bSetDOSExtendedError = TRUE;
1355 } else
1356 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1357 break;
1359 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1360 TRACE(int21,"READ from %d to %04lX:%04X for %d byte\n",BX_reg(context),
1361 DS_reg(context),DX_reg(context),CX_reg(context) );
1363 LONG result = _hread16( BX_reg(context),
1364 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1365 DX_reg(context) ),
1366 CX_reg(context) );
1367 if (result == -1) bSetDOSExtendedError = TRUE;
1368 else AX_reg(context) = (WORD)result;
1370 break;
1372 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1373 TRACE(int21,"WRITE from %04lX:%04X to handle %d for %d byte\n",
1374 DS_reg(context),DX_reg(context),BX_reg(context),CX_reg(context) );
1376 LONG result = _hwrite16( BX_reg(context),
1377 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1378 DX_reg(context) ),
1379 CX_reg(context) );
1380 if (result == -1) bSetDOSExtendedError = TRUE;
1381 else AX_reg(context) = (WORD)result;
1383 break;
1385 case 0x41: /* "UNLINK" - DELETE FILE */
1386 TRACE(int21,"UNLINK%s\n",
1387 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1388 bSetDOSExtendedError = (!DeleteFile32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1389 DX_reg(context) )));
1390 break;
1392 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1393 TRACE(int21,"LSEEK handle %d offset %ld from %s\n",
1394 BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)),
1395 (AL_reg(context)==0)?"start of file":(AL_reg(context)==1)?
1396 "current file position":"end of file");
1398 LONG status = _llseek16( BX_reg(context),
1399 MAKELONG(DX_reg(context),CX_reg(context)),
1400 AL_reg(context) );
1401 if (status == -1) bSetDOSExtendedError = TRUE;
1402 else
1404 AX_reg(context) = LOWORD(status);
1405 DX_reg(context) = HIWORD(status);
1408 break;
1410 case 0x43: /* FILE ATTRIBUTES */
1411 switch (AL_reg(context))
1413 case 0x00:
1414 TRACE(int21,"GET FILE ATTRIBUTES for %s\n",
1415 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1416 AX_reg(context) = (WORD)GetFileAttributes32A(
1417 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1418 DX_reg(context)));
1419 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1420 else CX_reg(context) = AX_reg(context);
1421 break;
1423 case 0x01:
1424 TRACE(int21,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context),
1425 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1426 bSetDOSExtendedError =
1427 (!SetFileAttributes32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1428 DX_reg(context)),
1429 CX_reg(context) ));
1430 break;
1431 case 0x02:
1432 TRACE(int21,"GET COMPRESSED FILE SIZE for %s stub\n",
1433 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1435 break;
1437 case 0x44: /* IOCTL */
1438 switch (AL_reg(context))
1440 case 0x00:
1441 ioctlGetDeviceInfo(context);
1442 break;
1444 case 0x01:
1445 break;
1446 case 0x02:{
1447 FILE_OBJECT *file;
1448 file = FILE_GetFile(HFILE16_TO_HFILE32(BX_reg(context)));
1449 if (!strcasecmp(file->unix_name, "SCSIMGR$"))
1450 ASPI_DOS_HandleInt(context);
1451 FILE_ReleaseFile( file );
1452 break;
1454 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1455 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context));*/
1456 int drive = DOS_GET_DRIVE(BL_reg(context));
1458 FIXME(int21,"program tried to write to block device control channel of drive %d:\n",drive);
1459 /* for (i=0;i<CX_reg(context);i++)
1460 fprintf(stdnimp,"%02x ",dataptr[i]);
1461 fprintf(stdnimp,"\n");*/
1462 AX_reg(context)=CX_reg(context);
1463 break;
1465 case 0x08: /* Check if drive is removable. */
1466 TRACE(int21,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1467 INT21_DriveName( BL_reg(context)));
1468 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1470 case DRIVE_CANNOTDETERMINE:
1471 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1472 AX_reg(context) = ER_InvalidDrive;
1473 SET_CFLAG(context);
1474 break;
1475 case DRIVE_REMOVABLE:
1476 AX_reg(context) = 0; /* removable */
1477 break;
1478 default:
1479 AX_reg(context) = 1; /* not removable */
1480 break;
1482 break;
1484 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1485 TRACE(int21,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1486 INT21_DriveName( BL_reg(context)));
1487 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1489 case DRIVE_CANNOTDETERMINE:
1490 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1491 AX_reg(context) = ER_InvalidDrive;
1492 SET_CFLAG(context);
1493 break;
1494 case DRIVE_REMOTE:
1495 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1496 break;
1497 default:
1498 DX_reg(context) = 0; /* FIXME: use driver attr here */
1499 break;
1501 break;
1503 case 0x0a: /* check if handle (BX) is remote */
1504 TRACE(int21,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context));
1505 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1506 * not set on close
1508 DX_reg(context) = 0;
1509 break;
1511 case 0x0b: /* SET SHARING RETRY COUNT */
1512 TRACE(int21,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1513 CX_reg(context), DX_reg(context));
1514 if (!CX_reg(context))
1516 AX_reg(context) = 1;
1517 SET_CFLAG(context);
1518 break;
1520 sharing_pause = CX_reg(context);
1521 if (!DX_reg(context))
1522 sharing_retries = DX_reg(context);
1523 RESET_CFLAG(context);
1524 break;
1526 case 0x0d:
1527 TRACE(int21,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1528 INT21_DriveName( BL_reg(context)));
1529 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1530 break;
1532 case 0x0e: /* get logical drive mapping */
1533 TRACE(int21,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1534 INT21_DriveName( BL_reg(context)));
1535 AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1536 break;
1538 case 0x0F: /* Set logical drive mapping */
1540 int drive;
1541 TRACE(int21,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1542 INT21_DriveName( BL_reg(context)));
1543 drive = DOS_GET_DRIVE ( BL_reg(context) );
1544 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1546 SET_CFLAG(context);
1547 AX_reg(context) = 0x000F; /* invalid drive */
1549 break;
1552 default:
1553 INT_BARF( context, 0x21 );
1554 break;
1556 break;
1558 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1559 TRACE(int21,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context));
1560 bSetDOSExtendedError = ((AX_reg(context) = HFILE32_TO_HFILE16(FILE_Dup(HFILE16_TO_HFILE32(BX_reg(context))))) == (WORD)HFILE_ERROR16);
1561 break;
1563 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1564 TRACE(int21,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1565 BX_reg(context),CX_reg(context));
1566 bSetDOSExtendedError = (FILE_Dup2( HFILE16_TO_HFILE32(BX_reg(context)), HFILE16_TO_HFILE32(CX_reg(context)) ) == HFILE_ERROR32);
1567 break;
1569 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1570 TRACE(int21,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1571 INT21_DriveName( DL_reg(context)));
1572 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1573 break;
1575 case 0x48: /* ALLOCATE MEMORY */
1576 TRACE(int21,"ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context));
1578 LPVOID *mem;
1579 if (ISV86(context))
1581 mem= DOSMEM_GetBlock(0,(DWORD)BX_reg(context)<<4,NULL);
1582 if (mem)
1583 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1585 else
1587 mem = (LPVOID)GlobalDOSAlloc(BX_reg(context)<<4);
1588 if (mem)
1589 AX_reg(context) = (DWORD)mem&0xffff;
1591 if (!mem)
1593 SET_CFLAG(context);
1594 AX_reg(context) = 0x0008; /* insufficient memory */
1595 BX_reg(context) = DOSMEM_Available(0)>>4;
1598 break;
1600 case 0x49: /* FREE MEMORY */
1601 TRACE(int21,"FREE MEMORY segment %04lX\n", ES_reg(context));
1603 BOOL32 ret;
1604 if (ISV86(context))
1605 ret= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4));
1606 else
1608 ret = !GlobalDOSFree(ES_reg(context));
1609 /* If we don't reset ES_reg, we will fail in the relay code */
1610 ES_reg(context)=ret;
1612 if (!ret)
1614 TRACE(int21,"FREE MEMORY failed\n");
1615 SET_CFLAG(context);
1616 AX_reg(context) = 0x0009; /* memory block address invalid */
1619 break;
1621 case 0x4a: /* RESIZE MEMORY BLOCK */
1622 TRACE(int21,"RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context), BX_reg(context));
1623 if (!ISV86(context))
1624 FIXME(int21,"RESIZE MEMORY probably insufficent implementation. Expect crash soon\n");
1626 LPVOID *mem = DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4),
1627 BX_reg(context)<<4,NULL);
1628 if (mem)
1629 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1630 else {
1631 SET_CFLAG(context);
1632 AX_reg(context) = 0x0008; /* insufficient memory */
1633 BX_reg(context) = DOSMEM_Available(0)>>4; /* not quite right */
1636 break;
1638 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1639 TRACE(int21,"EXEC %s\n",
1640 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context) ));
1641 AX_reg(context) = WinExec16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1642 DX_reg(context) ),
1643 SW_NORMAL );
1644 if (AX_reg(context) < 32) SET_CFLAG(context);
1645 break;
1647 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1648 TRACE(int21,"EXIT with return code %d\n",AL_reg(context));
1649 ExitProcess( AL_reg(context) );
1650 break;
1652 case 0x4d: /* GET RETURN CODE */
1653 TRACE(int21,"GET RETURN CODE (ERRORLEVEL)\n");
1654 AX_reg(context) = 0; /* normal exit */
1655 break;
1657 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1658 TRACE(int21,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
1659 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1660 if (!INT21_FindFirst(context)) break;
1661 /* fall through */
1663 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1664 TRACE(int21,"FINDNEXT\n");
1665 if (!INT21_FindNext(context))
1667 DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk );
1668 AX_reg(context) = ER_NoMoreFiles;
1669 SET_CFLAG(context);
1671 else AX_reg(context) = 0; /* OK */
1672 break;
1673 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1674 TRACE(int21, "SET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1675 /* FIXME: Is this right? */
1676 INT21_SetCurrentPSP(context);
1677 break;
1678 case 0x51: /* GET PSP ADDRESS */
1679 TRACE(int21,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1680 /* FIXME: should we return the original DOS PSP upon */
1681 /* Windows startup ? */
1682 BX_reg(context) = INT21_GetCurrentPSP();
1683 break;
1684 case 0x62: /* GET PSP ADDRESS */
1685 TRACE(int21,"GET CURRENT PSP ADDRESS\n");
1686 /* FIXME: should we return the original DOS PSP upon */
1687 /* Windows startup ? */
1688 BX_reg(context) = INT21_GetCurrentPSP();
1689 break;
1691 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1692 TRACE(int21,"SYSVARS - GET LIST OF LISTS\n");
1694 SEGPTR lol;
1695 lol = INT21_GetListOfLists();
1696 ES_reg(context) = HIWORD(lol);
1697 BX_reg(context) = LOWORD(lol);
1699 break;
1701 case 0x56: /* "RENAME" - RENAME FILE */
1702 TRACE(int21,"RENAME %s to %s\n",
1703 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)),
1704 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),DI_reg(context)));
1705 bSetDOSExtendedError =
1706 (!MoveFile32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)),
1707 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),DI_reg(context))));
1708 break;
1710 case 0x57: /* FILE DATE AND TIME */
1711 switch (AL_reg(context))
1713 case 0x00: /* Get */
1715 FILETIME filetime;
1716 TRACE(int21,"GET FILE DATE AND TIME for handle %d\n",
1717 BX_reg(context));
1718 if (!GetFileTime( BX_reg(context), NULL, NULL, &filetime ))
1719 bSetDOSExtendedError = TRUE;
1720 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1721 &CX_reg(context) );
1723 break;
1725 case 0x01: /* Set */
1727 FILETIME filetime;
1728 TRACE(int21,"SET FILE DATE AND TIME for handle %d\n",
1729 BX_reg(context));
1730 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1731 &filetime );
1732 bSetDOSExtendedError =
1733 (!SetFileTime( BX_reg(context), NULL, NULL, &filetime ));
1735 break;
1737 break;
1739 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1740 TRACE(int21,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1741 AL_reg(context));
1742 switch (AL_reg(context))
1744 case 0x00:
1745 AX_reg(context) = 1;
1746 break;
1747 case 0x02:
1748 AX_reg(context) = 0;
1749 break;
1750 case 0x01:
1751 case 0x03:
1752 break;
1754 RESET_CFLAG(context);
1755 break;
1757 case 0x5a: /* CREATE TEMPORARY FILE */
1758 TRACE(int21,"CREATE TEMPORARY FILE\n");
1759 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1760 break;
1762 case 0x5b: /* CREATE NEW FILE */
1763 TRACE(int21,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
1764 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1765 bSetDOSExtendedError = ((AX_reg(context) =
1766 HFILE32_TO_HFILE16(_lcreat_uniq( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)), 0 )))
1767 == (WORD)HFILE_ERROR16);
1768 break;
1770 case 0x5d: /* NETWORK */
1771 FIXME(int21,"Function 0x%04x not implemented.\n", AX_reg (context));
1772 /* Fix the following while you're at it. */
1773 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1774 bSetDOSExtendedError = TRUE;
1775 break;
1777 case 0x5e:
1778 bSetDOSExtendedError = INT21_networkfunc (context);
1779 break;
1781 case 0x5f: /* NETWORK */
1782 switch (AL_reg(context))
1784 case 0x07: /* ENABLE DRIVE */
1785 TRACE(int21,"ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1786 if (!DRIVE_Enable( DL_reg(context) ))
1788 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1789 bSetDOSExtendedError = TRUE;
1791 break;
1793 case 0x08: /* DISABLE DRIVE */
1794 TRACE(int21,"DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1795 if (!DRIVE_Disable( DL_reg(context) ))
1797 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1798 bSetDOSExtendedError = TRUE;
1800 break;
1802 default:
1803 /* network software not installed */
1804 TRACE(int21,"NETWORK function AX=%04x not implemented\n",AX_reg(context));
1805 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1806 bSetDOSExtendedError = TRUE;
1807 break;
1809 break;
1811 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1812 TRACE(int21,"TRUENAME %s\n",
1813 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),SI_reg(context)));
1815 if (!GetFullPathName32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1816 SI_reg(context)), 128,
1817 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
1818 DI_reg(context)),NULL))
1819 bSetDOSExtendedError = TRUE;
1820 else AX_reg(context) = 0;
1822 break;
1824 case 0x61: /* UNUSED */
1825 case 0x63: /* UNUSED */
1826 case 0x64: /* OS/2 DOS BOX */
1827 INT_BARF( context, 0x21 );
1828 SET_CFLAG(context);
1829 break;
1831 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1832 extern WORD WINE_LanguageId;
1833 BYTE *dataptr=CTX_SEG_OFF_TO_LIN(context, ES_reg(context),DI_reg(context));
1834 TRACE(int21,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1835 BX_reg(context), DX_reg(context));
1836 switch (AL_reg(context)) {
1837 case 0x01:
1838 TRACE(int21,"\tget general internationalization info\n");
1839 dataptr[0] = 0x1;
1840 *(WORD*)(dataptr+1) = 41;
1841 *(WORD*)(dataptr+3) = WINE_LanguageId;
1842 *(WORD*)(dataptr+5) = CodePage;
1843 *(DWORD*)(dataptr+0x19) = 0; /* FIXME: ptr to case map routine */
1844 break;
1845 case 0x06:
1846 TRACE(int21,"\tget pointer to collating sequence table\n");
1847 dataptr[0] = 0x06;
1848 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
1849 CX_reg(context) = 258;/*FIXME: size of table?*/
1850 break;
1851 default:
1852 TRACE(int21,"\tunimplemented function %d\n",AL_reg(context));
1853 INT_BARF( context, 0x21 );
1854 SET_CFLAG(context);
1855 break;
1857 break;
1859 case 0x66: /* GLOBAL CODE PAGE TABLE */
1860 switch (AL_reg(context))
1862 case 0x01:
1863 TRACE(int21,"GET GLOBAL CODE PAGE TABLE\n");
1864 DX_reg(context) = BX_reg(context) = CodePage;
1865 RESET_CFLAG(context);
1866 break;
1867 case 0x02:
1868 TRACE(int21,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
1869 BX_reg(context),DX_reg(context));
1870 CodePage = BX_reg(context);
1871 RESET_CFLAG(context);
1872 break;
1874 break;
1876 case 0x67: /* SET HANDLE COUNT */
1877 TRACE(int21,"SET HANDLE COUNT to %d\n",BX_reg(context) );
1878 SetHandleCount16( BX_reg(context) );
1879 if (DOS_ExtendedError) bSetDOSExtendedError = TRUE;
1880 break;
1882 case 0x68: /* "FFLUSH" - COMMIT FILE */
1883 case 0x6a: /* COMMIT FILE */
1884 TRACE(int21,"FFLUSH/COMMIT handle %d\n",BX_reg(context));
1885 bSetDOSExtendedError = (!FlushFileBuffers( HFILE16_TO_HFILE32(BX_reg(context)) ));
1886 break;
1888 case 0x69: /* DISK SERIAL NUMBER */
1889 switch (AL_reg(context))
1891 case 0x00:
1892 TRACE(int21,"GET DISK SERIAL NUMBER for drive %s\n",
1893 INT21_DriveName(BL_reg(context)));
1894 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1895 else AX_reg(context) = 0;
1896 break;
1898 case 0x01:
1899 TRACE(int21,"SET DISK SERIAL NUMBER for drive %s\n",
1900 INT21_DriveName(BL_reg(context)));
1901 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1902 else AX_reg(context) = 1;
1903 break;
1905 break;
1907 case 0x6C: /* Extended Open/Create*/
1908 TRACE(int21,"EXTENDED OPEN/CREATE %s\n",
1909 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DI_reg(context)));
1910 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
1911 break;
1913 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1914 if ((GetVersion32()&0xC0000004)!=0xC0000004) {
1915 /* not supported on anything but Win95 */
1916 TRACE(int21,"LONG FILENAME functions supported only by win95\n");
1917 SET_CFLAG(context);
1918 AL_reg(context) = 0;
1919 } else
1920 switch(AL_reg(context))
1922 case 0x39: /* Create directory */
1923 TRACE(int21,"LONG FILENAME - MAKE DIRECTORY %s\n",
1924 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
1925 bSetDOSExtendedError = (!CreateDirectory32A(
1926 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1927 DX_reg(context) ), NULL));
1928 break;
1929 case 0x3a: /* Remove directory */
1930 TRACE(int21,"LONG FILENAME - REMOVE DIRECTORY %s\n",
1931 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
1932 bSetDOSExtendedError = (!RemoveDirectory32A(
1933 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1934 DX_reg(context) )));
1935 break;
1936 case 0x43: /* Get/Set file attributes */
1937 TRACE(int21,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
1938 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
1939 switch (BL_reg(context))
1941 case 0x00: /* Get file attributes */
1942 TRACE(int21,"\tretrieve attributes\n");
1943 CX_reg(context) = (WORD)GetFileAttributes32A(
1944 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1945 DX_reg(context)));
1946 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1947 break;
1948 case 0x01:
1949 TRACE(int21,"\tset attributes 0x%04x\n",CX_reg(context));
1950 bSetDOSExtendedError = (!SetFileAttributes32A(
1951 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1952 DX_reg(context)),
1953 CX_reg(context) ) );
1954 break;
1955 default:
1956 FIXME(int21, "Unimplemented long file name function:\n");
1957 INT_BARF( context, 0x21 );
1958 SET_CFLAG(context);
1959 AL_reg(context) = 0;
1960 break;
1962 break;
1963 case 0x47: /* Get current directory */
1964 TRACE(int21," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
1965 INT21_DriveName(DL_reg(context)));
1966 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1967 break;
1969 case 0x4e: /* Find first file */
1970 TRACE(int21," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
1971 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
1972 /* FIXME: use attributes in CX */
1973 if ((AX_reg(context) = FindFirstFile16(
1974 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)),
1975 (WIN32_FIND_DATA32A *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
1976 DI_reg(context))))
1977 == INVALID_HANDLE_VALUE16)
1978 bSetDOSExtendedError = TRUE;
1979 break;
1980 case 0x4f: /* Find next file */
1981 TRACE(int21,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
1982 BX_reg(context));
1983 if (!FindNextFile16( BX_reg(context),
1984 (WIN32_FIND_DATA32A *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
1985 DI_reg(context))))
1986 bSetDOSExtendedError = TRUE;
1987 break;
1988 case 0xa1: /* Find close */
1989 TRACE(int21,"LONG FILENAME - FINDCLOSE for handle %d\n",
1990 BX_reg(context));
1991 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
1992 break;
1993 case 0xa0:
1994 TRACE(int21,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
1995 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
1996 break;
1997 case 0x60:
1998 switch(CL_reg(context))
2000 case 0x01: /*Get short filename or path */
2001 if (!GetShortPathName32A
2002 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2003 SI_reg(context)),
2004 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2005 DI_reg(context)), 67))
2006 bSetDOSExtendedError = TRUE;
2007 else AX_reg(context) = 0;
2008 break;
2009 case 0x02: /*Get canonical long filename or path */
2010 if (!GetFullPathName32A
2011 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2012 SI_reg(context)), 128,
2013 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2014 DI_reg(context)),NULL))
2015 bSetDOSExtendedError = TRUE;
2016 else AX_reg(context) = 0;
2017 break;
2018 default:
2019 FIXME(int21, "Unimplemented long file name function:\n");
2020 INT_BARF( context, 0x21 );
2021 SET_CFLAG(context);
2022 AL_reg(context) = 0;
2023 break;
2025 break;
2026 case 0x6c: /* Create or open file */
2027 TRACE(int21,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
2028 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), SI_reg(context)));
2029 /* translate Dos 7 action to Dos 6 action */
2030 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2031 break;
2033 case 0x3b: /* Change directory */
2034 TRACE(int21,"LONG FILENAME - CHANGE DIRECTORY %s\n",
2035 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
2036 if (!SetCurrentDirectory32A(CTX_SEG_OFF_TO_LIN(context,
2037 DS_reg(context),
2038 DX_reg(context)
2041 SET_CFLAG(context);
2042 AL_reg(context) = DOS_ExtendedError;
2044 break;
2045 case 0x41: /* Delete file */
2046 TRACE(int21,"LONG FILENAME - DELETE FILE %s\n",
2047 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
2048 if (!DeleteFile32A(CTX_SEG_OFF_TO_LIN(context,
2049 DS_reg(context),
2050 DX_reg(context))
2051 )) {
2052 SET_CFLAG(context);
2053 AL_reg(context) = DOS_ExtendedError;
2055 break;
2056 case 0x56: /* Move (rename) file */
2057 TRACE(int21,"LONG FILENAME - RENAME FILE %s to %s stub\n",
2058 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)),
2059 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context), DI_reg(context)));
2060 default:
2061 FIXME(int21, "Unimplemented long file name function:\n");
2062 INT_BARF( context, 0x21 );
2063 SET_CFLAG(context);
2064 AL_reg(context) = 0;
2065 break;
2067 break;
2069 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2070 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2071 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2072 TRACE(int21,"windows95 function AX %04x\n",
2073 AX_reg(context));
2074 WARN(int21, " returning unimplemented\n");
2075 SET_CFLAG(context);
2076 AL_reg(context) = 0;
2077 break;
2079 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2080 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2081 break;
2083 default:
2084 INT_BARF( context, 0x21 );
2085 break;
2087 } /* END OF SWITCH */
2089 if( bSetDOSExtendedError ) /* set general error condition */
2091 AX_reg(context) = DOS_ExtendedError;
2092 SET_CFLAG(context);
2095 if ((EFL_reg(context) & 0x0001))
2096 TRACE(int21, "failed, errorcode 0x%02x class 0x%02x action 0x%02x locus %02x\n",
2097 DOS_ExtendedError, DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus);
2099 TRACE(int21, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2100 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2101 AX_reg(context), BX_reg(context), CX_reg(context),
2102 DX_reg(context), SI_reg(context), DI_reg(context),
2103 (WORD)DS_reg(context), (WORD)ES_reg(context),
2104 EFL_reg(context));
2107 FARPROC16 WINAPI GetSetKernelDOSProc(FARPROC16 DosProc)
2109 FIXME(int21, "(DosProc=%08x);\n", (UINT32)DosProc);
2110 return NULL;