蹲一个代码大佬。
https://github.com/esmjanus/snes9xTYL/blob/6ce09a0ada7cc10b57ab8d7134385f44f29a9629/psp/menu.c#L1247
void show_batteryinfo()
{
static int update_infos = 0;
static char bat_info[128];
struct tm *tsys;
time_t cur_time;
char lifeTimeStr[16], tempStr[8];
int lifeTime, temp;
if (!((update_infos >> 3) & 1)) {
//get current time
sceKernelLibcTime(&cur_time);
cur_time += os9x_timezone * 60 + os9x_daylsavings * 3600;
tsys = localtime(&cur_time);
if (scePowerIsBatteryExist()) {
//if exists battery, gather infos
lifeTime = scePowerGetBatteryLifeTime();
if (lifeTime > 0)
sprintf(lifeTimeStr, s9xTYL_msg[MENU_TITLE_GENERIC_BAT_TIME],
lifeTime / 60, lifeTime % 60);
else
lifeTimeStr[0] = 0;
temp = scePowerGetBatteryTemp();
if (temp > 0)
sprintf(tempStr, s9xTYL_msg[MENU_TITLE_GENERIC_BAT_TEMP], temp);
else
tempStr[0] = 0;
sprintf(bat_info, "%02d%c%02d %s:%s%s%s %02d%%%s%s",
tsys->tm_hour, (tsys->tm_sec & 1 ? ':' : ' '), tsys->tm_min,
s9xTYL_msg[MENU_TITLE_GENERIC_BAT],
(scePowerIsPowerOnline() ? s9xTYL_msg[MENU_TITLE_GENERIC_BAT_PLG] : ""),
(scePowerIsBatteryCharging() ? s9xTYL_msg[MENU_TITLE_GENERIC_BAT_CHRG] : ""),
(scePowerIsLowBattery() ? s9xTYL_msg[MENU_TITLE_GENERIC_BAT_LOW] : ""),
scePowerGetBatteryLifePercent(),
lifeTimeStr, tempStr);
} else
sprintf(bat_info, "%02d%c%02d",
tsys->tm_hour, (tsys->tm_sec & 1 ? ':' : ' '), tsys->tm_min);
}
update_infos++;
mh_print(479 - strlen(bat_info) * 6, 0, bat_info,
(22 << 0) | (31 << 5) | (22 << 10));
}