Subversion Repositories Kolibri OS

Rev

Rev 9715 | Rev 9850 | 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: 9848 $
  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.         xor     ecx, ecx
  91.         inc     edx
  92.         cmp     edx, 24
  93.         jnz     mres
  94.         popad
  95.         ret
  96.  
  97. ;-----------------------------------------------------------------------------
  98.  
  99. align 4
  100. save_draw_mouse:
  101.         cmp     [_display.move_cursor], 0
  102.         je      .no_hw_cursor
  103.         pushad
  104.  
  105.         mov     [X_UNDER], ax
  106.         mov     [Y_UNDER], bx
  107.         movzx   eax, word [MOUSE_Y]
  108.         movzx   ebx, word [MOUSE_X]
  109.         push    eax
  110.         push    ebx
  111.  
  112. ;        mov     ecx, [Screen_Max_X]
  113. ;        inc     ecx
  114. ;        mul     ecx
  115.         mov     eax, [d_width_calc_area + eax*4]
  116.  
  117.         add     eax, [_display.win_map]
  118.         movzx   edx, byte [ebx + eax]
  119.         shl     edx, BSF sizeof.APPDATA
  120.         ; edx - thread slot of window under cursor
  121.         mov     esi, [SLOT_BASE + edx + APPDATA.cursor] ; cursor of window under cursor
  122.  
  123.         ; if cursor of window under cursor already equal to the
  124.         ; current_cursor then just draw it
  125.         cmp     esi, [current_cursor]
  126.         je      .draw
  127.  
  128.         ; eax = thread slot of current active window
  129.         mov     eax, [thread_count]
  130.         movzx   eax, word [WIN_POS + eax*2]
  131.         shl     eax, BSF sizeof.APPDATA
  132.  
  133.         ; window under cursor == active window ?
  134.         cmp     eax, edx
  135.         je      @F ; if yes then just draw cursor of app
  136.  
  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      .set_def_cursor ; if active window is not being resized now
  141.  
  142.         ; esi = cursor of active window:
  143.         mov     esi, [SLOT_BASE + eax + APPDATA.cursor]
  144.         jmp     .draw
  145.  
  146. .set_def_cursor:
  147.         mov     esi, [def_cursor]
  148.         cmp     esi, [current_cursor]
  149.         je      .draw
  150.  
  151. @@:
  152.         push    esi
  153.         call    [_display.select_cursor]
  154.         mov     [current_cursor], esi
  155. ;--------------------------------------
  156. align 4
  157. .draw:
  158.         stdcall [_display.move_cursor], esi
  159.         popad
  160.         ret
  161. ;--------------------------------------
  162. ;align 4
  163. ;.fail:
  164. ;        mov     ecx, [def_cursor]
  165. ;        mov     [edx+SLOT_BASE+APPDATA.cursor], ecx
  166. ;        stdcall [_display.move_cursor], ecx        ; stdcall: [esp]=ebx,eax
  167. ;        popad
  168. ;        ret
  169. ;--------------------------------------
  170. align 4
  171. .no_hw_cursor:
  172.         pushad
  173.         ; save & draw
  174.         mov     [X_UNDER], ax
  175.         mov     [Y_UNDER], bx
  176.         push    eax
  177.         push    ebx
  178.         mov     ecx, 0
  179.         mov     edx, 0
  180. ;--------------------------------------
  181. align 4
  182. drm:
  183.         push    eax
  184.         push    ebx
  185.         push    ecx
  186.         push    edx
  187.         ; helloworld
  188.         push    ecx
  189.         add     eax, ecx        ; save picture under mouse
  190.         add     ebx, edx
  191.         push    ecx
  192.         or      ecx, 0x04000000 ; don't load to mouseunder area
  193.         push    eax ebx edx edi
  194.         call    [GETPIXEL]
  195.         pop     edi edx ebx eax
  196.         mov     [COLOR_TEMP], ecx
  197.         pop     ecx
  198.         mov     eax, edx
  199.         shl     eax, 6
  200.         shl     ecx, 2
  201.         add     eax, ecx
  202.         add     eax, mouseunder
  203.         mov     ebx, [COLOR_TEMP]
  204.         and     ebx, 0xffffff
  205.         mov     [eax], ebx
  206.         pop     ecx
  207.         mov     edi, edx        ; y cycle
  208.         shl     edi, 4          ; *16 bytes per row
  209.         add     edi, ecx        ; x cycle
  210.         mov     esi, edi
  211.         add     edi, esi
  212.         add     edi, esi        ; *3
  213.         add     edi, [MOUSE_PICTURE]    ; we have our str address
  214.         mov     esi, edi
  215.         add     esi, 16*24*3
  216.         push    ecx
  217.         mov     ecx, [COLOR_TEMP]
  218.         call    combine_colors
  219.         and     ecx, 0xffffff
  220.         mov     [MOUSE_COLOR_MEM], ecx
  221.         pop     ecx
  222.         pop     edx
  223.         pop     ecx
  224.         pop     ebx
  225.         pop     eax
  226.         add     eax, ecx        ; we have x coord+cycle
  227.         add     ebx, edx        ; and y coord+cycle
  228.         push    ecx
  229.         mov     ecx, [MOUSE_COLOR_MEM]
  230.         mov     edi, 1 ; force
  231.         or      ecx, 0x04000000 ; don't save to mouseunder area
  232. ;        call    [putpixel]
  233.         call    __sys_putpixel
  234.         pop     ecx
  235.         mov     ebx, [esp+0]    ; pure y coord again
  236.         mov     eax, [esp+4]    ; and x
  237.         inc     ecx             ; +1 cycle
  238.         cmp     ecx, 16         ; if more than 16
  239.         jnz     drm
  240.         xor     ecx, ecx
  241.         inc     edx
  242.         cmp     edx, 24
  243.         jnz     drm
  244.         add     esp, 8
  245.         popad
  246.         ret
  247.  
  248. ;-----------------------------------------------------------------------------
  249.  
  250. align 4
  251. combine_colors:
  252.       ; in
  253.       ; ecx - color ( 00 RR GG BB )
  254.       ; edi - ref to new color byte
  255.       ; esi - ref to alpha byte
  256.       ;
  257.       ; out
  258.       ; ecx - new color ( roughly (ecx*[esi]>>8)+([edi]*[esi]>>8) )
  259.         push    eax
  260.         push    ebx
  261.         push    edx
  262.         push    ecx
  263.         xor     ecx, ecx
  264.          ; byte 0
  265.         mov     eax, 0xff
  266.         sub     al, [esi+0]
  267.         mov     ebx, [esp]
  268.         shr     ebx, 16
  269.         and     ebx, 0xff
  270.         mul     ebx
  271.         shr     eax, 8
  272.         add     ecx, eax
  273.         xor     eax, eax
  274.         xor     ebx, ebx
  275.         mov     al, [edi+0]
  276.         mov     bl, [esi+0]
  277.         mul     ebx
  278.         shr     eax, 8
  279.         add     ecx, eax
  280.         shl     ecx, 8
  281.          ; byte 1
  282.         mov     eax, 0xff
  283.         sub     al, [esi+1]
  284.         mov     ebx, [esp]
  285.         shr     ebx, 8
  286.         and     ebx, 0xff
  287.         mul     ebx
  288.         shr     eax, 8
  289.         add     ecx, eax
  290.         xor     eax, eax
  291.         xor     ebx, ebx
  292.         mov     al, [edi+1]
  293.         mov     bl, [esi+1]
  294.         mul     ebx
  295.         shr     eax, 8
  296.         add     ecx, eax
  297.         shl     ecx, 8
  298.          ; byte 2
  299.         mov     eax, 0xff
  300.         sub     al, [esi+2]
  301.         mov     ebx, [esp]
  302.         and     ebx, 0xff
  303.         mul     ebx
  304.         shr     eax, 8
  305.         add     ecx, eax
  306.         xor     eax, eax
  307.         xor     ebx, ebx
  308.         mov     al, [edi+2]
  309.         mov     bl, [esi+2]
  310.         mul     ebx
  311.         shr     eax, 8
  312.         add     ecx, eax
  313.         pop     eax
  314.         pop     edx
  315.         pop     ebx
  316.         pop     eax
  317.         ret
  318.  
  319. ;-----------------------------------------------------------------------------
  320.  
  321. align 4
  322. check_mouse_area_for_getpixel:
  323. ; in:
  324. ; eax = x
  325. ; ebx = y
  326. ; out:
  327. ; ecx = new color
  328.         push    eax ebx
  329. ; check for Y
  330.         xor     ecx, ecx
  331.         mov     cx, [Y_UNDER]   ; [MOUSE_Y]
  332.  
  333.         cmp     ebx, ecx
  334.         jb      .no_mouse_area
  335.         add     ecx, 23         ; mouse cursor Y size
  336.         cmp     ebx, ecx
  337.         ja      .no_mouse_area
  338. ; offset Y
  339.         sub     bx, [Y_UNDER]   ; [MOUSE_Y]
  340. ;--------------------------------------
  341. ; check for X
  342.         xor     ecx, ecx
  343.         mov     cx, [X_UNDER]   ; [MOUSE_X]
  344.         cmp     eax, ecx
  345.         jb      .no_mouse_area
  346.         add     ecx, 15         ; mouse cursor X size
  347.         cmp     eax, ecx
  348.         ja      .no_mouse_area
  349. ; offset X
  350.         sub     ax, [X_UNDER]   ; [MOUSE_X]
  351. ;--------------------------------------
  352. ; eax = offset x
  353. ; ebx = offset y
  354.         shl     ebx, 6  ;y
  355.         shl     eax, 2  ;x
  356.         add     eax, ebx
  357.         add     eax, mouseunder
  358.         mov     ecx, [eax]
  359.         and     ecx, 0xffffff
  360.         or      ecx, 0xff000000
  361.         pop     ebx eax
  362.         ret
  363.  
  364.   .no_mouse_area:
  365.         xor     ecx, ecx
  366.         pop     ebx eax
  367.         ret
  368.  
  369. ;-----------------------------------------------------------------------------
  370.  
  371. align 4
  372. check_mouse_area_for_putpixel:
  373. ; in:
  374. ; ecx = x shl 16 + y
  375. ; eax = color
  376. ; out:
  377. ; eax = new color
  378.         push    eax
  379. ; check for Y
  380.         mov     ax, [Y_UNDER]   ; [MOUSE_Y]
  381.         cmp     cx, ax
  382.         jb      .no_mouse_area
  383.         add     ax, 23          ; mouse cursor Y size
  384.         cmp     cx, ax
  385.         ja      .no_mouse_area
  386. ; offset Y
  387.         sub     cx, [Y_UNDER]   ; [MOUSE_Y]
  388.         mov     ax, cx
  389.         shl     eax, 16
  390.  
  391. ; check for X
  392.         mov     ax, [X_UNDER]   ; [MOUSE_X]
  393.         shr     ecx, 16
  394.         cmp     cx, ax
  395.         jb      .no_mouse_area
  396.         add     ax, 15          ; mouse cursor X size
  397.         cmp     cx, ax
  398.         ja      .no_mouse_area
  399. ; offset X
  400.         sub     cx, [X_UNDER]   ; [MOUSE_X]
  401.         mov     ax, cx
  402.  
  403. ; eax = (offset y) shl 16 + (offset x)
  404.  
  405.         pop     ecx
  406.  
  407.         push    eax ebx
  408.  
  409.         mov     ebx, eax
  410.         shr     ebx, 16         ; y
  411.         and     eax, 0xffff     ; x
  412.  
  413.         shl     ebx, 6
  414.         shl     eax, 2
  415.         add     eax, ebx
  416.         add     eax, mouseunder
  417.         and     ecx, 0xFFFFFF
  418.         mov     [eax], ecx
  419.  
  420.         pop     ebx eax
  421.  
  422.         push    esi edi
  423.         rol     eax, 16
  424.         movzx   edi, ax         ; y cycle
  425.         shl     edi, 4          ; *16 bytes per row
  426.         shr     eax, 16
  427.         add     edi, eax        ; x cycle
  428.         lea     edi, [edi*3]
  429.         add     edi, [MOUSE_PICTURE]    ; we have our str address
  430.         mov     esi, edi
  431.         add     esi, 16*24*3
  432.         call    combine_colors
  433.         pop     edi esi
  434.         mov     eax, ecx
  435.         ret
  436.  
  437.   .no_mouse_area:
  438.         pop     eax
  439.         ret
  440.  
  441. ;-----------------------------------------------------------------------------
  442.  
  443. align 4
  444. __sys_draw_pointer:
  445.         pushad
  446.         movzx   ecx, word [X_UNDER]
  447.         movzx   edx, word [Y_UNDER]
  448.         movzx   ebx, word [MOUSE_Y]
  449.         movzx   eax, word [MOUSE_X]
  450.         cmp     [redrawmouse_unconditional], 0
  451.         je      @f
  452.         mov     [redrawmouse_unconditional], 0
  453.         jmp     redrawmouse
  454.   @@:
  455.         cmp     eax, ecx
  456.         jne     redrawmouse
  457.         cmp     ebx, edx
  458.         je      nodmp
  459.  
  460. ;--------------------------------------
  461.  
  462. align 4
  463. redrawmouse:
  464.         pushfd
  465.         cli
  466.         call    draw_mouse_under
  467.         call    save_draw_mouse
  468.  
  469. ;        mov     eax, [_display.select_cursor]
  470. ;        test    eax, eax
  471. ;        jz      @f
  472.         cmp     [_display.select_cursor], select_cursor
  473.         jne     @f
  474.  
  475.         xor     eax, eax
  476.         mov     esi, [current_cursor]
  477.  
  478.         mov     ax, [Y_UNDER]
  479.         sub     eax, [esi + CURSOR.hot_y]
  480.         mov     [Y_UNDER_subtraction_CUR_hot_y], ax
  481.         add     eax, [cur.h]
  482.         mov     [Y_UNDER_sub_CUR_hot_y_add_curh], ax
  483.  
  484.         mov     ax, [X_UNDER]
  485.         sub     eax, [esi + CURSOR.hot_x]
  486.         mov     [X_UNDER_subtraction_CUR_hot_x], ax
  487.         add     eax, [cur.w]
  488.         mov     [X_UNDER_sub_CUR_hot_x_add_curh], ax
  489.   @@:
  490.         popfd
  491.   nodmp:
  492.         popad
  493.         ret
  494.  
  495. ;-----------------------------------------------------------------------------
  496.  
  497. align 4
  498. proc set_mouse_data stdcall uses ecx edx, BtnState:dword, XMoving:dword, YMoving:dword, VScroll:dword, HScroll:dword
  499.  
  500.         mov     eax, [BtnState]
  501.         and     eax, 0x3FFFFFFF         ; Top 2 bits are used to flag absolute movements
  502.         mov     [BTN_DOWN], eax
  503. ;--------------------------------------
  504.         mov     eax, [XMoving]
  505.         test    [BtnState], 0x80000000
  506.         jnz     .absolute_x
  507.         test    eax, eax
  508.         jz      @f
  509.         call    mouse_acceleration
  510.         add     ax, [MOUSE_X]
  511.         jns     .check_x
  512.         xor     eax, eax
  513.         jmp     .set_x
  514.  .absolute_x:
  515.         mov     edx, [_display.width]
  516.         mul     edx
  517.         shr     eax, 15
  518.  .check_x:
  519.         cmp     ax, word[_display.width]
  520.         jl      .set_x
  521.         mov     ax, word[_display.width]
  522.         dec     ax
  523.  .set_x:
  524.         mov     [MOUSE_X], ax
  525. ;--------------------------------------
  526. @@:
  527.         mov     eax, [YMoving]
  528.         test    [BtnState], 0x40000000
  529.         jnz     .absolute_y
  530.         test    eax, eax
  531.         jz      @f
  532.         neg     eax
  533.         call    mouse_acceleration
  534.         add     ax, [MOUSE_Y]
  535.         jns     .check_y
  536.         xor     eax, eax
  537.         jmp     .set_y
  538.  .absolute_y:
  539.         mov     edx, [_display.height]
  540.         mul     edx
  541.         shr     eax, 15
  542.  .check_y:
  543.         cmp     ax, word[_display.height]
  544.         jl      .set_y
  545.         mov     ax, word[_display.height]
  546.         dec     ax
  547.  .set_y:
  548.         mov     [MOUSE_Y], ax
  549. ;--------------------------------------
  550. @@:
  551.         mov     eax, [VScroll]
  552.         test    eax, eax
  553.         jz      @f
  554.         add     [MOUSE_SCROLL_V], ax
  555.         bts     word [BTN_DOWN], 15
  556. @@:
  557.         mov     eax, [HScroll]
  558.         test    eax, eax
  559.         jz      @f
  560.         add     [MOUSE_SCROLL_H], ax
  561.         bts     dword [BTN_DOWN], 23
  562. @@:
  563.         mov     [mouse_active], 1
  564.         call    wakeup_osloop
  565.         ret
  566. endp
  567.  
  568. ;-----------------------------------------------------------------------------
  569. mouse_acceleration:
  570.         neg     ax
  571.         jl      mouse_acceleration
  572.         add     al, [mouse_delay]
  573.         mul     al
  574.         mov     cx, [mouse_speed_factor]
  575.         dec     ax
  576.         shr     ax, cl
  577.         inc     ax
  578.         test    eax, eax
  579.         jns     @f
  580.         neg     ax
  581. @@:
  582.         ret
  583.