00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
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
00089
00090
00091
00092
00093
00094 }
00095
00096
00097
00098
00099
00100
00101
00102 #pragma optimize( "", off )
00103
00104
00105
00106
00107
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
00141 pop eax
00142 test eax, 0x00200000
00143 jz set21
00144 and eax, 0xffdfffff
00145 push eax
00146 popfd
00147 pushfd
00148 pop eax
00149 test eax, 0x00200000
00150 jz good
00151 jmp err
00152 set21:
00153 or eax, 0x00200000
00154 push eax
00155 popfd
00156 pushfd
00157 pop eax
00158 test eax, 0x00200000
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
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
00192
00193
00194
00195
00196 CPUID( 0x80000000, regs );
00197 if ( regs[0] < 0x80000000 )
00198 return qfalse;
00199
00200
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
00213 CPUID( 1, regs );
00214
00215
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
00227 CPUID( 1, regs );
00228
00229
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
00244 if ( !IsPentium() )
00245 return CPUID_INTEL_UNSUPPORTED;
00246
00247
00248 if ( !IsMMX() )
00249 {
00250
00251 return CPUID_INTEL_PENTIUM;
00252 }
00253
00254
00255 if ( Is3DNOW() )
00256 {
00257 return CPUID_AMD_3DNOW;
00258 }
00259
00260
00261 if ( IsKNI() )
00262 {
00263 return CPUID_INTEL_KATMAI;
00264 }
00265
00266
00267 return CPUID_INTEL_MMX;
00268
00269 #endif
00270 }
00271
00272
00273
00274
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