win_shared.c (5877B)
1 /* 2 =========================================================================== 3 Copyright (C) 1999-2005 Id Software, Inc. 4 5 This file is part of Quake III Arena source code. 6 7 Quake III Arena source code is free software; you can redistribute it 8 and/or modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the License, 10 or (at your option) any later version. 11 12 Quake III Arena source code is distributed in the hope that it will be 13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Foobar; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 =========================================================================== 21 */ 22 23 #include "../game/q_shared.h" 24 #include "../qcommon/qcommon.h" 25 #include "win_local.h" 26 #include <lmerr.h> 27 #include <lmcons.h> 28 #include <lmwksta.h> 29 #include <errno.h> 30 #include <fcntl.h> 31 #include <stdio.h> 32 #include <direct.h> 33 #include <io.h> 34 #include <conio.h> 35 36 /* 37 ================ 38 Sys_Milliseconds 39 ================ 40 */ 41 int sys_timeBase; 42 int Sys_Milliseconds (void) 43 { 44 int sys_curtime; 45 static qboolean initialized = qfalse; 46 47 if (!initialized) { 48 sys_timeBase = timeGetTime(); 49 initialized = qtrue; 50 } 51 sys_curtime = timeGetTime() - sys_timeBase; 52 53 return sys_curtime; 54 } 55 56 /* 57 ================ 58 Sys_SnapVector 59 ================ 60 */ 61 long fastftol( float f ) { 62 static int tmp; 63 __asm fld f 64 __asm fistp tmp 65 __asm mov eax, tmp 66 } 67 68 void Sys_SnapVector( float *v ) 69 { 70 int i; 71 float f; 72 73 f = *v; 74 __asm fld f; 75 __asm fistp i; 76 *v = i; 77 v++; 78 f = *v; 79 __asm fld f; 80 __asm fistp i; 81 *v = i; 82 v++; 83 f = *v; 84 __asm fld f; 85 __asm fistp i; 86 *v = i; 87 /* 88 *v = fastftol(*v); 89 v++; 90 *v = fastftol(*v); 91 v++; 92 *v = fastftol(*v); 93 */ 94 } 95 96 97 /* 98 ** 99 ** Disable all optimizations temporarily so this code works correctly! 100 ** 101 */ 102 #pragma optimize( "", off ) 103 104 /* 105 ** -------------------------------------------------------------------------------- 106 ** 107 ** PROCESSOR STUFF 108 ** 109 ** -------------------------------------------------------------------------------- 110 */ 111 static void CPUID( int func, unsigned regs[4] ) 112 { 113 unsigned regEAX, regEBX, regECX, regEDX; 114 115 #ifndef __VECTORC 116 __asm mov eax, func 117 __asm __emit 00fh 118 __asm __emit 0a2h 119 __asm mov regEAX, eax 120 __asm mov regEBX, ebx 121 __asm mov regECX, ecx 122 __asm mov regEDX, edx 123 124 regs[0] = regEAX; 125 regs[1] = regEBX; 126 regs[2] = regECX; 127 regs[3] = regEDX; 128 #else 129 regs[0] = 0; 130 regs[1] = 0; 131 regs[2] = 0; 132 regs[3] = 0; 133 #endif 134 } 135 136 static int IsPentium( void ) 137 { 138 __asm 139 { 140 pushfd // save eflags 141 pop eax 142 test eax, 0x00200000 // check ID bit 143 jz set21 // bit 21 is not set, so jump to set_21 144 and eax, 0xffdfffff // clear bit 21 145 push eax // save new value in register 146 popfd // store new value in flags 147 pushfd 148 pop eax 149 test eax, 0x00200000 // check ID bit 150 jz good 151 jmp err // cpuid not supported 152 set21: 153 or eax, 0x00200000 // set ID bit 154 push eax // store new value 155 popfd // store new value in EFLAGS 156 pushfd 157 pop eax 158 test eax, 0x00200000 // if bit 21 is on 159 jnz good 160 jmp err 161 } 162 163 err: 164 return qfalse; 165 good: 166 return qtrue; 167 } 168 169 static int Is3DNOW( void ) 170 { 171 unsigned regs[4]; 172 char pstring[16]; 173 char processorString[13]; 174 175 // get name of processor 176 CPUID( 0, ( unsigned int * ) pstring ); 177 processorString[0] = pstring[4]; 178 processorString[1] = pstring[5]; 179 processorString[2] = pstring[6]; 180 processorString[3] = pstring[7]; 181 processorString[4] = pstring[12]; 182 processorString[5] = pstring[13]; 183 processorString[6] = pstring[14]; 184 processorString[7] = pstring[15]; 185 processorString[8] = pstring[8]; 186 processorString[9] = pstring[9]; 187 processorString[10] = pstring[10]; 188 processorString[11] = pstring[11]; 189 processorString[12] = 0; 190 191 // REMOVED because you can have 3DNow! on non-AMD systems 192 // if ( strcmp( processorString, "AuthenticAMD" ) ) 193 // return qfalse; 194 195 // check AMD-specific functions 196 CPUID( 0x80000000, regs ); 197 if ( regs[0] < 0x80000000 ) 198 return qfalse; 199 200 // bit 31 of EDX denotes 3DNOW! support 201 CPUID( 0x80000001, regs ); 202 if ( regs[3] & ( 1 << 31 ) ) 203 return qtrue; 204 205 return qfalse; 206 } 207 208 static int IsKNI( void ) 209 { 210 unsigned regs[4]; 211 212 // get CPU feature bits 213 CPUID( 1, regs ); 214 215 // bit 25 of EDX denotes KNI existence 216 if ( regs[3] & ( 1 << 25 ) ) 217 return qtrue; 218 219 return qfalse; 220 } 221 222 static int IsMMX( void ) 223 { 224 unsigned regs[4]; 225 226 // get CPU feature bits 227 CPUID( 1, regs ); 228 229 // bit 23 of EDX denotes MMX existence 230 if ( regs[3] & ( 1 << 23 ) ) 231 return qtrue; 232 return qfalse; 233 } 234 235 int Sys_GetProcessorId( void ) 236 { 237 #if defined _M_ALPHA 238 return CPUID_AXP; 239 #elif !defined _M_IX86 240 return CPUID_GENERIC; 241 #else 242 243 // verify we're at least a Pentium or 486 w/ CPUID support 244 if ( !IsPentium() ) 245 return CPUID_INTEL_UNSUPPORTED; 246 247 // check for MMX 248 if ( !IsMMX() ) 249 { 250 // Pentium or PPro 251 return CPUID_INTEL_PENTIUM; 252 } 253 254 // see if we're an AMD 3DNOW! processor 255 if ( Is3DNOW() ) 256 { 257 return CPUID_AMD_3DNOW; 258 } 259 260 // see if we're an Intel Katmai 261 if ( IsKNI() ) 262 { 263 return CPUID_INTEL_KATMAI; 264 } 265 266 // by default we're functionally a vanilla Pentium/MMX or P2/MMX 267 return CPUID_INTEL_MMX; 268 269 #endif 270 } 271 272 /* 273 ** 274 ** Re-enable optimizations back to what they were 275 ** 276 */ 277 #pragma optimize( "", on ) 278 279 //============================================ 280 281 char *Sys_GetCurrentUser( void ) 282 { 283 static char s_userName[1024]; 284 unsigned long size = sizeof( s_userName ); 285 286 287 if ( !GetUserName( s_userName, &size ) ) 288 strcpy( s_userName, "player" ); 289 290 if ( !s_userName[0] ) 291 { 292 strcpy( s_userName, "player" ); 293 } 294 295 return s_userName; 296 } 297 298 char *Sys_DefaultHomePath(void) { 299 return NULL; 300 } 301 302 char *Sys_DefaultInstallPath(void) 303 { 304 return Sys_Cwd(); 305 } 306