Subversion Repositories Kolibri OS

Rev

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