Subversion Repositories Kolibri OS

Rev

Rev 1730 | Rev 2430 | 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: 2288 $
  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.   mousecount  dd  0x0
  26.   mousedata   dd  0x0
  27. endg
  28.  
  29. iglobal
  30. mouse_delay        dd 10
  31. mouse_speed_factor:
  32.                     dd 3
  33. mouse_timer_ticks  dd 0
  34. endg
  35.  
  36. ;include 'm_com.inc'
  37.  
  38.  
  39. ;test_mario79:
  40. ;        push   esi
  41. ;        push   eax
  42. ;        mov    [write_error_to],process_test_m79+43
  43. ;        movzx  eax,al  ;[DevErrorCode]
  44. ;        call   writehex
  45. ;        mov    esi,process_test_m79
  46. ;        call   sys_msg_board_str
  47. ;        pop    eax
  48. ;        pop    esi
  49. ;        ret
  50. ;process_test_m79 db 'K : Process - test Mario79 error    00000000',13,10,0
  51.  
  52. draw_mouse_under:
  53.         ; return old picture
  54.  
  55.         cmp     [_display.restore_cursor], 0
  56.         je      @F
  57.  
  58.         pushad
  59.         movzx   eax, word [X_UNDER]
  60.         movzx   ebx, word [Y_UNDER]
  61.         stdcall [_display.restore_cursor], eax, ebx
  62.         popad
  63.         ret
  64. @@:
  65.         pushad
  66.         xor     ecx, ecx
  67.         xor     edx, edx
  68.         align  4
  69. mres:
  70.         movzx   eax, word [X_UNDER]
  71.         movzx   ebx, word [Y_UNDER]
  72.         add     eax, ecx
  73.         add     ebx, edx
  74.         push    ecx
  75.         push    edx
  76.         push    eax
  77.         push    ebx
  78.         mov     eax, edx
  79.         shl     eax, 6
  80.         shl     ecx, 2
  81.         add     eax, ecx
  82.         add     eax, mouseunder
  83.         mov     ecx, [eax]
  84.         pop     ebx
  85.         pop     eax
  86.         mov     edi, 1;force
  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. save_draw_mouse:
  101.  
  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.         add     eax, [_WinMapAddress]
  117.         movzx   edx, byte [ebx+eax]
  118.         shl     edx, 8
  119.         mov     esi, [edx+SLOT_BASE+APPDATA.cursor]
  120.  
  121.         cmp     esi, [current_cursor]
  122.         je      .draw
  123.  
  124.         push    esi
  125.         call    [_display.select_cursor]
  126.         mov     [current_cursor], esi
  127. .draw:
  128.         stdcall [_display.move_cursor], esi
  129.         popad
  130.         ret
  131. .fail:
  132.         mov     ecx, [def_cursor]
  133.         mov     [edx+SLOT_BASE+APPDATA.cursor], ecx
  134.         stdcall [_display.move_cursor], ecx        ; stdcall: [esp]=ebx,eax
  135.         popad
  136.         ret
  137.  
  138. .no_hw_cursor:
  139.         pushad
  140.         ; save & draw
  141.         mov     [X_UNDER], ax
  142.         mov     [Y_UNDER], bx
  143.         push    eax
  144.         push    ebx
  145.         mov     ecx, 0
  146.         mov     edx, 0
  147.         align  4
  148. drm:
  149.         push    eax
  150.         push    ebx
  151.         push    ecx
  152.         push    edx
  153.         ; helloworld
  154.         push    ecx
  155.         add     eax, ecx; save picture under mouse
  156.         add     ebx, edx
  157.         push    ecx
  158.         call    getpixel
  159.         mov     [COLOR_TEMP], ecx
  160.         pop     ecx
  161.         mov     eax, edx
  162.         shl     eax, 6
  163.         shl     ecx, 2
  164.         add     eax, ecx
  165.         add     eax, mouseunder
  166.         mov     ebx, [COLOR_TEMP]
  167.         mov     [eax], ebx
  168.         pop     ecx
  169.         mov     edi, edx     ; y cycle
  170.         shl     edi, 4     ; *16 bytes per row
  171.         add     edi, ecx     ; x cycle
  172.         mov     esi, edi
  173.         add     edi, esi
  174.         add     edi, esi      ; *3
  175.         add     edi, [MOUSE_PICTURE]    ; we have our str address
  176.         mov     esi, edi
  177.         add     esi, 16*24*3
  178.         push    ecx
  179.         mov     ecx, [COLOR_TEMP]
  180.         call    combine_colors
  181.         mov     [MOUSE_COLOR_MEM], ecx
  182.         pop     ecx
  183.         pop     edx
  184.         pop     ecx
  185.         pop     ebx
  186.         pop     eax
  187.         add     eax, ecx     ; we have x coord+cycle
  188.         add     ebx, edx     ; and y coord+cycle
  189.         push    ecx
  190.         mov     ecx, [MOUSE_COLOR_MEM]
  191.         mov     edi, 1
  192.         call    [putpixel]
  193.         pop     ecx
  194.         mov     ebx, [esp+0]    ; pure y coord again
  195.         mov     eax, [esp+4]    ; and x
  196.         inc     ecx         ; +1 cycle
  197.         cmp     ecx, 16     ; if more than 16
  198.         jnz     drm
  199.         xor     ecx, ecx
  200.         inc     edx
  201.         cmp     edx, 24
  202.         jnz     drm
  203.         add     esp, 8
  204.         popad
  205.         ret
  206.  
  207.  
  208. combine_colors:
  209.       ; in
  210.       ; ecx - color ( 00 RR GG BB )
  211.       ; edi - ref to new color byte
  212.       ; esi - ref to alpha byte
  213.       ;
  214.       ; out
  215.       ; ecx - new color ( roughly (ecx*[esi]>>8)+([edi]*[esi]>>8) )
  216.         push    eax
  217.         push    ebx
  218.         push    edx
  219.         push    ecx
  220.         xor     ecx, ecx
  221.          ; byte 2
  222.         mov     eax, 0xff
  223.         sub     al, [esi+0]
  224.         mov     ebx, [esp]
  225.         shr     ebx, 16
  226.         and     ebx, 0xff
  227.         mul     ebx
  228.         shr     eax, 8
  229.         add     ecx, eax
  230.         xor     eax, eax
  231.         xor     ebx, ebx
  232.         mov     al, [edi+0]
  233.         mov     bl, [esi+0]
  234.         mul     ebx
  235.         shr     eax, 8
  236.         add     ecx, eax
  237.         shl     ecx, 8
  238.          ; byte 1
  239.         mov     eax, 0xff
  240.         sub     al, [esi+1]
  241.         mov     ebx, [esp]
  242.         shr     ebx, 8
  243.         and     ebx, 0xff
  244.         mul     ebx
  245.         shr     eax, 8
  246.         add     ecx, eax
  247.         xor     eax, eax
  248.         xor     ebx, ebx
  249.         mov     al, [edi+1]
  250.         mov     bl, [esi+1]
  251.         mul     ebx
  252.         shr     eax, 8
  253.         add     ecx, eax
  254.         shl     ecx, 8
  255.          ; byte 2
  256.         mov     eax, 0xff
  257.         sub     al, [esi+2]
  258.         mov     ebx, [esp]
  259.         and     ebx, 0xff
  260.         mul     ebx
  261.         shr     eax, 8
  262.         add     ecx, eax
  263.         xor     eax, eax
  264.         xor     ebx, ebx
  265.         mov     al, [edi+2]
  266.         mov     bl, [esi+2]
  267.         mul     ebx
  268.         shr     eax, 8
  269.         add     ecx, eax
  270.         pop     eax
  271.         pop     edx
  272.         pop     ebx
  273.         pop     eax
  274.         ret
  275.  
  276.  
  277. __sys_disable_mouse:
  278.         cmp     dword [MOUSE_VISIBLE], dword 0
  279.         je      @f
  280.         ret
  281. @@:
  282.         pushad
  283.         cmp     [CURRENT_TASK], dword 1
  284.         je      disable_m
  285.         mov     edx, [CURRENT_TASK]
  286.         shl     edx, 5
  287.         add     edx, window_data
  288.         movzx   eax, word [MOUSE_X]
  289.         movzx   ebx, word [MOUSE_Y]
  290.         mov     ecx, [Screen_Max_X]
  291.         inc     ecx
  292.         imul    ecx, ebx
  293.         add     ecx, eax
  294.         add     ecx, [_WinMapAddress]
  295.         mov     eax, [CURRENT_TASK]
  296.         cmp     al, [ecx]
  297.         je      yes_mouse_disable
  298.         cmp     al, [ecx+16]
  299.         je      yes_mouse_disable
  300.         add     ebx, 10
  301.         cmp     ebx, [Screen_Max_Y]
  302.         jae     no_mouse_disable
  303.         mov     ebx, [Screen_Max_X]
  304.         inc     ebx
  305.         imul    ebx, 10
  306.         add     ecx, ebx
  307.         cmp     al, [ecx]
  308.         je      yes_mouse_disable
  309.         cmp     al, [ecx+16]
  310.         je      yes_mouse_disable
  311.         jmp     no_mouse_disable
  312. yes_mouse_disable:
  313.         mov     edx, [CURRENT_TASK]
  314.         shl     edx, 5
  315.         add     edx, window_data
  316.         movzx   eax, word [MOUSE_X]
  317.         movzx   ebx, word [MOUSE_Y]
  318.         mov     ecx, [edx+0]; mouse inside the area ?
  319.         add     eax, 10
  320.         cmp     eax, ecx
  321.         jb      no_mouse_disable
  322.         sub     eax, 10
  323.         add     ecx, [edx+8]
  324.         cmp     eax, ecx
  325.         jg      no_mouse_disable
  326.         mov     ecx, [edx+4]
  327.         add     ebx, 14
  328.         cmp     ebx, ecx
  329.         jb      no_mouse_disable
  330.         sub     ebx, 14
  331.         add     ecx, [edx+12]
  332.         cmp     ebx, ecx
  333.         jg      no_mouse_disable
  334. disable_m:
  335.         cmp     dword [MOUSE_VISIBLE], dword 0
  336.         jne     no_mouse_disable
  337.         pushf
  338.         cli
  339.         call    draw_mouse_under
  340.         popf
  341.         mov     [MOUSE_VISIBLE], dword 1
  342. no_mouse_disable:
  343.         popad
  344.         ret
  345.  
  346. __sys_draw_pointer:
  347.         cmp     [mouse_pause], 0
  348.         je      @f
  349.         ret
  350. @@:
  351.         push    eax
  352.         mov     eax, [timer_ticks]
  353.         sub     eax, [MouseTickCounter]
  354.         cmp     eax, 1
  355.         ja      @f
  356.         pop     eax
  357.         ret
  358. @@:
  359.         mov     eax, [timer_ticks]
  360.         mov     [MouseTickCounter], eax
  361.         pop     eax
  362.         pushad
  363.         cmp     dword [MOUSE_VISIBLE], dword 0; mouse visible ?
  364.         je      chms00
  365.         mov     [MOUSE_VISIBLE], dword 0
  366.         movzx   ebx, word [MOUSE_Y]
  367.         movzx   eax, word [MOUSE_X]
  368.         pushfd
  369.         cli
  370.         call    save_draw_mouse
  371.         popfd
  372. nodmu2:
  373.         popad
  374.         ret
  375. chms00:
  376.         movzx   ecx, word [X_UNDER]
  377.         movzx   edx, word [Y_UNDER]
  378.         movzx   ebx, word [MOUSE_Y]
  379.         movzx   eax, word [MOUSE_X]
  380.         cmp     eax, ecx
  381.         jne     redrawmouse
  382.         cmp     ebx, edx
  383.         jne     redrawmouse
  384.         jmp     nodmp
  385. redrawmouse:
  386.         pushfd
  387.         cli
  388.         call    draw_mouse_under
  389.         call    save_draw_mouse
  390.         popfd
  391. nodmp:
  392.         popad
  393.         ret
  394.  
  395. proc set_mouse_data stdcall, BtnState:dword, XMoving:dword, YMoving:dword, VScroll:dword, HScroll:dword
  396.  
  397.         mov     eax, [BtnState]
  398.         mov     [BTN_DOWN], eax
  399.  
  400.         mov     eax, [XMoving]
  401.         call    mouse_acceleration
  402.         add     ax, [MOUSE_X];[XCoordinate]
  403.         cmp     ax, 0
  404.         jge     @@M1
  405.         mov     eax, 0
  406.         jmp     @@M2
  407. @@M1:
  408.         cmp     ax, [Screen_Max_X];ScreenLength
  409.         jl      @@M2
  410.         mov     ax, [Screen_Max_X];ScreenLength-1
  411.  
  412. @@M2:
  413.         mov     [MOUSE_X], ax;[XCoordinate]
  414.  
  415.         mov     eax, [YMoving]
  416.         neg     eax
  417.         call    mouse_acceleration
  418.  
  419.         add     ax, [MOUSE_Y];[YCoordinate]
  420.         cmp     ax, 0
  421.         jge     @@M3
  422.         mov     ax, 0
  423.         jmp     @@M4
  424. @@M3:
  425.         cmp     ax, [Screen_Max_Y];ScreenHeigth
  426.         jl      @@M4
  427.         mov     ax, [Screen_Max_Y];ScreenHeigth-1
  428.  
  429. @@M4:
  430.         mov     [MOUSE_Y], ax;[YCoordinate]
  431.  
  432.         mov     eax, [VScroll]
  433.         add     [MOUSE_SCROLL_V], ax
  434.  
  435.         mov     eax, [HScroll]
  436.         add     [MOUSE_SCROLL_H], ax
  437.  
  438.         mov     [mouse_active], 1
  439.         mov     eax, [timer_ticks]
  440.         mov     [mouse_timer_ticks], eax
  441.         ret
  442. endp
  443.  
  444. mouse_acceleration:
  445.         push    eax
  446.         mov     eax, [timer_ticks]
  447.         sub     eax, [mouse_timer_ticks]
  448.         cmp     eax, [mouse_delay]
  449.         pop     eax
  450.         ja      @f
  451.         ;push  edx
  452.         imul    eax, [mouse_speed_factor]
  453.         ;pop   edx
  454. @@:
  455.         ret
  456.  
  457.