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