Subversion Repositories Kolibri OS

Rev

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