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