Subversion Repositories Kolibri OS

Rev

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

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