Subversion Repositories Kolibri OS

Rev

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

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