Subversion Repositories Kolibri OS

Rev

Rev 4944 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;   This program shows  state of mouse buttons   ;
  2. ;  to compile: nasm -f bin mstate.asm -o mstate  ;
  3. ORG 0
  4. BITS 32
  5. ; ---------------------------------------------------------------------------- ;
  6. PATH_SIZE                         equ 256
  7. PARAMS_SIZE                       equ 256
  8. STACK_SIZE                        equ 256
  9. ; ---------------------------------------------------------------------------- ;
  10. TEXT_WIDTH                        equ 6
  11. TEXT_HEIGHT                       equ 9
  12. ; ---------------------------------------------------------------------------- ;
  13. MOUSE_LEFT_BUTTON_MASK            equ         1b
  14. MOUSE_RIGHT_BUTTON_MASK           equ        10b
  15. MOUSE_MIDDLE_BUTTON_MASK          equ       100b
  16. ; ---------------------------------------------------------------------------- ;
  17. EM_REDRAW                         equ         1b
  18. EM_KEY                            equ        10b
  19. EM_BUTTON                         equ       100b
  20. EM_RESERVED0                      equ      1000b
  21. EM_REDRAW_BACKGROUND              equ     10000b
  22. EM_MOUSE                          equ    100000b
  23. EM_IPC                            equ   1000000b
  24. EM_NETWORK                        equ  10000000b
  25. EM_DEBUG                          equ 100000000b
  26. ; ---------------------------------------------------------------------------- ;
  27. WINDOW_STYLE_SKINNED_FIXED        equ 0x4000000
  28. WINDOW_STYLE_COORD_CLIENT         equ 0x20000000
  29. WINDOW_STYLE_CAPTION              equ 0x10000000
  30. ; ---------------------------------------------------------------------------- ;
  31. WINDOW_BORDER_SIZE                equ 5
  32. ; ---------------------------------------------------------------------------- ;
  33. WINDOW_STYLE                      equ WINDOW_STYLE_SKINNED_FIXED | WINDOW_STYLE_COORD_CLIENT | WINDOW_STYLE_CAPTION
  34. ; ---------------------------------------------------------------------------- ;
  35. MOUSE_BODY_COLOR                  equ 0x007C7C96
  36. MOUSE_LEFT_BUTTON_COLOR           equ 0x008293A4
  37. MOUSE_RIGHT_BUTTON_COLOR          equ 0x008293A4
  38. MOUSE_MIDDLE_BUTTON_COLOR         equ 0x00A48293
  39. MOUSE_LEFT_BUTTON_PRESSED_COLOR   equ 0x00568EC7
  40. MOUSE_RIGHT_BUTTON_PRESSED_COLOR  equ 0x00568EC7
  41. MOUSE_MIDDLE_BUTTON_PRESSED_COLOR equ 0x00C7568E
  42. WINDOW_BACK_COLOR                 equ 0x00EFEFEF
  43. ; ---------------------------------------------------------------------------- ;
  44. MOUSE_WIDTH                       equ 120
  45. MOUSE_HEIGHT                      equ 240
  46. MOUSE_MARGIN                      equ 4
  47. BUTTONS_MARGIN                    equ 2
  48. ; ---------------------------------------------------------------------------- ;
  49. MOUSE_LEFT                        equ MOUSE_MARGIN
  50. MOUSE_TOP                         equ MOUSE_MARGIN
  51. WINDOW_WIDTH                      equ MOUSE_WIDTH + WINDOW_BORDER_SIZE * 2 + MOUSE_MARGIN * 2
  52. MOUSE_BODY_HEIGHT                 equ (MOUSE_HEIGHT - BUTTONS_MARGIN) / 2
  53. MOUSE_BODY_TOP                    equ MOUSE_HEIGHT  - MOUSE_BODY_HEIGHT + MOUSE_TOP
  54. LEFT_BUTTON_HEIGHT                equ MOUSE_HEIGHT - MOUSE_BODY_HEIGHT - BUTTONS_MARGIN
  55. RIGHT_BUTTON_HEIGHT               equ MOUSE_HEIGHT - MOUSE_BODY_HEIGHT - BUTTONS_MARGIN
  56. LEFT_BUTTON_WIDTH                 equ (MOUSE_WIDTH  - BUTTONS_MARGIN) / 2
  57. RIGHT_BUTTON_WIDTH                equ MOUSE_WIDTH  - LEFT_BUTTON_WIDTH - BUTTONS_MARGIN
  58. LEFT_BUTTON_LEFT                  equ MOUSE_LEFT
  59. RIGHT_BUTTON_LEFT                 equ LEFT_BUTTON_LEFT + LEFT_BUTTON_WIDTH + BUTTONS_MARGIN
  60. MIDDLE_BUTTON_WIDTH               equ MOUSE_WIDTH / 10
  61. MIDDLE_BUTTON_HEIGHT              equ MOUSE_HEIGHT / 6
  62. MIDDLE_BUTTON_LEFT                equ (MOUSE_WIDTH - MIDDLE_BUTTON_WIDTH) / 2 + MOUSE_LEFT
  63. MIDDLE_BUTTON_TOP                 equ (MOUSE_WIDTH / 2 - MIDDLE_BUTTON_WIDTH) / 2 + MOUSE_TOP
  64. ; ---------------------------------------------------------------------------- ;
  65. %define SZ_BUTTONS_STATE "Buttons state:"
  66. %define SZ_BIN "bin:"
  67. %define SZ_HEX "hex:0x"
  68. %strlen LEN_SZ_BUTTONS_STATE SZ_BUTTONS_STATE
  69. %strlen LEN_SZ_BIN SZ_BIN
  70. %strlen LEN_SZ_HEX SZ_HEX
  71. ; ---------------------------------------------------------------------------- ;
  72. STATE_VALUES_HEIGHT               equ 3 * TEXT_HEIGHT ; we have three lines of text
  73. STATE_VALUES_WIDTH                equ LEN_SZ_BUTTONS_STATE * TEXT_WIDTH
  74. STATE_VALUES_TOP                  equ (MOUSE_BODY_HEIGHT - STATE_VALUES_HEIGHT) / 2 + MOUSE_BODY_TOP
  75. STATE_VALUES_LEFT                 equ (MOUSE_WIDTH - STATE_VALUES_WIDTH) / 2 + MOUSE_LEFT
  76. ; ---------------------------------------------------------------------------- ;
  77. MENUET01                          db 'MENUET01'
  78. version                           dd 1
  79. program.start                     dd START
  80. program.end                       dd _END
  81. program.memory                    dd _END + PATH_SIZE + PARAMS_SIZE + STACK_SIZE
  82. program.stack                     dd _END + PATH_SIZE + PARAMS_SIZE + STACK_SIZE
  83. program.params                    dd _END + PATH_SIZE
  84. program.path                      dd _END
  85. ; ---------------------------------------------------------------------------- ;
  86. mouse_body_color                  dd MOUSE_BODY_COLOR
  87. mouse_left_button_color           dd MOUSE_LEFT_BUTTON_COLOR
  88. mouse_right_button_color          dd MOUSE_RIGHT_BUTTON_COLOR
  89. mouse_middle_button_color         dd MOUSE_MIDDLE_BUTTON_COLOR
  90. ; ---------------------------------------------------------------------------- ;
  91. mouse.button                      dd 0
  92. ; ---------------------------------------------------------------------------- ;
  93. sz_caption                        db "MouseState",0
  94. ; ---------------------------------------------------------------------------- ;
  95. sz_button_state                   db SZ_BUTTONS_STATE,0
  96. sz_bin                            db SZ_BIN,0
  97. sz_hex                            db SZ_HEX,0
  98. ; ---------------------------------------------------------------------------- ;
  99. %macro DrawMouseBody 0
  100. ; draw.rectangle
  101.         mov    eax, 13
  102.         mov    ebx, MOUSE_LEFT         << 16 | MOUSE_WIDTH
  103.         mov    ecx, MOUSE_BODY_TOP     << 16 | MOUSE_BODY_HEIGHT
  104.         mov    edx, [mouse_body_color]
  105.         int    64
  106. ; texts
  107.         mov    eax, 4
  108.         mov    ecx, 1100b << 28 | WINDOW_BACK_COLOR
  109.         mov    edi, [mouse_body_color]
  110. ; draw.text
  111.         mov    ebx, (STATE_VALUES_LEFT << 16) | STATE_VALUES_TOP
  112.         mov    edx, sz_button_state
  113.         int    64
  114. ; draw.text
  115.         add    ebx, TEXT_HEIGHT
  116.         mov    edx, sz_bin
  117.         int    64
  118. ; draw.text
  119.         add    ebx, TEXT_HEIGHT
  120.         mov    edx, sz_hex
  121.         int    64
  122. %endmacro
  123. ; ---------------------------------------------------------------------------- ;
  124. align 4
  125. DrawMouseButtons:
  126.         mov    eax, 13
  127. ; draw.rectangle
  128.         mov    ebx, LEFT_BUTTON_LEFT   << 16 | LEFT_BUTTON_WIDTH
  129.         mov    ecx, MOUSE_TOP          << 16 | LEFT_BUTTON_HEIGHT
  130.         mov    edx, [mouse_left_button_color]
  131.         int    64
  132. ; draw.rectangle
  133.         mov    ebx, RIGHT_BUTTON_LEFT  << 16 | RIGHT_BUTTON_WIDTH
  134.         mov    ecx, MOUSE_TOP          << 16 | RIGHT_BUTTON_HEIGHT
  135.         mov    edx, [mouse_right_button_color]
  136.         int    64
  137. ; draw.rectangle
  138.         mov    ebx, MIDDLE_BUTTON_LEFT << 16 | MIDDLE_BUTTON_WIDTH
  139.         mov    ecx, MIDDLE_BUTTON_TOP  << 16 | MIDDLE_BUTTON_HEIGHT
  140.         mov    edx, [mouse_middle_button_color]
  141.         int    64
  142. ; Draw State Values
  143.         mov    eax, 47
  144.         mov    esi, 0100b << 28 | WINDOW_BACK_COLOR
  145.         mov    ecx, [mouse.button]
  146.         mov    edi, [mouse_body_color]
  147. ; draw.number
  148.         mov    ebx, (10 << 16) | (2 << 8) ; 10 digits, base2
  149.         mov    edx, (LEN_SZ_BIN * TEXT_WIDTH + STATE_VALUES_LEFT) << 16 | (STATE_VALUES_TOP + TEXT_HEIGHT)
  150.         int    64
  151. ; draw.number
  152.         mov    ebx, (8 << 16) | (1 << 8) ; 8 digits, base16
  153.         mov    edx, (LEN_SZ_HEX * TEXT_WIDTH + STATE_VALUES_LEFT) << 16 | (STATE_VALUES_TOP + TEXT_HEIGHT * 2)
  154.         int    64
  155.         ret
  156. ; ---------------------------------------------------------------------------- ;
  157. align 4
  158. START:
  159. ; get.screen.size
  160.         mov    eax, 61
  161.         mov    ebx, 1
  162.         int    64        
  163.         mov    edx, eax
  164.         movzx  ecx, ax
  165.         shr    edx, 16
  166. ; skin.height
  167.         mov    eax, 48
  168.         mov    ebx, 4
  169.         int    64
  170.         add    eax, MOUSE_HEIGHT + WINDOW_BORDER_SIZE + MOUSE_MARGIN * 2 - 1
  171.         mov    esi, eax
  172.         sub    edx, (WINDOW_WIDTH - 1)
  173.         sub    ecx, eax
  174.         shr    edx, 1
  175.         shr    ecx, 1
  176. ; set.event
  177.         mov    eax, 40
  178.         mov    ebx, EM_REDRAW | EM_BUTTON | EM_MOUSE
  179.         int    64
  180. ; ---------------------------------------------------------------------------- ;
  181. align 4
  182. on_redraw:
  183. ; redraw.start
  184.         mov    eax, 12
  185.         mov    ebx, 1
  186.         int    64
  187. ; draw.window
  188.         xor    eax, eax
  189.         mov    ebx, edx ; window.left
  190. ; ecx = window.top
  191.         shl    ebx, 16
  192.         shl    ecx, 16
  193.         or     ebx, (WINDOW_WIDTH - 1)
  194.         or     ecx, esi ; window.height
  195.         mov    edx, WINDOW_STYLE | WINDOW_BACK_COLOR
  196.         mov    edi, sz_caption
  197.         xor    esi, esi
  198.         int    64
  199. ; redraw.finish
  200.         mov    eax, 12
  201.         mov    ebx, 2
  202.         int    64
  203.         DrawMouseBody
  204.         call   DrawMouseButtons
  205. align 4
  206. wait.event:
  207.         mov    eax, 10    ; redraw = 001b; 001b & 110b = 000b
  208.         int    64         ; button = 011b; 011b & 110b = 010b
  209.         test   eax, 110b  ; mouse  = 110b; 110b & 110b = 110b
  210.         jz     on_redraw
  211.         jnp    on_button
  212. ; get.mouse.button
  213.         mov    eax, 37
  214.         mov    ebx, 2
  215.         int    64
  216.         cmp    [mouse.button], eax ;      if equal
  217.         je     wait.event          ; then no need update
  218.         mov    ebx, dword MOUSE_LEFT_BUTTON_COLOR
  219.         mov    ecx, dword MOUSE_RIGHT_BUTTON_COLOR
  220.         mov    edx, dword MOUSE_MIDDLE_BUTTON_COLOR
  221. .left:
  222.         test   eax, MOUSE_LEFT_BUTTON_MASK
  223.         jz     .right
  224.         mov    ebx, dword MOUSE_LEFT_BUTTON_PRESSED_COLOR
  225. .right:
  226.         test   eax, MOUSE_RIGHT_BUTTON_MASK
  227.         jz     .middle
  228.         mov    ecx, dword MOUSE_RIGHT_BUTTON_PRESSED_COLOR
  229. .middle:
  230.         test   eax, MOUSE_MIDDLE_BUTTON_MASK
  231.         jz     .other
  232.         mov    edx, dword MOUSE_MIDDLE_BUTTON_PRESSED_COLOR
  233. .other:
  234.         mov    [mouse_left_button_color], ebx
  235.         mov    [mouse_right_button_color], ecx
  236.         mov    [mouse_middle_button_color], edx
  237.         mov    [mouse.button], eax
  238.         call   DrawMouseButtons
  239.         jmp    wait.event
  240. align 4
  241. on_button: ; terminate because we have only one button(close button)
  242.         or     eax, -1
  243.         int    64
  244. ; ---------------------------------------------------------------------------- ;
  245. align 4
  246. _END:
  247.