www.pudn.com > Gimcrack-v0.0051-Source.zip > compinfo.cpp
#include "compinfo.h" #include "../global.h" #include//////////////////////////////////////////////////////////////////////////// GcCompchar::GcCompchar() { // Get the computer's cabaplities and speed cpuSpeed = GetCPUSpeed(); cpuCaps = GetCPUCaps(); hasMMX = (GetCPUCaps() & CPU_FEATURE_MMX) != 0; GetWindowsVersion(); GlobalMemoryStatus(&meminfo); } //////////////////////////////////////////////////////////////////////////// GcCompchar::~GcCompchar() { } //////////////////////////////////////////////////////////////////////////// int GcCompchar::GetCPUSpeed(void) { DWORD dwFeatures; DWORD dwStartTime; DWORD dwStopTime; __int64 i64StartTicks; __int64 i64EndTicks; __int64 i64TotalTicks; int iSpeed; // Get the capabilities of the cpu. dwFeatures = GetCPUCaps(); // The rdtsc instruction must be available. if ( !( dwFeatures & CPU_FEATURE_RDTSC ) ) return -1; // Get the start time. dwStartTime = timeGetTime(); // // Wait for a new millisecond to start. // do { dwStopTime = timeGetTime(); } while ( ( dwStopTime - dwStartTime ) == 0 ); // Use the new start time. dwStartTime = dwStopTime; // // Get the start tick count. // __asm { // // Save registers. // push eax push ebx push edx // // Get the tick count. // rdtsc lea ebx, i64StartTicks mov [ebx], eax mov [ebx + 4], edx // // Restore registers. // pop edx pop ebx pop eax } // // Loop till time´s up. // while ( true ) { // If one second is over ... if ( ( timeGetTime() - dwStartTime ) >= 1000 ) { // // ... get the end tick count. // __asm { // // Save registers. // push eax push ebx push edx // // Get the tick count. // rdtsc lea ebx, i64EndTicks mov [ebx], eax mov [ebx + 4], edx // // Restore registers. // pop edx pop ebx pop eax } break; } } // Calculate the difference in clock ticks. i64TotalTicks = i64EndTicks - i64StartTicks; // Calculate the speed in Mhz. iSpeed = (int)(i64TotalTicks / 1000000); // Return the speed in Mhz. return iSpeed; } //////////////////////////////////////////////////////////////////////////// DWORD GcCompchar::GetCPUCaps(void) { SYSTEM_INFO si; DWORD dwFeatures; // Assume no features are present. dwFeatures = 0; // Get the system information. GetSystemInfo(&si); // If this is at least a pentium or compatibel ... if (si.dwProcessorType != PROCESSOR_INTEL_386 && si.dwProcessorType != PROCESSOR_INTEL_486) { // // ... get the features. // __asm { // // Save registers. // push eax push ebx push ecx push edx // // Get the features. // mov eax, 1 cpuid mov dwFeatures, edx // // Restore registers. // pop edx pop ecx pop ebx pop eax } } // Return the features. return dwFeatures; } //////////////////////////////////////////////////////////////////////////// void GcCompchar::GetWindowsVersion() { // Set the size of the struct osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); // Get the version GetVersionEx(&osinfo); } //////////////////////////////////////////////////////////////////////////// void GcCompchar::LogCompCharac() { /* Write the CPU stat to the log file */ g_Debug->Log("----------------- System -------------------\n"); // Check for OS version if((osinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) && (osinfo.dwMajorVersion == 4) && (osinfo.dwMinorVersion == 0)) { g_Debug->Log("Windows 95 %s %d\n", osinfo.szCSDVersion, osinfo.dwBuildNumber); } else if((osinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) && (osinfo.dwMajorVersion == 4) && (osinfo.dwMinorVersion > 0)) { g_Debug->Log("Windows 98 %s %d\n", osinfo.szCSDVersion, osinfo.dwBuildNumber); } else if(osinfo.dwPlatformId == VER_PLATFORM_WIN32_NT) { g_Debug->Log("Windows NT %d %s %d\n", osinfo.dwMajorVersion, osinfo.szCSDVersion, osinfo.dwBuildNumber); } else { g_Debug->Log("Unidentified OS: %d %d %d %s %d\n", osinfo.dwPlatformId, osinfo.dwMajorVersion, osinfo.dwMinorVersion, osinfo.szCSDVersion, osinfo.dwBuildNumber); } // Write memory info to the log g_Debug->Log("\nPhysical memory: %d Mb\n", meminfo.dwTotalPhys / 1024 / 1024); g_Debug->Log("Available memory: %d Mb\n", meminfo.dwAvailPhys / 1024 / 1024); g_Debug->Log("Virtual memory: %d Mb\n", meminfo.dwTotalVirtual / 1024 / 1024); g_Debug->Log("Available memory: %d Mb\n\n", meminfo.dwAvailVirtual / 1024 / 1024); // Write the cpu info to the log file g_Debug->Log("CPU Speed: %d MHz\n", cpuSpeed); if(cpuCaps & CPU_FEATURE_MMX) { g_Debug->Log("MMX: Yes\n"); } else { g_Debug->Log("MMX: No\n"); } if(cpuCaps & CPU_FEATURE_RDTSC) { g_Debug->Log("RDTSC: Yes\n"); } else { g_Debug->Log("RDTSC: No\n"); } // Write the open gl info to the logfile g_Debug->Log("\nOpenGL Vendor: "); g_Debug->Log((char*)glGetString(GL_VENDOR)); g_Debug->Log("\n"); g_Debug->Log("OpenGL Version: "); g_Debug->Log((char*)glGetString(GL_VERSION)); g_Debug->Log("\n"); g_Debug->Log("Graphic Card: "); g_Debug->Log((char*)glGetString(GL_RENDERER)); g_Debug->Log("\n"); g_Debug->Log("--------------------------------------------\n\n"); } ////////////////////////////////////////////////////////////////////////////