Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2455 | mario79 | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2009-2011. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
2288 | clevermous | 8 | ; 11.09.2009 staper@inbox.ru |
9 | ; see kernel\docs\apm.txt |
||
10 | |||
11 | use32 |
||
12 | |||
13 | org 0x0 |
||
14 | |||
15 | db 'MENUET01' |
||
16 | dd 0x1 |
||
17 | dd START |
||
18 | dd I_END |
||
19 | dd (I_END+100) and not 3 |
||
20 | dd (I_END+100) and not 3 |
||
21 | dd 0x0,0x0 |
||
22 | |||
23 | include 'macros.inc' |
||
24 | |||
25 | START: |
||
26 | mcall 40,0x7 |
||
27 | |||
28 | mcall 49,0x0001,0x0001,0x5308 ;CX = FFFFh APM v1.0 |
||
29 | ; mcall 49,0x0001,0x0001,0x530d |
||
30 | ; mcall 49,0x0001,0x0001,0x530f |
||
31 | |||
32 | ; mcall 49,0x0000,,0x5310 ;bl - number of batteries |
||
33 | redraw: |
||
34 | mcall 49,0x0000,,0x530c |
||
35 | dec cl |
||
36 | jz still |
||
37 | mcall 49,0x0001,0x0001,0x5308 |
||
38 | mcall 49,0x01ff,,0x530c |
||
39 | test cl, cl |
||
40 | jz @f |
||
41 | mcall 49,0x0000,0x0001,0x530d |
||
42 | mcall 49,0x0000,0x0000,0x5307 |
||
43 | mcall 49,0x0000,0x0001,0x5308 |
||
44 | @@: |
||
45 | mcall 12,1 |
||
46 | mcall 0,100*65536+235,100*65536+90,0x34ffffff,0x000000,title |
||
47 | mcall 49,0x0000,,0x5300 |
||
48 | jnc @f |
||
49 | mcall 4,10*65536+3,0x80000000,text.4 |
||
50 | bts [flags], 1 |
||
51 | jmp .end |
||
52 | @@: |
||
53 | cmp al, 0 |
||
54 | jne @f |
||
55 | mov edx, text.1 |
||
56 | jmp .0 |
||
57 | @@: |
||
58 | cmp al, 1 |
||
59 | jne @f |
||
60 | mov edx, text.2 |
||
61 | jmp .0 |
||
62 | @@: |
||
63 | mov edx, text.3 |
||
64 | .0: |
||
65 | push edx |
||
66 | mcall 4,169*65536+3,0x80dddddd,text.0 |
||
67 | pop edx |
||
68 | add ebx, 47*65536 |
||
69 | mcall |
||
70 | mcall 49,0x0001,,0x530a |
||
71 | jc .error |
||
72 | push si dx cx bx ;time of battery life, b. flag, b. status, AC line status |
||
73 | |||
74 | ;AC line status |
||
75 | cmp bh, 0 |
||
76 | jne @f |
||
77 | mov edx, text.01 |
||
78 | jmp .1 |
||
79 | @@: |
||
80 | cmp bh, 1 |
||
81 | jne @f |
||
82 | mov edx, text.02 |
||
83 | jmp .1 |
||
84 | @@: |
||
85 | cmp bh, 2 |
||
86 | jne @f |
||
87 | mov edx, text.03 |
||
88 | jmp .1 |
||
89 | @@: |
||
90 | mov edx, text.04 |
||
91 | .1: |
||
92 | push edx |
||
93 | mcall 4,10*65536+10,0x80000000,text.00 |
||
94 | pop edx |
||
95 | mcall ,100*65536+10,;0x80000000 |
||
96 | |||
97 | ;battery status |
||
98 | pop bx |
||
99 | cmp bl, 0 |
||
100 | jne @f |
||
101 | mov edx, text.11 |
||
102 | jmp .2 |
||
103 | @@: |
||
104 | cmp bl, 1 |
||
105 | jne @f |
||
106 | mov edx, text.12 |
||
107 | jmp .2 |
||
108 | @@: |
||
109 | cmp bl, 2 |
||
110 | jne @f |
||
111 | mov edx, text.13 |
||
112 | jmp .2 |
||
113 | @@: |
||
114 | cmp bl, 3 |
||
115 | jne @f |
||
116 | mov edx, text.14 |
||
117 | jmp .2 |
||
118 | @@: |
||
119 | mov edx, text.04 |
||
120 | .2: |
||
121 | push edx |
||
122 | mcall 4,10*65536+20,0x80000000,text.10 |
||
123 | pop edx |
||
124 | mcall ,100*65536+20, |
||
125 | |||
126 | ;battery life, percentage and minutes/seconds |
||
127 | mcall ,10*65536+30,,text.20 |
||
128 | pop cx |
||
129 | cmp cl, 0xff |
||
130 | jne @f |
||
131 | mcall ,100*65536+30,0x80000000,text.04 |
||
132 | pop eax |
||
133 | jmp .end |
||
134 | @@: |
||
135 | shl ecx, 24 |
||
136 | shr ecx, 24 |
||
137 | mcall 47,0x80030000,,100*65536+30,0x347636 |
||
138 | .3: |
||
139 | mcall 4,115*65536+30,0x80000000,text.15 |
||
140 | mov dx, [esp] |
||
141 | shl edx, 17 |
||
142 | shr edx, 17 |
||
143 | mov ecx, edx |
||
144 | mcall 47,0x80030000,,140*65536+30 |
||
145 | pop cx |
||
146 | mov edx, text.21 |
||
147 | bt cx, 15 |
||
148 | jc @f |
||
149 | mov edx, text.22 |
||
150 | @@: |
||
151 | mcall 4,160*65536+30,0x80000000 |
||
152 | pop si |
||
153 | .error: |
||
154 | .end: |
||
155 | ;buttons |
||
156 | mcall 8,148*65536+16,45*65536+15,3,0x00677ab0 |
||
157 | mcall ,166*65536+16,,4, |
||
158 | mcall ,184*65536+16,,5, |
||
159 | mcall ,202*65536+16,,6, |
||
160 | bt [flags], 1 |
||
161 | jc @f |
||
162 | mcall ,65*65536+45,,2, |
||
163 | @@: |
||
164 | mcall 4,10*65536+50,0x80564242,text.30 |
||
165 | mcall 12,2 |
||
166 | |||
167 | still: |
||
168 | ; mcall 10 |
||
169 | mcall 23,12000 |
||
170 | test eax, eax |
||
171 | jz redraw |
||
172 | |||
173 | dec al |
||
174 | jz redraw |
||
175 | dec al |
||
176 | jz key |
||
177 | dec al |
||
178 | jz button |
||
179 | jmp still |
||
180 | |||
181 | |||
182 | |||
183 | |||
184 | key: |
||
185 | mcall 2 |
||
186 | jmp still |
||
187 | |||
188 | button: |
||
189 | mcall 17 |
||
190 | cmp ah, 1 |
||
191 | jne @f |
||
192 | mcall -1 |
||
193 | |||
194 | @@: |
||
195 | cmp ah, 2 |
||
196 | jne @f |
||
197 | mcall 5,50 |
||
198 | mcall 49,0x0001,0x0001,0x5307 |
||
199 | jmp redraw |
||
200 | |||
201 | @@: |
||
202 | cmp ah, 4 |
||
203 | jg @f |
||
204 | mov edx, 0x01f7 ;primary chan. |
||
205 | call reserv_ports |
||
206 | jc redraw |
||
207 | sub bh, 3 |
||
208 | .1: |
||
209 | call set_drive |
||
210 | btc [flags], 2 |
||
211 | jnc .2 |
||
212 | call device_reset |
||
213 | jmp .3 |
||
214 | .2: |
||
215 | call standby_hdd |
||
216 | .3: |
||
217 | call free_ports |
||
218 | jmp redraw |
||
219 | |||
220 | @@: |
||
221 | cmp ah, 6 |
||
222 | jg redraw |
||
223 | mov edx, 0x0177 ;secondary chan. |
||
224 | call reserv_ports |
||
225 | jc redraw |
||
226 | sub bh, 5 |
||
227 | jmp .1 |
||
228 | |||
229 | set_drive: |
||
230 | dec dx |
||
231 | in al, dx |
||
232 | test bh, bh |
||
233 | jnz @f |
||
234 | btr ax, 4 |
||
235 | .1: |
||
236 | out dx, al |
||
237 | inc dx |
||
238 | ret |
||
239 | @@: |
||
240 | bts ax, 4 |
||
241 | jmp .1 |
||
242 | |||
243 | |||
244 | standby_hdd: |
||
245 | ; 94h E0h nondata standby immediate |
||
246 | ; 95h E1h nondata idle immediate |
||
247 | ; 96h E2h nondata standby |
||
248 | ; 97h E3h nondata idle |
||
249 | ; 98h E5h nondata check power mode |
||
250 | ; 99h E6h nondata set sleep mode |
||
251 | xor ecx, ecx |
||
252 | @@: |
||
253 | in al, dx |
||
254 | dec cx |
||
255 | jz @f |
||
256 | bt ax, 6 |
||
257 | jnc @b |
||
258 | mov al, 0x96 |
||
259 | out dx, al |
||
260 | mov al, 0xe2 |
||
261 | out dx, al |
||
262 | @@: |
||
263 | ret |
||
264 | |||
265 | reserv_ports: |
||
266 | mov ecx, edx |
||
267 | dec ecx |
||
268 | push ax |
||
269 | mcall 46,0 |
||
270 | test al, al |
||
271 | jnz @f |
||
272 | pop bx |
||
273 | clc |
||
274 | ret |
||
275 | @@: |
||
276 | pop bx |
||
277 | stc |
||
278 | ret |
||
279 | |||
280 | device_reset: |
||
281 | xor ecx, ecx |
||
282 | @@: |
||
283 | in al, dx |
||
284 | dec cx |
||
285 | jz @f |
||
286 | bt ax, 6 |
||
287 | jnc @b |
||
288 | mov al, 0x10 |
||
289 | out dx, al |
||
290 | @@: |
||
291 | ret |
||
292 | |||
293 | free_ports: |
||
294 | mov ecx, edx |
||
295 | dec ecx |
||
296 | mcall 46,1 |
||
297 | ret |
||
298 | |||
299 | |||
3539 | clevermous | 300 | ; ДАННЫЕ ПРОГРАММЫ |
2288 | clevermous | 301 | title db '',0 |
302 | flags dw 0 |
||
303 | |||
304 | text: |
||
305 | .0: |
||
306 | db 'APM v.1.',0 |
||
307 | .1: |
||
308 | db '0',0 |
||
309 | .2: |
||
310 | db '1',0 |
||
311 | .3: |
||
312 | db '2',0 |
||
313 | .4: |
||
314 | db 'APM not supported',0 |
||
315 | |||
316 | .00: |
||
317 | db 'power status:',0 |
||
318 | .01: |
||
319 | db 'off-line',0 |
||
320 | .02: |
||
321 | db 'on-line',0 |
||
322 | .03: |
||
323 | db 'on backup power',0 |
||
324 | .04: |
||
325 | db 'unknown',0 |
||
326 | |||
327 | .10: |
||
328 | db 'battery flag:',0 |
||
329 | .11: |
||
330 | db 'high',0 |
||
331 | .12: |
||
332 | db 'low',0 |
||
333 | .13: |
||
334 | db 'critical',0 |
||
335 | .14: |
||
336 | db 'charging',0 |
||
337 | .15: |
||
338 | db ' % ,',0 |
||
339 | |||
340 | .20: |
||
341 | db 'battery life:',0 |
||
342 | .21: |
||
343 | db 'min',0 |
||
344 | .22: |
||
345 | db 'sec',0 |
||
346 | |||
347 | .30: |
||
348 | db 'STAND-BY: SYSTEM HDD: 0 1 2 3',0 |
||
349 | |||
350 | I_END: |