Release 980517
[wine] / msdos / int2f.c
1 /*
2  * DOS interrupt 2fh handler
3  */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
9 #include "ldt.h"
10 #include "drive.h"
11 #include "msdos.h"
12 #include "miscemu.h"
13 #include "module.h"
14 /* #define DEBUG_INT */
15 #include "debug.h"
16
17   /* base WPROCS.DLL ordinal number for VxDs */
18 #define VXD_BASE 400
19
20 static void do_int2f_16( CONTEXT *context );
21
22 /**********************************************************************
23  *          INT_Int2fHandler
24  *
25  * Handler for int 2fh (multiplex).
26  */
27 void WINAPI INT_Int2fHandler( CONTEXT *context )
28 {
29     switch(AH_reg(context))
30     {
31     case 0x10:
32         AL_reg(context) = 0xff; /* share is installed */
33         break;
34
35     case 0x15: /* mscdex */
36         do_mscdex(context);
37         break;
38
39     case 0x16:
40         do_int2f_16( context );
41         break;
42
43     case 0x45:
44        switch (AL_reg(context)) 
45        {
46        case 0x00:
47        case 0x01:
48        case 0x02:
49        case 0x03:
50        case 0x04:
51        case 0x05:
52        case 0x06:
53        case 0x07:
54        case 0x08:
55            /* Microsoft Profiler - not installed */
56            break;
57        default:
58             INT_BARF( context, 0x2f );
59        }
60        break;
61
62     case 0x4a:
63         switch(AL_reg(context))
64         {
65         case 0x10:  /* smartdrv */
66             break;  /* not installed */
67         case 0x11:  /* dblspace */
68             break;  /* not installed */
69         case 0x12:  /* realtime compression interface */
70             break;  /* not installed */
71         default:
72             INT_BARF( context, 0x2f );
73         }
74         break;
75     case 0x56:  /* INTERLNK */
76         switch(AL_reg(context))
77         {
78         case 0x01:  /* check if redirected drive */
79             AL_reg(context) = 0; /* not redirected */
80             break;
81         default:
82             INT_BARF( context, 0x2f );
83         }
84         break;
85     case 0xb7:  /* append */
86         AL_reg(context) = 0; /* not installed */
87         break;
88     case 0xbd:  /* some Novell network install check ??? */
89         AX_reg(context) = 0xa5a5; /* pretend to have Novell IPX installed */
90         break;
91     case 0xfa:  /* Watcom debugger check, returns 0x666 if installed */
92         break;
93     default:
94         INT_BARF( context, 0x2f );
95         break;
96     }
97 }
98
99
100 /**********************************************************************
101  *          do_int2f_16
102  */
103 static void do_int2f_16( CONTEXT *context )
104 {
105     DWORD addr;
106
107     switch(AL_reg(context))
108     {
109     case 0x00:  /* Windows enhanced mode installation check */
110         AX_reg(context) = (GetWinFlags() & WF_ENHANCED) ?
111                                                   LOWORD(GetVersion16()) : 0;
112         break;
113         
114     case 0x0a:  /* Get Windows version and type */
115         AX_reg(context) = 0;
116         BX_reg(context) = (LOWORD(GetVersion16()) << 8) |
117                           (LOWORD(GetVersion16()) >> 8);
118         CX_reg(context) = (GetWinFlags() & WF_ENHANCED) ? 3 : 2;
119         break;
120
121     case 0x80:  /* Release time-slice */
122         AL_reg(context) = 0;
123         /* FIXME: We need to do something that lets some other process run
124            here.  */
125         sleep(0);
126         break;
127
128     case 0x81: /* Begin critical section.  */
129         /* FIXME? */
130         break;
131
132     case 0x82: /* End critical section.  */
133         /* FIXME? */
134         break;
135
136     case 0x83:  /* Return Current Virtual Machine ID */
137         /* Virtual Machines are usually created/destroyed when Windows runs
138          * DOS programs. Since we never do, we are always in the System VM.
139          * According to Ralf Brown's Interrupt List, never return 0. But it
140          * seems to work okay (returning 0), just to be sure we return 1.
141          */
142         BX_reg(context) = 1; /* VM 1 is probably the System VM */
143         break;
144
145     case 0x84:  /* Get device API entry point */
146         addr = (DWORD)NE_GetEntryPoint( GetModuleHandle16("WPROCS"),
147                                         VXD_BASE + BX_reg(context) );
148         if (!addr)  /* not supported */
149         {
150             WARN(int,"Application attempted to access VxD %04x\n",
151                      BX_reg(context) );
152             WARN(int,"This device is not known to Wine.");
153             WARN(int,"Expect a failure now\n");
154         }
155         ES_reg(context) = SELECTOROF(addr);
156         DI_reg(context) = OFFSETOF(addr);
157         break;
158
159     case 0x86:  /* DPMI detect mode */
160         AX_reg(context) = 0;  /* Running under DPMI */
161         break;
162
163     /* FIXME: is this right?  Specs say that this should only be callable
164        in real (v86) mode which we never enter.  */
165     case 0x87: /* DPMI installation check */
166         {
167             SYSTEM_INFO si;
168
169             GetSystemInfo(&si);
170             AX_reg(context) = 0x0000; /* DPMI Installed */
171             BX_reg(context) = 0x0001; /* 32bits available */
172             CL_reg(context) = si.wProcessorLevel;
173             DX_reg(context) = 0x005a; /* DPMI major/minor 0.90 */
174             SI_reg(context) = 0;      /* # of para. of DOS extended private data */
175             ES_reg(context) = 0;      /* ES:DI is DPMI switch entry point */
176             DI_reg(context) = 0;
177             break;
178         }
179     case 0x8a:  /* DPMI get vendor-specific API entry point. */
180         /* The 1.0 specs say this should work with all 0.9 hosts.  */
181         break;
182
183     default:
184         INT_BARF( context, 0x2f );
185     }
186 }
187
188 void do_mscdex( CONTEXT *context )
189 {
190     int drive, count;
191     char *p;
192
193     switch(AL_reg(context))
194     {
195         case 0x00: /* Installation check */
196             /* Count the number of contiguous CDROM drives
197              */
198             for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++)
199             {
200                 if (DRIVE_GetType(drive) == TYPE_CDROM)
201                 {
202                     while (DRIVE_GetType(drive + count) == TYPE_CDROM) count++;
203                     break;
204                 }
205             }
206
207             BX_reg(context) = count;
208             CX_reg(context) = (drive < MAX_DOS_DRIVES) ? drive : 0;
209             break;
210
211         case 0x0B: /* drive check */
212             AX_reg(context) = (DRIVE_GetType(CX_reg(context)) == TYPE_CDROM);
213             BX_reg(context) = 0xADAD;
214             break;
215
216         case 0x0C: /* get version */
217             BX_reg(context) = 0x020a;
218             break;
219
220         case 0x0D: /* get drive letters */
221             p = PTR_SEG_OFF_TO_LIN(ES_reg(context), BX_reg(context));
222             memset( p, 0, MAX_DOS_DRIVES );
223             for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
224             {
225                 if (DRIVE_GetType(drive) == TYPE_CDROM) *p++ = drive;
226             }
227             break;
228
229         default:
230             FIXME(int, "Unimplemented MSCDEX function 0x%02X.\n", AL_reg(context));
231             break;
232     }
233 }