Subversion Repositories Kolibri OS

Rev

Rev 221 | Rev 227 | 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.  
  155. endp
  156.  
  157. align 4
  158. proc alloc_cursor
  159.  
  160.            pushfd
  161.            cli
  162.            mov ebx, [cursor_start]
  163.            mov ecx, [cursor_end]
  164. .l1:
  165.            bsf eax,[ebx];
  166.            jnz .found
  167.            add ebx,4
  168.            cmp ebx, ecx
  169.            jb .l1
  170.            popfd
  171.            xor eax,eax
  172.            ret
  173. .found:
  174.            btr [ebx], eax
  175.            mov [cursor_start],ebx
  176.            sub ebx, cursor_map
  177.            shl ebx, 3
  178.            add eax,ebx
  179.            shl eax,3
  180.            lea eax,[cursors+eax+eax*2]
  181.            popfd
  182.            ret
  183. endp
  184.  
  185. align 4
  186. proc create_cursor
  187.            locals
  188.              h_cur  dd ?
  189.            endl
  190.  
  191.            call alloc_cursor
  192.            test eax, eax
  193.            jz .fail
  194.  
  195.            mov [h_cur], eax
  196.            mov edi, eax
  197.  
  198.            xor ebx, ebx
  199.  
  200.            mov [edi+CURSOR.magic], 'CURS'
  201.            mov [edi+CURSOR.size],  CURSOR_SIZE
  202.            mov [edi+CURSOR.pid], ebx
  203.            mov [edi+CURSOR.hot_x], ebx
  204.            mov [edi+CURSOR.hot_y], ebx
  205.  
  206.            stdcall kernel_alloc, dword 0x2000
  207.            test eax, eax
  208.            jz .fail
  209.  
  210.            mov ebx, eax
  211.            mov eax, [h_cur]
  212.            mov [eax+CURSOR.base], ebx
  213.            ret
  214. .fail:
  215.            ret
  216. endp
  217.  
  218. align 4
  219. proc set_cursor stdcall, hcursor:dword
  220.            mov eax, [hcursor]
  221.            mov ebx, [CURRENT_TASK]
  222.            shl ebx, 8
  223.            xchg eax, [ebx+PROC_BASE+APPDATA.cursor]
  224.            ret
  225. endp
  226.  
  227. align 4
  228. proc load_cursor stdcall, src:dword, flags:dword
  229.            locals
  230.              handle  dd ?
  231.            endl
  232.  
  233.            movzx eax, word [flags]
  234.            cmp eax, LOAD_FROM_FILE
  235.            jne .from_mem
  236.  
  237.            stdcall load_file, [src]
  238.            test eax, eax
  239.            jz .exit
  240.            mov [src], eax
  241.  
  242.            call create_cursor
  243.            test eax, eax
  244.            jz .fail
  245.  
  246.            mov [handle], eax
  247.            mov esi, [src]
  248.            movzx ebx, word [esi+10]
  249.            movzx ecx, word [esi+12]
  250.            mov [eax+CURSOR.hot_x], ebx
  251.            mov [eax+CURSOR.hot_y], ecx
  252.  
  253.            stdcall vesa_init_cursor, [eax+CURSOR.base], esi
  254.            stdcall kernel_free, [src]
  255.            mov eax, [handle]
  256.            ret
  257.  
  258. .from_mem:
  259.            cmp eax, LOAD_FROM_MEM
  260.            jne .indirect
  261.  
  262.            call create_cursor
  263.            test eax, eax
  264.            jz .exit
  265.  
  266.            mov [handle], eax
  267.            mov esi, [src]
  268.            movzx ebx, word [esi+10]
  269.            movzx ecx, word [esi+12]
  270.            mov [eax+CURSOR.hot_x], ebx
  271.            mov [eax+CURSOR.hot_y], ecx
  272.  
  273.            stdcall vesa_init_cursor, [eax+CURSOR.base], [src]
  274.            mov eax, [handle]
  275.            ret
  276.  
  277. .indirect:
  278.            cmp eax, LOAD_INDIRECT
  279.            jne .fail
  280.  
  281.            call create_cursor
  282.            test eax, eax
  283.            jz .exit
  284.  
  285.            movzx edx, byte [flags+2]
  286.            movzx ebx, byte [flags+3]
  287.            mov [eax+CURSOR.hot_x], ebx
  288.            mov [eax+CURSOR.hot_y], edx
  289.  
  290.            mov edi, [eax+CURSOR.base]
  291.            mov esi, [src]
  292.            mov ecx, 1024
  293.            cld
  294.            rep movsd
  295.            ret
  296. .fail:
  297.            mov ebx, [src]
  298.            stdcall kernel_free, ebx
  299. .exit:
  300.            xor eax, eax
  301.            ret
  302. endp
  303.  
  304. align 4
  305. proc init_cursors
  306.            movzx eax, byte [ScreenBPP]
  307.            mov ebx, [SCR_BYTES_PER_LINE]
  308.            cmp eax, 32
  309.            jne @F
  310.            sub ebx, 128
  311.            jmp .init
  312. @@:
  313.            cmp eax, 24
  314.            jne .fail
  315.            sub ebx, 96
  316. .init:
  317.            mov [cur_def_interl], ebx
  318.  
  319.            xor eax, eax
  320.            mov edi, cursors
  321.            mov ecx, CURSOR_SIZE*16
  322.            cld
  323.            rep stosd
  324.  
  325.            not eax
  326.            mov [cursor_map], eax
  327.            mov [cursor_map+4], eax
  328.            mov edx, cursor_map
  329.            mov [cursor_start], edx
  330.            add edx, 4
  331.            mov [cursor_end], edx
  332.  
  333.            stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM
  334.            mov [def_cursor], eax
  335.  
  336.            mov ecx, [SCR_X_SIZE]
  337.            mov edx, [SCR_Y_SIZE]
  338.            inc ecx
  339.            inc edx
  340.            mov [scr_width], ecx
  341.            mov [scr_height], edx
  342.  
  343.            movzx ebx, byte [ScreenBPP]
  344.            cmp ebx, 32
  345.            jne @F
  346.  
  347.            mov dword [set_hw_cursor], cursor_32
  348.            mov dword [hw_restore], restore_32
  349.            ret
  350. @@:
  351.            mov dword [set_hw_cursor], cursor_24
  352.            mov dword [hw_restore], restore_24
  353.            ret
  354. .fail:
  355.            xor eax, eax
  356.            mov dword [set_hw_cursor], eax
  357.            mov dword [hw_restore], eax
  358.            ret
  359. endp
  360.  
  361. align 4
  362. proc restore_24 stdcall, x:dword, y:dword
  363.            locals
  364.              w  dd ?
  365.            endl
  366.  
  367.            mov edi, [cur_saved_base]
  368.            mov edx, [cur_saved_h]
  369.            mov ebx, [cur_saved_interl]
  370.  
  371.            mov esi, cur_saved_data
  372. @@:
  373.            mov ecx, [cur_saved_w]
  374.            lea ecx, [ecx+ecx*2]
  375.            rep movsb
  376.            add edi, ebx
  377.            dec edx
  378.            jnz @B
  379.            ret
  380. endp
  381.  
  382. align 4
  383. proc restore_32 stdcall, x:dword, y:dword
  384.            locals
  385.              w  dd ?
  386.            endl
  387.  
  388.            mov edi, [cur_saved_base]
  389.            mov edx, [cur_saved_h]
  390.            mov ebx, [cur_saved_interl]
  391.  
  392.            mov esi, cur_saved_data
  393. @@:
  394.            mov ecx, [cur_saved_w]
  395.            rep movsd
  396.            add edi, ebx
  397.            dec edx
  398.            jnz @B
  399.            ret
  400. endp
  401.  
  402. align 4
  403. proc cursor_24 stdcall, hcursor:dword, x:dword, y:dword
  404.            locals
  405.              w      dd ?
  406.              h      dd ?
  407.              st     dd ?
  408.              _dx     dd ?
  409.              _dy     dd ?
  410.            endl
  411.  
  412.            mov esi, [hcursor]
  413.            mov ecx, [x]
  414.            mov eax, [y]
  415.            mov ebx, [BytesPerScanLine]
  416.  
  417.            xor edx, edx
  418.            sub ecx, [esi+CURSOR.hot_x]
  419.            mov [x], ecx
  420.            sets dl
  421.            dec edx
  422.            and ecx, edx       ;clip x to 0<=x
  423.            mov edi, ecx
  424.            sub edi, [x]
  425.            mov [_dx], edi
  426.  
  427.            xor edx, edx
  428.            sub eax, [esi+CURSOR.hot_y]
  429.            mov [y], eax
  430.            sets dl
  431.            dec edx
  432.            and eax, edx       ;clip y to 0<=y
  433.            mov edi, eax
  434.            sub edi, [y]
  435.            mov [_dy], edi
  436.  
  437.            mul ebx
  438.            lea esi, [ecx+ecx*2]
  439.            add esi, [LFBAddress]
  440.            add esi, eax
  441.            mov [cur_saved_base],esi
  442.  
  443.            mov edi, [scr_width]
  444.            mov edx, [scr_height]
  445.            mov eax, 32
  446.  
  447.            sub edi, ecx
  448.            cmp edi, eax
  449.            ;cmovg edi, eax
  450.            jng @F
  451.            mov edi, eax
  452. @@:
  453.            sub edi, [_dx]
  454.  
  455.            sub edx, [y]
  456.            cmp edx, eax
  457.            ;cmovg edx, eax
  458.            jng @F
  459.            mov edx, eax
  460. @@:
  461.            sub edx, [_dy]
  462.  
  463.            mov [w], edi
  464.            mov [h], edx
  465.            mov [cur_saved_w], edi
  466.            mov [cur_saved_h], edx
  467.  
  468.            sub eax, edi
  469.            shl eax, 2       ;lea eax, [eax+eax*2]
  470.            lea edi, [edi+edi*2]
  471.            sub ebx, edi
  472.            mov [cur_saved_interl], ebx
  473.  
  474.            mov edi, cur_saved_data
  475. @@:
  476.            mov ecx, [w]
  477.            lea ecx, [ecx+ecx*2]
  478.            rep movsb
  479.            add esi, ebx
  480.            dec edx
  481.            jnz @B
  482.  
  483. ;draw cursor
  484.            mov edx, eax
  485.            mov edi, [cur_saved_base]
  486.            mov eax, [_dy]
  487.            shl eax, 5
  488.            add eax, [_dx]
  489.            shl eax, 2
  490.  
  491.            mov esi, [hcursor]
  492.            mov esi, [esi+CURSOR.base]
  493.            add esi, eax
  494. .row:
  495.            mov ecx, [w]
  496. .pix:
  497.            lodsd
  498.            test eax, 0xFF000000
  499.            jz @F
  500.  
  501.            mov word [edi], ax
  502.            shr eax, 16
  503.            mov [edi+2],al
  504. @@:
  505.            add edi, 3
  506.            dec ecx
  507.            jnz .pix
  508.  
  509.            add esi, edx
  510.            add edi, ebx
  511.            dec [h]
  512.            jnz .row
  513.            ret
  514. endp
  515.  
  516. align 4
  517. proc cursor_32 stdcall, hcursor:dword, x:dword, y:dword
  518.            locals
  519.              w      dd ?
  520.              h      dd ?
  521.              st     dd ?
  522.              _dx     dd ?
  523.              _dy     dd ?
  524.            endl
  525.  
  526.            mov esi, [hcursor]
  527.            mov ecx, [x]
  528.            mov eax, [y]
  529.            mov ebx, [BytesPerScanLine]
  530.  
  531.            xor edx, edx
  532.            sub ecx, [esi+CURSOR.hot_x]
  533.            mov [x], ecx
  534.            sets dl
  535.            dec edx
  536.            and ecx, edx       ;clip x to 0<=x
  537.            mov edi, ecx
  538.            sub edi, [x]
  539.            mov [_dx], edi
  540.  
  541.            xor edx, edx
  542.            sub eax, [esi+CURSOR.hot_y]
  543.            mov [y], eax
  544.            sets dl
  545.            dec edx
  546.            and eax, edx       ;clip y to 0<=y
  547.            mov edi, eax
  548.            sub edi, [y]
  549.            mov [_dy], edi
  550.  
  551.            mul ebx
  552.            lea esi, [eax+ecx*4]
  553.            add esi, [LFBAddress]
  554.            mov [cur_saved_base],esi
  555.  
  556.            mov edi, [scr_width]
  557.            mov edx, [scr_height]
  558.            mov eax, 32
  559.  
  560.            sub edi, ecx
  561.            cmp edi, eax
  562. ;           cmovg edi, eax
  563.            jng @F
  564.            mov edi, eax
  565. @@:
  566.            sub edi, [_dx]
  567.  
  568.            sub edx, [y]
  569.            cmp edx, eax
  570. ;           cmovg edx, eax
  571.            jng @F
  572.            mov edx, eax
  573. @@:
  574.            sub edx, [_dy]
  575.  
  576.            mov [w], edi
  577.            mov [h], edx
  578.            mov [cur_saved_w], edi
  579.            mov [cur_saved_h], edx
  580.  
  581.            sub eax, edi
  582.            shl eax, 2
  583.            shl edi, 2
  584.            sub ebx, edi
  585.            mov [cur_saved_interl], ebx
  586.  
  587.            mov edi, cur_saved_data
  588. @@:
  589.            mov ecx, [w]
  590.            rep movsd
  591.            add esi, ebx
  592.            dec edx
  593.            jnz @B
  594.  
  595. ;draw cursor
  596.            mov edx, eax
  597.            mov edi, [cur_saved_base]
  598.            mov eax, [_dy]
  599.            shl eax, 5
  600.            add eax, [_dx]
  601.            shl eax, 2
  602.  
  603.            mov esi, [hcursor]
  604.            mov esi, [esi+CURSOR.base]
  605.            add esi, eax
  606. .row:
  607.            mov ecx, [w]
  608. .pix:
  609.            lodsd
  610.            test eax, 0xFF000000
  611.            jz @F
  612.            mov [edi], eax
  613. @@:
  614.            add edi, 4
  615.            dec ecx
  616.            jnz .pix
  617.            add esi, edx
  618.            add edi, ebx
  619.            dec [h]
  620.            jnz .row
  621.            ret
  622. endp
  623.  
  624. align 4
  625. def_arrow:
  626.   file 'arrow.cur'
  627.  
  628.