Subversion Repositories Kolibri OS

Rev

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