Subversion Repositories Kolibri OS

Rev

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