Subversion Repositories Kolibri OS

Rev

Rev 381 | Rev 465 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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