Subversion Repositories Kolibri OS

Rev

Rev 2128 | Rev 2582 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;
  2. ;   CPU -process Manager
  3. ;
  4. ;------------------------------------------------------------------------------
  5. ; version:      1.70
  6. ; last update:  04/04/2012
  7. ; changed by:   Marat Zakiyanov aka Mario79, aka Mario
  8. ; changes:      Code refactoring and optimization.
  9. ;               Added russian language support.
  10. ;               Fix - processes information showing  not been updated during
  11. ;               the processing of mouse events.
  12. ;------------------------------------------------------------------------------
  13. ; Many fix's and changes created by:
  14. ;               Diamond, Heavyiron, SPraid, <Lrz>,
  15. ;               Leency, IgorA, kaitz
  16. ;---------------------------------------------------------------------
  17. ;   integrated with load_lib.obj by <Lrz>
  18. ;---------------------------------------------------------------------
  19. ;   additions by M.Lisovin lisovin@26.ru
  20. ;---------------------------------------------------------------------
  21. ;   original author - VTurjanmaa
  22. ;------------------------------------------------------------------------------
  23.         use32
  24.         org 0x0
  25.         db 'MENUET01'           ; 8 byte id
  26.         dd 0x01                 ; header version
  27.         dd START                ; start of code
  28.         dd IM_END               ; size of image
  29.         dd U_END                ; memory for app
  30.         dd stack_area           ; esp
  31.         dd 0x0                  ; boot parameters
  32.         dd 0x0                  ; path
  33. ;------------------------------------------------------------------------------
  34. include 'lang.inc'
  35. include '../../../macros.inc'
  36. include '../../../develop/libraries/box_lib/trunk/box_lib.mac'
  37. include '../../../develop/libraries/box_lib/load_lib.mac'
  38. ;------------------------------------------------------------------------------
  39. display_processes=32            ; number of processes to show
  40. window_x_size=524
  41. window_y_size=430
  42. ;------------------------------------------------------------------------------
  43. @use_library    ;use load lib macros
  44. ;------------------------------------------------------------------------------
  45. START:                          ; start of execution
  46.         mcall   68,11
  47. sys_load_library  library_name, cur_dir_path, library_path, system_path, \
  48. err_message_found_lib, head_f_l, myimport, err_message_import, head_f_i
  49.         inc     eax
  50.         jz      close
  51. ;------------------------------------------------------------------------------
  52.         mcall   40,0x27 ;set event
  53. ;------------------------------------------------------------------------------
  54. ;set window size and position for 0 function
  55. ;to [winxpos] and [winypos] variables
  56. ;get screen size
  57.         mcall   14
  58.         mov     ebx,eax
  59. ;calculate (x_screen-window_x_size)/2    
  60.         shr     ebx,16+1
  61.         sub     ebx,window_x_size/2
  62.         shl     ebx,16
  63.         mov     bx,window_x_size
  64. ;winxpos=xcoord*65536+xsize    
  65.         mov     [winxpos],ebx
  66. ;calculate (y_screen-window_y_size)/2    
  67.         and     eax,0xffff
  68.         shr     eax,1
  69.         sub     eax,window_y_size/2
  70.         shl     eax,16
  71.         mov     ax,window_y_size
  72. ;winypos=ycoord*65536+ysize    
  73.         mov     [winypos],eax
  74. ;------------------------------------------------------------------------------
  75.         mcall   48,3,sc,40
  76.         edit_boxes_set_sys_color edit1,edit1_end,sc             ;set color
  77.         check_boxes_set_sys_color check1,check1_end,sc  ;set color
  78. ;------------------------------------------------------------------------------
  79. align 4  
  80. ;main loop when process name isn't edited.    
  81. red:   
  82.         call    draw_window             ; redraw all window
  83. ;------------------------------------------------------------------------------
  84. align 4
  85. still:
  86.         mcall   23,100          ; wait here for event 1 sec.
  87.  
  88.         dec     eax                   ; redraw request ?
  89.         jz      red
  90.  
  91.         dec     eax                   ; key in buffer ?
  92.         jz      key
  93.  
  94.         dec     eax                   ; button in buffer ?
  95.         jz      button
  96.  
  97. ;       sub     eax,3                 ; If not use mouse - show
  98. ;       jnz     still_end
  99.  
  100.         push    dword edit1
  101.         call    [edit_box_mouse]
  102.        
  103.         push    dword[check1+32]
  104.        
  105.         push    dword check1
  106.         call    [check_box_mouse]
  107.        
  108.         pop     eax
  109.        
  110.         cmp     eax, dword[check1+32]
  111.         jz      still_end
  112.        
  113.         push    dword check1
  114.         call    [check_box_draw]
  115. ;--------------------------------------
  116. align 4
  117. show_process_info_1:   
  118.         mcall   26,9
  119.         add     eax,100
  120.         mov     [time_counter],eax
  121.  
  122.         call    show_process_info       ; draw new state of processes
  123.         jmp     still
  124. ;------------------------------------------------------------------------------
  125. align 4
  126. still_end:
  127.         mcall   26,9
  128.         cmp     [time_counter],eax
  129.         ja      still
  130.  
  131.         add     eax,100
  132.         mov     [time_counter],eax
  133.  
  134.         call    show_process_info       ; draw new state of processes
  135.         jmp     still
  136. ;------------------------------------------------------------------------------
  137. align 4
  138. key:                            ; key
  139.         mcall   2
  140.  
  141.         cmp     ah,184          ; PageUp
  142.         jz      pgdn
  143.  
  144.         cmp     ah,183
  145.         jz      pgup                    ; PageDown
  146.  
  147.         cmp     ah,27
  148.         jz      close                   ; Esc
  149.  
  150.         push    dword edit1
  151.         call    [edit_box_key]
  152.                                 ; Check ENTER with ed_focus edit_box
  153.         lea     edi,[edit1]
  154.         test    word ed_flags,ed_focus
  155.         jz      still_end
  156.  
  157.         sub     ah,13                   ; ENTER?
  158.         jz      program_start           ; RUN a program
  159.  
  160.         jmp     still
  161. ;------------------------------------------------------------------------------
  162. align 4
  163. button:                
  164. ; get button id  
  165.         mcall   17
  166.         shr     eax,8                  
  167. ;id in [10,50] corresponds to terminate buttons.
  168.         cmp     eax,10
  169.         jb      noterm         
  170.  
  171.         cmp     eax,50
  172.         jg      noterm
  173. ;calculate button index        
  174.         sub     eax,11
  175. ;calculate process slot    
  176.         mov     ecx,[tasklist+4*eax]
  177. ;ignore empty buttons
  178.         test    ecx,ecx
  179.         jle     still_end
  180. ;terminate application    
  181.         mcall   18,2
  182.         jmp     show_process_info_1     ;still_end
  183. ;--------------------------------------
  184. align 4
  185. noterm:
  186. ;special buttons
  187.         dec     eax
  188.         jz      close
  189.  
  190.         sub     eax,50
  191.         jz      pgdn      ;51
  192.  
  193.         dec     eax
  194.         jz      pgup      ;52
  195.  
  196.         dec     eax
  197.         jz      program_start   ;53
  198.  
  199.         dec     eax
  200.         jz      reboot  ;54
  201.  
  202.         jmp     still_end
  203. ;buttons handlers    
  204. ;------------------------------------------------------------------------------
  205. align 4
  206. pgdn:
  207.         sub     [list_start],display_processes
  208. ;       cmp     [list_start],0
  209.         jge     show_process_info_1     ;still_end  
  210.         mov     [list_start],0
  211.         jmp     show_process_info_1     ;still_end  
  212. ;------------------------------------------------------------------------------
  213. align 4
  214. pgup:
  215.         mov     eax,[list_add]  ;maximal displayed process slot
  216.         mov     [list_start],eax
  217.         jmp     show_process_info_1     ;still_end  
  218. ;------------------------------------------------------------------------------
  219. align 4    
  220. program_start:    
  221.         mcall   70,file_start
  222.         jmp     show_process_info_1     ;still_end
  223. ;------------------------------------------------------------------------------
  224. align 4
  225. reboot:    
  226.         mcall   70,sys_reboot
  227. ;close program if we going to reboot
  228. ;------------------------------------------------------------------------------
  229. align 4
  230. close:
  231.         or      eax,-1          ; close this program
  232.         mcall
  233. ;------------------------------------------------------------------------------
  234. align 4
  235. draw_next_process:
  236. ;input:
  237. ;  edi - current slot
  238. ;  [curposy] - y position
  239. ;output:
  240. ;  edi - next slot (or -1 if no next slot)
  241. ;registers corrupted!
  242. ;delete old button
  243.         mov     edx,[index]
  244.         add     edx,(1 shl 31)+11
  245.         mcall   8
  246. ;create terminate process button
  247.         mov     ecx,[curposy]
  248.         shl     ecx,16
  249.         mov     cx,10
  250.         mov     edx,[index]
  251.         add     edx,11
  252.         mov     esi,0xaabbcc
  253. ;contrast    
  254.         test    dword [index],1
  255.         jz      .change_color_button
  256.         mov     esi,0x8899aa
  257. ;--------------------------------------
  258. align 4
  259. .change_color_button:
  260.         mcall   ,<10,99>
  261. ;draw background for proccess information
  262. ; ecx was already set
  263.         mov     edx,0x88ff88
  264. ;contrast
  265.         test    dword [index],1
  266.         jz      .change_color_info
  267.         mov     edx,0xddffdd
  268. ;--------------------------------------
  269. align 4
  270. .change_color_info:
  271.         mcall   13,<110,395>
  272. ;nothing else should be done
  273. ;if there is no process for this button    
  274.         test    edi,edi
  275.         jl      .ret
  276. ;--------------------------------------
  277. align 4
  278. .return_1:
  279. ;find process
  280.         inc     edi
  281. ;more comfortable register for next loop    
  282.         mov     ecx,edi
  283. ;precacluate pointer to process buffer    
  284.         mov     ebx,process_info_buffer
  285. ;--------------------------------------
  286. align 4
  287. .find_loop:
  288.         cmp     ecx,256
  289.         jge     .no_processes
  290. ;load process information in buffer
  291.         mcall   9
  292. ;if current slot greater than maximal slot,
  293. ;there is no more proccesses.    
  294.         cmp     ecx,eax
  295.         jg      .no_processes
  296. ;if slot state is equal to 9, it is empty.    
  297.         cmp     [process_info_buffer+process_information.slot_state],9
  298.         jnz     .process_found
  299.    
  300.         inc     ecx
  301.         jmp     .find_loop
  302. ;--------------------------------------
  303. align 4
  304. .no_processes:
  305.         or      edi,-1
  306.         ret
  307. ;--------------------------------------
  308. align 4
  309. .process_found:
  310. ;check on/off check box
  311.         push    edi
  312.         lea     edi,[check1]
  313.         test    dword ch_flags,ch_flag_en
  314.         pop     edi
  315.         jnz     @f
  316.  
  317.         cmp     dword [process_info_buffer+10],'ICON'
  318.         jz      .return_1
  319.  
  320.         cmp     dword [process_info_buffer+10],'OS/I'
  321.         jz      .return_1
  322.  
  323.         cmp     byte [process_info_buffer+10],'@'
  324.         jz      .return_1
  325. ;--------------------------------------
  326. align 4
  327. @@:
  328.         mov     edi,ecx
  329.         mov     [list_add],ecx
  330. ;get processor cpeed    
  331. ;for percent calculating
  332.         mcall   18,5
  333.         xor     edx,edx
  334.         mov     ebx,100
  335.         div     ebx
  336. ;eax = number of operation for 1% now
  337. ;calculate process cpu usage percent
  338.         mov     ebx,eax
  339.         mov     eax,[process_info_buffer+process_information.cpu_usage]
  340. ;       cdq
  341.         xor     edx,edx ; for CPU more 2 GHz - mike.dld
  342.         div     ebx
  343.         mov     [cpu_percent],eax
  344. ;set text color to display process information
  345. ;([tcolor] variable)
  346. ;0%      : black    
  347. ;1-80%   : green
  348. ;81-100% : red
  349.         test    eax,eax
  350.         jnz     .no_black
  351.  
  352.         mov     [tcolor],eax
  353.         jmp     .color_set
  354. ;--------------------------------------
  355. align 4
  356. .no_black:  
  357.         cmp     eax,80
  358.         ja      .no_green
  359.  
  360.         mov     dword [tcolor],0x107a30
  361.         jmp     .color_set
  362. ;--------------------------------------
  363. align 4
  364. .no_green:
  365.         mov     dword [tcolor],0xac0000
  366. ;--------------------------------------
  367. align 4
  368. .color_set:
  369. ;show slot number
  370. ;ecx haven't changed since .process_found    
  371. ;       mov     ecx,edi
  372.         mov     edx,[curposy]
  373.         add     edx,15*65536+1
  374.         mcall   47,<2,256>,,,[tcolor]
  375. ;show process name
  376.         mov     ebx,[curposy]
  377.         add     ebx,45*65536+1
  378.         mcall   4,,[tcolor],process_info_buffer.process_name,11
  379. ;show pid
  380.         mov     edx,[curposy]
  381.         add     edx,125*65536+1
  382.         mcall   47,<8,256>,[process_info_buffer.PID],,[tcolor]
  383. ;show cpu usage
  384.         add     edx,60*65536
  385.         mcall   ,,[process_info_buffer.cpu_usage]
  386. ;show cpu percent
  387.         add     edx,60*65536
  388.         mcall   ,<3,0>,[cpu_percent]
  389. ;show memory start - obsolete
  390.         add     edx,30*65536
  391.         mcall   ,<8,256>,[process_info_buffer.memory_start]
  392. ;show memory usage
  393.         mov     ecx,[process_info_buffer.used_memory]
  394.         inc     ecx
  395.         add     edx,60*65536
  396.         mcall
  397. ;show window stack and value
  398.         add     edx,60*65536
  399.         mcall   ,,dword [process_info_buffer.window_stack_position]
  400. ;show window xy size
  401.         mov     ecx,[process_info_buffer.box.left]
  402.         shl     ecx,16
  403.         add     ecx,[process_info_buffer.box.top]
  404.         add     edx,60*65536
  405.         mcall
  406. ;--------------------------------------
  407. align 4
  408. .ret:
  409. ;build index->slot map for terminating processes.
  410.         mov     eax,[index]
  411.         mov     [tasklist+4*eax],edi         
  412.         ret
  413. ;------------------------------------------------------------------------------
  414. align 4
  415. f11:
  416. ;full update  
  417.         push    edi
  418.         call    draw_window
  419.         pop     edi
  420. ;------------------------------------------------------------------------------
  421. ;   *********************************************
  422. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  423. ;   *********************************************
  424. align 4
  425. draw_window:
  426.         mcall   12, 1                  
  427. ; DRAW WINDOW
  428.         xor     eax,eax                         ; function 0 : define and draw window
  429.         xor     esi,esi
  430.         mcall   ,[winxpos],[winypos],0x34ddffdd,,title
  431. ; function 4 : write text to window
  432.         xor     ecx,ecx
  433.         mcall   4,<17,13>,,text,text_len
  434.  
  435.         push    dword edit1
  436.         call    [edit_box_draw]
  437.  
  438.         push    dword check1
  439.         call    [check_box_draw]
  440.  
  441.         mcall   26,9
  442.         add     eax,100
  443.         mov     [time_counter],eax
  444.  
  445.         call    show_process_info
  446. ; previous page button
  447.         mcall   8,<25,96>,<358,10>,51,0xaabbcc
  448. ; next page button  52
  449.         inc     edx
  450.         mcall   ,<125,96>
  451. ; ">" (text enter) button
  452.         add     ecx,20 shl 16
  453. ; run button 53
  454.         inc     edx
  455.         mcall   ,<451,50>
  456. ; reboot button    
  457.         sub     ebx,120*65536              
  458.         add     ebx,60
  459.         sub     ecx,20 shl 16
  460.         inc     edx
  461.         mcall
  462. ;"PREV PAGE", "NEXT PAGE" and "REBOOT" labels
  463.         xor     ecx,ecx
  464.         mcall   4,<45,360>,,tbts,tbte-tbts
  465. ;"RUN" labels
  466.         mcall   ,<464,380>,,tbts_3,tbte_2-tbts_3
  467. ;print application name in text box
  468.         mcall   12, 2
  469.         ret
  470. ;------------------------------------------------------------------------------
  471. align 4
  472. show_process_info:
  473.         mov     edi,[list_start]
  474.         mov     [list_add],edi
  475.         mov     dword [index],0
  476.         mov     dword [curposy],32
  477. ;--------------------------------------
  478. align 4
  479. .loop_draw:
  480.         call    draw_next_process
  481.         inc     dword [index]
  482.         add     dword [curposy],10
  483.         cmp     [index],display_processes
  484.         jl      .loop_draw
  485.         ret
  486. ;------------------------------------------------------------------------------
  487. ; DATA AREA
  488. ;------------------------------------------------------------------------------
  489. system_path      db '/sys/lib/'
  490. library_name     db 'box_lib.obj',0
  491. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  492.  
  493. err_message_found_lib   db 'Sorry I cannot load library box_lib.obj',0
  494. head_f_i:
  495. head_f_l        db 'System error',0
  496. err_message_import      db 'Error on load import library box_lib.obj',0
  497. ;------------------------------------------------------------------------------
  498. align 4
  499. myimport:  
  500. edit_box_draw           dd aEdit_box_draw
  501. edit_box_key            dd aEdit_box_key
  502. edit_box_mouse          dd aEdit_box_mouse
  503. ;version_ed             dd aVersion_ed
  504.  
  505. check_box_draw          dd aCheck_box_draw
  506. check_box_mouse         dd aCheck_box_mouse
  507. ;version_ch             dd aVersion_ch
  508.  
  509. ;option_box_draw        dd aOption_box_draw
  510. ;option_box_mouse       dd aOption_box_mouse
  511. ;version_op             dd aVersion_op
  512.  
  513.                 dd 0
  514.                 dd 0
  515.  
  516. aEdit_box_draw          db 'edit_box',0
  517. aEdit_box_key           db 'edit_box_key',0
  518. aEdit_box_mouse         db 'edit_box_mouse',0
  519. ;aVersion_ed            db 'version_ed',0
  520.  
  521. aCheck_box_draw         db 'check_box_draw',0
  522. aCheck_box_mouse        db 'check_box_mouse',0
  523. ;aVersion_ch            db 'version_ch',0
  524.  
  525. ;aOption_box_draw       db 'option_box_draw',0
  526. ;aOption_box_mouse      db 'option_box_mouse',0
  527. ;aVersion_op            db 'version_op',0
  528. ;------------------------------------------------------------------------------
  529. align 4
  530. check1 check_box 10,378,6,11,0x80AABBCC,0,0,check_text,check_t_e,0;ch_flag_en
  531. check1_end:
  532. edit1 edit_box 350,95,376,0xffffff,0x6f9480,0,0xAABBCC,0,start_application_c,\
  533.    start_application,mouse_dd,ed_focus,start_application_e,start_application_e
  534. edit1_end:
  535. list_start  dd 0
  536. ;------------------------------------------------------------------------------
  537. align 4
  538. sys_reboot:
  539.             dd 7
  540.             dd 0
  541.             dd 0
  542.             dd 0
  543.             dd 0
  544.             db '/sys/end',0
  545. ;------------------------------------------------------------------------------
  546. if lang eq de
  547. text:
  548.         db 'NAME/BEENDEN        PID     CPU-LAST   % '
  549.         db 'SPEICHER START/NUTZUNG  W-STACK   W-SIZE'
  550. text_len = $-text
  551.  
  552. tbts:   db 'SEITE ZURUECK       SEITE VOR                      REBOOT SYSTEM'
  553. tbte:
  554. tbts_3  db 'START'
  555. tbte_2:
  556. check_text      db '@ on/off'
  557. check_t_e=$-check_text
  558. title   db 'Prozesse  - Ctrl/Alt/Del',0
  559. ;--------------------------------------
  560. else if lang eq et
  561. text:
  562.         db 'NIMI/LÕPETA         PID    CPU-KASUTUS %   '
  563.         db 'MÄLU ALGUS/KASUTUS  W-PUHVER  W-SUURUS'
  564. text_len = $-text
  565.  
  566. tbts:   db 'EELMINE LEHT   JÄRGMINE LEHT                     REBOODI SÜSTEEM'
  567. tbte:
  568. tbts_3  db 'START'
  569. tbte_2:
  570. check_text      db '@ on/off'
  571. check_t_e=$-check_text
  572. title   db 'Protsessid - Ctrl/Alt/Del'
  573. ;--------------------------------------
  574. else if lang eq ru
  575. text:
  576.         db 'ˆŒŸ/‡€‚…˜ˆ’œ      PID     CPU-‡€ƒ“‡Š€ %  '
  577.         db '€ŒŸ’œ €—€‹Ž/‚‘…ƒŽ  W-STACK    W-SIZE'
  578. text_len = $-text
  579.  
  580. tbts:   db '…„.‘’        ‘‹…„.‘’                          ……‡€ƒ“‡Š€'
  581. tbte:
  582. tbts_3  db '‡€“‘Š'
  583. tbte_2:
  584. check_text      db '@ ¢ª«/¢ëª«'
  585. check_t_e=$-check_text
  586. title   db '„¨á¯¥âç¥à ¯à®æ¥áᮢ - Ctrl/Alt/Del',0
  587. ;--------------------------------------
  588. else
  589. text:
  590.         db 'NAME/TERMINATE      PID     CPU-USAGE  %   '
  591.         db 'MEMORY START/USAGE  W-STACK    W-SIZE'
  592. text_len = $-text
  593.  
  594. tbts:   db 'PREV PAGE       NEXT PAGE                         REBOOT SYSTEM'
  595. tbte:
  596. tbts_3  db ' RUN'
  597. tbte_2:
  598. check_text      db '@ on/off'
  599. check_t_e=$-check_text
  600. title   db 'Process manager - Ctrl/Alt/Del',0
  601.  
  602. end if
  603. ;------------------------------------------------------------------------------
  604. align 4
  605. file_start:
  606.         dd 7
  607.         dd 0
  608.         dd 0
  609.         dd 0
  610.         dd 0
  611. start_application: db '/sys/LAUNCHER',0
  612. start_application_e=$-start_application-1
  613. ;                   times 60 db 0
  614.         rb 60
  615. start_application_c=$-start_application-1
  616. ;------------------------------------------------------------------------------
  617. IM_END:
  618. ;------------------------------------------------------------------------------
  619. align 4
  620. sc system_colors
  621. winxpos         rd 1
  622. winypos         rd 1
  623. mouse_dd        rd 1
  624. cpu_percent     rd 1
  625. tcolor          rd 1
  626. list_add        rd 1
  627. curposy         rd 1
  628. index           rd 1
  629. tasklist        rd display_processes
  630. time_counter    rd 1
  631. ;------------------------------------------------------------------------------
  632. align 4
  633. library_path:
  634. process_info_buffer process_information
  635. ;------------------------------------------------------------------------------
  636. align 4
  637. cur_dir_path:
  638.         rb 1024
  639. ;------------------------------------------------------------------------------
  640. align 4
  641.         rb 1024
  642. stack_area:
  643. ;------------------------------------------------------------------------------
  644. U_END:
  645. ;------------------------------------------------------------------------------
  646.