Subversion Repositories Kolibri OS

Rev

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