Add sources of APM driver (by Staper) and battery driver (by Gluk)

git-svn-id: svn://kolibrios.org@1980 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Yogev Ezra 2011-06-25 15:19:38 +00:00
parent eb6cb66362
commit eed73247e9
2 changed files with 817 additions and 0 deletions

View File

@ -0,0 +1,295 @@
; 11.09.2009 staper@inbox.ru
; see kernel\docs\apm.txt
use32
org 0x0
db 'MENUET01'
dd 0x1
dd START
dd I_END
dd (I_END+100) and not 3
dd (I_END+100) and not 3
dd 0x0,0x0
include 'macros.inc'
START:
mcall 40,0x7
mcall 49,0x0001,0x0001,0x5308 ;CX = FFFFh APM v1.0
; mcall 49,0x0001,0x0001,0x530d
; mcall 49,0x0001,0x0001,0x530f
; mcall 49,0x0000,,0x5310 ;bl - number of batteries
redraw:
mcall 49,0x0000,,0x530c
dec cl
jz still
mcall 49,0x0001,0x0001,0x5308
mcall 49,0x01ff,,0x530c
test cl,cl
jz @f
mcall 49,0x0000,0x0001,0x530d
mcall 49,0x0000,0x0000,0x5307
mcall 49,0x0000,0x0001,0x5308
@@:
mcall 12,1
mcall 0,100*65536+235,100*65536+90,0x34ffffff,0x000000,title
mcall 49,0x0000,,0x5300
jnc @f
mcall 4,10*65536+3,0x80000000,text.4
bts [flags],1
jmp .end
@@: cmp al,0
jne @f
mov edx,text.1
jmp .0
@@: cmp al,1
jne @f
mov edx,text.2
jmp .0
@@: mov edx,text.3
.0: push edx
mcall 4,169*65536+3,0x80dddddd,text.0
pop edx
add ebx,47*65536
mcall
mcall 49,0x0001,,0x530a
jc .error
push si dx cx bx ;time of battery life, b. flag, b. status, AC line status
;AC line status
cmp bh,0
jne @f
mov edx,text.01
jmp .1
@@: cmp bh,1
jne @f
mov edx,text.02
jmp .1
@@: cmp bh,2
jne @f
mov edx,text.03
jmp .1
@@: mov edx,text.04
.1: push edx
mcall 4,10*65536+10,0x80000000,text.00
pop edx
mcall ,100*65536+10,;0x80000000
;battery status
pop bx
cmp bl,0
jne @f
mov edx,text.11
jmp .2
@@: cmp bl,1
jne @f
mov edx,text.12
jmp .2
@@: cmp bl,2
jne @f
mov edx,text.13
jmp .2
@@: cmp bl,3
jne @f
mov edx,text.14
jmp .2
@@: mov edx,text.04
.2: push edx
mcall 4,10*65536+20,0x80000000,text.10
pop edx
mcall ,100*65536+20,
;battery life, percentage and minutes/seconds
mcall ,10*65536+30,,text.20
pop cx
cmp cl,0xff
jne @f
mcall ,100*65536+30,0x80000000,text.04
pop eax
jmp .end
@@: shl ecx,24
shr ecx,24
mcall 47,0x80030000,,100*65536+30,0x347636
.3: mcall 4,115*65536+30,0x80000000,text.15
mov dx,[esp]
shl edx,17
shr edx,17
mov ecx,edx
mcall 47,0x80030000,,140*65536+30
pop cx
mov edx,text.21
bt cx,15
jc @f
mov edx,text.22
@@: mcall 4,160*65536+30,0x80000000
pop si
.error:
.end:
;buttons
mcall 8,148*65536+16,45*65536+15,3,0x00677ab0
mcall ,166*65536+16,,4,
mcall ,184*65536+16,,5,
mcall ,202*65536+16,,6,
bt [flags],1
jc @f
mcall ,65*65536+45,,2,
@@: mcall 4,10*65536+50,0x80564242,text.30
mcall 12,2
still:
; mcall 10
mcall 23,12000
test eax,eax
jz redraw
dec al
jz redraw
dec al
jz key
dec al
jz button
jmp still
key:
mcall 2
jmp still
button:
mcall 17
cmp ah,1
jne @f
mcall -1
@@: cmp ah,2
jne @f
mcall 5,50
mcall 49,0x0001,0x0001,0x5307
jmp redraw
@@: cmp ah,4
jg @f
mov edx,0x01f7 ;primary chan.
call reserv_ports
jc redraw
sub bh,3
.1: call set_drive
btc [flags],2
jnc .2
call device_reset
jmp .3
.2: call standby_hdd
.3: call free_ports
jmp redraw
@@: cmp ah,6
jg redraw
mov edx,0x0177 ;secondary chan.
call reserv_ports
jc redraw
sub bh,5
jmp .1
set_drive:
dec dx
in al,dx
test bh,bh
jnz @f
btr ax,4
.1: out dx,al
inc dx
ret
@@: bts ax,4
jmp .1
standby_hdd:
; 94h E0h nondata standby immediate
; 95h E1h nondata idle immediate
; 96h E2h nondata standby
; 97h E3h nondata idle
; 98h E5h nondata check power mode
; 99h E6h nondata set sleep mode
xor ecx,ecx
@@: in al,dx
dec cx
jz @f
bt ax,6
jnc @b
mov al,0x96
out dx,al
mov al,0xe2
out dx,al
@@:
ret
reserv_ports:
mov ecx,edx
dec ecx
push ax
mcall 46,0
test al,al
jnz @f
pop bx
clc
ret
@@: pop bx
stc
ret
device_reset:
xor ecx,ecx
@@: in al,dx
dec cx
jz @f
bt ax,6
jnc @b
mov al,0x10
out dx,al
@@:
ret
free_ports:
mov ecx,edx
dec ecx
mcall 46,1
ret
; „€<E2809E><E282AC><20><>Žƒ<C5BD>€ŒŒ
title db '',0
flags dw 0
text:
.0: db 'APM v.1.',0
.1: db '0',0
.2: db '1',0
.3: db '2',0
.4: db 'APM not supported',0
.00: db 'power status:',0
.01: db 'off-line',0
.02: db 'on-line',0
.03: db 'on backup power',0
.04: db 'unknown',0
.10: db 'battery flag:',0
.11: db 'high',0
.12: db 'low',0
.13: db 'critical',0
.14: db 'charging',0
.15: db ' % ,',0
.20: db 'battery life:',0
.21: db 'min',0
.22: db 'sec',0
.30: db 'STAND-BY: SYSTEM HDD: 0 1 2 3',0
I_END:

