Subversion Repositories Kolibri OS

Rev

Rev 390 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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