Subversion Repositories Kolibri OS

Rev

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