Subversion Repositories Kolibri OS

Rev

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