Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2022. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 9930 $
  9.  
  10.  
  11. ;   check mouse
  12. ;
  13. ;
  14. ;   FB00  ->   FB0F   mouse memory 00 chunk count - FB0A-B x - FB0C-D y
  15. ;   FB10  ->   FB17   mouse color mem
  16. ;   FB21              x move
  17. ;   FB22              y move
  18. ;   FB30              color temp
  19. ;   FB28              high bits temp
  20. ;   FB4A  ->   FB4D   FB4A-B x-under - FB4C-D y-under
  21. ;   FC00  ->   FCFE   com1/ps2 buffer
  22. ;   FCFF              com1/ps2 buffer count starting from FC00
  23.  
  24. uglobal
  25. ;--------------------------------------
  26. align 4
  27. mousecount                      dd ?
  28. mousedata                       dd ?
  29. Y_UNDER_sub_CUR_hot_y_add_curh  dw ?
  30. Y_UNDER_subtraction_CUR_hot_y   dw ?
  31. X_UNDER_sub_CUR_hot_x_add_curh  dw ?
  32. X_UNDER_subtraction_CUR_hot_x   dw ?
  33. endg
  34.  
  35. iglobal
  36. ;--------------------------------------
  37. align 4
  38. mouse_speed_factor      dw 4
  39. mouse_delay             db 3
  40. mouse_doubleclick_delay db 64
  41. endg
  42.  
  43. ;-----------------------------------------------------------------------------
  44.  
  45. align 4
  46. draw_mouse_under:
  47.  
  48.         ; return old picture
  49.         cmp     [_display.restore_cursor], 0
  50.         je      @F
  51.  
  52.         pushad
  53.         movzx   eax, word [X_UNDER]
  54.         movzx   ebx, word [Y_UNDER]
  55.         stdcall [_display.restore_cursor], eax, ebx
  56.         popad
  57.         ret
  58.  
  59.   @@:
  60.         pushad
  61.         xor     ecx, ecx
  62.         xor     edx, edx
  63.  
  64.   .mres:
  65.         movzx   eax, word [X_UNDER]
  66.         movzx   ebx, word [Y_UNDER]
  67.         add     eax, ecx
  68.         add     ebx, edx
  69.         push    ecx
  70.         push    edx
  71.         push    eax
  72.         push    ebx
  73.         mov     eax, edx
  74.         shl     eax, 6
  75.         shl     ecx, 2
  76.         add     eax, ecx
  77.         add     eax, mouseunder
  78.         mov     ecx, [eax]
  79.         pop     ebx
  80.         pop     eax
  81.         mov     edi, 1 ; force
  82.         or      ecx, 0x04000000  ; don't save to mouseunder area
  83. ;        call    [putpixel]
  84.         call    __sys_putpixel
  85.         pop     edx
  86.         pop     ecx
  87.         inc     ecx
  88.         cmp     ecx, 16
  89.         jnz     .mres
  90.  
  91.         xor     ecx, ecx
  92.         inc     edx
  93.         cmp     edx, 24
  94.         jnz     .mres
  95.  
  96.         popad
  97.         ret
  98.  
  99. ;-----------------------------------------------------------------------------
  100.  
  101. align 4
  102. save_draw_mouse:
  103.         cmp     [_display.move_cursor], 0
  104.         je      .no_hw_cursor
  105.         pushad
  106.  
  107.         mov     [X_UNDER], ax
  108.         mov     [Y_UNDER], bx
  109.         movzx   eax, word [MOUSE_Y]
  110.         movzx   ebx, word [MOUSE_X]
  111.         push    eax
  112.         push    ebx
  113.  
  114.         mov     eax, [d_width_calc_area + eax*4]
  115.  
  116.         add     eax, [_display.win_map]
  117.         movzx   edx, byte [ebx + eax]
  118.         shl     edx, BSF sizeof.WDATA
  119.         ; edx - thread slot of window under cursor
  120.         mov     esi, [window_data + edx + WDATA.cursor] ; cursor of window under cursor
  121.  
  122.         ; if cursor of window under cursor already equal to the
  123.         ; current_cursor then just draw it
  124.         cmp     esi, [current_cursor]
  125.         je      .draw
  126.  
  127.         ; eax = thread slot of current active window
  128.         mov     eax, [thread_count]
  129.         movzx   eax, word [WIN_POS + eax*2]
  130.         shl     eax, BSF sizeof.WDATA
  131.  
  132.         ; window under cursor == active window ?
  133.         cmp     eax, edx
  134.         je      @f
  135.  
  136.         ; check whether active window is being resized now:
  137.         mov     bl, [mouse.active_sys_window.action]
  138.         and     bl, mouse.WINDOW_RESIZE_S_FLAG or mouse.WINDOW_RESIZE_W_FLAG or mouse.WINDOW_RESIZE_E_FLAG
  139.         test    bl, bl
  140.         jz      .active_isnt_resizing
  141.         mov     esi, [window_data + eax + WDATA.cursor] ; esi = cursor of active window, it is resizing cursor
  142.         jmp     @f
  143.         .active_isnt_resizing:
  144.  
  145.         ; if cursor of window under the cursor is resizing cursor then draw it.
  146.         cmp     esi, [def_cursor_hresize]
  147.         je      @f
  148.         cmp     esi, [def_cursor_vresize]
  149.         je      @f
  150.         cmp     esi, [def_cursor_dresize1]
  151.         je      @f
  152.         cmp     esi, [def_cursor_dresize2]
  153.         je      @f
  154.  
  155.         ; set cursor of window under cursor
  156.         mov     esi, [window_data + edx + WDATA.cursor]
  157.         cmp     esi, [current_cursor]
  158.         je      .draw
  159.  
  160. @@:
  161.         push    esi
  162.         call    [_display.select_cursor]
  163.         mov     [current_cursor], esi
  164. ;--------------------------------------
  165. align 4
  166. .draw:
  167.         stdcall [_display.move_cursor], esi
  168.         popad
  169.         ret
  170. ;--------------------------------------
  171. ;align 4
  172. ;.fail:
  173. ;        mov     ecx, [def_cursor]
  174. ;        mov     [window_data + edx + WDATA.cursor], ecx
  175. ;        stdcall [_display.move_cursor], ecx        ; stdcall: [esp]=ebx,eax
  176. ;        popad
  177. ;        ret
  178. ;--------------------------------------
  179. align 4
  180. .no_hw_cursor:
  181.         pushad
  182.         ; save & draw
  183.         mov     [X_UNDER], ax
  184.         mov     [Y_UNDER], bx
  185.         push    eax
  186.         push    ebx
  187.         mov     ecx, 0
  188.         mov     edx, 0
  189. ;--------------------------------------
  190. align 4
  191. .drm:
  192.         push    eax
  193.         push    ebx
  194.         push    ecx
  195.         push    edx
  196.         ; helloworld
  197.         push    ecx
  198.         add     eax, ecx        ; save picture under mouse
  199.         add     ebx, edx
  200.         push    ecx
  201.         or      ecx, 0x04000000 ; don't load to mouseunder area
  202.         push    eax ebx edx edi
  203.         call    [GETPIXEL]
  204.         pop     edi edx ebx eax
  205.         mov     [COLOR_TEMP], ecx
  206.         pop     ecx
  207.         mov     eax, edx
  208.         shl     eax, 6
  209.         shl     ecx, 2
  210.         add     eax, ecx
  211.         add     eax, mouseunder
  212.         mov     ebx, [COLOR_TEMP]
  213.         and     ebx, 0xffffff
  214.         mov     [eax], ebx
  215.         pop     ecx
  216.         mov     edi, edx        ; y cycle
  217.         shl     edi, 4          ; *16 bytes per row
  218.         add     edi, ecx        ; x cycle
  219.         mov     esi, edi
  220.         add     edi, esi
  221.         add     edi, esi        ; *3
  222.         add     edi, [MOUSE_PICTURE]    ; we have our str address
  223.         mov     esi, edi
  224.         add     esi, 16*24*3
  225.         push    ecx
  226.         mov     ecx, [COLOR_TEMP]
  227.         call    combine_colors
  228.         and     ecx, 0xffffff
  229.         mov     [MOUSE_COLOR_MEM], ecx
  230.         pop     ecx
  231.         pop     edx
  232.         pop     ecx
  233.         pop     ebx
  234.         pop     eax
  235.         add     eax, ecx        ; we have x coord+cycle
  236.         add     ebx, edx        ; and y coord+cycle
  237.         push    ecx
  238.         mov     ecx, [MOUSE_COLOR_MEM]
  239.         mov     edi, 1 ; force
  240.         or      ecx, 0x04000000 ; don't save to mouseunder area
  241. ;        call    [putpixel]
  242.         call    __sys_putpixel
  243.         pop     ecx
  244.         mov     ebx, [esp+0]    ; pure y coord again
  245.         mov     eax, [esp+4]    ; and x
  246.         inc     ecx             ; +1 cycle
  247.         cmp     ecx, 16         ; if more than 16
  248.         jnz     .drm
  249.  
  250.         xor     ecx, ecx
  251.         inc     edx
  252.         cmp     edx, 24
  253.         jnz     .drm
  254.  
  255.         add     esp, 8
  256.         popad
  257.         ret
  258.  
  259. ;-----------------------------------------------------------------------------
  260.  
  261. align 4
  262. combine_colors:
  263.       ; in
  264.       ; ecx - color ( 00 RR GG BB )
  265.       ; edi - ref to new color byte
  266.       ; esi - ref to alpha byte
  267.       ;
  268.       ; out
  269.       ; ecx - new color ( roughly (ecx*[esi]>>8)+([edi]*[esi]>>8) )
  270.         push    eax
  271.         push    ebx
  272.         push    edx
  273.         push    ecx
  274.         xor     ecx, ecx
  275.          ; byte 0
  276.         mov     eax, 0xff
  277.         sub     al, [esi+0]
  278.         mov     ebx, [esp]
  279.         shr     ebx, 16
  280.         and     ebx, 0xff
  281.         mul     ebx
  282.         shr     eax, 8
  283.         add     ecx, eax
  284.         xor     eax, eax
  285.         xor     ebx, ebx
  286.         mov     al, [edi+0]
  287.         mov     bl, [esi+0]
  288.         mul     ebx
  289.         shr     eax, 8
  290.         add     ecx, eax
  291.         shl     ecx, 8
  292.          ; byte 1
  293.         mov     eax, 0xff
  294.         sub     al, [esi+1]
  295.         mov     ebx, [esp]
  296.         shr     ebx, 8
  297.         and     ebx, 0xff
  298.         mul     ebx
  299.         shr     eax, 8
  300.         add     ecx, eax
  301.         xor     eax, eax
  302.         xor     ebx, ebx
  303.         mov     al, [edi+1]
  304.         mov     bl, [esi+1]
  305.         mul     ebx
  306.         shr     eax, 8
  307.         add     ecx, eax
  308.         shl     ecx, 8
  309.          ; byte 2
  310.         mov     eax, 0xff
  311.         sub     al, [esi+2]
  312.         mov     ebx, [esp]
  313.         and     ebx, 0xff
  314.         mul     ebx
  315.         shr     eax, 8
  316.         add     ecx, eax
  317.         xor     eax, eax
  318.         xor     ebx, ebx
  319.         mov     al, [edi+2]
  320.         mov     bl, [esi+2]
  321.         mul     ebx
  322.         shr     eax, 8
  323.         add     ecx, eax
  324.         pop     eax
  325.         pop     edx
  326.         pop     ebx
  327.         pop     eax
  328.         ret
  329.  
  330. ;-----------------------------------------------------------------------------
  331.  
  332. align 4
  333. check_mouse_area_for_getpixel:
  334. ; in:
  335. ; eax = x
  336. ; ebx = y
  337. ; out:
  338. ; ecx = new color
  339.         push    eax ebx
  340. ; check for Y
  341.         xor     ecx, ecx
  342.         mov     cx, [Y_UNDER]   ; [MOUSE_Y]
  343.  
  344.         cmp     ebx, ecx
  345.         jb      .no_mouse_area
  346.         add     ecx, 23         ; mouse cursor Y size
  347.         cmp     ebx, ecx
  348.         ja      .no_mouse_area
  349. ; offset Y
  350.         sub     bx, [Y_UNDER]   ; [MOUSE_Y]
  351. ;--------------------------------------
  352. ; check for X
  353.         xor     ecx, ecx
  354.         mov     cx, [X_UNDER]   ; [MOUSE_X]
  355.         cmp     eax, ecx
  356.         jb      .no_mouse_area
  357.         add     ecx, 15         ; mouse cursor X size
  358.         cmp     eax, ecx
  359.         ja      .no_mouse_area
  360. ; offset X
  361.         sub     ax, [X_UNDER]   ; [MOUSE_X]
  362. ;--------------------------------------
  363. ; eax = offset x
  364. ; ebx = offset y
  365.         shl     ebx, 6  ;y
  366.         shl     eax, 2  ;x
  367.         add     eax, ebx
  368.         add     eax, mouseunder
  369.         mov     ecx, [eax]
  370.         and     ecx, 0xffffff
  371.         or      ecx, 0xff000000
  372.         pop     ebx eax
  373.         ret
  374.  
  375.   .no_mouse_area:
  376.         xor     ecx, ecx
  377.         pop     ebx eax
  378.         ret
  379.  
  380. ;-----------------------------------------------------------------------------
  381.  
  382. align 4
  383. check_mouse_area_for_putpixel:
  384. ; in:
  385. ; ecx = x shl 16 + y
  386. ; eax = color
  387. ; out:
  388. ; eax = new color
  389.         push    eax
  390. ; check for Y
  391.         mov     ax, [Y_UNDER]   ; [MOUSE_Y]
  392.         cmp     cx, ax
  393.         jb      .no_mouse_area
  394.         add     ax, 23          ; mouse cursor Y size
  395.         cmp     cx, ax
  396.         ja      .no_mouse_area
  397. ; offset Y
  398.         sub     cx, [Y_UNDER]   ; [MOUSE_Y]
  399.         mov     ax, cx
  400.         shl     eax, 16
  401.  
  402. ; check for X
  403.         mov     ax, [X_UNDER]   ; [MOUSE_X]
  404.         shr     ecx, 16
  405.         cmp     cx, ax
  406.         jb      .no_mouse_area
  407.         add     ax, 15          ; mouse cursor X size
  408.         cmp     cx, ax
  409.         ja      .no_mouse_area
  410. ; offset X
  411.         sub     cx, [X_UNDER]   ; [MOUSE_X]
  412.         mov     ax, cx
  413.  
  414. ; eax = (offset y) shl 16 + (offset x)
  415.  
  416.         pop     ecx
  417.  
  418.         push    eax ebx
  419.  
  420.         mov     ebx, eax
  421.         shr     ebx, 16         ; y
  422.         and     eax, 0xffff     ; x
  423.  
  424.         shl     ebx, 6
  425.         shl     eax, 2
  426.         add     eax, ebx
  427.         add     eax, mouseunder
  428.         and     ecx, 0xFFFFFF
  429.         mov     [eax], ecx
  430.  
  431.         pop     ebx eax
  432.  
  433.         push    esi edi
  434.         rol     eax, 16
  435.         movzx   edi, ax         ; y cycle
  436.         shl     edi, 4          ; *16 bytes per row
  437.         shr     eax, 16
  438.         add     edi, eax        ; x cycle
  439.         lea     edi, [edi*3]
  440.         add     edi, [MOUSE_PICTURE]    ; we have our str address
  441.         mov     esi, edi
  442.         add     esi, 16*24*3
  443.         call    combine_colors
  444.         pop     edi esi
  445.         mov     eax, ecx
  446.         ret
  447.  
  448.   .no_mouse_area:
  449.         pop     eax
  450.         ret
  451.  
  452. ;-----------------------------------------------------------------------------
  453.  
  454. align 4
  455. __sys_draw_pointer:
  456.         pushad
  457.         movzx   ecx, word [X_UNDER]
  458.         movzx   edx, word [Y_UNDER]
  459.         movzx   ebx, word [MOUSE_Y]
  460.         movzx   eax, word [MOUSE_X]
  461.         cmp     [redrawmouse_unconditional], 0
  462.         je      @f
  463.         mov     [redrawmouse_unconditional], 0
  464.         jmp     redrawmouse
  465.   @@:
  466.         cmp     eax, ecx
  467.         jne     redrawmouse
  468.         cmp     ebx, edx
  469.         je      nodmp
  470.  
  471. ;--------------------------------------
  472.  
  473. align 4
  474. redrawmouse:
  475.         pushfd
  476.         cli
  477.         call    draw_mouse_under
  478.         call    save_draw_mouse
  479.  
  480. ;        mov     eax, [_display.select_cursor]
  481. ;        test    eax, eax
  482. ;        jz      @f
  483.         cmp     [_display.select_cursor], select_cursor
  484.         jne     @f
  485.  
  486.         xor     eax, eax
  487.         mov     esi, [current_cursor]
  488.  
  489.         mov     ax, [Y_UNDER]
  490.         sub     eax, [esi + CURSOR.hot_y]
  491.         mov     [Y_UNDER_subtraction_CUR_hot_y], ax
  492.         add     eax, [cur.h]
  493.         mov     [Y_UNDER_sub_CUR_hot_y_add_curh], ax
  494.  
  495.         mov     ax, [X_UNDER]
  496.         sub     eax, [esi + CURSOR.hot_x]
  497.         mov     [X_UNDER_subtraction_CUR_hot_x], ax
  498.         add     eax, [cur.w]
  499.         mov     [X_UNDER_sub_CUR_hot_x_add_curh], ax
  500.   @@:
  501.         popfd
  502.   nodmp:
  503.         popad
  504.         ret
  505.  
  506. ;-----------------------------------------------------------------------------
  507.  
  508. align 4
  509. proc set_mouse_data stdcall uses ecx edx, BtnState:dword, XMoving:dword, YMoving:dword, VScroll:dword, HScroll:dword
  510.  
  511.         mov     eax, [BtnState]
  512.         and     eax, 0x3FFFFFFF         ; Top 2 bits are used to flag absolute movements
  513.         mov     [BTN_DOWN], eax
  514. ;--------------------------------------
  515.         mov     eax, [XMoving]
  516.         test    [BtnState], 0x80000000
  517.         jnz     .absolute_x
  518.         test    eax, eax
  519.         jz      @f
  520.         call    mouse_acceleration
  521.         add     ax, [MOUSE_X]
  522.         jns     .check_x
  523.         xor     eax, eax
  524.         jmp     .set_x
  525.  .absolute_x:
  526.         mov     edx, [_display.width]
  527.         mul     edx
  528.         shr     eax, 15
  529.  .check_x:
  530.         cmp     ax, word[_display.width]
  531.         jl      .set_x
  532.         mov     ax, word[_display.width]
  533.         dec     ax
  534.  .set_x:
  535.         mov     [MOUSE_X], ax
  536. ;--------------------------------------
  537. @@:
  538.         mov     eax, [YMoving]
  539.         test    [BtnState], 0x40000000
  540.         jnz     .absolute_y
  541.         test    eax, eax
  542.         jz      @f
  543.         neg     eax
  544.         call    mouse_acceleration
  545.         add     ax, [MOUSE_Y]
  546.         jns     .check_y
  547.         xor     eax, eax
  548.         jmp     .set_y
  549.  .absolute_y:
  550.         mov     edx, [_display.height]
  551.         mul     edx
  552.         shr     eax, 15
  553.  .check_y:
  554.         cmp     ax, word[_display.height]
  555.         jl      .set_y
  556.         mov     ax, word[_display.height]
  557.         dec     ax
  558.  .set_y:
  559.         mov     [MOUSE_Y], ax
  560. ;--------------------------------------
  561. @@:
  562.         mov     eax, [VScroll]
  563.         test    eax, eax
  564.         jz      @f
  565.         add     [MOUSE_SCROLL_V], ax
  566.         bts     word [BTN_DOWN], 15
  567. @@:
  568.         mov     eax, [HScroll]
  569.         test    eax, eax
  570.         jz      @f
  571.         add     [MOUSE_SCROLL_H], ax
  572.         bts     dword [BTN_DOWN], 23
  573. @@:
  574.         mov     [mouse_active], 1
  575.         call    wakeup_osloop
  576.         ret
  577. endp
  578.  
  579. ;-----------------------------------------------------------------------------
  580. mouse_acceleration:
  581.         neg     ax
  582.         jl      mouse_acceleration
  583.         add     al, [mouse_delay]
  584.         mul     al
  585.         mov     cx, [mouse_speed_factor]
  586.         dec     ax
  587.         shr     ax, cl
  588.         inc     ax
  589.         test    eax, eax
  590.         jns     @f
  591.         neg     ax
  592. @@:
  593.         ret
  594.