Subversion Repositories Kolibri OS

Rev

Rev 1980 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ; Battery Indicator v0.ALPHA by Gluk
  2. include "../../macros.inc"
  3. MEOS_APP_START
  4. CODE
  5.  
  6. init:
  7.         mov cl,48d                      ; setting waitingmask
  8.         mov edx,0x110
  9.         mcall 66,4
  10.  
  11. mov word[vminor],0
  12. mov dx,0x5300
  13. xor ebx,ebx
  14. mov eax,49
  15. jnc @f
  16. mov word[vminor],ax
  17. @@:
  18. mov dx,0x5308
  19. mov bx,1
  20. mov cx,bx
  21. mov eax,49
  22. int 0x40
  23. mov dx,0x530E
  24. xor bx,bx
  25. mov cx,0x0102
  26. mov eax,49
  27. int 0x40
  28. mov dx,0x530D
  29. mov bx,1
  30. mov cx,bx
  31. mov eax,49
  32. int 0x40
  33. mov dx,0x530F
  34. mov bx,1
  35. mov cx,bx
  36. mov eax,49
  37. int 0x40
  38.         xor ebx,ebx
  39.         mov bx,[bid]                    ; find a bid
  40.         dec ebx
  41.         @@:
  42.         mov eax,49
  43.         mov dx,530Ah
  44.         inc ebx
  45.         int 0x40
  46.         jc @b
  47.        ;cmp cl,0xff
  48.        ;je @b
  49.         finded:
  50.         mov [bid],bx
  51.         ;mcall 49,0,0,5310h
  52.  
  53.         mcall 9,streaminfo,-1           ; get process data
  54.         mov ecx,dword[streaminfo+30d]
  55.         mcall 18,21
  56.         mov [slotid],eax
  57.  
  58.         mov eax,48                      ; get system colors
  59.         mov ebx,3
  60.         mov ecx,sc
  61.         mov edx,sizeof.system_colors
  62.         mcall
  63. initend:
  64.  
  65.   redraw:
  66.    call     draw_window
  67.  
  68. wait_event:                             ; main cycle
  69.         call redata
  70.         mov ebx,[waiting]
  71.         mcall 23
  72.         cmp eax,0
  73.         jz wait_event
  74.         dec eax
  75.         jz redraw
  76.         dec eax
  77.         jz key
  78.         dec eax
  79.         jz button
  80. jmp wait_event
  81.  
  82. button:
  83.         mcall 17
  84.         @@:             ;1:
  85.         dec ah
  86.         ;jnz @f
  87.         ;        or eax,-1
  88.         ;        mcall
  89.         ;@@:             ;2
  90.         dec ah
  91.         jnz @f
  92.                 mov eax,dword[whatview]
  93.                 mov ebx,views_end-3
  94.                 add eax,4
  95.                 cmp eax,ebx
  96.                 jb allok1
  97.                         mov eax,views_start
  98.                 allok1:
  99.                 mov [whatview],eax
  100.                 mov eax,[eax]
  101.                 mov [viewer],eax
  102.         @@:
  103. jmp wait_event
  104.  
  105. redata:
  106.         call getdata
  107.         mov al,[window]
  108.         cmp al,0
  109.         jz @f
  110.                 call regraph
  111.                 call rebutton
  112.         @@:
  113. ret
  114.  
  115. key:                            ; key event handler
  116.     mov al,2                    ; get key code
  117.     mcall
  118.     cmp al,2
  119.     jne wait_event
  120.             call rewindow
  121. jmp wait_event
  122.  
  123.   draw_window:
  124.         mov eax,12
  125.         mov ebx,1
  126.         mcall
  127.  
  128.         mov al,byte[window]
  129.         cmp al,0
  130.         jz nowindow
  131.  
  132.         mcall 48,5
  133.         sub eax,[winotstx]
  134.         sub eax,[winsizex]
  135.         shl eax,16
  136.         sub ebx,[winotsty]
  137.         sub ebx,[winsizey]
  138.         shl ebx,16
  139.         mov ecx,ebx
  140.         mov ebx,eax
  141.  
  142.         xor eax,eax                     ; create and draw the window
  143.         add ebx,dword[winsizex]
  144.         dec ebx                         ; (window_c)*65536+(window_s)
  145.         add ecx,dword[winsizey]
  146.         dec ecx
  147.         mov edx,[sc.work]              ; work area color
  148.         or edx, 0x61000000              ; & window type 1
  149.         int 0x40
  150.  
  151.         mov eax,13d                     ;printing pryamougolniks
  152.         push eax                        ;pipka out
  153.                 mov eax,[winsizex]
  154.                 xor edx,edx
  155.                 mov ebx,3
  156.                 div ebx
  157.                 mov ebx,eax
  158.      ;                   pusha
  159.                         ;mov [nowpoint],0
  160.                         ;in: ebx - piplenght
  161.       ;                  mov eax,0
  162.                         ;mov edi, nowpoint
  163.        ;                 add edi,winform
  164.         ;                mov ecx,ebx
  165.          ;               rep stosb
  166.           ;              mov eax,1
  167.                         ;mov edi, nowpoint
  168.            ;             add edi,winform
  169.             ;            mov ecx,ebx
  170.              ;           rep stosb
  171.               ;          mov eax,0
  172.                         ;mov edi, nowpoint
  173.                ;         add edi,winform
  174.                 ;        mov ecx,ebx
  175.                  ;       rep stosb
  176.                   ;      popa
  177.                 mov ecx,ebx
  178.                 shl ebx,16
  179.         pop eax
  180.         add ebx,ecx
  181.         mov ecx,[winsizey]
  182.         shr ecx,4               ;div 16 ;)
  183.         xor edx,edx
  184.         int 0x40
  185.  
  186.         add ebx,65536-2                 ;pipka in
  187.         add ecx,65536-1
  188.         mov edx,[sc]
  189.         int 0x40
  190.  
  191.         mov ebx,[winsizex]              ;korpus out
  192.         mov ecx,[winsizey]
  193.         shr ecx,4
  194.         mov edx,ecx
  195.         shl ecx,16
  196.         add ecx,[winsizey]
  197.         sub ecx,edx
  198.         xor edx,edx
  199.         int 0x40
  200.  
  201.         add ebx,65536-2                 ;korpus in
  202.         add ecx,65536-2
  203.         mov edx,[sc]
  204.         int 0x40
  205.  
  206.         mov edx,[winborts]
  207.         mov edi,edx
  208.         shl edx,16
  209.         add ebx,edx
  210.         sub ebx,edi
  211.         sub ebx,edi                     ;black contur
  212.         add ecx,65536-3
  213.         sub ecx,[winknopy]
  214.         xor edx,edx
  215.         int 0x40
  216.  
  217.         add ebx,65536-2                 ;working area
  218.         add ecx,65536-2
  219.         mov edx,[sc.work]
  220.         int 0x40
  221.         mov [winworkx],ebx
  222.         mov [winworky],ecx
  223.  
  224.         call redata
  225.         nowindow:
  226.         mov eax,12                      ;finish drawing
  227.         mov ebx,2
  228.         int 0x40
  229. ret
  230.  
  231. rebutton:
  232.         mov eax,8
  233.         mov edx,0x80000002
  234.         int 0x40
  235.  
  236.         mov ebx,[winsizex]
  237.         add ebx,65536-3
  238.         mov edi,[winknopy]
  239.         mov ecx,[winsizey]
  240.         sub ecx,edi
  241.         sub ecx,2
  242.         shl ecx,16
  243.         add ecx,edi
  244.         mov edx,0x00000002
  245.         mov esi,[sc.work_button]
  246.         int 0x40
  247.  
  248.         mov [wintextx],3
  249.         sub edi,[winfonty]
  250.         shr edi,1
  251.         mov ebx,edi
  252.         add ebx,[winsizey]
  253.         sub ebx,[winknopy]
  254.         mov [wintexty],ebx
  255.         call dword[viewer]
  256. ret
  257.  
  258.  
  259. rewindow:
  260.         mov al,byte[window]
  261.         cmp al,1
  262.         jne @f
  263.                 mcall 67,1,1,0,0
  264.                 mov byte[window],0
  265.                 mcall 40,2
  266.                 jmp endrew
  267.         @@:
  268.                 mcall 48,5
  269.                 sub eax,[winotstx]
  270.                 sub eax,[winsizex]
  271.                 sub ebx,[winotsty]
  272.                 sub ebx,[winsizey]
  273.                 mov ecx,ebx
  274.                 mov ebx,eax
  275.  
  276.                 mov eax,67
  277.                 mov edx,[winsizex]
  278.                 dec edx
  279.                 mov esi,[winsizey]
  280.                 dec esi
  281.                 int 0x40
  282.  
  283.                 mov byte[window],1
  284.                 mov ecx,[slotid]
  285.                 mcall 18,3
  286.  
  287.                 mcall 40,7
  288.         endrew:
  289.         call draw_window
  290. ret
  291.  
  292. regraph:
  293.         mov eax,13
  294.         mov ebx,[winworkx]                 ;working area
  295.         mov ecx,[winworky]
  296.         mov edx,[sc.work]
  297.         int 0x40
  298.  
  299.         mov ebx,[winworky]
  300.         shl ebx,16
  301.         shr ebx,16
  302.         sub ebx,[wingotst]
  303.         sub ebx,[wingotst]
  304.         mov eax,ebx
  305.         shr ebx,3               ;div 8 ;)
  306.         shl eax,29
  307.         shr eax,32              ;ostatok
  308.         add eax,[wingotst]
  309.         cmp eax,ebx
  310.         jb @f
  311.                 inc ebx
  312.         @@:
  313.         mov [winlines],ebx
  314.         mov ecx,[delenia]
  315.         @@:
  316.                 push ecx
  317.                 mov edi,ecx
  318.  
  319.                 mov edx,[wingotst]
  320.                 mov ebx,[winworkx]
  321.                 shl edx,16
  322.                 add ebx,edx
  323.                 shr edx,16
  324.                 sub ebx,edx
  325.                 sub ebx,edx
  326.  
  327.                 mov ecx,[winworky]
  328.                 mov eax,[winworky]
  329.                 shl eax,16
  330.                 add ecx,eax
  331.  
  332.                 push edx
  333.                 mov eax,[winlines]
  334.                 mul edi
  335.                 pop edx
  336.                 add edx,eax
  337.  
  338.                 shl edx,16
  339.                 sub ecx,edx
  340.  
  341.                 shr ecx,16
  342.                 inc ecx
  343.                 shl ecx,16
  344.                 add ecx,[winlines]
  345.                 sub ecx,1 ;promezhutki
  346.                 mov edx,[sc.work_graph]
  347.                 mov eax,13
  348.                 int 0x40
  349.  
  350.                 pop ecx
  351.         loop @b
  352. endreg:
  353. ret
  354.  
  355. getdata:
  356.         xor ecx,ecx
  357.         xor edx,edx
  358.  
  359. ;HERE YOU MAY GET A PERCENTAGE AND REMAINING TIME FOR BATTERY UNIT [bid], AND PUT THEY INTO [gotperc] AND [gottime]
  360.         mov bx,[bid]
  361.         mov eax,49
  362.         mov dx,530Ah
  363.         int 0x40
  364.         mov [gotperc],cl
  365.         mov [gottime],dx
  366. ;/HERE
  367.  
  368.         xor eax,eax
  369.         mov al,[gotperc]
  370.         cmp al,0
  371.         jne @f
  372.                 mov [delenia],1
  373.                 ret
  374.         @@:
  375.         cmp al,100
  376.         jb @f
  377.                 mov [delenia],8
  378.                 ret
  379.         @@:
  380.         shl eax,3
  381.         mov ebx,100
  382.         xor edx,edx
  383.         div ebx
  384.         inc eax
  385.         mov [delenia],eax
  386. ret
  387.  
  388. viewers:
  389.         time:
  390.                 xor edx,edx
  391.                 mov dx,[gottime]
  392.                 cmp dx,0xffff
  393.                 jne @f
  394.                         mov eax,4
  395.                         mov ebx,[wintextx]
  396.                         shl ebx,16
  397.                         add ebx,[wintexty]
  398.                         mov ecx,0x00000000
  399.                         mov edx,simbols
  400.                         mov esi,3
  401.                         add ecx,[sc.work_button_text]
  402.                         int 0x40
  403.                 ret
  404.                 @@:
  405.                 shl edx,17
  406.                 shr edx,31
  407.                 mov eax,4
  408.                 mov ebx,[wintextx]
  409.                 add ebx,2*8
  410.                 shl ebx,16
  411.                 add ebx,[wintexty]
  412.                 mov ecx,0x00000000
  413.                 add edx,simbols
  414.                 mov esi,1
  415.                 add ecx,[sc.work_button_text]
  416.                 int 0x40
  417.       ;12345678901234567890123456789012
  418.                 mov eax,47
  419.                 mov bl,2        ;cifr
  420.                 mov bh,0
  421.                 shl ebx,16
  422.                 mov bl,0        ;ecx is chislo
  423.                 mov bh,0
  424.                 xor ecx,ecx
  425.                 mov cx,[gottime]
  426.                 shl ecx,18
  427.                 shr ecx,18
  428.                 mov edx,[wintextx]
  429.                 shl edx,16
  430.                 add edx,[wintexty]
  431.                 mov esi,0x10000000
  432.                 add esi,[sc.work_button_text]
  433.                 int 0x40
  434.         ret
  435.         percent:
  436.                 mov dl,[gotperc]
  437.                 cmp dl,0xff
  438.                 jne @f
  439.                         mov eax,4
  440.                         mov ebx,[wintextx]
  441.                         shl ebx,16
  442.                         add ebx,[wintexty]
  443.                         mov ecx,0x00000000
  444.                         mov edx,simbols
  445.                         mov esi,4
  446.                         add ecx,[sc.work_button_text]
  447.                         int 0x40
  448.                 ret
  449.                 @@:
  450.                 mov eax,4
  451.                 mov ebx,[wintextx]
  452.                 add ebx,3*8
  453.                 shl ebx,16
  454.                 add ebx,[wintexty]
  455.                 mov ecx,0x00000000
  456.                 mov edx,simbols
  457.                 add edx,3
  458.                 mov esi,1
  459.                 add ecx,[sc.work_button_text]
  460.                 int 0x40
  461.  
  462.                 mov eax,47
  463.                 mov bl,3        ;cifr
  464.                 mov bh,0
  465.                 shl ebx,16
  466.                 mov bl,0        ;ecx is chislo
  467.                 mov bh,0
  468.                 xor ecx,ecx
  469.                 mov cl,[gotperc]
  470.                 mov edx,[wintextx]
  471.                 shl edx,16
  472.                 add edx,[wintexty]
  473.                 mov esi,0x10000000
  474.                 add esi,[sc.work_button_text]
  475.                 int 0x40
  476.         ret
  477. ; <--- initialised data --->
  478. DATA
  479.  
  480. bid dw 8000h
  481.  
  482. viewer dd percent
  483. whatview dd views_start
  484. views_start:
  485.         dd percent
  486.         dd time
  487. views_end:
  488.  
  489. simbols db 'smh%??m???%'
  490.  
  491. waiting dd 1000
  492. watchings:
  493.         window db 1
  494.         winotstx dd 7
  495.         winotsty dd 7
  496.         winsizex dd 48
  497.         winsizey dd 64
  498.         winborts dd 1
  499.         winfonty dd 9
  500.         winknopy dd 10
  501.         wingotst dd 2
  502. ; <--- uninitialised data --->
  503. UDATA
  504. vminor dw ?
  505. sc system_colors
  506. streaminfo rb 1024
  507. winform rb 1024
  508. slotid dd ?
  509.  
  510. gotperc db ?
  511. gottime dw ?
  512. delenia dd ?
  513.  
  514. uwatchings:
  515.         winhomex dd ?
  516.         winhomey dd ?
  517.         winworkx dd ?           ;cx*65536+sx
  518.         winworky dd ?           ;cy*65536+sy
  519.         winlines dd ?
  520.         wintextx dd ?
  521.         wintexty dd ?
  522. MEOS_APP_END