67 lines
1.9 KiB
C
67 lines
1.9 KiB
C
|
|
#include <SDL.h>
|
|
|
|
#include "api.h"
|
|
|
|
void print_stats(enum ps ps) {
|
|
int procs = SDL_GetCPUCount();
|
|
int d ;
|
|
int L1;
|
|
char L1suf[6];
|
|
char dsuf[3];
|
|
SDL_PowerState pwr;
|
|
int psec;//seconds of battery life left
|
|
int ppct;//percentage of battery life left
|
|
char psecsuf[8];
|
|
const char*pwrdesc;
|
|
/*--system RAM--*/
|
|
d = SDL_GetSystemRAM();
|
|
if(d>1024) {
|
|
d /= 1024;
|
|
memcpy(dsuf,"gb",3);
|
|
}
|
|
else memcpy(dsuf,"mb",3);
|
|
/*--L1--*/
|
|
L1 = SDL_GetCPUCacheLineSize();
|
|
if(L1>1024*1024) {
|
|
L1 /= 1024 * 1024;
|
|
memcpy(L1suf,"mb",3);
|
|
} else if(L1>1024) {
|
|
L1 /= 1024;
|
|
memcpy(L1suf,"kb",3);
|
|
} else {
|
|
memcpy(L1suf,"bytes",6);
|
|
}
|
|
/*--power state--*/
|
|
pwr = SDL_GetPowerInfo(&psec, &ppct);
|
|
if(psec == -1) psec = 60*60;
|
|
if(psec>=60*60) {
|
|
psec /= 60*60;
|
|
memcpy(psecsuf,psec>1?"hours":"hour\0\0",6);
|
|
} else if(psec>=60) {
|
|
psec /= 60;
|
|
memcpy(psecsuf,psec>1?"minutes":"minute\0\0",8);
|
|
} else {
|
|
memcpy(psecsuf,psec>1?"seconds":"second\0\0",8);
|
|
}
|
|
switch(pwr){
|
|
case SDL_POWERSTATE_ON_BATTERY: pwrdesc="not plugged in, running on the battery";break;
|
|
case SDL_POWERSTATE_NO_BATTERY: pwrdesc="plugged in, no battery available";break;
|
|
case SDL_POWERSTATE_CHARGING: pwrdesc="plugged in, charging battery";break;
|
|
case SDL_POWERSTATE_CHARGED: pwrdesc="plugged in, battery charged";break;
|
|
default:
|
|
case SDL_POWERSTATE_UNKNOWN: pwrdesc="cannot determine power status";
|
|
}
|
|
/*--print stats--*/
|
|
switch(ps){
|
|
case ps_shutdown:
|
|
printf("SDL Quit Battery %d%% (%d%s)\n",ppct,psec,psecsuf);
|
|
break;
|
|
default:
|
|
case ps_startup:
|
|
printf("SDL %s %d%sRAM %dProc%s (L1align=%d%s) Battery %d%% (%d%s)\n",SDL_GetPlatform(),d,dsuf,procs,procs>1?"s":"",L1,L1suf,
|
|
ppct,psec,psecsuf);
|
|
}
|
|
|
|
}
|