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