Subversion Repositories Kolibri OS

Rev

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

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