Subversion Repositories Kolibri OS

Rev

Rev 5093 | Details | Compare with Previous | 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
 
5093 clevermous 23
include '../../macros.inc'
2288 clevermous 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
7647 leency 46
        mcall   0,100*65536+320,120*65536+120,0x34ffffff,0x000000,title
2288 clevermous 47
        mcall   49,0x0000,,0x5300
48
        jnc     @f
7647 leency 49
        mcall   4,10*65536+12,0x90CE362B,ver.4
2288 clevermous 50
        bts     [flags], 1
51
        jmp     .end
52
    @@:
53
        cmp     al, 0
54
        jne     @f
7647 leency 55
        mov     edx, ver.1
2288 clevermous 56
        jmp     .0
57
    @@:
58
        cmp     al, 1
59
        jne     @f
7647 leency 60
        mov     edx, ver.2
2288 clevermous 61
        jmp     .0
62
    @@:
7647 leency 63
        mov     edx, ver.3
2288 clevermous 64
    .0:
65
        push    edx
7647 leency 66
        mcall   4,237*65536+3,0x80AAAaaa,ver.0
2288 clevermous 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
7647 leency 122
        mcall   4,10*65536+22,0x80000000,text.10
2288 clevermous 123
        pop     edx
7647 leency 124
        mcall   ,100*65536+22,
2288 clevermous 125
 
126
                                ;battery life, percentage and minutes/seconds
7647 leency 127
        mcall   ,10*65536+34,,text.20
2288 clevermous 128
        pop     cx
129
        cmp     cl, 0xff
130
        jne     @f
7647 leency 131
        mcall   ,100*65536+34,0x80000000,text.04
2288 clevermous 132
        pop     eax
133
        jmp     .end
134
    @@:
135
        shl     ecx, 24
136
        shr     ecx, 24
7647 leency 137
        mcall   47,0x80030000,,100*65536+34,0x347636
2288 clevermous 138
    .3:
7647 leency 139
        mcall   4,115*65536+34,0x80000000,text.15
2288 clevermous 140
        mov     dx, [esp]
141
        shl     edx, 17
142
        shr     edx, 17
143
        mov     ecx, edx
7647 leency 144
        mcall   47,0x80030000,,140*65536+34
2288 clevermous 145
        pop     cx
146
        mov     edx, text.21
147
        bt      cx, 15
148
        jc      @f
149
        mov     edx, text.22
150
    @@:
7647 leency 151
        mcall   4,160*65536+34,0x80000000
2288 clevermous 152
        pop     si
153
  .error:
154
  .end:
155
        ;buttons
7647 leency 156
        mcall   8,195*65536+21,56*65536+20,3,0x00BBD5E6
157
        mcall   ,219*65536+21,,4,
158
        mcall   ,243*65536+21,,5,
159
        mcall   ,267*65536+21,,6,
2288 clevermous 160
        bt      [flags], 1
161
        jc      @f
7647 leency 162
        mcall   ,86*65536+56,,2,
2288 clevermous 163
  @@:
7647 leency 164
        mcall   4,10*65536+60,0x90564242,text.30
2288 clevermous 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
 
7647 leency 300
; DATA SECTION
301
title db 'Advanced Power Management',0
2288 clevermous 302
flags dw 0
303
 
7647 leency 304
ver:
305
.0: db 'APM v.1.',0
306
.1: db '0',0
307
.2: db '1',0
308
.3: db '2',0
309
.4: db 'APM is not supported',0
310
 
2288 clevermous 311
text:
7647 leency 312
.00: db 'power status:',0
313
.01: db 'off-line',0
314
.02: db 'on-line',0
315
.03: db 'on backup power',0
316
.04: db 'unknown',0
2288 clevermous 317
 
7647 leency 318
.10: db 'battery flag:',0
319
.11: db 'high',0
320
.12: db 'low',0
321
.13: db 'critical',0
322
.14: db 'charging',0
323
.15: db ' % ,',0
2288 clevermous 324
 
7647 leency 325
.20: db 'battery life:',0
326
.21: db 'min',0
327
.22: db 'sec',0
2288 clevermous 328
 
7647 leency 329
.30: db 'STAND-BY: SYSTEM  HDD:  0  1  2  3',0
2288 clevermous 330
 
331
I_END: