Subversion Repositories Kolibri OS

Rev

Rev 846 | Rev 887 | 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: 864 $
  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.            mov edi, eax
  317.            mov ecx, 0x1000
  318.            mov edx, PG_SW
  319.            call @mem_alloc@8
  320.            test eax, eax
  321.            mov [edi+CURSOR.base], eax
  322.            jz .fail
  323.  
  324.            mov esi, [.src]
  325.            mov ebx, [.flags]
  326.            cmp bx, LOAD_INDIRECT
  327.            je .indirect
  328.  
  329.            movzx ecx, word [esi+10]
  330.            movzx edx, word [esi+12]
  331.            mov [edi+CURSOR.hot_x], ecx
  332.            mov [edi+CURSOR.hot_y], edx
  333.  
  334.            stdcall vesa_init_cursor, eax, esi
  335.            mov eax, [.hcursor]
  336. .fail:
  337.            add esp, 12
  338.            ret
  339. .indirect:
  340.            shr ebx, 16
  341.            movzx ecx, bh
  342.            movzx edx, bl
  343.            mov [eax+CURSOR.hot_x], ecx
  344.            mov [eax+CURSOR.hot_y], edx
  345.  
  346.            xchg edi, eax
  347.            mov ecx, 1024
  348.            cld
  349.            rep movsd
  350.            add esp, 12
  351.            ret
  352.  
  353. align 4
  354. proc load_cursor stdcall, src:dword, flags:dword
  355.            locals
  356.              handle  dd ?
  357.            endl
  358.  
  359.            xor eax, eax
  360.            cmp [create_cursor], eax
  361.            je .fail2
  362.  
  363.            mov [handle], eax
  364.            cmp word [flags], LOAD_FROM_FILE
  365.            jne @F
  366.  
  367.            stdcall load_file, [src]
  368.            test eax, eax
  369.            jz .fail
  370.            mov [src], eax
  371. @@:
  372.            push ebx
  373.            push esi
  374.            push edi
  375.  
  376.            mov eax, [CURRENT_TASK]
  377.            shl eax, 5
  378.            mov eax, [CURRENT_TASK+eax+4]
  379.            mov ebx, [src]
  380.            mov ecx, [flags]
  381.            call [create_cursor]    ;eax, ebx, ecx
  382.            mov [handle], eax
  383.  
  384.            cmp word [flags], LOAD_FROM_FILE
  385.            jne .exit
  386.            stdcall kernel_free, [src]
  387. .exit:
  388.            pop edi
  389.            pop esi
  390.            pop ebx
  391. .fail:
  392.            mov eax, [handle]
  393. .fail2:
  394.            ret
  395. endp
  396.  
  397. align 4
  398. proc delete_cursor stdcall, hcursor:dword
  399.            locals
  400.              hsrv       dd ?
  401.              io_code    dd ?
  402.              input      dd ?
  403.              inp_size   dd ?
  404.              output     dd ?
  405.              out_size   dd ?
  406.            endl
  407.  
  408.            mov esi, [hcursor]
  409.            cmp [esi+CURSOR.magic], 'CURS'
  410.            jne .fail
  411. ;           cmp [esi+CURSOR.size], CURSOR_SIZE
  412. ;           jne .fail
  413.  
  414.            mov ebx, [CURRENT_TASK]
  415.            shl ebx, 5
  416.            mov ebx, [CURRENT_TASK+ebx+4]
  417.            cmp ebx, [esi+CURSOR.pid]
  418.            jne .fail
  419.  
  420.            mov ebx, [current_slot]
  421.            cmp esi, [ebx+APPDATA.cursor]
  422.            jne @F
  423.            mov eax, [def_cursor]
  424.            mov [ebx+APPDATA.cursor], eax
  425. @@:
  426.            mov eax, [hcursor]
  427.            call [eax+APPOBJ.destroy]
  428. .fail:
  429.            ret
  430. endp
  431.  
  432. ; param
  433. ;  eax= cursor
  434.  
  435. align 4
  436. destroy_cursor:
  437.  
  438.            push eax
  439.            stdcall kernel_free, [eax+CURSOR.base]
  440.            pop eax
  441.  
  442.            call destroy_kernel_object
  443.            ret
  444.  
  445. align 4
  446. select_cursor:
  447.  
  448.            ret 4
  449.  
  450. align 4
  451. proc init_cursors
  452.  
  453.            cmp [SCR_MODE],word 0x13
  454.            jbe .fail
  455.  
  456.            test word [SCR_MODE], 0x4000
  457.            jz .fail
  458.  
  459.            movzx eax, byte [ScreenBPP]
  460.            mov ebx, [BytesPerScanLine]
  461.            cmp eax, 32
  462.            jne @F
  463.            sub ebx, 128
  464.            jmp .init
  465. @@:
  466.            cmp eax, 24
  467.            jne .fail
  468.            sub ebx, 96
  469. .init:
  470.            mov [cur_def_interl], ebx
  471.  
  472.         ;   stdcall load_driver, szHwMouse
  473.         ;   mov [hw_cursor], eax
  474.         ;   test eax, eax
  475.         ;   jz .sw_mouse
  476.  
  477.         ;   stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM
  478.         ;   mov [def_cursor], eax
  479.         ;   ret
  480. .sw_mouse:
  481.            mov [create_cursor], vesa_cursor
  482.  
  483.            stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM
  484.            mov [def_cursor], eax
  485.  
  486.            mov ecx, [Screen_Max_X]
  487.            mov edx, [Screen_Max_Y]
  488.            inc ecx
  489.            inc edx
  490.            mov [scr_width], ecx
  491.            mov [scr_height], edx
  492.  
  493.            movzx ebx, byte [ScreenBPP]
  494.            cmp ebx, 32
  495.            jne @F
  496.  
  497.  
  498.            mov dword [select_hw_cursor], select_cursor
  499.            mov dword [set_hw_cursor], cursor_32
  500.            mov dword [hw_restore], restore_32
  501.            ret
  502. @@:
  503.            mov dword [select_hw_cursor], select_cursor
  504.            mov dword [set_hw_cursor], cursor_24
  505.            mov dword [hw_restore], restore_24
  506.            ret
  507. .fail:
  508.            xor eax, eax
  509.            mov dword [select_hw_cursor], eax
  510.            mov dword [set_hw_cursor], eax
  511.            mov dword [hw_restore], eax
  512.            ret
  513. endp
  514.  
  515. align 4
  516. proc restore_24 stdcall, x:dword, y:dword
  517.            locals
  518.              w  dd ?
  519.            endl
  520.  
  521.            mov edi, [cur_saved_base]
  522.            mov edx, [cur_saved_h]
  523.            mov ebx, [cur_saved_interl]
  524.            test edx, edx
  525.            jz  .ret
  526.  
  527.            mov esi, cur_saved_data
  528. @@:
  529.            mov ecx, [cur_saved_w]
  530.            lea ecx, [ecx+ecx*2]
  531.            rep movsb
  532.            add edi, ebx
  533.            dec edx
  534.            jnz @B
  535. .ret:
  536.            ret
  537. endp
  538.  
  539. align 4
  540. proc restore_32 stdcall, x:dword, y:dword
  541.            locals
  542.              w  dd ?
  543.            endl
  544.  
  545.            mov edi, [cur_saved_base]
  546.            mov edx, [cur_saved_h]
  547.            mov ebx, [cur_saved_interl]
  548.            test edx, edx
  549.            jz  .ret
  550.  
  551.            mov esi, cur_saved_data
  552. @@:
  553.            mov ecx, [cur_saved_w]
  554.            rep movsd
  555.            add edi, ebx
  556.            dec edx
  557.            jnz @B
  558. .ret:
  559.            ret
  560. endp
  561.  
  562. align 4
  563. proc cursor_24 stdcall, hcursor:dword, x:dword, y:dword
  564.            locals
  565.              w      dd ?
  566.              h      dd ?
  567.              st     dd ?
  568.              _dx     dd ?
  569.              _dy     dd ?
  570.            endl
  571.  
  572.            mov esi, [hcursor]
  573.            mov ecx, [x]
  574.            mov eax, [y]
  575.            mov ebx, [BytesPerScanLine]
  576.  
  577.            xor edx, edx
  578.            sub ecx, [esi+CURSOR.hot_x]
  579.            mov [x], ecx
  580.            sets dl
  581.            dec edx
  582.            and ecx, edx       ;clip x to 0<=x
  583.            mov edi, ecx
  584.            sub edi, [x]
  585.            mov [_dx], edi
  586.  
  587.            xor edx, edx
  588.            sub eax, [esi+CURSOR.hot_y]
  589.            mov [y], eax
  590.            sets dl
  591.            dec edx
  592.            and eax, edx       ;clip y to 0<=y
  593.            mov edi, eax
  594.            sub edi, [y]
  595.            mov [_dy], edi
  596.  
  597.            mul ebx
  598.            lea esi, [ecx+ecx*2]
  599.            add esi, [LFBAddress]
  600.            add esi, eax
  601.            mov [cur_saved_base],esi
  602.  
  603.            mov edi, [scr_width]
  604.            mov edx, [scr_height]
  605.            mov eax, 32
  606.  
  607.            sub edi, ecx
  608.            cmp edi, eax
  609.            jng @F
  610.            mov edi, eax
  611. @@:
  612.            sub edi, [_dx]
  613.  
  614.            sub edx, [y]
  615.            cmp edx, eax
  616.            jng @F
  617.            mov edx, eax
  618. @@:
  619.            sub edx, [_dy]
  620.  
  621.            mov [w], edi
  622.            mov [h], edx
  623.            mov [cur_saved_w], edi
  624.            mov [cur_saved_h], edx
  625.  
  626.            sub eax, edi
  627.            shl eax, 2       ;lea eax, [eax+eax*2]
  628.            lea edi, [edi+edi*2]
  629.            sub ebx, edi
  630.            mov [cur_saved_interl], ebx
  631.  
  632.            mov edi, cur_saved_data
  633. @@:
  634.            mov ecx, [w]
  635.            lea ecx, [ecx+ecx*2]
  636.            rep movsb
  637.            add esi, ebx
  638.            dec edx
  639.            jnz @B
  640.  
  641. ;draw cursor
  642.            mov edx, eax
  643.            mov edi, [cur_saved_base]
  644.            mov eax, [_dy]
  645.            shl eax, 5
  646.            add eax, [_dx]
  647.            shl eax, 2
  648.  
  649.            mov esi, [hcursor]
  650.            mov esi, [esi+CURSOR.base]
  651.            add esi, eax
  652. .row:
  653.            mov ecx, [w]
  654. .pix:
  655.            lodsd
  656.            test eax, 0xFF000000
  657.            jz @F
  658.  
  659.            mov word [edi], ax
  660.            shr eax, 16
  661.            mov [edi+2],al
  662. @@:
  663.            add edi, 3
  664.            dec ecx
  665.            jnz .pix
  666.  
  667.            add esi, edx
  668.            add edi, ebx
  669.            dec [h]
  670.            jnz .row
  671.            ret
  672. endp
  673.  
  674. align 4
  675. proc cursor_32 stdcall, hcursor:dword, x:dword, y:dword
  676.            locals
  677.              w      dd ?
  678.              h      dd ?
  679.              st     dd ?
  680.              _dx     dd ?
  681.              _dy     dd ?
  682.            endl
  683.  
  684.            mov esi, [hcursor]
  685.            mov ecx, [x]
  686.            mov eax, [y]
  687.            mov ebx, [BytesPerScanLine]
  688.  
  689.            xor edx, edx
  690.            sub ecx, [esi+CURSOR.hot_x]
  691.            mov [x], ecx
  692.            sets dl
  693.            dec edx
  694.            and ecx, edx       ;clip x to 0<=x
  695.            mov edi, ecx
  696.            sub edi, [x]
  697.            mov [_dx], edi
  698.  
  699.            xor edx, edx
  700.            sub eax, [esi+CURSOR.hot_y]
  701.            mov [y], eax
  702.            sets dl
  703.            dec edx
  704.            and eax, edx       ;clip y to 0<=y
  705.            mov edi, eax
  706.            sub edi, [y]
  707.            mov [_dy], edi
  708.  
  709.            mul ebx
  710.            lea esi, [eax+ecx*4]
  711.            add esi, [LFBAddress]
  712.            mov [cur_saved_base],esi
  713.  
  714.            mov edi, [scr_width]
  715.            mov edx, [scr_height]
  716.            mov eax, 32
  717.  
  718.            sub edi, ecx
  719.            cmp edi, eax
  720.            jng @F
  721.            mov edi, eax
  722. @@:
  723.            sub edi, [_dx]
  724.  
  725.            sub edx, [y]
  726.            cmp edx, eax
  727.            jng @F
  728.            mov edx, eax
  729. @@:
  730.            sub edx, [_dy]
  731.  
  732.            mov [w], edi
  733.            mov [h], edx
  734.            mov [cur_saved_w], edi
  735.            mov [cur_saved_h], edx
  736.  
  737.            sub eax, edi
  738.            shl eax, 2
  739.            shl edi, 2
  740.            sub ebx, edi
  741.            mov [cur_saved_interl], ebx
  742.  
  743.            mov edi, cur_saved_data
  744. @@:
  745.            mov ecx, [w]
  746.            rep movsd
  747.            add esi, ebx
  748.            dec edx
  749.            jnz @B
  750.  
  751. ;draw cursor
  752.            mov edx, eax
  753.            mov edi, [cur_saved_base]
  754.            mov eax, [_dy]
  755.            shl eax, 5
  756.            add eax, [_dx]
  757.            shl eax, 2
  758.  
  759.            mov esi, [hcursor]
  760.            mov esi, [esi+CURSOR.base]
  761.            add esi, eax
  762. .row:
  763.            mov ecx, [w]
  764. .pix:
  765.            lodsd
  766.            test eax, 0xFF000000
  767.            jz @F
  768.            mov [edi], eax
  769. @@:
  770.            add edi, 4
  771.            dec ecx
  772.            jnz .pix
  773.            add esi, edx
  774.            add edi, ebx
  775.            dec [h]
  776.            jnz .row
  777.            ret
  778. endp
  779.  
  780. align 4
  781. def_arrow:
  782.   file 'arrow.cur'
  783.  
  784.