Subversion Repositories Kolibri OS

Rev

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