Subversion Repositories Kolibri OS

Rev

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

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