Subversion Repositories Kolibri OS

Rev

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