Subversion Repositories Kolibri OS

Rev

Rev 8869 | Rev 9692 | 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: 9679 $
  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, 5
  427.         ;mov     eax, [TASK_TABLE+eax+TASKDATA.pid]
  428.         shl     eax, 8
  429.         mov     eax, [eax + SLOT_BASE + APPDATA.tid]
  430.         mov     ebx, [src]
  431.         mov     ecx, [flags]
  432.         call    create_cursor    ;eax, ebx, ecx
  433.         mov     [handle], eax
  434.  
  435.         cmp     word [flags], LOAD_FROM_FILE
  436.         jne     .exit
  437.         stdcall kernel_free, [src]
  438. ;--------------------------------------
  439. align 4
  440. .exit:
  441.         pop     edi
  442.         pop     esi
  443.         pop     ebx
  444. ;--------------------------------------
  445. align 4
  446. .fail:
  447.         mov     eax, [handle]
  448. ;--------------------------------------
  449. align 4
  450. .fail2:
  451.         ret
  452. endp
  453. ;------------------------------------------------------------------------------
  454. align 4
  455. proc delete_cursor stdcall, hcursor:dword
  456.  
  457. ;        DEBUGF 1,'K : delete_cursor %x\n', [hcursor]
  458.  
  459.         mov     esi, [hcursor]
  460.  
  461.         cmp     [esi+CURSOR.magic], 'CURS'
  462.         jne     .fail
  463.  
  464.         mov     ebx, [current_slot_idx]
  465.         ;shl     ebx, 5
  466.         ;mov     ebx, [TASK_TABLE+ebx+4]
  467.         shl     ebx, 8
  468.         mov     ebx, [ebx + SLOT_BASE + APPDATA.tid]
  469.         cmp     ebx, [esi+CURSOR.pid]
  470.         jne     .fail
  471.  
  472.         mov     ebx, [current_slot]
  473.         cmp     esi, [ebx+APPDATA.cursor]
  474.         jne     @F
  475.         mov     eax, [def_cursor]
  476.         mov     [ebx+APPDATA.cursor], eax
  477. ;--------------------------------------
  478. align 4
  479. @@:
  480.         mov     eax, [hcursor]
  481.         call    [eax+APPOBJ.destroy]
  482. ;--------------------------------------
  483. align 4
  484. .fail:
  485.         ret
  486. endp
  487. ;------------------------------------------------------------------------------
  488. align 4
  489. ; param
  490. ;  eax= cursor
  491. destroy_cursor:
  492.  
  493.         push    eax
  494.         stdcall kernel_free, [eax+CURSOR.base]
  495.  
  496.         mov     eax, [esp]
  497.         lea     eax, [eax+CURSOR.list_next]
  498.  
  499.         pushfd
  500.         cli
  501.         list_del eax
  502.         popfd
  503.  
  504.         pop     eax
  505.         call    destroy_kernel_object
  506.         ret
  507. ;------------------------------------------------------------------------------
  508. align 4
  509. select_cursor:
  510.         mov     eax, [esp+4]
  511.         mov     [_display.cursor], eax
  512.         ret     4
  513. ;------------------------------------------------------------------------------
  514. align 4
  515. proc restore_24 stdcall, x:dword, y:dword
  516.  
  517.         push    ebx
  518.  
  519.         mov     ebx, [cur_saved_base]
  520.         mov     edx, [cur.h]
  521.         test    edx, edx
  522.         jz      .ret
  523.  
  524.         push    esi
  525.         push    edi
  526.  
  527.         mov     esi, cur_saved_data
  528.         mov     ecx, [cur.w]
  529.         lea     ecx, [ecx+ecx*2]
  530.         push    ecx
  531. ;--------------------------------------
  532. align 4
  533. @@:
  534.         mov     edi, ebx
  535.         add     ebx, [_display.lfb_pitch]
  536.  
  537.         mov     ecx, [esp]
  538.         rep movsb
  539.         dec     edx
  540.         jnz     @B
  541.  
  542.         pop     ecx
  543.         pop     edi
  544.         pop     esi
  545. ;--------------------------------------
  546. align 4
  547. .ret:
  548.         pop     ebx
  549.         ret
  550. endp
  551. ;------------------------------------------------------------------------------
  552. align 4
  553. proc restore_32 stdcall, x:dword, y:dword
  554.  
  555.         push    ebx
  556.  
  557.         mov     ebx, [cur_saved_base]
  558.         mov     edx, [cur.h]
  559.         test    edx, edx
  560.         jz      .ret
  561.  
  562.         push    esi
  563.         push    edi
  564.  
  565.         mov     esi, cur_saved_data
  566. ;--------------------------------------
  567. align 4
  568. @@:
  569.         mov     edi, ebx
  570.         add     ebx, [_display.lfb_pitch]
  571.  
  572.         mov     ecx, [cur.w]
  573.         rep movsd
  574.         dec     edx
  575.         jnz     @B
  576.  
  577.         pop     edi
  578.         pop     esi
  579.  
  580. ;--------------------------------------
  581. align 4
  582. .ret:
  583.         pop     ebx
  584.         ret
  585. endp
  586. ;------------------------------------------------------------------------------
  587. align 4
  588. proc restore_16 stdcall, x:dword, y:dword
  589.  
  590.         push    ebx
  591.  
  592.         mov     ebx, [cur_saved_base]
  593.         mov     edx, [cur.h]
  594.         test    edx, edx
  595.         jz      .ret
  596.  
  597.         push    esi
  598.         push    edi
  599.  
  600.         mov     esi, cur_saved_data
  601. ;--------------------------------------
  602. align 4
  603. @@:
  604.         mov     edi, ebx
  605.         add     ebx, [_display.lfb_pitch]
  606.  
  607.         mov     ecx, [cur.w]
  608.         rep movsw
  609.         dec     edx
  610.         jnz     @B
  611.  
  612.         pop     edi
  613.         pop     esi
  614.  
  615. ;--------------------------------------
  616. align 4
  617. .ret:
  618.         pop     ebx
  619.         ret
  620. endp
  621. ;------------------------------------------------------------------------------
  622. align 4
  623. proc move_cursor_24 stdcall, hcursor:dword, x:dword, y:dword
  624.            locals
  625.              h      dd ?
  626.              _dx     dd ?
  627.              _dy     dd ?
  628.            endl
  629.  
  630.         mov     esi, [hcursor]
  631.         mov     ecx, [x]
  632.         mov     eax, [y]
  633. ;        mov     ebx, [BytesPerScanLine]
  634.  
  635.         xor     edx, edx
  636.         sub     ecx, [esi+CURSOR.hot_x]
  637.         lea     ebx, [ecx+32-1]
  638.         mov     [x], ecx
  639.         sets    dl
  640.         dec     edx
  641.         and     ecx, edx      ;clip x to 0<=x
  642.         mov     [cur.left], ecx
  643.         mov     edi, ecx
  644.         sub     edi, [x]
  645.         mov     [_dx], edi
  646.  
  647.         xor     edx, edx
  648.         sub     eax, [esi+CURSOR.hot_y]
  649.         lea     edi, [eax+32-1]
  650.         mov     [y], eax
  651.         sets    dl
  652.         dec     edx
  653.         and     eax, edx      ;clip y to 0<=y
  654.         mov     [cur.top], eax
  655.         mov     edx, eax
  656.         sub     edx, [y]
  657.         mov     [_dy], edx
  658.  
  659. ;        mul     dword [BytesPerScanLine]
  660.         mov     eax, [BPSLine_calc_area+eax*4]
  661.         lea     edx, [LFB_BASE+ecx*3]
  662.         add     edx, eax
  663.         mov     [cur_saved_base], edx
  664.  
  665.         cmp     ebx, [_display.width]
  666.         jb      @F
  667.         mov     ebx, [_display.width]
  668. ;--------------------------------------
  669. align 4
  670. @@:
  671.         cmp     edi, [_display.height]
  672.         jb      @F
  673.         mov     edi, [_display.height]
  674. ;--------------------------------------
  675. align 4
  676. @@:
  677.  
  678.         sub     ebx, [x]
  679.         sub     edi, [y]
  680.         sub     ebx, [_dx]
  681.         sub     edi, [_dy]
  682.  
  683.         mov     [cur.w], ebx
  684.         mov     [cur.h], edi
  685.         mov     [h], edi
  686.  
  687.         mov     eax, edi
  688.         mov     edi, cur_saved_data
  689. ;--------------------------------------
  690. align 4
  691. @@:
  692.         mov     esi, edx
  693.         add     edx, [_display.lfb_pitch]
  694.         mov     ecx, [cur.w]
  695.         lea     ecx, [ecx+ecx*2]
  696.         rep movsb
  697.         dec     eax
  698.         jnz     @B
  699.  
  700. ;draw cursor
  701.         mov     ebx, [cur_saved_base]
  702.         mov     eax, [_dy]
  703.         shl     eax, 5
  704.         add     eax, [_dx]
  705.  
  706.         mov     esi, [hcursor]
  707.         mov     esi, [esi+CURSOR.base]
  708.         lea     edx, [esi+eax*4]
  709. ;--------------------------------------
  710. align 4
  711. .row:
  712.         mov     ecx, [cur.w]
  713.         mov     esi, edx
  714.         mov     edi, ebx
  715.         add     edx, 32*4
  716.         add     ebx, [_display.lfb_pitch]
  717. ;--------------------------------------
  718. align 4
  719. .pix:
  720.         lodsd
  721.         test    eax, 0xFF000000
  722.         jz      @F
  723.         mov     [edi], ax
  724.         shr     eax, 16
  725.         mov     [edi+2], al
  726. ;--------------------------------------
  727. align 4
  728. @@:
  729.         add     edi, 3
  730.         dec     ecx
  731.         jnz     .pix
  732.  
  733.         dec     [h]
  734.         jnz     .row
  735.         ret
  736. endp
  737. ;------------------------------------------------------------------------------
  738. align 4
  739. proc move_cursor_32 stdcall, hcursor:dword, x:dword, y:dword
  740.            locals
  741.              h      dd ?
  742.              _dx     dd ?
  743.              _dy     dd ?
  744.            endl
  745.  
  746.         mov     esi, [hcursor]
  747.         mov     ecx, [x]
  748.         mov     eax, [y]
  749.  
  750.         xor     edx, edx
  751.         sub     ecx, [esi+CURSOR.hot_x]
  752.         lea     ebx, [ecx+32-1]
  753.         mov     [x], ecx
  754.         sets    dl
  755.         dec     edx
  756.         and     ecx, edx      ;clip x to 0<=x
  757.         mov     [cur.left], ecx
  758.         mov     edi, ecx
  759.         sub     edi, [x]
  760.         mov     [_dx], edi
  761.  
  762.         xor     edx, edx
  763.         sub     eax, [esi+CURSOR.hot_y]
  764.         lea     edi, [eax+32-1]
  765.         mov     [y], eax
  766.         sets    dl
  767.         dec     edx
  768.         and     eax, edx      ;clip y to 0<=y
  769.         mov     [cur.top], eax
  770.         mov     edx, eax
  771.         sub     edx, [y]
  772.         mov     [_dy], edx
  773.  
  774. ;        mul     dword [BytesPerScanLine]
  775.         mov     eax, [BPSLine_calc_area+eax*4]
  776.         lea     edx, [LFB_BASE+eax+ecx*4]
  777.         mov     [cur_saved_base], edx
  778.  
  779.         cmp     ebx, [_display.width]
  780.         jb      @F
  781.         mov     ebx, [_display.width]
  782. ;--------------------------------------
  783. align 4
  784. @@:
  785.         cmp     edi, [_display.height]
  786.         jb      @F
  787.         mov     edi, [_display.height]
  788. ;--------------------------------------
  789. align 4
  790. @@:
  791.         sub     ebx, [x]
  792.         sub     edi, [y]
  793.         sub     ebx, [_dx]
  794.         sub     edi, [_dy]
  795.  
  796.         mov     [cur.w], ebx
  797.         mov     [cur.h], edi
  798.         mov     [h], edi
  799.  
  800.         mov     eax, edi
  801.         mov     edi, cur_saved_data
  802. ;--------------------------------------
  803. align 4
  804. @@:
  805.         mov     esi, edx
  806.         add     edx, [_display.lfb_pitch]
  807.         mov     ecx, [cur.w]
  808.         rep movsd
  809.         dec     eax
  810.         jnz     @B
  811.  
  812. ;draw cursor
  813.         mov     ebx, [cur_saved_base]
  814.         mov     eax, [_dy]
  815.         shl     eax, 5
  816.         add     eax, [_dx]
  817.  
  818.         mov     esi, [hcursor]
  819.         mov     esi, [esi+CURSOR.base]
  820.         lea     edx, [esi+eax*4]
  821. ;--------------------------------------
  822. align 4
  823. .row:
  824.         mov     ecx, [cur.w]
  825.         mov     esi, edx
  826.         mov     edi, ebx
  827.         add     edx, 32*4
  828.         add     ebx, [_display.lfb_pitch]
  829. ;--------------------------------------
  830. align 4
  831. .pix:
  832.         lodsd
  833.         test    eax, 0xFF000000
  834.         jz      @F
  835.         mov     [edi], eax
  836. ;--------------------------------------
  837. align 4
  838. @@:
  839.         add     edi, 4
  840.         dec     ecx
  841.         jnz     .pix
  842.  
  843.         dec     [h]
  844.         jnz     .row
  845.         ret
  846. endp
  847. ;------------------------------------------------------------------------------
  848. align 4
  849. proc move_cursor_16 stdcall, hcursor:dword, x:dword, y:dword
  850.            locals
  851.              h      dd ?
  852.              _dx     dd ?
  853.              _dy     dd ?
  854.            endl
  855.  
  856.         mov     esi, [hcursor]
  857.         mov     ecx, [x]
  858.         mov     eax, [y]
  859.  
  860.         xor     edx, edx
  861.         sub     ecx, [esi+CURSOR.hot_x]
  862.         lea     ebx, [ecx+32-1]
  863.         mov     [x], ecx
  864.         sets    dl
  865.         dec     edx
  866.         and     ecx, edx      ;clip x to 0<=x
  867.         mov     [cur.left], ecx
  868.         mov     edi, ecx
  869.         sub     edi, [x]
  870.         mov     [_dx], edi
  871.  
  872.         xor     edx, edx
  873.         sub     eax, [esi+CURSOR.hot_y]
  874.         lea     edi, [eax+32-1]
  875.         mov     [y], eax
  876.         sets    dl
  877.         dec     edx
  878.         and     eax, edx      ;clip y to 0<=y
  879.         mov     [cur.top], eax
  880.         mov     edx, eax
  881.         sub     edx, [y]
  882.         mov     [_dy], edx
  883.  
  884. ;        mul     dword [BytesPerScanLine]
  885.         mov     eax, [BPSLine_calc_area+eax*4]
  886.         lea     edx, [LFB_BASE+eax+ecx*2]
  887.         mov     [cur_saved_base], edx
  888.  
  889.         cmp     ebx, [_display.width]
  890.         jb      @F
  891.         mov     ebx, [_display.width]
  892. ;--------------------------------------
  893. align 4
  894. @@:
  895.         cmp     edi, [_display.height]
  896.         jb      @F
  897.         mov     edi, [_display.height]
  898. ;--------------------------------------
  899. align 4
  900. @@:
  901.         sub     ebx, [x]
  902.         sub     edi, [y]
  903.         sub     ebx, [_dx]
  904.         sub     edi, [_dy]
  905.  
  906.         mov     [cur.w], ebx
  907.         mov     [cur.h], edi
  908.         mov     [h], edi
  909.  
  910.         mov     eax, edi
  911.         mov     edi, cur_saved_data
  912. ;--------------------------------------
  913. align 4
  914. @@:
  915.         mov     esi, edx
  916.         add     edx, [_display.lfb_pitch]
  917.         mov     ecx, [cur.w]
  918.  
  919.         rep movsw
  920.         dec     eax
  921.         jnz     @B
  922.  
  923. ;draw cursor
  924.         mov     ebx, [cur_saved_base]
  925.         mov     eax, [_dy]
  926.         shl     eax, 5
  927.         add     eax, [_dx]
  928.  
  929.         mov     esi, [hcursor]
  930.         mov     esi, [esi+CURSOR.base]
  931.         lea     edx, [esi+eax*4]
  932. ;--------------------------------------
  933. align 4
  934. .row:
  935.         mov     ecx, [cur.w]
  936.         mov     esi, edx
  937.         mov     edi, ebx
  938.         add     edx, 32*4
  939.         add     ebx, [_display.lfb_pitch]
  940. ;--------------------------------------
  941. align 4
  942. .pix:
  943.         lodsd
  944.         test    eax, 0xFF000000
  945.         jz      @F
  946. ; convert to 16 bpp and store to real LFB
  947.         and     eax, 00000000111110001111110011111000b
  948.         shr     ah, 2
  949.         shr     ax, 3
  950.         ror     eax, 8
  951.         add     al, ah
  952.         rol     eax, 8
  953.         mov     [edi], ax
  954. ;--------------------------------------
  955. align 4
  956. @@:
  957.         add     edi, 2
  958.         dec     ecx
  959.         jnz     .pix
  960.  
  961.         dec     [h]
  962.         jnz     .row
  963.         ret
  964. endp
  965. ;------------------------------------------------------------------------------
  966. align 4
  967. check_mouse_area_for_getpixel_new:
  968. ; in:
  969. ; eax = x
  970. ; ebx = y
  971. ; out:
  972. ; ecx = new color
  973. ;--------------------------------------
  974. ; check for Y
  975.         cmp     bx, [Y_UNDER_subtraction_CUR_hot_y]
  976.         jb      .no_mouse_area
  977.  
  978.         cmp     bx, [Y_UNDER_sub_CUR_hot_y_add_curh]
  979.         jae     .no_mouse_area
  980. ;--------------------------------------
  981. ; check for X
  982.         cmp     ax, [X_UNDER_subtraction_CUR_hot_x]
  983.         jb      .no_mouse_area
  984.  
  985.         cmp     ax, [X_UNDER_sub_CUR_hot_x_add_curh]
  986.         jae     .no_mouse_area
  987. ;--------------------------------------
  988.         push    eax ebx
  989. ; offset X
  990.         movzx   ecx, word [X_UNDER_subtraction_CUR_hot_x]
  991.         sub     eax, ecx        ; x1
  992. ; offset Y
  993.         movzx   ecx, word [Y_UNDER_subtraction_CUR_hot_y]
  994.         sub     ebx, ecx        ; y1
  995. ;--------------------------------------
  996. ; ebx = offset y
  997. ; eax = offset x
  998.         imul    ebx, [cur.w]     ;y
  999.         add     eax, ebx
  1000.         mov     ebx, eax
  1001.         shl     eax, 2
  1002.         cmp     byte [_display.bits_per_pixel], 32
  1003.         je      @f
  1004.         sub     eax, ebx
  1005.         cmp     byte [_display.bits_per_pixel], 24
  1006.         je      @f
  1007.         sub     eax, ebx
  1008.         add     eax, cur_saved_data
  1009.         mov     ecx, [eax]
  1010.         shl     ecx, 3
  1011.         ror     ecx, 8
  1012.         shl     cx, 2
  1013.         ror     ecx, 8
  1014.         shl     cl, 3
  1015.         rol     ecx, 16
  1016.         or      ecx, 0xff000000
  1017.         pop     ebx eax
  1018.         ret
  1019.  
  1020. ;--------------------------------------
  1021. align 4
  1022. @@:
  1023.         add     eax, cur_saved_data
  1024.         mov     ecx, [eax]
  1025.         or      ecx, 0xff000000
  1026.         pop     ebx eax
  1027.         ret
  1028. ;--------------------------------------
  1029. align 4
  1030. .no_mouse_area:
  1031.         xor     ecx, ecx
  1032.         ret
  1033. ;-----------------------------------------------------------------------------
  1034. align 4
  1035. check_mouse_area_for_putpixel_new:
  1036. ; in:
  1037. ; ecx = x shl 16 + y
  1038. ; eax = color
  1039. ; out:
  1040. ; eax = new color
  1041. ;--------------------------------------
  1042. ; check for Y
  1043.         cmp     cx, [Y_UNDER_sub_CUR_hot_y_add_curh]
  1044.         jae     .no_mouse_area
  1045.  
  1046.         sub     cx, [Y_UNDER_subtraction_CUR_hot_y]
  1047.         jb      .no_mouse_area
  1048.  
  1049.         rol     ecx, 16
  1050. ;--------------------------------------
  1051. ; check for X
  1052.         cmp     cx, [X_UNDER_sub_CUR_hot_x_add_curh]
  1053.         jae     .no_mouse_area
  1054.  
  1055.         sub     cx, [X_UNDER_subtraction_CUR_hot_x]
  1056.         jb      .no_mouse_area
  1057.  
  1058.         ror     ecx, 16
  1059. ;--------------------------------------
  1060. align 4
  1061. .1:
  1062.         push    eax
  1063. ;--------------------------------------
  1064. ; ecx = (offset x) shl 16 + (offset y)
  1065.         push    ebx
  1066.         mov     ebx, ecx
  1067.         shr     ebx, 16        ; x
  1068.         and     ecx, 0xffff    ; y
  1069.  
  1070.         cmp     ecx, [cur.h]
  1071.         jae     @f
  1072.  
  1073.         cmp     ebx, [cur.w]
  1074.         jb      .ok
  1075. ;--------------------------------------
  1076. align 4
  1077. @@:
  1078. ;        DEBUGF  1, "K : SHIT HAPPENS: %x %x \n", ecx,ebx
  1079.         pop     ebx
  1080.         jmp     .sh   ; SORRY! SHIT HAPPENS!
  1081. ;--------------------------------------
  1082. align 4
  1083. .ok:
  1084. ; ecx = offset y
  1085. ; ebx = offset x
  1086.         push    ebx ecx
  1087.         imul    ecx, [cur.w]    ;y
  1088.         add     ecx, ebx
  1089.         mov     ebx, ecx
  1090.         shl     ecx, 2
  1091.         cmp     byte [_display.bits_per_pixel], 16
  1092.         je      .16
  1093.         cmp     byte [_display.bits_per_pixel], 24
  1094.         je      .24
  1095.         and     eax, 0xFFFFFF
  1096.         mov     [ecx + cur_saved_data], eax   ;store new color  to
  1097.         jmp     @f
  1098. ;--------------------------------------
  1099. align 4
  1100. .16:
  1101.         sub     ecx, ebx
  1102.         sub     ecx, ebx
  1103. ; convert to 16 bpp and store to real LFB
  1104.         and     eax, 00000000111110001111110011111000b
  1105.         shr     ah, 2
  1106.         shr     ax, 3
  1107.         ror     eax, 8
  1108.         add     al, ah
  1109.         rol     eax, 8
  1110.         mov     [ecx + cur_saved_data], ax      ;store new color  to
  1111.         jmp     @f
  1112. ;--------------------------------------
  1113. align 4
  1114. .24:
  1115.         sub     ecx, ebx
  1116.         mov     [ecx + cur_saved_data], ax      ;store new color  to
  1117.         shr     eax, 16
  1118.         mov     [ecx + cur_saved_data + 2], al  ;store new color  to
  1119. ;--------------------------------------
  1120. align 4
  1121. @@:
  1122.         pop     ecx ebx
  1123.  
  1124.         shl     ecx, 5
  1125.         add     ecx, ebx
  1126.  
  1127.         mov     eax, [current_cursor]
  1128.         mov     eax, [eax+CURSOR.base]
  1129.         lea     eax, [eax+ecx*4]
  1130.         mov     eax, [eax]
  1131.  
  1132.         pop     ebx
  1133.  
  1134.         test    eax, 0xFF000000
  1135.         jz      @f
  1136.  
  1137.         add     esp, 4
  1138.         ret
  1139. ;--------------------------------------
  1140. align 4
  1141. .sh:
  1142.         mov     ecx, -1
  1143. ;--------------------------------------
  1144. align 4
  1145. @@:
  1146.         pop     eax
  1147. ;--------------------------------------
  1148. align 4
  1149. .no_mouse_area:
  1150.         ret
  1151. ;------------------------------------------------------------------------------
  1152. align 4
  1153. get_display:
  1154.         mov     eax, _display
  1155.         ret
  1156. ;------------------------------------------------------------------------------
  1157. align 4
  1158. init_display:
  1159.         xor     eax, eax
  1160.         mov     edi, _display
  1161.  
  1162.         mov     [edi+display_t.init_cursor], eax
  1163.         mov     [edi+display_t.select_cursor], eax
  1164.         mov     [edi+display_t.show_cursor], eax
  1165.         mov     [edi+display_t.move_cursor], eax
  1166.         mov     [edi+display_t.restore_cursor], eax
  1167.  
  1168.         lea     ecx, [edi+display_t.cr_list.next]
  1169.         mov     [edi+display_t.cr_list.next], ecx
  1170.         mov     [edi+display_t.cr_list.prev], ecx
  1171.  
  1172. if ~defined UEFI
  1173.         cmp     [SCR_MODE], word 0x13
  1174.         jbe     .fail
  1175.  
  1176.         test    word [SCR_MODE], 0x4000
  1177.         jz      .fail
  1178. end if
  1179.         mov     ebx, restore_32
  1180.         mov     ecx, move_cursor_32
  1181.         mov     edx, Vesa20_putpixel32_new
  1182.         mov     eax, [_display.bits_per_pixel]
  1183.         cmp     al, 32
  1184.         jne     .not_32bpp
  1185.  
  1186. .set:
  1187.         mov     [_display.select_cursor], select_cursor
  1188.         mov     [_display.move_cursor], ecx
  1189.         mov     [_display.restore_cursor], ebx
  1190.         mov     [_display.check_mouse], check_mouse_area_for_putpixel_new
  1191.         mov     [_display.check_m_pixel], check_mouse_area_for_getpixel_new
  1192.  
  1193.         cmp     [PUTPIXEL], dword VGA_putpixel
  1194.         je      @f
  1195.         mov     [PUTPIXEL], edx
  1196. @@:
  1197.         stdcall load_cursor, clock_arrow, dword LOAD_FROM_MEM
  1198.         mov     [def_cursor_clock], eax
  1199.         stdcall load_cursor, def_arrow, dword LOAD_FROM_MEM
  1200.         mov     [def_cursor], eax
  1201.         ret
  1202.  
  1203. .not_32bpp:
  1204.         cmp     al, 24
  1205.         jne     .not_24bpp
  1206.  
  1207.         mov     ebx, restore_24
  1208.         mov     ecx, move_cursor_24
  1209.         mov     edx, Vesa20_putpixel24_new
  1210.         jmp     .set
  1211.  
  1212. .not_24bpp:
  1213.         cmp     al, 16
  1214.         jne     .not_16bpp
  1215.         mov     ebx, restore_16
  1216.         mov     ecx, move_cursor_16
  1217.         mov     edx, Vesa20_putpixel16_new
  1218.         jmp     .set
  1219.  
  1220. .not_16bpp:
  1221. ;        cmp     al, 15
  1222. ;        jne     .fail
  1223. ;        mov     ebx, restore_15
  1224. ;        mov     ecx, move_cursor_15
  1225. ;        mov     edx, Vesa20_putpixel15_new
  1226. ;        jmp     .set
  1227.  
  1228. .fail:
  1229.         xor     eax, eax
  1230.         mov     [_display.select_cursor], eax
  1231.         mov     [_display.move_cursor], eax
  1232.         ret
  1233. ;------------------------------------------------------------------------------
  1234. align 4
  1235. def_arrow:
  1236.   file 'arrow.cur'
  1237. ;------------------------------------------------------------------------------
  1238. align 4
  1239. clock_arrow:
  1240.   file 'arrow_clock.cur'
  1241. ;------------------------------------------------------------------------------
  1242.  
  1243.