Subversion Repositories Kolibri OS

Rev

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