Mercurial > sdl-ios-xcode
annotate src/power/os2/SDL_syspower.c @ 3196:413672b09bb3
Fixed some compile errors and warnings under Visual C++
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 12 Jun 2009 08:41:48 +0000 |
parents | 51750b7a966f |
children |
rev | line source |
---|---|
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 /* |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 Copyright (C) 1997-2009 Sam Lantinga |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 Sam Lantinga |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 /* !!! FIXME: |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 * Please note that this code has not been tested (or even compiled!). It |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 * should, in theory, run on any version of OS/2, and work with any system |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 * that has APM.SYS loaded. I don't know if ACPI.SYS works. |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 #ifndef SDL_POWER_DISABLED |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 #ifdef SDL_POWER_OS2 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 #define INCL_DOSFILEMGR |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 #define INCL_DOSDEVICES |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 #define INCL_DOSDEVIOCTL |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 #define INCL_DOSERRORS |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 #include <os2.h> |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 #include "SDL_power.h" |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 |
3186 | 41 typedef struct |
42 { | |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 USHORT len; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 USHORT flags; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 UCHAR ac_status; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 UCHAR battery_status; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 UCHAR battery_life; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 UCHAR battery_time_form; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 USHORT battery_time; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 UCHAR battery_flags; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 } PowerStatus; |
3186 | 52 extern int CompilerAssertPowerStatus[(sizeof(PowerStatus) == 10) ? 1 : -1]; |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 SDL_bool |
3186 | 56 SDL_GetPowerInfo_OS2(SDL_PowerState * state, int *seconds, int *percent) |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 PowerStatus status; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 HFILE hfile = 0; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 ULONG action = 0; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 APIRET rc = 0; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 *state = SDL_POWERSTATE_UNKNOWN; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 *percent = -1; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 *seconds = -1; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 /* open the power management device */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 rc = DosOpen("APM$", &hfile, &action, 0, FILE_NORMAL, FILE_OPEN, |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, 0); |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 if (rc == NO_ERROR) { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 USHORT iorc = 0; |
3186 | 73 ULONG iorclen = sizeof(iorc); |
74 ULONG statuslen = sizeof(status); | |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
3186 | 76 SDL_memset(&status, '\0', sizeof(status)); |
77 status.len = sizeof(status); | |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
79 rc = DosDevIOCtl(hfile, IOCTL_POWER, POWER_GETPOWERSTATUS, &status, |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 statuslen, &statuslen, &iorc, iorclen, &iorclen); |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 DosClose(hfile); |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
82 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 /* (status.flags & 0x1) == power subsystem enabled. */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 if ((rc == NO_ERROR) && (status.flags & 0x1)) { |
3186 | 85 if (statuslen == 7) { /* older OS/2 APM driver? Less fields. */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 status.battery_time_form = 0xFF; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 status.battery_time = 0; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 if (status.battery_status == 0xFF) { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 status.battery_flags = 0xFF; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 } else { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 status.battery_flags = (1 << status.battery_status); |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
93 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
94 |
3186 | 95 if (status.battery_flags == 0xFF) { /* unknown state */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 *state = SDL_POWERSTATE_UNKNOWN; |
3186 | 97 } else if (status.battery_flags & (1 << 7)) { /* no battery */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
98 *state = SDL_POWERSTATE_NO_BATTERY; |
3186 | 99 } else if (status.battery_flags & (1 << 3)) { /* charging */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 *state = SDL_POWERSTATE_CHARGING; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
101 need_details = SDL_TRUE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
102 } else if (status.ac_status == 1) { |
3186 | 103 *state = SDL_POWERSTATE_CHARGED; /* on AC, not charging. */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
104 need_details = SDL_TRUE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
105 } else { |
3186 | 106 *state = SDL_POWERSTATE_ON_BATTERY; /* not on AC. */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
107 need_details = SDL_TRUE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
108 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
109 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
110 if (need_details) { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 const int pct = (int) status.battery_life; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
112 const int secs = (int) status.battery_time; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 |
3186 | 114 if (pct != 0xFF) { /* 255 == unknown */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
115 *percent = (pct > 100) ? 100 : pct; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
116 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 |
3186 | 118 if (status.battery_time_form == 0xFF) { /* unknown */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 *seconds = -1; |
3186 | 120 } else if (status.battery_time_form == 1) { /* minutes */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 *seconds = secs * 60; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 } else { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 *seconds = secs; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
124 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
125 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
127 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
128 |
3186 | 129 return SDL_TRUE; /* always the definitive answer on OS/2. */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
130 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
131 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
132 #endif /* SDL_POWER_OS2 */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 #endif /* SDL_POWER_DISABLED */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
134 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
135 /* vi: set ts=4 sw=4 expandtab: */ |