Subversion Repositories Kolibri OS

Rev

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

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