Subversion Repositories Kolibri OS

Rev

Rev 1980 | Rev 2455 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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