Subversion Repositories Kolibri OS

Rev

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