Subversion Repositories Kolibri OS

Rev

Rev 387 | 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_TASK]
  271.            shl ebx, 8
  272.            xchg eax, [ebx+SLOT_BASE+APPDATA.cursor]
  273.            ret
  274. .fail:
  275.            mov eax, [def_cursor]
  276.            mov ebx, [CURRENT_TASK]
  277.            shl ebx, 8
  278.            xchg eax, [ebx+SLOT_BASE+APPDATA.cursor]
  279.            ret
  280. endp
  281.  
  282. ; param
  283. ;  eax= pid
  284. ;  ebx= src
  285. ;  ecx= flags
  286.  
  287. vesa_cursor:
  288. .src     equ esp
  289. .flags   equ esp+4
  290. .hcursor equ esp+8
  291.  
  292.            sub esp, 4          ;space for .hcursor
  293.            push ecx
  294.            push ebx
  295.  
  296.            mov ebx, eax
  297.            mov eax, CURSOR_SIZE
  298.            call create_kernel_object
  299.            test eax, eax
  300.            jz .fail
  301.  
  302.            mov [.hcursor],eax
  303.  
  304.            xor ebx, ebx
  305.            mov [eax+CURSOR.magic], 'CURS'
  306.            mov [eax+CURSOR.destroy], destroy_cursor
  307.            mov [eax+CURSOR.hot_x], ebx
  308.            mov [eax+CURSOR.hot_y], ebx
  309.  
  310.            stdcall kernel_alloc, 0x1000
  311.            test eax, eax
  312.            jz .fail
  313.  
  314.            mov edi, [.hcursor]
  315.            mov [edi+CURSOR.base], eax
  316.  
  317.            mov esi, [.src]
  318.            mov ebx, [.flags]
  319.            cmp bx, LOAD_INDIRECT
  320.            je .indirect
  321.  
  322.            movzx ecx, word [esi+10]
  323.            movzx edx, word [esi+12]
  324.            mov [edi+CURSOR.hot_x], ecx
  325.            mov [edi+CURSOR.hot_y], edx
  326.  
  327.            stdcall vesa_init_cursor, eax, esi
  328.            mov eax, [.hcursor]
  329. .fail:
  330.            add esp, 12
  331.            ret
  332. .indirect:
  333.            shr ebx, 16
  334.            movzx ecx, bh
  335.            movzx edx, bl
  336.            mov [eax+CURSOR.hot_x], ecx
  337.            mov [eax+CURSOR.hot_y], edx
  338.  
  339.            xchg edi, eax
  340.            mov ecx, 1024
  341.            cld
  342.            rep movsd
  343.            add esp, 12
  344.            ret
  345.  
  346. align 4
  347. proc load_cursor stdcall, src:dword, flags:dword
  348.            locals
  349.              handle  dd ?
  350.            endl
  351.  
  352.            xor eax, eax
  353.            mov [handle], eax
  354.            cmp word [flags], LOAD_FROM_FILE
  355.            jne @F
  356.  
  357.            stdcall load_file, [src]
  358.            test eax, eax
  359.            jz .exit
  360.            mov [src], eax
  361. @@:
  362.            mov eax, [CURRENT_TASK]
  363.            shl eax, 5
  364.            mov eax, [CURRENT_TASK+eax+4]
  365.            mov ebx, [src]
  366.            mov ecx, [flags]
  367.            call [create_cursor]    ;eax, ebx, ecx
  368.            mov [handle], eax
  369. .fail:
  370.            cmp word [flags], LOAD_FROM_FILE
  371.            jne .exit
  372.            stdcall kernel_free, [src]
  373. .exit:
  374.            mov eax, [handle]
  375.            ret
  376. endp
  377.  
  378. align 4
  379. proc delete_cursor stdcall, hcursor:dword
  380.            locals
  381.              hsrv       dd ?
  382.              io_code    dd ?
  383.              input      dd ?
  384.              inp_size   dd ?
  385.              output     dd ?
  386.              out_size   dd ?
  387.            endl
  388.  
  389.            mov esi, [hcursor]
  390.            cmp [esi+CURSOR.magic], 'CURS'
  391.            jne .fail
  392. ;           cmp [esi+CURSOR.size], CURSOR_SIZE
  393. ;           jne .fail
  394.  
  395.            mov ebx, [CURRENT_TASK]
  396.            shl ebx, 5
  397.            mov ebx, [CURRENT_TASK+ebx+4]
  398.            cmp ebx, [esi+CURSOR.pid]
  399.            jne .fail
  400.  
  401.            mov ebx, [CURRENT_TASK]
  402.            shl ebx, 8
  403.            cmp esi, [ebx+SLOT_BASE+APPDATA.cursor]
  404.            jne @F
  405.            mov eax, [def_cursor]
  406.            mov [ebx+SLOT_BASE+APPDATA.cursor], eax
  407. @@:
  408.            mov eax, [hcursor]
  409.            call [eax+APPOBJ.destroy]
  410. .fail:
  411.            ret
  412. endp
  413.  
  414. ; param
  415. ;  eax= cursor
  416.  
  417. align 4
  418. destroy_cursor:
  419.  
  420.            push eax
  421.            stdcall kernel_free, [eax+CURSOR.base]
  422.            pop eax
  423.  
  424.            call destroy_kernel_object
  425.            ret
  426.  
  427. align 4
  428. proc init_cursors
  429.            cmp [SCR_MODE],word 0x13
  430.            jbe .fail
  431.  
  432.            movzx eax, byte [ScreenBPP]
  433.            mov ebx, [BytesPerScanLine]
  434.            cmp eax, 32
  435.            jne @F
  436.            sub ebx, 128
  437.            jmp .init
  438. @@:
  439.            cmp eax, 24
  440.            jne .fail
  441.            sub ebx, 96
  442. .init:
  443.            mov [cur_def_interl], ebx
  444.  
  445.            stdcall load_driver, szHwMouse
  446.            mov [hw_cursor], eax
  447.  
  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.