Small fixes to get the default language to a sensible value.
[wine/multimedia.git] / msdos / int21.c
blob24b26ac1b6e97bd55261c5117b1495f79895d614
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;
72 BYTE DummyDBCSLeadTable[6];
74 static struct DosHeap *heap;
75 static WORD DosHeapHandle;
77 WORD sharing_retries = 3; /* number of retries at sharing violation */
78 WORD sharing_pause = 1; /* pause between retries */
80 extern char TempDirectory[];
82 static BOOL32 INT21_CreateHeap(void)
84 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
86 WARN(int21, "Out of memory\n");
87 return FALSE;
89 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
90 dpbsegptr = PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
91 heap->InDosFlag = 0;
92 strcpy(heap->biosdate, "01/01/80");
93 memset(heap->DummyDBCSLeadTable, 0, 6);
94 return TRUE;
97 static BYTE *GetCurrentDTA( CONTEXT *context )
99 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
101 /* FIXME: This assumes DTA was set correctly! */
102 return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
103 OFFSETOF(pTask->dta) );
107 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
108 /* limited == TRUE is used with INT 0x21/0x440d */
110 if (drive > 1) {
111 setword(data, 512);
112 data[2] = 2;
113 setword(&data[3], 0);
114 data[5] = 2;
115 setword(&data[6], 240);
116 setword(&data[8], 64000);
117 data[0x0a] = 0xf8;
118 setword(&data[0x0b], 40);
119 setword(&data[0x0d], 56);
120 setword(&data[0x0f], 2);
121 setword(&data[0x11], 0);
122 if (!limited) {
123 setword(&data[0x1f], 800);
124 data[0x21] = 5;
125 setword(&data[0x22], 1);
127 } else { /* 1.44mb */
128 setword(data, 512);
129 data[2] = 2;
130 setword(&data[3], 0);
131 data[5] = 2;
132 setword(&data[6], 240);
133 setword(&data[8], 2880);
134 data[0x0a] = 0xf8;
135 setword(&data[0x0b], 6);
136 setword(&data[0x0d], 18);
137 setword(&data[0x0f], 2);
138 setword(&data[0x11], 0);
139 if (!limited) {
140 setword(&data[0x1f], 80);
141 data[0x21] = 7;
142 setword(&data[0x22], 2);
147 static int INT21_GetFreeDiskSpace( CONTEXT *context )
149 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
150 char root[] = "A:\\";
152 *root += DOS_GET_DRIVE( DL_reg(context) );
153 if (!GetDiskFreeSpace32A( root, &cluster_sectors, &sector_bytes,
154 &free_clusters, &total_clusters )) return 0;
155 AX_reg(context) = cluster_sectors;
156 BX_reg(context) = free_clusters;
157 CX_reg(context) = sector_bytes;
158 DX_reg(context) = total_clusters;
159 return 1;
162 static int INT21_GetDriveAllocInfo( CONTEXT *context )
164 if (!INT21_GetFreeDiskSpace( context )) return 0;
165 if (!heap && !INT21_CreateHeap()) return 0;
166 heap->mediaID = 0xf0;
167 DS_reg(context) = DosHeapHandle;
168 BX_reg(context) = (int)&heap->mediaID - (int)heap;
169 return 1;
172 static void GetDrivePB( CONTEXT *context, int drive )
174 if(!DRIVE_IsValid(drive))
176 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
177 AX_reg(context) = 0x00ff;
179 else if (heap || INT21_CreateHeap())
181 FIXME(int21, "GetDrivePB not fully implemented.\n");
183 /* FIXME: I have no idea what a lot of this information should
184 * say or whether it even really matters since we're not allowing
185 * direct block access. However, some programs seem to depend on
186 * getting at least _something_ back from here. The 'next' pointer
187 * does worry me, though. Should we have a complete table of
188 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
190 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
191 heap->dpb.sector_size = 512;
192 heap->dpb.high_sector = 1;
193 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
194 heap->dpb.reserved = 0;
195 heap->dpb.num_FAT = 1;
196 heap->dpb.dir_entries = 2;
197 heap->dpb.first_data = 2;
198 heap->dpb.high_cluster = 64000;
199 heap->dpb.sectors_in_FAT = 1;
200 heap->dpb.start_dir = 1;
201 heap->dpb.driver_head = 0;
202 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
203 heap->dpb.access_flag = 0;
204 heap->dpb.next = 0;
205 heap->dpb.free_search = 0;
206 heap->dpb.free_clusters = 0xFFFF; /* unknown */
208 AL_reg(context) = 0x00;
209 DS_reg(context) = SELECTOROF(dpbsegptr);
210 BX_reg(context) = OFFSETOF(dpbsegptr);
215 static void ioctlGetDeviceInfo( CONTEXT *context )
217 int curr_drive;
218 FILE_OBJECT *file;
220 TRACE(int21, "(%d)\n", BX_reg(context));
222 RESET_CFLAG(context);
224 /* DOS device ? */
225 if ((file = FILE_GetFile( HFILE16_TO_HFILE32(BX_reg(context)) )))
227 const DOS_DEVICE *dev = DOSFS_GetDevice( file->unix_name );
228 FILE_ReleaseFile( file );
229 if (dev)
231 DX_reg(context) = dev->flags;
232 return;
236 /* it seems to be a file */
237 curr_drive = DRIVE_GetCurrentDrive();
238 DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0);
239 /* no floppy */
240 /* bits 0-5 are current drive
241 * bit 6 - file has NOT been written..FIXME: correct?
242 * bit 8 - generate int24 if no diskspace on write/ read past end of file
243 * bit 11 - media not removable
244 * bit 14 - don't set file date/time on closing
245 * bit 15 - file is remote
249 static BOOL32 ioctlGenericBlkDevReq( CONTEXT *context )
251 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
252 int drive = DOS_GET_DRIVE( BL_reg(context) );
254 if (!DRIVE_IsValid(drive))
256 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
257 return TRUE;
260 if (CH_reg(context) != 0x08)
262 INT_BARF( context, 0x21 );
263 return FALSE;
266 switch (CL_reg(context))
268 case 0x4a: /* lock logical volume */
269 TRACE(int21,"lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
270 break;
272 case 0x60: /* get device parameters */
273 /* used by w4wgrp's winfile */
274 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
275 dataptr[0] = 0x04;
276 dataptr[6] = 0; /* media type */
277 if (drive > 1)
279 dataptr[1] = 0x05; /* fixed disk */
280 setword(&dataptr[2], 0x01); /* non removable */
281 setword(&dataptr[4], 0x300); /* # of cylinders */
283 else
285 dataptr[1] = 0x07; /* block dev, floppy */
286 setword(&dataptr[2], 0x02); /* removable */
287 setword(&dataptr[4], 80); /* # of cylinders */
289 CreateBPB(drive, &dataptr[7], TRUE);
290 RESET_CFLAG(context);
291 break;
293 case 0x66:/* get disk serial number */
295 char label[12],fsname[9],path[4];
296 DWORD serial;
298 strcpy(path,"x:\\");path[0]=drive+'A';
299 GetVolumeInformation32A(
300 path,label,12,&serial,NULL,NULL,fsname,9
302 *(WORD*)dataptr = 0;
303 memcpy(dataptr+2,&serial,4);
304 memcpy(dataptr+6,label ,11);
305 memcpy(dataptr+17,fsname,8);
307 break;
309 case 0x6a:
310 TRACE(int21,"logical volume %d unlocked.\n",drive);
311 break;
313 case 0x6f:
314 memset(dataptr+1, '\0', dataptr[0]-1);
315 dataptr[1] = dataptr[0];
316 dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
317 dataptr[3] = 0xFF; /* no physical drive */
318 break;
320 default:
321 INT_BARF( context, 0x21 );
323 return FALSE;
326 static void INT21_ParseFileNameIntoFCB( CONTEXT *context )
328 char *filename =
329 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), SI_reg(context) );
330 char *fcb =
331 CTX_SEG_OFF_TO_LIN(context, ES_reg(context), DI_reg(context) );
332 char *buffer, *s, *d;
334 AL_reg(context) = 0xff; /* failed */
336 TRACE(int21, "filename: '%s'\n", filename);
338 buffer = HeapAlloc( GetProcessHeap(), 0, strlen(filename) );
340 s = filename;
341 d = buffer;
342 while (*s)
344 if ((*s != ' ') && (*s != '\r') && (*s != '\n'))
345 *d++ = *s++;
346 else
347 break;
350 *d = '\0';
351 DOSFS_ToDosFCBFormat(buffer, fcb + 1);
352 *fcb = 0;
353 TRACE(int21, "FCB: '%s'\n", ((CHAR *)fcb + 1));
355 HeapFree( GetProcessHeap(), 0, buffer);
357 AL_reg(context) =
358 ((strchr(filename, '*')) || (strchr(filename, '$'))) != 0;
360 /* point DS:SI to first unparsed character */
361 SI_reg(context) += (int)s - (int)filename;
364 static void INT21_GetSystemDate( CONTEXT *context )
366 SYSTEMTIME systime;
367 GetLocalTime( &systime );
368 CX_reg(context) = systime.wYear;
369 DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
370 AX_reg(context) = systime.wDayOfWeek;
373 static void INT21_GetSystemTime( CONTEXT *context )
375 SYSTEMTIME systime;
376 GetLocalTime( &systime );
377 CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
378 DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
381 /* Many calls translate a drive argument like this:
382 drive number (00h = default, 01h = A:, etc)
384 static char drivestring[]="default";
386 char *INT21_DriveName(int drive)
389 if(drive >0)
391 drivestring[0]= (unsigned char)drive + '@';
392 drivestring[1]=':';
393 drivestring[2]=0;
395 return drivestring;
397 static BOOL32 INT21_CreateFile( CONTEXT *context )
399 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
400 DX_reg(context) ), CX_reg(context) );
401 return (AX_reg(context) == (WORD)HFILE_ERROR16);
405 static void OpenExistingFile( CONTEXT *context )
407 AX_reg(context) = _lopen16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)),
408 AL_reg(context) );
409 if (AX_reg(context) == (WORD)HFILE_ERROR16)
411 AX_reg(context) = DOS_ExtendedError;
412 SET_CFLAG(context);
414 #if 0
416 int handle;
417 int mode;
418 int lock;
420 switch (AX_reg(context) & 0x0070)
422 case 0x00: /* compatability mode */
423 case 0x40: /* DENYNONE */
424 lock = -1;
425 break;
427 case 0x30: /* DENYREAD */
428 TRACE(int21, "(%s): DENYREAD changed to DENYALL\n",
429 (char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
430 case 0x10: /* DENYALL */
431 lock = LOCK_EX;
432 break;
434 case 0x20: /* DENYWRITE */
435 lock = LOCK_SH;
436 break;
438 default:
439 lock = -1;
442 if (lock != -1)
445 int result,retries=sharing_retries;
447 #if defined(__svr4__) || defined(_SCO_DS)
448 ERR(int21, "Should call flock and needs porting to lockf\n");
449 result = 0;
450 retries = 0;
451 #else
452 result = flock(handle, lock | LOCK_NB);
453 #endif
454 if ( retries && (!result) )
456 int i;
457 for(i=0;i<32768*((int)sharing_pause);i++)
458 result++; /* stop the optimizer */
459 for(i=0;i<32768*((int)sharing_pause);i++)
460 result--;
463 while( (!result) && (!(retries--)) );
465 if(result)
467 errno_to_doserr();
468 AX_reg(context) = DOS_ExtendedError;
469 close(handle);
470 SET_CFLAG(context);
471 return;
476 Error (0,0,0);
477 AX_reg(context) = handle;
478 RESET_CFLAG(context);
480 #endif
483 static void CloseFile( CONTEXT *context )
485 if ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0)
487 AX_reg(context) = DOS_ExtendedError;
488 SET_CFLAG(context);
492 static BOOL32 INT21_ExtendedOpenCreateFile(CONTEXT *context )
494 BOOL32 bExtendedError = FALSE;
495 BYTE action = DL_reg(context);
497 /* Shuffle arguments to call OpenExistingFile */
498 AL_reg(context) = BL_reg(context);
499 DX_reg(context) = SI_reg(context);
500 /* BX,CX and DX should be preserved */
501 OpenExistingFile(context);
503 if ((EFL_reg(context) & 0x0001) == 0) /* File exists */
505 UINT16 uReturnCX = 0;
507 /* Now decide what do do */
509 if ((action & 0x07) == 0)
511 BX_reg(context) = AX_reg(context);
512 CloseFile(context);
513 AX_reg(context) = 0x0050; /*File exists*/
514 SET_CFLAG(context);
515 WARN(int21, "extended open/create: failed because file exists \n");
517 else if ((action & 0x07) == 2)
519 /* Truncate it, but first check if opened for write */
520 if ((BL_reg(context) & 0x0007)== 0)
522 BX_reg(context) = AX_reg(context);
523 CloseFile(context);
524 WARN(int21, "extended open/create: failed, trunc on ro file\n");
525 AX_reg(context) = 0x000C; /*Access code invalid*/
526 SET_CFLAG(context);
528 else
530 /* Shuffle arguments to call CloseFile while
531 * preserving BX and DX */
533 TRACE(int21, "extended open/create: Closing before truncate\n");
534 BX_reg(context) = AX_reg(context);
535 CloseFile(context);
536 if (EFL_reg(context) & 0x0001)
538 WARN(int21, "extended open/create: close before trunc failed\n");
539 AX_reg(context) = 0x0019; /*Seek Error*/
540 CX_reg(context) = 0;
541 SET_CFLAG(context);
543 /* Shuffle arguments to call CreateFile */
545 TRACE(int21, "extended open/create: Truncating\n");
546 AL_reg(context) = BL_reg(context);
547 /* CX is still the same */
548 DX_reg(context) = SI_reg(context);
549 bExtendedError = INT21_CreateFile(context);
551 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
553 WARN(int21, "extended open/create: trunc failed\n");
554 return bExtendedError;
556 uReturnCX = 0x3;
559 else uReturnCX = 0x1;
561 CX_reg(context) = uReturnCX;
563 else /* file does not exist */
565 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
566 if ((action & 0xF0)== 0)
568 CX_reg(context) = 0;
569 SET_CFLAG(context);
570 WARN(int21, "extended open/create: failed, file dosen't exist\n");
572 else
574 /* Shuffle arguments to call CreateFile */
575 TRACE(int21, "extended open/create: Creating\n");
576 AL_reg(context) = BL_reg(context);
577 /* CX should still be the same */
578 DX_reg(context) = SI_reg(context);
579 bExtendedError = INT21_CreateFile(context);
580 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
582 WARN(int21, "extended open/create: create failed\n");
583 return bExtendedError;
585 CX_reg(context) = 2;
589 return bExtendedError;
593 static BOOL32 INT21_ChangeDir( CONTEXT *context )
595 int drive;
596 char *dirname = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context));
598 TRACE(int21,"changedir %s\n", dirname);
599 if (dirname[0] && (dirname[1] == ':'))
601 drive = toupper(dirname[0]) - 'A';
602 dirname += 2;
604 else drive = DRIVE_GetCurrentDrive();
605 return DRIVE_Chdir( drive, dirname );
609 static int INT21_FindFirst( CONTEXT *context )
611 char *p;
612 const char *path;
613 DOS_FULL_NAME full_name;
614 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
616 path = (const char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
617 dta->unixPath = NULL;
618 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
620 AX_reg(context) = DOS_ExtendedError;
621 SET_CFLAG(context);
622 return 0;
624 dta->unixPath = HEAP_strdupA( GetProcessHeap(), 0, full_name.long_name );
625 p = strrchr( dta->unixPath, '/' );
626 *p = '\0';
628 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
629 * (doesn't matter as it is set below anyway)
631 if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
633 HeapFree( GetProcessHeap(), 0, dta->unixPath );
634 dta->unixPath = NULL;
635 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
636 AX_reg(context) = ER_FileNotFound;
637 SET_CFLAG(context);
638 return 0;
640 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
641 : DRIVE_GetCurrentDrive();
642 dta->count = 0;
643 dta->search_attr = CL_reg(context);
644 return 1;
648 static int INT21_FindNext( CONTEXT *context )
650 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
651 WIN32_FIND_DATA32A entry;
652 int count;
654 if (!dta->unixPath) return 0;
655 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
656 dta->search_attr, dta->count, &entry )))
658 HeapFree( GetProcessHeap(), 0, dta->unixPath );
659 dta->unixPath = NULL;
660 return 0;
662 if ((int)dta->count + count > 0xffff)
664 WARN(int21, "Too many directory entries in %s\n", dta->unixPath );
665 HeapFree( GetProcessHeap(), 0, dta->unixPath );
666 dta->unixPath = NULL;
667 return 0;
669 dta->count += count;
670 dta->fileattr = entry.dwFileAttributes;
671 dta->filesize = entry.nFileSizeLow;
672 FileTimeToDosDateTime( &entry.ftLastWriteTime,
673 &dta->filedate, &dta->filetime );
674 strcpy( dta->filename, entry.cAlternateFileName );
675 if (!memchr(dta->mask,'?',11)) {
676 /* wildcardless search, release resources in case no findnext will
677 * be issued, and as a workaround in case file creation messes up
678 * findnext, as sometimes happens with pkunzip */
679 HeapFree( GetProcessHeap(), 0, dta->unixPath );
680 dta->unixPath = NULL;
682 return 1;
686 static BOOL32 INT21_CreateTempFile( CONTEXT *context )
688 static int counter = 0;
689 char *name = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context) );
690 char *p = name + strlen(name);
692 /* despite what Ralf Brown says, some programs seem to call without
693 * ending backslash (DOS accepts that, so we accept it too) */
694 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
696 for (;;)
698 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
699 counter = (counter + 1) % 1000;
701 if ((AX_reg(context) = HFILE32_TO_HFILE16(_lcreat_uniq( name, 0 ))) != (WORD)HFILE_ERROR16)
703 TRACE(int21, "created %s\n", name );
704 return TRUE;
706 if (DOS_ExtendedError != ER_FileExists) return FALSE;
711 static BOOL32 INT21_GetCurrentDirectory( CONTEXT *context )
713 int drive = DOS_GET_DRIVE( DL_reg(context) );
714 char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), SI_reg(context) );
716 if (!DRIVE_IsValid(drive))
718 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
719 return FALSE;
721 lstrcpyn32A( ptr, DRIVE_GetDosCwd(drive), 64 );
722 AX_reg(context) = 0x0100; /* success return code */
723 return TRUE;
727 static void INT21_GetDBCSLeadTable( CONTEXT *context )
729 if (heap || INT21_CreateHeap())
730 { /* return an empty table just as DOS 4.0+ does */
731 DS_reg(context) = DosHeapHandle;
732 SI_reg(context) = (int)&heap->DummyDBCSLeadTable - (int)heap;
734 else
736 AX_reg(context) = 0x1; /* error */
737 SET_CFLAG(context);
742 static int INT21_GetDiskSerialNumber( CONTEXT *context )
744 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
745 int drive = DOS_GET_DRIVE( BL_reg(context) );
747 if (!DRIVE_IsValid(drive))
749 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
750 return 0;
753 *(WORD *)dataptr = 0;
754 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
755 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
756 strncpy(dataptr + 0x11, "FAT16 ", 8);
757 return 1;
761 static int INT21_SetDiskSerialNumber( CONTEXT *context )
763 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
764 int drive = DOS_GET_DRIVE( BL_reg(context) );
766 if (!DRIVE_IsValid(drive))
768 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
769 return 0;
772 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
773 return 1;
777 /* microsoft's programmers should be shot for using CP/M style int21
778 calls in Windows for Workgroup's winfile.exe */
780 static int INT21_FindFirstFCB( CONTEXT *context )
782 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
783 FINDFILE_FCB *pFCB;
784 LPCSTR root, cwd;
785 int drive;
787 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
788 else pFCB = (FINDFILE_FCB *)fcb;
789 drive = DOS_GET_DRIVE( pFCB->drive );
790 if (!DRIVE_IsValid( drive )) return 0;
791 root = DRIVE_GetRoot( drive );
792 cwd = DRIVE_GetUnixCwd( drive );
793 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
794 strlen(root)+strlen(cwd)+2 );
795 if (!pFCB->unixPath) return 0;
796 strcpy( pFCB->unixPath, root );
797 strcat( pFCB->unixPath, "/" );
798 strcat( pFCB->unixPath, cwd );
799 pFCB->count = 0;
800 return 1;
804 static int INT21_FindNextFCB( CONTEXT *context )
806 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context));
807 FINDFILE_FCB *pFCB;
808 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA(context);
809 WIN32_FIND_DATA32A entry;
810 BYTE attr;
811 int count;
813 if (*fcb == 0xff) /* extended FCB ? */
815 attr = fcb[6];
816 pFCB = (FINDFILE_FCB *)(fcb + 7);
818 else
820 attr = 0;
821 pFCB = (FINDFILE_FCB *)fcb;
824 if (!pFCB->unixPath) return 0;
825 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
826 DOS_GET_DRIVE( pFCB->drive ), attr,
827 pFCB->count, &entry )))
829 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
830 pFCB->unixPath = NULL;
831 return 0;
833 pFCB->count += count;
835 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
836 *(BYTE *)pResult = 0xff;
837 (BYTE *)pResult +=6; /* leave reserved field behind */
838 *(BYTE *)pResult = entry.dwFileAttributes;
839 ((BYTE *)pResult)++;
841 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
842 ((BYTE *)pResult)++;
843 pResult->fileattr = entry.dwFileAttributes;
844 pResult->cluster = 0; /* what else? */
845 pResult->filesize = entry.nFileSizeLow;
846 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
847 FileTimeToDosDateTime( &entry.ftLastWriteTime,
848 &pResult->filedate, &pResult->filetime );
850 /* Convert file name to FCB format */
852 memset( pResult->filename, ' ', sizeof(pResult->filename) );
853 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
854 else if (!strcmp( entry.cAlternateFileName, ".." ))
855 pResult->filename[0] = pResult->filename[1] = '.';
856 else
858 char *p = strrchr( entry.cAlternateFileName, '.' );
859 if (p && p[1] && (p != entry.cAlternateFileName))
861 memcpy( pResult->filename, entry.cAlternateFileName,
862 MIN( (p - entry.cAlternateFileName), 8 ) );
863 memcpy( pResult->filename + 8, p + 1, MIN( strlen(p), 3 ) );
865 else
866 memcpy( pResult->filename, entry.cAlternateFileName,
867 MIN( strlen(entry.cAlternateFileName), 8 ) );
869 return 1;
873 static void DeleteFileFCB( CONTEXT *context )
875 FIXME(int21, "(%p): stub\n", context);
878 static void RenameFileFCB( CONTEXT *context )
880 FIXME(int21, "(%p): stub\n", context);
885 static void fLock( CONTEXT * context )
888 switch ( AX_reg(context) & 0xff )
890 case 0x00: /* LOCK */
891 TRACE(int21,"lock handle %d offset %ld length %ld\n",
892 BX_reg(context),
893 MAKELONG(DX_reg(context),CX_reg(context)),
894 MAKELONG(DI_reg(context),SI_reg(context))) ;
895 if (!LockFile(HFILE16_TO_HFILE32(BX_reg(context)),
896 MAKELONG(DX_reg(context),CX_reg(context)), 0,
897 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
898 AX_reg(context) = DOS_ExtendedError;
899 SET_CFLAG(context);
901 break;
903 case 0x01: /* UNLOCK */
904 TRACE(int21,"unlock handle %d offset %ld length %ld\n",
905 BX_reg(context),
906 MAKELONG(DX_reg(context),CX_reg(context)),
907 MAKELONG(DI_reg(context),SI_reg(context))) ;
908 if (!UnlockFile(HFILE16_TO_HFILE32(BX_reg(context)),
909 MAKELONG(DX_reg(context),CX_reg(context)), 0,
910 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
911 AX_reg(context) = DOS_ExtendedError;
912 SET_CFLAG(context);
914 return;
915 default:
916 AX_reg(context) = 0x0001;
917 SET_CFLAG(context);
918 return;
922 static BOOL32
923 INT21_networkfunc (CONTEXT *context)
925 switch (AL_reg(context)) {
926 case 0x00: /* Get machine name. */
928 char *dst = CTX_SEG_OFF_TO_LIN (context,DS_reg(context),DX_reg(context));
929 TRACE(int21, "getting machine name to %p\n", dst);
930 if (gethostname (dst, 15))
932 WARN(int21,"failed!\n");
933 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
934 return TRUE;
935 } else {
936 int len = strlen (dst);
937 while (len < 15)
938 dst[len++] = ' ';
939 dst[15] = 0;
940 CH_reg(context) = 1; /* Valid */
941 CL_reg(context) = 1; /* NETbios number??? */
942 TRACE(int21, "returning %s\n", debugstr_an (dst, 16));
943 return FALSE;
947 default:
948 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
949 return TRUE;
953 static void INT21_SetCurrentPSP(WORD psp)
955 #ifdef MZ_SUPPORTED
956 TDB *pTask = hModule ? NULL : (TDB *)GlobalLock16( GetCurrentTask() );
957 NE_MODULE *pModule = (hModule || pTask) ? NE_GetPtr( hModule ? hModule : pTask->hModule ) : NULL;
959 GlobalUnlock16( GetCurrentTask() );
960 if (pModule->lpDosTask)
961 pModule->lpDosTask->psp_seg = psp;
962 else
963 #endif
964 ERR(int21, "Cannot change PSP for non-DOS task!\n");
967 static WORD INT21_GetCurrentPSP()
969 #ifdef MZ_SUPPORTED
970 TDB *pTask = hModule ? NULL : (TDB *)GlobalLock16( GetCurrentTask() );
971 NE_MODULE *pModule = (hModule || pTask) ? NE_GetPtr( hModule ? hModule : pTask->hModule ) : NULL;
973 GlobalUnlock16( GetCurrentTask() );
974 if (pModule->lpDosTask)
975 return pModule->lpDosTask->psp_seg;
976 else
977 #endif
978 return GetCurrentPDB();
982 SEGPTR INT21_GetListOfLists()
984 static DOS_LISTOFLISTS *LOL;
985 static SEGPTR seg_LOL;
988 Output of DOS 6.22:
990 0133:0020 6A 13-33 01 CC 00 33 01 59 00 j.3...3.Y.
991 0133:0030 70 00 00 00 72 02 00 02-6D 00 33 01 00 00 2E 05 p...r...m.3.....
992 0133:0040 00 00 FC 04 00 00 03 08-92 21 11 E0 04 80 C6 0D .........!......
993 0133:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..NUL ......
994 0133:0060 00 4B BA C1 06 14 00 00-00 03 01 00 04 70 CE FF .K...........p..
995 0133:0070 FF 00 00 00 00 00 00 00-00 01 00 00 0D 05 00 00 ................
996 0133:0080 00 FF FF 00 00 00 00 FE-00 00 F8 03 FF 9F 70 02 ..............p.
997 0133:0090 D0 44 C8 FD D4 44 C8 FD-D4 44 C8 FD D0 44 C8 FD .D...D...D...D..
998 0133:00A0 D0 44 C8 FD D0 44 .D...D
1000 if (!LOL) {
1001 LOL = SEGPTR_ALLOC(sizeof(DOS_LISTOFLISTS));
1003 LOL->CX_Int21_5e01 = 0x0;
1004 LOL->LRU_count_FCB_cache = 0x0;
1005 LOL->LRU_count_FCB_open = 0x0;
1006 LOL->OEM_func_handler = -1; /* not available */
1007 LOL->INT21_offset = 0x0;
1008 LOL->sharing_retry_count = sharing_retries; /* default value: 3 */
1009 LOL->sharing_retry_delay = sharing_pause; /* default value: 1 */
1010 LOL->ptr_disk_buf = 0x0;
1011 LOL->offs_unread_CON = 0x0;
1012 LOL->seg_first_MCB = 0x0;
1013 LOL->ptr_first_DPB = 0x0;
1014 LOL->ptr_first_SysFileTable = 0x0;
1015 LOL->ptr_clock_dev_hdr = 0x0;
1016 LOL->ptr_CON_dev_hdr = 0x0;
1017 LOL->max_byte_per_sec = 512;
1018 LOL->ptr_disk_buf_info = 0x0;
1019 LOL->ptr_array_CDS = 0x0;
1020 LOL->ptr_sys_FCB = 0x0;
1021 LOL->nr_protect_FCB = 0x0;
1022 LOL->nr_block_dev = 0x0;
1023 LOL->nr_avail_drive_letters = 26; /* A - Z */
1024 LOL->nr_drives_JOINed = 0x0;
1025 LOL->ptr_spec_prg_names = 0x0;
1026 LOL->ptr_SETVER_prg_list = 0x0; /* no SETVER list */
1027 LOL->DOS_HIGH_A20_func_offs = 0x0;
1028 LOL->PSP_last_exec = 0x0;
1029 LOL->BUFFERS_val = 99; /* maximum: 99 */
1030 LOL->BUFFERS_nr_lookahead = 8; /* maximum: 8 */
1031 LOL->boot_drive = 3; /* C: */
1032 LOL->flag_DWORD_moves = 0x01; /* i386+ */
1033 LOL->size_extended_mem = 0xf000; /* very high value */
1035 if (!seg_LOL) seg_LOL = SEGPTR_GET(LOL);
1036 return seg_LOL+(WORD)&((DOS_LISTOFLISTS*)0)->ptr_first_DPB;
1039 /***********************************************************************
1040 * DOS3Call (KERNEL.102)
1042 void WINAPI DOS3Call( CONTEXT *context )
1044 BOOL32 bSetDOSExtendedError = FALSE;
1046 #if 0
1047 TRACE(int21, "AX=%04x BX=%04x CX=%04x DX=%04x "
1048 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1049 AX_reg(context), BX_reg(context), CX_reg(context), DX_reg(context),
1050 SI_reg(context), DI_reg(context),
1051 (WORD)DS_reg(context), (WORD)ES_reg(context),
1052 EFL_reg(context) );
1053 #endif
1055 if (AH_reg(context) == 0x59) /* Get extended error info */
1057 TRACE(int21, "GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1058 DOS_ExtendedError, DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus);
1059 AX_reg(context) = DOS_ExtendedError;
1060 BH_reg(context) = DOS_ErrorClass;
1061 BL_reg(context) = DOS_ErrorAction;
1062 CH_reg(context) = DOS_ErrorLocus;
1063 return;
1066 if (AH_reg(context) == 0x0C) /* Flush buffer and read standard input */
1068 TRACE(int21, "FLUSH BUFFER AND READ STANDARD INPUT\n");
1069 /* no flush here yet */
1070 AH_reg(context) = AL_reg(context);
1073 DOS_ERROR( 0, 0, 0, 0 );
1074 RESET_CFLAG(context); /* Not sure if this is a good idea */
1076 switch(AH_reg(context))
1078 case 0x00: /* TERMINATE PROGRAM */
1079 TRACE(int21,"TERMINATE PROGRAM\n");
1080 ExitProcess( 0 );
1081 break;
1083 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1084 case 0x03: /* READ CHARACTER FROM STDAUX */
1085 case 0x04: /* WRITE CHARACTER TO STDAUX */
1086 case 0x05: /* WRITE CHARACTER TO PRINTER */
1087 case 0x0b: /* GET STDIN STATUS */
1088 case 0x0f: /* OPEN FILE USING FCB */
1089 case 0x10: /* CLOSE FILE USING FCB */
1090 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1091 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1092 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1093 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1094 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1095 case 0x23: /* GET FILE SIZE FOR FCB */
1096 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1097 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1098 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1099 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1100 case 0x54: /* GET VERIFY FLAG */
1101 INT_BARF( context, 0x21 );
1102 break;
1104 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1105 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1106 _lwrite16( 1, &DL_reg(context), 1);
1107 break;
1109 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1110 TRACE(int21,"DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1111 _lread16( 0, &AL_reg(context), 1);
1112 break;
1114 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1115 TRACE(int21,"CHARACTER INPUT WITHOUT ECHO\n");
1116 _lread16( 0, &AL_reg(context), 1);
1117 break;
1119 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1120 TRACE(int21,"WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1121 DS_reg(context),DX_reg(context) );
1123 LPSTR data = CTX_SEG_OFF_TO_LIN(context,DS_reg(context),DX_reg(context));
1124 LONG length = strchr(data,'$')-data;
1125 _hwrite16( 1, data, length);
1126 AL_reg(context) = '$'; /* yes, '$' (0x24) gets returned in AL */
1128 break;
1130 case 0x0a: /* BUFFERED INPUT */
1132 char *buffer = ((char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1133 DX_reg(context) ));
1134 int res;
1136 TRACE(int21,"BUFFERED INPUT (size=%d)\n",buffer[0]);
1137 if (buffer[1])
1138 TRACE(int21,"Handle old chars in buffer!\n");
1139 res=_lread16( 0, buffer+2,buffer[0]);
1140 buffer[1]=res;
1141 if(buffer[res+1] == '\n')
1142 buffer[res+1] = '\r';
1143 break;
1146 case 0x2e: /* SET VERIFY FLAG */
1147 TRACE(int21,"SET VERIFY FLAG ignored\n");
1148 /* we cannot change the behaviour anyway, so just ignore it */
1149 break;
1151 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1152 case 0x1d:
1153 case 0x1e:
1154 case 0x20:
1155 case 0x6b: /* NULL FUNCTION */
1156 AL_reg(context) = 0;
1157 break;
1159 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1160 fLock(context);
1161 break;
1163 case 0x0d: /* DISK BUFFER FLUSH */
1164 TRACE(int21,"DISK BUFFER FLUSH ignored\n");
1165 RESET_CFLAG(context); /* dos 6+ only */
1166 break;
1168 case 0x0e: /* SELECT DEFAULT DRIVE */
1169 TRACE(int21,"SELECT DEFAULT DRIVE %d\n", DL_reg(context));
1170 DRIVE_SetCurrentDrive( DL_reg(context) );
1171 AL_reg(context) = MAX_DOS_DRIVES;
1172 break;
1174 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1175 TRACE(int21,"FIND FIRST MATCHING FILE USING FCB %p\n",
1176 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1177 if (!INT21_FindFirstFCB(context))
1179 AL_reg(context) = 0xff;
1180 break;
1182 /* else fall through */
1184 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1185 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
1186 break;
1188 case 0x13: /* DELETE FILE USING FCB */
1189 DeleteFileFCB(context);
1190 break;
1192 case 0x17: /* RENAME FILE USING FCB */
1193 RenameFileFCB(context);
1194 break;
1196 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1197 AL_reg(context) = DRIVE_GetCurrentDrive();
1198 break;
1200 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1202 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1203 pTask->dta = PTR_SEG_OFF_TO_SEGPTR(DS_reg(context),DX_reg(context));
1204 TRACE(int21, "Set DTA: %08lx\n", pTask->dta);
1206 break;
1208 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1209 DL_reg(context) = 0;
1210 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1211 break;
1213 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1214 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1215 break;
1217 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1218 GetDrivePB(context, DRIVE_GetCurrentDrive());
1219 break;
1221 case 0x25: /* SET INTERRUPT VECTOR */
1222 INT_CtxSetHandler( context, AL_reg(context),
1223 (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1224 DX_reg(context)));
1225 break;
1227 case 0x29: /* PARSE FILENAME INTO FCB */
1228 INT21_ParseFileNameIntoFCB(context);
1229 break;
1231 case 0x2a: /* GET SYSTEM DATE */
1232 INT21_GetSystemDate(context);
1233 break;
1235 case 0x2b: /* SET SYSTEM DATE */
1236 FIXME(int21, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1237 DL_reg(context), DH_reg(context), CX_reg(context) );
1238 AL_reg(context) = 0; /* Let's pretend we succeeded */
1239 break;
1241 case 0x2c: /* GET SYSTEM TIME */
1242 INT21_GetSystemTime(context);
1243 break;
1245 case 0x2d: /* SET SYSTEM TIME */
1246 FIXME(int21, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1247 CH_reg(context), CL_reg(context),
1248 DH_reg(context), DL_reg(context) );
1249 AL_reg(context) = 0; /* Let's pretend we succeeded */
1250 break;
1252 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1253 TRACE(int21,"GET DISK TRANSFER AREA ADDRESS\n");
1255 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1256 ES_reg(context) = SELECTOROF( pTask->dta );
1257 BX_reg(context) = OFFSETOF( pTask->dta );
1259 break;
1261 case 0x30: /* GET DOS VERSION */
1262 TRACE(int21,"GET DOS VERSION %s requested\n",
1263 (AL_reg(context) == 0x00)?"OEM number":"version flag");
1264 AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
1265 (HIWORD(GetVersion16()) << 8);
1266 #if 0
1267 AH_reg(context) = 0x7;
1268 AL_reg(context) = 0xA;
1269 #endif
1271 BX_reg(context) = 0x00FF; /* 0x123456 is Wine's serial # */
1272 CX_reg(context) = 0x0000;
1273 break;
1275 case 0x31: /* TERMINATE AND STAY RESIDENT */
1276 FIXME(int21,"TERMINATE AND STAY RESIDENT stub\n");
1277 break;
1279 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1280 TRACE(int21,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1281 INT21_DriveName( DL_reg(context)));
1282 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
1283 break;
1285 case 0x33: /* MULTIPLEXED */
1286 switch (AL_reg(context))
1288 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1289 TRACE(int21,"GET CURRENT EXTENDED BREAK STATE stub\n");
1290 DL_reg(context) = 0;
1291 break;
1293 case 0x01: /* SET EXTENDED BREAK STATE */
1294 TRACE(int21,"SET CURRENT EXTENDED BREAK STATE stub\n");
1295 break;
1297 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1298 TRACE(int21,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE stub\n");
1299 DL_reg(context) = 0;
1300 break;
1302 case 0x05: /* GET BOOT DRIVE */
1303 TRACE(int21,"GET BOOT DRIVE\n");
1304 DL_reg(context) = 3;
1305 /* c: is Wine's bootdrive (a: is 1)*/
1306 break;
1308 case 0x06: /* GET TRUE VERSION NUMBER */
1309 TRACE(int21,"GET TRUE VERSION NUMBER\n");
1310 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1311 (HIWORD(GetVersion16() << 8));
1312 DX_reg(context) = 0x00;
1313 break;
1315 default:
1316 INT_BARF( context, 0x21 );
1317 break;
1319 break;
1321 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1322 TRACE(int21,"GET ADDRESS OF INDOS FLAG\n");
1323 if (!heap) INT21_CreateHeap();
1324 ES_reg(context) = DosHeapHandle;
1325 BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1326 break;
1328 case 0x35: /* GET INTERRUPT VECTOR */
1329 TRACE(int21,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1331 FARPROC16 addr = INT_CtxGetHandler( context, AL_reg(context) );
1332 ES_reg(context) = SELECTOROF(addr);
1333 BX_reg(context) = OFFSETOF(addr);
1335 break;
1337 case 0x36: /* GET FREE DISK SPACE */
1338 TRACE(int21,"GET FREE DISK SPACE FOR DRIVE %s\n",
1339 INT21_DriveName( DL_reg(context)));
1340 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1341 break;
1343 case 0x37:
1345 unsigned char switchchar='/';
1346 switch (AL_reg(context))
1348 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1349 TRACE(int21,"SWITCHAR - GET SWITCH CHARACTER\n");
1350 AL_reg(context) = 0x00; /* success*/
1351 DL_reg(context) = switchchar;
1352 break;
1353 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1354 TRACE(int21,"SWITCHAR - SET SWITCH CHARACTER\n");
1355 switchchar = DL_reg(context);
1356 AL_reg(context) = 0x00; /* success*/
1357 break;
1358 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1359 INT_BARF( context, 0x21 );
1360 break;
1362 break;
1365 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1366 TRACE(int21,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1367 AL_reg(context));
1368 AX_reg(context) = 0x02; /* no country support available */
1369 SET_CFLAG(context);
1370 break;
1372 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1373 TRACE(int21,"MKDIR %s\n",
1374 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1375 bSetDOSExtendedError = (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1376 DX_reg(context) ), NULL));
1377 break;
1379 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1380 TRACE(int21,"RMDIR %s\n",
1381 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1382 bSetDOSExtendedError = (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1383 DX_reg(context) )));
1384 break;
1386 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1387 TRACE(int21,"CHDIR %s\n",
1388 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1389 bSetDOSExtendedError = !INT21_ChangeDir(context);
1390 break;
1392 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1393 TRACE(int21,"CREAT flag 0x%02x %s\n",CX_reg(context),
1394 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1395 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1396 DX_reg(context) ), CX_reg(context) );
1397 bSetDOSExtendedError = (AX_reg(context) == (WORD)HFILE_ERROR16);
1398 break;
1400 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1401 TRACE(int21,"OPEN mode 0x%02x %s\n",AL_reg(context),
1402 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1403 OpenExistingFile(context);
1404 break;
1406 case 0x3e: /* "CLOSE" - CLOSE FILE */
1407 TRACE(int21,"CLOSE handle %d\n",BX_reg(context));
1408 if ((BX_reg(context)<5)||
1409 /* FIXME: need to improve on those handle conversion macros */
1410 (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_INPUT_HANDLE)))||
1411 (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_OUTPUT_HANDLE)))||
1412 (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_ERROR_HANDLE)))) {
1413 /* hack to make sure stdio isn't closed */
1414 FIXME(int21, "stdio handle closed, need proper conversion\n");
1415 DOS_ExtendedError = 0x06;
1416 bSetDOSExtendedError = TRUE;
1417 } else
1418 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1419 break;
1421 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1422 TRACE(int21,"READ from %d to %04lX:%04X for %d byte\n",BX_reg(context),
1423 DS_reg(context),DX_reg(context),CX_reg(context) );
1425 LONG result;
1426 if (ISV86(context))
1427 result = _hread16( BX_reg(context),
1428 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1429 DX_reg(context) ),
1430 CX_reg(context) );
1431 else
1432 result = WIN16_hread( BX_reg(context),
1433 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1434 DX_reg(context) ),
1435 CX_reg(context) );
1436 if (result == -1) bSetDOSExtendedError = TRUE;
1437 else AX_reg(context) = (WORD)result;
1439 break;
1441 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1442 TRACE(int21,"WRITE from %04lX:%04X to handle %d for %d byte\n",
1443 DS_reg(context),DX_reg(context),BX_reg(context),CX_reg(context) );
1445 LONG result = _hwrite16( BX_reg(context),
1446 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1447 DX_reg(context) ),
1448 CX_reg(context) );
1449 if (result == -1) bSetDOSExtendedError = TRUE;
1450 else AX_reg(context) = (WORD)result;
1452 break;
1454 case 0x41: /* "UNLINK" - DELETE FILE */
1455 TRACE(int21,"UNLINK%s\n",
1456 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1457 bSetDOSExtendedError = (!DeleteFile32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1458 DX_reg(context) )));
1459 break;
1461 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1462 TRACE(int21,"LSEEK handle %d offset %ld from %s\n",
1463 BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)),
1464 (AL_reg(context)==0)?"start of file":(AL_reg(context)==1)?
1465 "current file position":"end of file");
1467 LONG status = _llseek16( BX_reg(context),
1468 MAKELONG(DX_reg(context),CX_reg(context)),
1469 AL_reg(context) );
1470 if (status == -1) bSetDOSExtendedError = TRUE;
1471 else
1473 AX_reg(context) = LOWORD(status);
1474 DX_reg(context) = HIWORD(status);
1477 break;
1479 case 0x43: /* FILE ATTRIBUTES */
1480 switch (AL_reg(context))
1482 case 0x00:
1483 TRACE(int21,"GET FILE ATTRIBUTES for %s\n",
1484 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1485 AX_reg(context) = (WORD)GetFileAttributes32A(
1486 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1487 DX_reg(context)));
1488 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1489 else CX_reg(context) = AX_reg(context);
1490 break;
1492 case 0x01:
1493 TRACE(int21,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context),
1494 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1495 bSetDOSExtendedError =
1496 (!SetFileAttributes32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1497 DX_reg(context)),
1498 CX_reg(context) ));
1499 break;
1500 case 0x02:
1501 TRACE(int21,"GET COMPRESSED FILE SIZE for %s stub\n",
1502 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1504 break;
1506 case 0x44: /* IOCTL */
1507 switch (AL_reg(context))
1509 case 0x00:
1510 ioctlGetDeviceInfo(context);
1511 break;
1513 case 0x01:
1514 break;
1515 case 0x02:{
1516 FILE_OBJECT *file;
1517 file = FILE_GetFile(HFILE16_TO_HFILE32(BX_reg(context)));
1518 if (!strcasecmp(file->unix_name, "SCSIMGR$"))
1519 ASPI_DOS_HandleInt(context);
1520 FILE_ReleaseFile( file );
1521 break;
1523 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1524 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context));*/
1525 int drive = DOS_GET_DRIVE(BL_reg(context));
1527 FIXME(int21,"program tried to write to block device control channel of drive %d:\n",drive);
1528 /* for (i=0;i<CX_reg(context);i++)
1529 fprintf(stdnimp,"%02x ",dataptr[i]);
1530 fprintf(stdnimp,"\n");*/
1531 AX_reg(context)=CX_reg(context);
1532 break;
1534 case 0x08: /* Check if drive is removable. */
1535 TRACE(int21,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1536 INT21_DriveName( BL_reg(context)));
1537 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1539 case DRIVE_CANNOTDETERMINE:
1540 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1541 AX_reg(context) = ER_InvalidDrive;
1542 SET_CFLAG(context);
1543 break;
1544 case DRIVE_REMOVABLE:
1545 AX_reg(context) = 0; /* removable */
1546 break;
1547 default:
1548 AX_reg(context) = 1; /* not removable */
1549 break;
1551 break;
1553 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1554 TRACE(int21,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1555 INT21_DriveName( BL_reg(context)));
1556 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1558 case DRIVE_CANNOTDETERMINE:
1559 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1560 AX_reg(context) = ER_InvalidDrive;
1561 SET_CFLAG(context);
1562 break;
1563 case DRIVE_REMOTE:
1564 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1565 break;
1566 default:
1567 DX_reg(context) = 0; /* FIXME: use driver attr here */
1568 break;
1570 break;
1572 case 0x0a: /* check if handle (BX) is remote */
1573 TRACE(int21,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context));
1574 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1575 * not set on close
1577 DX_reg(context) = 0;
1578 break;
1580 case 0x0b: /* SET SHARING RETRY COUNT */
1581 TRACE(int21,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1582 CX_reg(context), DX_reg(context));
1583 if (!CX_reg(context))
1585 AX_reg(context) = 1;
1586 SET_CFLAG(context);
1587 break;
1589 sharing_pause = CX_reg(context);
1590 if (!DX_reg(context))
1591 sharing_retries = DX_reg(context);
1592 RESET_CFLAG(context);
1593 break;
1595 case 0x0d:
1596 TRACE(int21,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1597 INT21_DriveName( BL_reg(context)));
1598 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1599 break;
1601 case 0x0e: /* get logical drive mapping */
1602 TRACE(int21,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1603 INT21_DriveName( BL_reg(context)));
1604 AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1605 break;
1607 case 0x0F: /* Set logical drive mapping */
1609 int drive;
1610 TRACE(int21,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1611 INT21_DriveName( BL_reg(context)));
1612 drive = DOS_GET_DRIVE ( BL_reg(context) );
1613 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1615 SET_CFLAG(context);
1616 AX_reg(context) = 0x000F; /* invalid drive */
1618 break;
1621 case 0xe0: /* Sun PC-NFS API */
1622 /* not installed */
1623 break;
1625 default:
1626 INT_BARF( context, 0x21 );
1627 break;
1629 break;
1631 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1632 TRACE(int21,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context));
1633 bSetDOSExtendedError = ((AX_reg(context) = HFILE32_TO_HFILE16(FILE_Dup(HFILE16_TO_HFILE32(BX_reg(context))))) == (WORD)HFILE_ERROR16);
1634 break;
1636 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1637 TRACE(int21,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1638 BX_reg(context),CX_reg(context));
1639 bSetDOSExtendedError = (FILE_Dup2( HFILE16_TO_HFILE32(BX_reg(context)), HFILE16_TO_HFILE32(CX_reg(context)) ) == HFILE_ERROR32);
1640 break;
1642 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1643 TRACE(int21,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1644 INT21_DriveName( DL_reg(context)));
1645 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1646 break;
1648 case 0x48: /* ALLOCATE MEMORY */
1649 TRACE(int21,"ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context));
1651 LPVOID *mem;
1652 if (ISV86(context))
1654 mem= DOSMEM_GetBlock(0,(DWORD)BX_reg(context)<<4,NULL);
1655 if (mem)
1656 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1658 else
1660 mem = (LPVOID)GlobalDOSAlloc(BX_reg(context)<<4);
1661 if (mem)
1662 AX_reg(context) = (DWORD)mem&0xffff;
1664 if (!mem)
1666 SET_CFLAG(context);
1667 AX_reg(context) = 0x0008; /* insufficient memory */
1668 BX_reg(context) = DOSMEM_Available(0)>>4;
1671 break;
1673 case 0x49: /* FREE MEMORY */
1674 TRACE(int21,"FREE MEMORY segment %04lX\n", ES_reg(context));
1676 BOOL32 ret;
1677 if (ISV86(context))
1678 ret= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4));
1679 else
1681 ret = !GlobalDOSFree(ES_reg(context));
1682 /* If we don't reset ES_reg, we will fail in the relay code */
1683 ES_reg(context)=ret;
1685 if (!ret)
1687 TRACE(int21,"FREE MEMORY failed\n");
1688 SET_CFLAG(context);
1689 AX_reg(context) = 0x0009; /* memory block address invalid */
1692 break;
1694 case 0x4a: /* RESIZE MEMORY BLOCK */
1695 TRACE(int21,"RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context), BX_reg(context));
1696 if (!ISV86(context))
1697 FIXME(int21,"RESIZE MEMORY probably insufficent implementation. Expect crash soon\n");
1699 LPVOID *mem = DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4),
1700 BX_reg(context)<<4,NULL);
1701 if (mem)
1702 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1703 else {
1704 SET_CFLAG(context);
1705 AX_reg(context) = 0x0008; /* insufficient memory */
1706 BX_reg(context) = DOSMEM_Available(0)>>4; /* not quite right */
1709 break;
1711 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1712 TRACE(int21,"EXEC %s\n",
1713 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context) ));
1714 AX_reg(context) = WinExec16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1715 DX_reg(context) ),
1716 SW_NORMAL );
1717 if (AX_reg(context) < 32) SET_CFLAG(context);
1718 break;
1720 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1721 TRACE(int21,"EXIT with return code %d\n",AL_reg(context));
1722 ExitProcess( AL_reg(context) );
1723 break;
1725 case 0x4d: /* GET RETURN CODE */
1726 TRACE(int21,"GET RETURN CODE (ERRORLEVEL)\n");
1727 AX_reg(context) = 0; /* normal exit */
1728 break;
1730 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1731 TRACE(int21,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
1732 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1733 if (!INT21_FindFirst(context)) break;
1734 /* fall through */
1736 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1737 TRACE(int21,"FINDNEXT\n");
1738 if (!INT21_FindNext(context))
1740 DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk );
1741 AX_reg(context) = ER_NoMoreFiles;
1742 SET_CFLAG(context);
1744 else AX_reg(context) = 0; /* OK */
1745 break;
1746 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1747 TRACE(int21, "SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1748 INT21_SetCurrentPSP(BX_reg(context));
1749 break;
1750 case 0x51: /* GET PSP ADDRESS */
1751 TRACE(int21,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1752 /* FIXME: should we return the original DOS PSP upon */
1753 /* Windows startup ? */
1754 BX_reg(context) = INT21_GetCurrentPSP();
1755 break;
1756 case 0x62: /* GET PSP ADDRESS */
1757 TRACE(int21,"GET CURRENT PSP ADDRESS\n");
1758 /* FIXME: should we return the original DOS PSP upon */
1759 /* Windows startup ? */
1760 BX_reg(context) = INT21_GetCurrentPSP();
1761 break;
1763 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1764 TRACE(int21,"SYSVARS - GET LIST OF LISTS\n");
1766 SEGPTR lol;
1767 lol = INT21_GetListOfLists();
1768 ES_reg(context) = HIWORD(lol);
1769 BX_reg(context) = LOWORD(lol);
1771 break;
1773 case 0x56: /* "RENAME" - RENAME FILE */
1774 TRACE(int21,"RENAME %s to %s\n",
1775 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)),
1776 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),DI_reg(context)));
1777 bSetDOSExtendedError =
1778 (!MoveFile32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)),
1779 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),DI_reg(context))));
1780 break;
1782 case 0x57: /* FILE DATE AND TIME */
1783 switch (AL_reg(context))
1785 case 0x00: /* Get */
1787 FILETIME filetime;
1788 TRACE(int21,"GET FILE DATE AND TIME for handle %d\n",
1789 BX_reg(context));
1790 if (!GetFileTime( HFILE16_TO_HFILE32(BX_reg(context)), NULL, NULL, &filetime ))
1791 bSetDOSExtendedError = TRUE;
1792 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1793 &CX_reg(context) );
1795 break;
1797 case 0x01: /* Set */
1799 FILETIME filetime;
1800 TRACE(int21,"SET FILE DATE AND TIME for handle %d\n",
1801 BX_reg(context));
1802 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1803 &filetime );
1804 bSetDOSExtendedError =
1805 (!SetFileTime( BX_reg(context), NULL, NULL, &filetime ));
1807 break;
1809 break;
1811 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1812 TRACE(int21,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1813 AL_reg(context));
1814 switch (AL_reg(context))
1816 case 0x00:
1817 AX_reg(context) = 1;
1818 break;
1819 case 0x02:
1820 AX_reg(context) = 0;
1821 break;
1822 case 0x01:
1823 case 0x03:
1824 break;
1826 RESET_CFLAG(context);
1827 break;
1829 case 0x5a: /* CREATE TEMPORARY FILE */
1830 TRACE(int21,"CREATE TEMPORARY FILE\n");
1831 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1832 break;
1834 case 0x5b: /* CREATE NEW FILE */
1835 TRACE(int21,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
1836 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
1837 bSetDOSExtendedError = ((AX_reg(context) =
1838 HFILE32_TO_HFILE16(_lcreat_uniq( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)), 0 )))
1839 == (WORD)HFILE_ERROR16);
1840 break;
1842 case 0x5d: /* NETWORK */
1843 FIXME(int21,"Function 0x%04x not implemented.\n", AX_reg (context));
1844 /* Fix the following while you're at it. */
1845 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1846 bSetDOSExtendedError = TRUE;
1847 break;
1849 case 0x5e:
1850 bSetDOSExtendedError = INT21_networkfunc (context);
1851 break;
1853 case 0x5f: /* NETWORK */
1854 switch (AL_reg(context))
1856 case 0x07: /* ENABLE DRIVE */
1857 TRACE(int21,"ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1858 if (!DRIVE_Enable( DL_reg(context) ))
1860 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1861 bSetDOSExtendedError = TRUE;
1863 break;
1865 case 0x08: /* DISABLE DRIVE */
1866 TRACE(int21,"DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1867 if (!DRIVE_Disable( DL_reg(context) ))
1869 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1870 bSetDOSExtendedError = TRUE;
1872 break;
1874 default:
1875 /* network software not installed */
1876 TRACE(int21,"NETWORK function AX=%04x not implemented\n",AX_reg(context));
1877 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1878 bSetDOSExtendedError = TRUE;
1879 break;
1881 break;
1883 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1884 TRACE(int21,"TRUENAME %s\n",
1885 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),SI_reg(context)));
1887 if (!GetFullPathName32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1888 SI_reg(context)), 128,
1889 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
1890 DI_reg(context)),NULL))
1891 bSetDOSExtendedError = TRUE;
1892 else AX_reg(context) = 0;
1894 break;
1896 case 0x61: /* UNUSED */
1897 case 0x63: /* misc. language support */
1898 switch (AL_reg(context)) {
1899 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1900 INT21_GetDBCSLeadTable(context);
1901 break;
1903 break;
1904 case 0x64: /* OS/2 DOS BOX */
1905 INT_BARF( context, 0x21 );
1906 SET_CFLAG(context);
1907 break;
1909 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1910 extern WORD WINE_LanguageId;
1911 BYTE *dataptr=CTX_SEG_OFF_TO_LIN(context, ES_reg(context),DI_reg(context));
1912 TRACE(int21,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1913 BX_reg(context), DX_reg(context));
1914 switch (AL_reg(context)) {
1915 case 0x01:
1916 TRACE(int21,"\tget general internationalization info\n");
1917 dataptr[0] = 0x1;
1918 *(WORD*)(dataptr+1) = 41;
1919 *(WORD*)(dataptr+3) = WINE_LanguageId;
1920 *(WORD*)(dataptr+5) = CodePage;
1921 *(DWORD*)(dataptr+0x19) = 0; /* FIXME: ptr to case map routine */
1922 break;
1923 case 0x06:
1924 TRACE(int21,"\tget pointer to collating sequence table\n");
1925 dataptr[0] = 0x06;
1926 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
1927 CX_reg(context) = 258;/*FIXME: size of table?*/
1928 break;
1929 default:
1930 TRACE(int21,"\tunimplemented function %d\n",AL_reg(context));
1931 INT_BARF( context, 0x21 );
1932 SET_CFLAG(context);
1933 break;
1935 break;
1937 case 0x66: /* GLOBAL CODE PAGE TABLE */
1938 switch (AL_reg(context))
1940 case 0x01:
1941 TRACE(int21,"GET GLOBAL CODE PAGE TABLE\n");
1942 DX_reg(context) = BX_reg(context) = CodePage;
1943 RESET_CFLAG(context);
1944 break;
1945 case 0x02:
1946 TRACE(int21,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
1947 BX_reg(context),DX_reg(context));
1948 CodePage = BX_reg(context);
1949 RESET_CFLAG(context);
1950 break;
1952 break;
1954 case 0x67: /* SET HANDLE COUNT */
1955 TRACE(int21,"SET HANDLE COUNT to %d\n",BX_reg(context) );
1956 SetHandleCount16( BX_reg(context) );
1957 if (DOS_ExtendedError) bSetDOSExtendedError = TRUE;
1958 break;
1960 case 0x68: /* "FFLUSH" - COMMIT FILE */
1961 case 0x6a: /* COMMIT FILE */
1962 TRACE(int21,"FFLUSH/COMMIT handle %d\n",BX_reg(context));
1963 bSetDOSExtendedError = (!FlushFileBuffers( HFILE16_TO_HFILE32(BX_reg(context)) ));
1964 break;
1966 case 0x69: /* DISK SERIAL NUMBER */
1967 switch (AL_reg(context))
1969 case 0x00:
1970 TRACE(int21,"GET DISK SERIAL NUMBER for drive %s\n",
1971 INT21_DriveName(BL_reg(context)));
1972 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1973 else AX_reg(context) = 0;
1974 break;
1976 case 0x01:
1977 TRACE(int21,"SET DISK SERIAL NUMBER for drive %s\n",
1978 INT21_DriveName(BL_reg(context)));
1979 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1980 else AX_reg(context) = 1;
1981 break;
1983 break;
1985 case 0x6C: /* Extended Open/Create*/
1986 TRACE(int21,"EXTENDED OPEN/CREATE %s\n",
1987 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DI_reg(context)));
1988 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
1989 break;
1991 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1992 if ((GetVersion32()&0xC0000004)!=0xC0000004) {
1993 /* not supported on anything but Win95 */
1994 TRACE(int21,"LONG FILENAME functions supported only by win95\n");
1995 SET_CFLAG(context);
1996 AL_reg(context) = 0;
1997 } else
1998 switch(AL_reg(context))
2000 case 0x39: /* Create directory */
2001 TRACE(int21,"LONG FILENAME - MAKE DIRECTORY %s\n",
2002 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
2003 bSetDOSExtendedError = (!CreateDirectory32A(
2004 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2005 DX_reg(context) ), NULL));
2006 break;
2007 case 0x3a: /* Remove directory */
2008 TRACE(int21,"LONG FILENAME - REMOVE DIRECTORY %s\n",
2009 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
2010 bSetDOSExtendedError = (!RemoveDirectory32A(
2011 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2012 DX_reg(context) )));
2013 break;
2014 case 0x43: /* Get/Set file attributes */
2015 TRACE(int21,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2016 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
2017 switch (BL_reg(context))
2019 case 0x00: /* Get file attributes */
2020 TRACE(int21,"\tretrieve attributes\n");
2021 CX_reg(context) = (WORD)GetFileAttributes32A(
2022 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2023 DX_reg(context)));
2024 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
2025 break;
2026 case 0x01:
2027 TRACE(int21,"\tset attributes 0x%04x\n",CX_reg(context));
2028 bSetDOSExtendedError = (!SetFileAttributes32A(
2029 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2030 DX_reg(context)),
2031 CX_reg(context) ) );
2032 break;
2033 default:
2034 FIXME(int21, "Unimplemented long file name function:\n");
2035 INT_BARF( context, 0x21 );
2036 SET_CFLAG(context);
2037 AL_reg(context) = 0;
2038 break;
2040 break;
2041 case 0x47: /* Get current directory */
2042 TRACE(int21," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2043 INT21_DriveName(DL_reg(context)));
2044 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
2045 break;
2047 case 0x4e: /* Find first file */
2048 TRACE(int21," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2049 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
2050 /* FIXME: use attributes in CX */
2051 if ((AX_reg(context) = FindFirstFile16(
2052 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)),
2053 (WIN32_FIND_DATA32A *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2054 DI_reg(context))))
2055 == INVALID_HANDLE_VALUE16)
2056 bSetDOSExtendedError = TRUE;
2057 break;
2058 case 0x4f: /* Find next file */
2059 TRACE(int21,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2060 BX_reg(context));
2061 if (!FindNextFile16( BX_reg(context),
2062 (WIN32_FIND_DATA32A *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2063 DI_reg(context))))
2064 bSetDOSExtendedError = TRUE;
2065 break;
2066 case 0xa1: /* Find close */
2067 TRACE(int21,"LONG FILENAME - FINDCLOSE for handle %d\n",
2068 BX_reg(context));
2069 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
2070 break;
2071 case 0xa0:
2072 TRACE(int21,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2073 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context)));
2074 break;
2075 case 0x60:
2076 switch(CL_reg(context))
2078 case 0x01: /*Get short filename or path */
2079 if (!GetShortPathName32A
2080 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2081 SI_reg(context)),
2082 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2083 DI_reg(context)), 67))
2084 bSetDOSExtendedError = TRUE;
2085 else AX_reg(context) = 0;
2086 break;
2087 case 0x02: /*Get canonical long filename or path */
2088 if (!GetFullPathName32A
2089 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2090 SI_reg(context)), 128,
2091 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2092 DI_reg(context)),NULL))
2093 bSetDOSExtendedError = TRUE;
2094 else AX_reg(context) = 0;
2095 break;
2096 default:
2097 FIXME(int21, "Unimplemented long file name function:\n");
2098 INT_BARF( context, 0x21 );
2099 SET_CFLAG(context);
2100 AL_reg(context) = 0;
2101 break;
2103 break;
2104 case 0x6c: /* Create or open file */
2105 TRACE(int21,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
2106 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), SI_reg(context)));
2107 /* translate Dos 7 action to Dos 6 action */
2108 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2109 break;
2111 case 0x3b: /* Change directory */
2112 TRACE(int21,"LONG FILENAME - CHANGE DIRECTORY %s\n",
2113 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
2114 if (!SetCurrentDirectory32A(CTX_SEG_OFF_TO_LIN(context,
2115 DS_reg(context),
2116 DX_reg(context)
2119 SET_CFLAG(context);
2120 AL_reg(context) = DOS_ExtendedError;
2122 break;
2123 case 0x41: /* Delete file */
2124 TRACE(int21,"LONG FILENAME - DELETE FILE %s\n",
2125 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)));
2126 if (!DeleteFile32A(CTX_SEG_OFF_TO_LIN(context,
2127 DS_reg(context),
2128 DX_reg(context))
2129 )) {
2130 SET_CFLAG(context);
2131 AL_reg(context) = DOS_ExtendedError;
2133 break;
2134 case 0x56: /* Move (rename) file */
2135 TRACE(int21,"LONG FILENAME - RENAME FILE %s to %s stub\n",
2136 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), DX_reg(context)),
2137 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context), DI_reg(context)));
2138 default:
2139 FIXME(int21, "Unimplemented long file name function:\n");
2140 INT_BARF( context, 0x21 );
2141 SET_CFLAG(context);
2142 AL_reg(context) = 0;
2143 break;
2145 break;
2147 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2148 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2149 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2150 TRACE(int21,"windows95 function AX %04x\n",
2151 AX_reg(context));
2152 WARN(int21, " returning unimplemented\n");
2153 SET_CFLAG(context);
2154 AL_reg(context) = 0;
2155 break;
2157 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2158 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2159 break;
2161 default:
2162 INT_BARF( context, 0x21 );
2163 break;
2165 } /* END OF SWITCH */
2167 if( bSetDOSExtendedError ) /* set general error condition */
2169 AX_reg(context) = DOS_ExtendedError;
2170 SET_CFLAG(context);
2173 if ((EFL_reg(context) & 0x0001))
2174 TRACE(int21, "failed, errorcode 0x%02x class 0x%02x action 0x%02x locus %02x\n",
2175 DOS_ExtendedError, DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus);
2177 TRACE(int21, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2178 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2179 AX_reg(context), BX_reg(context), CX_reg(context),
2180 DX_reg(context), SI_reg(context), DI_reg(context),
2181 (WORD)DS_reg(context), (WORD)ES_reg(context),
2182 EFL_reg(context));
2185 FARPROC16 WINAPI GetSetKernelDOSProc(FARPROC16 DosProc)
2187 FIXME(int21, "(DosProc=0x%08x): stub\n", (UINT32)DosProc);
2188 return NULL;