View File

@ -0,0 +1,522 @@
; Battery Indicator v0.ALPHA by Gluk
include "macros.inc"
MEOS_APP_START
CODE
init:
mov cl,48d ; setting waitingmask
mov edx,0x110
mcall 66,4
mov word[vminor],0
mov dx,0x5300
xor ebx,ebx
mov eax,49
jnc @f
mov word[vminor],ax
@@:
mov dx,0x5308
mov bx,1
mov cx,bx
mov eax,49
int 0x40
mov dx,0x530E
xor bx,bx
mov cx,0x0102
mov eax,49
int 0x40
mov dx,0x530D
mov bx,1
mov cx,bx
mov eax,49
int 0x40
mov dx,0x530F
mov bx,1
mov cx,bx
mov eax,49
int 0x40
xor ebx,ebx
mov bx,[bid] ; find a bid
dec ebx
@@:
mov eax,49
mov dx,530Ah
inc ebx
int 0x40
jc @b
;cmp cl,0xff
;je @b
finded:
mov [bid],bx
;mcall 49,0,0,5310h
mcall 9,streaminfo,-1 ; get process data
mov ecx,dword[streaminfo+30d]
mcall 18,21
mov [slotid],eax
mov eax,48 ; get system colors
mov ebx,3
mov ecx,sc
mov edx,sizeof.system_colors
mcall
initend:
redraw:
call draw_window
wait_event: ; main cycle
call redata
mov ebx,[waiting]
mcall 23
cmp eax,0
jz wait_event
dec eax
jz redraw
dec eax
jz key
dec eax
jz button
jmp wait_event
button:
mcall 17
@@: ;1:
dec ah
;jnz @f
; or eax,-1
; mcall
;@@: ;2
dec ah
jnz @f
mov eax,dword[whatview]
mov ebx,views_end-3
add eax,4
cmp eax,ebx
jb allok1
mov eax,views_start
allok1:
mov [whatview],eax
mov eax,[eax]
mov [viewer],eax
@@:
jmp wait_event
redata:
call getdata
mov al,[window]
cmp al,0
jz @f
call regraph
call rebutton
@@:
ret
key: ; key event handler
mov al,2 ; get key code
mcall
cmp al,2
jne wait_event
call rewindow
jmp wait_event
draw_window:
mov eax,12
mov ebx,1
mcall
mov al,byte[window]
cmp al,0
jz nowindow
mcall 48,5
sub eax,[winotstx]
sub eax,[winsizex]
shl eax,16
sub ebx,[winotsty]
sub ebx,[winsizey]
shl ebx,16
mov ecx,ebx
mov ebx,eax
xor eax,eax ; create and draw the window
add ebx,dword[winsizex]
dec ebx ; (window_c)*65536+(window_s)
add ecx,dword[winsizey]
dec ecx
mov edx,[sc.work] ; work area color
or edx, 0x61000000 ; & window type 1
int 0x40
mov eax,13d ;printing pryamougolniks
push eax ;pipka out
mov eax,[winsizex]
xor edx,edx
mov ebx,3
div ebx
mov ebx,eax
; pusha
;mov [nowpoint],0
;in: ebx - piplenght
; mov eax,0
;mov edi, nowpoint
; add edi,winform
; mov ecx,ebx
; rep stosb
; mov eax,1
;mov edi, nowpoint
; add edi,winform
; mov ecx,ebx
; rep stosb
; mov eax,0
;mov edi, nowpoint
; add edi,winform
; mov ecx,ebx
; rep stosb
; popa
mov ecx,ebx
shl ebx,16
pop eax
add ebx,ecx
mov ecx,[winsizey]
shr ecx,4 ;div 16 ;)
xor edx,edx
int 0x40
add ebx,65536-2 ;pipka in
add ecx,65536-1
mov edx,[sc]
int 0x40
mov ebx,[winsizex] ;korpus out
mov ecx,[winsizey]
shr ecx,4
mov edx,ecx
shl ecx,16
add ecx,[winsizey]
sub ecx,edx
xor edx,edx
int 0x40
add ebx,65536-2 ;korpus in
add ecx,65536-2
mov edx,[sc]
int 0x40
mov edx,[winborts]
mov edi,edx
shl edx,16
add ebx,edx
sub ebx,edi
sub ebx,edi ;black contur
add ecx,65536-3
sub ecx,[winknopy]
xor edx,edx
int 0x40
add ebx,65536-2 ;working area
add ecx,65536-2
mov edx,[sc.work]
int 0x40
mov [winworkx],ebx
mov [winworky],ecx
call redata
nowindow:
mov eax,12 ;finish drawing
mov ebx,2
int 0x40
ret
rebutton:
mov eax,8
mov edx,0x80000002
int 0x40
mov ebx,[winsizex]
add ebx,65536-3
mov edi,[winknopy]
mov ecx,[winsizey]
sub ecx,edi
sub ecx,2
shl ecx,16
add ecx,edi
mov edx,0x00000002
mov esi,[sc.work_button]
int 0x40
mov [wintextx],3
sub edi,[winfonty]
shr edi,1
mov ebx,edi
add ebx,[winsizey]
sub ebx,[winknopy]
mov [wintexty],ebx
call dword[viewer]
ret
rewindow:
mov al,byte[window]
cmp al,1
jne @f
mcall 67,1,1,0,0
mov byte[window],0
mcall 40,2
jmp endrew
@@:
mcall 48,5
sub eax,[winotstx]
sub eax,[winsizex]
sub ebx,[winotsty]
sub ebx,[winsizey]
mov ecx,ebx
mov ebx,eax
mov eax,67
mov edx,[winsizex]
dec edx
mov esi,[winsizey]
dec esi
int 0x40
mov byte[window],1
mov ecx,[slotid]
mcall 18,3
mcall 40,7
endrew:
call draw_window
ret
regraph:
mov eax,13
mov ebx,[winworkx] ;working area
mov ecx,[winworky]
mov edx,[sc.work]
int 0x40
mov ebx,[winworky]
shl ebx,16
shr ebx,16
sub ebx,[wingotst]
sub ebx,[wingotst]
mov eax,ebx
shr ebx,3 ;div 8 ;)
shl eax,29
shr eax,32 ;ostatok
add eax,[wingotst]
cmp eax,ebx
jb @f
inc ebx
@@:
mov [winlines],ebx
mov ecx,[delenia]
@@:
push ecx
mov edi,ecx
mov edx,[wingotst]
mov ebx,[winworkx]
shl edx,16
add ebx,edx
shr edx,16
sub ebx,edx
sub ebx,edx
mov ecx,[winworky]
mov eax,[winworky]
shl eax,16
add ecx,eax
push edx
mov eax,[winlines]
mul edi
pop edx
add edx,eax
shl edx,16
sub ecx,edx
shr ecx,16
inc ecx
shl ecx,16
add ecx,[winlines]
sub ecx,1 ;promezhutki
mov edx,[sc.work_graph]
mov eax,13
int 0x40
pop ecx
loop @b
endreg:
ret
getdata:
xor ecx,ecx
xor edx,edx
;HERE YOU MAY GET A PERCENTAGE AND REMAINING TIME FOR BATTERY UNIT [bid], AND PUT THEY INTO [gotperc] AND [gottime]
mov bx,[bid]
mov eax,49
mov dx,530Ah
int 0x40
mov [gotperc],cl
mov [gottime],dx
;/HERE
xor eax,eax
mov al,[gotperc]
cmp al,0
jne @f
mov [delenia],1
ret
@@:
cmp al,100
jb @f
mov [delenia],8
ret
@@:
shl eax,3
mov ebx,100
xor edx,edx
div ebx
inc eax
mov [delenia],eax
ret
viewers:
time:
xor edx,edx
mov dx,[gottime]
cmp dx,0xffff
jne @f
mov eax,4
mov ebx,[wintextx]
shl ebx,16
add ebx,[wintexty]
mov ecx,0x00000000
mov edx,simbols
mov esi,3
add ecx,[sc.work_button_text]
int 0x40
ret
@@:
shl edx,17
shr edx,31
mov eax,4
mov ebx,[wintextx]
add ebx,2*8
shl ebx,16
add ebx,[wintexty]
mov ecx,0x00000000
add edx,simbols
mov esi,1
add ecx,[sc.work_button_text]
int 0x40
;12345678901234567890123456789012
mov eax,47
mov bl,2 ;cifr
mov bh,0
shl ebx,16
mov bl,0 ;ecx is chislo
mov bh,0
xor ecx,ecx
mov cx,[gottime]
shl ecx,18
shr ecx,18
mov edx,[wintextx]
shl edx,16
add edx,[wintexty]
mov esi,0x10000000
add esi,[sc.work_button_text]
int 0x40
ret
percent:
mov dl,[gotperc]
cmp dl,0xff
jne @f
mov eax,4
mov ebx,[wintextx]
shl ebx,16
add ebx,[wintexty]
mov ecx,0x00000000
mov edx,simbols
mov esi,4
add ecx,[sc.work_button_text]
int 0x40
ret
@@:
mov eax,4
mov ebx,[wintextx]
add ebx,3*8
shl ebx,16
add ebx,[wintexty]
mov ecx,0x00000000
mov edx,simbols
add edx,3
mov esi,1
add ecx,[sc.work_button_text]
int 0x40
mov eax,47
mov bl,3 ;cifr
mov bh,0
shl ebx,16
mov bl,0 ;ecx is chislo
mov bh,0
xor ecx,ecx
mov cl,[gotperc]
mov edx,[wintextx]
shl edx,16
add edx,[wintexty]
mov esi,0x10000000
add esi,[sc.work_button_text]
int 0x40
ret
; <--- initialised data --->
DATA
bid dw 8000h
viewer dd percent
whatview dd views_start
views_start:
dd percent
dd time
views_end:
simbols db 'smh%??m???%'
waiting dd 1000
watchings:
window db 1
winotstx dd 7
winotsty dd 7
winsizex dd 48
winsizey dd 64
winborts dd 1
winfonty dd 9
winknopy dd 10
wingotst dd 2
; <--- uninitialised data --->
UDATA
vminor dw ?
sc system_colors
streaminfo rb 1024
winform rb 1024
slotid dd ?
gotperc db ?
gottime dw ?
delenia dd ?
uwatchings:
winhomex dd ?
winhomey dd ?
winworkx dd ? ;cx*65536+sx
winworky dd ? ;cy*65536+sy
winlines dd ?
wintextx dd ?
wintexty dd ?
MEOS_APP_END