Subversion Repositories Kolibri OS

Rev

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