Report non-hercules video. Turned on int 2a.
[wine] / misc / version.c
1 /*
2  * Windows and DOS version functions
3  *
4  * Copyright 1997 Alexandre Julliard
5  * Copyright 1997 Marcus Meissner
6  * Copyright 1998 Patrik Stridvall
7  * Copyright 1998 Andreas Mohr
8  */
9
10 #include <string.h>
11 #include <stdlib.h>
12 #include "winbase.h"
13 #include "winuser.h"
14 #include "wine/winbase16.h"
15 #include "process.h"
16 #include "options.h"
17 #include "debugtools.h"
18 #include "neexe.h"
19 #include "winversion.h"
20 #include "winerror.h"
21
22 DEFAULT_DEBUG_CHANNEL(ver)
23
24 typedef struct
25 {
26     LONG             getVersion16; 
27     LONG             getVersion32;
28     OSVERSIONINFOA getVersionEx;
29 } VERSION_DATA;
30
31
32 /* FIXME: compare values below with original and fix */
33 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
34 {
35     /* WIN31 */
36     {
37         MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
38         MAKELONG( 0x0a03, 0x8000 ),
39         {
40             sizeof(OSVERSIONINFOA), 3, 10, 0,
41             VER_PLATFORM_WIN32s, "Win32s 1.3" 
42         }
43     },
44     /* WIN95 */
45     {
46         0x07005F03,
47         0xC0000004,
48         {
49             sizeof(OSVERSIONINFOA), 4, 0, 0x40003B6,
50             VER_PLATFORM_WIN32_WINDOWS, "Win95"
51         }
52     },
53     /* WIN98 */
54     {
55         0x07005F03,     /* FIXME: need DOS value from real Win98 */
56         0xC0000A04,
57         {
58             sizeof(OSVERSIONINFOA), 4, 10, 0x40A07CE,
59             VER_PLATFORM_WIN32_WINDOWS, "Win98"
60         }
61     },
62     /* NT351 */
63     {
64         0x05000A03,
65         0x04213303,
66         {
67             sizeof(OSVERSIONINFOA), 3, 51, 0x421,
68             VER_PLATFORM_WIN32_NT, "Service Pack 2"
69         }
70     },
71     /* NT40 */
72     {
73         0x05000A03,
74         0x05650004,
75         {
76             sizeof(OSVERSIONINFOA), 4, 0, 0x565,
77             VER_PLATFORM_WIN32_NT, "Service Pack 3"
78         }
79     }
80 };
81
82 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
83 {
84     "win31",
85     "win95",
86     "win98",
87     "nt351",
88     "nt40"
89 };
90
91 /* the current version has not been autodetected but forced via cmdline */
92 static BOOL versionForced = FALSE;
93 static WINDOWS_VERSION defaultWinVersion = WIN31;
94
95
96 /**********************************************************************
97  *         VERSION_ParseWinVersion
98  */
99 void VERSION_ParseWinVersion( const char *arg )
100 {
101     int i;
102     for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
103     {
104         if (!strcmp( WinVersionNames[i], arg ))
105         {
106             defaultWinVersion = (WINDOWS_VERSION)i;
107             versionForced = TRUE;
108             return;
109         }
110     }
111     MESSAGE("Invalid winver value '%s' specified.\n", arg );
112     MESSAGE("Valid versions are:" );
113     for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
114         MESSAGE(" '%s'%c", WinVersionNames[i],
115             (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
116 }
117
118
119 /**********************************************************************
120  *         VERSION_ParseDosVersion
121  */
122 void VERSION_ParseDosVersion( const char *arg )
123 {
124     int hi, lo;
125     if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
126     {
127         VersionData[WIN31].getVersion16 =
128             MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
129                      (hi<<8) + lo);
130     }
131     else
132         fprintf( stderr, "-dosver: Wrong version format. Use \"-dosver x.xx\"\n");
133 }
134
135
136 WINDOWS_VERSION VERSION_GetImageVersion(PDB *pdb)
137 {
138     PIMAGE_NT_HEADERS peheader;
139
140         if (!pdb->exe_modref)
141         {
142                 /* HACK: if we have loaded a PE image into this address space,
143                  * we are probably using thunks, so Win95 is our best bet
144                  */
145                 if (pdb->modref_list)
146                         return WIN95;
147                 /* FIXME: hmm, do anything else ?
148                    TDB.version doesn't help here
149                    as it always holds version 3.10 */
150                         return WIN31;
151         }
152         else
153         {
154                 peheader = PE_HEADER(pdb->exe_modref->module);
155 #define OPTHD peheader->OptionalHeader
156
157                 TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
158                           OPTHD.MajorLinkerVersion,
159                           OPTHD.MinorLinkerVersion,
160                           OPTHD.MajorOperatingSystemVersion,
161                           OPTHD.MinorOperatingSystemVersion,
162                           OPTHD.MajorImageVersion,
163                           OPTHD.MinorImageVersion,
164                           OPTHD.MajorSubsystemVersion,
165                           OPTHD.MinorSubsystemVersion);
166
167         switch (OPTHD.MajorSubsystemVersion)
168                 {
169                         case 4:
170                                 switch (OPTHD.MajorOperatingSystemVersion)
171                                 {
172                                         case 5:
173                                                 return NT40; /* FIXME: this is NT 5, isn't it ? */
174                                         case 4:
175                                                 if ((OPTHD.MajorImageVersion == 0) &&
176                                                         (OPTHD.SectionAlignment == 4096))
177                                                         return WIN95;
178                                                 else
179                                                         return NT40;
180                                         case 1:
181                                                 return WIN95;
182                                         default:
183                                                 return WIN95; /* FIXME ? */
184                                 }
185                         case 3:
186                                 /* 3.1x versions */
187                                 if (OPTHD.MinorSubsystemVersion <= 11)
188                                 {
189                                         if (OPTHD.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
190                                                 return NT351; /* FIXME: NT 3.1 */
191                                         else
192                                                 return WIN31;
193                                 }
194                                 else
195                                 {
196                                         /* NT 3.51 */
197                                         if (OPTHD.MinorSubsystemVersion == 50)
198                                                 return NT351;
199                                         else
200                                         if (OPTHD.MinorSubsystemVersion == 51)
201                                                 return NT351;
202                                 }
203                         default:
204                                 if (OPTHD.MajorSubsystemVersion)
205                                 ERR("unknown subsystem version: %04x.%04x, please report.\n",
206                                         OPTHD.MajorSubsystemVersion,
207                                         OPTHD.MinorSubsystemVersion );
208                                 return defaultWinVersion;
209                 }
210 #undef OPTHD
211         }
212 }
213
214
215 /**********************************************************************
216  *
217  * Check the version of COMDLG32, SHELL32, COMCTL32 and CTL3D32.
218  * Not functional yet.
219  */
220 DWORD VERSION_GetLinkedDllVersion(PDB *pdb)
221 {
222         WINE_MODREF *wm;
223     WORD VersionCounter[NB_WINDOWS_VERSIONS];
224
225     memset(VersionCounter, 0, sizeof(VersionCounter));
226
227         VersionCounter[WIN95] = 1;
228         for ( wm = PROCESS_Current()->modref_list; wm; wm=wm->next ) {
229             if (!(lstrncmpiA(wm->modname, "CTL3D32", 7)))
230                         VersionCounter[WIN95]++;
231         }
232
233         return MAKELONG(WIN95, VersionCounter[WIN95]);
234 }
235
236
237 /**********************************************************************
238  *         VERSION_GetVersion
239  *
240  * WARNING !!!
241  * Don't call this function too early during the Wine init,
242  * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
243  * be NULL in such cases, which causes the winver to ALWAYS be detected
244  * as WIN31.
245  * And as we cache the winver once it has been determined, this is bad.
246  * This can happen much easier than you might think, as this function
247  * is called by EVERY GetVersion*() API !
248  *
249  * Some version data:
250  * linker/OS/image/subsys       Name                    Intended for
251  *
252  * 2.39/1.00/0.00/3.10          freecell.exe    Win32s (any version)
253  * 2.55/1.00/0.00/4.00          acrord32.exe    Win32s, Win95 supported (?)
254  * 
255  * 2.50/1.00/4.00/4.00          winhlp32.exe    Win32s 1.30
256  * 4.20/4.00/1.00/4.00          Asuslm.exe              Win95 (Aaargh !)
257  * 5.12/4.00/1.07/4.00      clikfixi.exe    NT 4 (service pack files)
258  * 3.10/4.00/4.00/4.00          PLUMBING.EXE    NT
259  * ?.??/4.00/97.01/4.00         sse.exe                 huh ?? (damn crackerz ;)
260  * 5.12/5.00/5.00/4.00          comctl32.dll    NT4 / IE 5.0
261  * 6.00/5.00/5.00/4.00                                          NT 4 driver update (strange numbers)
262  * 
263  * Common versions:
264  * x.xx/1.00/0.00/3.10                                          Win32s (any version ?)
265  * 2.xx/1.00/0.00/4.00                                          Win95 (Microsoft/system files) 
266  * x.xx/4.00/0.00/4.00                                          Win95 (most applications !)
267  * x.xx/4.00/4.00/4.00                                          NT 4 (most apps)
268  * x.xx/5.00/5.00/4.00                                          NT 4 newer files / NT 5 ??
269  */
270 WINDOWS_VERSION VERSION_GetVersion(void)
271 {
272     PDB *pdb = PROCESS_Current();
273     DWORD DllVer;
274
275     if (versionForced) /* user has overridden any sensible checks */
276         return defaultWinVersion;
277
278     if (pdb->winver == 0xffff) /* to be determined */
279         {
280                 DllVer = 0/*VERSION_GetLinkedDllVersion(pdb)*/;
281                 if (HIWORD(DllVer) > 1)
282                         pdb->winver = LOWORD(DllVer);
283             else
284                         pdb->winver = VERSION_GetImageVersion(pdb);
285         }
286
287         return pdb->winver;
288 }
289
290
291 /**********************************************************************
292  *         VERSION_GetVersionName
293  */
294 char *VERSION_GetVersionName()
295 {
296   WINDOWS_VERSION ver = VERSION_GetVersion();
297   switch(ver)
298     {
299     case WIN31:
300       return "Windows 3.1";
301     case WIN95:  
302       return "Windows 95";
303     case WIN98:
304       return "Windows 98";
305     case NT351:
306       return "Windows NT 3.51";
307     case NT40:
308       return "Windows NT 4.0";
309     default:
310       FIXME("Windows version %d not named",ver);
311       return "Windows <Unknown>";
312     }
313 }
314
315 /***********************************************************************
316  *         GetVersion16   (KERNEL.3)
317  */
318 LONG WINAPI GetVersion16(void)
319 {
320     WINDOWS_VERSION ver = VERSION_GetVersion();
321     return VersionData[ver].getVersion16;
322 }
323
324
325 /***********************************************************************
326  *         GetVersion32   (KERNEL32.427)
327  */
328 LONG WINAPI GetVersion(void)
329 {
330     WINDOWS_VERSION ver = VERSION_GetVersion();
331     return VersionData[ver].getVersion32;
332 }
333
334
335 /***********************************************************************
336  *         GetVersionEx16   (KERNEL.149)
337  */
338 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
339 {
340     WINDOWS_VERSION ver = VERSION_GetVersion();
341     if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO16))
342     {
343         WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
344                         v->dwOSVersionInfoSize, sizeof(OSVERSIONINFO16));
345         SetLastError(ERROR_INSUFFICIENT_BUFFER);
346         return FALSE;
347     }
348     v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
349     v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
350     v->dwBuildNumber  = VersionData[ver].getVersionEx.dwBuildNumber;
351     v->dwPlatformId   = VersionData[ver].getVersionEx.dwPlatformId;
352     strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
353     return TRUE;
354 }
355
356
357 /***********************************************************************
358  *         GetVersionEx32A   (KERNEL32.428)
359  */
360 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
361 {
362     WINDOWS_VERSION ver = VERSION_GetVersion();
363     if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA))
364     {
365         WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
366                         v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA));
367         SetLastError(ERROR_INSUFFICIENT_BUFFER);
368         return FALSE;
369     }
370     v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
371     v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
372     v->dwBuildNumber  = VersionData[ver].getVersionEx.dwBuildNumber;
373     v->dwPlatformId   = VersionData[ver].getVersionEx.dwPlatformId;
374     strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
375     return TRUE;
376 }
377
378
379 /***********************************************************************
380  *         GetVersionEx32W   (KERNEL32.429)
381  */
382 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
383 {
384     WINDOWS_VERSION ver = VERSION_GetVersion();
385
386     if (v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFOW))
387     {
388         WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
389                         v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW));
390         SetLastError(ERROR_INSUFFICIENT_BUFFER);
391         return FALSE;
392     }
393     v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
394     v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
395     v->dwBuildNumber  = VersionData[ver].getVersionEx.dwBuildNumber;
396     v->dwPlatformId   = VersionData[ver].getVersionEx.dwPlatformId;
397     lstrcpyAtoW( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
398     return TRUE;
399 }
400
401
402 /***********************************************************************
403  *          GetWinFlags   (KERNEL.132)
404  */
405 DWORD WINAPI GetWinFlags16(void)
406 {
407   static const long cpuflags[5] =
408     { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
409   SYSTEM_INFO si;
410   OSVERSIONINFOA ovi;
411   DWORD result;
412
413   GetSystemInfo(&si);
414
415   /* There doesn't seem to be any Pentium flag.  */
416   result = cpuflags[MIN (si.wProcessorLevel, 4)];
417
418   switch(Options.mode)
419   {
420   case MODE_STANDARD:
421       result |= WF_STANDARD | WF_PMODE | WF_80x87;
422       break;
423
424   case MODE_ENHANCED:
425       result |= WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
426       break;
427
428   default:
429       ERR("Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
430       break;
431   }
432   if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
433   ovi.dwOSVersionInfoSize = sizeof(ovi);
434   GetVersionExA(&ovi);
435   if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
436       result |= WF_WIN32WOW; /* undocumented WF_WINNT */
437   return result;
438 }
439
440
441 /***********************************************************************
442  *          GetWinDebugInfo   (KERNEL.355)
443  */
444 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO *lpwdi, UINT16 flags)
445 {
446     FIXME("(%8lx,%d): stub returning 0\n",
447           (unsigned long)lpwdi, flags);
448     /* 0 means not in debugging mode/version */
449     /* Can this type of debugging be used in wine ? */
450     /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
451     return 0;
452 }
453
454
455 /***********************************************************************
456  *          SetWinDebugInfo   (KERNEL.356)
457  */
458 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO *lpwdi)
459 {
460     FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
461     /* 0 means not in debugging mode/version */
462     /* Can this type of debugging be used in wine ? */
463     /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
464     return 0;
465 }
466
467
468 /***********************************************************************
469  *           DebugFillBuffer                    (KERNEL.329)
470  *
471  * TODO:
472  * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
473  */
474 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
475 {
476         memset(lpBuffer, DBGFILL_BUFFER, wBytes);
477 }
478
479 /***********************************************************************
480  *           DiagQuery                          (KERNEL.339)
481  *
482  * returns TRUE if Win called with "/b" (bootlog.txt)
483  */
484 BOOL16 WINAPI DiagQuery16()
485 {
486         /* perhaps implement a Wine "/b" command line flag sometime ? */
487         return FALSE;
488 }
489
490 /***********************************************************************
491  *           DiagOutput                         (KERNEL.340)
492  *
493  * writes a debug string into <windir>\bootlog.txt
494  */
495 void WINAPI DiagOutput16(LPCSTR str)
496 {
497         /* FIXME */
498         DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));
499 }
500
501 /***********************************************************************
502  *           OaBuildVersion           [OLEAUT32.170]
503  */
504 UINT WINAPI OaBuildVersion()
505 {
506     WINDOWS_VERSION ver = VERSION_GetVersion();
507
508     FIXME("Please report to a.mohr@mailto.de if you get version error messages !\n");
509     switch(VersionData[ver].getVersion32)
510     {
511         case 0x80000a03: /* Win 3.1 */
512                 return 0x140fd1; /* from Win32s 1.1e */
513         case 0xc0000004: /* Win 95 */
514          case 0xc0000a04: /* Win 98: verified same as Win95 */
515                 return 0x1e10a9; /* some older version: 0x0a0bd3 */
516         case 0x04213303: /* NT 3.51 */
517                 FIXME("NT 3.51 version value unknown !\n");
518                 return 0x1e10a9; /* value borrowed from Win95 */
519         case 0x05650004: /* NT 4.0 */
520                 return 0x141016;
521         default:
522                 return 0x0;
523     }
524 }
525 /***********************************************************************
526  *        VERSION_OsIsUnicode   [internal]
527  *
528  * NOTES
529  *   some functions getting sometimes LPSTR sometimes LPWSTR...
530  *
531  */
532 BOOL VERSION_OsIsUnicode(void)
533 {
534     switch(VERSION_GetVersion())
535     {
536     case NT351:
537     case NT40:
538         return TRUE;
539     default:
540         return FALSE;
541     }
542 }