Implemented uppercasing functions (based on a patch by Robert
[wine/multimedia.git] / msdos / int21.c
blobdcfa684b0c02a31d17a441d3d6458e94fe61d93e
1 /*
2 * DOS interrupt 21h handler
3 */
5 #include <time.h>
6 #include <fcntl.h>
7 #include <errno.h>
8 #include <stdlib.h>
9 #ifdef HAVE_SYS_FILE_H
10 # include <sys/file.h>
11 #endif
12 #include <string.h>
13 #include <sys/stat.h>
14 #include <sys/time.h>
15 #include <sys/types.h>
16 #include <unistd.h>
17 #include <utime.h>
18 #include <ctype.h>
19 #include "windef.h"
20 #include "winbase.h"
21 #include "winuser.h" /* SW_NORMAL */
22 #include "wine/winbase16.h"
23 #include "winerror.h"
24 #include "drive.h"
25 #include "file.h"
26 #include "heap.h"
27 #include "msdos.h"
28 #include "ldt.h"
29 #include "task.h"
30 #include "options.h"
31 #include "miscemu.h"
32 #include "dosexe.h" /* for the MZ_SUPPORTED define */
33 #include "module.h"
34 #include "debugtools.h"
35 #include "console.h"
37 DEFAULT_DEBUG_CHANNEL(int21)
38 #if defined(__svr4__) || defined(_SCO_DS)
39 /* SVR4 DOESNT do locking the same way must implement properly */
40 #define LOCK_EX 0
41 #define LOCK_SH 1
42 #define LOCK_NB 8
43 #endif
46 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
48 /* Define the drive parameter block, as used by int21/1F
49 * and int21/32. This table can be accessed through the
50 * global 'dpb' pointer, which points into the local dos
51 * heap.
53 struct DPB
55 BYTE drive_num; /* 0=A, etc. */
56 BYTE unit_num; /* Drive's unit number (?) */
57 WORD sector_size; /* Sector size in bytes */
58 BYTE high_sector; /* Highest sector in a cluster */
59 BYTE shift; /* Shift count (?) */
60 WORD reserved; /* Number of reserved sectors at start */
61 BYTE num_FAT; /* Number of FATs */
62 WORD dir_entries; /* Number of root dir entries */
63 WORD first_data; /* First data sector */
64 WORD high_cluster; /* Highest cluster number */
65 WORD sectors_in_FAT; /* Number of sectors per FAT */
66 WORD start_dir; /* Starting sector of first dir */
67 DWORD driver_head; /* Address of device driver header (?) */
68 BYTE media_ID; /* Media ID */
69 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
70 DWORD next; /* Pointer to next DPB in list */
71 WORD free_search; /* Free cluster search start */
72 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
75 WORD CodePage = 437;
76 DWORD dpbsegptr;
78 struct DosHeap {
79 BYTE InDosFlag;
80 BYTE mediaID;
81 BYTE biosdate[8];
82 struct DPB dpb;
83 BYTE DummyDBCSLeadTable[6];
85 static struct DosHeap *heap;
86 static WORD DosHeapHandle;
88 extern char TempDirectory[];
90 static BOOL INT21_CreateHeap(void)
92 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
94 WARN("Out of memory\n");
95 return FALSE;
97 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
98 dpbsegptr = PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
99 heap->InDosFlag = 0;
100 strcpy(heap->biosdate, "01/01/80");
101 memset(heap->DummyDBCSLeadTable, 0, 6);
102 return TRUE;
105 static BYTE *GetCurrentDTA( CONTEXT86 *context )
107 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
109 /* FIXME: This assumes DTA was set correctly! */
110 return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
111 (DWORD)OFFSETOF(pTask->dta) );
115 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
116 /* limited == TRUE is used with INT 0x21/0x440d */
118 if (drive > 1) {
119 setword(data, 512);
120 data[2] = 2;
121 setword(&data[3], 0);
122 data[5] = 2;
123 setword(&data[6], 240);
124 setword(&data[8], 64000);
125 data[0x0a] = 0xf8;
126 setword(&data[0x0b], 40);
127 setword(&data[0x0d], 56);
128 setword(&data[0x0f], 2);
129 setword(&data[0x11], 0);
130 if (!limited) {
131 setword(&data[0x1f], 800);
132 data[0x21] = 5;
133 setword(&data[0x22], 1);
135 } else { /* 1.44mb */
136 setword(data, 512);
137 data[2] = 2;
138 setword(&data[3], 0);
139 data[5] = 2;
140 setword(&data[6], 240);
141 setword(&data[8], 2880);
142 data[0x0a] = 0xf8;
143 setword(&data[0x0b], 6);
144 setword(&data[0x0d], 18);
145 setword(&data[0x0f], 2);
146 setword(&data[0x11], 0);
147 if (!limited) {
148 setword(&data[0x1f], 80);
149 data[0x21] = 7;
150 setword(&data[0x22], 2);
155 static int INT21_GetFreeDiskSpace( CONTEXT86 *context )
157 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
158 char root[] = "A:\\";
160 *root += DOS_GET_DRIVE( DL_reg(context) );
161 if (!GetDiskFreeSpaceA( root, &cluster_sectors, &sector_bytes,
162 &free_clusters, &total_clusters )) return 0;
163 AX_reg(context) = cluster_sectors;
164 BX_reg(context) = free_clusters;
165 CX_reg(context) = sector_bytes;
166 DX_reg(context) = total_clusters;
167 return 1;
170 static int INT21_GetDriveAllocInfo( CONTEXT86 *context )
172 if (!INT21_GetFreeDiskSpace( context )) return 0;
173 if (!heap && !INT21_CreateHeap()) return 0;
174 heap->mediaID = 0xf0;
175 DS_reg(context) = DosHeapHandle;
176 BX_reg(context) = (int)&heap->mediaID - (int)heap;
177 return 1;
180 static void GetDrivePB( CONTEXT86 *context, int drive )
182 if(!DRIVE_IsValid(drive))
184 SetLastError( ERROR_INVALID_DRIVE );
185 AX_reg(context) = 0x00ff;
187 else if (heap || INT21_CreateHeap())
189 FIXME("GetDrivePB not fully implemented.\n");
191 /* FIXME: I have no idea what a lot of this information should
192 * say or whether it even really matters since we're not allowing
193 * direct block access. However, some programs seem to depend on
194 * getting at least _something_ back from here. The 'next' pointer
195 * does worry me, though. Should we have a complete table of
196 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
198 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
199 heap->dpb.sector_size = 512;
200 heap->dpb.high_sector = 1;
201 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
202 heap->dpb.reserved = 0;
203 heap->dpb.num_FAT = 1;
204 heap->dpb.dir_entries = 2;
205 heap->dpb.first_data = 2;
206 heap->dpb.high_cluster = 64000;
207 heap->dpb.sectors_in_FAT = 1;
208 heap->dpb.start_dir = 1;
209 heap->dpb.driver_head = 0;
210 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
211 heap->dpb.access_flag = 0;
212 heap->dpb.next = 0;
213 heap->dpb.free_search = 0;
214 heap->dpb.free_clusters = 0xFFFF; /* unknown */
216 AL_reg(context) = 0x00;
217 DS_reg(context) = SELECTOROF(dpbsegptr);
218 BX_reg(context) = OFFSETOF(dpbsegptr);
223 static void ioctlGetDeviceInfo( CONTEXT86 *context )
225 int curr_drive;
226 const DOS_DEVICE *dev;
228 TRACE("(%d)\n", BX_reg(context));
230 RESET_CFLAG(context);
232 /* DOS device ? */
233 if ((dev = DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context)) )))
235 DX_reg(context) = dev->flags;
236 return;
239 /* it seems to be a file */
240 curr_drive = DRIVE_GetCurrentDrive();
241 DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0);
242 /* no floppy */
243 /* bits 0-5 are current drive
244 * bit 6 - file has NOT been written..FIXME: correct?
245 * bit 8 - generate int24 if no diskspace on write/ read past end of file
246 * bit 11 - media not removable
247 * bit 14 - don't set file date/time on closing
248 * bit 15 - file is remote
252 static BOOL ioctlGenericBlkDevReq( CONTEXT86 *context )
254 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
255 int drive = DOS_GET_DRIVE( BL_reg(context) );
257 if (!DRIVE_IsValid(drive))
259 SetLastError( ERROR_FILE_NOT_FOUND );
260 return TRUE;
263 if (CH_reg(context) != 0x08)
265 INT_BARF( context, 0x21 );
266 return FALSE;
269 switch (CL_reg(context))
271 case 0x4a: /* lock logical volume */
272 TRACE("lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
273 break;
275 case 0x60: /* get device parameters */
276 /* used by w4wgrp's winfile */
277 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
278 dataptr[0] = 0x04;
279 dataptr[6] = 0; /* media type */
280 if (drive > 1)
282 dataptr[1] = 0x05; /* fixed disk */
283 setword(&dataptr[2], 0x01); /* non removable */
284 setword(&dataptr[4], 0x300); /* # of cylinders */
286 else
288 dataptr[1] = 0x07; /* block dev, floppy */
289 setword(&dataptr[2], 0x02); /* removable */
290 setword(&dataptr[4], 80); /* # of cylinders */
292 CreateBPB(drive, &dataptr[7], TRUE);
293 RESET_CFLAG(context);
294 break;
296 case 0x41: /* write logical device track */
297 case 0x61: /* read logical device track */
299 BYTE drive = BL_reg(context) ?
300 BL_reg(context) : DRIVE_GetCurrentDrive();
301 WORD head = *(WORD *)dataptr+1;
302 WORD cyl = *(WORD *)dataptr+3;
303 WORD sect = *(WORD *)dataptr+5;
304 WORD nrsect = *(WORD *)dataptr+7;
305 BYTE *data = (BYTE *)dataptr+9;
306 int (*raw_func)(BYTE, DWORD, DWORD, BYTE *, BOOL);
308 raw_func = (CL_reg(context) == 0x41) ?
309 DRIVE_RawWrite : DRIVE_RawRead;
311 if (raw_func(drive, head*cyl*sect, nrsect, data, FALSE))
312 RESET_CFLAG(context);
313 else
315 AX_reg(context) = 0x1e; /* read fault */
316 SET_CFLAG(context);
319 break;
320 case 0x66:/* get disk serial number */
322 char label[12],fsname[9],path[4];
323 DWORD serial;
325 strcpy(path,"x:\\");path[0]=drive+'A';
326 GetVolumeInformationA(
327 path,label,12,&serial,NULL,NULL,fsname,9
329 *(WORD*)dataptr = 0;
330 memcpy(dataptr+2,&serial,4);
331 memcpy(dataptr+6,label ,11);
332 memcpy(dataptr+17,fsname,8);
334 break;
336 case 0x6a:
337 TRACE("logical volume %d unlocked.\n",drive);
338 break;
340 case 0x6f:
341 memset(dataptr+1, '\0', dataptr[0]-1);
342 dataptr[1] = dataptr[0];
343 dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
344 dataptr[3] = 0xFF; /* no physical drive */
345 break;
347 case 0x72:
348 /* Trail on error implementation */
349 AX_reg(context) = GetDriveType16(BL_reg(context)) == DRIVE_CANNOTDETERMINE ? 0x0f : 0x01;
350 SET_CFLAG(context); /* Seems to be set all the time */
351 break;
353 default:
354 INT_BARF( context, 0x21 );
356 return FALSE;
359 static void INT21_ParseFileNameIntoFCB( CONTEXT86 *context )
361 char *filename =
362 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context) );
363 char *fcb =
364 CTX_SEG_OFF_TO_LIN(context, ES_reg(context), EDI_reg(context) );
365 char *buffer, *s, *d;
367 AL_reg(context) = 0xff; /* failed */
369 TRACE("filename: '%s'\n", filename);
371 buffer = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + 1);
373 s = filename;
374 d = buffer;
375 while (*s)
377 if ((*s != ' ') && (*s != '\r') && (*s != '\n'))
378 *d++ = *s++;
379 else
380 break;
383 *d = '\0';
384 DOSFS_ToDosFCBFormat(buffer, fcb + 1);
385 *fcb = 0;
386 TRACE("FCB: '%s'\n", ((CHAR *)fcb + 1));
388 HeapFree( GetProcessHeap(), 0, buffer);
390 AL_reg(context) =
391 ((strchr(filename, '*')) || (strchr(filename, '$'))) != 0;
393 /* point DS:SI to first unparsed character */
394 SI_reg(context) += (int)s - (int)filename;
397 static void INT21_GetSystemDate( CONTEXT86 *context )
399 SYSTEMTIME systime;
400 GetLocalTime( &systime );
401 CX_reg(context) = systime.wYear;
402 DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
403 AX_reg(context) = systime.wDayOfWeek;
406 static void INT21_GetSystemTime( CONTEXT86 *context )
408 SYSTEMTIME systime;
409 GetLocalTime( &systime );
410 CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
411 DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
414 /* Many calls translate a drive argument like this:
415 drive number (00h = default, 01h = A:, etc)
417 static char drivestring[]="default";
419 char *INT21_DriveName(int drive)
422 if(drive >0)
424 drivestring[0]= (unsigned char)drive + '@';
425 drivestring[1]=':';
426 drivestring[2]=0;
428 return drivestring;
430 static BOOL INT21_CreateFile( CONTEXT86 *context )
432 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
433 EDX_reg(context) ), CX_reg(context) );
434 return (AX_reg(context) == (WORD)HFILE_ERROR16);
437 static HFILE16 _lcreat16_uniq( LPCSTR path, INT attr )
439 /* Mask off all flags not explicitly allowed by the doc */
440 attr &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM;
441 return FILE_AllocDosHandle( CreateFileA( path, GENERIC_READ | GENERIC_WRITE,
442 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
443 CREATE_NEW, attr, -1 ));
446 static void OpenExistingFile( CONTEXT86 *context )
448 AX_reg(context) = _lopen16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
449 AL_reg(context) );
450 if (AX_reg(context) == (WORD)HFILE_ERROR16)
452 AX_reg(context) = GetLastError();
453 SET_CFLAG(context);
457 static BOOL INT21_ExtendedOpenCreateFile(CONTEXT86 *context )
459 BOOL bExtendedError = FALSE;
460 BYTE action = DL_reg(context);
462 /* Shuffle arguments to call OpenExistingFile */
463 AL_reg(context) = BL_reg(context);
464 DX_reg(context) = SI_reg(context);
465 /* BX,CX and DX should be preserved */
466 OpenExistingFile(context);
468 if ((EFL_reg(context) & 0x0001) == 0) /* File exists */
470 UINT16 uReturnCX = 0;
472 /* Now decide what do do */
474 if ((action & 0x07) == 0)
476 _lclose16( AX_reg(context) );
477 AX_reg(context) = 0x0050; /*File exists*/
478 SET_CFLAG(context);
479 WARN("extended open/create: failed because file exists \n");
481 else if ((action & 0x07) == 2)
483 /* Truncate it, but first check if opened for write */
484 if ((BL_reg(context) & 0x0007)== 0)
486 _lclose16( AX_reg(context) );
487 WARN("extended open/create: failed, trunc on ro file\n");
488 AX_reg(context) = 0x000C; /*Access code invalid*/
489 SET_CFLAG(context);
491 else
493 TRACE("extended open/create: Closing before truncate\n");
494 if (_lclose16( AX_reg(context) ))
496 WARN("extended open/create: close before trunc failed\n");
497 AX_reg(context) = 0x0019; /*Seek Error*/
498 CX_reg(context) = 0;
499 SET_CFLAG(context);
501 /* Shuffle arguments to call CreateFile */
503 TRACE("extended open/create: Truncating\n");
504 AL_reg(context) = BL_reg(context);
505 /* CX is still the same */
506 DX_reg(context) = SI_reg(context);
507 bExtendedError = INT21_CreateFile(context);
509 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
511 WARN("extended open/create: trunc failed\n");
512 return bExtendedError;
514 uReturnCX = 0x3;
517 else uReturnCX = 0x1;
519 CX_reg(context) = uReturnCX;
521 else /* file does not exist */
523 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
524 if ((action & 0xF0)== 0)
526 CX_reg(context) = 0;
527 SET_CFLAG(context);
528 WARN("extended open/create: failed, file dosen't exist\n");
530 else
532 /* Shuffle arguments to call CreateFile */
533 TRACE("extended open/create: Creating\n");
534 AL_reg(context) = BL_reg(context);
535 /* CX should still be the same */
536 DX_reg(context) = SI_reg(context);
537 bExtendedError = INT21_CreateFile(context);
538 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
540 WARN("extended open/create: create failed\n");
541 return bExtendedError;
543 CX_reg(context) = 2;
547 return bExtendedError;
551 static BOOL INT21_ChangeDir( CONTEXT86 *context )
553 int drive;
554 char *dirname = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));
556 TRACE("changedir %s\n", dirname);
557 if (dirname[0] && (dirname[1] == ':'))
559 drive = toupper(dirname[0]) - 'A';
560 dirname += 2;
562 else drive = DRIVE_GetCurrentDrive();
563 return DRIVE_Chdir( drive, dirname );
567 static int INT21_FindFirst( CONTEXT86 *context )
569 char *p;
570 const char *path;
571 DOS_FULL_NAME full_name;
572 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
574 path = (const char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
575 dta->unixPath = NULL;
576 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
578 AX_reg(context) = GetLastError();
579 SET_CFLAG(context);
580 return 0;
582 dta->unixPath = HEAP_strdupA( GetProcessHeap(), 0, full_name.long_name );
583 p = strrchr( dta->unixPath, '/' );
584 *p = '\0';
586 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
587 * (doesn't matter as it is set below anyway)
589 if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
591 HeapFree( GetProcessHeap(), 0, dta->unixPath );
592 dta->unixPath = NULL;
593 SetLastError( ERROR_FILE_NOT_FOUND );
594 AX_reg(context) = ERROR_FILE_NOT_FOUND;
595 SET_CFLAG(context);
596 return 0;
598 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
599 : DRIVE_GetCurrentDrive();
600 dta->count = 0;
601 dta->search_attr = CL_reg(context);
602 return 1;
606 static int INT21_FindNext( CONTEXT86 *context )
608 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
609 WIN32_FIND_DATAA entry;
610 int count;
612 if (!dta->unixPath) return 0;
613 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
614 dta->search_attr, dta->count, &entry )))
616 HeapFree( GetProcessHeap(), 0, dta->unixPath );
617 dta->unixPath = NULL;
618 return 0;
620 if ((int)dta->count + count > 0xffff)
622 WARN("Too many directory entries in %s\n", dta->unixPath );
623 HeapFree( GetProcessHeap(), 0, dta->unixPath );
624 dta->unixPath = NULL;
625 return 0;
627 dta->count += count;
628 dta->fileattr = entry.dwFileAttributes;
629 dta->filesize = entry.nFileSizeLow;
630 FileTimeToDosDateTime( &entry.ftLastWriteTime,
631 &dta->filedate, &dta->filetime );
632 strcpy( dta->filename, entry.cAlternateFileName );
633 if (!memchr(dta->mask,'?',11)) {
634 /* wildcardless search, release resources in case no findnext will
635 * be issued, and as a workaround in case file creation messes up
636 * findnext, as sometimes happens with pkunzip */
637 HeapFree( GetProcessHeap(), 0, dta->unixPath );
638 dta->unixPath = NULL;
640 return 1;
644 static BOOL INT21_CreateTempFile( CONTEXT86 *context )
646 static int counter = 0;
647 char *name = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context) );
648 char *p = name + strlen(name);
650 /* despite what Ralf Brown says, some programs seem to call without
651 * ending backslash (DOS accepts that, so we accept it too) */
652 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
654 for (;;)
656 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
657 counter = (counter + 1) % 1000;
659 if ((AX_reg(context) = _lcreat16_uniq( name, 0 )) != (WORD)HFILE_ERROR16)
661 TRACE("created %s\n", name );
662 return TRUE;
664 if (GetLastError() != ERROR_FILE_EXISTS) return FALSE;
669 static BOOL INT21_GetCurrentDirectory( CONTEXT86 *context )
671 int drive = DOS_GET_DRIVE( DL_reg(context) );
672 char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context) );
674 if (!DRIVE_IsValid(drive))
676 SetLastError( ERROR_INVALID_DRIVE );
677 return FALSE;
679 lstrcpynA( ptr, DRIVE_GetDosCwd(drive), 64 );
680 AX_reg(context) = 0x0100; /* success return code */
681 return TRUE;
685 static void INT21_GetDBCSLeadTable( CONTEXT86 *context )
687 if (heap || INT21_CreateHeap())
688 { /* return an empty table just as DOS 4.0+ does */
689 DS_reg(context) = DosHeapHandle;
690 SI_reg(context) = (int)&heap->DummyDBCSLeadTable - (int)heap;
692 else
694 AX_reg(context) = 0x1; /* error */
695 SET_CFLAG(context);
700 static int INT21_GetDiskSerialNumber( CONTEXT86 *context )
702 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
703 int drive = DOS_GET_DRIVE( BL_reg(context) );
705 if (!DRIVE_IsValid(drive))
707 SetLastError( ERROR_INVALID_DRIVE );
708 return 0;
711 *(WORD *)dataptr = 0;
712 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
713 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
714 strncpy(dataptr + 0x11, "FAT16 ", 8);
715 return 1;
719 static int INT21_SetDiskSerialNumber( CONTEXT86 *context )
721 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
722 int drive = DOS_GET_DRIVE( BL_reg(context) );
724 if (!DRIVE_IsValid(drive))
726 SetLastError( ERROR_INVALID_DRIVE );
727 return 0;
730 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
731 return 1;
735 /* microsoft's programmers should be shot for using CP/M style int21
736 calls in Windows for Workgroup's winfile.exe */
738 static int INT21_FindFirstFCB( CONTEXT86 *context )
740 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
741 FINDFILE_FCB *pFCB;
742 LPCSTR root, cwd;
743 int drive;
745 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
746 else pFCB = (FINDFILE_FCB *)fcb;
747 drive = DOS_GET_DRIVE( pFCB->drive );
748 if (!DRIVE_IsValid( drive )) return 0;
749 root = DRIVE_GetRoot( drive );
750 cwd = DRIVE_GetUnixCwd( drive );
751 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
752 strlen(root)+strlen(cwd)+2 );
753 if (!pFCB->unixPath) return 0;
754 strcpy( pFCB->unixPath, root );
755 strcat( pFCB->unixPath, "/" );
756 strcat( pFCB->unixPath, cwd );
757 pFCB->count = 0;
758 return 1;
762 static int INT21_FindNextFCB( CONTEXT86 *context )
764 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
765 FINDFILE_FCB *pFCB;
766 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA(context);
767 WIN32_FIND_DATAA entry;
768 BYTE attr;
769 int count;
771 if (*fcb == 0xff) /* extended FCB ? */
773 attr = fcb[6];
774 pFCB = (FINDFILE_FCB *)(fcb + 7);
776 else
778 attr = 0;
779 pFCB = (FINDFILE_FCB *)fcb;
782 if (!pFCB->unixPath) return 0;
783 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
784 DOS_GET_DRIVE( pFCB->drive ), attr,
785 pFCB->count, &entry )))
787 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
788 pFCB->unixPath = NULL;
789 return 0;
791 pFCB->count += count;
793 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
794 *(BYTE *)pResult = 0xff;
795 (BYTE *)pResult +=6; /* leave reserved field behind */
796 *(BYTE *)pResult = entry.dwFileAttributes;
797 ((BYTE *)pResult)++;
799 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
800 ((BYTE *)pResult)++;
801 pResult->fileattr = entry.dwFileAttributes;
802 pResult->cluster = 0; /* what else? */
803 pResult->filesize = entry.nFileSizeLow;
804 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
805 FileTimeToDosDateTime( &entry.ftLastWriteTime,
806 &pResult->filedate, &pResult->filetime );
808 /* Convert file name to FCB format */
810 memset( pResult->filename, ' ', sizeof(pResult->filename) );
811 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
812 else if (!strcmp( entry.cAlternateFileName, ".." ))
813 pResult->filename[0] = pResult->filename[1] = '.';
814 else
816 char *p = strrchr( entry.cAlternateFileName, '.' );
817 if (p && p[1] && (p != entry.cAlternateFileName))
819 memcpy( pResult->filename, entry.cAlternateFileName,
820 MIN( (p - entry.cAlternateFileName), 8 ) );
821 memcpy( pResult->filename + 8, p + 1, MIN( strlen(p), 3 ) );
823 else
824 memcpy( pResult->filename, entry.cAlternateFileName,
825 MIN( strlen(entry.cAlternateFileName), 8 ) );
827 return 1;
831 static void DeleteFileFCB( CONTEXT86 *context )
833 FIXME("(%p): stub\n", context);
836 static void RenameFileFCB( CONTEXT86 *context )
838 FIXME("(%p): stub\n", context);
843 static void fLock( CONTEXT86 * context )
846 switch ( AX_reg(context) & 0xff )
848 case 0x00: /* LOCK */
849 TRACE("lock 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 (!LockFile(FILE_GetHandle(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) = GetLastError();
857 SET_CFLAG(context);
859 break;
861 case 0x01: /* UNLOCK */
862 TRACE("unlock handle %d offset %ld length %ld\n",
863 BX_reg(context),
864 MAKELONG(DX_reg(context),CX_reg(context)),
865 MAKELONG(DI_reg(context),SI_reg(context))) ;
866 if (!UnlockFile(FILE_GetHandle(BX_reg(context)),
867 MAKELONG(DX_reg(context),CX_reg(context)), 0,
868 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
869 AX_reg(context) = GetLastError();
870 SET_CFLAG(context);
872 return;
873 default:
874 AX_reg(context) = 0x0001;
875 SET_CFLAG(context);
876 return;
880 static BOOL
881 INT21_networkfunc (CONTEXT86 *context)
883 switch (AL_reg(context)) {
884 case 0x00: /* Get machine name. */
886 char *dst = CTX_SEG_OFF_TO_LIN (context,DS_reg(context),EDX_reg(context));
887 TRACE("getting machine name to %p\n", dst);
888 if (gethostname (dst, 15))
890 WARN("failed!\n");
891 SetLastError( ER_NoNetwork );
892 return TRUE;
893 } else {
894 int len = strlen (dst);
895 while (len < 15)
896 dst[len++] = ' ';
897 dst[15] = 0;
898 CH_reg(context) = 1; /* Valid */
899 CL_reg(context) = 1; /* NETbios number??? */
900 TRACE("returning %s\n", debugstr_an (dst, 16));
901 return FALSE;
905 default:
906 SetLastError( ER_NoNetwork );
907 return TRUE;
911 static void INT21_SetCurrentPSP(WORD psp)
913 #ifdef MZ_SUPPORTED
914 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
915 NE_MODULE *pModule = pTask ? NE_GetPtr( pTask->hModule ) : NULL;
917 GlobalUnlock16( GetCurrentTask() );
918 if (pModule->lpDosTask)
919 pModule->lpDosTask->psp_seg = psp;
920 else
921 #endif
922 ERR("Cannot change PSP for non-DOS task!\n");
925 static WORD INT21_GetCurrentPSP()
927 #ifdef MZ_SUPPORTED
928 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
929 NE_MODULE *pModule = pTask ? NE_GetPtr( pTask->hModule ) : NULL;
931 GlobalUnlock16( GetCurrentTask() );
932 if (pModule->lpDosTask)
933 return pModule->lpDosTask->psp_seg;
934 else
935 #endif
936 return GetCurrentPDB16();
940 /***********************************************************************
941 * INT21_GetExtendedError
943 static void INT21_GetExtendedError( CONTEXT86 *context )
945 BYTE class, action, locus;
946 WORD error = GetLastError();
948 switch(error)
950 case ERROR_SUCCESS:
951 class = action = locus = 0;
952 break;
953 case ERROR_DIR_NOT_EMPTY:
954 class = EC_Exists;
955 action = SA_Ignore;
956 locus = EL_Disk;
957 break;
958 case ERROR_ACCESS_DENIED:
959 class = EC_AccessDenied;
960 action = SA_Abort;
961 locus = EL_Disk;
962 break;
963 case ERROR_CANNOT_MAKE:
964 class = EC_AccessDenied;
965 action = SA_Abort;
966 locus = EL_Unknown;
967 break;
968 case ERROR_DISK_FULL:
969 case ERROR_HANDLE_DISK_FULL:
970 class = EC_MediaError;
971 action = SA_Abort;
972 locus = EL_Disk;
973 break;
974 case ERROR_FILE_EXISTS:
975 case ERROR_ALREADY_EXISTS:
976 class = EC_Exists;
977 action = SA_Abort;
978 locus = EL_Disk;
979 break;
980 case ERROR_FILE_NOT_FOUND:
981 class = EC_NotFound;
982 action = SA_Abort;
983 locus = EL_Disk;
984 break;
985 case ER_GeneralFailure:
986 class = EC_SystemFailure;
987 action = SA_Abort;
988 locus = EL_Unknown;
989 break;
990 case ERROR_INVALID_DRIVE:
991 class = EC_MediaError;
992 action = SA_Abort;
993 locus = EL_Disk;
994 break;
995 case ERROR_INVALID_HANDLE:
996 class = EC_ProgramError;
997 action = SA_Abort;
998 locus = EL_Disk;
999 break;
1000 case ERROR_LOCK_VIOLATION:
1001 class = EC_AccessDenied;
1002 action = SA_Abort;
1003 locus = EL_Disk;
1004 break;
1005 case ERROR_NO_MORE_FILES:
1006 class = EC_MediaError;
1007 action = SA_Abort;
1008 locus = EL_Disk;
1009 break;
1010 case ER_NoNetwork:
1011 class = EC_NotFound;
1012 action = SA_Abort;
1013 locus = EL_Network;
1014 break;
1015 case ERROR_NOT_ENOUGH_MEMORY:
1016 class = EC_OutOfResource;
1017 action = SA_Abort;
1018 locus = EL_Memory;
1019 break;
1020 case ERROR_PATH_NOT_FOUND:
1021 class = EC_NotFound;
1022 action = SA_Abort;
1023 locus = EL_Disk;
1024 break;
1025 case ERROR_SEEK:
1026 class = EC_NotFound;
1027 action = SA_Ignore;
1028 locus = EL_Disk;
1029 break;
1030 case ERROR_SHARING_VIOLATION:
1031 class = EC_Temporary;
1032 action = SA_Retry;
1033 locus = EL_Disk;
1034 break;
1035 case ERROR_TOO_MANY_OPEN_FILES:
1036 class = EC_ProgramError;
1037 action = SA_Abort;
1038 locus = EL_Disk;
1039 break;
1040 default:
1041 FIXME("Unknown error %d\n", error );
1042 class = EC_SystemFailure;
1043 action = SA_Abort;
1044 locus = EL_Unknown;
1045 break;
1047 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1048 error, class, action, locus );
1049 AX_reg(context) = error;
1050 BH_reg(context) = class;
1051 BL_reg(context) = action;
1052 CH_reg(context) = locus;
1055 /***********************************************************************
1056 * DOS3Call (KERNEL.102)
1058 void WINAPI DOS3Call( CONTEXT86 *context )
1060 BOOL bSetDOSExtendedError = FALSE;
1063 TRACE("AX=%04x BX=%04x CX=%04x DX=%04x "
1064 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1065 AX_reg(context), BX_reg(context), CX_reg(context), DX_reg(context),
1066 SI_reg(context), DI_reg(context),
1067 (WORD)DS_reg(context), (WORD)ES_reg(context),
1068 EFL_reg(context) );
1071 if (AH_reg(context) == 0x59) /* Get extended error info */
1073 INT21_GetExtendedError( context );
1074 return;
1077 if (AH_reg(context) == 0x0C) /* Flush buffer and read standard input */
1079 TRACE("FLUSH BUFFER AND READ STANDARD INPUT\n");
1080 /* no flush here yet */
1081 AH_reg(context) = AL_reg(context);
1084 if (AH_reg(context)>=0x2f) {
1085 /* extended error is used by (at least) functions 0x2f to 0x62 */
1086 SetLastError(0);
1088 RESET_CFLAG(context); /* Not sure if this is a good idea */
1090 switch(AH_reg(context))
1092 case 0x03: /* READ CHARACTER FROM STDAUX */
1093 case 0x04: /* WRITE CHARACTER TO STDAUX */
1094 case 0x05: /* WRITE CHARACTER TO PRINTER */
1095 case 0x0f: /* OPEN FILE USING FCB */
1096 case 0x10: /* CLOSE FILE USING FCB */
1097 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1098 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1099 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1100 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1101 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1102 case 0x23: /* GET FILE SIZE FOR FCB */
1103 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1104 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1105 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1106 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1107 INT_BARF( context, 0x21 );
1108 break;
1110 case 0x00: /* TERMINATE PROGRAM */
1111 TRACE("TERMINATE PROGRAM\n");
1112 ExitProcess( 0 );
1113 break;
1115 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1116 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
1117 AL_reg(context) = CONSOLE_GetCharacter();
1118 /* FIXME: no echo */
1119 break;
1121 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1122 TRACE("Write Character to Standard Output\n");
1123 CONSOLE_Write(DL_reg(context), 0, 0, 0);
1124 break;
1126 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1127 if (DL_reg(context) == 0xff) {
1128 static char scan = 0;
1129 TRACE("Direct Console Input\n");
1130 if (scan) {
1131 /* return pending scancode */
1132 AL_reg(context) = scan;
1133 EFL_reg(context) &= ~0x40; /* clear ZF */
1134 scan = 0;
1135 } else {
1136 char ascii;
1137 if (CONSOLE_CheckForKeystroke(&scan,&ascii)) {
1138 CONSOLE_GetKeystroke(&scan,&ascii);
1139 /* return ASCII code */
1140 AL_reg(context) = ascii;
1141 EFL_reg(context) &= ~0x40; /* clear ZF */
1142 /* return scan code on next call only if ascii==0 */
1143 if (ascii) scan = 0;
1144 } else {
1145 /* nothing pending, clear everything */
1146 AL_reg(context) = 0;
1147 EFL_reg(context) |= 0x40; /* set ZF */
1148 scan = 0; /* just in case */
1151 } else {
1152 TRACE("Direct Console Output\n");
1153 CONSOLE_Write(DL_reg(context), 0, 0, 0);
1155 break;
1157 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1158 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1159 AL_reg(context) = CONSOLE_GetCharacter();
1160 break;
1162 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1163 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
1164 AL_reg(context) = CONSOLE_GetCharacter();
1165 break;
1167 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1168 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1169 DS_reg(context),DX_reg(context) );
1171 LPSTR data = CTX_SEG_OFF_TO_LIN(context,DS_reg(context),EDX_reg(context));
1172 LPSTR p = data;
1173 /* do NOT use strchr() to calculate the string length,
1174 as '\0' is valid string content, too !
1175 Maybe we should check for non-'$' strings, but DOS doesn't. */
1176 while (*p != '$') p++;
1177 _hwrite16( 1, data, (int)p - (int)data);
1178 AL_reg(context) = '$'; /* yes, '$' (0x24) gets returned in AL */
1180 break;
1182 case 0x0a: /* BUFFERED INPUT */
1184 char *buffer = ((char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1185 EDX_reg(context) ));
1186 int res;
1188 TRACE("BUFFERED INPUT (size=%d)\n",buffer[0]);
1189 if (buffer[1])
1190 TRACE("Handle old chars in buffer!\n");
1191 res=_lread16( 0, buffer+2,buffer[0]);
1192 buffer[1]=res;
1193 if(buffer[res+1] == '\n')
1194 buffer[res+1] = '\r';
1195 break;
1198 case 0x0b: {/* GET STDIN STATUS */
1199 char x1,x2;
1201 if (CONSOLE_CheckForKeystroke(&x1,&x2))
1202 AL_reg(context) = 0xff;
1203 else
1204 AL_reg(context) = 0;
1205 break;
1207 case 0x2e: /* SET VERIFY FLAG */
1208 TRACE("SET VERIFY FLAG ignored\n");
1209 /* we cannot change the behaviour anyway, so just ignore it */
1210 break;
1212 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1213 case 0x1d:
1214 case 0x1e:
1215 case 0x20:
1216 case 0x6b: /* NULL FUNCTION */
1217 AL_reg(context) = 0;
1218 break;
1220 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1221 fLock(context);
1222 break;
1224 case 0x0d: /* DISK BUFFER FLUSH */
1225 TRACE("DISK BUFFER FLUSH ignored\n");
1226 RESET_CFLAG(context); /* dos 6+ only */
1227 break;
1229 case 0x0e: /* SELECT DEFAULT DRIVE */
1230 TRACE("SELECT DEFAULT DRIVE %d\n", DL_reg(context));
1231 DRIVE_SetCurrentDrive( DL_reg(context) );
1232 AL_reg(context) = MAX_DOS_DRIVES;
1233 break;
1235 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1236 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
1237 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1238 if (!INT21_FindFirstFCB(context))
1240 AL_reg(context) = 0xff;
1241 break;
1243 /* else fall through */
1245 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1246 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
1247 break;
1249 case 0x13: /* DELETE FILE USING FCB */
1250 DeleteFileFCB(context);
1251 break;
1253 case 0x17: /* RENAME FILE USING FCB */
1254 RenameFileFCB(context);
1255 break;
1257 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1258 AL_reg(context) = DRIVE_GetCurrentDrive();
1259 break;
1261 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1263 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1264 pTask->dta = PTR_SEG_OFF_TO_SEGPTR(DS_reg(context),DX_reg(context));
1265 TRACE("Set DTA: %08lx\n", pTask->dta);
1267 break;
1269 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1270 DL_reg(context) = 0;
1271 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1272 break;
1274 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1275 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1276 break;
1278 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1279 GetDrivePB(context, DRIVE_GetCurrentDrive());
1280 break;
1282 case 0x25: /* SET INTERRUPT VECTOR */
1283 INT_CtxSetHandler( context, AL_reg(context),
1284 (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1285 DX_reg(context)));
1286 break;
1288 case 0x29: /* PARSE FILENAME INTO FCB */
1289 INT21_ParseFileNameIntoFCB(context);
1290 break;
1292 case 0x2a: /* GET SYSTEM DATE */
1293 INT21_GetSystemDate(context);
1294 break;
1296 case 0x2b: /* SET SYSTEM DATE */
1297 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
1298 DL_reg(context), DH_reg(context), CX_reg(context) );
1299 AL_reg(context) = 0; /* Let's pretend we succeeded */
1300 break;
1302 case 0x2c: /* GET SYSTEM TIME */
1303 INT21_GetSystemTime(context);
1304 break;
1306 case 0x2d: /* SET SYSTEM TIME */
1307 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1308 CH_reg(context), CL_reg(context),
1309 DH_reg(context), DL_reg(context) );
1310 AL_reg(context) = 0; /* Let's pretend we succeeded */
1311 break;
1313 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1314 TRACE("GET DISK TRANSFER AREA ADDRESS\n");
1316 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1317 ES_reg(context) = SELECTOROF( pTask->dta );
1318 BX_reg(context) = OFFSETOF( pTask->dta );
1320 break;
1322 case 0x30: /* GET DOS VERSION */
1323 TRACE("GET DOS VERSION %s requested\n",
1324 (AL_reg(context) == 0x00)?"OEM number":"version flag");
1325 AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
1326 (HIWORD(GetVersion16()) << 8);
1327 #if 0
1328 AH_reg(context) = 0x7;
1329 AL_reg(context) = 0xA;
1330 #endif
1332 BX_reg(context) = 0x00FF; /* 0x123456 is Wine's serial # */
1333 CX_reg(context) = 0x0000;
1334 break;
1336 case 0x31: /* TERMINATE AND STAY RESIDENT */
1337 FIXME("TERMINATE AND STAY RESIDENT stub\n");
1338 break;
1340 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1341 TRACE("GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1342 INT21_DriveName( DL_reg(context)));
1343 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
1344 break;
1346 case 0x33: /* MULTIPLEXED */
1347 switch (AL_reg(context))
1349 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1350 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
1351 DL_reg(context) = DOSCONF_config.brk_flag;
1352 break;
1354 case 0x01: /* SET EXTENDED BREAK STATE */
1355 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
1356 DOSCONF_config.brk_flag = (DL_reg(context) > 0);
1357 break;
1359 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1360 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1361 /* ugly coding in order to stay reentrant */
1362 if (DL_reg(context))
1364 DL_reg(context) = DOSCONF_config.brk_flag;
1365 DOSCONF_config.brk_flag = 1;
1367 else
1369 DL_reg(context) = DOSCONF_config.brk_flag;
1370 DOSCONF_config.brk_flag = 0;
1372 break;
1374 case 0x05: /* GET BOOT DRIVE */
1375 TRACE("GET BOOT DRIVE\n");
1376 DL_reg(context) = 3;
1377 /* c: is Wine's bootdrive (a: is 1)*/
1378 break;
1380 case 0x06: /* GET TRUE VERSION NUMBER */
1381 TRACE("GET TRUE VERSION NUMBER\n");
1382 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1383 (HIWORD(GetVersion16() << 8));
1384 DX_reg(context) = 0x00;
1385 break;
1387 default:
1388 INT_BARF( context, 0x21 );
1389 break;
1391 break;
1393 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1394 TRACE("GET ADDRESS OF INDOS FLAG\n");
1395 if (!heap) INT21_CreateHeap();
1396 ES_reg(context) = DosHeapHandle;
1397 BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1398 break;
1400 case 0x35: /* GET INTERRUPT VECTOR */
1401 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1403 FARPROC16 addr = INT_CtxGetHandler( context, AL_reg(context) );
1404 ES_reg(context) = SELECTOROF(addr);
1405 BX_reg(context) = OFFSETOF(addr);
1407 break;
1409 case 0x36: /* GET FREE DISK SPACE */
1410 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
1411 INT21_DriveName( DL_reg(context)));
1412 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1413 break;
1415 case 0x37:
1417 unsigned char switchchar='/';
1418 switch (AL_reg(context))
1420 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1421 TRACE("SWITCHAR - GET SWITCH CHARACTER\n");
1422 AL_reg(context) = 0x00; /* success*/
1423 DL_reg(context) = switchchar;
1424 break;
1425 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1426 TRACE("SWITCHAR - SET SWITCH CHARACTER\n");
1427 switchchar = DL_reg(context);
1428 AL_reg(context) = 0x00; /* success*/
1429 break;
1430 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1431 INT_BARF( context, 0x21 );
1432 break;
1434 break;
1437 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1438 TRACE("GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1439 AL_reg(context));
1440 AX_reg(context) = 0x02; /* no country support available */
1441 SET_CFLAG(context);
1442 break;
1444 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1445 TRACE("MKDIR %s\n",
1446 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1447 bSetDOSExtendedError = (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1448 EDX_reg(context) ), NULL));
1449 /* FIXME: CreateDirectory's LastErrors will clash with the ones
1450 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
1451 * denied), while CreateDirectory return several ones. remap some of
1452 * them. -Marcus
1454 if (bSetDOSExtendedError) {
1455 switch (GetLastError()) {
1456 case ERROR_ALREADY_EXISTS:
1457 case ERROR_FILENAME_EXCED_RANGE:
1458 case ERROR_DISK_FULL:
1459 SetLastError(ERROR_ACCESS_DENIED);
1460 break;
1461 default: break;
1464 break;
1466 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1467 TRACE("RMDIR %s\n",
1468 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1469 bSetDOSExtendedError = (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1470 EDX_reg(context) )));
1471 break;
1473 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1474 TRACE("CHDIR %s\n",
1475 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1476 bSetDOSExtendedError = !INT21_ChangeDir(context);
1477 break;
1479 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1480 TRACE("CREAT flag 0x%02x %s\n",CX_reg(context),
1481 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1482 bSetDOSExtendedError = INT21_CreateFile( context );
1483 break;
1485 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1486 TRACE("OPEN mode 0x%02x %s\n",AL_reg(context),
1487 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1488 OpenExistingFile(context);
1489 break;
1491 case 0x3e: /* "CLOSE" - CLOSE FILE */
1492 TRACE("CLOSE handle %d\n",BX_reg(context));
1493 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1494 break;
1496 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1497 TRACE("READ from %d to %04lX:%04X for %d byte\n",BX_reg(context),
1498 DS_reg(context),DX_reg(context),CX_reg(context) );
1500 LONG result;
1501 if (ISV86(context))
1502 result = _hread16( BX_reg(context),
1503 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1504 EDX_reg(context) ),
1505 CX_reg(context) );
1506 else
1507 result = WIN16_hread( BX_reg(context),
1508 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1509 EDX_reg(context) ),
1510 CX_reg(context) );
1511 if (result == -1) bSetDOSExtendedError = TRUE;
1512 else AX_reg(context) = (WORD)result;
1514 break;
1516 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1517 TRACE("WRITE from %04lX:%04X to handle %d for %d byte\n",
1518 DS_reg(context),DX_reg(context),BX_reg(context),CX_reg(context) );
1520 LONG result = _hwrite16( BX_reg(context),
1521 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1522 EDX_reg(context) ),
1523 CX_reg(context) );
1524 if (result == -1) bSetDOSExtendedError = TRUE;
1525 else AX_reg(context) = (WORD)result;
1527 break;
1529 case 0x41: /* "UNLINK" - DELETE FILE */
1530 TRACE("UNLINK%s\n",
1531 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1532 bSetDOSExtendedError = (!DeleteFileA( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1533 EDX_reg(context) )));
1534 break;
1536 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1537 TRACE("LSEEK handle %d offset %ld from %s\n",
1538 BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)),
1539 (AL_reg(context)==0)?"start of file":(AL_reg(context)==1)?
1540 "current file position":"end of file");
1542 LONG status = _llseek16( BX_reg(context),
1543 MAKELONG(DX_reg(context),CX_reg(context)),
1544 AL_reg(context) );
1545 if (status == -1) bSetDOSExtendedError = TRUE;
1546 else
1548 AX_reg(context) = LOWORD(status);
1549 DX_reg(context) = HIWORD(status);
1552 break;
1554 case 0x43: /* FILE ATTRIBUTES */
1555 switch (AL_reg(context))
1557 case 0x00:
1558 TRACE("GET FILE ATTRIBUTES for %s\n",
1559 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1560 AX_reg(context) = (WORD)GetFileAttributesA(
1561 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1562 EDX_reg(context)));
1563 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1564 else CX_reg(context) = AX_reg(context);
1565 break;
1567 case 0x01:
1568 TRACE("SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context),
1569 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1570 bSetDOSExtendedError =
1571 (!SetFileAttributesA( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1572 EDX_reg(context)),
1573 CX_reg(context) ));
1574 break;
1575 case 0x02:
1576 TRACE("GET COMPRESSED FILE SIZE for %s stub\n",
1577 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1579 break;
1581 case 0x44: /* IOCTL */
1582 switch (AL_reg(context))
1584 case 0x00:
1585 ioctlGetDeviceInfo(context);
1586 break;
1588 case 0x01:
1589 break;
1590 case 0x02:{
1591 const DOS_DEVICE *dev;
1592 if ((dev = DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context)) )) &&
1593 !strcasecmp( dev->name, "SCSIMGR$" ))
1595 ASPI_DOS_HandleInt(context);
1597 break;
1599 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1600 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));*/
1601 int drive = DOS_GET_DRIVE(BL_reg(context));
1603 FIXME("program tried to write to block device control channel of drive %d:\n",drive);
1604 /* for (i=0;i<CX_reg(context);i++)
1605 fprintf(stdnimp,"%02x ",dataptr[i]);
1606 fprintf(stdnimp,"\n");*/
1607 AX_reg(context)=CX_reg(context);
1608 break;
1610 case 0x08: /* Check if drive is removable. */
1611 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1612 INT21_DriveName( BL_reg(context)));
1613 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1615 case DRIVE_CANNOTDETERMINE:
1616 SetLastError( ERROR_INVALID_DRIVE );
1617 AX_reg(context) = ERROR_INVALID_DRIVE;
1618 SET_CFLAG(context);
1619 break;
1620 case DRIVE_REMOVABLE:
1621 AX_reg(context) = 0; /* removable */
1622 break;
1623 default:
1624 AX_reg(context) = 1; /* not removable */
1625 break;
1627 break;
1629 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1630 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1631 INT21_DriveName( BL_reg(context)));
1632 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1634 case DRIVE_CANNOTDETERMINE:
1635 SetLastError( ERROR_INVALID_DRIVE );
1636 AX_reg(context) = ERROR_INVALID_DRIVE;
1637 SET_CFLAG(context);
1638 break;
1639 case DRIVE_REMOTE:
1640 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1641 break;
1642 default:
1643 DX_reg(context) = 0; /* FIXME: use driver attr here */
1644 break;
1646 break;
1648 case 0x0a: /* check if handle (BX) is remote */
1649 TRACE("IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context));
1650 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1651 * not set on close
1653 DX_reg(context) = 0;
1654 break;
1656 case 0x0b: /* SET SHARING RETRY COUNT */
1657 TRACE("IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1658 CX_reg(context), DX_reg(context));
1659 if (!CX_reg(context))
1661 AX_reg(context) = 1;
1662 SET_CFLAG(context);
1663 break;
1665 DOSMEM_LOL()->sharing_retry_delay = CX_reg(context);
1666 if (!DX_reg(context))
1667 DOSMEM_LOL()->sharing_retry_count = DX_reg(context);
1668 RESET_CFLAG(context);
1669 break;
1671 case 0x0d:
1672 TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1673 INT21_DriveName( BL_reg(context)));
1674 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1675 break;
1677 case 0x0e: /* get logical drive mapping */
1678 TRACE("IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1679 INT21_DriveName( BL_reg(context)));
1680 AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1681 break;
1683 case 0x0F: /* Set logical drive mapping */
1685 int drive;
1686 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1687 INT21_DriveName( BL_reg(context)));
1688 drive = DOS_GET_DRIVE ( BL_reg(context) );
1689 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1691 SET_CFLAG(context);
1692 AX_reg(context) = 0x000F; /* invalid drive */
1694 break;
1697 case 0xe0: /* Sun PC-NFS API */
1698 /* not installed */
1699 break;
1701 default:
1702 INT_BARF( context, 0x21 );
1703 break;
1705 break;
1707 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1709 HANDLE handle;
1710 TRACE("DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context));
1711 if ((bSetDOSExtendedError = !DuplicateHandle( GetCurrentProcess(),
1712 FILE_GetHandle(BX_reg(context)),
1713 GetCurrentProcess(), &handle,
1714 0, TRUE, DUPLICATE_SAME_ACCESS )))
1715 AX_reg(context) = HFILE_ERROR16;
1716 else
1717 AX_reg(context) = FILE_AllocDosHandle(handle);
1718 break;
1721 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1722 TRACE("FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1723 BX_reg(context),CX_reg(context));
1724 bSetDOSExtendedError = (FILE_Dup2( BX_reg(context), CX_reg(context) ) == HFILE_ERROR16);
1725 break;
1727 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1728 TRACE("CWD - GET CURRENT DIRECTORY for drive %s\n",
1729 INT21_DriveName( DL_reg(context)));
1730 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1731 break;
1733 case 0x48: /* ALLOCATE MEMORY */
1734 TRACE("ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context));
1736 LPVOID *mem;
1737 if (ISV86(context))
1739 mem= DOSMEM_GetBlock(0,(DWORD)BX_reg(context)<<4,NULL);
1740 if (mem)
1741 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1743 else
1745 mem = (LPVOID)GlobalDOSAlloc16(BX_reg(context)<<4);
1746 if (mem)
1747 AX_reg(context) = (DWORD)mem&0xffff;
1749 if (!mem)
1751 SET_CFLAG(context);
1752 AX_reg(context) = 0x0008; /* insufficient memory */
1753 BX_reg(context) = DOSMEM_Available(0)>>4;
1756 break;
1758 case 0x49: /* FREE MEMORY */
1759 TRACE("FREE MEMORY segment %04lX\n", ES_reg(context));
1761 BOOL ret;
1762 if (ISV86(context))
1763 ret= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4));
1764 else
1766 ret = !GlobalDOSFree16(ES_reg(context));
1767 /* If we don't reset ES_reg, we will fail in the relay code */
1768 ES_reg(context)=ret;
1770 if (!ret)
1772 TRACE("FREE MEMORY failed\n");
1773 SET_CFLAG(context);
1774 AX_reg(context) = 0x0009; /* memory block address invalid */
1777 break;
1779 case 0x4a: /* RESIZE MEMORY BLOCK */
1780 TRACE("RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context), BX_reg(context));
1781 if (!ISV86(context))
1782 FIXME("RESIZE MEMORY probably insufficient implementation. Expect crash soon\n");
1784 LPVOID *mem = DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4),
1785 BX_reg(context)<<4,NULL);
1786 if (mem)
1787 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1788 else {
1789 SET_CFLAG(context);
1790 AX_reg(context) = 0x0008; /* insufficient memory */
1791 BX_reg(context) = DOSMEM_Available(0)>>4; /* not quite right */
1794 break;
1796 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1797 TRACE("EXEC %s\n",
1798 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context) ));
1799 AX_reg(context) = WinExec16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1800 EDX_reg(context) ),
1801 SW_NORMAL );
1802 if (AX_reg(context) < 32) SET_CFLAG(context);
1803 break;
1805 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1806 TRACE("EXIT with return code %d\n",AL_reg(context));
1807 ExitProcess( AL_reg(context) );
1808 break;
1810 case 0x4d: /* GET RETURN CODE */
1811 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
1812 AX_reg(context) = 0; /* normal exit */
1813 break;
1815 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1816 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
1817 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1818 if (!INT21_FindFirst(context)) break;
1819 /* fall through */
1821 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1822 TRACE("FINDNEXT\n");
1823 if (!INT21_FindNext(context))
1825 SetLastError( ERROR_NO_MORE_FILES );
1826 AX_reg(context) = ERROR_NO_MORE_FILES;
1827 SET_CFLAG(context);
1829 else AX_reg(context) = 0; /* OK */
1830 break;
1831 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1832 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1833 INT21_SetCurrentPSP(BX_reg(context));
1834 break;
1835 case 0x51: /* GET PSP ADDRESS */
1836 TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1837 /* FIXME: should we return the original DOS PSP upon */
1838 /* Windows startup ? */
1839 BX_reg(context) = INT21_GetCurrentPSP();
1840 break;
1841 case 0x62: /* GET PSP ADDRESS */
1842 TRACE("GET CURRENT PSP ADDRESS\n");
1843 /* FIXME: should we return the original DOS PSP upon */
1844 /* Windows startup ? */
1845 BX_reg(context) = INT21_GetCurrentPSP();
1846 break;
1848 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1849 TRACE("SYSVARS - GET LIST OF LISTS\n");
1851 ES_reg(context) = ISV86(context) ? HIWORD(DOS_LOLSeg) : LOWORD(DOS_LOLSeg);
1852 BX_reg(context) = FIELD_OFFSET(DOS_LISTOFLISTS, ptr_first_DPB);
1854 break;
1856 case 0x54: /* Get Verify Flag */
1857 TRACE("Get Verify Flag - Not Supported\n");
1858 AL_reg(context) = 0x00; /* pretend we can tell. 00h = off 01h = on */
1859 break;
1861 case 0x56: /* "RENAME" - RENAME FILE */
1862 TRACE("RENAME %s to %s\n",
1863 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1864 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context)));
1865 bSetDOSExtendedError =
1866 (!MoveFileA( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1867 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context))));
1868 break;
1870 case 0x57: /* FILE DATE AND TIME */
1871 switch (AL_reg(context))
1873 case 0x00: /* Get */
1875 FILETIME filetime;
1876 TRACE("GET FILE DATE AND TIME for handle %d\n",
1877 BX_reg(context));
1878 if (!GetFileTime( FILE_GetHandle(BX_reg(context)), NULL, NULL, &filetime ))
1879 bSetDOSExtendedError = TRUE;
1880 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1881 &CX_reg(context) );
1883 break;
1885 case 0x01: /* Set */
1887 FILETIME filetime;
1888 TRACE("SET FILE DATE AND TIME for handle %d\n",
1889 BX_reg(context));
1890 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1891 &filetime );
1892 bSetDOSExtendedError =
1893 (!SetFileTime( FILE_GetHandle(BX_reg(context)),
1894 NULL, NULL, &filetime ));
1896 break;
1898 break;
1900 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1901 TRACE("GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1902 AL_reg(context));
1903 switch (AL_reg(context))
1905 case 0x00:
1906 AX_reg(context) = 1;
1907 break;
1908 case 0x02:
1909 AX_reg(context) = 0;
1910 break;
1911 case 0x01:
1912 case 0x03:
1913 break;
1915 RESET_CFLAG(context);
1916 break;
1918 case 0x5a: /* CREATE TEMPORARY FILE */
1919 TRACE("CREATE TEMPORARY FILE\n");
1920 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1921 break;
1923 case 0x5b: /* CREATE NEW FILE */
1924 TRACE("CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
1925 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1926 bSetDOSExtendedError = ((AX_reg(context) =
1927 _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1928 CX_reg(context) )) == (WORD)HFILE_ERROR16);
1929 break;
1931 case 0x5d: /* NETWORK */
1932 FIXME("Function 0x%04x not implemented.\n", AX_reg (context));
1933 /* Fix the following while you're at it. */
1934 SetLastError( ER_NoNetwork );
1935 bSetDOSExtendedError = TRUE;
1936 break;
1938 case 0x5e:
1939 bSetDOSExtendedError = INT21_networkfunc (context);
1940 break;
1942 case 0x5f: /* NETWORK */
1943 switch (AL_reg(context))
1945 case 0x07: /* ENABLE DRIVE */
1946 TRACE("ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1947 if (!DRIVE_Enable( DL_reg(context) ))
1949 SetLastError( ERROR_INVALID_DRIVE );
1950 bSetDOSExtendedError = TRUE;
1952 break;
1954 case 0x08: /* DISABLE DRIVE */
1955 TRACE("DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1956 if (!DRIVE_Disable( DL_reg(context) ))
1958 SetLastError( ERROR_INVALID_DRIVE );
1959 bSetDOSExtendedError = TRUE;
1961 break;
1963 default:
1964 /* network software not installed */
1965 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context));
1966 SetLastError( ER_NoNetwork );
1967 bSetDOSExtendedError = TRUE;
1968 break;
1970 break;
1972 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1973 TRACE("TRUENAME %s\n",
1974 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),ESI_reg(context)));
1976 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1977 ESI_reg(context)), 128,
1978 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
1979 EDI_reg(context)),NULL))
1980 bSetDOSExtendedError = TRUE;
1981 else AX_reg(context) = 0;
1983 break;
1985 case 0x61: /* UNUSED */
1986 case 0x63: /* misc. language support */
1987 switch (AL_reg(context)) {
1988 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1989 INT21_GetDBCSLeadTable(context);
1990 break;
1992 break;
1993 case 0x64: /* OS/2 DOS BOX */
1994 INT_BARF( context, 0x21 );
1995 SET_CFLAG(context);
1996 break;
1998 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1999 extern WORD WINE_LanguageId;
2000 BYTE *dataptr=CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context));
2001 TRACE("GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
2002 BX_reg(context), DX_reg(context));
2003 switch (AL_reg(context)) {
2004 case 0x01:
2005 TRACE("\tget general internationalization info\n");
2006 dataptr[0] = 0x1;
2007 *(WORD*)(dataptr+1) = 41;
2008 *(WORD*)(dataptr+3) = WINE_LanguageId;
2009 *(WORD*)(dataptr+5) = CodePage;
2010 *(DWORD*)(dataptr+0x19) = 0; /* FIXME: ptr to case map routine */
2011 break;
2012 case 0x06:
2013 TRACE("\tget pointer to collating sequence table\n");
2014 dataptr[0] = 0x06;
2015 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
2016 CX_reg(context) = 258;/*FIXME: size of table?*/
2017 break;
2018 case 0x20:
2019 TRACE("\tConvert char to uppercase\n");
2020 DL_reg(context) = toupper(DL_reg(context));
2021 break;
2022 case 0x21:
2023 TRACE("\tconvert string to uppercase with length\n");
2024 CharUpperBuffA( (LPSTR)CTX_SEG_OFF_TO_LIN(context,DS_reg(context),EDX_reg(context)),
2025 CX_reg(context) );
2026 break;
2027 case 0x22:
2028 TRACE("\tConvert ASCIIZ string to uppercase\n");
2029 CharUpperA( (LPSTR)CTX_SEG_OFF_TO_LIN(context,DS_reg(context),EDX_reg(context)) );
2030 break;
2031 default:
2032 TRACE("\tunimplemented function %d\n",AL_reg(context));
2033 INT_BARF( context, 0x21 );
2034 SET_CFLAG(context);
2035 break;
2037 break;
2039 case 0x66: /* GLOBAL CODE PAGE TABLE */
2040 switch (AL_reg(context))
2042 case 0x01:
2043 TRACE("GET GLOBAL CODE PAGE TABLE\n");
2044 DX_reg(context) = BX_reg(context) = CodePage;
2045 RESET_CFLAG(context);
2046 break;
2047 case 0x02:
2048 TRACE("SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2049 BX_reg(context),DX_reg(context));
2050 CodePage = BX_reg(context);
2051 RESET_CFLAG(context);
2052 break;
2054 break;
2056 case 0x67: /* SET HANDLE COUNT */
2057 TRACE("SET HANDLE COUNT to %d\n",BX_reg(context) );
2058 SetHandleCount16( BX_reg(context) );
2059 if (GetLastError()) bSetDOSExtendedError = TRUE;
2060 break;
2062 case 0x68: /* "FFLUSH" - COMMIT FILE */
2063 case 0x6a: /* COMMIT FILE */
2064 TRACE("FFLUSH/COMMIT handle %d\n",BX_reg(context));
2065 bSetDOSExtendedError = (!FlushFileBuffers( FILE_GetHandle(BX_reg(context)) ));
2066 break;
2068 case 0x69: /* DISK SERIAL NUMBER */
2069 switch (AL_reg(context))
2071 case 0x00:
2072 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
2073 INT21_DriveName(BL_reg(context)));
2074 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2075 else AX_reg(context) = 0;
2076 break;
2078 case 0x01:
2079 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
2080 INT21_DriveName(BL_reg(context)));
2081 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2082 else AX_reg(context) = 1;
2083 break;
2085 break;
2087 case 0x6C: /* Extended Open/Create*/
2088 TRACE("EXTENDED OPEN/CREATE %s\n",
2089 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDI_reg(context)));
2090 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2091 break;
2093 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2094 if ((GetVersion()&0xC0000004)!=0xC0000004) {
2095 /* not supported on anything but Win95 */
2096 TRACE("LONG FILENAME functions supported only by win95\n");
2097 SET_CFLAG(context);
2098 AL_reg(context) = 0;
2099 } else
2100 switch(AL_reg(context))
2102 case 0x39: /* Create directory */
2103 TRACE("LONG FILENAME - MAKE DIRECTORY %s\n",
2104 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2105 bSetDOSExtendedError = (!CreateDirectoryA(
2106 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2107 EDX_reg(context) ), NULL));
2108 break;
2109 case 0x3a: /* Remove directory */
2110 TRACE("LONG FILENAME - REMOVE DIRECTORY %s\n",
2111 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2112 bSetDOSExtendedError = (!RemoveDirectoryA(
2113 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2114 EDX_reg(context) )));
2115 break;
2116 case 0x43: /* Get/Set file attributes */
2117 TRACE("LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2118 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2119 switch (BL_reg(context))
2121 case 0x00: /* Get file attributes */
2122 TRACE("\tretrieve attributes\n");
2123 CX_reg(context) = (WORD)GetFileAttributesA(
2124 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2125 EDX_reg(context)));
2126 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
2127 break;
2128 case 0x01:
2129 TRACE("\tset attributes 0x%04x\n",CX_reg(context));
2130 bSetDOSExtendedError = (!SetFileAttributesA(
2131 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2132 EDX_reg(context)),
2133 CX_reg(context) ) );
2134 break;
2135 default:
2136 FIXME("Unimplemented long file name function:\n");
2137 INT_BARF( context, 0x21 );
2138 SET_CFLAG(context);
2139 AL_reg(context) = 0;
2140 break;
2142 break;
2143 case 0x47: /* Get current directory */
2144 TRACE(" LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2145 INT21_DriveName(DL_reg(context)));
2146 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
2147 break;
2149 case 0x4e: /* Find first file */
2150 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2151 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2152 /* FIXME: use attributes in CX */
2153 if ((AX_reg(context) = FindFirstFile16(
2154 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
2155 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2156 EDI_reg(context))))
2157 == INVALID_HANDLE_VALUE16)
2158 bSetDOSExtendedError = TRUE;
2159 break;
2160 case 0x4f: /* Find next file */
2161 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2162 BX_reg(context));
2163 if (!FindNextFile16( BX_reg(context),
2164 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2165 EDI_reg(context))))
2166 bSetDOSExtendedError = TRUE;
2167 break;
2168 case 0xa1: /* Find close */
2169 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
2170 BX_reg(context));
2171 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
2172 break;
2173 case 0xa0:
2174 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2175 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2176 break;
2177 case 0x60:
2178 switch(CL_reg(context))
2180 case 0x01: /*Get short filename or path */
2181 if (!GetShortPathNameA
2182 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2183 ESI_reg(context)),
2184 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2185 EDI_reg(context)), 67))
2186 bSetDOSExtendedError = TRUE;
2187 else AX_reg(context) = 0;
2188 break;
2189 case 0x02: /*Get canonical long filename or path */
2190 if (!GetFullPathNameA
2191 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2192 ESI_reg(context)), 128,
2193 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2194 EDI_reg(context)),NULL))
2195 bSetDOSExtendedError = TRUE;
2196 else AX_reg(context) = 0;
2197 break;
2198 default:
2199 FIXME("Unimplemented long file name function:\n");
2200 INT_BARF( context, 0x21 );
2201 SET_CFLAG(context);
2202 AL_reg(context) = 0;
2203 break;
2205 break;
2206 case 0x6c: /* Create or open file */
2207 TRACE("LONG FILENAME - CREATE OR OPEN FILE %s\n",
2208 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context)));
2209 /* translate Dos 7 action to Dos 6 action */
2210 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2211 break;
2213 case 0x3b: /* Change directory */
2214 TRACE("LONG FILENAME - CHANGE DIRECTORY %s\n",
2215 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
2216 if (!SetCurrentDirectoryA(CTX_SEG_OFF_TO_LIN(context,
2217 DS_reg(context),
2218 EDX_reg(context)
2221 SET_CFLAG(context);
2222 AL_reg(context) = GetLastError();
2224 break;
2225 case 0x41: /* Delete file */
2226 TRACE("LONG FILENAME - DELETE FILE %s\n",
2227 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
2228 if (!DeleteFileA(CTX_SEG_OFF_TO_LIN(context,
2229 DS_reg(context),
2230 EDX_reg(context))
2231 )) {
2232 SET_CFLAG(context);
2233 AL_reg(context) = GetLastError();
2235 break;
2236 case 0x56: /* Move (rename) file */
2237 TRACE("LONG FILENAME - RENAME FILE %s to %s stub\n",
2238 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)),
2239 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context), EDI_reg(context)));
2240 default:
2241 FIXME("Unimplemented long file name function:\n");
2242 INT_BARF( context, 0x21 );
2243 SET_CFLAG(context);
2244 AL_reg(context) = 0;
2245 break;
2247 break;
2249 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2250 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2251 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2252 TRACE("windows95 function AX %04x\n",
2253 AX_reg(context));
2254 WARN(" returning unimplemented\n");
2255 SET_CFLAG(context);
2256 AL_reg(context) = 0;
2257 break;
2259 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2260 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2261 break;
2263 default:
2264 INT_BARF( context, 0x21 );
2265 break;
2267 } /* END OF SWITCH */
2269 if( bSetDOSExtendedError ) /* set general error condition */
2271 AX_reg(context) = GetLastError();
2272 SET_CFLAG(context);
2275 if ((EFL_reg(context) & 0x0001))
2276 TRACE("failed, error 0x%04lx\n", GetLastError() );
2278 TRACE("returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2279 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2280 AX_reg(context), BX_reg(context), CX_reg(context),
2281 DX_reg(context), SI_reg(context), DI_reg(context),
2282 (WORD)DS_reg(context), (WORD)ES_reg(context),
2283 EFL_reg(context));
2286 FARPROC16 WINAPI GetSetKernelDOSProc16(FARPROC16 DosProc)
2288 FIXME("(DosProc=0x%08x): stub\n", (UINT)DosProc);
2289 return NULL;