Subversion Repositories Kolibri OS

Rev

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

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