Subversion Repositories Kolibri OS

Rev

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

  1. ;   This program shows  information about thread   ;
  2. ;        usage:  tinfo [slot of the thread]        ;
  3. ; if slot number is omitted then assume  slot = -1 ;
  4. ;    to compile: nasm -f bin tinfo.asm -o tinfo    ;
  5. ORG 0
  6. BITS 32
  7. ; ---------------------------------------------------------------------------- ;
  8. PATH_SIZE                         equ 1024
  9. PARAMS_SIZE                       equ 256
  10. STACK_SIZE                        equ 256
  11. PROC_INFO_SIZE                    equ 1024
  12. TMP_BUFFER_SIZE                   equ 64
  13. ; ---------------------------------------------------------------------------- ;
  14. TEXT_WIDTH                        equ 6
  15. BOLD_TEXT_WIDTH                   equ TEXT_WIDTH + 1
  16. ; ---------------------------------------------------------------------------- ;
  17. COLUMN1_MAX_COUNT                 equ 13
  18. COLUMN2_MAX_COUNT                 equ 12
  19. COLUMN3_MAX_COUNT                 equ 26
  20. ; ---------------------------------------------------------------------------- ;
  21. COLUMN_PADDING                    equ 3
  22. COLUMN1_PADDING                   equ COLUMN_PADDING
  23. COLUMN2_PADDING                   equ COLUMN_PADDING
  24. COLUMN3_PADDING                   equ COLUMN_PADDING
  25. ; ---------------------------------------------------------------------------- ;
  26. ITEM_HEIGHT                       equ 15
  27. TEXT_HEIGHT                       equ 9
  28. COLUMN1_ITEM_WIDTH                equ COLUMN1_MAX_COUNT * BOLD_TEXT_WIDTH + COLUMN1_PADDING * 2
  29. COLUMN2_ITEM_WIDTH                equ COLUMN2_MAX_COUNT * BOLD_TEXT_WIDTH + COLUMN2_PADDING * 2
  30. COLUMN3_ITEM_WIDTH                equ COLUMN3_MAX_COUNT * BOLD_TEXT_WIDTH + COLUMN3_PADDING * 2
  31. ITEM_MARGIN                       equ 6
  32. ITEM_BACK_COLOR_1                 equ 0x00EAEAEA
  33. ITEM_BACK_COLOR_2                 equ 0x00F4F4F4
  34. ITEM_COUNT                        equ 18 ; at current time we have 18 items
  35. ; ---------------------------------------------------------------------------- ;
  36. COLUMN_Y                          equ 10
  37. COLUMN1_X                         equ 10
  38. COLUMN2_X                         equ COLUMN1_X + COLUMN1_ITEM_WIDTH + ITEM_MARGIN
  39. COLUMN3_X                         equ COLUMN2_X + COLUMN2_ITEM_WIDTH + ITEM_MARGIN
  40. ; ---------------------------------------------------------------------------- ;
  41. COLUMN1_TEXT_X                    equ COLUMN1_X + COLUMN1_PADDING
  42. COLUMN2_TEXT_X                    equ COLUMN2_X + COLUMN2_PADDING
  43. COLUMN3_TEXT_X                    equ COLUMN3_X + COLUMN3_PADDING
  44. ; ---------------------------------------------------------------------------- ;
  45. FRAME_TOP                         equ COLUMN_Y - ITEM_MARGIN / 2
  46. FRAME_BOTTOM                      equ COLUMN_Y + ITEM_HEIGHT * ITEM_COUNT + ITEM_MARGIN / 2 - 1
  47.  ; ---------------------------------------------------------------------------- ;
  48. FRAME1_LEFT                       equ COLUMN1_X - ITEM_MARGIN / 2
  49. FRAME1_RIGHT                      equ COLUMN1_X + COLUMN1_ITEM_WIDTH + ITEM_MARGIN / 2 - 1
  50. ; ---------------------------------------------------------------------------- ;
  51. FRAME2_LEFT                       equ COLUMN2_X - ITEM_MARGIN / 2
  52. FRAME2_RIGHT                      equ COLUMN2_X + COLUMN2_ITEM_WIDTH + ITEM_MARGIN / 2 - 1
  53. ; ---------------------------------------------------------------------------- ;
  54. FRAME3_LEFT                       equ COLUMN3_X - ITEM_MARGIN / 2
  55. FRAME3_RIGHT                      equ COLUMN3_X + COLUMN3_ITEM_WIDTH + ITEM_MARGIN / 2 - 1
  56. ; ---------------------------------------------------------------------------- ;
  57. WINDOW_STYLE_SKINNED_FIXED        equ 0x4000000
  58. WINDOW_STYLE_COORD_CLIENT         equ 0x20000000
  59. WINDOW_STYLE_CAPTION              equ 0x10000000
  60. ; ---------------------------------------------------------------------------- ;
  61. WINDOW_BORDER_SIZE                equ 5
  62. WINDOW_WIDTH                      equ FRAME3_RIGHT + FRAME1_LEFT + WINDOW_BORDER_SIZE * 2
  63. WINDOW_STYLE                      equ WINDOW_STYLE_SKINNED_FIXED | WINDOW_STYLE_COORD_CLIENT | WINDOW_STYLE_CAPTION
  64. WINDOW_BACK_COLOR                 equ 0x00FFFFFF
  65. ; ---------------------------------------------------------------------------- ;
  66. INDICATOR_WIDTH                   equ 3
  67. INDICATOR_HEIGHT                  equ 3
  68. INDICATOR_LEFT                    equ COLUMN3_X + COLUMN3_ITEM_WIDTH + ITEM_MARGIN / 2
  69. INDICATOR_TOP                     equ COLUMN_Y  - ITEM_MARGIN / 2 - INDICATOR_HEIGHT
  70. ; ---------------------------------------------------------------------------- ;
  71. UPDATE_TIME                       equ 28
  72. ; ---------------------------------------------------------------------------- ;
  73. thread_info                       equ END + PATH_SIZE + PARAMS_SIZE
  74. tmpbuffer                         equ END + PATH_SIZE + PARAMS_SIZE + PROC_INFO_SIZE
  75. ; ---------------------------------------------------------------------------- ;
  76. KEYBOARD_MODE_ASCII               equ 0
  77. KEYBOARD_MODE_SCAN                equ 1
  78. ; ---------------------------------------------------------------------------- ;
  79. WINDOW_STATE_MAXIMIZED            equ 1
  80. WINDOW_STATE_MINIMIZED            equ 2
  81. WINDOW_STATE_ROLLED_UP            equ 4
  82. ; ---------------------------------------------------------------------------- ;
  83. THREAD_STATE_RUNNING              equ 0
  84. THREAD_STATE_SUSPENDED            equ 1
  85. THREAD_STATE_SUSPENDED_WAIT_EVENT equ 2
  86. THREAD_STATE_NORMAL_TERMINATING   equ 3
  87. THREAD_STATE_EXCEPT_TERMINATING   equ 4
  88. THREAD_STATE_WAIT_EVENT           equ 5
  89. THREAD_STATE_SLOT_IS_FREE         equ 9
  90. ; ---------------------------------------------------------------------------- ;
  91. EM_REDRAW                         equ         1b
  92. EM_KEY                            equ        10b
  93. EM_BUTTON                         equ       100b
  94. EM_RESERVED0                      equ      1000b
  95. EM_REDRAW_BACKGROUND              equ     10000b
  96. EM_MOUSE                          equ    100000b
  97. EM_IPC                            equ   1000000b
  98. EM_NETWORK                        equ  10000000b
  99. EM_DEBUG                          equ 100000000b
  100. ; ---------------------------------------------------------------------------- ;
  101. struc THREAD_INFO
  102.         .cpu_usage               resd 1  ; usage of the processor
  103.         .win_stack_pos           resw 1  ; position of the window of thread in the window stack
  104.         .reserved0               resw 1  ; has no relation to the specified thread
  105.         .reserved1               resw 1  ; reserved
  106.         .name                    resb 11 ; name of the started file - executable file without extension
  107.         .reserved2               resb 1  ; reserved, this byte is not changed
  108.         .mem_address             resd 1  ; address of the process in memory
  109.         .mem_usage               resd 1  ; size of used memory - 1
  110.         .identifier              resd 1  ; identifier (PID/TID)
  111.         .x                       resd 1  ; coordinate of the thread window on axis x
  112.         .y                       resd 1  ; coordinate of the thread window on axis y
  113.         .size_x                  resd 1  ; size of the thread window on axis x
  114.         .size_y                  resd 1  ; size of the thread window on axis y
  115.         .thread_state            resw 1  ; status of the thread slot
  116.         .reserved3               resw 1  ; reserved, this word is not changed
  117.         .client_x                resd 1  ; coordinate of the client area on axis x
  118.         .client_y                resd 1  ; coordinate of the client area on axis y
  119.         .client_size_x           resd 1  ; width of the client area
  120.         .client_size_y           resd 1  ; height of the client area
  121.         .window_state            resb 1  ; state of the window - bitfield
  122.         .event_mask              resd 1  ; event mask
  123.         .keyboard_mode           resb 1  ; keyboard mode
  124. endstruc
  125. ; ---------------------------------------------------------------------------- ;
  126. MENUET01       db 'MENUET01'
  127. version        dd 1
  128. program.start  dd START
  129. program.end    dd END
  130. program.memory dd END + PATH_SIZE + PARAMS_SIZE + PROC_INFO_SIZE + TMP_BUFFER_SIZE + STACK_SIZE
  131. program.stack  dd END + PATH_SIZE + PARAMS_SIZE + PROC_INFO_SIZE + TMP_BUFFER_SIZE + STACK_SIZE
  132. program.params dd END + PATH_SIZE
  133. program.path   dd END
  134. ; ---------------------------------------------------------------------------- ;
  135. slot                              dd -1 ; for default if no params
  136. ; ---------------------------------------------------------------------------- ;
  137. screen:
  138. .height                           dw 0
  139. .width                            dw 0
  140. ; ---------------------------------------------------------------------------- ;
  141. window:
  142. .left                             dd 0
  143. .top                              dd 0
  144. .width                            dd 0
  145. .height                           dd 0
  146. ; ---------------------------------------------------------------------------- ;
  147. fore_color                        dd 0x00000000
  148. back_color                        dd ITEM_BACK_COLOR_1
  149. frame_color                       dd 0x00CCCCCC
  150. ; ---------------------------------------------------------------------------- ;
  151. BackColors:
  152.                                   dd 1
  153.                                   dd ITEM_BACK_COLOR_1
  154.                                   dd ITEM_BACK_COLOR_2
  155. ; ---------------------------------------------------------------------------- ;
  156. IndicatorColors:
  157.                                   dd 1
  158.                                   dd 0x000AF000
  159.                                   dd 0x00000FA0
  160. ; ---------------------------------------------------------------------------- ;
  161. %define x [Pos.x]
  162. %define y [Pos.y]
  163. Pos:
  164. .x                                dd COLUMN1_X
  165. .y                                dd COLUMN_Y
  166. ; ---------------------------------------------------------------------------- ;
  167. sz_caption                        db "ThreadInfo",0
  168. ; ---------------------------------------------------------------------------- ;
  169. sz_cpu_usage                      db "CPU usage",0
  170. sz_win_stack_pos                  db "Win stack pos",0
  171. sz_name                           db "Name",0
  172. sz_mem_address                    db "Mem address",0
  173. sz_mem_usage                      db "Mem usage",0
  174. sz_identifier                     db "Identifier",0
  175. sz_x                              db "X",0
  176. sz_y                              db "Y",0
  177. sz_size_x                         db "Size X",0
  178. sz_size_y                         db "Size Y",0
  179. sz_thread_state                   db "Thread state",0
  180. sz_client_x                       db "Client X",0
  181. sz_client_y                       db "Client Y",0
  182. sz_client_size_x                  db "Client Size X",0
  183. sz_client_size_y                  db "Client Size Y",0
  184. sz_window_state                   db "Window state",0
  185. sz_event_mask                     db "Event mask",0
  186. sz_keyboard_mode                  db "Keyboard mode",0
  187. ; ---------------------------------------------------------------------------- ;
  188. ; state of the window
  189. sz_maximized                      db "Max ",0
  190. sz_minimized                      db "Min ",0
  191. sz_rolled_up                      db "RollUp ",0
  192. ; ---------------------------------------------------------------------------- ;
  193. ; keyboard mode
  194. sz_ascii                          db "ASCII",0
  195. sz_scan                           db "SCAN ",0
  196. ; ---------------------------------------------------------------------------- ;
  197. ; status of the thread slot
  198. sz_running                        db "running             ",0
  199. sz_suspended                      db "suspended           ",0
  200. sz_suspended_wait_event           db "suspended wait event",0
  201. sz_normal_terminating             db "normal terminating  ",0
  202. sz_except_terminating             db "except. terminating ",0
  203. sz_wait_event                     db "wait event          ",0
  204. sz_slot_is_free                   db "slot is free        ",0
  205. ; ---------------------------------------------------------------------------- ;
  206. ; event mask
  207. sz_redraw                         db "rdrw ",0
  208. sz_key                            db "key ",0
  209. sz_button                         db "btn ",0
  210. sz_reserved0                      db "rsrvd0 ",0
  211. sz_redraw_background              db "bckgr ",0
  212. sz_mouse                          db "mouse ",0
  213. sz_ipc                            db "ipc ",0
  214. sz_network                        db "net ",0
  215. sz_debug                          db "dbg ",0
  216. ; ---------------------------------------------------------------------------- ;
  217. sz_undefined                      db "UnDef               ",0
  218. ; **************************************************************************** ;
  219. %macro DrawCpuUsage 0
  220. ; sz_cpu_usage
  221.         push   dword COLUMN1_TEXT_X
  222.         push   dword y
  223.         push   dword sz_cpu_usage
  224.         push   dword [fore_color]
  225.         push   dword [back_color]
  226.         call   DrawTextBold
  227. ; [cpu_usage]
  228.         push   dword [thread_info + THREAD_INFO.cpu_usage]
  229.         call   uint2str
  230.         push   dword COLUMN2_MAX_COUNT
  231.         call   PadBuffSpaces
  232.         push   dword COLUMN2_TEXT_X
  233.         push   dword y
  234.         push   dword tmpbuffer
  235.         push   dword [fore_color]
  236.         push   dword [back_color]
  237.         call   DrawTextBold
  238.         call   ChangeBackColor
  239.         add    y, dword ITEM_HEIGHT
  240. %endmacro
  241. ; **************************************************************************** ;
  242. %macro DrawWinStackPos 0
  243. ; sz_win_stack_pos
  244.         push   dword COLUMN1_TEXT_X
  245.         push   dword y
  246.         push   dword sz_win_stack_pos
  247.         push   dword [fore_color]
  248.         push   dword [back_color]
  249.         call   DrawTextBold
  250. ; [win_stack_pos]
  251.         movzx  eax, word [thread_info + THREAD_INFO.win_stack_pos]
  252.         push   eax
  253.         call   uint2str
  254.         push   dword COLUMN2_MAX_COUNT
  255.         call   PadBuffSpaces
  256.         push   dword COLUMN2_TEXT_X
  257.         push   dword y
  258.         push   dword tmpbuffer
  259.         push   dword [fore_color]
  260.         push   dword [back_color]
  261.         call   DrawTextBold
  262.         call   ChangeBackColor
  263.         add    y, dword ITEM_HEIGHT
  264. %endmacro
  265. ; **************************************************************************** ;
  266. %macro DrawName 0
  267. ; sz_name
  268.         push   dword COLUMN1_TEXT_X
  269.         push   dword y
  270.         push   dword sz_name
  271.         push   dword [fore_color]
  272.         push   dword [back_color]
  273.         call   DrawTextBold
  274. ; name
  275.         push   dword COLUMN2_TEXT_X
  276.         push   dword y
  277.         push   dword (thread_info + THREAD_INFO.name)
  278.         push   dword [fore_color]
  279.         push   dword [back_color]
  280.         call   DrawTextBold
  281.         call   ChangeBackColor
  282.         add    y, dword ITEM_HEIGHT
  283. %endmacro
  284. ; **************************************************************************** ;
  285. %macro DrawMemAddress 0
  286. ; sz_mem_address
  287.         push   dword COLUMN1_TEXT_X
  288.         push   dword y
  289.         push   dword sz_mem_address
  290.         push   dword [fore_color]
  291.         push   dword [back_color]
  292.         call   DrawTextBold
  293. ; [mem_address]
  294.         push   dword [thread_info + THREAD_INFO.mem_address]
  295.         call   uint2str
  296.         push   dword COLUMN2_MAX_COUNT
  297.         call   PadBuffSpaces
  298.         push   dword COLUMN2_TEXT_X
  299.         push   dword y
  300.         push   dword tmpbuffer
  301.         push   dword [fore_color]
  302.         push   dword [back_color]
  303.         call   DrawTextBold
  304.         call   ChangeBackColor
  305.         add    y, dword ITEM_HEIGHT
  306. %endmacro
  307. ; **************************************************************************** ;
  308. %macro DrawMemUsage 0
  309. ; sz_mem_usage
  310.         push   dword COLUMN1_TEXT_X
  311.         push   dword y
  312.         push   dword sz_mem_usage
  313.         push   dword [fore_color]
  314.         push   dword [back_color]
  315.         call   DrawTextBold
  316. ; [mem_usage]
  317.         push   dword [thread_info + THREAD_INFO.mem_usage]
  318.         call   uint2str
  319.         push   dword COLUMN2_MAX_COUNT
  320.         call   PadBuffSpaces
  321.         push   dword COLUMN2_TEXT_X
  322.         push   dword y
  323.         push   dword tmpbuffer
  324.         push   dword [fore_color]
  325.         push   dword [back_color]
  326.         call   DrawTextBold
  327.         call   ChangeBackColor
  328.         add    y, dword ITEM_HEIGHT
  329. %endmacro
  330. ; **************************************************************************** ;
  331. %macro DrawIdentifier 0
  332. ; sz_identifier
  333.         push   dword COLUMN1_TEXT_X
  334.         push   dword y
  335.         push   dword sz_identifier
  336.         push   dword [fore_color]
  337.         push   dword [back_color]
  338.         call   DrawTextBold
  339. ; [identifier]
  340.         push   dword [thread_info + THREAD_INFO.identifier]
  341.         call   uint2str
  342.         push   dword COLUMN2_MAX_COUNT
  343.         call   PadBuffSpaces
  344.         push   dword COLUMN2_TEXT_X
  345.         push   dword y
  346.         push   dword tmpbuffer
  347.         push   dword [fore_color]
  348.         push   dword [back_color]
  349.         call   DrawTextBold
  350.         call   ChangeBackColor
  351.         add    y, dword ITEM_HEIGHT
  352. %endmacro
  353. ; **************************************************************************** ;
  354. %macro DrawWindowX 0
  355. ; sz_x
  356.         push   dword COLUMN1_TEXT_X
  357.         push   dword y
  358.         push   dword sz_x
  359.         push   dword [fore_color]
  360.         push   dword [back_color]
  361.         call   DrawTextBold
  362. ; [x]
  363.         push   dword [thread_info + THREAD_INFO.x]
  364.         call   uint2str
  365.         push   dword COLUMN2_MAX_COUNT
  366.         call   PadBuffSpaces
  367.         push   dword COLUMN2_TEXT_X
  368.         push   dword y
  369.         push   dword tmpbuffer
  370.         push   dword [fore_color]
  371.         push   dword [back_color]
  372.         call   DrawTextBold
  373.         call   ChangeBackColor
  374.         add    y, dword ITEM_HEIGHT
  375. %endmacro
  376. ; **************************************************************************** ;
  377. %macro DrawWindowY 0
  378. ; sz_y
  379.         push   dword COLUMN1_TEXT_X
  380.         push   dword y
  381.         push   dword sz_y
  382.         push   dword [fore_color]
  383.         push   dword [back_color]
  384.         call   DrawTextBold
  385. ; [y]
  386.         push   dword [thread_info + THREAD_INFO.y]
  387.         call   uint2str
  388.         push   dword COLUMN2_MAX_COUNT
  389.         call   PadBuffSpaces
  390.         push   dword COLUMN2_TEXT_X
  391.         push   dword y
  392.         push   dword tmpbuffer
  393.         push   dword [fore_color]
  394.         push   dword [back_color]
  395.         call   DrawTextBold
  396.         call   ChangeBackColor
  397.         add    y, dword ITEM_HEIGHT
  398. %endmacro
  399. ; **************************************************************************** ;
  400. %macro DrawWindowSizeX 0
  401. ; sz_size_x
  402.         push   dword COLUMN1_TEXT_X
  403.         push   dword y
  404.         push   dword sz_size_x
  405.         push   dword [fore_color]
  406.         push   dword [back_color]
  407.         call   DrawTextBold
  408. ; [size_x]
  409.         push   dword [thread_info + THREAD_INFO.size_x]
  410.         call   uint2str
  411.         push   dword COLUMN2_MAX_COUNT
  412.         call   PadBuffSpaces
  413.         push   dword COLUMN2_TEXT_X
  414.         push   dword y
  415.         push   dword tmpbuffer
  416.         push   dword [fore_color]
  417.         push   dword [back_color]
  418.         call   DrawTextBold
  419.         call   ChangeBackColor
  420.         add    y, dword ITEM_HEIGHT
  421. %endmacro
  422. ; **************************************************************************** ;
  423. %macro DrawWindowSizeY 0
  424. ; sz_size_y
  425.         push   dword COLUMN1_TEXT_X
  426.         push   dword y
  427.         push   dword sz_size_y
  428.         push   dword [fore_color]
  429.         push   dword [back_color]
  430.         call   DrawTextBold
  431. ; [size_y]
  432.         push   dword [thread_info + THREAD_INFO.size_y]
  433.         call   uint2str
  434.         push   dword COLUMN2_MAX_COUNT
  435.         call   PadBuffSpaces
  436.         push   dword COLUMN2_TEXT_X
  437.         push   dword y
  438.         push   dword tmpbuffer
  439.         push   dword [fore_color]
  440.         push   dword [back_color]
  441.         call   DrawTextBold
  442.         call   ChangeBackColor
  443.         add    y, dword ITEM_HEIGHT
  444. %endmacro
  445. ; **************************************************************************** ;
  446. %macro DrawThreadState 0
  447. ; sz_thread_state
  448.         push   dword COLUMN1_TEXT_X
  449.         push   dword y
  450.         push   dword sz_thread_state
  451.         push   dword [fore_color]
  452.         push   dword [back_color]
  453.         call   DrawTextBold
  454. ; decoded_thread_state & [thread_state]
  455.         movzx  eax, word [thread_info + THREAD_INFO.thread_state]
  456.         push   eax ; for "call uint2str" below
  457. %%running:
  458.         cmp    eax, THREAD_STATE_RUNNING
  459.         jne    %%suspended
  460.         mov    eax, sz_running
  461.         jmp    %%draw_decoded_thread_state
  462. %%suspended:
  463.         cmp    eax, THREAD_STATE_SUSPENDED
  464.         jne    %%suspended_w
  465.         mov    eax, sz_suspended
  466.         jmp    %%draw_decoded_thread_state
  467. %%suspended_w:
  468.         cmp    eax, THREAD_STATE_SUSPENDED_WAIT_EVENT
  469.         jne    %%normal_term
  470.         mov    eax, sz_suspended_wait_event
  471.         jmp    %%draw_decoded_thread_state
  472. %%normal_term:
  473.         cmp    eax, THREAD_STATE_NORMAL_TERMINATING
  474.         jne    %%except_term
  475.         mov    eax, sz_normal_terminating
  476.         jmp    %%draw_decoded_thread_state
  477. %%except_term:
  478.         cmp    eax, THREAD_STATE_EXCEPT_TERMINATING
  479.         jne    %%wait_event
  480.         mov    eax, sz_except_terminating
  481.         jmp    %%draw_decoded_thread_state
  482. %%wait_event:
  483.         cmp    eax, THREAD_STATE_WAIT_EVENT
  484.         jne    %%slot_free
  485.         mov    eax, sz_wait_event
  486.         jmp    %%draw_decoded_thread_state
  487. %%slot_free:
  488.         cmp    eax, THREAD_STATE_SLOT_IS_FREE
  489.         jne    %%undefined
  490.         mov    eax, sz_slot_is_free
  491.         jmp    %%draw_decoded_thread_state
  492. %%undefined:
  493.         mov    eax, sz_undefined
  494. %%draw_decoded_thread_state:
  495.         push   dword COLUMN3_TEXT_X
  496.         push   dword y
  497.         push   eax
  498.         push   dword [fore_color]
  499.         push   dword [back_color]
  500.         call   DrawTextBold
  501.         call   uint2str
  502.         push   dword COLUMN2_MAX_COUNT
  503.         call   PadBuffSpaces
  504.         push   dword COLUMN2_TEXT_X
  505.         push   dword y
  506.         push   dword tmpbuffer
  507.         push   dword [fore_color]
  508.         push   dword [back_color]
  509.         call   DrawTextBold
  510.         call   ChangeBackColor
  511.         add    y, dword ITEM_HEIGHT
  512. %endmacro
  513. ; **************************************************************************** ;
  514. %macro DrawClientX 0
  515. ; sz_client_x
  516.         push   dword COLUMN1_TEXT_X
  517.         push   dword y
  518.         push   dword sz_client_x
  519.         push   dword [fore_color]
  520.         push   dword [back_color]
  521.         call   DrawTextBold
  522. ; [client_x]
  523.         push   dword [thread_info + THREAD_INFO.client_x]
  524.         call   uint2str
  525.         push   dword COLUMN2_MAX_COUNT
  526.         call   PadBuffSpaces
  527.         push   dword COLUMN2_TEXT_X
  528.         push   dword y
  529.         push   dword tmpbuffer
  530.         push   dword [fore_color]
  531.         push   dword [back_color]
  532.         call   DrawTextBold
  533.         call   ChangeBackColor
  534.         add    y, dword ITEM_HEIGHT
  535. %endmacro
  536. ; **************************************************************************** ;
  537. %macro DrawClientY 0
  538. ; sz_client_y
  539.         push   dword COLUMN1_TEXT_X
  540.         push   dword y
  541.         push   dword sz_client_y
  542.         push   dword [fore_color]
  543.         push   dword [back_color]
  544.         call   DrawTextBold
  545. ; [client_y]
  546.         push   dword [thread_info + THREAD_INFO.client_y]
  547.         call   uint2str
  548.         push   dword COLUMN2_MAX_COUNT
  549.         call   PadBuffSpaces
  550.         push   dword COLUMN2_TEXT_X
  551.         push   dword y
  552.         push   dword tmpbuffer
  553.         push   dword [fore_color]
  554.         push   dword [back_color]
  555.         call   DrawTextBold
  556.         call   ChangeBackColor
  557.         add    y, dword ITEM_HEIGHT
  558. %endmacro
  559. ; **************************************************************************** ;
  560. %macro DrawClientSizeX 0
  561. ; sz_client_size_x
  562.         push   dword COLUMN1_TEXT_X
  563.         push   dword y
  564.         push   dword sz_client_size_x
  565.         push   dword [fore_color]
  566.         push   dword [back_color]
  567.         call   DrawTextBold
  568. ; [client_size_x]
  569.         push   dword [thread_info + THREAD_INFO.client_size_x]
  570.         call   uint2str
  571.         push   dword COLUMN2_MAX_COUNT
  572.         call   PadBuffSpaces
  573.         push   dword COLUMN2_TEXT_X
  574.         push   dword y
  575.         push   dword tmpbuffer
  576.         push   dword [fore_color]
  577.         push   dword [back_color]
  578.         call   DrawTextBold
  579.         call   ChangeBackColor
  580.         add    y, dword ITEM_HEIGHT
  581. %endmacro
  582. ; **************************************************************************** ;
  583. %macro DrawClientSizeY 0
  584. ; sz_client_size_y
  585.         push   dword COLUMN1_TEXT_X
  586.         push   dword y
  587.         push   dword sz_client_size_y
  588.         push   dword [fore_color]
  589.         push   dword [back_color]
  590.         call   DrawTextBold
  591. ; [client_size_y]
  592.         push   dword [thread_info + THREAD_INFO.client_size_y]
  593.         call   uint2str
  594.         push   dword COLUMN2_MAX_COUNT
  595.         call   PadBuffSpaces
  596.         push   dword COLUMN2_TEXT_X
  597.         push   dword y
  598.         push   dword tmpbuffer
  599.         push   dword [fore_color]
  600.         push   dword [back_color]
  601.         call   DrawTextBold
  602.         call   ChangeBackColor
  603.         add    y, dword ITEM_HEIGHT
  604. %endmacro
  605. ; **************************************************************************** ;
  606. %macro DrawWindowState 0
  607. ; sz_window_state
  608.         push   dword COLUMN1_TEXT_X
  609.         push   dword y
  610.         push   dword sz_window_state
  611.         push   dword [fore_color]
  612.         push   dword [back_color]
  613.         call   DrawTextBold
  614. ; decoded_window_state & [window_state]
  615.         movzx  eax, byte [thread_info + THREAD_INFO.window_state]
  616.         push   eax ; for "call uint2str" below
  617.         mov    ebx, eax
  618.         mov    [tmpbuffer], byte 0
  619. %%maximized:
  620.         test   ebx, WINDOW_STATE_MAXIMIZED
  621.         jz     %%minimized
  622.         push   tmpbuffer
  623.         push   sz_maximized
  624.         call   StringConcatenate
  625. %%minimized:
  626.         test   ebx, WINDOW_STATE_MINIMIZED
  627.         jz     %%rolled_up
  628.         push   tmpbuffer
  629.         push   sz_minimized
  630.         call   StringConcatenate
  631. %%rolled_up:
  632.         test   ebx, WINDOW_STATE_ROLLED_UP
  633.         jz     %%draw_decoded_window_state
  634.         push   tmpbuffer
  635.         push   sz_rolled_up
  636.         call   StringConcatenate
  637. %%draw_decoded_window_state:
  638.         push   dword COLUMN3_MAX_COUNT
  639.         call   PadBuffSpaces
  640.         push   dword COLUMN3_TEXT_X
  641.         push   dword y
  642.         push   dword tmpbuffer
  643.         push   dword [fore_color]
  644.         push   dword [back_color]
  645.         call   DrawTextBold
  646.         call   uint2str
  647.         push   dword COLUMN2_MAX_COUNT
  648.         call   PadBuffSpaces
  649.         push   dword COLUMN2_TEXT_X
  650.         push   dword y
  651.         push   dword tmpbuffer
  652.         push   dword [fore_color]
  653.         push   dword [back_color]
  654.         call   DrawTextBold
  655.         call   ChangeBackColor
  656.         add    y, dword ITEM_HEIGHT
  657. %endmacro
  658. ; **************************************************************************** ;
  659. %macro DrawEventMask 0
  660. ; sz_event_mask
  661.         push   dword COLUMN1_TEXT_X
  662.         push   dword y
  663.         push   dword sz_event_mask
  664.         push   dword [fore_color]
  665.         push   dword [back_color]
  666.         call   DrawTextBold
  667. ; decoded_event_mask & [event_mask]
  668.         mov    eax, [thread_info + THREAD_INFO.event_mask]
  669.         push   eax ; for "call uint2str" below
  670.         mov    ebx, eax
  671.         mov    [tmpbuffer], byte 0
  672. %%redraw:
  673.         test   ebx, EM_REDRAW
  674.         jz     %%key
  675.         push   tmpbuffer
  676.         push   sz_redraw
  677.         call   StringConcatenate
  678. %%key:
  679.         test   ebx, EM_KEY
  680.         jz     %%button
  681.         push   tmpbuffer
  682.         push   sz_key
  683.         call   StringConcatenate
  684. %%button:
  685.         test   ebx, EM_BUTTON
  686.         jz     %%reserved0
  687.         push   tmpbuffer
  688.         push   sz_button
  689.         call   StringConcatenate
  690. %%reserved0:
  691.         test   ebx, EM_RESERVED0
  692.         jz     %%redraw_background
  693.         push   tmpbuffer
  694.         push   sz_reserved0
  695.         call   StringConcatenate
  696. %%redraw_background:
  697.         test   ebx, EM_REDRAW_BACKGROUND
  698.         jz     %%mouse
  699.         push   tmpbuffer
  700.         push   sz_redraw_background
  701.         call   StringConcatenate
  702. %%mouse:
  703.         test   ebx, EM_MOUSE
  704.         jz     %%ipc
  705.         push   tmpbuffer
  706.         push   sz_mouse
  707.         call   StringConcatenate
  708. %%ipc:
  709.         test   ebx, EM_IPC
  710.         jz     %%network
  711.         push   tmpbuffer
  712.         push   sz_ipc
  713.         call   StringConcatenate
  714. %%network:
  715.         test   ebx, EM_NETWORK
  716.         jz     %%debug
  717.         push   tmpbuffer
  718.         push   sz_network
  719.         call   StringConcatenate
  720. %%debug:
  721.         test   ebx, EM_DEBUG
  722.         jz     %%draw_decoded_event_mask
  723.         push   tmpbuffer
  724.         push   sz_debug
  725.         call   StringConcatenate
  726. %%draw_decoded_event_mask:
  727.         push   dword COLUMN3_MAX_COUNT
  728.         call   PadBuffSpaces
  729.         push   dword COLUMN3_TEXT_X
  730.         push   dword y
  731.         push   dword tmpbuffer
  732.         push   dword [fore_color]
  733.         push   dword [back_color]
  734.         call   DrawTextBold
  735.         call   uint2str
  736.         push   dword COLUMN2_MAX_COUNT
  737.         call   PadBuffSpaces
  738.         push   dword COLUMN2_TEXT_X
  739.         push   dword y
  740.         push   dword tmpbuffer
  741.         push   dword [fore_color]
  742.         push   dword [back_color]
  743.         call   DrawTextBold
  744.         call   ChangeBackColor
  745.         add    y, dword ITEM_HEIGHT
  746. %endmacro
  747. ; **************************************************************************** ;
  748. %macro DrawKeyboardMode 0
  749.         push   dword COLUMN2_MAX_COUNT
  750.         call   PadBuffSpaces
  751. ; sz_keyboard_mode
  752.         push   dword COLUMN1_TEXT_X
  753.         push   dword y
  754.         push   dword sz_keyboard_mode
  755.         push   dword [fore_color]
  756.         push   dword [back_color]
  757.         call   DrawTextBold
  758. ; decoded_keyboard_mode & [keyboard_mode]
  759.         movzx  eax, byte [thread_info + THREAD_INFO.keyboard_mode]
  760.         push   eax ; for "call uint2str" below
  761. %%ascii:
  762.         cmp    eax, KEYBOARD_MODE_ASCII
  763.         jne    %%scan
  764.         mov    eax, sz_ascii
  765.         jmp    %%draw_decoded_keyboard_mode
  766. %%scan:
  767.         cmp    eax, KEYBOARD_MODE_SCAN
  768.         jne    %%undefined
  769.         mov    eax, sz_scan
  770.         jmp    %%draw_decoded_keyboard_mode
  771. %%undefined:
  772.         mov    eax, sz_undefined
  773. %%draw_decoded_keyboard_mode:
  774.         push   dword COLUMN3_TEXT_X
  775.         push   dword y
  776.         push   eax
  777.         push   dword [fore_color]
  778.         push   dword [back_color]
  779.         call   DrawTextBold
  780.         call   uint2str
  781.         push   dword COLUMN2_TEXT_X
  782.         push   dword y
  783.         push   dword tmpbuffer
  784.         push   dword [fore_color]
  785.         push   dword [back_color]
  786.         call   DrawTextBold
  787.         call   ChangeBackColor
  788.         add    y, dword ITEM_HEIGHT
  789. %endmacro
  790. ; **************************************************************************** ;
  791. %macro DrawUpdateIndicator 0
  792.         mov    eax, [IndicatorColors]
  793.         sub    eax, 3
  794.         neg    eax
  795.         mov    [IndicatorColors], eax
  796. ; draw.rectangle
  797.         mov    edx, [eax * 4 + IndicatorColors]
  798.         mov    eax, 13
  799.         mov    ebx, INDICATOR_LEFT << 16 | INDICATOR_WIDTH
  800.         mov    ecx, INDICATOR_TOP  << 16 | INDICATOR_HEIGHT
  801.         int    64
  802. %endmacro
  803. ; **************************************************************************** ;
  804. %macro DrawTable 0
  805. ; DrawFrames
  806.         push   dword FRAME1_LEFT
  807.         push   dword FRAME_TOP
  808.         push   dword FRAME1_RIGHT
  809.         push   dword FRAME_BOTTOM
  810.         push   dword [frame_color]
  811.         call   DrawFrame
  812.         push   dword FRAME2_LEFT
  813.         push   dword FRAME_TOP
  814.         push   dword FRAME2_RIGHT
  815.         push   dword FRAME_BOTTOM
  816.         push   dword [frame_color]
  817.         call   DrawFrame
  818.         push   dword FRAME3_LEFT
  819.         push   dword FRAME_TOP
  820.         push   dword FRAME3_RIGHT
  821.         push   dword FRAME_BOTTOM
  822.         push   dword [frame_color]
  823.         call   DrawFrame
  824. ; DrawItems
  825.         mov    esi, COLUMN_Y
  826.         xor    edi, edi
  827. %%draw_item:
  828.         cmp    edi, ITEM_COUNT
  829.         jnl    %%done
  830.         mov    ecx, esi
  831.         shl    ecx, 16
  832.         or     ecx, ITEM_HEIGHT
  833. ; draw.rectangle
  834.         mov    eax, 13
  835.         mov    ebx, COLUMN1_X << 16 | COLUMN1_ITEM_WIDTH
  836.         mov    edx, [back_color]
  837.         int    64
  838. ; draw.rectangle
  839.         mov    eax, 13
  840.         mov    ebx, COLUMN2_X << 16 | COLUMN2_ITEM_WIDTH
  841.         mov    edx, [back_color]
  842.         int    64
  843. ; draw.rectangle
  844.         mov    eax, 13
  845.         mov    ebx, COLUMN3_X << 16 | COLUMN3_ITEM_WIDTH
  846.         mov    edx, [back_color]
  847.         int    64
  848.         call   ChangeBackColor
  849.         add    esi, ITEM_HEIGHT
  850.         inc    edi
  851.         jmp    %%draw_item
  852. %%done:
  853. %endmacro
  854. ; ---------------------------------------------------------------------------- ;
  855. align 4
  856. START:
  857.         mov    esi, [program.params]
  858.         test   [esi], byte 0xFF
  859.         jz     .no_params
  860. ; str2uint(program.params)
  861.         xor    eax, eax
  862.         xor    ecx, ecx
  863. .convert:
  864.         lodsb
  865.         test   al, al
  866.         jz     .converted
  867.         lea    ecx, [ecx + ecx * 4]
  868.         lea    ecx, [eax + ecx * 2 - 48]
  869.         jmp    .convert
  870. .converted:
  871.         mov    [slot], ecx
  872. .no_params:
  873. ; get.screen.size
  874.         mov    eax, 61
  875.         mov    ebx, 1
  876.         int    64
  877.         mov    [screen], eax
  878. ; skin.height
  879.         mov    eax, 48
  880.         mov    ebx, 4
  881.         int    64
  882.         add    eax, FRAME_BOTTOM + FRAME_TOP + WINDOW_BORDER_SIZE
  883.         mov    [window.width], dword WINDOW_WIDTH
  884.         mov    [window.height], eax
  885.         movzx  eax, word [screen.width]
  886.         movzx  edx, word [screen.height]
  887.         sub    eax, [window.width]
  888.         sub    edx, [window.height]
  889.         shr    eax, 1
  890.         shr    edx, 1
  891.         mov    [window.left], eax
  892.         mov    [window.top], edx
  893. ; set.event
  894.         mov    eax, 40
  895.         mov    ebx, EM_REDRAW | EM_BUTTON
  896.         int    64
  897. ; ---------------------------------------------------------------------------- ;
  898. align 4
  899. on_redraw:
  900. ; redraw.start
  901.         mov    eax, 12
  902.         mov    ebx, 1
  903.         int    64
  904. ; draw.window
  905.         xor    eax, eax
  906.         mov    ebx, [window.left]
  907.         mov    ecx, [window.top]
  908.         shl    ebx, 16
  909.         shl    ecx, 16
  910.         or     ebx, [window.width]
  911.         or     ecx, [window.height]
  912.         mov    edx, WINDOW_STYLE | WINDOW_BACK_COLOR
  913.         mov    edi, sz_caption
  914.         xor    esi, esi
  915.         int    64
  916. ; redraw.finish
  917.         mov    eax, 12
  918.         mov    ebx, 2
  919.         int    64
  920.         DrawTable
  921.         call   UpdateThreadInfo
  922. align 4
  923. wait.event.by.time:
  924.         mov    eax, 23
  925.         mov    ebx, UPDATE_TIME
  926.         int    64
  927.         dec    eax
  928.         jz     on_redraw        ; IF      eax = 1 THEN   redraw
  929.         jns    on_button        ; ELSEIF  eax = 2 THEN   button
  930.         call   UpdateThreadInfo ; ELSE no event -> update thread info
  931.         jmp    wait.event.by.time
  932. align 4
  933. on_button: ; terminate because we have only one button(close button)
  934.         or     eax, -1
  935.         int    64
  936. ; ---------------------------------------------------------------------------- ;
  937. align 4
  938. UpdateThreadInfo:
  939. ; get.thread.info
  940.         mov    eax, 9
  941.         mov    ebx, thread_info
  942.         mov    ecx, [slot]
  943.         int    64
  944.  
  945.         mov    x, dword COLUMN1_X
  946.         mov    y, dword COLUMN_Y + (ITEM_HEIGHT - TEXT_HEIGHT) / 2
  947.         mov    [back_color], dword ITEM_BACK_COLOR_1
  948.         mov    [BackColors], dword 1
  949. ; order of next "Draw..." can be changed
  950.         DrawName
  951.         DrawThreadState
  952.         DrawWindowState
  953.         DrawEventMask
  954.         DrawKeyboardMode
  955.         DrawCpuUsage
  956.         DrawMemUsage
  957.         DrawMemAddress
  958.         DrawIdentifier
  959.         DrawWinStackPos
  960.         DrawWindowX
  961.         DrawWindowY
  962.         DrawWindowSizeX
  963.         DrawWindowSizeY
  964.         DrawClientX
  965.         DrawClientY
  966.         DrawClientSizeX
  967.         DrawClientSizeY
  968.  
  969.         DrawUpdateIndicator ; blinking thing at upper right corner
  970.  
  971.         ret
  972. ; ---------------------------------------------------------------------------- ;
  973. align 4
  974. DrawFrame:
  975. %define Color  [esp +  4 +1*4]
  976. %define Bottom [esp +  8 +1*4]
  977. %define Top    [esp + 16 +1*4]
  978. %define Right  [esp + 12 +1*4]
  979. %define Left   [esp + 20 +1*4]
  980.         push   ebp
  981.         mov    eax, 38
  982.         mov    edx, Color
  983.         mov    esi, Bottom
  984.         mov    edi, Top
  985.         mov    ebp, Right
  986.         mov    ebx, Left
  987.         shl    ebx, 16
  988.         mov    bx, bp
  989.         shrd   ecx, edi, 16
  990.         mov    cx, di
  991.         int    64
  992.         shrd   ecx, esi, 16
  993.         mov    cx, si
  994.         int    64
  995.         shld   esi, ebx, 16
  996.         mov    bx, si
  997.         shrd   ecx, edi, 16
  998.         int    64
  999.         shrd   ebx, ebp, 16
  1000.         mov    bx, bp
  1001.         int    64
  1002.         pop    ebp
  1003.         ret    20
  1004. %undef Color
  1005. %undef Bottom
  1006. %undef Top
  1007. %undef Right
  1008. %undef Left
  1009. ; ---------------------------------------------------------------------------- ;
  1010. align 4
  1011. StringConcatenate:
  1012. %define stradd [esp +  4]
  1013. %define str    [esp +  8]
  1014.         mov    esi, stradd
  1015.         or     ecx, -1
  1016.         mov    edi, esi
  1017.         xor    eax, eax
  1018.         repne scasb
  1019.         mov    edx, ecx
  1020.         mov    edi, str
  1021.         repne scasb
  1022.         dec    edi
  1023.         not    edx
  1024.         mov    eax, str
  1025.         mov    ecx, edx
  1026.         shr    ecx, 2
  1027.         and    edx, 3
  1028.         rep movsd
  1029.         mov    ecx, edx
  1030.         rep movsb
  1031.         ret    8
  1032. %undef stradd
  1033. %undef str
  1034. ; ---------------------------------------------------------------------------- ;
  1035. align 4
  1036. DrawTextBold:
  1037. %define x          [esp + 20]
  1038. %define y          [esp + 16]
  1039. %define text       [esp + 12]
  1040. %define fore_color [esp +  8]
  1041. %define back_color [esp +  4]
  1042.         mov    eax, 4
  1043.         mov    ecx, fore_color
  1044.         mov    edi, back_color
  1045.         mov    esi, 1 ; count
  1046.         mov    edx, text
  1047.         mov    ebx, x
  1048.         shl    ebx, 16
  1049.         or     ebx, y
  1050. align 4
  1051. .next:
  1052.         test   [edx], byte 0xFF
  1053.         jz     .done
  1054.         or     ecx, 0x40000000
  1055.         int    64
  1056.         add    ebx, (1 << 16)
  1057.         and    ecx, 0x00FFFFFF
  1058.         int    64
  1059.         add    ebx, (6 << 16)
  1060.         inc    edx
  1061.         jmp    .next
  1062. align 4
  1063. .done:
  1064.         ret    20
  1065. %undef x
  1066. %undef y
  1067. %undef text
  1068. %undef fore_color
  1069. %undef back_color
  1070. ; ---------------------------------------------------------------------------- ;
  1071. align 4
  1072. ChangeBackColor:
  1073.         mov    eax, [BackColors]
  1074.         sub    eax, 3
  1075.         neg    eax
  1076.         mov    [BackColors], eax
  1077.         mov    eax, [eax * 4 + BackColors]
  1078.         mov    [back_color], eax
  1079.         ret
  1080. ; ---------------------------------------------------------------------------- ;
  1081. align 4
  1082. uint2str:
  1083. %define value  [esp + 4]
  1084.         push   dword value     ; value
  1085.         push   dword 10        ; base(decimal)
  1086.         push   dword tmpbuffer ; buffer
  1087.         call   ConvertToBase
  1088.         ret    4
  1089. %undef value
  1090. ; ---------------------------------------------------------------------------- ;
  1091. align 4
  1092. ConvertToBase:
  1093. %define value  [esp + 12]        ; value treated as unsigned
  1094. %define base   [esp +  8]        ; 2 <= base <= 36
  1095. %define buffer [esp +  4]        ; SizeOf(buffer) => (32 + 1)
  1096.         mov    eax, value
  1097.         mov    ecx, base
  1098.         mov    esi, buffer
  1099.         mov    edi, esi          ;                    +0                             +31 +32
  1100.         add    esi, 32           ; base2(0xFFFFFFFF) = 11111111111111111111111111111111b
  1101.         mov    [esi], byte 0     ; end of string                                       byte 0
  1102. align 4
  1103. .next:
  1104.         xor    edx, edx
  1105.         div    ecx
  1106.         dec    esi
  1107.         mov    dl, [edx + .digits]; (put digit
  1108.         mov    [esi], dl          ;           to buffer)
  1109.         test   eax, eax
  1110.         jnz    .next
  1111. ; shift result string to buffer beginning
  1112.         mov    eax, esi
  1113.         sub    eax, edi
  1114.         mov    ecx, 32 + 1
  1115.         sub    ecx, eax
  1116.         mov    eax, edi          ; return buffer
  1117. ; yes, memory overlapped, but edi not above than esi
  1118. ; hope that movsD faster than movsB in this case
  1119. ; if you want only "rep movsb" because it shorter then remove five next lines before "rep movsb"
  1120.         mov    edx, ecx
  1121.         shr    ecx, 2
  1122.         and    edx, 3
  1123.         rep    movsd
  1124.         mov    ecx, edx
  1125.         rep    movsb
  1126.         ret    12
  1127. %undef value
  1128. %undef base
  1129. %undef buffer
  1130. align 4
  1131. .digits  db    "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  1132. ; ---------------------------------------------------------------------------- ;
  1133. align 4
  1134. PadBuffSpaces:
  1135. %define maxlen [esp + 4]
  1136.         mov    edi, tmpbuffer
  1137.         or     ecx, -1
  1138.         xor    eax, eax
  1139.         repne scasb
  1140.         dec    edi
  1141.         sub    eax, ecx
  1142.         dec    eax
  1143.         mov    ecx, maxlen
  1144.         sub    ecx, eax
  1145.         mov    eax, "    "
  1146.         mov    edx, ecx
  1147.         shr    ecx, 2
  1148.         and    edx, 3
  1149.         rep    stosd
  1150.         mov    ecx, edx
  1151.         rep    stosb
  1152.         mov    [edi], byte 0
  1153.         ret    4
  1154. %undef maxlen
  1155. ; ---------------------------------------------------------------------------- ;
  1156. align 4
  1157. END: