Subversion Repositories Kolibri OS

Rev

Rev 641 | Rev 673 | 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: 662 $
  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.            cmp [SCR_MODE],word 0x13
  448.            jbe .fail
  449.  
  450.            movzx eax, byte [ScreenBPP]
  451.            mov ebx, [BytesPerScanLine]
  452.            cmp eax, 32
  453.            jne @F
  454.            sub ebx, 128
  455.            jmp .init
  456. @@:
  457.            cmp eax, 24
  458.            jne .fail
  459.            sub ebx, 96
  460. .init:
  461.            mov [cur_def_interl], ebx
  462.  
  463.            stdcall load_driver, szHwMouse
  464.            mov [hw_cursor], eax
  465.            test eax, eax
  466.            jz .sw_mouse
  467.  
  468.            stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM
  469.            mov [def_cursor], eax
  470.            ret
  471. .sw_mouse:
  472.            mov [create_cursor], vesa_cursor
  473.  
  474.            stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM
  475.            mov [def_cursor], eax
  476.  
  477.            mov ecx, [ScreenWidth]
  478.            mov edx, [ScreenHeight]
  479.            inc ecx
  480.            inc edx
  481.            mov [scr_width], ecx
  482.            mov [scr_height], edx
  483.  
  484.            movzx ebx, byte [ScreenBPP]
  485.            cmp ebx, 32
  486.            jne @F
  487.  
  488.  
  489.            mov dword [select_hw_cursor], select_cursor
  490.            mov dword [set_hw_cursor], cursor_32
  491.            mov dword [hw_restore], restore_32
  492.            ret
  493. @@:
  494.            mov dword [select_hw_cursor], select_cursor
  495.            mov dword [set_hw_cursor], cursor_24
  496.            mov dword [hw_restore], restore_24
  497.            ret
  498. .fail:
  499.            xor eax, eax
  500.            mov dword [select_hw_cursor], eax
  501.            mov dword [set_hw_cursor], eax
  502.            mov dword [hw_restore], eax
  503.            ret
  504. endp
  505.  
  506. align 4
  507. proc restore_24 stdcall, x:dword, y:dword
  508.            locals
  509.              w  dd ?
  510.            endl
  511.  
  512.            mov edi, [cur_saved_base]
  513.            mov edx, [cur_saved_h]
  514.            mov ebx, [cur_saved_interl]
  515.            test edx, edx
  516.            jz  .ret
  517.  
  518.            mov esi, cur_saved_data
  519. @@:
  520.            mov ecx, [cur_saved_w]
  521.            lea ecx, [ecx+ecx*2]
  522.            rep movsb
  523.            add edi, ebx
  524.            dec edx
  525.            jnz @B
  526. .ret:
  527.            ret
  528. endp
  529.  
  530. align 4
  531. proc restore_32 stdcall, x:dword, y:dword
  532.            locals
  533.              w  dd ?
  534.            endl
  535.  
  536.            mov edi, [cur_saved_base]
  537.            mov edx, [cur_saved_h]
  538.            mov ebx, [cur_saved_interl]
  539.            test edx, edx
  540.            jz  .ret
  541.  
  542.            mov esi, cur_saved_data
  543. @@:
  544.            mov ecx, [cur_saved_w]
  545.            rep movsd
  546.            add edi, ebx
  547.            dec edx
  548.            jnz @B
  549. .ret:
  550.            ret
  551. endp
  552.  
  553. align 4
  554. proc cursor_24 stdcall, hcursor:dword, x:dword, y:dword
  555.            locals
  556.              w      dd ?
  557.              h      dd ?
  558.              st     dd ?
  559.              _dx     dd ?
  560.              _dy     dd ?
  561.            endl
  562.  
  563.            mov esi, [hcursor]
  564.            mov ecx, [x]
  565.            mov eax, [y]
  566.            mov ebx, [BytesPerScanLine]
  567.  
  568.            xor edx, edx
  569.            sub ecx, [esi+CURSOR.hot_x]
  570.            mov [x], ecx
  571.            sets dl
  572.            dec edx
  573.            and ecx, edx       ;clip x to 0<=x
  574.            mov edi, ecx
  575.            sub edi, [x]
  576.            mov [_dx], edi
  577.  
  578.            xor edx, edx
  579.            sub eax, [esi+CURSOR.hot_y]
  580.            mov [y], eax
  581.            sets dl
  582.            dec edx
  583.            and eax, edx       ;clip y to 0<=y
  584.            mov edi, eax
  585.            sub edi, [y]
  586.            mov [_dy], edi
  587.  
  588.            mul ebx
  589.            lea esi, [ecx+ecx*2]
  590.            add esi, [LFBAddress]
  591.            add esi, eax
  592.            mov [cur_saved_base],esi
  593.  
  594.            mov edi, [scr_width]
  595.            mov edx, [scr_height]
  596.            mov eax, 32
  597.  
  598.            sub edi, ecx
  599.            cmp edi, eax
  600.            jng @F
  601.            mov edi, eax
  602. @@:
  603.            sub edi, [_dx]
  604.  
  605.            sub edx, [y]
  606.            cmp edx, eax
  607.            jng @F
  608.            mov edx, eax
  609. @@:
  610.            sub edx, [_dy]
  611.  
  612.            mov [w], edi
  613.            mov [h], edx
  614.            mov [cur_saved_w], edi
  615.            mov [cur_saved_h], edx
  616.  
  617.            sub eax, edi
  618.            shl eax, 2       ;lea eax, [eax+eax*2]
  619.            lea edi, [edi+edi*2]
  620.            sub ebx, edi
  621.            mov [cur_saved_interl], ebx
  622.  
  623.            mov edi, cur_saved_data
  624. @@:
  625.            mov ecx, [w]
  626.            lea ecx, [ecx+ecx*2]
  627.            rep movsb
  628.            add esi, ebx
  629.            dec edx
  630.            jnz @B
  631.  
  632. ;draw cursor
  633.            mov edx, eax
  634.            mov edi, [cur_saved_base]
  635.            mov eax, [_dy]
  636.            shl eax, 5
  637.            add eax, [_dx]
  638.            shl eax, 2
  639.  
  640.            mov esi, [hcursor]
  641.            mov esi, [esi+CURSOR.base]
  642.            add esi, eax
  643. .row:
  644.            mov ecx, [w]
  645. .pix:
  646.            lodsd
  647.            test eax, 0xFF000000
  648.            jz @F
  649.  
  650.            mov word [edi], ax
  651.            shr eax, 16
  652.            mov [edi+2],al
  653. @@:
  654.            add edi, 3
  655.            dec ecx
  656.            jnz .pix
  657.  
  658.            add esi, edx
  659.            add edi, ebx
  660.            dec [h]
  661.            jnz .row
  662.            ret
  663. endp
  664.  
  665. align 4
  666. proc cursor_32 stdcall, hcursor:dword, x:dword, y:dword
  667.            locals
  668.              w      dd ?
  669.              h      dd ?
  670.              st     dd ?
  671.              _dx     dd ?
  672.              _dy     dd ?
  673.            endl
  674.  
  675.            mov esi, [hcursor]
  676.            mov ecx, [x]
  677.            mov eax, [y]
  678.            mov ebx, [BytesPerScanLine]
  679.  
  680.            xor edx, edx
  681.            sub ecx, [esi+CURSOR.hot_x]
  682.            mov [x], ecx
  683.            sets dl
  684.            dec edx
  685.            and ecx, edx       ;clip x to 0<=x
  686.            mov edi, ecx
  687.            sub edi, [x]
  688.            mov [_dx], edi
  689.  
  690.            xor edx, edx
  691.            sub eax, [esi+CURSOR.hot_y]
  692.            mov [y], eax
  693.            sets dl
  694.            dec edx
  695.            and eax, edx       ;clip y to 0<=y
  696.            mov edi, eax
  697.            sub edi, [y]
  698.            mov [_dy], edi
  699.  
  700.            mul ebx
  701.            lea esi, [eax+ecx*4]
  702.            add esi, [LFBAddress]
  703.            mov [cur_saved_base],esi
  704.  
  705.            mov edi, [scr_width]
  706.            mov edx, [scr_height]
  707.            mov eax, 32
  708.  
  709.            sub edi, ecx
  710.            cmp edi, eax
  711.            jng @F
  712.            mov edi, eax
  713. @@:
  714.            sub edi, [_dx]
  715.  
  716.            sub edx, [y]
  717.            cmp edx, eax
  718.            jng @F
  719.            mov edx, eax
  720. @@:
  721.            sub edx, [_dy]
  722.  
  723.            mov [w], edi
  724.            mov [h], edx
  725.            mov [cur_saved_w], edi
  726.            mov [cur_saved_h], edx
  727.  
  728.            sub eax, edi
  729.            shl eax, 2
  730.            shl edi, 2
  731.            sub ebx, edi
  732.            mov [cur_saved_interl], ebx
  733.  
  734.            mov edi, cur_saved_data
  735. @@:
  736.            mov ecx, [w]
  737.            rep movsd
  738.            add esi, ebx
  739.            dec edx
  740.            jnz @B
  741.  
  742. ;draw cursor
  743.            mov edx, eax
  744.            mov edi, [cur_saved_base]
  745.            mov eax, [_dy]
  746.            shl eax, 5
  747.            add eax, [_dx]
  748.            shl eax, 2
  749.  
  750.            mov esi, [hcursor]
  751.            mov esi, [esi+CURSOR.base]
  752.            add esi, eax
  753. .row:
  754.            mov ecx, [w]
  755. .pix:
  756.            lodsd
  757.            test eax, 0xFF000000
  758.            jz @F
  759.            mov [edi], eax
  760. @@:
  761.            add edi, 4
  762.            dec ecx
  763.            jnz .pix
  764.            add esi, edx
  765.            add edi, ebx
  766.            dec [h]
  767.            jnz .row
  768.            ret
  769. endp
  770.  
  771. align 4
  772. def_arrow:
  773.   file 'arrow.cur'
  774.  
  775.