Subversion Repositories Kolibri OS

Rev

Rev 227 | Rev 233 | 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.  
  7. struc BITMAPINFOHEADER {
  8.   .biSize          dd ? ; DWORD
  9.   .biWidth         dd ? ; LONG
  10.   .biHeight        dd ? ; LONG
  11.   .biPlanes        dw ? ; WORD
  12.   .biBitCount      dw ? ; WORD
  13.   .biCompression   dd ? ; DWORD
  14.   .biSizeImage     dd ? ; DWORD
  15.   .biXPelsPerMeter dd ? ; LONG
  16.   .biYPelsPerMeter dd ? ; LONG
  17.   .biClrUsed       dd ? ; DWORD
  18.   .biClrImportant  dd ? ; DWORD
  19. }
  20.  
  21. virtual at 0
  22.   BI BITMAPINFOHEADER
  23. end virtual
  24.  
  25. align 4
  26. proc vesa_init_cursor stdcall, dst:dword, src:dword
  27.            locals
  28.              rBase    dd ?
  29.              pQuad    dd ?
  30.              pBits    dd ?
  31.              pAnd     dd ?
  32.              width    dd ?
  33.              height   dd ?
  34.              counter  dd ?
  35.            endl
  36.  
  37.            mov esi, [src]
  38.            add esi,[esi+18]
  39.            mov eax,esi
  40.  
  41.            cmp [esi+BI.biBitCount], 24
  42.            je .img_24
  43. .img_4:
  44.            add eax, [esi]
  45.            mov [pQuad],eax
  46.            add eax,64
  47.            mov [pBits],eax
  48.            add eax, 0x200
  49.            mov [pAnd],eax
  50.            mov eax,[esi+4]
  51.            mov [width],eax
  52.            mov ebx,[esi+8]
  53.            shr ebx,1
  54.            mov [height],ebx
  55.  
  56.            mov edi, [dst]
  57.            add edi, 32*31*4
  58.            mov [rBase],edi
  59.  
  60.            mov esi,[pAnd]
  61.            mov ebx, [pBits]
  62. .l1:
  63.            mov eax, [esi]
  64.            bswap eax
  65.            mov [counter], 16
  66. @@:
  67.            xor edx, edx
  68.            shl eax,1
  69.            setc dl
  70.            dec edx
  71.  
  72.            mov ecx, [ebx]
  73.            and ecx, 0xF0
  74.            shr ecx, 2
  75.            add ecx, [pQuad]
  76.            mov ecx, [ecx]
  77.            and ecx, edx
  78.            and edx, 0xFF000000
  79.            or edx, ecx
  80.            mov [edi], edx
  81.  
  82.            xor edx, edx
  83.            shl eax,1
  84.            setc dl
  85.            dec edx
  86.  
  87.            mov ecx, [ebx]
  88.            and ecx, 0x0F
  89.            shl ecx, 2
  90.            add ecx, [pQuad]
  91.            mov ecx, [ecx]
  92.            and ecx, edx
  93.            and edx, 0xFF000000
  94.            or edx, ecx
  95.            mov [edi+4], edx
  96.  
  97.            inc ebx
  98.            add edi, 8
  99.            dec [counter]
  100.            jnz @B
  101.  
  102.            add esi, 4
  103.            mov edi,[rBase]
  104.            sub edi,128
  105.            mov [rBase],edi
  106.            sub [height],1
  107.            jnz .l1
  108.            ret
  109. .img_24:
  110.            add eax, [esi]
  111.            mov [pQuad],eax
  112.            add eax, 0xC00
  113.            mov [pAnd],eax
  114.            mov eax,[esi+BI.biWidth]
  115.            mov [width],eax
  116.            mov ebx,[esi+BI.biHeight]
  117.            shr ebx,1
  118.            mov [height],ebx
  119.  
  120.            mov edi, [dst]
  121.            add edi, 32*31*4
  122.            mov [rBase],edi
  123.  
  124.            mov esi,[pAnd]
  125.            mov ebx, [pQuad]
  126. .row_24:
  127.            mov eax, [esi]
  128.            bswap eax
  129.            mov [counter], 32
  130. @@:
  131.            xor edx, edx
  132.            shl eax,1
  133.            setc dl
  134.            dec edx
  135.  
  136.            mov ecx, [ebx]
  137.            and ecx, 0x00FFFFFF
  138.            and ecx, edx
  139.            and edx, 0xFF000000
  140.            or edx, ecx
  141.            mov [edi], edx
  142.            add ebx, 3
  143.            add edi, 4
  144.            dec [counter]
  145.            jnz @B
  146.  
  147.            add esi, 4
  148.            mov edi,[rBase]
  149.            sub edi,128
  150.            mov [rBase],edi
  151.            sub [height],1
  152.            jnz .row_24
  153.            ret
  154. endp
  155.  
  156. align 4
  157. proc alloc_cursor
  158.  
  159.            pushfd
  160.            cli
  161.            mov ebx, [cursor_start]
  162.            mov ecx, [cursor_end]
  163. .l1:
  164.            bsf eax,[ebx];
  165.            jnz .found
  166.            add ebx,4
  167.            cmp ebx, ecx
  168.            jb .l1
  169.            popfd
  170.            xor eax,eax
  171.            ret
  172. .found:
  173.            btr [ebx], eax
  174.            popfd
  175.  
  176.            mov [cursor_start],ebx
  177.            sub ebx, cursor_map
  178.            shl ebx, 3
  179.            add eax,ebx
  180.            shl eax,3
  181.            lea eax,[cursors+eax+eax*2]
  182.  
  183.            xor ebx, ebx
  184.            mov [eax+CURSOR.magic], 'CURS'
  185.            mov [eax+CURSOR.size],  CURSOR_SIZE
  186.            mov [eax+CURSOR.pid], ebx
  187.            mov [eax+CURSOR.hot_x], ebx
  188.            mov [eax+CURSOR.hot_y], ebx
  189.            ret
  190. endp
  191.  
  192. align 4
  193. proc set_cursor stdcall, hcursor:dword
  194.            mov eax, [hcursor]
  195.            cmp [eax+CURSOR.magic], 'CURS'
  196.            jne .fail
  197.            cmp [eax+CURSOR.size], CURSOR_SIZE
  198.            jne .fail
  199.            mov ebx, [CURRENT_TASK]
  200.            shl ebx, 8
  201.            xchg eax, [ebx+PROC_BASE+APPDATA.cursor]
  202.            ret
  203. .fail:
  204.            mov eax, [def_cursor]
  205.            mov ebx, [CURRENT_TASK]
  206.            shl ebx, 8
  207.            xchg eax, [ebx+PROC_BASE+APPDATA.cursor]
  208.            ret
  209. endp
  210.  
  211. proc vesa_cursor stdcall, hcursor:dword, src:dword, flags:dword
  212.  
  213.            stdcall kernel_alloc, 0x1000
  214.            test eax, eax
  215.            jz .fail
  216.  
  217.            mov edi, [hcursor]
  218.            mov [edi+CURSOR.base], eax
  219.  
  220.            mov esi, [src]
  221.            mov ebx, [flags]
  222.            cmp bx, LOAD_INDIRECT
  223.            je .indirect
  224.  
  225.            movzx ecx, word [esi+10]
  226.            movzx edx, word [esi+12]
  227.            mov [edi+CURSOR.hot_x], ecx
  228.            mov [edi+CURSOR.hot_y], edx
  229.  
  230.            stdcall vesa_init_cursor, eax, esi
  231.            mov eax, [hcursor]
  232. .fail:
  233.            ret
  234. .indirect:
  235.            shr ebx, 16
  236.            movzx ecx, bh
  237.            movzx edx, bl
  238.            mov [eax+CURSOR.hot_x], ecx
  239.            mov [eax+CURSOR.hot_y], edx
  240.  
  241.            xchg edi, eax
  242.            mov ecx, 1024
  243.            cld
  244.            rep movsd
  245.            ret
  246. endp
  247.  
  248. align 4
  249. proc load_cursor stdcall, src:dword, flags:dword
  250.            locals
  251.              handle  dd ?
  252.            endl
  253.  
  254.            xor eax, eax
  255.            mov [handle], eax
  256.            cmp word [flags], LOAD_FROM_FILE
  257.            jne @F
  258.  
  259.            stdcall load_file, [src]
  260.            test eax, eax
  261.            jz .exit
  262.            mov [src], eax
  263. @@:
  264.            call alloc_cursor
  265.            test eax, eax
  266.            jz .fail
  267.  
  268.            mov ebx, [CURRENT_TASK]
  269.            shl ebx, 5
  270.            mov ebx, [0x3000+ebx+4]
  271.            mov [eax+CURSOR.pid], ebx
  272.  
  273.            stdcall [create_cursor], eax, [src], [flags]
  274.            mov [handle], eax
  275. .fail:
  276.            cmp word [flags], LOAD_FROM_FILE
  277.            jne .exit
  278.            stdcall kernel_free, [src]
  279. .exit:
  280.            mov eax, [handle]
  281.            ret
  282. endp
  283.  
  284. align 4
  285. proc init_cursors
  286.            movzx eax, byte [ScreenBPP]
  287.            mov ebx, [SCR_BYTES_PER_LINE]
  288.            cmp eax, 32
  289.            jne @F
  290.            sub ebx, 128
  291.            jmp .init
  292. @@:
  293.            cmp eax, 24
  294.            jne .fail
  295.            sub ebx, 96
  296. .init:
  297.            mov [cur_def_interl], ebx
  298.  
  299.            xor eax, eax
  300.            mov edi, cursors
  301.            mov ecx, CURSOR_SIZE*16
  302.            cld
  303.            rep stosd
  304.  
  305.            not eax
  306.            mov [cursor_map], eax
  307.            mov [cursor_map+4], eax
  308.            mov edx, cursor_map
  309.            mov [cursor_start], edx
  310.            add edx, 8
  311.            mov [cursor_end], edx
  312.  
  313.            stdcall load_driver, drv_hw_mouse
  314.            test eax, eax
  315.            jz .sw_mouse
  316.  
  317.            stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM
  318.            mov [def_cursor], eax
  319.            ret
  320. .sw_mouse:
  321.            mov [create_cursor], vesa_cursor
  322.  
  323.            stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM
  324.            mov [def_cursor], eax
  325.  
  326.            mov ecx, [SCR_X_SIZE]
  327.            mov edx, [SCR_Y_SIZE]
  328.            inc ecx
  329.            inc edx
  330.            mov [scr_width], ecx
  331.            mov [scr_height], edx
  332.  
  333.            movzx ebx, byte [ScreenBPP]
  334.            cmp ebx, 32
  335.            jne @F
  336.  
  337.            mov dword [set_hw_cursor], cursor_32
  338.            mov dword [hw_restore], restore_32
  339.            ret
  340. @@:
  341.            mov dword [set_hw_cursor], cursor_24
  342.            mov dword [hw_restore], restore_24
  343.            ret
  344. .fail:
  345.            xor eax, eax
  346.            mov dword [set_hw_cursor], eax
  347.            mov dword [hw_restore], eax
  348.            ret
  349. endp
  350.  
  351. align 4
  352. proc restore_24 stdcall, x:dword, y:dword
  353.            locals
  354.              w  dd ?
  355.            endl
  356.  
  357.            mov edi, [cur_saved_base]
  358.            mov edx, [cur_saved_h]
  359.            mov ebx, [cur_saved_interl]
  360.  
  361.            mov esi, cur_saved_data
  362. @@:
  363.            mov ecx, [cur_saved_w]
  364.            lea ecx, [ecx+ecx*2]
  365.            rep movsb
  366.            add edi, ebx
  367.            dec edx
  368.            jnz @B
  369.            ret
  370. endp
  371.  
  372. align 4
  373. proc restore_32 stdcall, x:dword, y:dword
  374.            locals
  375.              w  dd ?
  376.            endl
  377.  
  378.            mov edi, [cur_saved_base]
  379.            mov edx, [cur_saved_h]
  380.            mov ebx, [cur_saved_interl]
  381.  
  382.            mov esi, cur_saved_data
  383. @@:
  384.            mov ecx, [cur_saved_w]
  385.            rep movsd
  386.            add edi, ebx
  387.            dec edx
  388.            jnz @B
  389.            ret
  390. endp
  391.  
  392. align 4
  393. proc cursor_24 stdcall, hcursor:dword, x:dword, y:dword
  394.            locals
  395.              w      dd ?
  396.              h      dd ?
  397.              st     dd ?
  398.              _dx     dd ?
  399.              _dy     dd ?
  400.            endl
  401.  
  402.            mov esi, [hcursor]
  403.            mov ecx, [x]
  404.            mov eax, [y]
  405.            mov ebx, [BytesPerScanLine]
  406.  
  407.            xor edx, edx
  408.            sub ecx, [esi+CURSOR.hot_x]
  409.            mov [x], ecx
  410.            sets dl
  411.            dec edx
  412.            and ecx, edx       ;clip x to 0<=x
  413.            mov edi, ecx
  414.            sub edi, [x]
  415.            mov [_dx], edi
  416.  
  417.            xor edx, edx
  418.            sub eax, [esi+CURSOR.hot_y]
  419.            mov [y], eax
  420.            sets dl
  421.            dec edx
  422.            and eax, edx       ;clip y to 0<=y
  423.            mov edi, eax
  424.            sub edi, [y]
  425.            mov [_dy], edi
  426.  
  427.            mul ebx
  428.            lea esi, [ecx+ecx*2]
  429.            add esi, [LFBAddress]
  430.            add esi, eax
  431.            mov [cur_saved_base],esi
  432.  
  433.            mov edi, [scr_width]
  434.            mov edx, [scr_height]
  435.            mov eax, 32
  436.  
  437.            sub edi, ecx
  438.            cmp edi, eax
  439.            jng @F
  440.            mov edi, eax
  441. @@:
  442.            sub edi, [_dx]
  443.  
  444.            sub edx, [y]
  445.            cmp edx, eax
  446.            jng @F
  447.            mov edx, eax
  448. @@:
  449.            sub edx, [_dy]
  450.  
  451.            mov [w], edi
  452.            mov [h], edx
  453.            mov [cur_saved_w], edi
  454.            mov [cur_saved_h], edx
  455.  
  456.            sub eax, edi
  457.            shl eax, 2       ;lea eax, [eax+eax*2]
  458.            lea edi, [edi+edi*2]
  459.            sub ebx, edi
  460.            mov [cur_saved_interl], ebx
  461.  
  462.            mov edi, cur_saved_data
  463. @@:
  464.            mov ecx, [w]
  465.            lea ecx, [ecx+ecx*2]
  466.            rep movsb
  467.            add esi, ebx
  468.            dec edx
  469.            jnz @B
  470.  
  471. ;draw cursor
  472.            mov edx, eax
  473.            mov edi, [cur_saved_base]
  474.            mov eax, [_dy]
  475.            shl eax, 5
  476.            add eax, [_dx]
  477.            shl eax, 2
  478.  
  479.            mov esi, [hcursor]
  480.            mov esi, [esi+CURSOR.base]
  481.            add esi, eax
  482. .row:
  483.            mov ecx, [w]
  484. .pix:
  485.            lodsd
  486.            test eax, 0xFF000000
  487.            jz @F
  488.  
  489.            mov word [edi], ax
  490.            shr eax, 16
  491.            mov [edi+2],al
  492. @@:
  493.            add edi, 3
  494.            dec ecx
  495.            jnz .pix
  496.  
  497.            add esi, edx
  498.            add edi, ebx
  499.            dec [h]
  500.            jnz .row
  501.            ret
  502. endp
  503.  
  504. align 4
  505. proc cursor_32 stdcall, hcursor:dword, x:dword, y:dword
  506.            locals
  507.              w      dd ?
  508.              h      dd ?
  509.              st     dd ?
  510.              _dx     dd ?
  511.              _dy     dd ?
  512.            endl
  513.  
  514.            mov esi, [hcursor]
  515.            mov ecx, [x]
  516.            mov eax, [y]
  517.            mov ebx, [BytesPerScanLine]
  518.  
  519.            xor edx, edx
  520.            sub ecx, [esi+CURSOR.hot_x]
  521.            mov [x], ecx
  522.            sets dl
  523.            dec edx
  524.            and ecx, edx       ;clip x to 0<=x
  525.            mov edi, ecx
  526.            sub edi, [x]
  527.            mov [_dx], edi
  528.  
  529.            xor edx, edx
  530.            sub eax, [esi+CURSOR.hot_y]
  531.            mov [y], eax
  532.            sets dl
  533.            dec edx
  534.            and eax, edx       ;clip y to 0<=y
  535.            mov edi, eax
  536.            sub edi, [y]
  537.            mov [_dy], edi
  538.  
  539.            mul ebx
  540.            lea esi, [eax+ecx*4]
  541.            add esi, [LFBAddress]
  542.            mov [cur_saved_base],esi
  543.  
  544.            mov edi, [scr_width]
  545.            mov edx, [scr_height]
  546.            mov eax, 32
  547.  
  548.            sub edi, ecx
  549.            cmp edi, eax
  550.            jng @F
  551.            mov edi, eax
  552. @@:
  553.            sub edi, [_dx]
  554.  
  555.            sub edx, [y]
  556.            cmp edx, eax
  557.            jng @F
  558.            mov edx, eax
  559. @@:
  560.            sub edx, [_dy]
  561.  
  562.            mov [w], edi
  563.            mov [h], edx
  564.            mov [cur_saved_w], edi
  565.            mov [cur_saved_h], edx
  566.  
  567.            sub eax, edi
  568.            shl eax, 2
  569.            shl edi, 2
  570.            sub ebx, edi
  571.            mov [cur_saved_interl], ebx
  572.  
  573.            mov edi, cur_saved_data
  574. @@:
  575.            mov ecx, [w]
  576.            rep movsd
  577.            add esi, ebx
  578.            dec edx
  579.            jnz @B
  580.  
  581. ;draw cursor
  582.            mov edx, eax
  583.            mov edi, [cur_saved_base]
  584.            mov eax, [_dy]
  585.            shl eax, 5
  586.            add eax, [_dx]
  587.            shl eax, 2
  588.  
  589.            mov esi, [hcursor]
  590.            mov esi, [esi+CURSOR.base]
  591.            add esi, eax
  592. .row:
  593.            mov ecx, [w]
  594. .pix:
  595.            lodsd
  596.            test eax, 0xFF000000
  597.            jz @F
  598.            mov [edi], eax
  599. @@:
  600.            add edi, 4
  601.            dec ecx
  602.            jnz .pix
  603.            add esi, edx
  604.            add edi, ebx
  605.            dec [h]
  606.            jnz .row
  607.            ret
  608. endp
  609.  
  610. align 4
  611. def_arrow:
  612.   file 'arrow.cur'
  613.  
  614.