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