Subversion Repositories Kolibri OS

Rev

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

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