Subversion Repositories Kolibri OS

Rev

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