Subversion Repositories Kolibri OS

Rev

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

  1. ;-----------------------;
  2. ; CPU - process manager ;
  3. ;-----------------------;
  4.  
  5.         format  binary as ""
  6.  
  7.         use32
  8.         org     0x0
  9.        
  10.         db      "MENUET01"              ; 8 byte id
  11.         dd      0x01             ; header version
  12.         dd      START           ; start of code
  13.         dd      IM_END          ; size of image
  14.         dd      U_END           ; memory for app
  15.         dd      stack_area              ; esp
  16.         dd      0x0                     ; boot parameters
  17.         dd      cur_dir_path     ; path
  18. ;-------------------------------------------------------------------------------
  19. include "lang.inc"
  20. include "../../../macros.inc"
  21. include "../../../develop/libraries/box_lib/trunk/box_lib.mac"
  22. include "../../../KOSfuncs.inc"
  23. include "../../../load_lib.mac"
  24. ;-------------------------------------------------------------------------------
  25. DISPLAY_PROCESSES = 20  ;number of processes to show
  26. ;-------------------------------------------------------------------------------
  27. WINDOW.WIDTH = PROCESS_TABLE.WIDTH + 10*2
  28. WINDOW.HEIGHT = WORK_AREA.HEIGHT + 30
  29. WORK_AREA.HEIGHT = CHECKBOX.Y + BUTTON.HEIGHT + 10
  30. PROCESS_TABLE:
  31.         .X = 10
  32.         .Y = 10
  33.         .WIDTH = 640
  34.         .HEIGHT = DISPLAY_PROCESSES * BUTTON.HEIGHT
  35. UNDERTABLE:
  36.         .X = PROCESS_TABLE.X
  37.         .Y = PROCESS_TABLE.Y + PROCESS_TABLE.HEIGHT + 20
  38. BUTTON:
  39.         .HEIGHT = 16 + 4
  40. EDITBOX:
  41.         .X = CHECKBOX.X + 100
  42.         .Y = UNDERTABLE.Y + BUTTON.HEIGHT + 25
  43.         .WIDTH = 465
  44.         .HEIGHT = 15
  45.        
  46. CHECKBOX:
  47.         .X = PROCESS_TABLE.X
  48.         .Y = UNDERTABLE.Y + BUTTON.HEIGHT + 25
  49. ;-------------------------------------------------------------------------------
  50. @use_library    ;use load lib macros
  51. ;-------------------------------------------------------------------------------
  52.         struc   utf8z   string
  53. {
  54.         .       db      string, 0
  55.         .size = $ - . - 1
  56. }
  57.  
  58. ;-------------------------------------------------------------------------------
  59. START:                          ; start of execution
  60.         mcall   SF_SYS_MISC,SSF_HEAP_INIT
  61.         sys_load_library        library_name, library_path, system_path, myimport
  62.         inc     eax
  63.         jz      close
  64. ;-------------------------------------------------------------------------------
  65.         mcall   SF_SET_EVENTS_MASK,0x80000027 ;set event
  66. ;-------------------------------------------------------------------------------
  67. ;set window size and position for 0 function
  68. ;to [winxpos] and [winypos] variables
  69. ;get screen size
  70.         mcall   SF_GET_SCREEN_SIZE
  71.         mov     ebx,eax
  72. ;calculate (x_screen-WINDOW.WIDTH)/2
  73.         shr     ebx,16+1
  74.         sub     ebx,WINDOW.WIDTH/2
  75.         shl     ebx,16
  76.         mov     bx,WINDOW.WIDTH
  77. ;winxpos=xcoord*65536+xsize
  78.         mov     [winxpos],ebx
  79. ;calculate (y_screen-WINDOW.HEIGHT)/2
  80.         and     eax,0xffff
  81.         shr     eax,1
  82.         sub     eax,WINDOW.HEIGHT/2
  83.         shl     eax,16
  84.         mov     ax,WINDOW.HEIGHT
  85. ;winypos=ycoord*65536+ysize
  86.         mov     [winypos],eax
  87. ;-------------------------------------------------------------------------------
  88.         init_checkboxes2 check1,check1_end
  89.         mcall   SF_STYLE_SETTINGS,SSF_GET_COLORS,sc,40
  90.         edit_boxes_set_sys_color edit1,edit1_end,sc             ;set color
  91.         ;check_boxes_set_sys_color2 check1,check1_end,sc ;set color
  92. ;-------------------------------------------------------------------------------
  93. align 4
  94. ;main loop when process name isn"t edited.
  95. red:
  96.         call    draw_window             ; redraw all window
  97. ;-------------------------------------------------------------------------------
  98. align 4
  99. still:
  100.         mcall   SF_WAIT_EVENT_TIMEOUT,100               ; wait here for event 1 sec.
  101.  
  102.         test    eax,eax
  103.         jz      still_end
  104.  
  105.         dec     eax                     ; redraw request ?
  106.         jz      red
  107.  
  108.         dec     eax                     ; key in buffer ?
  109.         jz      key
  110.  
  111.         dec     eax                     ; button in buffer ?
  112.         jz      button
  113.  
  114.         push    dword   edit1
  115.         call    [edit_box_mouse]
  116.  
  117.         push    dword[check1.flags]
  118.  
  119.         push    dword   check1
  120.         call    [check_box_mouse]
  121.  
  122.         pop     eax
  123.  
  124.         cmp     eax, dword[check1.flags]
  125.         jz      still_end
  126.  
  127.         push    dword   check1
  128.         call    [check_box_draw]
  129. ;-------------------------------------------------------------------------------
  130. align 4
  131. show_process_info_1:
  132.         mcall   SF_SYSTEM_GET, SSF_TIME_COUNT
  133.         add     eax, 100
  134.         mov     [time_counter],eax
  135.  
  136.         call    show_process_info       ; draw new state of processes
  137.         jmp     still
  138. ;-------------------------------------------------------------------------------
  139. align 4
  140. still_end:
  141.         mcall   SF_SYSTEM_GET,SSF_TIME_COUNT
  142.         cmp     [time_counter],eax
  143.         ja      still
  144.  
  145.         add     eax,100
  146.         mov     [time_counter],eax
  147.  
  148.         call    show_process_info       ; draw new state of processes
  149.         jmp     still
  150. ;-------------------------------------------------------------------------------
  151. align 4
  152. key:                            ; key
  153.         mcall   SF_GET_KEY
  154.  
  155.         cmp     ah,184          ; PageUp
  156.         jz      pgdn
  157.  
  158.         cmp     ah,183
  159.         jz      pgup                    ; PageDown
  160.  
  161.         cmp     ah,27
  162.         jz      close                   ; Esc
  163.  
  164.         push    dword   edit1
  165.         call    [edit_box_key]
  166.                                 ; Check ENTER with ed_focus edit_box
  167.         lea     edi,[edit1]
  168.         test    word    ed_flags,ed_focus
  169.         jz      still_end
  170.  
  171.         sub     ah,13                   ; ENTER?
  172.         jz      program_start           ; RUN a program
  173.  
  174.         jmp     still
  175. ;-------------------------------------------------------------------------------
  176. align 4
  177. button:
  178. ; get button id
  179.         mcall   SF_GET_BUTTON
  180.         mov     bl, al ; save mouse button to bl
  181.         shr     eax,8
  182. ;id in [10,50] corresponds to terminate buttons.
  183.         cmp     eax,10
  184.         jb      noterm
  185.  
  186.         cmp     eax,50
  187.         jg      noterm
  188. ;calculate button index
  189.         sub     eax,11
  190. ;calculate process slot
  191.         mov     ecx,[tasklist+4*eax]
  192. ;ignore empty buttons
  193.         test    ecx,ecx
  194.         jle     still_end
  195.         test    bl, bl ; check mouse button
  196.         jz      .terminate
  197.         mov     eax, ecx
  198.         mov     edi, tinfo.params_buf
  199. ;; number in eax
  200. ;; buffer in edi
  201. ; int2str:
  202.         push    0
  203.         mov     ecx, 10
  204. .push:
  205.         xor     edx, edx
  206.         div     ecx
  207.         add     edx, 48
  208.         push    edx
  209.         test    eax, eax
  210.         jnz     .push
  211. .pop:
  212.         pop     eax
  213.         stosb
  214.         test    eax, eax
  215.         jnz     .pop
  216. ; launch tinfo app
  217.         mov     ebx, tinfo
  218.         mov     eax, SF_FILE
  219.         int     64
  220.         jmp     show_process_info_1
  221. .terminate:
  222. ;terminate application
  223.         mcall   SF_SYSTEM,SSF_TERMINATE_THREAD
  224.         jmp     show_process_info_1
  225. ;-------------------------------------------------------------------------------
  226. align 4
  227. noterm:
  228. ;special buttons
  229.         dec     eax
  230.         jz      close
  231.  
  232.         sub     eax,50
  233.         jz      pgdn    ;51
  234.  
  235.         dec     eax
  236.         jz      pgup    ;52
  237.  
  238.         dec     eax
  239.         jz      reboot  ;53
  240.  
  241.         dec     eax
  242.         jz      program_start   ;54
  243.  
  244.         jmp     still_end
  245. ;buttons handlers
  246. ;-------------------------------------------------------------------------------
  247. align 4
  248. pgdn:
  249.         sub     [list_start],DISPLAY_PROCESSES
  250.         jge     show_process_info_1
  251.         mov     [list_start],0
  252.         jmp     show_process_info_1
  253. ;-------------------------------------------------------------------------------
  254. align 4
  255. pgup:
  256.         mov     eax,[list_add]  ;maximal displayed process slot
  257.         mov     [list_start],eax
  258.         jmp     show_process_info_1
  259. ;-------------------------------------------------------------------------------
  260. align 4
  261. program_start:
  262.         mcall   SF_FILE,file_start
  263.         jmp     show_process_info_1
  264. ;-------------------------------------------------------------------------------
  265. align 4
  266. reboot:
  267.         mcall   SF_FILE,sys_reboot
  268. ;close program if we going to reboot
  269. ;-------------------------------------------------------------------------------
  270. align 4
  271. close:
  272.         or      eax,SF_TERMINATE_PROCESS ; close this program
  273.         mcall
  274. ;-------------------------------------------------------------------------------
  275. align 4
  276. draw_empty_slot:
  277.         cmp     [draw_window_flag],1
  278.         je      @f
  279.         mov     ecx,[curposy]
  280.         shl     ecx,16
  281.         mov     cx, BUTTON.HEIGHT
  282.         mcall   SF_DRAW_RECT, <132, PROCESS_TABLE.WIDTH-131>, , [bar_bacground_color]
  283. @@:
  284.         ret
  285. ;-------------------------------------------------------------------------------
  286. align 4
  287. draw_next_process:
  288. ;input:
  289. ;       edi - current slot
  290. ;       [curposy] - y position
  291. ;output:
  292. ;       edi - next slot (or -1 if no next slot)
  293. ;registers corrupted!
  294. ;create terminate process button
  295.         mov     ecx,[curposy]
  296.         shl     ecx,16
  297.         mov     cx, BUTTON.HEIGHT
  298.         mov     edx,[index]
  299.         add     edx,11
  300.         mov     esi,0xccddee
  301.         test    dword   [index],1
  302.         jz      @f
  303.         mov     esi,0xaabbcc
  304. @@:
  305.                 add     edx,0x80000000 ; delete a button
  306.                 mcall   SF_DEFINE_BUTTON ; before create
  307.                 sub     edx,0x80000000 ; a new one below
  308.         mcall   SF_DEFINE_BUTTON,<10,120>
  309.         mov     [btn_bacground_color],esi
  310. ;draw background for proccess information
  311.         mov     edx,0xEFEFF5
  312.         test    dword   [index],1
  313.         jz      @f
  314.         mov     edx,0xffffff
  315. @@:
  316.         inc     cx
  317.  
  318.         mcall   SF_DRAW_RECT, <131, PROCESS_TABLE.WIDTH-131>
  319.  
  320.         mov     [bar_bacground_color],edx
  321. ;nothing else should be done if there is no process for this button
  322.         cmp     edi,-1
  323.         jne     .return_1
  324.  
  325.         call    draw_empty_slot
  326.         or      edi,-1
  327.         jmp     .ret
  328. ;-------------------------------------------------------------------------------
  329. align 4
  330. .return_1:
  331. ;find process
  332.         inc     edi
  333. ;more comfortable register for next loop
  334.         mov     ecx,edi
  335. ;precacluate pointer to process buffer
  336.         mov     ebx,process_info_buffer
  337. ;-------------------------------------------------------------------------------
  338. align 4
  339. .find_loop:
  340.         cmp     ecx,256
  341.         jge     .no_processes
  342. ;load process information in buffer
  343.         mcall   SF_THREAD_INFO
  344. ;if current slot greater than maximal slot,
  345. ;there is no more proccesses.
  346.         cmp     ecx,eax
  347.         jg      .no_processes
  348. ;if slot state is equal to 9, it is empty.
  349.         cmp     [process_info_buffer+process_information.slot_state],9
  350.         jnz     .process_found
  351.  
  352.         inc     ecx
  353.         jmp     .find_loop
  354. ;-------------------------------------------------------------------------------
  355. align 4
  356. .no_processes:
  357.         call    draw_empty_slot
  358.         or      edi,-1
  359.         ret
  360. ;-------------------------------------------------------------------------------
  361. align 4
  362. .process_found:
  363. ;check on/off check box
  364.         test    dword   [check1.flags], ch_flag_en
  365.         jnz     .no_filter
  366.  
  367.         cmp     dword   [process_info_buffer+10],"ICON"
  368.         jnz     @f
  369.         cmp     dword   [process_info_buffer+10+4],0
  370.         jz      .return_1
  371. @@:
  372.         cmp     dword   [process_info_buffer+10],"IDLE"
  373.         jnz     @f
  374.         cmp     dword   [process_info_buffer+10+4],0
  375.         jz      .return_1
  376. @@:
  377.         cmp     word    [process_info_buffer+10],"OS"
  378.         jnz     @f
  379.         cmp     dword   [process_info_buffer+10+2],0
  380.         jz      .return_1
  381. @@:
  382.         cmp     byte [process_info_buffer+10],"@"
  383.         jz      .return_1
  384. ;-------------------------------------------------------------------------------
  385. align 4
  386. .no_filter:
  387.         mov     edi,ecx
  388.         mov     [list_add],ecx
  389. ;get processor cpeed
  390. ;for percent calculating
  391.         mcall   SF_SYSTEM,SSF_GET_CPU_FREQUENCY
  392.         xor     edx,edx
  393.         mov     ebx,100
  394.         div     ebx
  395. ;eax = number of operation for 1% now
  396. ;calculate process cpu usage percent
  397.         mov     ebx,eax
  398.         mov     eax,[process_info_buffer+process_information.cpu_usage]
  399. ;       cdq
  400.         xor     edx,edx ; for CPU more 2 GHz - mike.dld
  401.         div     ebx
  402.         mov     [cpu_percent],eax
  403. ;set text color to display process information
  404. ;0%     : black
  405. ;1-80%  : green
  406. ;81-100% : red
  407.         test    eax,eax
  408.         jnz     .no_black
  409.  
  410.         mov     esi, 0x10000000
  411.         jmp     .color_set
  412. ;-------------------------------------------------------------------------------
  413. align 4
  414. .no_black:
  415.         cmp     eax,80
  416.         ja      .no_green
  417.  
  418.         mov     esi, 0x10107A30
  419.         jmp     .color_set
  420. ;-------------------------------------------------------------------------------
  421. align 4
  422. .no_green:
  423.         mov     esi,0x10AC0000
  424. ;-------------------------------------------------------------------------------
  425. align 4
  426. .color_set:
  427. ;show slot number
  428. ;ecx haven"t changed since .process_found
  429.         push    edi
  430.         mov     eax, ecx
  431.         mov     ebx, [curposy]
  432.         add     ebx, 40 shl 16 + 3
  433.         mov     ecx, esi
  434.         xor     edx, edx
  435.         call    draw_ra_dec_number
  436.         push    ecx
  437. ;show process name
  438.         mov     ebx,[curposy]
  439.         add     ebx,50*65536+3
  440.         mov     ecx, esi
  441.         or      ecx, 0x80000000
  442.         mcall   SF_DRAW_TEXT,,,process_info_buffer.process_name,11
  443.         pop     ecx
  444. ;show PTID
  445.         mov     eax, [process_info_buffer.PID]
  446.         add     ebx, 160 shl 16
  447.         xor     edx, edx
  448.         call    draw_ra_dec_number
  449. ;show cpu usage
  450.         mov     eax, [process_info_buffer.cpu_usage]
  451.         add     ebx, 100 shl 16
  452.         call    draw_ra_dec_number
  453. ;show cpu percent
  454.         mov     eax, [cpu_percent]
  455.         add     ebx, 55 shl 16
  456.         call    draw_ra_dec_number
  457. ;show memory usage
  458.         mov     eax, [process_info_buffer.used_memory]
  459.         add     ebx, 60 shl 16
  460.         call    draw_ra_data_size
  461. ;show window stack position
  462.         movzx   eax, word [process_info_buffer.window_stack_position]
  463.         add     ebx, 70 shl 16
  464.         call    draw_ra_dec_number
  465. ;show window x size
  466.         movzx   eax, word [process_info_buffer.box.left]
  467.         add     ebx, 70 shl 16
  468.         call    draw_ra_dec_number
  469. ;show window y size
  470.         movzx   eax, word [process_info_buffer.box.top]
  471.         add     ebx, 70 shl 16
  472.         call    draw_ra_dec_number     
  473.         pop     edi
  474. ;-------------------------------------------------------------------------------
  475. align 4
  476. .ret:
  477. ;build index->slot map for terminating processes.
  478.         mov     eax,[index]
  479.         mov     [tasklist+4*eax],edi
  480.         ret
  481. ;-------------------------------------------------------------------------------
  482. align 4
  483. f11:
  484. ;full update
  485.         push    edi
  486.         call    draw_window
  487.         pop     edi
  488. ;-------------------------------------------------------------------------------
  489. ;       *********************************************
  490. ;       ******* WINDOW DEFINITIONS AND DRAW ********
  491. ;       *********************************************
  492. align 4
  493. draw_window:
  494.         mcall   SF_REDRAW, SSF_BEGIN_DRAW
  495. ; DRAW WINDOW
  496.         xor     eax,eax                  ; function 0 : define and draw window
  497.         xor     esi,esi
  498.         mcall   ,[winxpos],[winypos], 0x34FFFFFF,, strings.tmp_window_caption   ;0x34ddffdd
  499.  
  500.         mcall   SF_THREAD_INFO,process_info_buffer,-1
  501.  
  502.         mov     eax,[ebx+70]
  503.         mov     [window_status],eax
  504.         test    [window_status],100b            ; window is rolled up
  505.         jnz     .exit
  506.  
  507.         test    [window_status],10b             ; window is minimized to panel
  508.         jnz     .exit
  509.        
  510.         mov     eax, strings.process_name
  511.         mov     ebx, 130 shl 16 + 5
  512.         xor     ecx, ecx
  513.         call    draw_ra_text
  514.        
  515.         mov     eax, strings.ptid
  516.         add     ebx, 80 shl 16
  517.         call    draw_ra_text
  518.        
  519.         mov     eax, strings.cpu_usage_cycles
  520.         add     ebx, 100 shl 16
  521.         call    draw_ra_text
  522.        
  523.         mov     eax, strings.cpu_usage_percent
  524.         add     ebx, 55 shl 16
  525.         call    draw_ra_text
  526.        
  527.         mov     eax, strings.memory_usage
  528.         add     ebx, 60 shl 16
  529.         call    draw_ra_text
  530.        
  531.         mov     eax, strings.window_stack_pos
  532.         add     ebx, 70 shl 16
  533.         call    draw_ra_text
  534.        
  535.         mov     eax, strings.window_position.x
  536.         add     ebx, 70 shl 16
  537.         call    draw_ra_text
  538.        
  539.         mov     eax, strings.window_position.y
  540.         add     ebx, 70 shl 16
  541.         call    draw_ra_text
  542.  
  543.         mcall   SF_SYSTEM_GET,SSF_TIME_COUNT
  544.         add     eax,100
  545.         mov     [time_counter],eax
  546.  
  547.         mov     [draw_window_flag],1
  548.         call    show_process_info
  549.         mov     [draw_window_flag],0
  550.  
  551.         push    dword   edit1
  552.         call    [edit_box_draw]
  553.  
  554.         push    dword   check1
  555.         call    [check_box_draw]
  556.  
  557. ;previous page button, ID = 51:
  558.         mov     eax, strings.previous_page
  559.         mov     ebx, UNDERTABLE.X shl 16 + UNDERTABLE.Y
  560.         mov     ecx, 51
  561.         mov     edx, 0xCCDDEE
  562.         xor     esi, esi
  563.         call    draw_button_with_caption
  564. ;next page button, ID = 52:
  565.         mov     eax, strings.next_page
  566.         add     ebx, 10 shl 16
  567.         inc     ecx
  568.         call    draw_button_with_caption
  569. ;reboot button, ID = 53:
  570.         mov     eax, strings.reboot
  571.         add     ebx, 345 shl 16
  572.         inc     ecx
  573.         call    draw_button_with_caption
  574. ;run button, ID = 54
  575.         mov     eax, strings.run
  576.         mov     ebx, (EDITBOX.X + EDITBOX.WIDTH + 10) shl 16 + (EDITBOX.Y + EDITBOX.HEIGHT/2 - BUTTON.HEIGHT/2)
  577.         inc     ecx
  578.         call    draw_button_with_caption
  579. ;-------------------------------------------------------------------------------
  580. align 4
  581. .exit:
  582.         mcall   SF_REDRAW, SSF_END_DRAW
  583.         ret
  584. ;-------------------------------------------------------------------------------
  585. align 4
  586. show_process_info:
  587.         test    [window_status], 100b           ; window is rolled up
  588.         jnz     .exit
  589.  
  590.         test    [window_status], 10b            ; window is minimized to panel
  591.         jnz     .exit
  592.  
  593.         mov     ecx,DISPLAY_PROCESSES
  594.         mov     edi,tasklist
  595.         xor     eax,eax
  596.         cld
  597.         rep     stosd
  598.  
  599.         mov     edi,[list_start]
  600.         mov     [list_add],edi
  601.         mov     dword   [index],0
  602.         mov     dword   [curposy],20
  603. ;-------------------------------------------------------------------------------
  604. align 4
  605. .loop_draw:
  606.         call    draw_next_process
  607.         inc     dword   [index]
  608.         add     dword   [curposy],16+4
  609.         cmp     [index],DISPLAY_PROCESSES
  610.         jl      .loop_draw
  611. ;-------------------------------------------------------------------------------
  612. align 4
  613. .exit:
  614.         ret
  615.        
  616. ;-------------------------------------------------------------------------------
  617.  
  618. draw_ra_dec_number:
  619. ;-------------------------------------------------------------------------------
  620. ;draws (posfixed) number with flush right alignment in decimal form
  621. ;8x16 number + 8x16 UTF8Z text
  622. ;in:
  623. ;eax = number
  624. ;ebx = right margin coordinates (x shl 16 + y)
  625. ;ecx = 0x00RRGGBB
  626. ;edx = pointer to postfix string or 0 - no postfix
  627. ;-------------------------------------------------------------------------------
  628.         pusha
  629.  
  630.         ror     ebx, 16
  631.         mov     ebp, eax
  632.        
  633.         test    edx, edx
  634.         jz      .no_postfix
  635.        
  636.         mov     eax, edx
  637.         call    count_utf8z_chars
  638.        
  639.         test    eax, eax
  640.         jz      .no_postfix
  641.         push    ecx
  642.         lea     eax, [eax*8]
  643.         sub     bx, ax
  644.         rol     ebx, 16
  645.         or      ecx, 0xB0000000
  646.         mcall   SF_DRAW_TEXT
  647.         ror     ebx, 16
  648.         pop     ecx
  649.        
  650. .no_postfix:
  651.         mov     eax, ebp
  652.         push    edx
  653.  
  654.         xor     edi, edi
  655.        
  656.         mov     esi, 10
  657. @@:
  658.         xor     edx, edx
  659.         div     esi
  660.         inc     edi
  661.         test    eax, eax
  662.         jz      @f
  663.         jmp     @b
  664.  
  665. @@:
  666.         pop     edx
  667.         mov     esi, ecx
  668.         or      esi, 0x10000000
  669.         mov     ecx, ebp
  670.         mov     edx, ebx
  671.         lea     eax, [edi*8]
  672.         sub     dx, ax
  673.         rol     edx, 16
  674.         mcall   SF_DRAW_NUMBER, (11 shl 16) or 0x80000000
  675.        
  676.         popa
  677.         ret
  678. ;-------------------------------------------------------------------------------
  679.  
  680. draw_ra_data_size:
  681. ;-------------------------------------------------------------------------------
  682. ;draws data size with flush right alignment in following form:
  683. ;n (for <1024 bytes) or n xB (KB/MB/GB)
  684. ;8x16 font
  685. ;in:
  686. ;eax = number
  687. ;ebx = right margin coordinates (x shl 16 + y)
  688. ;ecx = 0x00RRGGBB
  689. ;-------------------------------------------------------------------------------
  690.         pusha
  691.  
  692.         xor     edx, edx
  693.         cmp     eax, 1024
  694.         ja      @f
  695.         jmp     .draw_text
  696.        
  697. @@:
  698.         cmp     eax, 1024*1024
  699.         jae     @f
  700.         mov     esi,  1024
  701.         div     esi
  702.         mov     edx, strings.KB
  703.         jmp     .draw_text
  704.        
  705. @@:
  706.         cmp     eax, 1024*1024*1024
  707.         jae     @f
  708.         mov     esi,  1024*1024
  709.         div     esi
  710.         mov     edx, strings.MB
  711.         jmp     .draw_text
  712.        
  713. @@:
  714.         mov     esi,  1024*1024*1024
  715.         div     esi
  716.         mov     edx, strings.GB
  717.        
  718. .draw_text:
  719.         call    draw_ra_dec_number
  720.        
  721.         popa
  722.         ret
  723. ;-------------------------------------------------------------------------------
  724.  
  725. draw_ra_text:
  726. ;-------------------------------------------------------------------------------
  727. ;draws 8x16 UTF8Z text with flush right alignment in decimal form
  728. ;in:
  729. ;eax = pointer to text string
  730. ;ebx = right margin coordinates (x shl 16 + y)
  731. ;ecx = 0x00RRGGBB
  732. ;-------------------------------------------------------------------------------
  733.         pusha
  734.  
  735.         ror     ebx, 16
  736.         mov     edx, eax
  737.        
  738.         call    count_utf8z_chars
  739.        
  740.         test    eax, eax
  741.         jz      .ret
  742.         lea     eax, [eax*8]
  743.         sub     bx, ax
  744.         rol     ebx, 16
  745.         or      ecx, 0xB0000000
  746.         mcall   SF_DRAW_TEXT
  747.        
  748. .ret:
  749.         popa
  750.         ret
  751. ;-------------------------------------------------------------------------------
  752.  
  753. draw_button_with_caption:
  754. ;-------------------------------------------------------------------------------
  755. ;draws button with 8x16 UTF8Z caption in center
  756. ;in:
  757. ;eax = pointer to button caption or 0 - no caption
  758. ;ebx = x shl 16 + y
  759. ;ecx = 0x00XXXXXX, where XXXXXX - button ID
  760. ;edx = 0x00RRGGBB - button color
  761. ;esi = 0x00RRGGBB - text color
  762. ;out:
  763. ;eax = width of button
  764. ;ebx = x+width shl 16 + y
  765. ;-------------------------------------------------------------------------------
  766.         pusha
  767.        
  768.         xor     ebp, ebp
  769.         mov     edi, eax
  770.         test    eax, eax
  771.         jz      .no_caption_0
  772.  
  773.         call    count_utf8z_chars
  774.         mov     ebp, eax
  775.  
  776. .no_caption_0: 
  777.         push    ebx esi
  778.         lea     eax, [ebp*8]
  779.         mov     esi, edx
  780.         mov     edx, ecx
  781.         mov     ecx, ebx
  782.         shl     ecx, 16
  783.         mov     bx, ax
  784.         add     bx, 3*2
  785.         movzx   eax, bx
  786.         mov     dword [esp+4*2+4*7], eax        ;out eax = width
  787.         add     word [esp+4*2+4*4+2], ax        ;out ebx = x+width shl 16 + y
  788.         mov     cx, BUTTON.HEIGHT
  789.         mcall   SF_DEFINE_BUTTON
  790.         pop     esi ebx
  791.         test    edi, edi
  792.         jz      .no_caption_1
  793.         mov     edx, edi
  794.         add     ebx, 3 shl 16 + 3
  795.         mov     ecx, esi
  796.         or      ecx, 0xB0000000
  797.         mcall   SF_DRAW_TEXT
  798.        
  799. .no_caption_1:
  800.         popa
  801.         ret
  802. ;-------------------------------------------------------------------------------
  803.  
  804. count_utf8z_chars:
  805. ;-------------------------------------------------------------------------------
  806. ;in:
  807. ;eax = pointer to UTF8Z string
  808. ;out:
  809. ;eax = count of chars (excluding finishing zero) (0 if string is empty or invalid)
  810. ;-------------------------------------------------------------------------------
  811.         push    esi ebx
  812.         mov     esi, eax
  813.         xor     ebx, ebx
  814.        
  815. .0:
  816.         lodsb
  817.         test    al, al
  818.         jz      .ok
  819.         inc     ebx
  820.         cmp     al, 0x7F
  821.         ja      @f
  822.         jmp     .0
  823. @@:
  824.         cmp     al, 0xC0
  825.         jb      .err
  826.         cmp     al, 0xDF
  827.         ja      @f
  828.         inc     esi
  829.         jmp     .0
  830.        
  831. @@:
  832.         cmp     al, 0xEF
  833.         ja      @f
  834.         inc     esi
  835.         inc     esi
  836.         jmp     .0
  837.        
  838. @@:
  839.         cmp     al, 0xF7
  840.         ja      .err
  841.         add     esi, 3
  842.         jmp     .0
  843.        
  844. .ok:
  845.         mov     eax, ebx
  846.         pop     ebx esi
  847.         ret
  848.        
  849. .err:
  850.         xor     eax, eax
  851.         pop     ebx esi
  852.         ret
  853. ;-------------------------------------------------------------------------------
  854.  
  855. ; DATA AREA
  856. ;-------------------------------------------------------------------------------
  857. system_path     db      "/sys/lib/"
  858. library_name    db      "box_lib.obj", 0
  859.  
  860. ;-------------------------------------------------------------------------------
  861. align 4
  862. myimport:
  863. edit_box_draw           dd      aEdit_box_draw
  864. edit_box_key            dd      aEdit_box_key
  865. edit_box_mouse          dd      aEdit_box_mouse
  866. ;version_ed             dd      aVersion_ed
  867.  
  868. init_checkbox           dd      aInit_checkbox
  869. check_box_draw          dd      aCheck_box_draw
  870. check_box_mouse  dd     aCheck_box_mouse
  871. ;version_ch             dd      aVersion_ch
  872.  
  873. ;option_box_draw        dd      aOption_box_draw
  874. ;option_box_mouse       dd      aOption_box_mouse
  875. ;version_op             dd      aVersion_op
  876.  
  877.                 dd      0
  878.                 dd      0
  879.  
  880. aEdit_box_draw          db      "edit_box",0
  881. aEdit_box_key           db      "edit_box_key",0
  882. aEdit_box_mouse  db     "edit_box_mouse",0
  883. ;aVersion_ed            db      "version_ed",0
  884.  
  885. aInit_checkbox          db      "init_checkbox2",0
  886. aCheck_box_draw  db     "check_box_draw2",0
  887. aCheck_box_mouse        db      "check_box_mouse2",0
  888. ;aVersion_ch            db      "version_ch",0
  889.  
  890. ;aOption_box_draw       db      "option_box_draw",0
  891. ;aOption_box_mouse      db      "option_box_mouse",0
  892. ;aVersion_op            db      "version_op",0
  893. ;-------------------------------------------------------------------------------
  894. align 4
  895. check1 check_box2 CHECKBOX.X shl 16 + 12, CHECKBOX.Y shl 16 + 12, 6, 0x80D6DEE7, 0x4C5258, 0xB0000000, strings.checkbox_caption, ch_flag_top
  896. check1_end:
  897. edit1 edit_box EDITBOX.WIDTH, EDITBOX.X, EDITBOX.Y, 0xffffff, 0x6f9480, 0, 0xAABBCC, 0, start_application_c,\
  898.         start_application,mouse_dd,ed_focus,start_application_e,start_application_e
  899. edit1_end:
  900. list_start      dd      0
  901. ;-------------------------------------------------------------------------------
  902. align 4
  903. sys_reboot:
  904.                 dd      SSF_START_APP
  905.                 dd      0
  906.                 dd      0
  907.                 dd      0
  908.                 dd      0
  909.                 db      "/sys/end",0
  910. ;-------------------------------------------------------------------------------
  911. strings:
  912. if lang eq de
  913.         .window_caption         utf8z   "Prozesse  - [Ctrl+Alt+Del]"
  914.         .tmp_window_caption     db      "Process manager v0.2 - [Ctrl+Alt+Del]", 0
  915.        
  916.         .process_name           utf8z   "NAME/BEENDEN"
  917.         .ptid                   utf8z   "PID/TID"
  918.         .cpu_usage_cycles       utf8z   "CPU(ZYKLEN)"
  919.         .cpu_usage_percent      utf8z   "CPU(%)"
  920.         .memory_usage           utf8z   "SPEICHER"
  921.         .window_stack_pos       utf8z   "W-STACK"
  922.         .window_position.x      utf8z   "W-POS-X"
  923.         .window_position.y      utf8z   "W-POS-Y"
  924.        
  925.         .previous_page          utf8z   "SEITE ZURUECK"
  926.         .next_page              utf8z   "SEITE VOR"
  927.         .reboot                 utf8z   "REBOOT SYSTEM"
  928.         .run                    utf8z   "START"
  929.        
  930.         .checkbox_caption       utf8z   "System"
  931.        
  932.         .KB                     utf8z   " KB"
  933.         .MB                     utf8z   " MB"
  934.         .GB                     utf8z   " GB"
  935. ;-------------------------------------------------------------------------------
  936. else if lang eq et
  937.         .window_caption         utf8z   "Protsessid v0.2 - [Ctrl+Alt+Del]"
  938.         .tmp_window_caption     db      "Process manager v0.2 - [Ctrl+Alt+Del]", 0
  939.        
  940.         .process_name           utf8z   "NIMI/LÕPETA"
  941.         .ptid                   utf8z   "PID/TID"
  942.         .cpu_usage_cycles       utf8z   "CPU(TSÜKLID)"
  943.         .cpu_usage_percent      utf8z   "CPU(%)"
  944.         .memory_usage           utf8z   "MÄLU"
  945.         .window_stack_pos       utf8z   "W-PUHVER"
  946.         .window_position.x      utf8z   "W-POS-X"
  947.         .window_position.y      utf8z   "W-POS-Y"
  948.        
  949.         .previous_page          utf8z   "EELMINE LEHT"
  950.         .next_page              utf8z   "JÄRGMINE LEHT"
  951.         .reboot                 utf8z   "REBOODI SÜSTEEM"
  952.         .run                    utf8z   "START"
  953.        
  954.         .checkbox_caption       utf8z   "System"
  955.                
  956.         .KB                     utf8z   " KB"
  957.         .MB                     utf8z   " MB"
  958.         .GB                     utf8z   " GB"
  959. ;-------------------------------------------------------------------------------
  960. else if lang eq ru
  961.         .window_caption         utf8z   "Диспетчер процессов v0.2 - [Ctrl+Alt+Del]"
  962.         .tmp_window_caption     db      "Process manager v0.2 - [Ctrl+Alt+Del]", 0
  963.        
  964.         .process_name           utf8z   "ИМЯ/ЗАВЕРШИТЬ"
  965.         .ptid                   utf8z   "PID/TID"
  966.         .cpu_usage_cycles       utf8z   "CPU(ТАКТЫ)"
  967.         .cpu_usage_percent      utf8z   "CPU(%)"
  968.         .memory_usage           utf8z   "ПАМЯТЬ"
  969.         .window_stack_pos       utf8z   "W-STACK"
  970.         .window_position.x      utf8z   "W-POS-X"
  971.         .window_position.y      utf8z   "W-POS-Y"
  972.        
  973.         .previous_page          utf8z   "ПРЕД. СТР."
  974.         .next_page              utf8z   "СЛЕД. СТР."
  975.         .reboot                 utf8z   "ПЕРЕЗАГРУЗКА"
  976.         .run                    utf8z   "ЗАПУСК"
  977.        
  978.         .checkbox_caption       utf8z   "Системные"
  979.                
  980.         .KB                     utf8z   " КБ"
  981.         .MB                     utf8z   " МБ"
  982.         .GB                     utf8z   " ГБ"
  983. ;-------------------------------------------------------------------------------
  984. else if lang eq it
  985.         .window_caption         utf8z   "Gestore processi v0.2 - [Ctrl+Alt+Del]"
  986.         .tmp_window_caption     db      "Process manager v0.2 - [Ctrl+Alt+Del]", 0
  987.        
  988.         .process_name           utf8z   "NOME-PROGRAMMA"
  989.         .ptid                   utf8z   "PID/TID"
  990.         .cpu_usage_cycles       utf8z   "CPU(CICLI)"
  991.         .cpu_usage_percent      utf8z   "CPU(%)"
  992.         .memory_usage           utf8z   "MEMORY"
  993.         .window_stack_pos       utf8z   "W-STACK"
  994.         .window_position.x      utf8z   "W-POS-X"
  995.         .window_position.y      utf8z   "W-POS-Y"
  996.        
  997.         .previous_page          utf8z   "INDIETRO"
  998.         .next_page              utf8z   "AVANTI"
  999.         .reboot                 utf8z   "RIAVVIA SISTEMA"
  1000.         .run                    utf8z   "START"
  1001.        
  1002.         .checkbox_caption       utf8z   "System"
  1003.        
  1004.         .KB                     utf8z   " KB"
  1005.         .MB                     utf8z   " MB"
  1006.         .GB                     utf8z   " GB"
  1007. ;-------------------------------------------------------------------------------
  1008. else
  1009.         .window_caption         utf8z   "Process manager v0.2 - [Ctrl+Alt+Del]"
  1010.         .tmp_window_caption     db      "Process manager v0.2 - [Ctrl+Alt+Del]", 0
  1011.        
  1012.         .process_name           utf8z   "NAME/TERMINATE"
  1013.         .ptid                   utf8z   "PID/TID"
  1014.         .cpu_usage_cycles       utf8z   "CPU(CYCLES)"
  1015.         .cpu_usage_percent      utf8z   "CPU(%)"
  1016.         .memory_usage           utf8z   "MEMORY"
  1017.         .window_stack_pos       utf8z   "W-STACK"
  1018.         .window_position.x      utf8z   "W-POS-X"
  1019.         .window_position.y      utf8z   "W-POS-Y"
  1020.        
  1021.        
  1022.         .previous_page          utf8z   "PREV PAGE"
  1023.         .next_page              utf8z   "NEXT PAGE"
  1024.         .reboot                 utf8z   "REBOOT SYSTEM"
  1025.         .run                    utf8z   "RUN"
  1026.        
  1027.         .checkbox_caption       utf8z   "System"
  1028.        
  1029.         .KB                     utf8z   " KB"
  1030.         .MB                     utf8z   " MB"
  1031.         .GB                     utf8z   " GB"
  1032. end if
  1033. ;-------------------------------------------------------------------------------
  1034. align 4
  1035. tinfo:
  1036.                         dd      SSF_START_APP
  1037.                         dd      0
  1038. .params         dd      .params_buf
  1039.                         dd      0
  1040.                         dd      0
  1041.                         db      0
  1042. .file_path              dd      sz_tinfo_file_path
  1043. align 4
  1044. .params_buf:
  1045. times 11 db     0 ; at now 4 bytes will be enough, but may be in the future not
  1046. align 4
  1047. sz_tinfo_file_path      db      "/sys/tinfo",0
  1048. ;-------------------------------------------------------------------------------
  1049. align 4
  1050. file_start:
  1051.         dd      SSF_START_APP
  1052.         dd      0
  1053.         dd      0
  1054.         dd      0
  1055.         dd      0
  1056. start_application: db   "/sys/LAUNCHER",0
  1057. start_application_e=$-start_application-1
  1058. ;                       times 60 db     0
  1059.         rb      60
  1060. start_application_c=$-start_application-1
  1061. ;-------------------------------------------------------------------------------
  1062. IM_END:
  1063. ;-------------------------------------------------------------------------------
  1064. align 4
  1065. sc system_colors
  1066. winxpos  rd     1
  1067. winypos  rd     1
  1068. mouse_dd        rd      1
  1069. cpu_percent     rd      1
  1070. list_add        rd      1
  1071. curposy  rd     1
  1072. index           rd      1
  1073. tasklist        rd      DISPLAY_PROCESSES
  1074. time_counter    rd      1
  1075.  
  1076. window_status           rd      1
  1077. client_area_x_size      rd      1
  1078. client_area_y_size      rd      1
  1079. bar_bacground_color     rd      1
  1080. btn_bacground_color     rd      1
  1081. draw_window_flag        rd      1
  1082. ;-------------------------------------------------------------------------------
  1083. align 4
  1084. library_path:
  1085. process_info_buffer process_information
  1086. ;-------------------------------------------------------------------------------
  1087. align 4
  1088. cur_dir_path:
  1089.         rb      1024
  1090.         rb      1024
  1091. stack_area:
  1092. U_END:
  1093.