Subversion Repositories Kolibri OS

Rev

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