Subversion Repositories Kolibri OS

Rev

Rev 427 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. $Revision: 425 $
  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. LOAD_FROM_FILE  equ 0
  10. LOAD_FROM_MEM   equ 1
  11. LOAD_INDIRECT   equ 2
  12. LOAD_SYSTEM     equ 3
  13. VIDEO_FREE      equ 2
  14.  
  15. struc BITMAPINFOHEADER {
  16.   .biSize          dd ? ; DWORD
  17.   .biWidth         dd ? ; LONG
  18.   .biHeight        dd ? ; LONG
  19.   .biPlanes        dw ? ; WORD
  20.   .biBitCount      dw ? ; WORD
  21.   .biCompression   dd ? ; DWORD
  22.   .biSizeImage     dd ? ; DWORD
  23.   .biXPelsPerMeter dd ? ; LONG
  24.   .biYPelsPerMeter dd ? ; LONG
  25.   .biClrUsed       dd ? ; DWORD
  26.   .biClrImportant  dd ? ; DWORD
  27. }
  28.  
  29. virtual at 0
  30.   BI BITMAPINFOHEADER
  31. end virtual
  32.  
  33. align 4
  34. proc vesa_init_cursor stdcall, dst:dword, src:dword
  35.            locals
  36.              rBase    dd ?
  37.              pQuad    dd ?
  38.              pBits    dd ?
  39.              pAnd     dd ?
  40.              width    dd ?
  41.              height   dd ?
  42.              counter  dd ?
  43.            endl
  44.  
  45.            mov esi, [src]
  46.            add esi,[esi+18]
  47.            mov eax,esi
  48.  
  49.            cmp [esi+BI.biBitCount], 24
  50.            je .img_24
  51.            cmp [esi+BI.biBitCount], 8
  52.            je .img_8
  53.            cmp [esi+BI.biBitCount], 4
  54.            je .img_4
  55.  
  56. .img_2:
  57.            add eax, [esi]
  58.            mov [pQuad],eax
  59.            add eax,8
  60.            mov [pBits],eax
  61.            add eax, 128
  62.            mov [pAnd],eax
  63.            mov eax,[esi+4]
  64.            mov [width],eax
  65.            mov ebx,[esi+8]
  66.            shr ebx,1
  67.            mov [height],ebx
  68.  
  69.            mov edi, [dst]
  70.            add edi, 32*31*4
  71.            mov [rBase],edi
  72.  
  73.            mov esi,[pQuad]
  74. .l21:
  75.            mov ebx, [pBits]
  76.            mov ebx, [ebx]
  77.            bswap ebx
  78.            mov eax, [pAnd]
  79.            mov eax, [eax]
  80.            bswap eax
  81.            mov [counter], 32
  82. @@:
  83.            xor edx, edx
  84.            shl eax,1
  85.            setc dl
  86.            dec edx
  87.  
  88.            xor ecx, ecx
  89.            shl ebx,1
  90.            setc cl
  91.            mov ecx, [esi+ecx*4]
  92.            and ecx, edx
  93.            and edx, 0xFF000000
  94.            or edx, ecx
  95.            mov [edi], edx
  96.  
  97.            add edi, 4
  98.            dec [counter]
  99.            jnz @B
  100.  
  101.            add [pBits], 4
  102.            add [pAnd], 4
  103.            mov edi,[rBase]
  104.            sub edi,128
  105.            mov [rBase],edi
  106.            sub [height],1
  107.            jnz .l21
  108.            ret
  109.  
  110. .img_4:
  111.            add eax, [esi]
  112.            mov [pQuad],eax
  113.            add eax,64
  114.            mov [pBits],eax
  115.            add eax, 0x200
  116.            mov [pAnd],eax
  117.            mov eax,[esi+4]
  118.            mov [width],eax
  119.            mov ebx,[esi+8]
  120.            shr ebx,1
  121.            mov [height],ebx
  122.  
  123.            mov edi, [dst]
  124.            add edi, 32*31*4
  125.            mov [rBase],edi
  126.  
  127.            mov esi,[pQuad]
  128.            mov ebx, [pBits]
  129. .l4:
  130.            mov eax, [pAnd]
  131.            mov eax, [eax]
  132.            bswap eax
  133.            mov [counter], 16
  134. @@:
  135.            xor edx, edx
  136.            shl eax,1
  137.            setc dl
  138.            dec edx
  139.  
  140.            movzx ecx, byte [ebx]
  141.            and cl, 0xF0
  142.            shr ecx, 2
  143.            mov ecx, [esi+ecx]
  144.            and ecx, edx
  145.            and edx, 0xFF000000
  146.            or edx, ecx
  147.            mov [edi], edx
  148.  
  149.            xor edx, edx
  150.            shl eax,1
  151.            setc dl
  152.            dec edx
  153.  
  154.            movzx ecx, byte [ebx]
  155.            and cl, 0x0F
  156.            mov ecx, [esi+ecx*4]
  157.            and ecx, edx
  158.            and edx, 0xFF000000
  159.            or edx, ecx
  160.            mov [edi+4], edx
  161.  
  162.            inc ebx
  163.            add edi, 8
  164.            dec [counter]
  165.            jnz @B
  166.  
  167.            add [pAnd], 4
  168.            mov edi,[rBase]
  169.            sub edi,128
  170.            mov [rBase],edi
  171.            sub [height],1
  172.            jnz .l4
  173.            ret
  174. .img_8:
  175.            add eax, [esi]
  176.            mov [pQuad],eax
  177.            add eax,1024
  178.            mov [pBits],eax
  179.            add eax, 1024
  180.            mov [pAnd],eax
  181.            mov eax,[esi+4]
  182.            mov [width],eax
  183.            mov ebx,[esi+8]
  184.            shr ebx,1
  185.            mov [height],ebx
  186.  
  187.            mov edi, [dst]
  188.            add edi, 32*31*4
  189.            mov [rBase],edi
  190.  
  191.            mov esi,[pQuad]
  192.            mov ebx, [pBits]
  193. .l81:
  194.            mov eax, [pAnd]
  195.            mov eax, [eax]
  196.            bswap eax
  197.            mov [counter], 32
  198. @@:
  199.            xor edx, edx
  200.            shl eax,1
  201.            setc dl
  202.            dec edx
  203.  
  204.            movzx ecx,  byte [ebx]
  205.            mov ecx, [esi+ecx*4]
  206.            and ecx, edx
  207.            and edx, 0xFF000000
  208.            or edx, ecx
  209.            mov [edi], edx
  210.  
  211.            inc ebx
  212.            add edi, 4
  213.            dec [counter]
  214.            jnz @B
  215.  
  216.            add [pAnd], 4
  217.            mov edi,[rBase]
  218.            sub edi,128
  219.            mov [rBase],edi
  220.            sub [height],1
  221.            jnz .l81
  222.            ret
  223. .img_24:
  224.            add eax, [esi]
  225.            mov [pQuad],eax
  226.            add eax, 0xC00
  227.            mov [pAnd],eax
  228.            mov eax,[esi+BI.biWidth]
  229.            mov [width],eax
  230.            mov ebx,[esi+BI.biHeight]
  231.            shr ebx,1
  232.            mov [height],ebx
  233.  
  234.            mov edi, [dst]
  235.            add edi, 32*31*4
  236.            mov [rBase],edi
  237.  
  238.            mov esi,[pAnd]
  239.            mov ebx, [pQuad]
  240. .row_24:
  241.            mov eax, [esi]
  242.            bswap eax
  243.            mov [counter], 32
  244. @@:
  245.            xor edx, edx
  246.            shl eax,1
  247.            setc dl
  248.            dec edx
  249.  
  250.            mov ecx, [ebx]
  251.            and ecx, 0x00FFFFFF
  252.            and ecx, edx
  253.            and edx, 0xFF000000
  254.            or edx, ecx
  255.            mov [edi], edx
  256.            add ebx, 3
  257.            add edi, 4
  258.            dec [counter]
  259.            jnz @B
  260.  
  261.            add esi, 4
  262.            mov edi,[rBase]
  263.            sub edi,128
  264.            mov [rBase],edi
  265.            sub [height],1
  266.            jnz .row_24
  267.            ret
  268. endp
  269.  
  270. align 4
  271. proc set_cursor stdcall, hcursor:dword
  272.            mov eax, [hcursor]
  273.            cmp [eax+CURSOR.magic], 'CURS'
  274.            jne .fail
  275. ;           cmp [eax+CURSOR.size], CURSOR_SIZE
  276. ;           jne .fail
  277.            mov ebx, [current_slot]
  278.            xchg eax, [ebx+APPDATA.cursor]
  279.            ret
  280. .fail:
  281.            mov eax, [def_cursor]
  282.            mov ebx, [current_slot]
  283.            xchg eax, [ebx+APPDATA.cursor]
  284.            ret
  285. endp
  286.  
  287. ; param
  288. ;  eax= pid
  289. ;  ebx= src
  290. ;  ecx= flags
  291.  
  292. vesa_cursor:
  293. .src     equ esp
  294. .flags   equ esp+4
  295. .hcursor equ esp+8
  296.  
  297.            sub esp, 4          ;space for .hcursor
  298.            push ecx
  299.            push ebx
  300.  
  301.            mov ebx, eax
  302.            mov eax, CURSOR_SIZE
  303.            call create_kernel_object
  304.            test eax, eax
  305.            jz .fail
  306.  
  307.            mov [.hcursor],eax
  308.  
  309.            xor ebx, ebx
  310.            mov [eax+CURSOR.magic], 'CURS'
  311.            mov [eax+CURSOR.destroy], destroy_cursor
  312.            mov [eax+CURSOR.hot_x], ebx
  313.            mov [eax+CURSOR.hot_y], ebx
  314.  
  315.            stdcall kernel_alloc, 0x1000
  316.            test eax, eax
  317.            jz .fail
  318.  
  319.            mov edi, [.hcursor]
  320.            mov [edi+CURSOR.base], eax
  321.  
  322.            mov esi, [.src]
  323.            mov ebx, [.flags]
  324.            cmp bx, LOAD_INDIRECT
  325.            je .indirect
  326.  
  327.            movzx ecx, word [esi+10]
  328.            movzx edx, word [esi+12]
  329.            mov [edi+CURSOR.hot_x], ecx
  330.            mov [edi+CURSOR.hot_y], edx
  331.  
  332.            stdcall vesa_init_cursor, eax, esi
  333.            mov eax, [.hcursor]
  334. .fail:
  335.            add esp, 12
  336.            ret
  337. .indirect:
  338.            shr ebx, 16
  339.            movzx ecx, bh
  340.            movzx edx, bl
  341.            mov [eax+CURSOR.hot_x], ecx
  342.            mov [eax+CURSOR.hot_y], edx
  343.  
  344.            xchg edi, eax
  345.            mov ecx, 1024
  346.            cld
  347.            rep movsd
  348.            add esp, 12
  349.            ret
  350.  
  351. align 4
  352. proc load_cursor stdcall, src:dword, flags:dword
  353.            locals
  354.              handle  dd ?
  355.            endl
  356.  
  357.            xor eax, eax
  358.            mov [handle], eax
  359.            cmp word [flags], LOAD_FROM_FILE
  360.            jne @F
  361.  
  362.            stdcall load_file, [src]
  363.            test eax, eax
  364.            jz .exit
  365.            mov [src], eax
  366. @@:
  367.            mov eax, [CURRENT_TASK]
  368.            shl eax, 5
  369.            mov eax, [CURRENT_TASK+eax+4]
  370.            mov ebx, [src]
  371.            mov ecx, [flags]
  372.            call [create_cursor]    ;eax, ebx, ecx
  373.            mov [handle], eax
  374. .fail:
  375.            cmp word [flags], LOAD_FROM_FILE
  376.            jne .exit
  377.            stdcall kernel_free, [src]
  378. .exit:
  379.            mov eax, [handle]
  380.            ret
  381. endp
  382.  
  383. align 4
  384. proc delete_cursor stdcall, hcursor:dword
  385.            locals
  386.              hsrv       dd ?
  387.              io_code    dd ?
  388.              input      dd ?
  389.              inp_size   dd ?
  390.              output     dd ?
  391.              out_size   dd ?
  392.            endl
  393.  
  394.            mov esi, [hcursor]
  395.            cmp [esi+CURSOR.magic], 'CURS'
  396.            jne .fail
  397. ;           cmp [esi+CURSOR.size], CURSOR_SIZE
  398. ;           jne .fail
  399.  
  400.            mov ebx, [CURRENT_TASK]
  401.            shl ebx, 5
  402.            mov ebx, [CURRENT_TASK+ebx+4]
  403.            cmp ebx, [esi+CURSOR.pid]
  404.            jne .fail
  405.  
  406.            mov ebx, [current_slot]
  407.            cmp esi, [ebx+APPDATA.cursor]
  408.            jne @F
  409.            mov eax, [def_cursor]
  410.            mov [ebx+APPDATA.cursor], eax
  411. @@:
  412.            mov eax, [hcursor]
  413.            call [eax+APPOBJ.destroy]
  414. .fail:
  415.            ret
  416. endp
  417.  
  418. ; param
  419. ;  eax= cursor
  420.  
  421. align 4
  422. destroy_cursor:
  423.  
  424.            push eax
  425.            stdcall kernel_free, [eax+CURSOR.base]
  426.            pop eax
  427.  
  428.            call destroy_kernel_object
  429.            ret
  430.  
  431. align 4
  432. proc init_cursors
  433.            cmp [SCR_MODE],word 0x13
  434.            jbe .fail
  435.  
  436.            movzx eax, byte [ScreenBPP]
  437.            mov ebx, [BytesPerScanLine]
  438.            cmp eax, 32
  439.            jne @F
  440.            sub ebx, 128
  441.            jmp .init
  442. @@:
  443.            cmp eax, 24
  444.            jne .fail
  445.            sub ebx, 96
  446. .init:
  447.            mov [cur_def_interl], ebx
  448.  
  449.            stdcall load_driver, szHwMouse
  450.            mov [hw_cursor], eax
  451.            test eax, eax
  452.            jz .sw_mouse
  453.  
  454.            stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM
  455.            mov [def_cursor], eax
  456.            ret
  457. .sw_mouse:
  458.            mov [create_cursor], vesa_cursor
  459.  
  460.            stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM
  461.            mov [def_cursor], eax
  462.  
  463.            mov ecx, [ScreenWidth]
  464.            mov edx, [ScreenHeight]
  465.            inc ecx
  466.            inc edx
  467.            mov [scr_width], ecx
  468.            mov [scr_height], edx
  469.  
  470.            movzx ebx, byte [ScreenBPP]
  471.            cmp ebx, 32
  472.            jne @F
  473.  
  474.            mov dword [set_hw_cursor], cursor_32
  475.            mov dword [hw_restore], restore_32
  476.            ret
  477. @@:
  478.            mov dword [set_hw_cursor], cursor_24
  479.            mov dword [hw_restore], restore_24
  480.            ret
  481. .fail:
  482.            xor eax, eax
  483.            mov dword [set_hw_cursor], eax
  484.            mov dword [hw_restore], eax
  485.            ret
  486. endp
  487.  
  488. align 4
  489. proc restore_24 stdcall, x:dword, y:dword
  490.            locals
  491.              w  dd ?
  492.            endl
  493.  
  494.            mov edi, [cur_saved_base]
  495.            mov edx, [cur_saved_h]
  496.            mov ebx, [cur_saved_interl]
  497.  
  498.            mov esi, cur_saved_data
  499. @@:
  500.            mov ecx, [cur_saved_w]
  501.            lea ecx, [ecx+ecx*2]
  502.            rep movsb
  503.            add edi, ebx
  504.            dec edx
  505.            jnz @B
  506.            ret
  507. endp
  508.  
  509. align 4
  510. proc restore_32 stdcall, x:dword, y:dword
  511.            locals
  512.              w  dd ?
  513.            endl
  514.  
  515.            mov edi, [cur_saved_base]
  516.            mov edx, [cur_saved_h]
  517.            mov ebx, [cur_saved_interl]
  518.  
  519.            mov esi, cur_saved_data
  520. @@:
  521.            mov ecx, [cur_saved_w]
  522.            rep movsd
  523.            add edi, ebx
  524.            dec edx
  525.            jnz @B
  526.            ret
  527. endp
  528.  
  529. align 4
  530. proc cursor_24 stdcall, hcursor:dword, x:dword, y:dword
  531.            locals
  532.              w      dd ?
  533.              h      dd ?
  534.              st     dd ?
  535.              _dx     dd ?
  536.              _dy     dd ?
  537.            endl
  538.  
  539.            mov esi, [hcursor]
  540.            mov ecx, [x]
  541.            mov eax, [y]
  542.            mov ebx, [BytesPerScanLine]
  543.  
  544.            xor edx, edx
  545.            sub ecx, [esi+CURSOR.hot_x]
  546.            mov [x], ecx
  547.            sets dl
  548.            dec edx
  549.            and ecx, edx       ;clip x to 0<=x
  550.            mov edi, ecx
  551.            sub edi, [x]
  552.            mov [_dx], edi
  553.  
  554.            xor edx, edx
  555.            sub eax, [esi+CURSOR.hot_y]
  556.            mov [y], eax
  557.            sets dl
  558.            dec edx
  559.            and eax, edx       ;clip y to 0<=y
  560.            mov edi, eax
  561.            sub edi, [y]
  562.            mov [_dy], edi
  563.  
  564.            mul ebx
  565.            lea esi, [ecx+ecx*2]
  566.            add esi, [LFBAddress]
  567.            add esi, eax
  568.            mov [cur_saved_base],esi
  569.  
  570.            mov edi, [scr_width]
  571.            mov edx, [scr_height]
  572.            mov eax, 32
  573.  
  574.            sub edi, ecx
  575.            cmp edi, eax
  576.            jng @F
  577.            mov edi, eax
  578. @@:
  579.            sub edi, [_dx]
  580.  
  581.            sub edx, [y]
  582.            cmp edx, eax
  583.            jng @F
  584.            mov edx, eax
  585. @@:
  586.            sub edx, [_dy]
  587.  
  588.            mov [w], edi
  589.            mov [h], edx
  590.            mov [cur_saved_w], edi
  591.            mov [cur_saved_h], edx
  592.  
  593.            sub eax, edi
  594.            shl eax, 2       ;lea eax, [eax+eax*2]
  595.            lea edi, [edi+edi*2]
  596.            sub ebx, edi
  597.            mov [cur_saved_interl], ebx
  598.  
  599.            mov edi, cur_saved_data
  600. @@:
  601.            mov ecx, [w]
  602.            lea ecx, [ecx+ecx*2]
  603.            rep movsb
  604.            add esi, ebx
  605.            dec edx
  606.            jnz @B
  607.  
  608. ;draw cursor
  609.            mov edx, eax
  610.            mov edi, [cur_saved_base]
  611.            mov eax, [_dy]
  612.            shl eax, 5
  613.            add eax, [_dx]
  614.            shl eax, 2
  615.  
  616.            mov esi, [hcursor]
  617.            mov esi, [esi+CURSOR.base]
  618.            add esi, eax
  619. .row:
  620.            mov ecx, [w]
  621. .pix:
  622.            lodsd
  623.            test eax, 0xFF000000
  624.            jz @F
  625.  
  626.            mov word [edi], ax
  627.            shr eax, 16
  628.            mov [edi+2],al
  629. @@:
  630.            add edi, 3
  631.            dec ecx
  632.            jnz .pix
  633.  
  634.            add esi, edx
  635.            add edi, ebx
  636.            dec [h]
  637.            jnz .row
  638.            ret
  639. endp
  640.  
  641. align 4
  642. proc cursor_32 stdcall, hcursor:dword, x:dword, y:dword
  643.            locals
  644.              w      dd ?
  645.              h      dd ?
  646.              st     dd ?
  647.              _dx     dd ?
  648.              _dy     dd ?
  649.            endl
  650.  
  651.            mov esi, [hcursor]
  652.            mov ecx, [x]
  653.            mov eax, [y]
  654.            mov ebx, [BytesPerScanLine]
  655.  
  656.            xor edx, edx
  657.            sub ecx, [esi+CURSOR.hot_x]
  658.            mov [x], ecx
  659.            sets dl
  660.            dec edx
  661.            and ecx, edx       ;clip x to 0<=x
  662.            mov edi, ecx
  663.            sub edi, [x]
  664.            mov [_dx], edi
  665.  
  666.            xor edx, edx
  667.            sub eax, [esi+CURSOR.hot_y]
  668.            mov [y], eax
  669.            sets dl
  670.            dec edx
  671.            and eax, edx       ;clip y to 0<=y
  672.            mov edi, eax
  673.            sub edi, [y]
  674.            mov [_dy], edi
  675.  
  676.            mul ebx
  677.            lea esi, [eax+ecx*4]
  678.            add esi, [LFBAddress]
  679.            mov [cur_saved_base],esi
  680.  
  681.            mov edi, [scr_width]
  682.            mov edx, [scr_height]
  683.            mov eax, 32
  684.  
  685.            sub edi, ecx
  686.            cmp edi, eax
  687.            jng @F
  688.            mov edi, eax
  689. @@:
  690.            sub edi, [_dx]
  691.  
  692.            sub edx, [y]
  693.            cmp edx, eax
  694.            jng @F
  695.            mov edx, eax
  696. @@:
  697.            sub edx, [_dy]
  698.  
  699.            mov [w], edi
  700.            mov [h], edx
  701.            mov [cur_saved_w], edi
  702.            mov [cur_saved_h], edx
  703.  
  704.            sub eax, edi
  705.            shl eax, 2
  706.            shl edi, 2
  707.            sub ebx, edi
  708.            mov [cur_saved_interl], ebx
  709.  
  710.            mov edi, cur_saved_data
  711. @@:
  712.            mov ecx, [w]
  713.            rep movsd
  714.            add esi, ebx
  715.            dec edx
  716.            jnz @B
  717.  
  718. ;draw cursor
  719.            mov edx, eax
  720.            mov edi, [cur_saved_base]
  721.            mov eax, [_dy]
  722.            shl eax, 5
  723.            add eax, [_dx]
  724.            shl eax, 2
  725.  
  726.            mov esi, [hcursor]
  727.            mov esi, [esi+CURSOR.base]
  728.            add esi, eax
  729. .row:
  730.            mov ecx, [w]
  731. .pix:
  732.            lodsd
  733.            test eax, 0xFF000000
  734.            jz @F
  735.            mov [edi], eax
  736. @@:
  737.            add edi, 4
  738.            dec ecx
  739.            jnz .pix
  740.            add esi, edx
  741.            add edi, ebx
  742.            dec [h]
  743.            jnz .row
  744.            ret
  745. endp
  746.  
  747. align 4
  748. def_arrow:
  749.   file 'arrow.cur'
  750.  
  751.