Made the buffer list in the directsound object thread-safe.
[wine/hacks.git] / msdos / int21.c
blobe6833cf87548404b47651dd3fea6900f400c5f61
1 /*
2 * DOS interrupt 21h handler
3 */
5 #include "config.h"
7 #include <time.h>
8 #include <fcntl.h>
9 #include <errno.h>
10 #include <stdlib.h>
11 #ifdef HAVE_SYS_FILE_H
12 # include <sys/file.h>
13 #endif
14 #include <string.h>
15 #include <sys/stat.h>
16 #include <sys/time.h>
17 #include <sys/types.h>
18 #include <unistd.h>
19 #include <utime.h>
20 #include <ctype.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "windef.h"
24 #include "wingdi.h"
25 #include "winuser.h" /* SW_NORMAL */
26 #include "wine/winbase16.h"
27 #include "winerror.h"
28 #include "drive.h"
29 #include "file.h"
30 #include "heap.h"
31 #include "msdos.h"
32 #include "ldt.h"
33 #include "task.h"
34 #include "options.h"
35 #include "miscemu.h"
36 #include "dosexe.h" /* for the MZ_SUPPORTED define */
37 #include "module.h"
38 #include "debugtools.h"
39 #include "console.h"
41 DEFAULT_DEBUG_CHANNEL(int21)
42 #if defined(__svr4__) || defined(_SCO_DS)
43 /* SVR4 DOESNT do locking the same way must implement properly */
44 #define LOCK_EX 0
45 #define LOCK_SH 1
46 #define LOCK_NB 8
47 #endif
50 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
52 /* Define the drive parameter block, as used by int21/1F
53 * and int21/32. This table can be accessed through the
54 * global 'dpb' pointer, which points into the local dos
55 * heap.
57 struct DPB
59 BYTE drive_num; /* 0=A, etc. */
60 BYTE unit_num; /* Drive's unit number (?) */
61 WORD sector_size; /* Sector size in bytes */
62 BYTE high_sector; /* Highest sector in a cluster */
63 BYTE shift; /* Shift count (?) */
64 WORD reserved; /* Number of reserved sectors at start */
65 BYTE num_FAT; /* Number of FATs */
66 WORD dir_entries; /* Number of root dir entries */
67 WORD first_data; /* First data sector */
68 WORD high_cluster; /* Highest cluster number */
69 WORD sectors_in_FAT; /* Number of sectors per FAT */
70 WORD start_dir; /* Starting sector of first dir */
71 DWORD driver_head; /* Address of device driver header (?) */
72 BYTE media_ID; /* Media ID */
73 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
74 DWORD next; /* Pointer to next DPB in list */
75 WORD free_search; /* Free cluster search start */
76 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
79 WORD CodePage = 437;
80 DWORD dpbsegptr;
82 struct DosHeap {
83 BYTE InDosFlag;
84 BYTE mediaID;
85 BYTE biosdate[8];
86 struct DPB dpb;
87 BYTE DummyDBCSLeadTable[6];
89 static struct DosHeap *heap;
90 static WORD DosHeapHandle;
92 extern char TempDirectory[];
94 static BOOL INT21_CreateHeap(void)
96 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
98 WARN("Out of memory\n");
99 return FALSE;
101 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
102 dpbsegptr = PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
103 heap->InDosFlag = 0;
104 strcpy(heap->biosdate, "01/01/80");
105 memset(heap->DummyDBCSLeadTable, 0, 6);
106 return TRUE;
109 static BYTE *GetCurrentDTA( CONTEXT86 *context )
111 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
113 /* FIXME: This assumes DTA was set correctly! */
114 return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
115 (DWORD)OFFSETOF(pTask->dta) );
119 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
120 /* limited == TRUE is used with INT 0x21/0x440d */
122 if (drive > 1) {
123 setword(data, 512);
124 data[2] = 2;
125 setword(&data[3], 0);
126 data[5] = 2;
127 setword(&data[6], 240);
128 setword(&data[8], 64000);
129 data[0x0a] = 0xf8;
130 setword(&data[0x0b], 40);
131 setword(&data[0x0d], 56);
132 setword(&data[0x0f], 2);
133 setword(&data[0x11], 0);
134 if (!limited) {
135 setword(&data[0x1f], 800);
136 data[0x21] = 5;
137 setword(&data[0x22], 1);
139 } else { /* 1.44mb */
140 setword(data, 512);
141 data[2] = 2;
142 setword(&data[3], 0);
143 data[5] = 2;
144 setword(&data[6], 240);
145 setword(&data[8], 2880);
146 data[0x0a] = 0xf8;
147 setword(&data[0x0b], 6);
148 setword(&data[0x0d], 18);
149 setword(&data[0x0f], 2);
150 setword(&data[0x11], 0);
151 if (!limited) {
152 setword(&data[0x1f], 80);
153 data[0x21] = 7;
154 setword(&data[0x22], 2);
159 static int INT21_GetFreeDiskSpace( CONTEXT86 *context )
161 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
162 char root[] = "A:\\";
164 *root += DOS_GET_DRIVE( DL_reg(context) );
165 if (!GetDiskFreeSpaceA( root, &cluster_sectors, &sector_bytes,
166 &free_clusters, &total_clusters )) return 0;
167 AX_reg(context) = cluster_sectors;
168 BX_reg(context) = free_clusters;
169 CX_reg(context) = sector_bytes;
170 DX_reg(context) = total_clusters;
171 return 1;
174 static int INT21_GetDriveAllocInfo( CONTEXT86 *context )
176 if (!INT21_GetFreeDiskSpace( context )) return 0;
177 if (!heap && !INT21_CreateHeap()) return 0;
178 heap->mediaID = 0xf0;
179 DS_reg(context) = DosHeapHandle;
180 BX_reg(context) = (int)&heap->mediaID - (int)heap;
181 return 1;
184 static void GetDrivePB( CONTEXT86 *context, int drive )
186 if(!DRIVE_IsValid(drive))
188 SetLastError( ERROR_INVALID_DRIVE );
189 AX_reg(context) = 0x00ff;
191 else if (heap || INT21_CreateHeap())
193 FIXME("GetDrivePB not fully implemented.\n");
195 /* FIXME: I have no idea what a lot of this information should
196 * say or whether it even really matters since we're not allowing
197 * direct block access. However, some programs seem to depend on
198 * getting at least _something_ back from here. The 'next' pointer
199 * does worry me, though. Should we have a complete table of
200 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
202 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
203 heap->dpb.sector_size = 512;
204 heap->dpb.high_sector = 1;
205 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
206 heap->dpb.reserved = 0;
207 heap->dpb.num_FAT = 1;
208 heap->dpb.dir_entries = 2;
209 heap->dpb.first_data = 2;
210 heap->dpb.high_cluster = 64000;
211 heap->dpb.sectors_in_FAT = 1;
212 heap->dpb.start_dir = 1;
213 heap->dpb.driver_head = 0;
214 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
215 heap->dpb.access_flag = 0;
216 heap->dpb.next = 0;
217 heap->dpb.free_search = 0;
218 heap->dpb.free_clusters = 0xFFFF; /* unknown */
220 AL_reg(context) = 0x00;
221 DS_reg(context) = SELECTOROF(dpbsegptr);
222 BX_reg(context) = OFFSETOF(dpbsegptr);
227 static void ioctlGetDeviceInfo( CONTEXT86 *context )
229 int curr_drive;
230 const DOS_DEVICE *dev;
232 TRACE("(%d)\n", BX_reg(context));
234 RESET_CFLAG(context);
236 /* DOS device ? */
237 if ((dev = DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context)) )))
239 DX_reg(context) = dev->flags;
240 return;
243 /* it seems to be a file */
244 curr_drive = DRIVE_GetCurrentDrive();
245 DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0);
246 /* no floppy */
247 /* bits 0-5 are current drive
248 * bit 6 - file has NOT been written..FIXME: correct?
249 * bit 8 - generate int24 if no diskspace on write/ read past end of file
250 * bit 11 - media not removable
251 * bit 14 - don't set file date/time on closing
252 * bit 15 - file is remote
256 static BOOL ioctlGenericBlkDevReq( CONTEXT86 *context )
258 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
259 int drive = DOS_GET_DRIVE( BL_reg(context) );
261 if (!DRIVE_IsValid(drive))
263 SetLastError( ERROR_FILE_NOT_FOUND );
264 return TRUE;
267 if (CH_reg(context) != 0x08)
269 INT_BARF( context, 0x21 );
270 return FALSE;
273 switch (CL_reg(context))
275 case 0x4a: /* lock logical volume */
276 TRACE("lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
277 break;
279 case 0x60: /* get device parameters */
280 /* used by w4wgrp's winfile */
281 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
282 dataptr[0] = 0x04;
283 dataptr[6] = 0; /* media type */
284 if (drive > 1)
286 dataptr[1] = 0x05; /* fixed disk */
287 setword(&dataptr[2], 0x01); /* non removable */
288 setword(&dataptr[4], 0x300); /* # of cylinders */
290 else
292 dataptr[1] = 0x07; /* block dev, floppy */
293 setword(&dataptr[2], 0x02); /* removable */
294 setword(&dataptr[4], 80); /* # of cylinders */
296 CreateBPB(drive, &dataptr[7], TRUE);
297 RESET_CFLAG(context);
298 break;
300 case 0x41: /* write logical device track */
301 case 0x61: /* read logical device track */
303 BYTE drive = BL_reg(context) ?
304 BL_reg(context) : DRIVE_GetCurrentDrive();
305 WORD head = *(WORD *)dataptr+1;
306 WORD cyl = *(WORD *)dataptr+3;
307 WORD sect = *(WORD *)dataptr+5;
308 WORD nrsect = *(WORD *)dataptr+7;
309 BYTE *data = (BYTE *)dataptr+9;
310 int (*raw_func)(BYTE, DWORD, DWORD, BYTE *, BOOL);
312 raw_func = (CL_reg(context) == 0x41) ?
313 DRIVE_RawWrite : DRIVE_RawRead;
315 if (raw_func(drive, head*cyl*sect, nrsect, data, FALSE))
316 RESET_CFLAG(context);
317 else
319 AX_reg(context) = 0x1e; /* read fault */
320 SET_CFLAG(context);
323 break;
324 case 0x66:/* get disk serial number */
326 char label[12],fsname[9],path[4];
327 DWORD serial;
329 strcpy(path,"x:\\");path[0]=drive+'A';
330 GetVolumeInformationA(
331 path,label,12,&serial,NULL,NULL,fsname,9
333 *(WORD*)dataptr = 0;
334 memcpy(dataptr+2,&serial,4);
335 memcpy(dataptr+6,label ,11);
336 memcpy(dataptr+17,fsname,8);
338 break;
340 case 0x6a:
341 TRACE("logical volume %d unlocked.\n",drive);
342 break;
344 case 0x6f:
345 memset(dataptr+1, '\0', dataptr[0]-1);
346 dataptr[1] = dataptr[0];
347 dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
348 dataptr[3] = 0xFF; /* no physical drive */
349 break;
351 case 0x72:
352 /* Trail on error implementation */
353 AX_reg(context) = GetDriveType16(BL_reg(context)) == DRIVE_CANNOTDETERMINE ? 0x0f : 0x01;
354 SET_CFLAG(context); /* Seems to be set all the time */
355 break;
357 default:
358 INT_BARF( context, 0x21 );
360 return FALSE;
363 static void INT21_ParseFileNameIntoFCB( CONTEXT86 *context )
365 char *filename =
366 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context) );
367 char *fcb =
368 CTX_SEG_OFF_TO_LIN(context, ES_reg(context), EDI_reg(context) );
369 char *buffer, *s, *d;
371 AL_reg(context) = 0xff; /* failed */
373 TRACE("filename: '%s'\n", filename);
375 buffer = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + 1);
377 s = filename;
378 d = buffer;
379 while (*s)
381 if ((*s != ' ') && (*s != '\r') && (*s != '\n'))
382 *d++ = *s++;
383 else
384 break;
387 *d = '\0';
388 DOSFS_ToDosFCBFormat(buffer, fcb + 1);
389 *fcb = 0;
390 TRACE("FCB: '%s'\n", ((CHAR *)fcb + 1));
392 HeapFree( GetProcessHeap(), 0, buffer);
394 AL_reg(context) =
395 ((strchr(filename, '*')) || (strchr(filename, '$'))) != 0;
397 /* point DS:SI to first unparsed character */
398 SI_reg(context) += (int)s - (int)filename;
401 static void INT21_GetSystemDate( CONTEXT86 *context )
403 SYSTEMTIME systime;
404 GetLocalTime( &systime );
405 CX_reg(context) = systime.wYear;
406 DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
407 AX_reg(context) = systime.wDayOfWeek;
410 static void INT21_GetSystemTime( CONTEXT86 *context )
412 SYSTEMTIME systime;
413 GetLocalTime( &systime );
414 CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
415 DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
418 /* Many calls translate a drive argument like this:
419 drive number (00h = default, 01h = A:, etc)
421 static char drivestring[]="default";
423 char *INT21_DriveName(int drive)
426 if(drive >0)
428 drivestring[0]= (unsigned char)drive + '@';
429 drivestring[1]=':';
430 drivestring[2]=0;
432 return drivestring;
434 static BOOL INT21_CreateFile( CONTEXT86 *context )
436 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
437 EDX_reg(context) ), CX_reg(context) );
438 return (AX_reg(context) == (WORD)HFILE_ERROR16);
441 static HFILE16 _lcreat16_uniq( LPCSTR path, INT attr )
443 /* Mask off all flags not explicitly allowed by the doc */
444 attr &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM;
445 return FILE_AllocDosHandle( CreateFileA( path, GENERIC_READ | GENERIC_WRITE,
446 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
447 CREATE_NEW, attr, -1 ));
450 static void OpenExistingFile( CONTEXT86 *context )
452 AX_reg(context) = _lopen16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
453 AL_reg(context) );
454 if (AX_reg(context) == (WORD)HFILE_ERROR16)
456 AX_reg(context) = GetLastError();
457 SET_CFLAG(context);
461 static BOOL INT21_ExtendedOpenCreateFile(CONTEXT86 *context )
463 BOOL bExtendedError = FALSE;
464 BYTE action = DL_reg(context);
466 /* Shuffle arguments to call OpenExistingFile */
467 AL_reg(context) = BL_reg(context);
468 DX_reg(context) = SI_reg(context);
469 /* BX,CX and DX should be preserved */
470 OpenExistingFile(context);
472 if ((EFL_reg(context) & 0x0001) == 0) /* File exists */
474 UINT16 uReturnCX = 0;
476 /* Now decide what do do */
478 if ((action & 0x07) == 0)
480 _lclose16( AX_reg(context) );
481 AX_reg(context) = 0x0050; /*File exists*/
482 SET_CFLAG(context);
483 WARN("extended open/create: failed because file exists \n");
485 else if ((action & 0x07) == 2)
487 /* Truncate it, but first check if opened for write */
488 if ((BL_reg(context) & 0x0007)== 0)
490 _lclose16( AX_reg(context) );
491 WARN("extended open/create: failed, trunc on ro file\n");
492 AX_reg(context) = 0x000C; /*Access code invalid*/
493 SET_CFLAG(context);
495 else
497 TRACE("extended open/create: Closing before truncate\n");
498 if (_lclose16( AX_reg(context) ))
500 WARN("extended open/create: close before trunc failed\n");
501 AX_reg(context) = 0x0019; /*Seek Error*/
502 CX_reg(context) = 0;
503 SET_CFLAG(context);
505 /* Shuffle arguments to call CreateFile */
507 TRACE("extended open/create: Truncating\n");
508 AL_reg(context) = BL_reg(context);
509 /* CX is still the same */
510 DX_reg(context) = SI_reg(context);
511 bExtendedError = INT21_CreateFile(context);
513 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
515 WARN("extended open/create: trunc failed\n");
516 return bExtendedError;
518 uReturnCX = 0x3;
521 else uReturnCX = 0x1;
523 CX_reg(context) = uReturnCX;
525 else /* file does not exist */
527 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
528 if ((action & 0xF0)== 0)
530 CX_reg(context) = 0;
531 SET_CFLAG(context);
532 WARN("extended open/create: failed, file dosen't exist\n");
534 else
536 /* Shuffle arguments to call CreateFile */
537 TRACE("extended open/create: Creating\n");
538 AL_reg(context) = BL_reg(context);
539 /* CX should still be the same */
540 DX_reg(context) = SI_reg(context);
541 bExtendedError = INT21_CreateFile(context);
542 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
544 WARN("extended open/create: create failed\n");
545 return bExtendedError;
547 CX_reg(context) = 2;
551 return bExtendedError;
555 static BOOL INT21_ChangeDir( CONTEXT86 *context )
557 int drive;
558 char *dirname = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));
560 TRACE("changedir %s\n", dirname);
561 if (dirname[0] && (dirname[1] == ':'))
563 drive = toupper(dirname[0]) - 'A';
564 dirname += 2;
566 else drive = DRIVE_GetCurrentDrive();
567 return DRIVE_Chdir( drive, dirname );
571 static int INT21_FindFirst( CONTEXT86 *context )
573 char *p;
574 const char *path;
575 DOS_FULL_NAME full_name;
576 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
578 path = (const char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
579 dta->unixPath = NULL;
580 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
582 AX_reg(context) = GetLastError();
583 SET_CFLAG(context);
584 return 0;
586 dta->unixPath = HEAP_strdupA( GetProcessHeap(), 0, full_name.long_name );
587 p = strrchr( dta->unixPath, '/' );
588 *p = '\0';
590 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
591 * (doesn't matter as it is set below anyway)
593 if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
595 HeapFree( GetProcessHeap(), 0, dta->unixPath );
596 dta->unixPath = NULL;
597 SetLastError( ERROR_FILE_NOT_FOUND );
598 AX_reg(context) = ERROR_FILE_NOT_FOUND;
599 SET_CFLAG(context);
600 return 0;
602 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
603 : DRIVE_GetCurrentDrive();
604 dta->count = 0;
605 dta->search_attr = CL_reg(context);
606 return 1;
610 static int INT21_FindNext( CONTEXT86 *context )
612 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
613 WIN32_FIND_DATAA entry;
614 int count;
616 if (!dta->unixPath) return 0;
617 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
618 dta->search_attr, dta->count, &entry )))
620 HeapFree( GetProcessHeap(), 0, dta->unixPath );
621 dta->unixPath = NULL;
622 return 0;
624 if ((int)dta->count + count > 0xffff)
626 WARN("Too many directory entries in %s\n", dta->unixPath );
627 HeapFree( GetProcessHeap(), 0, dta->unixPath );
628 dta->unixPath = NULL;
629 return 0;
631 dta->count += count;
632 dta->fileattr = entry.dwFileAttributes;
633 dta->filesize = entry.nFileSizeLow;
634 FileTimeToDosDateTime( &entry.ftLastWriteTime,
635 &dta->filedate, &dta->filetime );
636 strcpy( dta->filename, entry.cAlternateFileName );
637 if (!memchr(dta->mask,'?',11)) {
638 /* wildcardless search, release resources in case no findnext will
639 * be issued, and as a workaround in case file creation messes up
640 * findnext, as sometimes happens with pkunzip */
641 HeapFree( GetProcessHeap(), 0, dta->unixPath );
642 dta->unixPath = NULL;
644 return 1;
648 static BOOL INT21_CreateTempFile( CONTEXT86 *context )
650 static int counter = 0;
651 char *name = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context) );
652 char *p = name + strlen(name);
654 /* despite what Ralf Brown says, some programs seem to call without
655 * ending backslash (DOS accepts that, so we accept it too) */
656 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
658 for (;;)
660 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
661 counter = (counter + 1) % 1000;
663 if ((AX_reg(context) = _lcreat16_uniq( name, 0 )) != (WORD)HFILE_ERROR16)
665 TRACE("created %s\n", name );
666 return TRUE;
668 if (GetLastError() != ERROR_FILE_EXISTS) return FALSE;
673 static BOOL INT21_GetCurrentDirectory( CONTEXT86 *context )
675 int drive = DOS_GET_DRIVE( DL_reg(context) );
676 char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context) );
678 if (!DRIVE_IsValid(drive))
680 SetLastError( ERROR_INVALID_DRIVE );
681 return FALSE;
683 lstrcpynA( ptr, DRIVE_GetDosCwd(drive), 64 );
684 AX_reg(context) = 0x0100; /* success return code */
685 return TRUE;
689 static void INT21_GetDBCSLeadTable( CONTEXT86 *context )
691 if (heap || INT21_CreateHeap())
692 { /* return an empty table just as DOS 4.0+ does */
693 DS_reg(context) = DosHeapHandle;
694 SI_reg(context) = (int)&heap->DummyDBCSLeadTable - (int)heap;
696 else
698 AX_reg(context) = 0x1; /* error */
699 SET_CFLAG(context);
704 static int INT21_GetDiskSerialNumber( CONTEXT86 *context )
706 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
707 int drive = DOS_GET_DRIVE( BL_reg(context) );
709 if (!DRIVE_IsValid(drive))
711 SetLastError( ERROR_INVALID_DRIVE );
712 return 0;
715 *(WORD *)dataptr = 0;
716 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
717 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
718 strncpy(dataptr + 0x11, "FAT16 ", 8);
719 return 1;
723 static int INT21_SetDiskSerialNumber( CONTEXT86 *context )
725 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
726 int drive = DOS_GET_DRIVE( BL_reg(context) );
728 if (!DRIVE_IsValid(drive))
730 SetLastError( ERROR_INVALID_DRIVE );
731 return 0;
734 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
735 return 1;
739 /* microsoft's programmers should be shot for using CP/M style int21
740 calls in Windows for Workgroup's winfile.exe */
742 static int INT21_FindFirstFCB( CONTEXT86 *context )
744 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
745 FINDFILE_FCB *pFCB;
746 LPCSTR root, cwd;
747 int drive;
749 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
750 else pFCB = (FINDFILE_FCB *)fcb;
751 drive = DOS_GET_DRIVE( pFCB->drive );
752 if (!DRIVE_IsValid( drive )) return 0;
753 root = DRIVE_GetRoot( drive );
754 cwd = DRIVE_GetUnixCwd( drive );
755 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
756 strlen(root)+strlen(cwd)+2 );
757 if (!pFCB->unixPath) return 0;
758 strcpy( pFCB->unixPath, root );
759 strcat( pFCB->unixPath, "/" );
760 strcat( pFCB->unixPath, cwd );
761 pFCB->count = 0;
762 return 1;
766 static int INT21_FindNextFCB( CONTEXT86 *context )
768 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
769 FINDFILE_FCB *pFCB;
770 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA(context);
771 WIN32_FIND_DATAA entry;
772 BYTE attr;
773 int count;
775 if (*fcb == 0xff) /* extended FCB ? */
777 attr = fcb[6];
778 pFCB = (FINDFILE_FCB *)(fcb + 7);
780 else
782 attr = 0;
783 pFCB = (FINDFILE_FCB *)fcb;
786 if (!pFCB->unixPath) return 0;
787 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
788 DOS_GET_DRIVE( pFCB->drive ), attr,
789 pFCB->count, &entry )))
791 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
792 pFCB->unixPath = NULL;
793 return 0;
795 pFCB->count += count;
797 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
798 *(BYTE *)pResult = 0xff;
799 (BYTE *)pResult +=6; /* leave reserved field behind */
800 *(BYTE *)pResult = entry.dwFileAttributes;
801 ((BYTE *)pResult)++;
803 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
804 ((BYTE *)pResult)++;
805 pResult->fileattr = entry.dwFileAttributes;
806 pResult->cluster = 0; /* what else? */
807 pResult->filesize = entry.nFileSizeLow;
808 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
809 FileTimeToDosDateTime( &entry.ftLastWriteTime,
810 &pResult->filedate, &pResult->filetime );
812 /* Convert file name to FCB format */
814 memset( pResult->filename, ' ', sizeof(pResult->filename) );
815 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
816 else if (!strcmp( entry.cAlternateFileName, ".." ))
817 pResult->filename[0] = pResult->filename[1] = '.';
818 else
820 char *p = strrchr( entry.cAlternateFileName, '.' );
821 if (p && p[1] && (p != entry.cAlternateFileName))
823 memcpy( pResult->filename, entry.cAlternateFileName,
824 MIN( (p - entry.cAlternateFileName), 8 ) );
825 memcpy( pResult->filename + 8, p + 1, MIN( strlen(p), 3 ) );
827 else
828 memcpy( pResult->filename, entry.cAlternateFileName,
829 MIN( strlen(entry.cAlternateFileName), 8 ) );
831 return 1;
835 static void DeleteFileFCB( CONTEXT86 *context )
837 FIXME("(%p): stub\n", context);
840 static void RenameFileFCB( CONTEXT86 *context )
842 FIXME("(%p): stub\n", context);
847 static void fLock( CONTEXT86 * context )
850 switch ( AX_reg(context) & 0xff )
852 case 0x00: /* LOCK */
853 TRACE("lock handle %d offset %ld length %ld\n",
854 BX_reg(context),
855 MAKELONG(DX_reg(context),CX_reg(context)),
856 MAKELONG(DI_reg(context),SI_reg(context))) ;
857 if (!LockFile(FILE_GetHandle(BX_reg(context)),
858 MAKELONG(DX_reg(context),CX_reg(context)), 0,
859 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
860 AX_reg(context) = GetLastError();
861 SET_CFLAG(context);
863 break;
865 case 0x01: /* UNLOCK */
866 TRACE("unlock handle %d offset %ld length %ld\n",
867 BX_reg(context),
868 MAKELONG(DX_reg(context),CX_reg(context)),
869 MAKELONG(DI_reg(context),SI_reg(context))) ;
870 if (!UnlockFile(FILE_GetHandle(BX_reg(context)),
871 MAKELONG(DX_reg(context),CX_reg(context)), 0,
872 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
873 AX_reg(context) = GetLastError();
874 SET_CFLAG(context);
876 return;
877 default:
878 AX_reg(context) = 0x0001;
879 SET_CFLAG(context);
880 return;
884 static BOOL
885 INT21_networkfunc (CONTEXT86 *context)
887 switch (AL_reg(context)) {
888 case 0x00: /* Get machine name. */
890 char *dst = CTX_SEG_OFF_TO_LIN (context,DS_reg(context),EDX_reg(context));
891 TRACE("getting machine name to %p\n", dst);
892 if (gethostname (dst, 15))
894 WARN("failed!\n");
895 SetLastError( ER_NoNetwork );
896 return TRUE;
897 } else {
898 int len = strlen (dst);
899 while (len < 15)
900 dst[len++] = ' ';
901 dst[15] = 0;
902 CH_reg(context) = 1; /* Valid */
903 CL_reg(context) = 1; /* NETbios number??? */
904 TRACE("returning %s\n", debugstr_an (dst, 16));
905 return FALSE;
909 default:
910 SetLastError( ER_NoNetwork );
911 return TRUE;
915 static void INT21_SetCurrentPSP(WORD psp)
917 #ifdef MZ_SUPPORTED
918 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
919 NE_MODULE *pModule = pTask ? NE_GetPtr( pTask->hModule ) : NULL;
921 GlobalUnlock16( GetCurrentTask() );
922 if (pModule->lpDosTask)
923 pModule->lpDosTask->psp_seg = psp;
924 else
925 #endif
926 ERR("Cannot change PSP for non-DOS task!\n");
929 static WORD INT21_GetCurrentPSP()
931 #ifdef MZ_SUPPORTED
932 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
933 NE_MODULE *pModule = pTask ? NE_GetPtr( pTask->hModule ) : NULL;
935 GlobalUnlock16( GetCurrentTask() );
936 if (pModule->lpDosTask)
937 return pModule->lpDosTask->psp_seg;
938 else
939 #endif
940 return GetCurrentPDB16();
944 /***********************************************************************
945 * INT21_GetExtendedError
947 static void INT21_GetExtendedError( CONTEXT86 *context )
949 BYTE class, action, locus;
950 WORD error = GetLastError();
952 switch(error)
954 case ERROR_SUCCESS:
955 class = action = locus = 0;
956 break;
957 case ERROR_DIR_NOT_EMPTY:
958 class = EC_Exists;
959 action = SA_Ignore;
960 locus = EL_Disk;
961 break;
962 case ERROR_ACCESS_DENIED:
963 class = EC_AccessDenied;
964 action = SA_Abort;
965 locus = EL_Disk;
966 break;
967 case ERROR_CANNOT_MAKE:
968 class = EC_AccessDenied;
969 action = SA_Abort;
970 locus = EL_Unknown;
971 break;
972 case ERROR_DISK_FULL:
973 case ERROR_HANDLE_DISK_FULL:
974 class = EC_MediaError;
975 action = SA_Abort;
976 locus = EL_Disk;
977 break;
978 case ERROR_FILE_EXISTS:
979 case ERROR_ALREADY_EXISTS:
980 class = EC_Exists;
981 action = SA_Abort;
982 locus = EL_Disk;
983 break;
984 case ERROR_FILE_NOT_FOUND:
985 class = EC_NotFound;
986 action = SA_Abort;
987 locus = EL_Disk;
988 break;
989 case ER_GeneralFailure:
990 class = EC_SystemFailure;
991 action = SA_Abort;
992 locus = EL_Unknown;
993 break;
994 case ERROR_INVALID_DRIVE:
995 class = EC_MediaError;
996 action = SA_Abort;
997 locus = EL_Disk;
998 break;
999 case ERROR_INVALID_HANDLE:
1000 class = EC_ProgramError;
1001 action = SA_Abort;
1002 locus = EL_Disk;
1003 break;
1004 case ERROR_LOCK_VIOLATION:
1005 class = EC_AccessDenied;
1006 action = SA_Abort;
1007 locus = EL_Disk;
1008 break;
1009 case ERROR_NO_MORE_FILES:
1010 class = EC_MediaError;
1011 action = SA_Abort;
1012 locus = EL_Disk;
1013 break;
1014 case ER_NoNetwork:
1015 class = EC_NotFound;
1016 action = SA_Abort;
1017 locus = EL_Network;
1018 break;
1019 case ERROR_NOT_ENOUGH_MEMORY:
1020 class = EC_OutOfResource;
1021 action = SA_Abort;
1022 locus = EL_Memory;
1023 break;
1024 case ERROR_PATH_NOT_FOUND:
1025 class = EC_NotFound;
1026 action = SA_Abort;
1027 locus = EL_Disk;
1028 break;
1029 case ERROR_SEEK:
1030 class = EC_NotFound;
1031 action = SA_Ignore;
1032 locus = EL_Disk;
1033 break;
1034 case ERROR_SHARING_VIOLATION:
1035 class = EC_Temporary;
1036 action = SA_Retry;
1037 locus = EL_Disk;
1038 break;
1039 case ERROR_TOO_MANY_OPEN_FILES:
1040 class = EC_ProgramError;
1041 action = SA_Abort;
1042 locus = EL_Disk;
1043 break;
1044 default:
1045 FIXME("Unknown error %d\n", error );
1046 class = EC_SystemFailure;
1047 action = SA_Abort;
1048 locus = EL_Unknown;
1049 break;
1051 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1052 error, class, action, locus );
1053 AX_reg(context) = error;
1054 BH_reg(context) = class;
1055 BL_reg(context) = action;
1056 CH_reg(context) = locus;
1059 /***********************************************************************
1060 * DOS3Call (KERNEL.102)
1062 void WINAPI DOS3Call( CONTEXT86 *context )
1064 BOOL bSetDOSExtendedError = FALSE;
1067 TRACE("AX=%04x BX=%04x CX=%04x DX=%04x "
1068 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1069 AX_reg(context), BX_reg(context), CX_reg(context), DX_reg(context),
1070 SI_reg(context), DI_reg(context),
1071 (WORD)DS_reg(context), (WORD)ES_reg(context),
1072 EFL_reg(context) );
1075 if (AH_reg(context) == 0x59) /* Get extended error info */
1077 INT21_GetExtendedError( context );
1078 return;
1081 if (AH_reg(context) == 0x0C) /* Flush buffer and read standard input */
1083 TRACE("FLUSH BUFFER AND READ STANDARD INPUT\n");
1084 /* no flush here yet */
1085 AH_reg(context) = AL_reg(context);
1088 if (AH_reg(context)>=0x2f) {
1089 /* extended error is used by (at least) functions 0x2f to 0x62 */
1090 SetLastError(0);
1092 RESET_CFLAG(context); /* Not sure if this is a good idea */
1094 switch(AH_reg(context))
1096 case 0x03: /* READ CHARACTER FROM STDAUX */
1097 case 0x04: /* WRITE CHARACTER TO STDAUX */
1098 case 0x05: /* WRITE CHARACTER TO PRINTER */
1099 case 0x0f: /* OPEN FILE USING FCB */
1100 case 0x10: /* CLOSE FILE USING FCB */
1101 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1102 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1103 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1104 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1105 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1106 case 0x23: /* GET FILE SIZE FOR FCB */
1107 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1108 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1109 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1110 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1111 INT_BARF( context, 0x21 );
1112 break;
1114 case 0x00: /* TERMINATE PROGRAM */
1115 TRACE("TERMINATE PROGRAM\n");
1116 ExitProcess( 0 );
1117 break;
1119 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1120 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
1121 AL_reg(context) = CONSOLE_GetCharacter();
1122 /* FIXME: no echo */
1123 break;
1125 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1126 TRACE("Write Character to Standard Output\n");
1127 CONSOLE_Write(DL_reg(context), 0, 0, 0);
1128 break;
1130 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1131 if (DL_reg(context) == 0xff) {
1132 static char scan = 0;
1133 TRACE("Direct Console Input\n");
1134 if (scan) {
1135 /* return pending scancode */
1136 AL_reg(context) = scan;
1137 EFL_reg(context) &= ~0x40; /* clear ZF */
1138 scan = 0;
1139 } else {
1140 char ascii;
1141 if (CONSOLE_CheckForKeystroke(&scan,&ascii)) {
1142 CONSOLE_GetKeystroke(&scan,&ascii);
1143 /* return ASCII code */
1144 AL_reg(context) = ascii;
1145 EFL_reg(context) &= ~0x40; /* clear ZF */
1146 /* return scan code on next call only if ascii==0 */
1147 if (ascii) scan = 0;
1148 } else {
1149 /* nothing pending, clear everything */
1150 AL_reg(context) = 0;
1151 EFL_reg(context) |= 0x40; /* set ZF */
1152 scan = 0; /* just in case */
1155 } else {
1156 TRACE("Direct Console Output\n");
1157 CONSOLE_Write(DL_reg(context), 0, 0, 0);
1159 break;
1161 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1162 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1163 AL_reg(context) = CONSOLE_GetCharacter();
1164 break;
1166 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1167 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
1168 AL_reg(context) = CONSOLE_GetCharacter();
1169 break;
1171 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1172 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1173 DS_reg(context),DX_reg(context) );
1175 LPSTR data = CTX_SEG_OFF_TO_LIN(context,DS_reg(context),EDX_reg(context));
1176 LPSTR p = data;
1177 /* do NOT use strchr() to calculate the string length,
1178 as '\0' is valid string content, too !
1179 Maybe we should check for non-'$' strings, but DOS doesn't. */
1180 while (*p != '$') p++;
1181 _hwrite16( 1, data, (int)p - (int)data);
1182 AL_reg(context) = '$'; /* yes, '$' (0x24) gets returned in AL */
1184 break;
1186 case 0x0a: /* BUFFERED INPUT */
1188 char *buffer = ((char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1189 EDX_reg(context) ));
1190 int res;
1192 TRACE("BUFFERED INPUT (size=%d)\n",buffer[0]);
1193 if (buffer[1])
1194 TRACE("Handle old chars in buffer!\n");
1195 res=_lread16( 0, buffer+2,buffer[0]);
1196 buffer[1]=res;
1197 if(buffer[res+1] == '\n')
1198 buffer[res+1] = '\r';
1199 break;
1202 case 0x0b: {/* GET STDIN STATUS */
1203 char x1,x2;
1205 if (CONSOLE_CheckForKeystroke(&x1,&x2))
1206 AL_reg(context) = 0xff;
1207 else
1208 AL_reg(context) = 0;
1209 break;
1211 case 0x2e: /* SET VERIFY FLAG */
1212 TRACE("SET VERIFY FLAG ignored\n");
1213 /* we cannot change the behaviour anyway, so just ignore it */
1214 break;
1216 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1217 case 0x1d:
1218 case 0x1e:
1219 case 0x20:
1220 case 0x6b: /* NULL FUNCTION */
1221 AL_reg(context) = 0;
1222 break;
1224 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1225 fLock(context);
1226 break;
1228 case 0x0d: /* DISK BUFFER FLUSH */
1229 TRACE("DISK BUFFER FLUSH ignored\n");
1230 RESET_CFLAG(context); /* dos 6+ only */
1231 break;
1233 case 0x0e: /* SELECT DEFAULT DRIVE */
1234 TRACE("SELECT DEFAULT DRIVE %d\n", DL_reg(context));
1235 DRIVE_SetCurrentDrive( DL_reg(context) );
1236 AL_reg(context) = MAX_DOS_DRIVES;
1237 break;
1239 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1240 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
1241 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1242 if (!INT21_FindFirstFCB(context))
1244 AL_reg(context) = 0xff;
1245 break;
1247 /* else fall through */
1249 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1250 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
1251 break;
1253 case 0x13: /* DELETE FILE USING FCB */
1254 DeleteFileFCB(context);
1255 break;
1257 case 0x17: /* RENAME FILE USING FCB */
1258 RenameFileFCB(context);
1259 break;
1261 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1262 AL_reg(context) = DRIVE_GetCurrentDrive();
1263 break;
1265 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1267 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1268 pTask->dta = PTR_SEG_OFF_TO_SEGPTR(DS_reg(context),DX_reg(context));
1269 TRACE("Set DTA: %08lx\n", pTask->dta);
1271 break;
1273 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1274 DL_reg(context) = 0;
1275 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1276 break;
1278 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1279 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1280 break;
1282 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1283 GetDrivePB(context, DRIVE_GetCurrentDrive());
1284 break;
1286 case 0x25: /* SET INTERRUPT VECTOR */
1287 INT_CtxSetHandler( context, AL_reg(context),
1288 (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1289 DX_reg(context)));
1290 break;
1292 case 0x29: /* PARSE FILENAME INTO FCB */
1293 INT21_ParseFileNameIntoFCB(context);
1294 break;
1296 case 0x2a: /* GET SYSTEM DATE */
1297 INT21_GetSystemDate(context);
1298 break;
1300 case 0x2b: /* SET SYSTEM DATE */
1301 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
1302 DL_reg(context), DH_reg(context), CX_reg(context) );
1303 AL_reg(context) = 0; /* Let's pretend we succeeded */
1304 break;
1306 case 0x2c: /* GET SYSTEM TIME */
1307 INT21_GetSystemTime(context);
1308 break;
1310 case 0x2d: /* SET SYSTEM TIME */
1311 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1312 CH_reg(context), CL_reg(context),
1313 DH_reg(context), DL_reg(context) );
1314 AL_reg(context) = 0; /* Let's pretend we succeeded */
1315 break;
1317 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1318 TRACE("GET DISK TRANSFER AREA ADDRESS\n");
1320 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1321 ES_reg(context) = SELECTOROF( pTask->dta );
1322 BX_reg(context) = OFFSETOF( pTask->dta );
1324 break;
1326 case 0x30: /* GET DOS VERSION */
1327 TRACE("GET DOS VERSION %s requested\n",
1328 (AL_reg(context) == 0x00)?"OEM number":"version flag");
1329 AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
1330 (HIWORD(GetVersion16()) << 8);
1331 #if 0
1332 AH_reg(context) = 0x7;
1333 AL_reg(context) = 0xA;
1334 #endif
1336 BX_reg(context) = 0x00FF; /* 0x123456 is Wine's serial # */
1337 CX_reg(context) = 0x0000;
1338 break;
1340 case 0x31: /* TERMINATE AND STAY RESIDENT */
1341 FIXME("TERMINATE AND STAY RESIDENT stub\n");
1342 break;
1344 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1345 TRACE("GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1346 INT21_DriveName( DL_reg(context)));
1347 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
1348 break;
1350 case 0x33: /* MULTIPLEXED */
1351 switch (AL_reg(context))
1353 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1354 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
1355 DL_reg(context) = DOSCONF_config.brk_flag;
1356 break;
1358 case 0x01: /* SET EXTENDED BREAK STATE */
1359 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
1360 DOSCONF_config.brk_flag = (DL_reg(context) > 0);
1361 break;
1363 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1364 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1365 /* ugly coding in order to stay reentrant */
1366 if (DL_reg(context))
1368 DL_reg(context) = DOSCONF_config.brk_flag;
1369 DOSCONF_config.brk_flag = 1;
1371 else
1373 DL_reg(context) = DOSCONF_config.brk_flag;
1374 DOSCONF_config.brk_flag = 0;
1376 break;
1378 case 0x05: /* GET BOOT DRIVE */
1379 TRACE("GET BOOT DRIVE\n");
1380 DL_reg(context) = 3;
1381 /* c: is Wine's bootdrive (a: is 1)*/
1382 break;
1384 case 0x06: /* GET TRUE VERSION NUMBER */
1385 TRACE("GET TRUE VERSION NUMBER\n");
1386 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1387 (HIWORD(GetVersion16() << 8));
1388 DX_reg(context) = 0x00;
1389 break;
1391 default:
1392 INT_BARF( context, 0x21 );
1393 break;
1395 break;
1397 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1398 TRACE("GET ADDRESS OF INDOS FLAG\n");
1399 if (!heap) INT21_CreateHeap();
1400 ES_reg(context) = DosHeapHandle;
1401 BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1402 break;
1404 case 0x35: /* GET INTERRUPT VECTOR */
1405 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1407 FARPROC16 addr = INT_CtxGetHandler( context, AL_reg(context) );
1408 ES_reg(context) = SELECTOROF(addr);
1409 BX_reg(context) = OFFSETOF(addr);
1411 break;
1413 case 0x36: /* GET FREE DISK SPACE */
1414 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
1415 INT21_DriveName( DL_reg(context)));
1416 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1417 break;
1419 case 0x37:
1421 unsigned char switchchar='/';
1422 switch (AL_reg(context))
1424 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1425 TRACE("SWITCHAR - GET SWITCH CHARACTER\n");
1426 AL_reg(context) = 0x00; /* success*/
1427 DL_reg(context) = switchchar;
1428 break;
1429 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1430 TRACE("SWITCHAR - SET SWITCH CHARACTER\n");
1431 switchchar = DL_reg(context);
1432 AL_reg(context) = 0x00; /* success*/
1433 break;
1434 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1435 INT_BARF( context, 0x21 );
1436 break;
1438 break;
1441 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1442 TRACE("GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1443 AL_reg(context));
1444 AX_reg(context) = 0x02; /* no country support available */
1445 SET_CFLAG(context);
1446 break;
1448 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1449 TRACE("MKDIR %s\n",
1450 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1451 bSetDOSExtendedError = (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1452 EDX_reg(context) ), NULL));
1453 /* FIXME: CreateDirectory's LastErrors will clash with the ones
1454 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
1455 * denied), while CreateDirectory return several ones. remap some of
1456 * them. -Marcus
1458 if (bSetDOSExtendedError) {
1459 switch (GetLastError()) {
1460 case ERROR_ALREADY_EXISTS:
1461 case ERROR_FILENAME_EXCED_RANGE:
1462 case ERROR_DISK_FULL:
1463 SetLastError(ERROR_ACCESS_DENIED);
1464 break;
1465 default: break;
1468 break;
1470 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1471 TRACE("RMDIR %s\n",
1472 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1473 bSetDOSExtendedError = (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1474 EDX_reg(context) )));
1475 break;
1477 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1478 TRACE("CHDIR %s\n",
1479 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1480 bSetDOSExtendedError = !INT21_ChangeDir(context);
1481 break;
1483 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1484 TRACE("CREAT flag 0x%02x %s\n",CX_reg(context),
1485 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1486 bSetDOSExtendedError = INT21_CreateFile( context );
1487 break;
1489 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1490 TRACE("OPEN mode 0x%02x %s\n",AL_reg(context),
1491 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1492 OpenExistingFile(context);
1493 break;
1495 case 0x3e: /* "CLOSE" - CLOSE FILE */
1496 TRACE("CLOSE handle %d\n",BX_reg(context));
1497 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1498 break;
1500 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1501 TRACE("READ from %d to %04lX:%04X for %d byte\n",BX_reg(context),
1502 DS_reg(context),DX_reg(context),CX_reg(context) );
1504 LONG result;
1505 if (ISV86(context))
1506 result = _hread16( BX_reg(context),
1507 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1508 EDX_reg(context) ),
1509 CX_reg(context) );
1510 else
1511 result = WIN16_hread( BX_reg(context),
1512 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1513 EDX_reg(context) ),
1514 CX_reg(context) );
1515 if (result == -1) bSetDOSExtendedError = TRUE;
1516 else AX_reg(context) = (WORD)result;
1518 break;
1520 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1521 TRACE("WRITE from %04lX:%04X to handle %d for %d byte\n",
1522 DS_reg(context),DX_reg(context),BX_reg(context),CX_reg(context) );
1524 LONG result = _hwrite16( BX_reg(context),
1525 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1526 EDX_reg(context) ),
1527 CX_reg(context) );
1528 if (result == -1) bSetDOSExtendedError = TRUE;
1529 else AX_reg(context) = (WORD)result;
1531 break;
1533 case 0x41: /* "UNLINK" - DELETE FILE */
1534 TRACE("UNLINK%s\n",
1535 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1536 bSetDOSExtendedError = (!DeleteFileA( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1537 EDX_reg(context) )));
1538 break;
1540 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1541 TRACE("LSEEK handle %d offset %ld from %s\n",
1542 BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)),
1543 (AL_reg(context)==0)?"start of file":(AL_reg(context)==1)?
1544 "current file position":"end of file");
1546 LONG status = _llseek16( BX_reg(context),
1547 MAKELONG(DX_reg(context),CX_reg(context)),
1548 AL_reg(context) );
1549 if (status == -1) bSetDOSExtendedError = TRUE;
1550 else
1552 AX_reg(context) = LOWORD(status);
1553 DX_reg(context) = HIWORD(status);
1556 break;
1558 case 0x43: /* FILE ATTRIBUTES */
1559 switch (AL_reg(context))
1561 case 0x00:
1562 TRACE("GET FILE ATTRIBUTES for %s\n",
1563 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1564 AX_reg(context) = (WORD)GetFileAttributesA(
1565 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1566 EDX_reg(context)));
1567 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1568 else CX_reg(context) = AX_reg(context);
1569 break;
1571 case 0x01:
1572 TRACE("SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context),
1573 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1574 bSetDOSExtendedError =
1575 (!SetFileAttributesA( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1576 EDX_reg(context)),
1577 CX_reg(context) ));
1578 break;
1579 case 0x02:
1580 TRACE("GET COMPRESSED FILE SIZE for %s stub\n",
1581 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1583 break;
1585 case 0x44: /* IOCTL */
1586 switch (AL_reg(context))
1588 case 0x00:
1589 ioctlGetDeviceInfo(context);
1590 break;
1592 case 0x01:
1593 break;
1594 case 0x02:{
1595 const DOS_DEVICE *dev;
1596 if ((dev = DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context)) )) &&
1597 !strcasecmp( dev->name, "SCSIMGR$" ))
1599 ASPI_DOS_HandleInt(context);
1601 break;
1603 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1604 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));*/
1605 int drive = DOS_GET_DRIVE(BL_reg(context));
1607 FIXME("program tried to write to block device control channel of drive %d:\n",drive);
1608 /* for (i=0;i<CX_reg(context);i++)
1609 fprintf(stdnimp,"%02x ",dataptr[i]);
1610 fprintf(stdnimp,"\n");*/
1611 AX_reg(context)=CX_reg(context);
1612 break;
1614 case 0x08: /* Check if drive is removable. */
1615 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1616 INT21_DriveName( BL_reg(context)));
1617 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1619 case DRIVE_CANNOTDETERMINE:
1620 SetLastError( ERROR_INVALID_DRIVE );
1621 AX_reg(context) = ERROR_INVALID_DRIVE;
1622 SET_CFLAG(context);
1623 break;
1624 case DRIVE_REMOVABLE:
1625 AX_reg(context) = 0; /* removable */
1626 break;
1627 default:
1628 AX_reg(context) = 1; /* not removable */
1629 break;
1631 break;
1633 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1634 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1635 INT21_DriveName( BL_reg(context)));
1636 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1638 case DRIVE_CANNOTDETERMINE:
1639 SetLastError( ERROR_INVALID_DRIVE );
1640 AX_reg(context) = ERROR_INVALID_DRIVE;
1641 SET_CFLAG(context);
1642 break;
1643 case DRIVE_REMOTE:
1644 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1645 break;
1646 default:
1647 DX_reg(context) = 0; /* FIXME: use driver attr here */
1648 break;
1650 break;
1652 case 0x0a: /* check if handle (BX) is remote */
1653 TRACE("IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context));
1654 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1655 * not set on close
1657 DX_reg(context) = 0;
1658 break;
1660 case 0x0b: /* SET SHARING RETRY COUNT */
1661 TRACE("IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1662 CX_reg(context), DX_reg(context));
1663 if (!CX_reg(context))
1665 AX_reg(context) = 1;
1666 SET_CFLAG(context);
1667 break;
1669 DOSMEM_LOL()->sharing_retry_delay = CX_reg(context);
1670 if (!DX_reg(context))
1671 DOSMEM_LOL()->sharing_retry_count = DX_reg(context);
1672 RESET_CFLAG(context);
1673 break;
1675 case 0x0d:
1676 TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1677 INT21_DriveName( BL_reg(context)));
1678 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1679 break;
1681 case 0x0e: /* get logical drive mapping */
1682 TRACE("IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1683 INT21_DriveName( BL_reg(context)));
1684 AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1685 break;
1687 case 0x0F: /* Set logical drive mapping */
1689 int drive;
1690 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1691 INT21_DriveName( BL_reg(context)));
1692 drive = DOS_GET_DRIVE ( BL_reg(context) );
1693 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1695 SET_CFLAG(context);
1696 AX_reg(context) = 0x000F; /* invalid drive */
1698 break;
1701 case 0xe0: /* Sun PC-NFS API */
1702 /* not installed */
1703 break;
1705 default:
1706 INT_BARF( context, 0x21 );
1707 break;
1709 break;
1711 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1713 HANDLE handle;
1714 TRACE("DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context));
1715 if ((bSetDOSExtendedError = !DuplicateHandle( GetCurrentProcess(),
1716 FILE_GetHandle(BX_reg(context)),
1717 GetCurrentProcess(), &handle,
1718 0, TRUE, DUPLICATE_SAME_ACCESS )))
1719 AX_reg(context) = HFILE_ERROR16;
1720 else
1721 AX_reg(context) = FILE_AllocDosHandle(handle);
1722 break;
1725 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1726 TRACE("FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1727 BX_reg(context),CX_reg(context));
1728 bSetDOSExtendedError = (FILE_Dup2( BX_reg(context), CX_reg(context) ) == HFILE_ERROR16);
1729 break;
1731 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1732 TRACE("CWD - GET CURRENT DIRECTORY for drive %s\n",
1733 INT21_DriveName( DL_reg(context)));
1734 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1735 break;
1737 case 0x48: /* ALLOCATE MEMORY */
1738 TRACE("ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context));
1740 LPVOID *mem;
1741 if (ISV86(context))
1743 mem= DOSMEM_GetBlock(0,(DWORD)BX_reg(context)<<4,NULL);
1744 if (mem)
1745 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1747 else
1749 mem = (LPVOID)GlobalDOSAlloc16(BX_reg(context)<<4);
1750 if (mem)
1751 AX_reg(context) = (DWORD)mem&0xffff;
1753 if (!mem)
1755 SET_CFLAG(context);
1756 AX_reg(context) = 0x0008; /* insufficient memory */
1757 BX_reg(context) = DOSMEM_Available(0)>>4;
1760 break;
1762 case 0x49: /* FREE MEMORY */
1763 TRACE("FREE MEMORY segment %04lX\n", ES_reg(context));
1765 BOOL ret;
1766 if (ISV86(context))
1767 ret= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4));
1768 else
1770 ret = !GlobalDOSFree16(ES_reg(context));
1771 /* If we don't reset ES_reg, we will fail in the relay code */
1772 ES_reg(context)=ret;
1774 if (!ret)
1776 TRACE("FREE MEMORY failed\n");
1777 SET_CFLAG(context);
1778 AX_reg(context) = 0x0009; /* memory block address invalid */
1781 break;
1783 case 0x4a: /* RESIZE MEMORY BLOCK */
1784 TRACE("RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context), BX_reg(context));
1785 if (!ISV86(context))
1786 FIXME("RESIZE MEMORY probably insufficient implementation. Expect crash soon\n");
1788 LPVOID *mem = DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4),
1789 BX_reg(context)<<4,NULL);
1790 if (mem)
1791 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1792 else {
1793 SET_CFLAG(context);
1794 AX_reg(context) = 0x0008; /* insufficient memory */
1795 BX_reg(context) = DOSMEM_Available(0)>>4; /* not quite right */
1798 break;
1800 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1801 TRACE("EXEC %s\n",
1802 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context) ));
1803 AX_reg(context) = WinExec16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1804 EDX_reg(context) ),
1805 SW_NORMAL );
1806 if (AX_reg(context) < 32) SET_CFLAG(context);
1807 break;
1809 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1810 TRACE("EXIT with return code %d\n",AL_reg(context));
1811 ExitProcess( AL_reg(context) );
1812 break;
1814 case 0x4d: /* GET RETURN CODE */
1815 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
1816 AX_reg(context) = 0; /* normal exit */
1817 break;
1819 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1820 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
1821 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1822 if (!INT21_FindFirst(context)) break;
1823 /* fall through */
1825 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1826 TRACE("FINDNEXT\n");
1827 if (!INT21_FindNext(context))
1829 SetLastError( ERROR_NO_MORE_FILES );
1830 AX_reg(context) = ERROR_NO_MORE_FILES;
1831 SET_CFLAG(context);
1833 else AX_reg(context) = 0; /* OK */
1834 break;
1835 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1836 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1837 INT21_SetCurrentPSP(BX_reg(context));
1838 break;
1839 case 0x51: /* GET PSP ADDRESS */
1840 TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1841 /* FIXME: should we return the original DOS PSP upon */
1842 /* Windows startup ? */
1843 BX_reg(context) = INT21_GetCurrentPSP();
1844 break;
1845 case 0x62: /* GET PSP ADDRESS */
1846 TRACE("GET CURRENT PSP ADDRESS\n");
1847 /* FIXME: should we return the original DOS PSP upon */
1848 /* Windows startup ? */
1849 BX_reg(context) = INT21_GetCurrentPSP();
1850 break;
1852 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1853 TRACE("SYSVARS - GET LIST OF LISTS\n");
1855 ES_reg(context) = ISV86(context) ? HIWORD(DOS_LOLSeg) : LOWORD(DOS_LOLSeg);
1856 BX_reg(context) = FIELD_OFFSET(DOS_LISTOFLISTS, ptr_first_DPB);
1858 break;
1860 case 0x54: /* Get Verify Flag */
1861 TRACE("Get Verify Flag - Not Supported\n");
1862 AL_reg(context) = 0x00; /* pretend we can tell. 00h = off 01h = on */
1863 break;
1865 case 0x56: /* "RENAME" - RENAME FILE */
1866 TRACE("RENAME %s to %s\n",
1867 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1868 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context)));
1869 bSetDOSExtendedError =
1870 (!MoveFileA( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1871 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context))));
1872 break;
1874 case 0x57: /* FILE DATE AND TIME */
1875 switch (AL_reg(context))
1877 case 0x00: /* Get */
1879 FILETIME filetime;
1880 TRACE("GET FILE DATE AND TIME for handle %d\n",
1881 BX_reg(context));
1882 if (!GetFileTime( FILE_GetHandle(BX_reg(context)), NULL, NULL, &filetime ))
1883 bSetDOSExtendedError = TRUE;
1884 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1885 &CX_reg(context) );
1887 break;
1889 case 0x01: /* Set */
1891 FILETIME filetime;
1892 TRACE("SET FILE DATE AND TIME for handle %d\n",
1893 BX_reg(context));
1894 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1895 &filetime );
1896 bSetDOSExtendedError =
1897 (!SetFileTime( FILE_GetHandle(BX_reg(context)),
1898 NULL, NULL, &filetime ));
1900 break;
1902 break;
1904 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1905 TRACE("GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1906 AL_reg(context));
1907 switch (AL_reg(context))
1909 case 0x00:
1910 AX_reg(context) = 1;
1911 break;
1912 case 0x02:
1913 AX_reg(context) = 0;
1914 break;
1915 case 0x01:
1916 case 0x03:
1917 break;
1919 RESET_CFLAG(context);
1920 break;
1922 case 0x5a: /* CREATE TEMPORARY FILE */
1923 TRACE("CREATE TEMPORARY FILE\n");
1924 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1925 break;
1927 case 0x5b: /* CREATE NEW FILE */
1928 TRACE("CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
1929 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1930 bSetDOSExtendedError = ((AX_reg(context) =
1931 _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1932 CX_reg(context) )) == (WORD)HFILE_ERROR16);
1933 break;
1935 case 0x5d: /* NETWORK */
1936 FIXME("Function 0x%04x not implemented.\n", AX_reg (context));
1937 /* Fix the following while you're at it. */
1938 SetLastError( ER_NoNetwork );
1939 bSetDOSExtendedError = TRUE;
1940 break;
1942 case 0x5e:
1943 bSetDOSExtendedError = INT21_networkfunc (context);
1944 break;
1946 case 0x5f: /* NETWORK */
1947 switch (AL_reg(context))
1949 case 0x07: /* ENABLE DRIVE */
1950 TRACE("ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1951 if (!DRIVE_Enable( DL_reg(context) ))
1953 SetLastError( ERROR_INVALID_DRIVE );
1954 bSetDOSExtendedError = TRUE;
1956 break;
1958 case 0x08: /* DISABLE DRIVE */
1959 TRACE("DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1960 if (!DRIVE_Disable( DL_reg(context) ))
1962 SetLastError( ERROR_INVALID_DRIVE );
1963 bSetDOSExtendedError = TRUE;
1965 break;
1967 default:
1968 /* network software not installed */
1969 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context));
1970 SetLastError( ER_NoNetwork );
1971 bSetDOSExtendedError = TRUE;
1972 break;
1974 break;
1976 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1977 TRACE("TRUENAME %s\n",
1978 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),ESI_reg(context)));
1980 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1981 ESI_reg(context)), 128,
1982 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
1983 EDI_reg(context)),NULL))
1984 bSetDOSExtendedError = TRUE;
1985 else AX_reg(context) = 0;
1987 break;
1989 case 0x61: /* UNUSED */
1990 case 0x63: /* misc. language support */
1991 switch (AL_reg(context)) {
1992 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1993 INT21_GetDBCSLeadTable(context);
1994 break;
1996 break;
1997 case 0x64: /* OS/2 DOS BOX */
1998 INT_BARF( context, 0x21 );
1999 SET_CFLAG(context);
2000 break;
2002 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
2003 extern WORD WINE_LanguageId;
2004 BYTE *dataptr=CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context));
2005 TRACE("GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
2006 BX_reg(context), DX_reg(context));
2007 switch (AL_reg(context)) {
2008 case 0x01:
2009 TRACE("\tget general internationalization info\n");
2010 dataptr[0] = 0x1;
2011 *(WORD*)(dataptr+1) = 41;
2012 *(WORD*)(dataptr+3) = WINE_LanguageId;
2013 *(WORD*)(dataptr+5) = CodePage;
2014 *(DWORD*)(dataptr+0x19) = 0; /* FIXME: ptr to case map routine */
2015 break;
2016 case 0x06:
2017 TRACE("\tget pointer to collating sequence table\n");
2018 dataptr[0] = 0x06;
2019 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
2020 CX_reg(context) = 258;/*FIXME: size of table?*/
2021 break;
2022 case 0x20:
2023 TRACE("\tConvert char to uppercase\n");
2024 DL_reg(context) = toupper(DL_reg(context));
2025 break;
2026 case 0x21:
2027 TRACE("\tconvert string to uppercase with length\n");
2028 CharUpperBuffA( (LPSTR)CTX_SEG_OFF_TO_LIN(context,DS_reg(context),EDX_reg(context)),
2029 CX_reg(context) );
2030 break;
2031 case 0x22:
2032 TRACE("\tConvert ASCIIZ string to uppercase\n");
2033 CharUpperA( (LPSTR)CTX_SEG_OFF_TO_LIN(context,DS_reg(context),EDX_reg(context)) );
2034 break;
2035 default:
2036 TRACE("\tunimplemented function %d\n",AL_reg(context));
2037 INT_BARF( context, 0x21 );
2038 SET_CFLAG(context);
2039 break;
2041 break;
2043 case 0x66: /* GLOBAL CODE PAGE TABLE */
2044 switch (AL_reg(context))
2046 case 0x01:
2047 TRACE("GET GLOBAL CODE PAGE TABLE\n");
2048 DX_reg(context) = BX_reg(context) = CodePage;
2049 RESET_CFLAG(context);
2050 break;
2051 case 0x02:
2052 TRACE("SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2053 BX_reg(context),DX_reg(context));
2054 CodePage = BX_reg(context);
2055 RESET_CFLAG(context);
2056 break;
2058 break;
2060 case 0x67: /* SET HANDLE COUNT */
2061 TRACE("SET HANDLE COUNT to %d\n",BX_reg(context) );
2062 SetHandleCount16( BX_reg(context) );
2063 if (GetLastError()) bSetDOSExtendedError = TRUE;
2064 break;
2066 case 0x68: /* "FFLUSH" - COMMIT FILE */
2067 case 0x6a: /* COMMIT FILE */
2068 TRACE("FFLUSH/COMMIT handle %d\n",BX_reg(context));
2069 bSetDOSExtendedError = (!FlushFileBuffers( FILE_GetHandle(BX_reg(context)) ));
2070 break;
2072 case 0x69: /* DISK SERIAL NUMBER */
2073 switch (AL_reg(context))
2075 case 0x00:
2076 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
2077 INT21_DriveName(BL_reg(context)));
2078 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2079 else AX_reg(context) = 0;
2080 break;
2082 case 0x01:
2083 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
2084 INT21_DriveName(BL_reg(context)));
2085 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2086 else AX_reg(context) = 1;
2087 break;
2089 break;
2091 case 0x6C: /* Extended Open/Create*/
2092 TRACE("EXTENDED OPEN/CREATE %s\n",
2093 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDI_reg(context)));
2094 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2095 break;
2097 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2098 if ((GetVersion()&0xC0000004)!=0xC0000004) {
2099 /* not supported on anything but Win95 */
2100 TRACE("LONG FILENAME functions supported only by win95\n");
2101 SET_CFLAG(context);
2102 AL_reg(context) = 0;
2103 } else
2104 switch(AL_reg(context))
2106 case 0x39: /* Create directory */
2107 TRACE("LONG FILENAME - MAKE DIRECTORY %s\n",
2108 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2109 bSetDOSExtendedError = (!CreateDirectoryA(
2110 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2111 EDX_reg(context) ), NULL));
2112 /* FIXME: CreateDirectory's LastErrors will clash with the ones
2113 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
2114 * denied), while CreateDirectory return several ones. remap some of
2115 * them. -Marcus
2117 if (bSetDOSExtendedError) {
2118 switch (GetLastError()) {
2119 case ERROR_ALREADY_EXISTS:
2120 case ERROR_FILENAME_EXCED_RANGE:
2121 case ERROR_DISK_FULL:
2122 SetLastError(ERROR_ACCESS_DENIED);
2123 break;
2124 default: break;
2127 break;
2128 case 0x3a: /* Remove directory */
2129 TRACE("LONG FILENAME - REMOVE DIRECTORY %s\n",
2130 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2131 bSetDOSExtendedError = (!RemoveDirectoryA(
2132 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2133 EDX_reg(context) )));
2134 break;
2135 case 0x43: /* Get/Set file attributes */
2136 TRACE("LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2137 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2138 switch (BL_reg(context))
2140 case 0x00: /* Get file attributes */
2141 TRACE("\tretrieve attributes\n");
2142 CX_reg(context) = (WORD)GetFileAttributesA(
2143 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2144 EDX_reg(context)));
2145 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
2146 break;
2147 case 0x01:
2148 TRACE("\tset attributes 0x%04x\n",CX_reg(context));
2149 bSetDOSExtendedError = (!SetFileAttributesA(
2150 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2151 EDX_reg(context)),
2152 CX_reg(context) ) );
2153 break;
2154 default:
2155 FIXME("Unimplemented long file name function:\n");
2156 INT_BARF( context, 0x21 );
2157 SET_CFLAG(context);
2158 AL_reg(context) = 0;
2159 break;
2161 break;
2162 case 0x47: /* Get current directory */
2163 TRACE(" LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2164 INT21_DriveName(DL_reg(context)));
2165 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
2166 break;
2168 case 0x4e: /* Find first file */
2169 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2170 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2171 /* FIXME: use attributes in CX */
2172 if ((AX_reg(context) = FindFirstFile16(
2173 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
2174 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2175 EDI_reg(context))))
2176 == INVALID_HANDLE_VALUE16)
2177 bSetDOSExtendedError = TRUE;
2178 break;
2179 case 0x4f: /* Find next file */
2180 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2181 BX_reg(context));
2182 if (!FindNextFile16( BX_reg(context),
2183 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2184 EDI_reg(context))))
2185 bSetDOSExtendedError = TRUE;
2186 break;
2187 case 0xa1: /* Find close */
2188 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
2189 BX_reg(context));
2190 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
2191 break;
2192 case 0xa0:
2193 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2194 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2195 break;
2196 case 0x60:
2197 switch(CL_reg(context))
2199 case 0x01: /*Get short filename or path */
2200 if (!GetShortPathNameA
2201 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2202 ESI_reg(context)),
2203 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2204 EDI_reg(context)), 67))
2205 bSetDOSExtendedError = TRUE;
2206 else AX_reg(context) = 0;
2207 break;
2208 case 0x02: /*Get canonical long filename or path */
2209 if (!GetFullPathNameA
2210 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2211 ESI_reg(context)), 128,
2212 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2213 EDI_reg(context)),NULL))
2214 bSetDOSExtendedError = TRUE;
2215 else AX_reg(context) = 0;
2216 break;
2217 default:
2218 FIXME("Unimplemented long file name function:\n");
2219 INT_BARF( context, 0x21 );
2220 SET_CFLAG(context);
2221 AL_reg(context) = 0;
2222 break;
2224 break;
2225 case 0x6c: /* Create or open file */
2226 TRACE("LONG FILENAME - CREATE OR OPEN FILE %s\n",
2227 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context)));
2228 /* translate Dos 7 action to Dos 6 action */
2229 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2230 break;
2232 case 0x3b: /* Change directory */
2233 TRACE("LONG FILENAME - CHANGE DIRECTORY %s\n",
2234 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
2235 if (!SetCurrentDirectoryA(CTX_SEG_OFF_TO_LIN(context,
2236 DS_reg(context),
2237 EDX_reg(context)
2240 SET_CFLAG(context);
2241 AL_reg(context) = GetLastError();
2243 break;
2244 case 0x41: /* Delete file */
2245 TRACE("LONG FILENAME - DELETE FILE %s\n",
2246 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
2247 if (!DeleteFileA(CTX_SEG_OFF_TO_LIN(context,
2248 DS_reg(context),
2249 EDX_reg(context))
2250 )) {
2251 SET_CFLAG(context);
2252 AL_reg(context) = GetLastError();
2254 break;
2255 case 0x56: /* Move (rename) file */
2256 TRACE("LONG FILENAME - RENAME FILE %s to %s stub\n",
2257 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)),
2258 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context), EDI_reg(context)));
2259 default:
2260 FIXME("Unimplemented long file name function:\n");
2261 INT_BARF( context, 0x21 );
2262 SET_CFLAG(context);
2263 AL_reg(context) = 0;
2264 break;
2266 break;
2268 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2269 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2270 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2271 TRACE("windows95 function AX %04x\n",
2272 AX_reg(context));
2273 WARN(" returning unimplemented\n");
2274 SET_CFLAG(context);
2275 AL_reg(context) = 0;
2276 break;
2278 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2279 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2280 break;
2282 default:
2283 INT_BARF( context, 0x21 );
2284 break;
2286 } /* END OF SWITCH */
2288 if( bSetDOSExtendedError ) /* set general error condition */
2290 AX_reg(context) = GetLastError();
2291 SET_CFLAG(context);
2294 if ((EFL_reg(context) & 0x0001))
2295 TRACE("failed, error 0x%04lx\n", GetLastError() );
2297 TRACE("returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2298 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2299 AX_reg(context), BX_reg(context), CX_reg(context),
2300 DX_reg(context), SI_reg(context), DI_reg(context),
2301 (WORD)DS_reg(context), (WORD)ES_reg(context),
2302 EFL_reg(context));
2305 FARPROC16 WINAPI GetSetKernelDOSProc16(FARPROC16 DosProc)
2307 FIXME("(DosProc=0x%08x): stub\n", (UINT)DosProc);
2308 return NULL;