Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2018. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 9692 $
  9.  
  10.  
  11. LOAD_FROM_FILE  = 0
  12. LOAD_FROM_MEM   = 1
  13. LOAD_INDIRECT   = 2
  14. LOAD_SYSTEM     = 3
  15.  
  16. struct  BITMAPINFOHEADER
  17.         Size                    dd ?
  18.         Width                   dd ?
  19.         Height                  dd ?
  20.         Planes                  dw ?
  21.         BitCount                dw ?
  22.         Compression             dd ?
  23.         SizeImage               dd ?
  24.         XPelsPerMeter           dd ?
  25.         YPelsPerMeter           dd ?
  26.         ClrUsed                 dd ?
  27.         ClrImportant            dd ?
  28. ends
  29. ;------------------------------------------------------------------------------
  30. align 4
  31. proc init_cursor stdcall, dst:dword, src:dword
  32.            locals
  33.              rBase    dd ?
  34.              pQuad    dd ?
  35.              pBits    dd ?
  36.              pAnd     dd ?
  37.              width    dd ?
  38.              height   dd ?
  39.              counter  dd ?
  40.            endl
  41.  
  42.         mov     esi, [src]
  43.         add     esi, [esi+18]
  44.         mov     eax, esi
  45.  
  46.         cmp     [esi+BITMAPINFOHEADER.BitCount], 24
  47.         je      .img_24
  48.         cmp     [esi+BITMAPINFOHEADER.BitCount], 8
  49.         je      .img_8
  50.         cmp     [esi+BITMAPINFOHEADER.BitCount], 4
  51.         je      .img_4
  52. ;--------------------------------------
  53. align 4
  54. .img_2:
  55.         add     eax, [esi]
  56.         mov     [pQuad], eax
  57.         add     eax, 8
  58.         mov     [pBits], eax
  59.         add     eax, 128
  60.         mov     [pAnd], eax
  61.         mov     eax, [esi+4]
  62.         mov     [width], eax
  63.         mov     ebx, [esi+8]
  64.         shr     ebx, 1
  65.         mov     [height], ebx
  66.  
  67.         mov     edi, [dst]
  68.         add     edi, 32*31*4
  69.         mov     [rBase], edi
  70.  
  71.         mov     esi, [pQuad]
  72. ;--------------------------------------
  73. align 4
  74. .l21:
  75.         mov     ebx, [pBits]
  76.         mov     ebx, [ebx]
  77.         bswap   ebx
  78.         mov     eax, [pAnd]
  79.         mov     eax, [eax]
  80.         bswap   eax
  81.         mov     [counter], 32
  82. ;--------------------------------------
  83. align 4
  84. @@:
  85.         xor     edx, edx
  86.         shl     eax, 1
  87.         setc    dl
  88.         dec     edx
  89.  
  90.         xor     ecx, ecx
  91.         shl     ebx, 1
  92.         setc    cl
  93.         mov     ecx, [esi+ecx*4]
  94.         and     ecx, edx
  95.         and     edx, 0xFF000000
  96.         or      edx, ecx
  97.         mov     [edi], edx
  98.  
  99.         add     edi, 4
  100.         dec     [counter]
  101.         jnz     @B
  102.  
  103.         add     [pBits], 4
  104.         add     [pAnd], 4
  105.         mov     edi, [rBase]
  106.         sub     edi, 128
  107.         mov     [rBase], edi
  108.         sub     [height], 1
  109.         jnz     .l21
  110.         ret
  111. ;--------------------------------------
  112. align 4
  113. .img_4:
  114.         add     eax, [esi]
  115.         mov     [pQuad], eax
  116.         add     eax, 64
  117.         mov     [pBits], eax
  118.         add     eax, 0x200
  119.         mov     [pAnd], eax
  120.         mov     eax, [esi+4]
  121.         mov     [width], eax
  122.         mov     ebx, [esi+8]
  123.         shr     ebx, 1
  124.         mov     [height], ebx
  125.  
  126.         mov     edi, [dst]
  127.         add     edi, 32*31*4
  128.         mov     [rBase], edi
  129.  
  130.         mov     esi, [pQuad]
  131.         mov     ebx, [pBits]
  132. ;--------------------------------------
  133. align 4
  134. .l4:
  135.         mov     eax, [pAnd]
  136.         mov     eax, [eax]
  137.         bswap   eax
  138.         mov     [counter], 16
  139. ;--------------------------------------
  140. align 4
  141. @@:
  142.         xor     edx, edx
  143.         shl     eax, 1
  144.         setc    dl
  145.         dec     edx
  146.  
  147.         movzx   ecx, byte [ebx]
  148.         and     cl, 0xF0
  149.         shr     ecx, 2
  150.         mov     ecx, [esi+ecx]
  151.         and     ecx, edx
  152.         and     edx, 0xFF000000
  153.         or      edx, ecx
  154.         mov     [edi], edx
  155.  
  156.         xor     edx, edx
  157.         shl     eax, 1
  158.         setc    dl
  159.         dec     edx
  160.  
  161.         movzx   ecx, byte [ebx]
  162.         and     cl, 0x0F
  163.         mov     ecx, [esi+ecx*4]
  164.         and     ecx, edx
  165.         and     edx, 0xFF000000
  166.         or      edx, ecx
  167.         mov     [edi+4], edx
  168.  
  169.         inc     ebx
  170.         add     edi, 8
  171.         dec     [counter]
  172.         jnz     @B
  173.  
  174.         add     [pAnd], 4
  175.         mov     edi, [rBase]
  176.         sub     edi, 128
  177.         mov     [rBase], edi
  178.         sub     [height], 1
  179.         jnz     .l4
  180.         ret
  181. ;--------------------------------------
  182. align 4
  183. .img_8:
  184.         add     eax, [esi]
  185.         mov     [pQuad], eax
  186.         add     eax, 1024
  187.         mov     [pBits], eax
  188.         add     eax, 1024
  189.         mov     [pAnd], eax
  190.         mov     eax, [esi+4]
  191.         mov     [width], eax
  192.         mov     ebx, [esi+8]
  193.         shr     ebx, 1
  194.         mov     [height], ebx
  195.  
  196.         mov     edi, [dst]
  197.         add     edi, 32*31*4
  198.         mov     [rBase], edi
  199.  
  200.         mov     esi, [pQuad]
  201.         mov     ebx, [pBits]
  202. ;--------------------------------------
  203. align 4
  204. .l81:
  205.         mov     eax, [pAnd]
  206.         mov     eax, [eax]
  207.         bswap   eax
  208.         mov     [counter], 32
  209. ;--------------------------------------
  210. align 4
  211. @@:
  212.         xor     edx, edx
  213.         shl     eax, 1
  214.         setc    dl
  215.         dec     edx
  216.  
  217.         movzx   ecx, byte [ebx]
  218.         mov     ecx, [esi+ecx*4]
  219.         and     ecx, edx
  220.         and     edx, 0xFF000000
  221.         or      edx, ecx
  222.         mov     [edi], edx
  223.  
  224.         inc     ebx
  225.         add     edi, 4
  226.         dec     [counter]
  227.         jnz     @B
  228.  
  229.         add     [pAnd], 4
  230.         mov     edi, [rBase]
  231.         sub     edi, 128
  232.         mov     [rBase], edi
  233.         sub     [height], 1
  234.         jnz     .l81
  235.         ret
  236. ;--------------------------------------
  237. align 4
  238. .img_24:
  239.         add     eax, [esi]
  240.         mov     [pQuad], eax
  241.         add     eax, 0xC00
  242.         mov     [pAnd], eax
  243.         mov     eax, [esi+BITMAPINFOHEADER.Width]
  244.         mov     [width], eax
  245.         mov     ebx, [esi+BITMAPINFOHEADER.Height]
  246.         shr     ebx, 1
  247.         mov     [height], ebx
  248.  
  249.         mov     edi, [dst]
  250.         add     edi, 32*31*4
  251.         mov     [rBase], edi
  252.  
  253.         mov     esi, [pAnd]
  254.         mov     ebx, [pQuad]
  255. ;--------------------------------------
  256. align 4
  257. .row_24:
  258.         mov     eax, [esi]
  259.         bswap   eax
  260.         mov     [counter], 32
  261. ;--------------------------------------
  262. align 4
  263. @@:
  264.         xor     edx, edx
  265.         shl     eax, 1
  266.         setc    dl
  267.         dec     edx
  268.  
  269.         mov     ecx, [ebx]
  270.         and     ecx, 0x00FFFFFF
  271.         and     ecx, edx
  272.         and     edx, 0xFF000000
  273.         or      edx, ecx
  274.         mov     [edi], edx
  275.         add     ebx, 3
  276.         add     edi, 4
  277.         dec     [counter]
  278.         jnz     @B
  279.  
  280.         add     esi, 4
  281.         mov     edi, [rBase]
  282.         sub     edi, 128
  283.         mov     [rBase], edi
  284.         sub     [height], 1
  285.         jnz     .row_24
  286.         ret
  287. endp
  288. ;------------------------------------------------------------------------------
  289. align 4
  290. proc set_cursor stdcall, hcursor:dword
  291.         mov     eax, [hcursor]
  292.         cmp     [eax+CURSOR.magic], 'CURS'
  293.         jne     .fail
  294. ;           cmp [eax+CURSOR.size], CURSOR_SIZE
  295. ;           jne .fail
  296.         mov     ebx, [current_slot]
  297.         xchg    eax, [ebx+APPDATA.cursor]
  298.         jmp     .end
  299. ;--------------------------------------
  300. align 4
  301. .fail:
  302.         mov     eax, [def_cursor]
  303.         mov     ebx, [current_slot]
  304.         xchg    eax, [ebx+APPDATA.cursor]
  305. align 4
  306. .end:
  307.         mov     [redrawmouse_unconditional], 1
  308.         call    __sys_draw_pointer
  309.         ret
  310. endp
  311. ;------------------------------------------------------------------------------
  312. align 4
  313. ; param
  314. ;  eax= pid
  315. ;  ebx= src
  316. ;  ecx= flags
  317.  
  318. create_cursor:
  319. .src     equ esp
  320. .flags   equ esp+4
  321. .hcursor equ esp+8
  322.  
  323.         sub     esp, 4         ;space for .hcursor
  324.         push    ecx
  325.         push    ebx
  326.  
  327.         mov     ebx, eax
  328.         mov     eax, sizeof.CURSOR
  329.         call    create_kernel_object
  330.         test    eax, eax
  331.         jz      .fail
  332.  
  333.         mov     [.hcursor], eax
  334.  
  335.         xor     ebx, ebx
  336.         mov     [eax+CURSOR.magic], 'CURS'
  337.         mov     [eax+CURSOR.destroy], destroy_cursor
  338.         mov     [eax+CURSOR.hot_x], ebx
  339.         mov     [eax+CURSOR.hot_y], ebx
  340.  
  341.         stdcall kernel_alloc, 0x1000
  342.         test    eax, eax
  343.         jz      .fail
  344.  
  345.         mov     edi, [.hcursor]
  346.         mov     [edi+CURSOR.base], eax
  347.  
  348.         mov     esi, [.src]
  349.         mov     ebx, [.flags]
  350.         cmp     bx, LOAD_INDIRECT
  351.         je      .indirect
  352.  
  353.         movzx   ecx, word [esi+10]
  354.         movzx   edx, word [esi+12]
  355.         mov     [edi+CURSOR.hot_x], ecx
  356.         mov     [edi+CURSOR.hot_y], edx
  357.  
  358.         stdcall init_cursor, eax, esi
  359.  
  360. align 4
  361. .add_cursor:
  362.         mov     ecx, [.hcursor]
  363.         lea     ecx, [ecx+CURSOR.list_next]
  364.         lea     edx, [_display.cr_list.next]
  365.  
  366.         pushfd
  367.         cli
  368.         list_add ecx, edx   ;list_add_tail(new, head)
  369.         popfd
  370.  
  371.         mov     eax, [.hcursor]
  372.         cmp     [_display.init_cursor], 0
  373.         je      .fail
  374.  
  375.         push    eax
  376.         call    [_display.init_cursor]
  377.         add     esp, 4
  378.  
  379.         mov     eax, [.hcursor]
  380. ;--------------------------------------
  381. align 4
  382. .fail:
  383.         add     esp, 12
  384.         ret
  385. ;--------------------------------------
  386. align 4
  387. .indirect:
  388.         shr     ebx, 16
  389.         movzx   ecx, bh
  390.         movzx   edx, bl
  391.         mov     [edi+CURSOR.hot_x], ecx
  392.         mov     [edi+CURSOR.hot_y], edx
  393.  
  394.         xchg    edi, eax
  395.         mov     ecx, 1024
  396.         cld
  397.         rep movsd
  398.         jmp     .add_cursor
  399. ;------------------------------------------------------------------------------
  400. align 4
  401. proc load_cursor stdcall, src:dword, flags:dword
  402.            locals
  403.              handle  dd ?
  404.            endl
  405.  
  406.         xor     eax, eax
  407.         cmp     [create_cursor], eax
  408.         je      .fail2
  409.  
  410.         mov     [handle], eax
  411.         cmp     word [flags], LOAD_FROM_FILE
  412.         jne     @F
  413.  
  414.         stdcall load_file, [src]
  415.         test    eax, eax
  416.         jz      .fail
  417.         mov     [src], eax
  418. ;--------------------------------------
  419. align 4
  420. @@:
  421.         push    ebx
  422.         push    esi
  423.         push    edi
  424.  
  425.         mov     eax, [current_slot_idx]
  426.         shl     eax, 8
  427.         mov     eax, [eax + SLOT_BASE + APPDATA.tid]
  428.         mov     ebx, [src]
  429.         mov     ecx, [flags]
  430.         call    create_cursor    ;eax, ebx, ecx
  431.         mov     [handle], eax
  432.  
  433.         cmp     word [flags], LOAD_FROM_FILE
  434.         jne     .exit
  435.         stdcall kernel_free, [src]
  436. ;--------------------------------------
  437. align 4
  438. .exit:
  439.         pop     edi
  440.         pop     esi
  441.         pop     ebx
  442. ;--------------------------------------
  443. align 4
  444. .fail:
  445.         mov     eax, [handle]
  446. ;--------------------------------------
  447. align 4
  448. .fail2:
  449.         ret
  450. endp
  451. ;------------------------------------------------------------------------------
  452. align 4
  453. proc delete_cursor stdcall, hcursor:dword
  454.  
  455. ;        DEBUGF 1,'K : delete_cursor %x\n', [hcursor]
  456.  
  457.         mov     esi, [hcursor]
  458.  
  459.         cmp     [esi+CURSOR.magic], 'CURS'
  460.         jne     .fail
  461.  
  462.         mov     ebx, [current_slot_idx]
  463.         ;shl     ebx, 5
  464.         ;mov     ebx, [TASK_TABLE+ebx+4]
  465.         shl     ebx, 8
  466.         mov     ebx, [ebx + SLOT_BASE + APPDATA.tid]
  467.         cmp     ebx, [esi+CURSOR.pid]
  468.         jne     .fail
  469.  
  470.         mov     ebx, [current_slot]
  471.         cmp     esi, [ebx+APPDATA.cursor]
  472.         jne     @F
  473.         mov     eax, [def_cursor]
  474.         mov     [ebx+APPDATA.cursor], eax
  475. ;--------------------------------------
  476. align 4
  477. @@:
  478.         mov     eax, [hcursor]
  479.         call    [eax+APPOBJ.destroy]
  480. ;--------------------------------------
  481. align 4
  482. .fail:
  483.         ret
  484. endp
  485. ;------------------------------------------------------------------------------
  486. align 4
  487. ; param
  488. ;  eax= cursor
  489. destroy_cursor:
  490.  
  491.         push    eax
  492.         stdcall kernel_free, [eax+CURSOR.base]
  493.  
  494.         mov     eax, [esp]
  495.         lea     eax, [eax+CURSOR.list_next]
  496.  
  497.         pushfd
  498.         cli
  499.         list_del eax
  500.         popfd
  501.  
  502.         pop     eax
  503.         call    destroy_kernel_object
  504.         ret
  505. ;------------------------------------------------------------------------------
  506. align 4
  507. select_cursor:
  508.         mov     eax, [esp+4]
  509.         mov     [_display.cursor], eax
  510.         ret     4
  511. ;------------------------------------------------------------------------------
  512. align 4
  513. proc restore_24 stdcall, x:dword, y:dword
  514.  
  515.         push    ebx
  516.  
  517.         mov     ebx, [cur_saved_base]
  518.         mov     edx, [cur.h]
  519.         test    edx, edx
  520.         jz      .ret
  521.  
  522.         push    esi
  523.         push    edi
  524.  
  525.         mov     esi, cur_saved_data
  526.         mov     ecx, [cur.w]
  527.         lea     ecx, [ecx+ecx*2]
  528.         push    ecx
  529. ;--------------------------------------
  530. align 4
  531. @@:
  532.         mov     edi, ebx
  533.         add     ebx, [_display.lfb_pitch]
  534.  
  535.         mov     ecx, [esp]
  536.         rep movsb
  537.         dec     edx
  538.         jnz     @B
  539.  
  540.         pop     ecx
  541.         pop     edi
  542.         pop     esi
  543. ;--------------------------------------
  544. align 4
  545. .ret:
  546.         pop     ebx
  547.         ret
  548. endp
  549. ;------------------------------------------------------------------------------
  550. align 4
  551. proc restore_32 stdcall, x:dword, y:dword
  552.  
  553.         push    ebx
  554.  
  555.         mov     ebx, [cur_saved_base]
  556.         mov     edx, [cur.h]
  557.         test    edx, edx
  558.         jz      .ret
  559.  
  560.         push    esi
  561.         push    edi
  562.  
  563.         mov     esi, cur_saved_data
  564. ;--------------------------------------
  565. align 4
  566. @@:
  567.         mov     edi, ebx
  568.         add     ebx, [_display.lfb_pitch]
  569.  
  570.         mov     ecx, [cur.w]
  571.         rep movsd
  572.         dec     edx
  573.         jnz     @B
  574.  
  575.         pop     edi
  576.         pop     esi
  577.  
  578. ;--------------------------------------
  579. align 4
  580. .ret:
  581.         pop     ebx
  582.         ret
  583. endp
  584. ;------------------------------------------------------------------------------
  585. align 4
  586. proc restore_16 stdcall, x:dword, y:dword
  587.  
  588.         push    ebx
  589.  
  590.         mov     ebx, [cur_saved_base]
  591.         mov     edx, [cur.h]
  592.         test    edx, edx
  593.         jz      .ret
  594.  
  595.         push    esi
  596.         push    edi
  597.  
  598.         mov     esi, cur_saved_data
  599. ;--------------------------------------
  600. align 4
  601. @@:
  602.         mov     edi, ebx
  603.         add     ebx, [_display.lfb_pitch]
  604.  
  605.         mov     ecx, [cur.w]
  606.         rep movsw
  607.         dec     edx
  608.         jnz     @B
  609.  
  610.         pop     edi
  611.         pop     esi
  612.  
  613. ;--------------------------------------
  614. align 4
  615. .ret:
  616.         pop     ebx
  617.         ret
  618. endp
  619. ;------------------------------------------------------------------------------
  620. align 4
  621. proc move_cursor_24 stdcall, hcursor:dword, x:dword, y:dword
  622.            locals
  623.              h      dd ?
  624.              _dx     dd ?
  625.              _dy     dd ?
  626.            endl
  627.  
  628.         mov     esi, [hcursor]
  629.         mov     ecx, [x]
  630.         mov     eax, [y]
  631. ;        mov     ebx, [BytesPerScanLine]
  632.  
  633.         xor     edx, edx
  634.         sub     ecx, [esi+CURSOR.hot_x]
  635.         lea     ebx, [ecx+32-1]
  636.         mov     [x], ecx
  637.         sets    dl
  638.         dec     edx
  639.         and     ecx, edx      ;clip x to 0<=x
  640.         mov     [cur.left], ecx
  641.         mov     edi, ecx
  642.         sub     edi, [x]
  643.         mov     [_dx], edi
  644.  
  645.         xor     edx, edx
  646.         sub     eax, [esi+CURSOR.hot_y]
  647.         lea     edi, [eax+32-1]
  648.         mov     [y], eax
  649.         sets    dl
  650.         dec     edx
  651.         and     eax, edx      ;clip y to 0<=y
  652.         mov     [cur.top], eax
  653.         mov     edx, eax
  654.         sub     edx, [y]
  655.         mov     [_dy], edx
  656.  
  657. ;        mul     dword [BytesPerScanLine]
  658.         mov     eax, [BPSLine_calc_area+eax*4]
  659.         lea     edx, [LFB_BASE+ecx*3]
  660.         add     edx, eax
  661.         mov     [cur_saved_base], edx
  662.  
  663.         cmp     ebx, [_display.width]
  664.         jb      @F
  665.         mov     ebx, [_display.width]
  666. ;--------------------------------------
  667. align 4
  668. @@:
  669.         cmp     edi, [_display.height]
  670.         jb      @F
  671.         mov     edi, [_display.height]
  672. ;--------------------------------------
  673. align 4
  674. @@:
  675.  
  676.         sub     ebx, [x]
  677.         sub     edi, [y]
  678.         sub     ebx, [_dx]
  679.         sub     edi, [_dy]
  680.  
  681.         mov     [cur.w], ebx
  682.         mov     [cur.h], edi
  683.         mov     [h], edi
  684.  
  685.         mov     eax, edi
  686.         mov     edi, cur_saved_data
  687. ;--------------------------------------
  688. align 4
  689. @@:
  690.         mov     esi, edx
  691.         add     edx, [_display.lfb_pitch]
  692.         mov     ecx, [cur.w]
  693.         lea     ecx, [ecx+ecx*2]
  694.         rep movsb
  695.         dec     eax
  696.         jnz     @B
  697.  
  698. ;draw cursor
  699.         mov     ebx, [cur_saved_base]
  700.         mov     eax, [_dy]
  701.         shl     eax, 5
  702.         add     eax, [_dx]
  703.  
  704.         mov     esi, [hcursor]
  705.         mov     esi, [esi+CURSOR.base]
  706.         lea     edx, [esi+eax*4]
  707. ;--------------------------------------
  708. align 4
  709. .row:
  710.         mov     ecx, [cur.w]
  711.         mov     esi, edx
  712.         mov     edi, ebx
  713.         add     edx, 32*4
  714.         add     ebx, [_display.lfb_pitch]
  715. ;--------------------------------------
  716. align 4
  717. .pix:
  718.         lodsd
  719.         test    eax, 0xFF000000
  720.         jz      @F
  721.         mov     [edi], ax
  722.         shr     eax, 16
  723.         mov     [edi+2], al
  724. ;--------------------------------------
  725. align 4
  726. @@:
  727.         add     edi, 3
  728.         dec     ecx
  729.         jnz     .pix
  730.  
  731.         dec     [h]
  732.         jnz     .row
  733.         ret
  734. endp
  735. ;------------------------------------------------------------------------------
  736. align 4
  737. proc move_cursor_32 stdcall, hcursor:dword, x:dword, y:dword
  738.            locals
  739.              h      dd ?
  740.              _dx     dd ?
  741.              _dy     dd ?
  742.            endl
  743.  
  744.         mov     esi, [hcursor]
  745.         mov     ecx, [x]
  746.         mov     eax, [y]
  747.  
  748.         xor     edx, edx
  749.         sub     ecx, [esi+CURSOR.hot_x]
  750.         lea     ebx, [ecx+32-1]
  751.         mov     [x], ecx
  752.         sets    dl
  753.         dec     edx
  754.         and     ecx, edx      ;clip x to 0<=x
  755.         mov     [cur.left], ecx
  756.         mov     edi, ecx
  757.         sub     edi, [x]
  758.         mov     [_dx], edi
  759.  
  760.         xor     edx, edx
  761.         sub     eax, [esi+CURSOR.hot_y]
  762.         lea     edi, [eax+32-1]
  763.         mov     [y], eax
  764.         sets    dl
  765.         dec     edx
  766.         and     eax, edx      ;clip y to 0<=y
  767.         mov     [cur.top], eax
  768.         mov     edx, eax
  769.         sub     edx, [y]
  770.         mov     [_dy], edx
  771.  
  772. ;        mul     dword [BytesPerScanLine]
  773.         mov     eax, [BPSLine_calc_area+eax*4]
  774.         lea     edx, [LFB_BASE+eax+ecx*4]
  775.         mov     [cur_saved_base], edx
  776.  
  777.         cmp     ebx, [_display.width]
  778.         jb      @F
  779.         mov     ebx, [_display.width]
  780. ;--------------------------------------
  781. align 4
  782. @@:
  783.         cmp     edi, [_display.height]
  784.         jb      @F
  785.         mov     edi, [_display.height]
  786. ;--------------------------------------
  787. align 4
  788. @@:
  789.         sub     ebx, [x]
  790.         sub     edi, [y]
  791.         sub     ebx, [_dx]
  792.         sub     edi, [_dy]
  793.  
  794.         mov     [cur.w], ebx
  795.         mov     [cur.h], edi
  796.         mov     [h], edi
  797.  
  798.         mov     eax, edi
  799.         mov     edi, cur_saved_data
  800. ;--------------------------------------
  801. align 4
  802. @@:
  803.         mov     esi, edx
  804.         add     edx, [_display.lfb_pitch]
  805.         mov     ecx, [cur.w]
  806.         rep movsd
  807.         dec     eax
  808.         jnz     @B
  809.  
  810. ;draw cursor
  811.         mov     ebx, [cur_saved_base]
  812.         mov     eax, [_dy]
  813.         shl     eax, 5
  814.         add     eax, [_dx]
  815.  
  816.         mov     esi, [hcursor]
  817.         mov     esi, [esi+CURSOR.base]
  818.         lea     edx, [esi+eax*4]
  819. ;--------------------------------------
  820. align 4
  821. .row:
  822.         mov     ecx, [cur.w]
  823.         mov     esi, edx
  824.         mov     edi, ebx
  825.         add     edx, 32*4
  826.         add     ebx, [_display.lfb_pitch]
  827. ;--------------------------------------
  828. align 4
  829. .pix:
  830.         lodsd
  831.         test    eax, 0xFF000000
  832.         jz      @F
  833.         mov     [edi], eax
  834. ;--------------------------------------
  835. align 4
  836. @@:
  837.         add     edi, 4
  838.         dec     ecx
  839.         jnz     .pix
  840.  
  841.         dec     [h]
  842.         jnz     .row
  843.         ret
  844. endp
  845. ;------------------------------------------------------------------------------
  846. align 4
  847. proc move_cursor_16 stdcall, hcursor:dword, x:dword, y:dword
  848.            locals
  849.              h      dd ?
  850.              _dx     dd ?
  851.              _dy     dd ?
  852.            endl
  853.  
  854.         mov     esi, [hcursor]
  855.         mov     ecx, [x]
  856.         mov     eax, [y]
  857.  
  858.         xor     edx, edx
  859.         sub     ecx, [esi+CURSOR.hot_x]
  860.         lea     ebx, [ecx+32-1]
  861.         mov     [x], ecx
  862.         sets    dl
  863.         dec     edx
  864.         and     ecx, edx      ;clip x to 0<=x
  865.         mov     [cur.left], ecx
  866.         mov     edi, ecx
  867.         sub     edi, [x]
  868.         mov     [_dx], edi
  869.  
  870.         xor     edx, edx
  871.         sub     eax, [esi+CURSOR.hot_y]
  872.         lea     edi, [eax+32-1]
  873.         mov     [y], eax
  874.         sets    dl
  875.         dec     edx
  876.         and     eax, edx      ;clip y to 0<=y
  877.         mov     [cur.top], eax
  878.         mov     edx, eax
  879.         sub     edx, [y]
  880.         mov     [_dy], edx
  881.  
  882. ;        mul     dword [BytesPerScanLine]
  883.         mov     eax, [BPSLine_calc_area+eax*4]
  884.         lea     edx, [LFB_BASE+eax+ecx*2]
  885.         mov     [cur_saved_base], edx
  886.  
  887.         cmp     ebx, [_display.width]
  888.         jb      @F
  889.         mov     ebx, [_display.width]
  890. ;--------------------------------------
  891. align 4
  892. @@:
  893.         cmp     edi, [_display.height]
  894.         jb      @F
  895.         mov     edi, [_display.height]
  896. ;--------------------------------------
  897. align 4
  898. @@:
  899.         sub     ebx, [x]
  900.         sub     edi, [y]
  901.         sub     ebx, [_dx]
  902.         sub     edi, [_dy]
  903.  
  904.         mov     [cur.w], ebx
  905.         mov     [cur.h], edi
  906.         mov     [h], edi
  907.  
  908.         mov     eax, edi
  909.         mov     edi, cur_saved_data
  910. ;--------------------------------------
  911. align 4
  912. @@:
  913.         mov     esi, edx
  914.         add     edx, [_display.lfb_pitch]
  915.         mov     ecx, [cur.w]
  916.  
  917.         rep movsw
  918.         dec     eax
  919.         jnz     @B
  920.  
  921. ;draw cursor
  922.         mov     ebx, [cur_saved_base]
  923.         mov     eax, [_dy]
  924.         shl     eax, 5
  925.         add     eax, [_dx]
  926.  
  927.         mov     esi, [hcursor]
  928.         mov     esi, [esi+CURSOR.base]
  929.         lea     edx, [esi+eax*4]
  930. ;--------------------------------------
  931. align 4
  932. .row:
  933.         mov     ecx, [cur.w]
  934.         mov     esi, edx
  935.         mov     edi, ebx
  936.         add     edx, 32*4
  937.         add     ebx, [_display.lfb_pitch]
  938. ;--------------------------------------
  939. align 4
  940. .pix:
  941.         lodsd
  942.         test    eax, 0xFF000000
  943.         jz      @F
  944. ; convert to 16 bpp and store to real LFB
  945.         and     eax, 00000000111110001111110011111000b
  946.         shr     ah, 2
  947.         shr     ax, 3
  948.         ror     eax, 8
  949.         add     al, ah
  950.         rol     eax, 8
  951.         mov     [edi], ax
  952. ;--------------------------------------
  953. align 4
  954. @@:
  955.         add     edi, 2
  956.         dec     ecx
  957.         jnz     .pix
  958.  
  959.         dec     [h]
  960.         jnz     .row
  961.         ret
  962. endp
  963. ;------------------------------------------------------------------------------
  964. align 4
  965. check_mouse_area_for_getpixel_new:
  966. ; in:
  967. ; eax = x
  968. ; ebx = y
  969. ; out:
  970. ; ecx = new color
  971. ;--------------------------------------
  972. ; check for Y
  973.         cmp     bx, [Y_UNDER_subtraction_CUR_hot_y]
  974.         jb      .no_mouse_area
  975.  
  976.         cmp     bx, [Y_UNDER_sub_CUR_hot_y_add_curh]
  977.         jae     .no_mouse_area
  978. ;--------------------------------------
  979. ; check for X
  980.         cmp     ax, [X_UNDER_subtraction_CUR_hot_x]
  981.         jb      .no_mouse_area
  982.  
  983.         cmp     ax, [X_UNDER_sub_CUR_hot_x_add_curh]
  984.         jae     .no_mouse_area
  985. ;--------------------------------------
  986.         push    eax ebx
  987. ; offset X
  988.         movzx   ecx, word [X_UNDER_subtraction_CUR_hot_x]
  989.         sub     eax, ecx        ; x1
  990. ; offset Y
  991.         movzx   ecx, word [Y_UNDER_subtraction_CUR_hot_y]
  992.         sub     ebx, ecx        ; y1
  993. ;--------------------------------------
  994. ; ebx = offset y
  995. ; eax = offset x
  996.         imul    ebx, [cur.w]     ;y
  997.         add     eax, ebx
  998.         mov     ebx, eax
  999.         shl     eax, 2
  1000.         cmp     byte [_display.bits_per_pixel], 32
  1001.         je      @f
  1002.         sub     eax, ebx
  1003.         cmp     byte [_display.bits_per_pixel], 24
  1004.         je      @f
  1005.         sub     eax, ebx
  1006.         add     eax, cur_saved_data
  1007.         mov     ecx, [eax]
  1008.         shl     ecx, 3
  1009.         ror     ecx, 8
  1010.         shl     cx, 2
  1011.         ror     ecx, 8
  1012.         shl     cl, 3
  1013.         rol     ecx, 16
  1014.         or      ecx, 0xff000000
  1015.         pop     ebx eax
  1016.         ret
  1017.  
  1018. ;--------------------------------------
  1019. align 4
  1020. @@:
  1021.         add     eax, cur_saved_data
  1022.         mov     ecx, [eax]
  1023.         or      ecx, 0xff000000
  1024.         pop     ebx eax
  1025.         ret
  1026. ;--------------------------------------
  1027. align 4
  1028. .no_mouse_area:
  1029.         xor     ecx, ecx
  1030.         ret
  1031. ;-----------------------------------------------------------------------------
  1032. align 4
  1033. check_mouse_area_for_putpixel_new:
  1034. ; in:
  1035. ; ecx = x shl 16 + y
  1036. ; eax = color
  1037. ; out:
  1038. ; eax = new color
  1039. ;--------------------------------------
  1040. ; check for Y
  1041.         cmp     cx, [Y_UNDER_sub_CUR_hot_y_add_curh]
  1042.         jae     .no_mouse_area
  1043.  
  1044.         sub     cx, [Y_UNDER_subtraction_CUR_hot_y]
  1045.         jb      .no_mouse_area
  1046.  
  1047.         rol     ecx, 16
  1048. ;--------------------------------------
  1049. ; check for X
  1050.         cmp     cx, [X_UNDER_sub_CUR_hot_x_add_curh]
  1051.         jae     .no_mouse_area
  1052.  
  1053.         sub     cx, [X_UNDER_subtraction_CUR_hot_x]
  1054.         jb      .no_mouse_area
  1055.  
  1056.         ror     ecx, 16
  1057. ;--------------------------------------
  1058. align 4
  1059. .1:
  1060.         push    eax
  1061. ;--------------------------------------
  1062. ; ecx = (offset x) shl 16 + (offset y)
  1063.         push    ebx
  1064.         mov     ebx, ecx
  1065.         shr     ebx, 16        ; x
  1066.         and     ecx, 0xffff    ; y
  1067.  
  1068.         cmp     ecx, [cur.h]
  1069.         jae     @f
  1070.  
  1071.         cmp     ebx, [cur.w]
  1072.         jb      .ok
  1073. ;--------------------------------------
  1074. align 4
  1075. @@:
  1076. ;        DEBUGF  1, "K : SHIT HAPPENS: %x %x \n", ecx,ebx
  1077.         pop     ebx
  1078.         jmp     .sh   ; SORRY! SHIT HAPPENS!
  1079. ;--------------------------------------
  1080. align 4
  1081. .ok:
  1082. ; ecx = offset y
  1083. ; ebx = offset x
  1084.         push    ebx ecx
  1085.         imul    ecx, [cur.w]    ;y
  1086.         add     ecx, ebx
  1087.         mov     ebx, ecx
  1088.         shl     ecx, 2
  1089.         cmp     byte [_display.bits_per_pixel], 16
  1090.         je      .16
  1091.         cmp     byte [_display.bits_per_pixel], 24
  1092.         je      .24
  1093.         and     eax, 0xFFFFFF
  1094.         mov     [ecx + cur_saved_data], eax   ;store new color  to
  1095.         jmp     @f
  1096. ;--------------------------------------
  1097. align 4
  1098. .16:
  1099.         sub     ecx, ebx
  1100.         sub     ecx, ebx
  1101. ; convert to 16 bpp and store to real LFB
  1102.         and     eax, 00000000111110001111110011111000b
  1103.         shr     ah, 2
  1104.         shr     ax, 3
  1105.         ror     eax, 8
  1106.         add     al, ah
  1107.         rol     eax, 8
  1108.         mov     [ecx + cur_saved_data], ax      ;store new color  to
  1109.         jmp     @f
  1110. ;--------------------------------------
  1111. align 4
  1112. .24:
  1113.         sub     ecx, ebx
  1114.         mov     [ecx + cur_saved_data], ax      ;store new color  to
  1115.         shr     eax, 16
  1116.         mov     [ecx + cur_saved_data + 2], al  ;store new color  to
  1117. ;--------------------------------------
  1118. align 4
  1119. @@:
  1120.         pop     ecx ebx
  1121.  
  1122.         shl     ecx, 5
  1123.         add     ecx, ebx
  1124.  
  1125.         mov     eax, [current_cursor]
  1126.         mov     eax, [eax+CURSOR.base]
  1127.         lea     eax, [eax+ecx*4]
  1128.         mov     eax, [eax]
  1129.  
  1130.         pop     ebx
  1131.  
  1132.         test    eax, 0xFF000000
  1133.         jz      @f
  1134.  
  1135.         add     esp, 4
  1136.         ret
  1137. ;--------------------------------------
  1138. align 4
  1139. .sh:
  1140.         mov     ecx, -1
  1141. ;--------------------------------------
  1142. align 4
  1143. @@:
  1144.         pop     eax
  1145. ;--------------------------------------
  1146. align 4
  1147. .no_mouse_area:
  1148.         ret
  1149. ;------------------------------------------------------------------------------
  1150. align 4
  1151. get_display:
  1152.         mov     eax, _display
  1153.         ret
  1154. ;------------------------------------------------------------------------------
  1155. align 4
  1156. init_display:
  1157.         xor     eax, eax
  1158.         mov     edi, _display
  1159.  
  1160.         mov     [edi+display_t.init_cursor], eax
  1161.         mov     [edi+display_t.select_cursor], eax
  1162.         mov     [edi+display_t.show_cursor], eax
  1163.         mov     [edi+display_t.move_cursor], eax
  1164.         mov     [edi+display_t.restore_cursor], eax
  1165.  
  1166.         lea     ecx, [edi+display_t.cr_list.next]
  1167.         mov     [edi+display_t.cr_list.next], ecx
  1168.         mov     [edi+display_t.cr_list.prev], ecx
  1169.  
  1170. if ~defined UEFI
  1171.         cmp     [SCR_MODE], word 0x13
  1172.         jbe     .fail
  1173.  
  1174.         test    word [SCR_MODE], 0x4000
  1175.         jz      .fail
  1176. end if
  1177.         mov     ebx, restore_32
  1178.         mov     ecx, move_cursor_32
  1179.         mov     edx, Vesa20_putpixel32_new
  1180.         mov     eax, [_display.bits_per_pixel]
  1181.         cmp     al, 32
  1182.         jne     .not_32bpp
  1183.  
  1184. .set:
  1185.         mov     [_display.select_cursor], select_cursor
  1186.         mov     [_display.move_cursor], ecx
  1187.         mov     [_display.restore_cursor], ebx
  1188.         mov     [_display.check_mouse], check_mouse_area_for_putpixel_new
  1189.         mov     [_display.check_m_pixel], check_mouse_area_for_getpixel_new
  1190.  
  1191.         cmp     [PUTPIXEL], dword VGA_putpixel
  1192.         je      @f
  1193.         mov     [PUTPIXEL], edx
  1194. @@:
  1195.         stdcall load_cursor, clock_arrow, dword LOAD_FROM_MEM
  1196.         mov     [def_cursor_clock], eax
  1197.         stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM
  1198.         mov     [def_cursor], eax
  1199.         ret
  1200.  
  1201. .not_32bpp:
  1202.         cmp     al, 24
  1203.         jne     .not_24bpp
  1204.  
  1205.         mov     ebx, restore_24
  1206.         mov     ecx, move_cursor_24
  1207.         mov     edx, Vesa20_putpixel24_new
  1208.         jmp     .set
  1209.  
  1210. .not_24bpp:
  1211.         cmp     al, 16
  1212.         jne     .not_16bpp
  1213.         mov     ebx, restore_16
  1214.         mov     ecx, move_cursor_16
  1215.         mov     edx, Vesa20_putpixel16_new
  1216.         jmp     .set
  1217.  
  1218. .not_16bpp:
  1219. ;        cmp     al, 15
  1220. ;        jne     .fail
  1221. ;        mov     ebx, restore_15
  1222. ;        mov     ecx, move_cursor_15
  1223. ;        mov     edx, Vesa20_putpixel15_new
  1224. ;        jmp     .set
  1225.  
  1226. .fail:
  1227.         xor     eax, eax
  1228.         mov     [_display.select_cursor], eax
  1229.         mov     [_display.move_cursor], eax
  1230.         ret
  1231. ;------------------------------------------------------------------------------
  1232. align 4
  1233. def_arrow:
  1234.   file 'arrow.cur'
  1235. ;------------------------------------------------------------------------------
  1236. align 4
  1237. clock_arrow:
  1238.   file 'arrow_clock.cur'
  1239. ;------------------------------------------------------------------------------
  1240.  
  1241.