Subversion Repositories Kolibri OS

Rev

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