Subversion Repositories Kolibri OS

Rev

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