Subversion Repositories Kolibri OS

Rev

Rev 753 | Rev 802 | 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: 769 $
  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.         je .no_hw_cursor
  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, [Screen_Max_X]
  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, [current_cursor]
  120.         je .draw
  121.  
  122.         cmp [ecx+CURSOR.magic], 'CURS'
  123.         jne .fail
  124.  
  125.         push ecx
  126.         call [select_hw_cursor]
  127.         mov [current_cursor], ecx
  128.  
  129. ;        cmp [ecx+CURSOR.size], CURSOR_SIZE
  130. ;        jne .fail
  131.  
  132. .draw:
  133.         stdcall [set_hw_cursor], ecx
  134.         popad
  135.         ret
  136. .fail:
  137.         mov ecx, [def_cursor]
  138.         mov [edx+SLOT_BASE+APPDATA.cursor], ecx
  139.         stdcall [set_hw_cursor], ecx
  140.         popad
  141.         ret
  142.  
  143. .no_hw_cursor:
  144.         pushad
  145.         ; save & draw
  146.         mov    [X_UNDER],ax
  147.         mov    [Y_UNDER],bx
  148.         push   eax
  149.         push   ebx
  150.         mov    ecx,0
  151.         mov    edx,0
  152.         align  4
  153. drm:
  154.         push   eax
  155.         push   ebx
  156.         push   ecx
  157.         push   edx
  158.         ; helloworld
  159.         push  ecx
  160.         add    eax,ecx  ; save picture under mouse
  161.         add    ebx,edx
  162.         push   ecx
  163.         call   getpixel
  164.         mov    [COLOR_TEMP],ecx
  165.         pop    ecx
  166.         mov    eax,edx
  167.         shl    eax,6
  168.         shl    ecx,2
  169.         add    eax,ecx
  170.         add    eax,mouseunder
  171.         mov    ebx,[COLOR_TEMP]
  172.         mov    [eax],ebx
  173.         pop  ecx
  174.         mov    edi,edx       ; y cycle
  175.         shl    edi,4       ; *16 bytes per row
  176.         add    edi,ecx       ; x cycle
  177.         mov    esi, edi
  178.         add    edi, esi
  179.         add    edi, esi       ; *3
  180.         add    edi,[MOUSE_PICTURE]      ; we have our str address
  181.         mov    esi, edi
  182.         add    esi, 16*24*3
  183.         push   ecx
  184.         mov    ecx, [COLOR_TEMP]
  185.         call   combine_colors
  186.         mov    [MOUSE_COLOR_MEM], ecx
  187.         pop    ecx
  188.         pop    edx
  189.         pop    ecx
  190.         pop    ebx
  191.         pop    eax
  192.         add    eax,ecx       ; we have x coord+cycle
  193.         add    ebx,edx       ; and y coord+cycle
  194.         push   ecx
  195.         mov    ecx, [MOUSE_COLOR_MEM]
  196.         mov    edi, 1
  197.         call   [putpixel]
  198.         pop    ecx
  199.         mov    ebx,[esp+0]      ; pure y coord again
  200.         mov    eax,[esp+4]      ; and x
  201.         inc    ecx          ; +1 cycle
  202.         cmp    ecx,16       ; if more than 16
  203.         jnz    drm
  204.         xor    ecx, ecx
  205.         inc    edx
  206.         cmp    edx,24
  207.         jnz    drm
  208.         add   esp,8
  209.         popad
  210.         ret
  211.  
  212.  
  213. combine_colors:
  214.       ; in
  215.       ; ecx - color ( 00 RR GG BB )
  216.       ; edi - ref to new color byte
  217.       ; esi - ref to alpha byte
  218.       ;
  219.       ; out
  220.       ; ecx - new color ( roughly (ecx*[esi]>>8)+([edi]*[esi]>>8) )
  221.       push eax
  222.       push ebx
  223.       push edx
  224.       push ecx
  225.       xor ecx, ecx
  226.          ; byte 2
  227.       mov eax, 0xff
  228.       sub al, [esi+0]
  229.       mov ebx, [esp]
  230.       shr ebx, 16
  231.       and ebx, 0xff
  232.       mul ebx
  233.       shr eax, 8
  234.       add ecx, eax
  235.       xor eax, eax
  236.       xor ebx, ebx
  237.       mov al, [edi+0]
  238.       mov bl, [esi+0]
  239.       mul ebx
  240.       shr eax, 8
  241.       add ecx, eax
  242.       shl ecx, 8
  243.          ; byte 1
  244.       mov eax, 0xff
  245.       sub al, [esi+1]
  246.       mov ebx, [esp]
  247.       shr ebx, 8
  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+1]
  255.       mov bl, [esi+1]
  256.       mul ebx
  257.       shr eax, 8
  258.       add ecx, eax
  259.       shl ecx, 8
  260.          ; byte 2
  261.       mov eax, 0xff
  262.       sub al, [esi+2]
  263.       mov ebx, [esp]
  264.       and ebx, 0xff
  265.       mul ebx
  266.       shr eax, 8
  267.       add ecx, eax
  268.       xor eax, eax
  269.       xor ebx, ebx
  270.       mov al, [edi+2]
  271.       mov bl, [esi+2]
  272.       mul ebx
  273.       shr eax, 8
  274.       add ecx, eax
  275.       pop eax
  276.       pop edx
  277.       pop ebx
  278.       pop eax
  279.       ret
  280.  
  281.  
  282. __sys_disable_mouse:
  283.       cmp  dword [MOUSE_VISIBLE],dword 0
  284.       je    @f
  285.       ret
  286. @@:
  287.       pushad
  288.       cmp  [CURRENT_TASK],dword 1
  289.       je   disable_m
  290.       mov  edx,[CURRENT_TASK]
  291.       shl  edx,5
  292.       add  edx,window_data
  293.       movzx  eax, word [MOUSE_X]
  294.       movzx  ebx, word [MOUSE_Y]
  295.       mov  ecx,[Screen_Max_X]
  296.       inc  ecx
  297.       imul  ecx,ebx
  298.       add  ecx,eax
  299.       add  ecx, display_data
  300.       mov   eax, [CURRENT_TASK]
  301.       movzx ebx, byte [ecx]
  302.       cmp   eax,ebx
  303.       je    yes_mouse_disable
  304.       movzx ebx, byte [ecx+16]
  305.       cmp   eax,ebx
  306.       je    yes_mouse_disable
  307.       mov   ebx,[Screen_Max_X]
  308.       inc   ebx
  309.       imul  ebx,10
  310.       add   ecx,ebx
  311.       movzx ebx, byte [ecx]
  312.       cmp   eax,ebx
  313.       je    yes_mouse_disable
  314.       movzx ebx, byte [ecx+16]
  315.       cmp   eax,ebx
  316.       je    yes_mouse_disable
  317.       jmp   no_mouse_disable
  318. yes_mouse_disable:
  319.       mov  edx,[CURRENT_TASK]
  320.       shl  edx,5
  321.       add  edx,window_data
  322.       movzx  eax, word [MOUSE_X]
  323.       movzx  ebx, word [MOUSE_Y]
  324.       mov  ecx,[edx+0]   ; mouse inside the area ?
  325.       add  eax,10
  326.       cmp  eax,ecx
  327.       jb   no_mouse_disable
  328.       sub  eax,10
  329.       add  ecx,[edx+8]
  330.       cmp  eax,ecx
  331.       jg   no_mouse_disable
  332.       mov  ecx,[edx+4]
  333.       add  ebx,14
  334.       cmp  ebx,ecx
  335.       jb   no_mouse_disable
  336.       sub  ebx,14
  337.       add  ecx,[edx+12]
  338.       cmp  ebx,ecx
  339.       jg   no_mouse_disable
  340. disable_m:
  341.       cmp  dword [MOUSE_VISIBLE],dword 0
  342.       jne  no_mouse_disable
  343.       pushf
  344.       cli
  345.       call draw_mouse_under
  346.       popf
  347.       mov  [MOUSE_VISIBLE],dword 1
  348. no_mouse_disable:
  349.       popad
  350.       ret
  351.  
  352. __sys_draw_pointer:
  353.         cmp   [mouse_pause],0
  354.         je    @f
  355.         ret
  356. @@:
  357.         push   eax
  358.         mov     eax,[timer_ticks]
  359.         sub     eax,[MouseTickCounter]
  360.         cmp     eax,1
  361.         ja      @f
  362.         pop    eax
  363.         ret
  364. @@:
  365.         mov     eax,[timer_ticks]
  366.         mov     [MouseTickCounter],eax
  367.         pop     eax
  368.         pushad
  369.         cmp    dword [MOUSE_VISIBLE],dword 0  ; mouse visible ?
  370.         je     chms00
  371.         mov     [MOUSE_VISIBLE], dword 0
  372.         movzx  ebx,word [MOUSE_Y]
  373.         movzx  eax,word [MOUSE_X]
  374.         pushfd
  375.         cli
  376.         call   save_draw_mouse
  377.         popfd
  378. nodmu2:
  379.         popad
  380.         ret
  381. chms00:
  382.         movzx  ecx,word [X_UNDER]
  383.         movzx  edx,word [Y_UNDER]
  384.         movzx  ebx,word [MOUSE_Y]
  385.         movzx  eax,word [MOUSE_X]
  386.         cmp    eax,ecx
  387.         jne    redrawmouse
  388.         cmp    ebx,edx
  389.         jne    redrawmouse
  390.         jmp    nodmp
  391. redrawmouse:
  392.         pushfd
  393.         cli
  394.         call   draw_mouse_under
  395.         call   save_draw_mouse
  396.         popfd
  397. nodmp:
  398.         popad
  399.         ret
  400.  
  401. proc set_mouse_data stdcall, BtnState:dword, XMoving:dword, YMoving:dword, VScroll:dword, HScroll:dword
  402.  
  403.     mov  eax,[BtnState]
  404.     mov  [BTN_DOWN],eax
  405.  
  406.     mov  eax,[XMoving]
  407.     call mouse_acceleration
  408.     add  ax,[MOUSE_X]    ;[XCoordinate]
  409.     cmp  ax,0
  410.     jge  @@M1
  411.     mov  eax,0
  412.     jmp  @@M2
  413. @@M1:
  414.     cmp  ax,[Screen_Max_X]   ;ScreenLength
  415.     jl   @@M2
  416.     mov  ax,[Screen_Max_X]   ;ScreenLength-1
  417.  
  418. @@M2:
  419.     mov  [MOUSE_X],ax     ;[XCoordinate]
  420.  
  421.     mov  eax,[YMoving]
  422.     neg  eax
  423.     call mouse_acceleration
  424.  
  425.     add  ax,[MOUSE_Y]   ;[YCoordinate]
  426.     cmp  ax,0
  427.     jge  @@M3
  428.     mov  ax,0
  429.     jmp  @@M4
  430. @@M3:
  431.     cmp  ax,[Screen_Max_Y]  ;ScreenHeigth
  432.     jl   @@M4
  433.     mov  ax,[Screen_Max_Y] ;ScreenHeigth-1
  434.  
  435. @@M4:
  436.     mov  [MOUSE_Y],ax     ;[YCoordinate]
  437.  
  438.     mov  eax,[VScroll]
  439.     add  [MOUSE_SCROLL_V],ax
  440.  
  441.     mov  eax,[HScroll]
  442.     add  [MOUSE_SCROLL_H],ax
  443.  
  444.     mov  [mouse_active],1
  445.     mov  eax,[timer_ticks]
  446.     mov  [mouse_timer_ticks],eax
  447.     ret
  448. endp
  449.  
  450. mouse_acceleration:
  451.         push  eax
  452.         mov   eax,[timer_ticks]
  453.         sub   eax,[mouse_timer_ticks]
  454.         cmp   eax,[mouse_delay]
  455.         pop   eax
  456.         ja    @f
  457.         ;push  edx
  458.         imul  eax,[mouse_speed_factor]
  459.         ;pop   edx
  460. @@:
  461.         ret
  462.  
  463.