2003-11-03 17:22:45 +01:00
|
|
|
// system detect
|
|
|
|
//
|
|
|
|
// Copyright (c) 2003 Jan Wassenberg
|
|
|
|
//
|
2004-03-03 01:44:06 +01:00
|
|
|
// This file is free software; you can redistribute it and/or
|
2003-11-03 17:22:45 +01:00
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
2004-03-03 01:44:06 +01:00
|
|
|
// This file is distributed in the hope that it will be useful, but
|
2003-11-03 17:22:45 +01:00
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// Contact info:
|
|
|
|
// Jan.Wassenberg@stud.uni-karlsruhe.de
|
|
|
|
// http://www.stud.uni-karlsruhe.de/~urkt/
|
|
|
|
|
|
|
|
// things missing in POSIX, SDL, and OpenGL :P
|
2004-03-03 01:44:06 +01:00
|
|
|
// large platform-specific routines (e.g. CPU or gfx card info)
|
|
|
|
// are split out of here.
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2004-05-08 03:11:51 +02:00
|
|
|
#include "precompiled.h"
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2004-03-03 01:44:06 +01:00
|
|
|
#include "lib.h"
|
2003-11-03 17:22:45 +01:00
|
|
|
#include "detect.h"
|
2004-05-08 03:11:51 +02:00
|
|
|
#include "timer.h"
|
2004-05-26 01:16:21 +02:00
|
|
|
|
2004-03-04 21:36:31 +01:00
|
|
|
#ifdef _M_IX86
|
2004-05-26 01:16:21 +02:00
|
|
|
extern void ia32_get_cpu_info();
|
2004-03-04 21:36:31 +01:00
|
|
|
#endif
|
2004-05-08 03:11:51 +02:00
|
|
|
|
2004-05-26 01:16:21 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
extern int win_get_gfx_info();
|
2004-03-03 01:44:06 +01:00
|
|
|
extern int win_get_cpu_info();
|
2004-05-26 01:16:21 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
extern "C" int ogl_get_gfx_info();
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2004-03-03 01:44:06 +01:00
|
|
|
//
|
|
|
|
// memory
|
|
|
|
//
|
2003-11-03 17:22:45 +01:00
|
|
|
|
|
|
|
size_t tot_mem = 0;
|
|
|
|
size_t avl_mem = 0;
|
|
|
|
|
2003-11-12 15:47:38 +01:00
|
|
|
size_t page_size = 0;
|
|
|
|
|
2003-11-03 17:22:45 +01:00
|
|
|
void get_mem_status()
|
|
|
|
{
|
2003-11-12 15:47:38 +01:00
|
|
|
#ifdef _SC_PAGESIZE
|
2004-03-03 01:44:06 +01:00
|
|
|
if(!page_size)
|
|
|
|
page_size = (size_t)sysconf(_SC_PAGESIZE);
|
2003-11-12 15:47:38 +01:00
|
|
|
#endif
|
|
|
|
|
2003-11-03 17:22:45 +01:00
|
|
|
// Sys V derived (GNU/Linux, Solaris)
|
2003-11-12 15:47:38 +01:00
|
|
|
#ifdef _SC_AVPHYS_PAGES
|
2003-11-03 17:22:45 +01:00
|
|
|
|
|
|
|
tot_mem = sysconf(_SC_PHYS_PAGES ) * page_size;
|
|
|
|
avl_mem = sysconf(_SC_AVPHYS_PAGES) * page_size;
|
|
|
|
|
|
|
|
// BSD / Mac OS X
|
|
|
|
#elif HAVE_SYSCTL && defined(HW_PHYSMEM)
|
|
|
|
|
|
|
|
size_t len = sizeof(tot_mem);
|
|
|
|
int mib[2] = { CTL_HW, HW_PHYSMEM };
|
|
|
|
sysctl(mib, 2, &tot_mem, &len, 0, 0);
|
|
|
|
mib[1] = HW_USERMEM;
|
|
|
|
sysctl(mib, 2, &avl_mem, &len, 0, 0);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-03-03 01:44:06 +01:00
|
|
|
//
|
|
|
|
// graphics card
|
|
|
|
//
|
|
|
|
|
2004-05-26 01:16:21 +02:00
|
|
|
char gfx_card[64] = "";
|
|
|
|
char gfx_drv_ver[64] = "";
|
2003-11-03 17:22:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
// attempt to detect graphics card without OpenGL (in case ogl init fails,
|
|
|
|
// or we want more detailed info). gfx_card[] is unchanged on failure.
|
2004-03-04 21:36:31 +01:00
|
|
|
void get_gfx_info()
|
2003-11-03 17:22:45 +01:00
|
|
|
{
|
2004-05-26 01:16:21 +02:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
// try platform-specific versions first: they return more
|
|
|
|
// detailed information, and don't require OpenGL to be ready.
|
|
|
|
|
2003-11-03 17:22:45 +01:00
|
|
|
#ifdef _WIN32
|
2004-05-26 01:16:21 +02:00
|
|
|
ret = win_get_gfx_info();
|
2003-11-03 17:22:45 +01:00
|
|
|
#endif
|
2004-05-26 01:16:21 +02:00
|
|
|
|
|
|
|
// success; done.
|
|
|
|
if(ret == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// the OpenGL version should always work, unless OpenGL isn't ready for use,
|
|
|
|
// or we were called between glBegin and glEnd.
|
|
|
|
ogl_get_gfx_info();
|
2003-11-03 17:22:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// CPU
|
|
|
|
//
|
|
|
|
|
2004-05-26 01:16:21 +02:00
|
|
|
char cpu_type[64] = ""; // processor brand string is 48 chars
|
2003-11-03 17:22:45 +01:00
|
|
|
double cpu_freq = 0.f;
|
|
|
|
|
|
|
|
// -1 if detect not yet called, or cannot be determined
|
|
|
|
int cpus = -1;
|
2004-03-03 01:44:06 +01:00
|
|
|
int cpu_speedstep = -1;
|
2003-11-03 17:22:45 +01:00
|
|
|
|
|
|
|
|
2004-03-03 01:44:06 +01:00
|
|
|
static inline void get_cpu_info()
|
2003-11-03 17:22:45 +01:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
2004-03-03 01:44:06 +01:00
|
|
|
win_get_cpu_info();
|
|
|
|
#endif
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2004-03-03 01:44:06 +01:00
|
|
|
#ifdef _M_IX86
|
|
|
|
ia32_get_cpu_info();
|
2003-11-03 17:22:45 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-03 01:44:06 +01:00
|
|
|
|
|
|
|
|
2003-11-03 17:22:45 +01:00
|
|
|
void detect()
|
|
|
|
{
|
|
|
|
get_mem_status();
|
2004-03-03 01:44:06 +01:00
|
|
|
get_gfx_info();
|
2003-11-03 17:22:45 +01:00
|
|
|
get_cpu_info();
|
|
|
|
}
|