Subversion Repositories Kolibri OS

Rev

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

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