Subversion Repositories Kolibri OS

Rev

Rev 276 | Rev 326 | 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. alloc_cursor:
  265.  
  266.            mov eax, CURSOR_SIZE
  267.            call malloc
  268.            test eax, eax
  269.            jz .fail
  270.  
  271.            xor ebx, ebx
  272.            mov [eax+CURSOR.magic], 'CURS'
  273. ;           mov [eax+CURSOR.destructor],  CURSOR_SIZE
  274.            mov [eax+CURSOR.pid], ebx
  275.            mov [eax+CURSOR.hot_x], ebx
  276.            mov [eax+CURSOR.hot_y], ebx
  277. .fail:
  278.            ret
  279.  
  280. align 4
  281. proc set_cursor stdcall, hcursor:dword
  282.            mov eax, [hcursor]
  283.            cmp [eax+CURSOR.magic], 'CURS'
  284.            jne .fail
  285. ;           cmp [eax+CURSOR.size], CURSOR_SIZE
  286. ;           jne .fail
  287.            mov ebx, [CURRENT_TASK]
  288.            shl ebx, 8
  289.            xchg eax, [ebx+PROC_BASE+APPDATA.cursor]
  290.            ret
  291. .fail:
  292.            mov eax, [def_cursor]
  293.            mov ebx, [CURRENT_TASK]
  294.            shl ebx, 8
  295.            xchg eax, [ebx+PROC_BASE+APPDATA.cursor]
  296.            ret
  297. endp
  298.  
  299. ; param
  300. ;  eax= pid
  301. ;  ebx= src
  302. ;  ecx= flags
  303.  
  304. vesa_cursor:
  305. .src     equ esp
  306. .flags   equ esp+4
  307. .hcursor equ esp+8
  308.  
  309.            sub esp, 4          ;space for .hcursor
  310.            push ecx
  311.            push ebx
  312.  
  313.            mov ebx, eax
  314.            mov eax, CURSOR_SIZE
  315.            call create_kernel_object
  316.            test eax, eax
  317.            jz .fail
  318.  
  319.            mov [.hcursor],eax
  320.  
  321.            xor ebx, ebx
  322.            mov [eax+CURSOR.magic], 'CURS'
  323.            mov [eax+CURSOR.destroy], destroy_cursor
  324.            mov [eax+CURSOR.hot_x], ebx
  325.            mov [eax+CURSOR.hot_y], ebx
  326.  
  327.            stdcall kernel_alloc, 0x1000
  328.            test eax, eax
  329.            jz .fail
  330.  
  331.            mov edi, [.hcursor]
  332.            mov [edi+CURSOR.base], eax
  333.  
  334.            mov esi, [.src]
  335.            mov ebx, [.flags]
  336.            cmp bx, LOAD_INDIRECT
  337.            je .indirect
  338.  
  339.            movzx ecx, word [esi+10]
  340.            movzx edx, word [esi+12]
  341.            mov [edi+CURSOR.hot_x], ecx
  342.            mov [edi+CURSOR.hot_y], edx
  343.  
  344.            stdcall vesa_init_cursor, eax, esi
  345.            mov eax, [.hcursor]
  346. .fail:
  347.            add esp, 12
  348.            ret
  349. .indirect:
  350.            shr ebx, 16
  351.            movzx ecx, bh
  352.            movzx edx, bl
  353.            mov [eax+CURSOR.hot_x], ecx
  354.            mov [eax+CURSOR.hot_y], edx
  355.  
  356.            xchg edi, eax
  357.            mov ecx, 1024
  358.            cld
  359.            rep movsd
  360.            add esp, 12
  361.            ret
  362.  
  363. align 4
  364. proc load_cursor stdcall, src:dword, flags:dword
  365.            locals
  366.              handle  dd ?
  367.            endl
  368.  
  369.            xor eax, eax
  370.            mov [handle], eax
  371.            cmp word [flags], LOAD_FROM_FILE
  372.            jne @F
  373.  
  374.            stdcall load_file, [src]
  375.            test eax, eax
  376.            jz .exit
  377.            mov [src], eax
  378. @@:
  379.            mov eax, [CURRENT_TASK]
  380.            shl eax, 5
  381.            mov eax, [0x3000+eax+4]
  382.            mov ebx, [src]
  383.            mov ecx, [flags]
  384.            call [create_cursor]    ;eax, ebx, ecx
  385.            mov [handle], eax
  386. .fail:
  387.            cmp word [flags], LOAD_FROM_FILE
  388.            jne .exit
  389.            stdcall kernel_free, [src]
  390. .exit:
  391.            mov eax, [handle]
  392.            ret
  393. endp
  394.  
  395. align 4
  396. proc delete_cursor stdcall, hcursor:dword
  397.            locals
  398.              hsrv       dd ?
  399.              io_code    dd ?
  400.              input      dd ?
  401.              inp_size   dd ?
  402.              output     dd ?
  403.              out_size   dd ?
  404.            endl
  405.  
  406.            mov esi, [hcursor]
  407.            cmp [esi+CURSOR.magic], 'CURS'
  408.            jne .fail
  409. ;           cmp [esi+CURSOR.size], CURSOR_SIZE
  410. ;           jne .fail
  411.  
  412.            mov ebx, [CURRENT_TASK]
  413.            shl ebx, 5
  414.            mov ebx, [0x3000+ebx+4]
  415.            cmp ebx, [esi+CURSOR.pid]
  416.            jne .fail
  417.  
  418.            mov ebx, [CURRENT_TASK]
  419.            shl ebx, 8
  420.            cmp esi, [ebx+PROC_BASE+APPDATA.cursor]
  421.            jne @F
  422.            mov eax, [def_cursor]
  423.            mov [ebx+PROC_BASE+APPDATA.cursor], eax
  424. @@:
  425.            mov eax, [hcursor]
  426.            call [eax+APPOBJ.destroy]
  427. .fail:
  428.            ret
  429.  
  430. ;@@:
  431. ;           mov eax, [hw_cursor]
  432. ;           test eax, eax
  433. ;           jz @F
  434.  
  435. ;           xor ebx, ebx
  436. ;           mov ecx, [esi+CURSOR.base]
  437. ;           mov [hsrv], eax
  438. ;           mov [io_code], VIDEO_FREE
  439. ;           mov [input], ecx
  440. ;           mov [inp_size], 4
  441. ;           mov [output], ebx
  442. ;           mov [out_size], ebx
  443.  
  444. ;           lea eax, [hsrv]
  445. ;           stdcall srv_handler, eax
  446. ;           jmp .exit
  447. ;@@:
  448. ;           stdcall kernel_free, [esi+CURSOR.base]
  449. ;.exit:
  450. ;           mov eax, [hcursor]
  451. ;           call destroy_kernel_object
  452. ;.fail:
  453. ;           ret
  454. endp
  455.  
  456. ; param
  457. ;  eax= cursor
  458.  
  459. align 4
  460. destroy_cursor:
  461.  
  462.            push eax
  463.            stdcall kernel_free, [eax+CURSOR.base]
  464.            pop eax
  465.  
  466.  
  467.            call destroy_kernel_object
  468.            ret
  469.  
  470. align 4
  471. proc init_cursors
  472.            cmp [0xfe0c],word 0x13
  473.            jbe .fail
  474.  
  475.            movzx eax, byte [ScreenBPP]
  476.            mov ebx, [SCR_BYTES_PER_LINE]
  477.            cmp eax, 32
  478.            jne @F
  479.            sub ebx, 128
  480.            jmp .init
  481. @@:
  482.            cmp eax, 24
  483.            jne .fail
  484.            sub ebx, 96
  485. .init:
  486.            mov [cur_def_interl], ebx
  487.  
  488.            stdcall load_driver, drv_hw_mouse
  489.            mov [hw_cursor], eax
  490.            test eax, eax
  491.            jz .sw_mouse
  492.  
  493.            stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM
  494.            mov [def_cursor], eax
  495.            ret
  496. .sw_mouse:
  497.            mov [create_cursor], vesa_cursor
  498.  
  499.            stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM
  500.            mov [def_cursor], eax
  501.  
  502.            mov ecx, [SCR_X_SIZE]
  503.            mov edx, [SCR_Y_SIZE]
  504.            inc ecx
  505.            inc edx
  506.            mov [scr_width], ecx
  507.            mov [scr_height], edx
  508.  
  509.            movzx ebx, byte [ScreenBPP]
  510.            cmp ebx, 32
  511.            jne @F
  512.  
  513.            mov dword [set_hw_cursor], cursor_32
  514.            mov dword [hw_restore], restore_32
  515.            ret
  516. @@:
  517.            mov dword [set_hw_cursor], cursor_24
  518.            mov dword [hw_restore], restore_24
  519.            ret
  520. .fail:
  521.            xor eax, eax
  522.            mov dword [set_hw_cursor], eax
  523.            mov dword [hw_restore], eax
  524.            ret
  525. endp
  526.  
  527. align 4
  528. proc restore_24 stdcall, x:dword, y:dword
  529.            locals
  530.              w  dd ?
  531.            endl
  532.  
  533.            mov edi, [cur_saved_base]
  534.            mov edx, [cur_saved_h]
  535.            mov ebx, [cur_saved_interl]
  536.  
  537.            mov esi, cur_saved_data
  538. @@:
  539.            mov ecx, [cur_saved_w]
  540.            lea ecx, [ecx+ecx*2]
  541.            rep movsb
  542.            add edi, ebx
  543.            dec edx
  544.            jnz @B
  545.            ret
  546. endp
  547.  
  548. align 4
  549. proc restore_32 stdcall, x:dword, y:dword
  550.            locals
  551.              w  dd ?
  552.            endl
  553.  
  554.            mov edi, [cur_saved_base]
  555.            mov edx, [cur_saved_h]
  556.            mov ebx, [cur_saved_interl]
  557.  
  558.            mov esi, cur_saved_data
  559. @@:
  560.            mov ecx, [cur_saved_w]
  561.            rep movsd
  562.            add edi, ebx
  563.            dec edx
  564.            jnz @B
  565.            ret
  566. endp
  567.  
  568. align 4
  569. proc cursor_24 stdcall, hcursor:dword, x:dword, y:dword
  570.            locals
  571.              w      dd ?
  572.              h      dd ?
  573.              st     dd ?
  574.              _dx     dd ?
  575.              _dy     dd ?
  576.            endl
  577.  
  578.            mov esi, [hcursor]
  579.            mov ecx, [x]
  580.            mov eax, [y]
  581.            mov ebx, [BytesPerScanLine]
  582.  
  583.            xor edx, edx
  584.            sub ecx, [esi+CURSOR.hot_x]
  585.            mov [x], ecx
  586.            sets dl
  587.            dec edx
  588.            and ecx, edx       ;clip x to 0<=x
  589.            mov edi, ecx
  590.            sub edi, [x]
  591.            mov [_dx], edi
  592.  
  593.            xor edx, edx
  594.            sub eax, [esi+CURSOR.hot_y]
  595.            mov [y], eax
  596.            sets dl
  597.            dec edx
  598.            and eax, edx       ;clip y to 0<=y
  599.            mov edi, eax
  600.            sub edi, [y]
  601.            mov [_dy], edi
  602.  
  603.            mul ebx
  604.            lea esi, [ecx+ecx*2]
  605.            add esi, [LFBAddress]
  606.            add esi, eax
  607.            mov [cur_saved_base],esi
  608.  
  609.            mov edi, [scr_width]
  610.            mov edx, [scr_height]
  611.            mov eax, 32
  612.  
  613.            sub edi, ecx
  614.            cmp edi, eax
  615.            jng @F
  616.            mov edi, eax
  617. @@:
  618.            sub edi, [_dx]
  619.  
  620.            sub edx, [y]
  621.            cmp edx, eax
  622.            jng @F
  623.            mov edx, eax
  624. @@:
  625.            sub edx, [_dy]
  626.  
  627.            mov [w], edi
  628.            mov [h], edx
  629.            mov [cur_saved_w], edi
  630.            mov [cur_saved_h], edx
  631.  
  632.            sub eax, edi
  633.            shl eax, 2       ;lea eax, [eax+eax*2]
  634.            lea edi, [edi+edi*2]
  635.            sub ebx, edi
  636.            mov [cur_saved_interl], ebx
  637.  
  638.            mov edi, cur_saved_data
  639. @@:
  640.            mov ecx, [w]
  641.            lea ecx, [ecx+ecx*2]
  642.            rep movsb
  643.            add esi, ebx
  644.            dec edx
  645.            jnz @B
  646.  
  647. ;draw cursor
  648.            mov edx, eax
  649.            mov edi, [cur_saved_base]
  650.            mov eax, [_dy]
  651.            shl eax, 5
  652.            add eax, [_dx]
  653.            shl eax, 2
  654.  
  655.            mov esi, [hcursor]
  656.            mov esi, [esi+CURSOR.base]
  657.            add esi, eax
  658. .row:
  659.            mov ecx, [w]
  660. .pix:
  661.            lodsd
  662.            test eax, 0xFF000000
  663.            jz @F
  664.  
  665.            mov word [edi], ax
  666.            shr eax, 16
  667.            mov [edi+2],al
  668. @@:
  669.            add edi, 3
  670.            dec ecx
  671.            jnz .pix
  672.  
  673.            add esi, edx
  674.            add edi, ebx
  675.            dec [h]
  676.            jnz .row
  677.            ret
  678. endp
  679.  
  680. align 4
  681. proc cursor_32 stdcall, hcursor:dword, x:dword, y:dword
  682.            locals
  683.              w      dd ?
  684.              h      dd ?
  685.              st     dd ?
  686.              _dx     dd ?
  687.              _dy     dd ?
  688.            endl
  689.  
  690.            mov esi, [hcursor]
  691.            mov ecx, [x]
  692.            mov eax, [y]
  693.            mov ebx, [BytesPerScanLine]
  694.  
  695.            xor edx, edx
  696.            sub ecx, [esi+CURSOR.hot_x]
  697.            mov [x], ecx
  698.            sets dl
  699.            dec edx
  700.            and ecx, edx       ;clip x to 0<=x
  701.            mov edi, ecx
  702.            sub edi, [x]
  703.            mov [_dx], edi
  704.  
  705.            xor edx, edx
  706.            sub eax, [esi+CURSOR.hot_y]
  707.            mov [y], eax
  708.            sets dl
  709.            dec edx
  710.            and eax, edx       ;clip y to 0<=y
  711.            mov edi, eax
  712.            sub edi, [y]
  713.            mov [_dy], edi
  714.  
  715.            mul ebx
  716.            lea esi, [eax+ecx*4]
  717.            add esi, [LFBAddress]
  718.            mov [cur_saved_base],esi
  719.  
  720.            mov edi, [scr_width]
  721.            mov edx, [scr_height]
  722.            mov eax, 32
  723.  
  724.            sub edi, ecx
  725.            cmp edi, eax
  726.            jng @F
  727.            mov edi, eax
  728. @@:
  729.            sub edi, [_dx]
  730.  
  731.            sub edx, [y]
  732.            cmp edx, eax
  733.            jng @F
  734.            mov edx, eax
  735. @@:
  736.            sub edx, [_dy]
  737.  
  738.            mov [w], edi
  739.            mov [h], edx
  740.            mov [cur_saved_w], edi
  741.            mov [cur_saved_h], edx
  742.  
  743.            sub eax, edi
  744.            shl eax, 2
  745.            shl edi, 2
  746.            sub ebx, edi
  747.            mov [cur_saved_interl], ebx
  748.  
  749.            mov edi, cur_saved_data
  750. @@:
  751.            mov ecx, [w]
  752.            rep movsd
  753.            add esi, ebx
  754.            dec edx
  755.            jnz @B
  756.  
  757. ;draw cursor
  758.            mov edx, eax
  759.            mov edi, [cur_saved_base]
  760.            mov eax, [_dy]
  761.            shl eax, 5
  762.            add eax, [_dx]
  763.            shl eax, 2
  764.  
  765.            mov esi, [hcursor]
  766.            mov esi, [esi+CURSOR.base]
  767.            add esi, eax
  768. .row:
  769.            mov ecx, [w]
  770. .pix:
  771.            lodsd
  772.            test eax, 0xFF000000
  773.            jz @F
  774.            mov [edi], eax
  775. @@:
  776.            add edi, 4
  777.            dec ecx
  778.            jnz .pix
  779.            add esi, edx
  780.            add edi, ebx
  781.            dec [h]
  782.            jnz .row
  783.            ret
  784. endp
  785.  
  786. align 4
  787. def_arrow:
  788.   file 'arrow.cur'
  789.  
  790.