Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ;   PROCESS MANAGEMENT
  3. ;
  4. ;   VTurjanmaa
  5. ;   additions by M.Lisovin lisovin@26.ru
  6. ;   integrated with load_lib.obj by <Lrz>
  7. ;   Compile with FASM for Menuet
  8. ;
  9.  
  10.   use32
  11.   org    0x0
  12. STACK_SIZE=1024
  13. offset_y=22
  14. offset_x=5
  15.   db     'MENUET01'              ; 8 byte id
  16.   dd     0x01                    ; header version
  17.   dd     START                   ; start of code
  18.   dd     I_END                   ; size of image
  19.   dd     U_END+STACK_SIZE        ; memory for app
  20.   dd     U_END+STACK_SIZE        ; esp
  21.   dd     0x0 , 0x0               ; I_Param , I_Icon
  22.  
  23. include 'lang.inc'
  24. include '../../../macros.inc'
  25. include '../../../develop/libraries/box_lib/asm/trunk/editbox_ex.mac'
  26. include '../../../develop/libraries/box_lib/load_lib.mac'
  27. display_processes=32            ; number of processes to show
  28. @use_library    ;use load lib macros
  29. START:                          ; start of execution
  30.  
  31. sys_load_library  library_name, cur_dir_path, library_path, system_path, \
  32. err_message_found_lib, head_f_l, myimport, err_message_import, head_f_i
  33.         inc     eax
  34.         jz      close
  35. ; calculate window position
  36. ; at the center of the screen
  37.     call calculate_window_pos
  38.    
  39. ;main loop when process name isn't edited.    
  40. red:    
  41.         xor     ebp,ebp
  42.         inc     ebp
  43. ;    mov  ebp,1
  44.     call draw_window            ; redraw all window
  45. align 16
  46. still:
  47.     mov  eax,23                 ; wait here for event
  48.     mov  ebx,100                ; 2 sec.
  49.     mcall
  50.  
  51.     dec  eax                  ; redraw request ?
  52.     jz   red
  53.     dec  eax                  ; key in buffer ?
  54.     jz   key
  55.     dec  eax                  ; button in buffer ?
  56.     jz   button
  57.  
  58.         push    dword edit1
  59.         call    [edit_box_mouse]
  60.  
  61.  
  62. still_end:    
  63.     xor  ebp,ebp                ; draw new state of processes
  64.     call draw_window
  65.     jmp  still
  66.  
  67.  
  68.   key:                          ; key
  69.     mov  eax,2                  
  70.     mcall
  71.  
  72.     cmp  ah,184                 ; PageUp
  73.     je   pgdn
  74.     cmp  ah,183
  75.     je   pgup                   ; PageDown
  76.     cmp  ah,27
  77.     je   close                  ; Esc
  78.  
  79.         push    dword edit1
  80.         call    [edit_box_key]
  81.  
  82.     jmp  still_end
  83.  
  84.   button:                      
  85. ; get button id  
  86.     mov  eax,17                
  87.     mcall
  88.     shr  eax,8                  
  89.  
  90. ;id in [10,50] corresponds to terminate buttons.
  91.     cmp  eax,10
  92.     jb   noterm                
  93.     cmp  eax,50
  94.     jg   noterm
  95.  
  96. ;calculate button index        
  97.     sub  eax,11
  98.    
  99. ;calculate process slot    
  100.     mov  ecx,[tasklist+4*eax]
  101.    
  102. ;ignore empty buttons
  103.     test ecx,ecx
  104.     jle  still_end
  105. ;terminate application    
  106.     mov  eax,18
  107.     mov  ebx,2
  108.     mcall
  109.     jmp  still_end
  110.  
  111.   noterm:
  112.  
  113. ;special buttons
  114.     dec  eax
  115.     jz   close
  116.  
  117.     sub  eax,50
  118.     jz   pgdn     ;51
  119.     dec  eax
  120.     jz   pgup     ;52
  121. ;    dec  eax
  122. ;    jz   read_string
  123.     dec  eax
  124.     jz   program_start  ;53
  125.     dec  eax
  126.     jz   reboot         ;54
  127.     jmp  still_end
  128.    
  129. ;buttons handlers    
  130.  
  131.   pgdn:
  132.     sub  [list_start],display_processes
  133. ;    cmp  [list_start],0
  134.     jge  still_end  
  135.     mov  [list_start],0
  136.     jmp  still_end  
  137.  
  138.   pgup:
  139.     mov  eax,[list_add]  ;maximal displayed process slot
  140.     mov  [list_start],eax
  141.     jmp  still_end  
  142.    
  143.   program_start:    
  144.     mov  eax,70
  145.     mov  ebx,file_start
  146.     mcall
  147.     jmp  still_end
  148.    
  149.   reboot:    
  150.     mov  eax,70
  151.     mov  ebx,sys_reboot
  152.     mcall
  153. ;close program if we going to reboot
  154.  
  155.   close:
  156.     or   eax,-1                 ; close this program
  157.     mcall
  158.  
  159. draw_next_process:
  160. ;input:
  161. ;  edi - current slot
  162. ;  [curposy] - y position
  163. ;output:
  164. ;  edi - next slot (or -1 if no next slot)
  165. ;registers corrupted!
  166.    
  167. ;create button
  168.     test  ebp,ebp
  169.     jnz   .nodelete
  170. ;delete old button
  171.     mov   eax,8
  172.     mov   edx,[index]
  173.     add   edx,(1 shl 31)+11
  174.     mcall
  175.  
  176. .nodelete:
  177. ;create terminate process button
  178.     mov   eax,8
  179.     mov   ebx,(15-offset_x)*65536+100-offset_y
  180.     mov   ecx,[curposy]
  181.     shl   ecx,16
  182.     mov   cx,10
  183.     mov   edx,[index]
  184.     add   edx,11
  185.     mov   esi,0xaabbcc
  186. ;contrast    
  187.     test  dword [index],1
  188.     jz    .change_color_button
  189.     mov   esi,0x8899aa
  190.  
  191. .change_color_button:
  192.     mcall
  193.    
  194. ;draw background for proccess information
  195.     mov   eax,13
  196.     mov   ebx,(115-offset_x)*65536+395
  197.     ;ecx was already set
  198.     mov   edx,0x88ff88
  199. ;contrast
  200.     test  dword [index],1
  201.     jz    .change_color_info
  202.     mov   edx,0xddffdd
  203.  
  204. .change_color_info:
  205.     mcall
  206.    
  207. ;nothing else should be done
  208. ;if there is no process for this button    
  209.     test  edi,edi
  210.     jl    .ret
  211.    
  212. ;find process
  213.     inc   edi
  214. ;more comfortable register for next loop    
  215.     mov   ecx,edi
  216. ;precacluate pointer to process buffer    
  217.     mov   ebx,process_info_buffer
  218.    
  219. ;find process loop
  220.  
  221. .find_loop:
  222.     cmp   ecx,256
  223.     jge   .no_processes
  224.    
  225. ;load process information in buffer
  226.     mov   eax,9
  227. ;    mov   ebx,process_info_buffer
  228.     mcall
  229.    
  230. ;if current slot greater than maximal slot,
  231. ;there is no more proccesses.    
  232.     cmp   ecx,eax
  233.     jg    .no_processes
  234.    
  235. ;if slot state is equal to 9, it is empty.    
  236.     cmp   [process_info_buffer+process_information.slot_state],9
  237.     jnz   .process_found
  238.    
  239.     inc   ecx
  240.     jmp   .find_loop
  241.    
  242. .no_processes:
  243.     or   edi,-1
  244.     ret
  245.    
  246. .process_found:
  247.     mov  edi,ecx
  248.     mov  [list_add],ecx
  249.    
  250. ;get processor cpeed    
  251. ;for percent calculating
  252.     mov  eax,18
  253.     mov  ebx,5
  254.     mcall
  255.    
  256.     xor  edx,edx
  257.     mov  ebx,100
  258.     div ebx
  259.    
  260. ;eax = number of operation for 1% now
  261. ;calculate process cpu usage percent
  262.     mov  ebx,eax
  263.     mov  eax,[process_info_buffer+process_information.cpu_usage]
  264. ;    cdq
  265.     xor edx,edx ; for CPU more 2 GHz - mike.dld
  266.  
  267.     div  ebx
  268.     mov  [cpu_percent],eax
  269.    
  270. ;set text color to display process information
  271. ;([tcolor] variable)
  272. ;0%      : black    
  273. ;1-80%   : green
  274. ;81-100% : red
  275.     test eax,eax
  276.     jg   .no_black
  277.     mov  [tcolor],eax
  278.     jmp  .color_set
  279.  
  280. .no_black:  
  281.     cmp  eax,80
  282.     ja   .no_green
  283.     mov  dword [tcolor],0x107a30
  284.     jmp  .color_set
  285.  
  286. .no_green:
  287.     mov  dword [tcolor],0xac0000
  288. .color_set:
  289.  
  290. ;show slot number
  291.     mov  eax,47                
  292.     mov  ebx,2*65536+1*256
  293. ;ecx haven't changed since .process_found    
  294. ;    mov  ecx,edi
  295.     mov  edx,[curposy]
  296.     add  edx,(20-offset_x)*65536+1
  297.     mov  esi,[tcolor]
  298.     mcall
  299.    
  300. ;show process name
  301.     mov  eax,4
  302.     mov  ebx,[curposy]
  303.     add  ebx,(50-offset_x)*65536+1
  304.     mov  ecx,[tcolor]
  305.     mov  edx,process_info_buffer.process_name
  306.     mov  esi,11
  307.     mcall
  308.    
  309. ;show pid
  310.     mov  eax,47
  311.     mov  ebx,8*65536+1*256
  312.     mov  ecx,[process_info_buffer.PID]
  313.     mov  edx,[curposy]
  314.     add  edx,(130-offset_x)*65536+1
  315.     mov  esi,[tcolor]
  316.     mcall
  317.    
  318. ;show cpu usage
  319.     mov  ecx,[process_info_buffer.cpu_usage]
  320.     add  edx,60*65536
  321.     mcall
  322.    
  323. ;show cpu percent
  324.     mov  ebx,3*65536+0*256
  325.     mov  ecx,[cpu_percent]
  326.     add  edx,60*65536
  327.     mcall
  328.    
  329. ;show memory start - obsolete
  330.     mov  ebx,8*65536+1*256
  331.     mov  ecx,[process_info_buffer.memory_start]
  332.     add  edx,30*65536
  333.     mcall
  334.    
  335. ;show memory usage
  336.     mov  ecx,[process_info_buffer.used_memory]
  337.     inc  ecx
  338.     add  edx,60*65536
  339.     mcall
  340.    
  341. ;show window stack and value
  342.     mov  ecx,dword [process_info_buffer.window_stack_position]
  343.     add  edx,60*65536
  344.     mcall
  345.    
  346. ;show window xy size
  347.     mov  ecx,[process_info_buffer.box.left]
  348.     shl  ecx,16
  349.     add  ecx,[process_info_buffer.box.top]
  350.     add  edx,60*65536
  351.     mcall    
  352.            
  353. .ret:
  354. ;build index->slot map for terminating processes.
  355.     mov  eax,[index]
  356.     mov  [tasklist+4*eax],edi        
  357.     ret
  358.  
  359. ;read_string:
  360. ;clean string
  361. ;    mov  edi,start_application
  362. ;    xor  eax,eax
  363. ;    mov  ecx,60
  364. ;    cld
  365. ;    rep  stosb
  366. ;    call print_text
  367.  
  368. ;    mov  edi,start_application
  369. ;edi now contains pointer to last symbol      
  370. ;    jmp  still1
  371.  
  372. ;read string main loop
  373.  
  374.   f11:
  375. ;full update  
  376.     push edi
  377.         xor     ebp,ebp
  378.         inc     ebp
  379. ;    mov  ebp,1
  380.     call draw_window
  381.     pop  edi
  382. ;
  383. ;  still1:  
  384. ;wait for message  
  385. ;    mov  eax,23
  386. ;    mov  ebx,100
  387. ;    mcall
  388. ;    cmp  eax,1
  389. ;    je   f11
  390. ;if no message - update process information    
  391. ;    cmp  eax,0
  392. ;    jnz  .message_received
  393. ;    push edi                ;edi should be saved since draw_window
  394. ;    xor  ebp,ebp            ;corrupt registers
  395. ;    call draw_window
  396. ;    pop  edi
  397. ;    jmp  still1
  398. ;    
  399. ;.message_received:
  400. ;    cmp  eax,2
  401. ;    jne  read_done          ;buttons message
  402. ;read char    
  403. ;    mov  eax,2
  404. ;    mcall
  405. ;    shr  eax,8
  406.    
  407. ;if enter pressed, exit read string loop    
  408. ;    cmp  eax,13
  409. ;    je   read_done
  410. ;if backslash pressed?    
  411. ;    cmp  eax,8
  412. ;    jnz  nobsl
  413. ;decrease pointer to last symbol    
  414. ;    cmp  edi,start_application
  415. ;    jz   still1
  416. ;    dec  edi
  417. ;fill last symbol with space because
  418. ;print_text show all symbols    
  419. ;    mov  [edi],byte 32
  420. ;    call print_text
  421. ;    jmp  still1
  422. ;    
  423. ;  nobsl:
  424. ;write new symbol  
  425. ;    mov  [edi],al
  426. ;display new text
  427. ;    call print_text
  428. ;increment pointer to last symbol
  429. ;    inc  edi
  430. ;compare with end of string    
  431. ;    mov  esi,start_application
  432. ;    add  esi,60
  433. ;    cmp  esi,edi
  434. ;    jnz  still1
  435.  
  436. ;exiting from read string loop
  437. ;
  438. ;  read_done:
  439. ;terminate string for file functions
  440. ;    mov  [edi],byte 0
  441.  
  442. ;    call print_text
  443. ;    jmp  still
  444.  
  445. ;
  446. ;print_text:
  447. ;display start_application string
  448.  
  449. ;    pushad
  450.    
  451. ;display text background
  452. ;    mov  eax,13
  453. ;    mov  ebx,64*65536+62*6
  454. ;    mov  ecx,400*65536+12
  455. ;    mov  edx,0xffffcc  ;0xeeeeee
  456. ;    mcall
  457.    
  458. ;display text    
  459. ;    mov  eax,4                  
  460. ;    mov  edx,start_application  ;from start_application string
  461. ;    mov  ebx,70*65536+402       ;text center-aligned
  462. ;    xor  ecx,ecx                ;black text
  463. ;    mov  esi,60                 ;60 symbols
  464. ;    mcall
  465.  
  466. ;    popad
  467. ;    ret
  468.  
  469. window_x_size=524
  470. window_y_size=430
  471.  
  472. calculate_window_pos:
  473. ;set window size and position for 0 function
  474. ;to [winxpos] and [winypos] variables
  475.  
  476. ;get screen size
  477.     mov  eax,14
  478.     mcall
  479.     mov  ebx,eax
  480.    
  481. ;calculate (x_screen-window_x_size)/2    
  482.     shr  ebx,16+1
  483.     sub  ebx,window_x_size/2
  484.     shl  ebx,16
  485.     mov  bx,window_x_size
  486. ;winxpos=xcoord*65536+xsize    
  487.     mov  [winxpos],ebx
  488.    
  489. ;calculate (y_screen-window_y_size)/2    
  490.     and  eax,0xffff
  491.     shr  eax,1
  492.     sub  eax,window_y_size/2
  493.     shl  eax,16
  494.     mov  ax,window_y_size
  495. ;winypos=ycoord*65536+ysize    
  496.     mov  [winypos],eax
  497.    
  498.     ret
  499.  
  500. ;   *********************************************
  501. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  502. ;   *********************************************
  503.  
  504. align 16
  505. draw_window:
  506. ;ebp=1 - redraw all
  507. ;ebp=0 - redraw only process information
  508.  
  509.     test ebp,ebp
  510.     jz   .show_process_info
  511.    
  512.     mov  eax,12                    ; function 12:tell os about windowdraw
  513. ;    mov  ebx,1                     ; 1, start of draw
  514.     xor  ebx,ebx
  515.     inc  ebx
  516.     mcall                      
  517.  
  518.                                    ; DRAW WINDOW
  519.     xor  eax,eax                   ; function 0 : define and draw window
  520.     mov  ebx,[winxpos]             ; [x start] *65536 + [x size]
  521.     mov  ecx,[winypos]             ; [y start] *65536 + [y size]
  522.     mov  edx,0x34ddffdd  ;ffffff   ; color of work area RRGGBB,8->color
  523.     mov  edi,title                ; WINDOW CAPTION;
  524.     mcall
  525.  
  526.                                    
  527.     add  eax,4                     ; function 4 : write text to window
  528.     mov  ebx,(22-offset_x)*65536+35-offset_y           ; draw info text with function 4
  529.     xor  ecx,ecx
  530.     mov  edx,text
  531.     mov  esi,text_len
  532.     mcall
  533.  
  534.         push    dword edit1
  535.         call    [edit_box_draw]
  536.  
  537. align 16
  538. .show_process_info:
  539.     mov  edi,[list_start]
  540.     mov  [list_add],edi
  541.     mov  dword [index],0
  542.     mov  dword [curposy],54-offset_y
  543.  
  544. .loop_draw:
  545.     call draw_next_process
  546.     inc  dword [index]
  547.     add  dword [curposy],10
  548.     cmp  [index],display_processes
  549.     jl   .loop_draw
  550.    
  551.     test ebp,ebp
  552.     jz   .end_redraw
  553.     mov  eax,8
  554.     mov  esi,0xaabbcc
  555.                                    
  556. ; previous page button
  557.     mov  ebx,(30-offset_x)*65536+96
  558.     mov  ecx,(380-offset_y)*65536+10
  559.     mov  edx,51
  560.     mcall
  561.                                    
  562. ; next page button  52
  563.     mov  ebx,(130-offset_x)*65536+96
  564.     inc  edx
  565.     mcall
  566.                              
  567. ; ">" (text enter) button
  568. ;    mov  ebx,30*65536+20
  569.     add  ecx,20 shl 16
  570. ;    inc  edx
  571. ;    mcall
  572.                                    
  573. ; run button 53
  574.     mov  ebx,(456-offset_x)*65536+50
  575.     inc  edx
  576.     mcall
  577.  
  578. ; reboot button    
  579.     sub  ebx,120*65536              
  580.     add  ebx,60
  581.     sub  ecx,20 shl 16
  582.     inc  edx
  583.     mcall
  584.    
  585. ;"PREV PAGE", "NEXT PAGE" and "REBOOT" labels
  586.     mov  eax,4
  587.     mov  ebx,(50-offset_x)*65536+382-offset_y
  588.     xor  ecx,ecx
  589.     mov  edx,tbts
  590.     mov  esi,tbte-tbts
  591.     mcall
  592.  
  593. ;">" labels
  594. ;    mov  eax,4
  595. ;    mov  ebx,40*65536+402
  596. ;    xor  ecx,ecx
  597. ;    mov  edx,tbts_2
  598. ;    mov  esi,1
  599. ;    mcall
  600.  
  601. ;"RUN" labels
  602. ;    mov  eax,4
  603.     mov  ebx,(475-offset_x)*65536+402-offset_y
  604.     xor  ecx,ecx
  605.     mov  edx,tbts_3
  606.     mov  esi,tbte_2-tbts_3
  607.     mcall
  608.  
  609. ;print application name in text box
  610. ;    call print_text
  611.  
  612.     mov  eax,12                    ; function 12:tell os about windowdraw
  613.     mov  ebx,2                     ; 2, end of draw
  614.     mcall
  615.    
  616. .end_redraw:
  617.     ret
  618.  
  619.  
  620. ; DATA AREA
  621. system_path      db '/sys/lib/'
  622. library_name     db 'box_lib.obj',0
  623. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  624.  
  625. err_message_found_lib   db 'Sorry I cannot load library box_lib.obj',0
  626. head_f_i:
  627. head_f_l        db 'System error',0
  628. err_message_import      db 'Error on load import library box_lib.obj',0
  629.  
  630. myimport:  
  631.  
  632. edit_box_draw   dd      aEdit_box_draw
  633. edit_box_key    dd      aEdit_box_key
  634. edit_box_mouse  dd      aEdit_box_mouse
  635. ;version_ed      dd      aVersion_ed
  636.  
  637. ;check_box_draw  dd      aCheck_box_draw
  638. ;check_box_mouse dd      aCheck_box_mouse
  639. ;version_ch      dd      aVersion_ch
  640.  
  641. ;option_box_draw  dd      aOption_box_draw
  642. ;option_box_mouse dd      aOption_box_mouse
  643. ;version_op       dd      aVersion_op
  644.  
  645.                 dd      0
  646.                 dd      0
  647.  
  648. aEdit_box_draw  db 'edit_box',0
  649. aEdit_box_key   db 'edit_box_key',0
  650. aEdit_box_mouse db 'edit_box_mouse',0
  651. ;aVersion_ed     db 'version_ed',0
  652.  
  653. ;aCheck_box_draw  db 'check_box_draw',0
  654. ;aCheck_box_mouse db 'check_box_mouse',0
  655. ;aVersion_ch      db 'version_ch',0
  656.  
  657. ;aOption_box_draw  db 'option_box_draw',0
  658. ;aOption_box_mouse db 'option_box_mouse',0
  659. ;aVersion_op       db 'version_op',0
  660.  
  661. edit1 edit_box 350,(64-offset_x),(398-offset_y),0xffffff,0x6f9480,0,0xAABBCC,0,start_application_c,start_application,ed_focus,start_application_e,start_application_e
  662.  
  663. list_start  dd 0
  664.  
  665. sys_reboot:
  666.             dd 7
  667.             dd 0
  668.             dd 0
  669.             dd 0
  670.             dd 0
  671.             db '/sys/end',0
  672.  
  673. if lang eq de
  674. text:
  675.   db 'NAME/BEENDEN        PID     CPU-LAST   % '
  676.   db 'SPEICHER START/NUTZUNG  W-STACK  W-SIZE'
  677. text_len = $-text
  678.  
  679. tbts:   db  'SEITE ZURUECK       SEITE VOR                      REBOOT SYSTEM'
  680. tbte:
  681. ;tbts_2  db  '>'
  682. tbts_3  db  'START'
  683. tbte_2:
  684.  
  685. title  db   'Prozesse  - Ctrl/Alt/Del',0
  686.  
  687. else if lang eq et
  688. text:
  689.   db 'NIMI/LÕPETA         PID    CPU-KASUTUS %   '
  690.   db 'MÄLU ALGUS/KASUTUS  W-PUHVER  W-SUURUS'
  691. text_len = $-text
  692.  
  693. tbts:   db  'EELMINE LEHT   JÄRGMINE LEHT                     REBOODI SÜSTEEM'
  694. tbte:
  695. ;tbts_2 db  '>'
  696. tbts_3  db  'START'
  697. tbte_2:
  698.  
  699. title  db   'Protsessid - Ctrl/Alt/Del',0
  700.  
  701. else
  702. text:
  703.   db 'NAME/TERMINATE      PID     CPU-USAGE  %   '
  704.   db 'MEMORY START/USAGE  W-STACK   W-SIZE'
  705. text_len = $-text
  706.  
  707. tbts:   db  'PREV PAGE       NEXT PAGE                         REBOOT SYSTEM'
  708. tbte:
  709. ;tbts_2  db  '>'
  710. tbts_3  db  'RUN'
  711. tbte_2:
  712.  
  713. title  db   'Processes - Ctrl/Alt/Del',0
  714.  
  715. end if
  716. file_start: dd 7
  717.             dd 0,0,0,0
  718. start_application: db '/sys/LAUNCHER',0
  719. start_application_e=$-start_application-1
  720. ;                   times 60 db 0
  721. rb      60
  722. start_application_c=$-start_application-1
  723.  
  724. I_END:
  725. winxpos  rd 1
  726. winypos  rd 1
  727.  
  728. cpu_percent rd 1
  729. tcolor      rd 1
  730. list_add    rd 1
  731. curposy     rd 1
  732. index       rd 1
  733. tasklist    rd display_processes
  734. process_info_buffer process_information
  735. cur_dir_path    rb 1024
  736. library_path    rb 1024
  737.  
  738. U_END:
  739.