Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

win_shared.c

Go to the documentation of this file.
00001 /*
00002 ===========================================================================
00003 Copyright (C) 1999-2005 Id Software, Inc.
00004 
00005 This file is part of Quake III Arena source code.
00006 
00007 Quake III Arena source code is free software; you can redistribute it
00008 and/or modify it under the terms of the GNU General Public License as
00009 published by the Free Software Foundation; either version 2 of the License,
00010 or (at your option) any later version.
00011 
00012 Quake III Arena source code is distributed in the hope that it will be
00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Foobar; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 ===========================================================================
00021 */
00022 
00023 #include "../game/q_shared.h"
00024 #include "../qcommon/qcommon.h"
00025 #include "win_local.h"
00026 #include <lmerr.h>
00027 #include <lmcons.h>
00028 #include <lmwksta.h>
00029 #include <errno.h>
00030 #include <fcntl.h>
00031 #include <stdio.h>
00032 #include <direct.h>
00033 #include <io.h>
00034 #include <conio.h>
00035 
00036 /*
00037 ================
00038 Sys_Milliseconds
00039 ================
00040 */
00041 int         sys_timeBase;
00042 int Sys_Milliseconds (void)
00043 {
00044     int         sys_curtime;
00045     static qboolean initialized = qfalse;
00046 
00047     if (!initialized) {
00048         sys_timeBase = timeGetTime();
00049         initialized = qtrue;
00050     }
00051     sys_curtime = timeGetTime() - sys_timeBase;
00052 
00053     return sys_curtime;
00054 }
00055 
00056 /*
00057 ================
00058 Sys_SnapVector
00059 ================
00060 */
00061 long fastftol( float f ) {
00062     static int tmp;
00063     __asm fld f
00064     __asm fistp tmp
00065     __asm mov eax, tmp
00066 }
00067 
00068 void Sys_SnapVector( float *v )
00069 {
00070     int i;
00071     float f;
00072 
00073     f = *v;
00074     __asm   fld     f;
00075     __asm   fistp   i;
00076     *v = i;
00077     v++;
00078     f = *v;
00079     __asm   fld     f;
00080     __asm   fistp   i;
00081     *v = i;
00082     v++;
00083     f = *v;
00084     __asm   fld     f;
00085     __asm   fistp   i;
00086     *v = i;
00087     /*
00088     *v = fastftol(*v);
00089     v++;
00090     *v = fastftol(*v);
00091     v++;
00092     *v = fastftol(*v);
00093     */
00094 }
00095 
00096 
00097 /*
00098 **
00099 ** Disable all optimizations temporarily so this code works correctly!
00100 **
00101 */
00102 #pragma optimize( "", off )
00103 
00104 /*
00105 ** --------------------------------------------------------------------------------
00106 **
00107 ** PROCESSOR STUFF
00108 **
00109 ** --------------------------------------------------------------------------------
00110 */
00111 static void CPUID( int func, unsigned regs[4] )
00112 {
00113     unsigned regEAX, regEBX, regECX, regEDX;
00114 
00115 #ifndef __VECTORC
00116     __asm mov eax, func
00117     __asm __emit 00fh
00118     __asm __emit 0a2h
00119     __asm mov regEAX, eax
00120     __asm mov regEBX, ebx
00121     __asm mov regECX, ecx
00122     __asm mov regEDX, edx
00123 
00124     regs[0] = regEAX;
00125     regs[1] = regEBX;
00126     regs[2] = regECX;
00127     regs[3] = regEDX;
00128 #else
00129     regs[0] = 0;
00130     regs[1] = 0;
00131     regs[2] = 0;
00132     regs[3] = 0;
00133 #endif
00134 }
00135 
00136 static int IsPentium( void )
00137 {
00138     __asm 
00139     {
00140         pushfd                      // save eflags
00141         pop     eax
00142         test    eax, 0x00200000     // check ID bit
00143         jz      set21               // bit 21 is not set, so jump to set_21
00144         and     eax, 0xffdfffff     // clear bit 21
00145         push    eax                 // save new value in register
00146         popfd                       // store new value in flags
00147         pushfd
00148         pop     eax
00149         test    eax, 0x00200000     // check ID bit
00150         jz      good
00151         jmp     err                 // cpuid not supported
00152 set21:
00153         or      eax, 0x00200000     // set ID bit
00154         push    eax                 // store new value
00155         popfd                       // store new value in EFLAGS
00156         pushfd
00157         pop     eax
00158         test    eax, 0x00200000     // if bit 21 is on
00159         jnz     good
00160         jmp     err
00161     }
00162 
00163 err:
00164     return qfalse;
00165 good:
00166     return qtrue;
00167 }
00168 
00169 static int Is3DNOW( void )
00170 {
00171     unsigned regs[4];
00172     char pstring[16];
00173     char processorString[13];
00174 
00175     // get name of processor
00176     CPUID( 0, ( unsigned int * ) pstring );
00177     processorString[0] = pstring[4];
00178     processorString[1] = pstring[5];
00179     processorString[2] = pstring[6];
00180     processorString[3] = pstring[7];
00181     processorString[4] = pstring[12];
00182     processorString[5] = pstring[13];
00183     processorString[6] = pstring[14];
00184     processorString[7] = pstring[15];
00185     processorString[8] = pstring[8];
00186     processorString[9] = pstring[9];
00187     processorString[10] = pstring[10];
00188     processorString[11] = pstring[11];
00189     processorString[12] = 0;
00190 
00191 //  REMOVED because you can have 3DNow! on non-AMD systems
00192 //  if ( strcmp( processorString, "AuthenticAMD" ) )
00193 //      return qfalse;
00194 
00195     // check AMD-specific functions
00196     CPUID( 0x80000000, regs );
00197     if ( regs[0] < 0x80000000 )
00198         return qfalse;
00199 
00200     // bit 31 of EDX denotes 3DNOW! support
00201     CPUID( 0x80000001, regs );
00202     if ( regs[3] & ( 1 << 31 ) )
00203         return qtrue;
00204 
00205     return qfalse;
00206 }
00207 
00208 static int IsKNI( void )
00209 {
00210     unsigned regs[4];
00211 
00212     // get CPU feature bits
00213     CPUID( 1, regs );
00214 
00215     // bit 25 of EDX denotes KNI existence
00216     if ( regs[3] & ( 1 << 25 ) )
00217         return qtrue;
00218 
00219     return qfalse;
00220 }
00221 
00222 static int IsMMX( void )
00223 {
00224     unsigned regs[4];
00225 
00226     // get CPU feature bits
00227     CPUID( 1, regs );
00228 
00229     // bit 23 of EDX denotes MMX existence
00230     if ( regs[3] & ( 1 << 23 ) )
00231         return qtrue;
00232     return qfalse;
00233 }
00234 
00235 int Sys_GetProcessorId( void )
00236 {
00237 #if defined _M_ALPHA
00238     return CPUID_AXP;
00239 #elif !defined _M_IX86
00240     return CPUID_GENERIC;
00241 #else
00242 
00243     // verify we're at least a Pentium or 486 w/ CPUID support
00244     if ( !IsPentium() )
00245         return CPUID_INTEL_UNSUPPORTED;
00246 
00247     // check for MMX
00248     if ( !IsMMX() )
00249     {
00250         // Pentium or PPro
00251         return CPUID_INTEL_PENTIUM;
00252     }
00253 
00254     // see if we're an AMD 3DNOW! processor
00255     if ( Is3DNOW() )
00256     {
00257         return CPUID_AMD_3DNOW;
00258     }
00259 
00260     // see if we're an Intel Katmai
00261     if ( IsKNI() )
00262     {
00263         return CPUID_INTEL_KATMAI;
00264     }
00265 
00266     // by default we're functionally a vanilla Pentium/MMX or P2/MMX
00267     return CPUID_INTEL_MMX;
00268 
00269 #endif
00270 }
00271 
00272 /*
00273 **
00274 ** Re-enable optimizations back to what they were
00275 **
00276 */
00277 #pragma optimize( "", on )
00278 
00279 //============================================
00280 
00281 char *Sys_GetCurrentUser( void )
00282 {
00283     static char s_userName[1024];
00284     unsigned long size = sizeof( s_userName );
00285 
00286 
00287     if ( !GetUserName( s_userName, &size ) )
00288         strcpy( s_userName, "player" );
00289 
00290     if ( !s_userName[0] )
00291     {
00292         strcpy( s_userName, "player" );
00293     }
00294 
00295     return s_userName;
00296 }
00297 
00298 char    *Sys_DefaultHomePath(void) {
00299     return NULL;
00300 }
00301 
00302 char *Sys_DefaultInstallPath(void)
00303 {
00304     return Sys_Cwd();
00305 }
00306 

Generated on Thu Aug 25 12:38:06 2005 for Quake III Arena by  doxygen 1.3.9.1