Subversion Repositories Kolibri OS

Rev

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