21 #include "../../SDL_internal.h" 26 #ifndef SDL_POWER_DISABLED 34 #include <drivers/Drivers.h> 37 #define APM_DEVICE_PATH "/dev/misc/apm" 38 #define APM_FUNC_OFFSET 0x5300 39 #define APM_FUNC_GET_POWER_STATUS 10 40 #define APM_DEVICE_ALL 1 41 #define APM_BIOS_CALL (B_DEVICE_OP_CODES_END + 3) 48 const int fd = open(
"/dev/misc/apm", O_RDONLY);
62 memset(regs,
'\0',
sizeof(regs));
63 regs[0] = APM_FUNC_OFFSET + APM_FUNC_GET_POWER_STATUS;
64 regs[1] = APM_DEVICE_ALL;
65 rc = ioctl(fd, APM_BIOS_CALL, regs);
72 ac_status = regs[1] >> 8;
73 battery_status = regs[1] & 0xFF;
74 battery_flags = regs[2] >> 8;
75 battery_life = regs[2] & 0xFF;
76 battery_time = (uint32) regs[3];
79 if (battery_flags == 0x00) {
80 battery_time = 0xFFFF;
81 if (battery_status == 0xFF) {
84 battery_flags = (1 << battery_status);
88 if ((battery_time != 0xFFFF) && (battery_time & (1 << 15))) {
90 battery_time = (battery_time & 0x7FFF) * 60;
93 if (battery_flags == 0xFF) {
95 }
else if (battery_flags & (1 << 7)) {
97 }
else if (battery_flags & (1 << 3)) {
100 }
else if (ac_status == 1) {
111 const int pct = (int) battery_life;
112 const int secs = (int) battery_time;
115 *percent = (pct > 100) ? 100 : pct;
117 if (secs != 0xFFFF) {
SDL_bool SDL_GetPowerInfo_Haiku(SDL_PowerState *, int *, int *)
SDL_PowerState
The basic state for the system's power supply.