Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 5201 $
  9.  
  10.  
  11. LOAD_FROM_FILE  equ 0
  12. LOAD_FROM_MEM   equ 1
  13. LOAD_INDIRECT   equ 2
  14. LOAD_SYSTEM     equ 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_TASK]
  426.         shl     eax, 5
  427.         mov     eax, [CURRENT_TASK+eax+4]
  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_TASK]
  463.         shl     ebx, 5
  464.         mov     ebx, [CURRENT_TASK+ebx+4]
  465.         cmp     ebx, [esi+CURSOR.pid]
  466.         jne     .fail
  467.  
  468.         mov     ebx, [current_slot]
  469.         cmp     esi, [ebx+APPDATA.cursor]
  470.         jne     @F
  471.         mov     eax, [def_cursor]
  472.         mov     [ebx+APPDATA.cursor], eax
  473. ;--------------------------------------
  474. align 4
  475. @@:
  476.         mov     eax, [hcursor]
  477.         call    [eax+APPOBJ.destroy]
  478. ;--------------------------------------
  479. align 4
  480. .fail:
  481.         ret
  482. endp
  483. ;------------------------------------------------------------------------------
  484. align 4
  485. ; param
  486. ;  eax= cursor
  487. destroy_cursor:
  488.  
  489.         push    eax
  490.         stdcall kernel_free, [eax+CURSOR.base]
  491.  
  492.         mov     eax, [esp]
  493.         lea     eax, [eax+CURSOR.list_next]
  494.  
  495.         pushfd
  496.         cli
  497.         list_del eax
  498.         popfd
  499.  
  500.         pop     eax
  501.         call    destroy_kernel_object
  502.         ret
  503. ;------------------------------------------------------------------------------
  504. align 4
  505. select_cursor:
  506.         mov     eax, [esp+4]
  507.         mov     [_display.cursor], eax
  508.         ret     4
  509. ;------------------------------------------------------------------------------
  510. align 4
  511. proc restore_24 stdcall, x:dword, y:dword
  512.  
  513.         push    ebx
  514.  
  515.         mov     ebx, [cur_saved_base]
  516.         mov     edx, [cur.h]
  517.         test    edx, edx
  518.         jz      .ret
  519.  
  520.         push    esi
  521.         push    edi
  522.  
  523.         mov     esi, cur_saved_data
  524.         mov     ecx, [cur.w]
  525.         lea     ecx, [ecx+ecx*2]
  526.         push    ecx
  527. ;--------------------------------------
  528. align 4
  529. @@:
  530.         mov     edi, ebx
  531.         add     ebx, [_display.pitch]
  532.  
  533.         mov     ecx, [esp]
  534.         rep movsb
  535.         dec     edx
  536.         jnz     @B
  537.  
  538.         pop     ecx
  539.         pop     edi
  540.         pop     esi
  541. ;--------------------------------------
  542. align 4
  543. .ret:
  544.         pop     ebx
  545.         ret
  546. endp
  547. ;------------------------------------------------------------------------------
  548. align 4
  549. proc restore_32 stdcall, x:dword, y:dword
  550.  
  551.         push    ebx
  552.  
  553.         mov     ebx, [cur_saved_base]
  554.         mov     edx, [cur.h]
  555.         test    edx, edx
  556.         jz      .ret
  557.  
  558.         push    esi
  559.         push    edi
  560.  
  561.         mov     esi, cur_saved_data
  562. ;--------------------------------------
  563. align 4
  564. @@:
  565.         mov     edi, ebx
  566.         add     ebx, [_display.pitch]
  567.  
  568.         mov     ecx, [cur.w]
  569.         rep movsd
  570.         dec     edx
  571.         jnz     @B
  572.  
  573.         pop     edi
  574. ;--------------------------------------
  575. align 4
  576. .ret:
  577.         pop     esi
  578.         pop     ebx
  579.         ret
  580. endp
  581. ;------------------------------------------------------------------------------
  582. align 4
  583. proc restore_16 stdcall, x:dword, y:dword
  584.  
  585.         push    ebx
  586.  
  587.         mov     ebx, [cur_saved_base]
  588.         mov     edx, [cur.h]
  589.         test    edx, edx
  590.         jz      .ret
  591.  
  592.         push    esi
  593.         push    edi
  594.  
  595.         mov     esi, cur_saved_data
  596. ;--------------------------------------
  597. align 4
  598. @@:
  599.         mov     edi, ebx
  600.         add     ebx, [_display.pitch]
  601.  
  602.         mov     ecx, [cur.w]
  603.         rep movsw
  604.         dec     edx
  605.         jnz     @B
  606.  
  607.         pop     edi
  608. ;--------------------------------------
  609. align 4
  610. .ret:
  611.         pop     esi
  612.         pop     ebx
  613.         ret
  614. endp
  615. ;------------------------------------------------------------------------------
  616. align 4
  617. proc move_cursor_24 stdcall, hcursor:dword, x:dword, y:dword
  618.            locals
  619.              h      dd ?
  620.              _dx     dd ?
  621.              _dy     dd ?
  622.            endl
  623.  
  624.         mov     esi, [hcursor]
  625.         mov     ecx, [x]
  626.         mov     eax, [y]
  627. ;        mov     ebx, [BytesPerScanLine]
  628.  
  629.         xor     edx, edx
  630.         sub     ecx, [esi+CURSOR.hot_x]
  631.         lea     ebx, [ecx+32-1]
  632.         mov     [x], ecx
  633.         sets    dl
  634.         dec     edx
  635.         and     ecx, edx      ;clip x to 0<=x
  636.         mov     [cur.left], ecx
  637.         mov     edi, ecx
  638.         sub     edi, [x]
  639.         mov     [_dx], edi
  640.  
  641.         xor     edx, edx
  642.         sub     eax, [esi+CURSOR.hot_y]
  643.         lea     edi, [eax+32-1]
  644.         mov     [y], eax
  645.         sets    dl
  646.         dec     edx
  647.         and     eax, edx      ;clip y to 0<=y
  648.         mov     [cur.top], eax
  649.         mov     edx, eax
  650.         sub     edx, [y]
  651.         mov     [_dy], edx
  652.  
  653. ;        mul     dword [BytesPerScanLine]
  654.         mov     eax, [BPSLine_calc_area+eax*4]
  655.         lea     edx, [LFB_BASE+ecx*3]
  656.         add     edx, eax
  657.         mov     [cur_saved_base], edx
  658.  
  659.         cmp     ebx, [_display.width]
  660.         jb      @F
  661.         mov     ebx, [_display.width]
  662.         dec     ebx
  663. ;--------------------------------------
  664. align 4
  665. @@:
  666.         cmp     edi, [_display.height]
  667.         jb      @F
  668.         mov     edi, [_display.height]
  669.         dec     edi
  670. ;--------------------------------------
  671. align 4
  672. @@:
  673.         mov     [cur.right], ebx
  674.         mov     [cur.bottom], edi
  675.  
  676.         sub     ebx, [x]
  677.         sub     edi, [y]
  678.         inc     ebx
  679.         inc     edi
  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.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.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.         dec     ebx
  783. ;--------------------------------------
  784. align 4
  785. @@:
  786.         cmp     edi, [_display.height]
  787.         jb      @F
  788.         mov     edi, [_display.height]
  789.         dec     edi
  790. ;--------------------------------------
  791. align 4
  792. @@:
  793.         mov     [cur.right], ebx
  794.         mov     [cur.bottom], edi
  795.  
  796.         sub     ebx, [x]
  797.         sub     edi, [y]
  798.         inc     ebx
  799.         inc     edi
  800.         sub     ebx, [_dx]
  801.         sub     edi, [_dy]
  802.  
  803.         mov     [cur.w], ebx
  804.         mov     [cur.h], edi
  805.         mov     [h], edi
  806.  
  807.         mov     eax, edi
  808.         mov     edi, cur_saved_data
  809. ;--------------------------------------
  810. align 4
  811. @@:
  812.         mov     esi, edx
  813.         add     edx, [_display.pitch]
  814.         mov     ecx, [cur.w]
  815.         rep movsd
  816.         dec     eax
  817.         jnz     @B
  818.  
  819. ;draw cursor
  820.         mov     ebx, [cur_saved_base]
  821.         mov     eax, [_dy]
  822.         shl     eax, 5
  823.         add     eax, [_dx]
  824.  
  825.         mov     esi, [hcursor]
  826.         mov     esi, [esi+CURSOR.base]
  827.         lea     edx, [esi+eax*4]
  828. ;--------------------------------------
  829. align 4
  830. .row:
  831.         mov     ecx, [cur.w]
  832.         mov     esi, edx
  833.         mov     edi, ebx
  834.         add     edx, 32*4
  835.         add     ebx, [_display.pitch]
  836. ;--------------------------------------
  837. align 4
  838. .pix:
  839.         lodsd
  840.         test    eax, 0xFF000000
  841.         jz      @F
  842.         mov     [edi], eax
  843. ;--------------------------------------
  844. align 4
  845. @@:
  846.         add     edi, 4
  847.         dec     ecx
  848.         jnz     .pix
  849.  
  850.         dec     [h]
  851.         jnz     .row
  852.         ret
  853. endp
  854. ;------------------------------------------------------------------------------
  855. align 4
  856. proc move_cursor_16 stdcall, hcursor:dword, x:dword, y:dword
  857.            locals
  858.              h      dd ?
  859.              _dx     dd ?
  860.              _dy     dd ?
  861.            endl
  862.  
  863.         mov     esi, [hcursor]
  864.         mov     ecx, [x]
  865.         mov     eax, [y]
  866.  
  867.         xor     edx, edx
  868.         sub     ecx, [esi+CURSOR.hot_x]
  869.         lea     ebx, [ecx+32-1]
  870.         mov     [x], ecx
  871.         sets    dl
  872.         dec     edx
  873.         and     ecx, edx      ;clip x to 0<=x
  874.         mov     [cur.left], ecx
  875.         mov     edi, ecx
  876.         sub     edi, [x]
  877.         mov     [_dx], edi
  878.  
  879.         xor     edx, edx
  880.         sub     eax, [esi+CURSOR.hot_y]
  881.         lea     edi, [eax+32-1]
  882.         mov     [y], eax
  883.         sets    dl
  884.         dec     edx
  885.         and     eax, edx      ;clip y to 0<=y
  886.         mov     [cur.top], eax
  887.         mov     edx, eax
  888.         sub     edx, [y]
  889.         mov     [_dy], edx
  890.  
  891. ;        mul     dword [BytesPerScanLine]
  892.         mov     eax, [BPSLine_calc_area+eax*4]
  893.         lea     edx, [LFB_BASE+eax+ecx*2]
  894.         mov     [cur_saved_base], edx
  895.  
  896.         cmp     ebx, [Screen_Max_X]
  897.         jbe     @F
  898.         mov     ebx, [Screen_Max_X]
  899. ;--------------------------------------
  900. align 4
  901. @@:
  902.         cmp     edi, [Screen_Max_Y]
  903.         jbe     @F
  904.         mov     edi, [Screen_Max_Y]
  905. ;--------------------------------------
  906. align 4
  907. @@:
  908.         mov     [cur.right], ebx
  909.         mov     [cur.bottom], edi
  910.  
  911.         sub     ebx, [x]
  912.         sub     edi, [y]
  913.         inc     ebx
  914.         inc     edi
  915.         sub     ebx, [_dx]
  916.         sub     edi, [_dy]
  917.  
  918.         mov     [cur.w], ebx
  919.         mov     [cur.h], edi
  920.         mov     [h], edi
  921.  
  922.         mov     eax, edi
  923.         mov     edi, cur_saved_data
  924. ;--------------------------------------
  925. align 4
  926. @@:
  927.         mov     esi, edx
  928.         add     edx, [_display.pitch]
  929.         mov     ecx, [cur.w]
  930.  
  931.         rep movsw
  932.         dec     eax
  933.         jnz     @B
  934.  
  935. ;draw cursor
  936.         mov     ebx, [cur_saved_base]
  937.         mov     eax, [_dy]
  938.         shl     eax, 5
  939.         add     eax, [_dx]
  940.  
  941.         mov     esi, [hcursor]
  942.         mov     esi, [esi+CURSOR.base]
  943.         lea     edx, [esi+eax*4]
  944. ;--------------------------------------
  945. align 4
  946. .row:
  947.         mov     ecx, [cur.w]
  948.         mov     esi, edx
  949.         mov     edi, ebx
  950.         add     edx, 32*4
  951.         add     ebx, [_display.pitch]
  952. ;--------------------------------------
  953. align 4
  954. .pix:
  955.         lodsd
  956.         test    eax, 0xFF000000
  957.         jz      @F
  958. ; convert to 16 bpp and store to real LFB
  959.         and     eax, 00000000111110001111110011111000b
  960.         shr     ah, 2
  961.         shr     ax, 3
  962.         ror     eax, 8
  963.         add     al, ah
  964.         rol     eax, 8
  965.         mov     [edi], ax
  966. ;--------------------------------------
  967. align 4
  968. @@:
  969.         add     edi, 2
  970.         dec     ecx
  971.         jnz     .pix
  972.  
  973.         dec     [h]
  974.         jnz     .row
  975.         ret
  976. endp
  977. ;------------------------------------------------------------------------------
  978. align 4
  979. check_mouse_area_for_getpixel_new:
  980. ; in:
  981. ; eax = x
  982. ; ebx = y
  983. ; out:
  984. ; ecx = new color
  985. ;--------------------------------------
  986. ; check for Y
  987.         cmp     bx, [Y_UNDER_subtraction_CUR_hot_y]
  988.         jb      .no_mouse_area
  989.  
  990.         cmp     bx, [Y_UNDER_sub_CUR_hot_y_add_curh]
  991.         jae     .no_mouse_area
  992. ;--------------------------------------
  993. ; check for X
  994.         cmp     ax, [X_UNDER_subtraction_CUR_hot_x]
  995.         jb      .no_mouse_area
  996.  
  997.         cmp     ax, [X_UNDER_sub_CUR_hot_x_add_curh]
  998.         jae     .no_mouse_area
  999. ;--------------------------------------
  1000.         push    eax ebx
  1001. ; offset X
  1002.         movzx   ecx, word [X_UNDER_subtraction_CUR_hot_x]
  1003.         sub     eax, ecx        ; x1
  1004. ; offset Y
  1005.         movzx   ecx, word [Y_UNDER_subtraction_CUR_hot_y]
  1006.         sub     ebx, ecx        ; y1
  1007. ;--------------------------------------
  1008. ; ebx = offset y
  1009. ; eax = offset x
  1010.         imul    ebx, [cur.w]     ;y
  1011.         add     eax, ebx
  1012.         mov     ebx, eax
  1013.         shl     eax, 2
  1014.         cmp     byte [_display.bits_per_pixel], 32
  1015.         je      @f
  1016.         sub     eax, ebx
  1017.         cmp     byte [_display.bits_per_pixel], 24
  1018.         je      @f
  1019.         sub     eax, ebx
  1020. ;--------------------------------------
  1021. align 4
  1022. @@:
  1023.         add     eax, cur_saved_data
  1024.         mov     ecx, [eax]
  1025.         and     ecx, 0xffffff
  1026.         add     ecx, 0xff000000
  1027.         pop     ebx eax
  1028.         ret
  1029. ;--------------------------------------
  1030. align 4
  1031. .no_mouse_area:
  1032.         xor     ecx, ecx
  1033.         ret
  1034. ;-----------------------------------------------------------------------------
  1035. align 4
  1036. check_mouse_area_for_putpixel_new:
  1037. ; in:
  1038. ; ecx = x shl 16 + y
  1039. ; eax = color
  1040. ; out:
  1041. ; eax = new color
  1042. ;--------------------------------------
  1043. ; check for Y
  1044.         cmp     cx, [Y_UNDER_sub_CUR_hot_y_add_curh]
  1045.         jae     .no_mouse_area
  1046.  
  1047.         sub     cx, [Y_UNDER_subtraction_CUR_hot_y]
  1048.         jb      .no_mouse_area
  1049.  
  1050.         rol     ecx, 16
  1051. ;--------------------------------------
  1052. ; check for X
  1053.         cmp     cx, [X_UNDER_sub_CUR_hot_x_add_curh]
  1054.         jae     .no_mouse_area
  1055.  
  1056.         sub     cx, [X_UNDER_subtraction_CUR_hot_x]
  1057.         jb      .no_mouse_area
  1058.  
  1059.         ror     ecx, 16
  1060. ;--------------------------------------
  1061. align 4
  1062. .1:
  1063.         push    eax
  1064. ;--------------------------------------
  1065. ; ecx = (offset x) shl 16 + (offset y)
  1066.         push    ebx
  1067.         mov     ebx, ecx
  1068.         shr     ebx, 16        ; x
  1069.         and     ecx, 0xffff    ; y
  1070.  
  1071.         cmp     ecx, [cur.h]
  1072.         jae     @f
  1073.  
  1074.         cmp     ebx, [cur.w]
  1075.         jb      .ok
  1076. ;--------------------------------------
  1077. align 4
  1078. @@:
  1079. ;        DEBUGF  1, "K : SHIT HAPPENS: %x %x \n", ecx,ebx
  1080.         pop     ebx
  1081.         jmp     .sh   ; SORRY! SHIT HAPPENS!
  1082. ;--------------------------------------
  1083. align 4
  1084. .ok:
  1085. ; ecx = offset y
  1086. ; ebx = offset x
  1087.         push    ebx ecx
  1088.         imul    ecx, [cur.w]    ;y
  1089.         add     ecx, ebx
  1090.         mov     ebx, ecx
  1091.         shl     ecx, 2
  1092.         cmp     byte [_display.bits_per_pixel], 16
  1093.         je      .16
  1094.         cmp     byte [_display.bits_per_pixel], 24
  1095.         je      .24
  1096.         and     eax, 0xFFFFFF
  1097.         mov     [ecx + cur_saved_data], eax   ;store new color  to
  1098.         jmp     @f
  1099. ;--------------------------------------
  1100. align 4
  1101. .16:
  1102.         sub     ecx, ebx
  1103.         sub     ecx, ebx
  1104. ; convert to 16 bpp and store to real LFB
  1105.         and     eax, 00000000111110001111110011111000b
  1106.         shr     ah, 2
  1107.         shr     ax, 3
  1108.         ror     eax, 8
  1109.         add     al, ah
  1110.         rol     eax, 8
  1111.         mov     [ecx + cur_saved_data], ax      ;store new color  to
  1112.         jmp     @f
  1113. ;--------------------------------------
  1114. align 4
  1115. .24:
  1116.         sub     ecx, ebx
  1117.         mov     [ecx + cur_saved_data], ax      ;store new color  to
  1118.         shr     eax, 16
  1119.         mov     [ecx + cur_saved_data + 2], al  ;store new color  to
  1120. ;--------------------------------------
  1121. align 4
  1122. @@:
  1123.         pop     ecx ebx
  1124.  
  1125.         shl     ecx, 5
  1126.         add     ecx, ebx
  1127.  
  1128.         mov     eax, [current_cursor]
  1129.         mov     eax, [eax+CURSOR.base]
  1130.         lea     eax, [eax+ecx*4]
  1131.         mov     eax, [eax]
  1132.  
  1133.         pop     ebx
  1134.  
  1135.         test    eax, 0xFF000000
  1136.         jz      @f
  1137.  
  1138.         add     esp, 4
  1139.         ret
  1140. ;--------------------------------------
  1141. align 4
  1142. .sh:
  1143.         mov     ecx, -1
  1144. ;--------------------------------------
  1145. align 4
  1146. @@:
  1147.         pop     eax
  1148. ;--------------------------------------
  1149. align 4
  1150. .no_mouse_area:
  1151.         ret
  1152. ;------------------------------------------------------------------------------
  1153. align 4
  1154. get_display:
  1155.         mov     eax, _display
  1156.         ret
  1157. ;------------------------------------------------------------------------------
  1158. align 4
  1159. init_display:
  1160.         xor     eax, eax
  1161.         mov     edi, _display
  1162.  
  1163.         mov     [edi+display_t.init_cursor], eax
  1164.         mov     [edi+display_t.select_cursor], eax
  1165.         mov     [edi+display_t.show_cursor], eax
  1166.         mov     [edi+display_t.move_cursor], eax
  1167.         mov     [edi+display_t.restore_cursor], eax
  1168.  
  1169.         lea     ecx, [edi+display_t.cr_list.next]
  1170.         mov     [edi+display_t.cr_list.next], ecx
  1171.         mov     [edi+display_t.cr_list.prev], ecx
  1172.  
  1173.         cmp     [SCR_MODE], word 0x13
  1174.         jbe     .fail
  1175.  
  1176.         test    word [SCR_MODE], 0x4000
  1177.         jz      .fail
  1178.  
  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.