Subversion Repositories Kolibri OS

Rev

Rev 4587 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;  VESA20.INC                                                  ;;
  7. ;;                                                              ;;
  8. ;;  Vesa 2.0 functions for MenuetOS                             ;;
  9. ;;                                                              ;;
  10. ;;  Copyright 2002 Ville Turjanmaa                              ;;
  11. ;;  Alexey, kgaz@crosswindws.net                                ;;
  12. ;;  - Voodoo compatible graphics                                ;;
  13. ;;  Juan M. Caravaca                                            ;;
  14. ;;  - Graphics optimimizations eg. drawline                     ;;
  15. ;;                                                              ;;
  16. ;;  See file COPYING for details                                ;;
  17. ;;                                                              ;;
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19.  
  20. $Revision: 3606 $
  21.  
  22.  
  23. ; If you're planning to write your own video driver I suggest
  24. ; you replace the VESA12.INC file and see those instructions.
  25.  
  26.  
  27. ;-----------------------------------------------------------------------------
  28. ; getpixel
  29. ;
  30. ; in:
  31. ; eax = x coordinate
  32. ; ebx = y coordinate
  33. ;
  34. ; ret:
  35. ; ecx = 00 RR GG BB
  36. ;-----------------------------------------------------------------------------
  37. align 4
  38. getpixel:
  39.         push    eax ebx edx edi
  40.         call    dword [GETPIXEL]
  41.         pop     edi edx ebx eax
  42.         ret
  43. ;-----------------------------------------------------------------------------
  44. align 4
  45. Vesa20_getpixel24:
  46. ; eax = x
  47. ; ebx = y
  48. ;--------------------------------------
  49. ; check for hardware cursor
  50.         cmp     [_display.select_cursor], select_cursor
  51.         je      @f
  52.         cmp     [_display.select_cursor], 0
  53.         jne     .no_mouseunder
  54. ;--------------------------------------
  55. align 4
  56. @@:
  57. ; check mouse area for putpixel
  58.         test    ecx, 0x04000000  ; don't load to mouseunder area
  59.         jnz     .no_mouseunder
  60.         call    [_display.check_m_pixel]
  61.         test    ecx, ecx        ;0xff000000
  62.         jnz     @f
  63. ;--------------------------------------
  64. align 4
  65. .no_mouseunder:
  66. ;--------------------------------------
  67. ;        imul    ebx, [BytesPerScanLine] ; ebx = y * y multiplier
  68.         mov     ebx, [BPSLine_calc_area+ebx*4]
  69.         lea     edi, [eax+eax*2]; edi = x*3
  70.         add     edi, ebx      ; edi = x*3+(y*y multiplier)
  71.         mov     ecx, [LFB_BASE+edi]
  72. ;--------------------------------------
  73. align 4
  74. @@:
  75.         and     ecx, 0xffffff
  76.         ret
  77. ;-----------------------------------------------------------------------------
  78. align 4
  79. Vesa20_getpixel32:
  80. ;--------------------------------------
  81. ; check for hardware cursor
  82.         cmp     [_display.select_cursor], select_cursor
  83.         je      @f
  84.         cmp     [_display.select_cursor], 0
  85.         jne     .no_mouseunder
  86. ;--------------------------------------
  87. align 4
  88. @@:
  89. ; check mouse area for putpixel
  90.         test    ecx, 0x04000000  ; don't load to mouseunder area
  91.         jnz     .no_mouseunder
  92.         call    [_display.check_m_pixel]
  93.         test    ecx, ecx        ;0xff000000
  94.         jnz     @f
  95. ;--------------------------------------
  96. align 4
  97. .no_mouseunder:
  98. ;--------------------------------------
  99. ;        imul    ebx, [BytesPerScanLine] ; ebx = y * y multiplier
  100.         mov     ebx, [BPSLine_calc_area+ebx*4]
  101.         lea     edi, [ebx+eax*4]; edi = x*4+(y*y multiplier)
  102.         mov     ecx, [LFB_BASE+edi]
  103. ;--------------------------------------
  104. align 4
  105. @@:
  106.         and     ecx, 0xffffff
  107.         ret
  108. ;-----------------------------------------------------------------------------
  109. virtual at esp
  110.  putimg:
  111.    .real_sx        dd ?
  112.    .real_sy        dd ?
  113.    .image_sx       dd ?
  114.    .image_sy       dd ?
  115.    .image_cx       dd ?
  116.    .image_cy       dd ?
  117.    .pti            dd ?
  118.    .abs_cx         dd ?
  119.    .abs_cy         dd ?
  120.    .line_increment dd ?
  121.    .winmap_newline dd ?
  122.    .screen_newline dd ?
  123.    .real_sx_and_abs_cx dd ?
  124.    .real_sy_and_abs_cy dd ?
  125.    .stack_data = 4*14
  126.    .edi         dd      ?
  127.    .esi         dd      ?
  128.    .ebp         dd      ?
  129.    .esp         dd      ?
  130.    .ebx         dd      ?
  131.    .edx         dd      ?
  132.    .ecx         dd      ?
  133.    .eax         dd      ?
  134.    .ret_addr    dd      ?
  135.    .arg_0       dd      ?
  136. end virtual
  137. ;-----------------------------------------------------------------------------
  138. align 16
  139. ; ebx = pointer
  140. ; ecx = size [x|y]
  141. ; edx = coordinates [x|y]
  142. ; ebp = pointer to 'get' function
  143. ; esi = pointer to 'init' function
  144. ; edi = parameter for 'get' function
  145. vesa20_putimage:
  146.         pushad
  147.         sub     esp, putimg.stack_data
  148. ; save pointer to image
  149.         mov     [putimg.pti], ebx
  150. ; unpack the size
  151.         mov     eax, ecx
  152.         and     ecx, 0xFFFF
  153.         shr     eax, 16
  154.         mov     [putimg.image_sx], eax
  155.         mov     [putimg.image_sy], ecx
  156. ; unpack the coordinates
  157.         mov     eax, edx
  158.         and     edx, 0xFFFF
  159.         shr     eax, 16
  160.         mov     [putimg.image_cx], eax
  161.         mov     [putimg.image_cy], edx
  162. ; calculate absolute (i.e. screen) coordinates
  163.         mov     eax, [TASK_BASE]
  164.         mov     ebx, [eax-twdw + WDATA.box.left]
  165.         add     ebx, [putimg.image_cx]
  166.         mov     [putimg.abs_cx], ebx
  167.         mov     ebx, [eax-twdw + WDATA.box.top]
  168.         add     ebx, [putimg.image_cy]
  169.         mov     [putimg.abs_cy], ebx
  170. ; real_sx = MIN(wnd_sx-image_cx, image_sx);
  171.         mov     ebx, [eax-twdw + WDATA.box.width]; ebx = wnd_sx
  172. ; \begin{diamond}[20.08.2006]
  173. ; note that WDATA.box.width is one pixel less than real window x-size
  174.         inc     ebx
  175. ; \end{diamond}[20.08.2006]
  176.         sub     ebx, [putimg.image_cx]
  177.         ja      @f
  178.         add     esp, putimg.stack_data
  179.         popad
  180.         ret
  181. ;--------------------------------------
  182. align 4
  183. @@:
  184.         cmp     ebx, [putimg.image_sx]
  185.         jbe     .end_x
  186.         mov     ebx, [putimg.image_sx]
  187. ;--------------------------------------
  188. align 4
  189. .end_x:
  190.         mov     [putimg.real_sx], ebx
  191. ; init real_sy
  192.         mov     ebx, [eax-twdw + WDATA.box.height]; ebx = wnd_sy
  193. ; \begin{diamond}[20.08.2006]
  194.         inc     ebx
  195. ; \end{diamond}[20.08.2006]
  196.         sub     ebx, [putimg.image_cy]
  197.         ja      @f
  198.         add     esp, putimg.stack_data
  199.         popad
  200.         ret
  201. ;--------------------------------------
  202. align 4
  203. @@:
  204.         cmp     ebx, [putimg.image_sy]
  205.         jbe     .end_y
  206.         mov     ebx, [putimg.image_sy]
  207. ;--------------------------------------
  208. align 4
  209. .end_y:
  210.         mov     [putimg.real_sy], ebx
  211. ; line increment
  212.         mov     eax, [putimg.image_sx]
  213.         mov     ecx, [putimg.real_sx]
  214.         sub     eax, ecx
  215. ;;     imul    eax, [putimg.source_bpp]
  216. ;     lea     eax, [eax + eax * 2]
  217.         call    esi
  218.         add     eax, [putimg.arg_0]
  219.         mov     [putimg.line_increment], eax
  220. ; winmap new line increment
  221.         mov     eax, [_display.width]
  222.         sub     eax, [putimg.real_sx]
  223.         mov     [putimg.winmap_newline], eax
  224. ; screen new line increment
  225.         mov     eax, [_display.pitch]
  226.         mov     ebx, [_display.bpp]
  227.         shr     ebx, 3
  228.         imul    ecx, ebx
  229.         sub     eax, ecx
  230.         mov     [putimg.screen_newline], eax
  231. ; pointer to image
  232.         mov     esi, [putimg.pti]
  233. ; pointer to screen
  234.         mov     edx, [putimg.abs_cy]
  235. ;        imul    edx, [BytesPerScanLine]
  236.         mov     edx, [BPSLine_calc_area+edx*4]
  237.         mov     eax, [putimg.abs_cx]
  238. ;        movzx   ebx, byte [ScreenBPP]
  239. ;        shr     ebx, 3
  240.         imul    eax, ebx
  241.         add     edx, eax
  242. ; pointer to pixel map
  243.         mov     eax, [putimg.abs_cy]
  244.         mov     eax, [d_width_calc_area + eax*4]
  245.  
  246.         add     eax, [putimg.abs_cx]
  247.         add     eax, [_WinMapAddress]
  248.         xchg    eax, ebp
  249. ;--------------------------------------
  250.         mov     ecx, [putimg.real_sx]
  251.         add     ecx, [putimg.abs_cx]
  252.         mov     [putimg.real_sx_and_abs_cx], ecx
  253.         mov     ecx, [putimg.real_sy]
  254.         add     ecx, [putimg.abs_cy]
  255.         mov     [putimg.real_sy_and_abs_cy], ecx
  256. ;--------------------------------------
  257. ; get process number
  258.         mov     ebx, [CURRENT_TASK]
  259.         cmp     byte [_display.bpp], 32
  260.         je      put_image_end_32
  261. ;--------------------------------------
  262. put_image_end_24:
  263.         mov     edi, [putimg.real_sy]
  264. ;--------------------------------------
  265. ; check for hardware cursor
  266.         mov     ecx, [_display.select_cursor]
  267.         cmp     ecx, select_cursor
  268.         je      put_image_end_24_new
  269.         cmp     ecx, 0
  270.         je      put_image_end_24_old
  271. ;--------------------------------------
  272. align 4
  273. .new_line:
  274.         mov     ecx, [putimg.real_sx]
  275. ;--------------------------------------
  276. align 4
  277. .new_x:
  278.         push    [putimg.edi]
  279.         mov     eax, [putimg.ebp+4]
  280.         call    eax
  281.         cmp     [ebp], bl
  282.         jne     .skip
  283. ;--------------------------------------
  284. ; store to real LFB
  285.         mov     [LFB_BASE+edx], ax
  286.         shr     eax, 16
  287.         mov     [LFB_BASE+edx+2], al
  288. ;--------------------------------------
  289. align 4
  290. .skip:
  291.         add     edx, 3
  292.         inc     ebp
  293.         dec     ecx
  294.         jnz     .new_x
  295.  
  296.         add     esi, [putimg.line_increment]
  297.         add     edx, [putimg.screen_newline];[BytesPerScanLine]
  298.         add     ebp, [putimg.winmap_newline];[Screen_Max_X]
  299.  
  300.         cmp     [putimg.ebp], putimage_get1bpp
  301.         jz      .correct
  302.         cmp     [putimg.ebp], putimage_get2bpp
  303.         jz      .correct
  304.         cmp     [putimg.ebp], putimage_get4bpp
  305.         jnz     @f
  306. ;--------------------------------------
  307. align 4
  308. .correct:
  309.         mov     eax, [putimg.edi]
  310.         mov     byte [eax], 80h
  311. ;--------------------------------------
  312. align 4
  313. @@:
  314.         dec     edi
  315.         jnz     .new_line
  316. ;--------------------------------------
  317. align 4
  318. .finish:
  319.         add     esp, putimg.stack_data
  320.         popad
  321.         ret
  322. ;------------------------------------------------------------------------------
  323. align 4
  324. put_image_end_24_old:
  325. ;--------------------------------------
  326. align 4
  327. .new_line:
  328.         mov     ecx, [putimg.real_sx]
  329. ;--------------------------------------
  330. align 4
  331. .new_x:
  332.         push    [putimg.edi]
  333.         mov     eax, [putimg.ebp+4]
  334.         call    eax
  335.         cmp     [ebp], bl
  336.         jne     .skip
  337. ;--------------------------------------
  338.         push    ecx
  339.  
  340.         neg     ecx
  341.         add     ecx, [putimg.real_sx_and_abs_cx + 4]
  342.         shl     ecx, 16
  343.         add     ecx, [putimg.real_sy_and_abs_cy + 4]
  344.         sub     ecx, edi
  345.  
  346. ; check mouse area for putpixel
  347.         call    check_mouse_area_for_putpixel
  348.         pop     ecx
  349. ; store to real LFB
  350.         mov     [LFB_BASE+edx], ax
  351.         shr     eax, 16
  352.         mov     [LFB_BASE+edx+2], al
  353. ;--------------------------------------
  354. align 4
  355. .skip:
  356.         add     edx, 3
  357.         inc     ebp
  358.         dec     ecx
  359.         jnz     .new_x
  360.  
  361.         add     esi, [putimg.line_increment]
  362.         add     edx, [putimg.screen_newline];[BytesPerScanLine]
  363.         add     ebp, [putimg.winmap_newline];[Screen_Max_X]
  364.  
  365.         cmp     [putimg.ebp], putimage_get1bpp
  366.         jz      .correct
  367.         cmp     [putimg.ebp], putimage_get2bpp
  368.         jz      .correct
  369.         cmp     [putimg.ebp], putimage_get4bpp
  370.         jnz     @f
  371. ;--------------------------------------
  372. align 4
  373. .correct:
  374.         mov     eax, [putimg.edi]
  375.         mov     byte [eax], 80h
  376. ;--------------------------------------
  377. align 4
  378. @@:
  379.         dec     edi
  380.         jnz     .new_line
  381.         jmp     put_image_end_24.finish
  382. ;------------------------------------------------------------------------------
  383. align 4
  384. put_image_end_24_new:
  385. ;--------------------------------------
  386. align 4
  387. .new_line:
  388.         mov     ecx, [putimg.real_sx]
  389. ;--------------------------------------
  390. align 4
  391. .new_x:
  392.         push    [putimg.edi]
  393.         mov     eax, [putimg.ebp+4]
  394.         call    eax
  395.         cmp     [ebp], bl
  396.         jne     .skip
  397. ;--------------------------------------
  398.         push    ecx
  399. ;--------------------------------------
  400. align 4
  401. .sh:
  402.         neg     ecx
  403.         add     ecx, [putimg.real_sx_and_abs_cx + 4]
  404. ;--------------------------------------
  405. ; check for X
  406.         cmp     cx, [X_UNDER_sub_CUR_hot_x_add_curh]
  407.         jae     .no_mouse_area
  408.  
  409.         sub     cx, [X_UNDER_subtraction_CUR_hot_x]
  410.         jb      .no_mouse_area
  411.  
  412.         shl     ecx, 16
  413.  
  414.         add     ecx, [putimg.real_sy_and_abs_cy + 4]
  415.         sub     ecx, edi
  416. ;--------------------------------------
  417. ; check for Y
  418.         cmp     cx, [Y_UNDER_sub_CUR_hot_y_add_curh]
  419.         jae     .no_mouse_area
  420.  
  421.         sub     cx, [Y_UNDER_subtraction_CUR_hot_y]
  422.         jb      .no_mouse_area
  423. ;--------------------------------------
  424. ; check mouse area for putpixel
  425.         call    check_mouse_area_for_putpixel_new.1
  426.         cmp     ecx, -1   ;SHIT HAPPENS?
  427.         jne     .no_mouse_area
  428.  
  429.         mov     ecx, [esp]
  430.         jmp     .sh
  431. ;--------------------------------------
  432. align 4
  433. .no_mouse_area:
  434.         pop     ecx
  435. ; store to real LFB
  436.         mov     [LFB_BASE+edx], ax
  437.         shr     eax, 16
  438.         mov     [LFB_BASE+edx+2], al
  439. ;--------------------------------------
  440. align 4
  441. .skip:
  442.         add     edx, 3
  443.         inc     ebp
  444.         dec     ecx
  445.         jnz     .new_x
  446.  
  447.         add     esi, [putimg.line_increment]
  448.         add     edx, [putimg.screen_newline];[BytesPerScanLine]
  449.         add     ebp, [putimg.winmap_newline];[Screen_Max_X]
  450.  
  451.         cmp     [putimg.ebp], putimage_get1bpp
  452.         jz      .correct
  453.         cmp     [putimg.ebp], putimage_get2bpp
  454.         jz      .correct
  455.         cmp     [putimg.ebp], putimage_get4bpp
  456.         jnz     @f
  457. ;--------------------------------------
  458. align 4
  459. .correct:
  460.         mov     eax, [putimg.edi]
  461.         mov     byte [eax], 80h
  462. ;--------------------------------------
  463. align 4
  464. @@:
  465.         dec     edi
  466.         jnz     .new_line
  467.         jmp     put_image_end_24.finish
  468. ;------------------------------------------------------------------------------
  469. align 4
  470. put_image_end_32:
  471.         mov     edi, [putimg.real_sy]
  472. ;--------------------------------------
  473. ; check for hardware cursor
  474.         mov     ecx, [_display.select_cursor]
  475.         cmp     ecx, select_cursor
  476.         je      put_image_end_32_new
  477.         cmp     ecx, 0
  478.         je      put_image_end_32_old
  479. ;--------------------------------------
  480. align 4
  481. .new_line:
  482.         mov     ecx, [putimg.real_sx]
  483. ;--------------------------------------
  484. align 4
  485. .new_x:
  486.         push    [putimg.edi]
  487.         mov     eax, [putimg.ebp+4]
  488.         call    eax
  489.         cmp     [ebp], bl
  490.         jne     .skip
  491. ;--------------------------------------
  492. ; store to real LFB
  493.         mov     [LFB_BASE+edx], eax
  494. ;--------------------------------------
  495. align 4
  496. .skip:
  497.         add     edx, 4
  498.         inc     ebp
  499.         dec     ecx
  500.         jnz     .new_x
  501.  
  502.         add     esi, [putimg.line_increment]
  503.         add     edx, [putimg.screen_newline];[BytesPerScanLine]
  504.         add     ebp, [putimg.winmap_newline];[Screen_Max_X]
  505.  
  506.         cmp     [putimg.ebp], putimage_get1bpp
  507.         jz      .correct
  508.         cmp     [putimg.ebp], putimage_get2bpp
  509.         jz      .correct
  510.         cmp     [putimg.ebp], putimage_get4bpp
  511.         jnz     @f
  512. ;--------------------------------------
  513. align 4
  514. .correct:
  515.         mov     eax, [putimg.edi]
  516.         mov     byte [eax], 80h
  517. ;--------------------------------------
  518. align 4
  519. @@:
  520.         dec     edi
  521.         jnz     .new_line
  522. ;--------------------------------------
  523. align 4
  524. .finish:
  525.         add     esp, putimg.stack_data
  526.         popad
  527.         cmp     [SCR_MODE], 0x12
  528.         jne     @f
  529.         call    VGA__putimage
  530. ;--------------------------------------
  531. align 4
  532. @@:
  533.         mov     [EGA_counter], 1
  534.         ret
  535. ;------------------------------------------------------------------------------
  536. align 4
  537. put_image_end_32_old:
  538. ;--------------------------------------
  539. align 4
  540. .new_line:
  541.         mov     ecx, [putimg.real_sx]
  542. ;--------------------------------------
  543. align 4
  544. .new_x:
  545.         push    [putimg.edi]
  546.         mov     eax, [putimg.ebp+4]
  547.         call    eax
  548.         cmp     [ebp], bl
  549.         jne     .skip
  550. ;--------------------------------------
  551.         push    ecx
  552.  
  553.         neg     ecx
  554.         add     ecx, [putimg.real_sx_and_abs_cx + 4]
  555.         shl     ecx, 16
  556.         add     ecx, [putimg.real_sy_and_abs_cy + 4]
  557.         sub     ecx, edi
  558.  
  559. ; check mouse area for putpixel
  560.         call    check_mouse_area_for_putpixel
  561.         pop     ecx
  562. ; store to real LFB
  563.         mov     [LFB_BASE+edx], eax
  564. ;--------------------------------------
  565. align 4
  566. .skip:
  567.         add     edx, 4
  568.         inc     ebp
  569.         dec     ecx
  570.         jnz     .new_x
  571.  
  572.         add     esi, [putimg.line_increment]
  573.         add     edx, [putimg.screen_newline];[BytesPerScanLine]
  574.         add     ebp, [putimg.winmap_newline];[Screen_Max_X]
  575.  
  576.         cmp     [putimg.ebp], putimage_get1bpp
  577.         jz      .correct
  578.         cmp     [putimg.ebp], putimage_get2bpp
  579.         jz      .correct
  580.         cmp     [putimg.ebp], putimage_get4bpp
  581.         jnz     @f
  582. ;--------------------------------------
  583. align 4
  584. .correct:
  585.         mov     eax, [putimg.edi]
  586.         mov     byte [eax], 80h
  587. ;--------------------------------------
  588. align 4
  589. @@:
  590.         dec     edi
  591.         jnz     .new_line
  592.         jmp     put_image_end_32.finish
  593. ;------------------------------------------------------------------------------
  594. align 4
  595. put_image_end_32_new:
  596. ;--------------------------------------
  597. align 4
  598. .new_line:
  599.         mov     ecx, [putimg.real_sx]
  600. ;--------------------------------------
  601. align 4
  602. .new_x:
  603.         push    [putimg.edi]
  604.         mov     eax, [putimg.ebp+4]
  605.         call    eax
  606.         cmp     [ebp], bl
  607.         jne     .skip
  608. ;--------------------------------------
  609.         push    ecx
  610. ;--------------------------------------
  611. align 4
  612. .sh:
  613.         neg     ecx
  614.         add     ecx, [putimg.real_sx_and_abs_cx + 4]
  615. ;--------------------------------------
  616. ; check for X
  617.         cmp     cx, [X_UNDER_sub_CUR_hot_x_add_curh]
  618.         jae     .no_mouse_area
  619.  
  620.         sub     cx, [X_UNDER_subtraction_CUR_hot_x]
  621.         jb      .no_mouse_area
  622.  
  623.         shl     ecx, 16
  624.  
  625.         add     ecx, [putimg.real_sy_and_abs_cy + 4]
  626.         sub     ecx, edi
  627. ;--------------------------------------
  628. ; check for Y
  629.         cmp     cx, [Y_UNDER_sub_CUR_hot_y_add_curh]
  630.         jae     .no_mouse_area
  631.  
  632.         sub     cx, [Y_UNDER_subtraction_CUR_hot_y]
  633.         jb      .no_mouse_area
  634. ;--------------------------------------
  635. ; check mouse area for putpixel
  636.         call    check_mouse_area_for_putpixel_new.1
  637.         cmp     ecx, -1   ;SHIT HAPPENS?
  638.         jne     .no_mouse_area
  639.  
  640.         mov     ecx, [esp]
  641.         jmp     .sh
  642. ;--------------------------------------
  643. align 4
  644. .no_mouse_area:
  645.         pop     ecx
  646. ; store to real LFB
  647.         mov     [LFB_BASE+edx], eax
  648. ;--------------------------------------
  649. align 4
  650. .skip:
  651.         add     edx, 4
  652.         inc     ebp
  653.         dec     ecx
  654.         jnz     .new_x
  655.  
  656.         add     esi, [putimg.line_increment]
  657.         add     edx, [putimg.screen_newline];[BytesPerScanLine]
  658.         add     ebp, [putimg.winmap_newline];[Screen_Max_X]
  659.  
  660.         cmp     [putimg.ebp], putimage_get1bpp
  661.         jz      .correct
  662.         cmp     [putimg.ebp], putimage_get2bpp
  663.         jz      .correct
  664.         cmp     [putimg.ebp], putimage_get4bpp
  665.         jnz     @f
  666. ;--------------------------------------
  667. align 4
  668. .correct:
  669.         mov     eax, [putimg.edi]
  670.         mov     byte [eax], 80h
  671. ;--------------------------------------
  672. align 4
  673. @@:
  674.         dec     edi
  675.         jnz     .new_line
  676.         jmp     put_image_end_32.finish
  677. ;------------------------------------------------------------------------------
  678. align 4
  679. __sys_putpixel:
  680.  
  681. ; eax = x coordinate
  682. ; ebx = y coordinate
  683. ; ecx = ?? RR GG BB    ; 0x01000000 negation
  684.                        ; 0x02000000 used for draw_rectangle without top line
  685.                        ;            for example drawwindow_III and drawwindow_IV
  686. ; edi = 0x00000001 force
  687.  
  688.         pushad
  689.         cmp     eax, [_display.width]
  690.         jae     .exit
  691.         cmp     ebx, [_display.height]
  692.         jae     .exit
  693.         test    edi, 1           ; force ?
  694.         jnz     .forced
  695.  
  696. ; not forced:
  697.         mov     edx, [d_width_calc_area + ebx*4]
  698.         add     edx, [_WinMapAddress]
  699.         movzx   edx, byte [eax+edx]
  700.         cmp     edx, [CURRENT_TASK]
  701.         jne     .exit
  702. ;--------------------------------------
  703. align 4
  704. .forced:
  705. ; check if negation
  706.         test    ecx, 0x01000000
  707.         jz      .noneg
  708.  
  709.         call    getpixel
  710.         not     ecx
  711.  
  712.         rol     ecx, 8
  713.         mov     cl, [esp+32-8+3]
  714.         ror     ecx, 8
  715.         mov     [esp+32-8], ecx
  716. ;--------------------------------------
  717. align 4
  718. .noneg:
  719. ; OK to set pixel
  720.         call    dword [PUTPIXEL]; call the real put_pixel function
  721. ;--------------------------------------
  722. align 4
  723. .exit:
  724.         popad
  725.         ret
  726. ;-----------------------------------------------------------------------------
  727. align 4
  728. Vesa20_putpixel24:
  729. ; eax = x
  730. ; ebx = y
  731.         mov     ecx, eax
  732.         shl     ecx, 16
  733.         mov     cx, bx
  734.  
  735. ;        imul    ebx, [BytesPerScanLine]  ; ebx = y * y multiplier
  736.         mov     ebx, [BPSLine_calc_area+ebx*4]
  737.         lea     edi, [eax+eax*2]; edi = x*3
  738.         mov     eax, [esp+32-8+4]
  739. ;--------------------------------------
  740. ; check for hardware cursor
  741.         cmp     [_display.select_cursor], 0
  742.         jne     @f
  743. ; check mouse area for putpixel
  744.         test    eax, 0x04000000
  745.         jnz     @f
  746.         call    check_mouse_area_for_putpixel
  747. ;--------------------------------------
  748. align 4
  749. @@:
  750. ; store to real LFB
  751.         mov     [LFB_BASE+ebx+edi], ax
  752.         shr     eax, 16
  753.         mov     [LFB_BASE+ebx+edi+2], al
  754.         ret
  755. ;-----------------------------------------------------------------------------
  756. align 4
  757. Vesa20_putpixel24_new:
  758. ; eax = x
  759. ; ebx = y
  760.         mov     ecx, eax
  761.         shl     ecx, 16
  762.         mov     cx, bx
  763.  
  764. ;        imul    ebx, [BytesPerScanLine]  ; ebx = y * y multiplier
  765.         mov     ebx, [BPSLine_calc_area+ebx*4]
  766.         lea     edi, [eax+eax*2]; edi = x*3
  767.         mov     eax, [esp+32-8+4]
  768. ;--------------------------------------
  769. ; check for hardware cursor
  770.         cmp     [_display.select_cursor], select_cursor
  771.         jne     @f
  772. ; check mouse area for putpixel
  773.         test    eax, 0x04000000
  774.         jnz     @f
  775. ;--------------------------------------
  776. ; check for Y
  777.         cmp     cx, [Y_UNDER_sub_CUR_hot_y_add_curh]
  778.         jae     @f
  779.  
  780.         sub     cx, [Y_UNDER_subtraction_CUR_hot_y]
  781.         jb      @f
  782.  
  783.         rol     ecx, 16
  784. ;--------------------------------------
  785. ; check for X
  786.         cmp     cx, [X_UNDER_sub_CUR_hot_x_add_curh]
  787.         jae     @f
  788.  
  789.         sub     cx, [X_UNDER_subtraction_CUR_hot_x]
  790.         jb      @f
  791.  
  792.         ror     ecx, 16
  793.  
  794.         call    check_mouse_area_for_putpixel_new.1
  795. ;--------------------------------------
  796. align 4
  797. @@:
  798. ; store to real LFB
  799.         mov     [LFB_BASE+ebx+edi], ax
  800.         shr     eax, 16
  801.         mov     [LFB_BASE+ebx+edi+2], al
  802.         ret
  803. ;-----------------------------------------------------------------------------
  804. align 4
  805. Vesa20_putpixel32:
  806. ; eax = x
  807. ; ebx = y
  808.         mov     ecx, eax
  809.         shl     ecx, 16
  810.         mov     cx, bx
  811.  
  812. ;        imul    ebx, [BytesPerScanLine]  ; ebx = y * y multiplier
  813.         mov     ebx, [BPSLine_calc_area+ebx*4]
  814.         lea     edi, [ebx+eax*4]; edi = x*4+(y*y multiplier)
  815.         mov     eax, [esp+32-8+4]; eax = color
  816. ;--------------------------------------
  817. ; check for hardware cursor
  818.         cmp     [_display.select_cursor], 0
  819.         jne     @f
  820. ; check mouse area for putpixel
  821.         test    eax, 0x04000000
  822.         jnz     @f
  823.         call    check_mouse_area_for_putpixel
  824. ;--------------------------------------
  825. align 4
  826. @@:
  827.         and     eax, 0xffffff
  828. ; store to real LFB
  829.         mov     [LFB_BASE+edi], eax
  830.         ret
  831. ;-----------------------------------------------------------------------------
  832. align 4
  833. Vesa20_putpixel32_new:
  834. ; eax = x
  835. ; ebx = y
  836.         mov     ecx, eax
  837.         shl     ecx, 16
  838.         mov     cx, bx
  839.  
  840. ;        imul    ebx, [BytesPerScanLine]  ; ebx = y * y multiplier
  841.         mov     ebx, [BPSLine_calc_area+ebx*4]
  842.         lea     edi, [ebx+eax*4]; edi = x*4+(y*y multiplier)
  843.         mov     eax, [esp+32-8+4]; eax = color
  844. ;--------------------------------------
  845. ; check for hardware cursor
  846.         cmp     [_display.select_cursor], select_cursor
  847.         jne     @f
  848. ; check mouse area for putpixel
  849.         test    eax, 0x04000000
  850.         jnz     @f
  851. ;--------------------------------------
  852. ; check for Y
  853.         cmp     cx, [Y_UNDER_sub_CUR_hot_y_add_curh]
  854.         jae     @f
  855.  
  856.         sub     cx, [Y_UNDER_subtraction_CUR_hot_y]
  857.         jb      @f
  858.  
  859.         rol     ecx, 16
  860. ;--------------------------------------
  861. ; check for X
  862.         cmp     cx, [X_UNDER_sub_CUR_hot_x_add_curh]
  863.         jae     @f
  864.  
  865.         sub     cx, [X_UNDER_subtraction_CUR_hot_x]
  866.         jb      @f
  867.  
  868.         ror     ecx, 16
  869.  
  870.         call    check_mouse_area_for_putpixel_new.1
  871. ;--------------------------------------
  872. align 4
  873. @@:
  874.         and     eax, 0xffffff
  875. ; store to real LFB
  876.         mov     [LFB_BASE+edi], eax
  877.         ret
  878. ;-----------------------------------------------------------------------------
  879. align 4
  880. calculate_edi:
  881.         mov     edi, [d_width_calc_area + ebx*4]
  882.         add     edi, eax
  883.         ret
  884. ;-----------------------------------------------------------------------------
  885. ; DRAWLINE
  886. ;-----------------------------------------------------------------------------
  887. align 4
  888. __sys_draw_line:
  889. ; draw a line
  890. ; eax = HIWORD = x1
  891. ;       LOWORD = x2
  892. ; ebx = HIWORD = y1
  893. ;       LOWORD = y2
  894. ; ecx = color
  895. ; edi = force ?
  896.         pusha
  897.  
  898. dl_x1 equ esp+20
  899. dl_y1 equ esp+16
  900. dl_x2 equ esp+12
  901. dl_y2 equ esp+8
  902. dl_dx equ esp+4
  903. dl_dy equ esp+0
  904.  
  905.         xor     edx, edx   ; clear edx
  906.         xor     esi, esi   ; unpack arguments
  907.         xor     ebp, ebp
  908.         mov     si, ax     ; esi = x2
  909.         mov     bp, bx     ; ebp = y2
  910.         shr     eax, 16    ; eax = x1
  911.         shr     ebx, 16    ; ebx = y1
  912.         push    eax        ; save x1
  913.         push    ebx        ; save y1
  914.         push    esi        ; save x2
  915.         push    ebp        ; save y2
  916. ; checking x-axis...
  917.         sub     esi, eax   ; esi = x2-x1
  918.         push    esi        ; save y2-y1
  919.         jl      .x2lx1     ; is x2 less than x1 ?
  920.         jg      .no_vline  ; x1 > x2 ?
  921.         mov     edx, ebp   ; else (if x1=x2)
  922.         call    vline
  923.         push    edx ; necessary to rightly restore stack frame at .exit
  924.         jmp     .exit
  925. ;--------------------------------------
  926. align 4
  927. .x2lx1:
  928.         neg     esi         ; get esi absolute value
  929. ;--------------------------------------
  930. align 4
  931. .no_vline:
  932. ; checking y-axis...
  933.         sub     ebp, ebx    ; ebp = y2-y1
  934.         push    ebp         ; save y2-y1
  935.         jl      .y2ly1      ; is y2 less than y1 ?
  936.         jg      .no_hline   ; y1 > y2 ?
  937.         mov     edx, [dl_x2]; else (if y1=y2)
  938.         call    hline
  939.         jmp     .exit
  940. ;--------------------------------------
  941. align 4
  942. .y2ly1:
  943.         neg     ebp         ; get ebp absolute value
  944. ;--------------------------------------
  945. align 4
  946. .no_hline:
  947.         cmp     ebp, esi
  948.         jle     .x_rules    ; |y2-y1| < |x2-x1|  ?
  949.         cmp     [dl_y2], ebx; make sure y1 is at the begining
  950.         jge     .no_reverse1
  951.         neg     dword [dl_dx]
  952.         mov     edx, [dl_x2]
  953.         mov     [dl_x2], eax
  954.         mov     [dl_x1], edx
  955.         mov     edx, [dl_y2]
  956.         mov     [dl_y2], ebx
  957.         mov     [dl_y1], edx
  958. ;--------------------------------------
  959. align 4
  960. .no_reverse1:
  961.         mov     eax, [dl_dx]
  962.         cdq                 ; extend eax sing to edx
  963.         shl     eax, 16     ; using 16bit fix-point maths
  964.         idiv    ebp         ; eax = ((x2-x1)*65536)/(y2-y1)
  965. ;--------------------------------------
  966. ; correction for the remainder of the division
  967.         shl     edx, 1
  968.         cmp     ebp, edx
  969.         jb      @f
  970.         inc     eax
  971. ;--------------------------------------
  972. align 4
  973. @@:
  974. ;--------------------------------------
  975.         mov     edx, ebp    ; edx = counter (number of pixels to draw)
  976.         mov     ebp, 1 *65536; <<16   ; ebp = dy = 1.0
  977.         mov     esi, eax    ; esi = dx
  978.         jmp     .y_rules
  979. ;--------------------------------------
  980. align 4
  981. .x_rules:
  982.         cmp     [dl_x2], eax ; make sure x1 is at the begining
  983.         jge     .no_reverse2
  984.         neg     dword [dl_dy]
  985.         mov     edx, [dl_x2]
  986.         mov     [dl_x2], eax
  987.         mov     [dl_x1], edx
  988.         mov     edx, [dl_y2]
  989.         mov     [dl_y2], ebx
  990.         mov     [dl_y1], edx
  991. ;--------------------------------------
  992. align 4
  993. .no_reverse2:
  994.         xor     edx, edx
  995.         mov     eax, [dl_dy]
  996.         cdq                 ; extend eax sing to edx
  997.         shl     eax, 16     ; using 16bit fix-point maths
  998.         idiv    esi         ; eax = ((y2-y1)*65536)/(x2-x1)
  999. ;--------------------------------------
  1000. ; correction for the remainder of the division
  1001.         shl     edx, 1
  1002.         cmp     esi, edx
  1003.         jb      @f
  1004.         inc     eax
  1005. ;--------------------------------------
  1006. align 4
  1007. @@:
  1008. ;--------------------------------------
  1009.         mov     edx, esi    ; edx = counter (number of pixels to draw)
  1010.         mov     esi, 1 *65536;<< 16   ; esi = dx = 1.0
  1011.         mov     ebp, eax    ; ebp = dy
  1012. ;--------------------------------------
  1013. align 4
  1014. .y_rules:
  1015.         mov     eax, [dl_x1]
  1016.         mov     ebx, [dl_y1]
  1017.         shl     eax, 16
  1018.         shl     ebx, 16
  1019.  
  1020.         and     ecx, 0xFBFFFFFF ;negate 0x04000000 save to mouseunder area
  1021. ;-----------------------------------------------------------------------------
  1022. align 4
  1023. .draw:
  1024.         push    eax ebx
  1025. ;--------------------------------------
  1026. ; correction for the remainder of the division
  1027.         test    ah, 0x80
  1028.         jz      @f
  1029.         add     eax, 1 shl 16
  1030. ;--------------------------------------
  1031. align 4
  1032. @@:
  1033. ;--------------------------------------
  1034.         shr     eax, 16
  1035. ;--------------------------------------
  1036. ; correction for the remainder of the division
  1037.         test    bh, 0x80
  1038.         jz      @f
  1039.         add     ebx, 1 shl 16
  1040. ;--------------------------------------
  1041. align 4
  1042. @@:
  1043. ;--------------------------------------
  1044.         shr     ebx, 16
  1045. ;        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 save to mouseunder area
  1046. ;        call    [putpixel]
  1047.         call    __sys_putpixel
  1048.         pop     ebx eax
  1049.         add     ebx, ebp     ; y = y+dy
  1050.         add     eax, esi     ; x = x+dx
  1051.         dec     edx
  1052.         jnz     .draw
  1053. ; force last drawn pixel to be at (x2,y2)
  1054.         mov     eax, [dl_x2]
  1055.         mov     ebx, [dl_y2]
  1056. ;        and     ecx, 0xFBFFFFFF ;negate 0x04000000 save to mouseunder area
  1057. ;        call    [putpixel]
  1058.         call    __sys_putpixel
  1059. ;--------------------------------------
  1060. align 4
  1061. .exit:
  1062.         add     esp, 6*4
  1063.         popa
  1064. ;        call    [draw_pointer]
  1065.         ret
  1066. ;------------------------------------------------------------------------------
  1067. align 4
  1068. hline:
  1069. ; draw an horizontal line
  1070. ; eax = x1
  1071. ; edx = x2
  1072. ; ebx = y
  1073. ; ecx = color
  1074. ; edi = force ?
  1075.         push    eax edx
  1076.         cmp     edx, eax   ; make sure x2 is above x1
  1077.         jge     @f
  1078.         xchg    eax, edx
  1079. ;--------------------------------------
  1080. align 4
  1081. @@:
  1082.         and     ecx, 0xFBFFFFFF  ;negate 0x04000000 save to mouseunder area
  1083. ;--------------------------------------
  1084. align 4
  1085. @@:
  1086. ;        call    [putpixel]
  1087.         call    __sys_putpixel
  1088.         inc     eax
  1089.         cmp     eax, edx
  1090.         jle     @b
  1091.         pop     edx eax
  1092.         ret
  1093. ;------------------------------------------------------------------------------
  1094. align 4
  1095. vline:
  1096. ; draw a vertical line
  1097. ; eax = x
  1098. ; ebx = y1
  1099. ; edx = y2
  1100. ; ecx = color
  1101. ; edi = force ?
  1102.         push    ebx edx
  1103.         cmp     edx, ebx   ; make sure y2 is above y1
  1104.         jge     @f
  1105.         xchg    ebx, edx
  1106. ;--------------------------------------
  1107. align 4
  1108. @@:
  1109.         and     ecx, 0xFBFFFFFF ;negate 0x04000000 save to mouseunder area
  1110. ;--------------------------------------
  1111. align 4
  1112. @@:
  1113. ;        call    [putpixel]
  1114.         call    __sys_putpixel
  1115.         inc     ebx
  1116.         cmp     ebx, edx
  1117.         jle     @b
  1118.         pop     edx ebx
  1119.         ret
  1120. ;------------------------------------------------------------------------------
  1121. align 4
  1122. virtual at esp
  1123. drbar:
  1124.      .bar_sx       dd ?
  1125.      .bar_sy       dd ?
  1126.      .bar_cx       dd ?
  1127.      .bar_cy       dd ?
  1128.      .abs_cx       dd ?
  1129.      .abs_cy       dd ?
  1130.      .real_sx      dd ?
  1131.      .real_sy      dd ?
  1132.      .color        dd ?
  1133.      .line_inc_scr dd ?
  1134.      .line_inc_map dd ?
  1135.      .real_sx_and_abs_cx dd ?
  1136.      .real_sy_and_abs_cy dd ?
  1137.      .stack_data = 4*13
  1138. end virtual
  1139. ;--------------------------------------
  1140. align 4
  1141. ; eax   cx
  1142. ; ebx   cy
  1143. ; ecx   xe
  1144. ; edx   ye
  1145. ; edi   color
  1146. vesa20_drawbar:
  1147.         pushad
  1148.         sub     esp, drbar.stack_data
  1149.         mov     [drbar.color], edi
  1150.         sub     edx, ebx
  1151.         jle     .exit       ;// mike.dld, 2005-01-29
  1152.         sub     ecx, eax
  1153.         jle     .exit       ;// mike.dld, 2005-01-29
  1154.         mov     [drbar.bar_sy], edx
  1155.         mov     [drbar.bar_sx], ecx
  1156.         mov     [drbar.bar_cx], eax
  1157.         mov     [drbar.bar_cy], ebx
  1158.         mov     edi, [TASK_BASE]
  1159.         add     eax, [edi-twdw + WDATA.box.left]; win_cx
  1160.         add     ebx, [edi-twdw + WDATA.box.top]; win_cy
  1161.         mov     [drbar.abs_cx], eax
  1162.         mov     [drbar.abs_cy], ebx
  1163. ; real_sx = MIN(wnd_sx-bar_cx, bar_sx);
  1164.         mov     ebx, [edi-twdw + WDATA.box.width]; ebx = wnd_sx
  1165. ; \begin{diamond}[20.08.2006]
  1166. ; note that WDATA.box.width is one pixel less than real window x-size
  1167.         inc     ebx
  1168. ; \end{diamond}[20.08.2006]
  1169.         sub     ebx, [drbar.bar_cx]
  1170.         ja      @f
  1171. ;--------------------------------------
  1172. align 4
  1173. .exit:                       ;// mike.dld, 2005-01-29
  1174.         add     esp, drbar.stack_data
  1175.         popad
  1176.         xor     eax, eax
  1177.         inc     eax
  1178.         ret
  1179. ;--------------------------------------
  1180. align 4
  1181. @@:
  1182.         cmp     ebx, [drbar.bar_sx]
  1183.         jbe     .end_x
  1184.         mov     ebx, [drbar.bar_sx]
  1185. ;--------------------------------------
  1186. align 4
  1187. .end_x:
  1188.         mov     [drbar.real_sx], ebx
  1189. ; real_sy = MIN(wnd_sy-bar_cy, bar_sy);
  1190.         mov     ebx, [edi-twdw + WDATA.box.height]; ebx = wnd_sy
  1191. ; \begin{diamond}[20.08.2006]
  1192.         inc     ebx
  1193. ; \end{diamond}
  1194.         sub     ebx, [drbar.bar_cy]
  1195.         ja      @f
  1196.         add     esp, drbar.stack_data
  1197.         popad
  1198.         xor     eax, eax
  1199.         inc     eax
  1200.         ret
  1201. ;--------------------------------------
  1202. align 4
  1203. @@:
  1204.         cmp     ebx, [drbar.bar_sy]
  1205.         jbe     .end_y
  1206.         mov     ebx, [drbar.bar_sy]
  1207. ;--------------------------------------
  1208. align 4
  1209. .end_y:
  1210.         mov     [drbar.real_sy], ebx
  1211. ; line_inc_map
  1212.         mov     eax, [_display.width]
  1213.         sub     eax, [drbar.real_sx]
  1214.         mov     [drbar.line_inc_map], eax
  1215. ; line_inc_scr
  1216.         mov     eax, [drbar.real_sx]
  1217.         mov     ebx, [_display.bpp]
  1218.         shr     ebx, 3
  1219.         imul    eax, ebx
  1220.         neg     eax
  1221.         add     eax, [_display.pitch]
  1222.         mov     [drbar.line_inc_scr], eax
  1223. ; pointer to screen
  1224.         mov     edx, [drbar.abs_cy]
  1225. ;        imul    edx, [BytesPerScanLine]
  1226.         mov     edx, [BPSLine_calc_area+edx*4]
  1227.         mov     eax, [drbar.abs_cx]
  1228.         imul    eax, ebx
  1229.         add     edx, eax
  1230. ; pointer to pixel map
  1231.         mov     eax, [drbar.abs_cy]
  1232. ;        imul    eax, [Screen_Max_X]
  1233. ;        add     eax, [drbar.abs_cy]
  1234.         mov     eax, [d_width_calc_area + eax*4]
  1235.  
  1236.         add     eax, [drbar.abs_cx]
  1237.         add     eax, [_WinMapAddress]
  1238.         xchg    eax, ebp
  1239. ;--------------------------------------
  1240.         mov     ebx, [drbar.real_sx]
  1241.         add     ebx, [drbar.abs_cx]
  1242.         mov     [drbar.real_sx_and_abs_cx], ebx
  1243.         mov     ebx, [drbar.real_sy]
  1244.         add     ebx, [drbar.abs_cy]
  1245.         mov     [drbar.real_sy_and_abs_cy], ebx
  1246.  
  1247.         add     edx, LFB_BASE
  1248. ;--------------------------------------
  1249. ; get process number
  1250.         mov     ebx, [CURRENT_TASK]  ; bl - process num
  1251.         mov     esi, [drbar.real_sy]
  1252.         mov     eax, [drbar.color] ; BBGGRR00
  1253.         rol     eax, 8
  1254.         mov     bh, al  ; 0x80 drawing gradient bars
  1255.         ror     eax, 8
  1256.         cmp     byte [_display.bpp], 24
  1257.         jne     draw_bar_end_32
  1258. ;--------------------------------------
  1259. align 4
  1260. draw_bar_end_24:
  1261. ; eax - color high   RRGGBB
  1262. ; bl - process num
  1263. ; ecx - temp
  1264. ; edx - pointer to screen
  1265. ; esi - counter
  1266. ; edi - counter
  1267. ;--------------------------------------
  1268. ; check for hardware cursor
  1269.         mov     ecx, [_display.select_cursor]
  1270.         cmp     ecx, select_cursor
  1271.         je      draw_bar_end_24_new
  1272.         cmp     ecx, 0
  1273.         je      draw_bar_end_24_old
  1274. ;--------------------------------------
  1275. align 4
  1276. .new_y:
  1277.         mov     edi, [drbar.real_sx]
  1278. ;--------------------------------------
  1279. align 4
  1280. .new_x:
  1281.         cmp     byte [ebp], bl
  1282.         jne     .skip
  1283. ;--------------------------------------
  1284. ; store to real LFB
  1285.         mov     [edx], ax
  1286.         shr     eax, 16
  1287.         mov     [edx + 2], al
  1288. ;--------------------------------------
  1289. align 4
  1290. .skip:
  1291. ; add pixel
  1292.         add     edx, 3
  1293.         inc     ebp
  1294.         dec     edi
  1295.         jnz     .new_x
  1296. ; add line
  1297.         add     edx, [drbar.line_inc_scr]
  1298.         add     ebp, [drbar.line_inc_map]
  1299. ; drawing gradient bars
  1300.         test    bh, 0x80
  1301.         jz      @f
  1302.         test    al, al
  1303.         jz      @f
  1304.         dec     al
  1305. ;--------------------------------------
  1306. align 4
  1307. @@:
  1308.         dec     esi
  1309.         jnz     .new_y
  1310. ;--------------------------------------
  1311. align 4
  1312. .end:
  1313.         add     esp, drbar.stack_data
  1314.         popad
  1315.         xor     eax, eax
  1316.         ret
  1317. ;------------------------------------------------------------------------------
  1318. align 4
  1319. draw_bar_end_24_old:
  1320. ;--------------------------------------
  1321. align 4
  1322. .new_y:
  1323.         mov     edi, [drbar.real_sx]
  1324. ;--------------------------------------
  1325. align 4
  1326. .new_x:
  1327.         cmp     byte [ebp], bl
  1328.         jne     .skip
  1329. ;--------------------------------------
  1330.         mov     ecx, [drbar.real_sx_and_abs_cx]
  1331.         sub     ecx, edi
  1332.         shl     ecx, 16
  1333.         add     ecx, [drbar.real_sy_and_abs_cy]
  1334.         sub     ecx, esi
  1335. ; check mouse area for putpixel
  1336.         call    check_mouse_area_for_putpixel
  1337. ; store to real LFB
  1338.         mov     [edx], ax
  1339.         shr     eax, 16
  1340.         mov     [edx + 2], al
  1341.         mov     eax, [drbar.color]
  1342. ;--------------------------------------
  1343. align 4
  1344. .skip:
  1345. ; add pixel
  1346.         add     edx, 3
  1347.         inc     ebp
  1348.         dec     edi
  1349.         jnz     .new_x
  1350. ; add line
  1351.         add     edx, [drbar.line_inc_scr]
  1352.         add     ebp, [drbar.line_inc_map]
  1353. ; drawing gradient bars
  1354.         test    bh, 0x80
  1355.         jz      @f
  1356.         test    al, al
  1357.         jz      @f
  1358.         dec     al
  1359. ;--------------------------------------
  1360. align 4
  1361. @@:
  1362.         dec     esi
  1363.         jnz     .new_y
  1364.         jmp     draw_bar_end_24.end
  1365. ;------------------------------------------------------------------------------
  1366. align 4
  1367. draw_bar_end_24_new:
  1368. ;--------------------------------------
  1369. align 4
  1370. .new_y:
  1371.         mov     edi, [drbar.real_sx]
  1372. ;--------------------------------------
  1373. align 4
  1374. .new_x:
  1375.         cmp     byte [ebp], bl
  1376.         jne     .skip
  1377. ;--------------------------------------
  1378.         mov     ecx, [drbar.real_sy_and_abs_cy]
  1379.         sub     ecx, esi
  1380. ;--------------------------------------
  1381. ; check for Y
  1382.         cmp     cx, [Y_UNDER_sub_CUR_hot_y_add_curh]
  1383.         jae     .no_mouse_area
  1384.  
  1385.         sub     cx, [Y_UNDER_subtraction_CUR_hot_y]
  1386.         jb      .no_mouse_area
  1387.  
  1388.         rol     ecx, 16
  1389.         add     ecx, [drbar.real_sx_and_abs_cx]
  1390.         sub     ecx, edi
  1391. ;--------------------------------------
  1392. ; check for X
  1393.         cmp     cx, [X_UNDER_sub_CUR_hot_x_add_curh]
  1394.         jae     .no_mouse_area
  1395.  
  1396.         sub     cx, [X_UNDER_subtraction_CUR_hot_x]
  1397.         jb      .no_mouse_area
  1398.  
  1399.         ror     ecx, 16
  1400. ;--------------------------------------
  1401. ; check mouse area for putpixel
  1402.         push    eax
  1403.         call    check_mouse_area_for_putpixel_new.1
  1404.         mov     [edx], ax
  1405.         shr     eax, 16
  1406.         mov     [edx + 2], al
  1407.         pop     eax
  1408.         jmp     .skip
  1409. ; store to real LFB
  1410. ;--------------------------------------
  1411. align 4
  1412. .no_mouse_area:
  1413.         mov     [edx], ax
  1414.         ror     eax, 16
  1415.         mov     [edx + 2], al
  1416.         rol     eax, 16
  1417. ;--------------------------------------
  1418. align 4
  1419. .skip:
  1420. ; add pixel
  1421.         add     edx, 3
  1422.         inc     ebp
  1423.         dec     edi
  1424.         jnz     .new_x
  1425. ; add line
  1426.         add     edx, [drbar.line_inc_scr]
  1427.         add     ebp, [drbar.line_inc_map]
  1428. ; drawing gradient bars
  1429.         test    bh, 0x80
  1430.         jz      @f
  1431.         test    al, al
  1432.         jz      @f
  1433.         dec     al
  1434. ;--------------------------------------
  1435. align 4
  1436. @@:
  1437.         dec     esi
  1438.         jnz     .new_y
  1439.         jmp     draw_bar_end_24.end
  1440. ;------------------------------------------------------------------------------
  1441. align 4
  1442. draw_bar_end_32:
  1443. ; eax - color high   RRGGBB
  1444. ; bl - process num
  1445. ; ecx - temp
  1446. ; edx - pointer to screen
  1447. ; esi - counter
  1448. ; edi - counter
  1449. ;--------------------------------------
  1450. ; check for hardware cursor
  1451.         mov     ecx, [_display.select_cursor]
  1452.         cmp     ecx, select_cursor
  1453.         je      draw_bar_end_32_new
  1454.         cmp     ecx, 0
  1455.         je      draw_bar_end_32_old
  1456. ;--------------------------------------
  1457. align 4
  1458. .new_y:
  1459.         mov     edi, [drbar.real_sx]
  1460. ;--------------------------------------
  1461. align 4
  1462. .new_x:
  1463.         cmp     byte [ebp], bl
  1464.         jne     .skip
  1465. ;--------------------------------------
  1466. ; store to real LFB
  1467.         mov     [edx], eax
  1468.         mov     eax, [drbar.color]
  1469. ;--------------------------------------
  1470. align 4
  1471. .skip:
  1472. ; add pixel
  1473.         add     edx, 4
  1474.         inc     ebp
  1475.         dec     edi
  1476.         jnz     .new_x
  1477. ; add line
  1478.         add     edx, [drbar.line_inc_scr]
  1479.         add     ebp, [drbar.line_inc_map]
  1480. ; drawing gradient bars
  1481.         test    bh, 0x80
  1482.         jz      @f
  1483.         test    al, al
  1484.         jz      @f
  1485.         dec     al
  1486. ;--------------------------------------
  1487. align 4
  1488. @@:
  1489.         dec     esi
  1490.         jnz     .new_y
  1491. ;--------------------------------------
  1492. align 4
  1493. .end:
  1494.         add     esp, drbar.stack_data
  1495.         popad
  1496.         cmp     [SCR_MODE], 0x12
  1497.         jne     @f
  1498.         call    VGA_draw_bar
  1499. ;--------------------------------------
  1500. align 4
  1501. @@:
  1502.         xor     eax, eax
  1503.         mov     [EGA_counter], 1
  1504.         ret
  1505. ;------------------------------------------------------------------------------
  1506. align 4
  1507. draw_bar_end_32_old:
  1508. ;--------------------------------------
  1509. align 4
  1510. .new_y:
  1511.         mov     edi, [drbar.real_sx]
  1512. ;--------------------------------------
  1513. align 4
  1514. .new_x:
  1515.         cmp     byte [ebp], bl
  1516.         jne     .skip
  1517. ;--------------------------------------
  1518.         mov     ecx, [drbar.real_sx_and_abs_cx]
  1519.         sub     ecx, edi
  1520.         shl     ecx, 16
  1521.         add     ecx, [drbar.real_sy_and_abs_cy]
  1522.         sub     ecx, esi
  1523.  
  1524. ; check mouse area for putpixel
  1525.         call    check_mouse_area_for_putpixel
  1526. ; store to real LFB
  1527.         mov     [edx], eax
  1528.         mov     eax, [drbar.color]
  1529. ;--------------------------------------
  1530. align 4
  1531. .skip:
  1532. ; add pixel
  1533.         add     edx, 4
  1534.         inc     ebp
  1535.         dec     edi
  1536.         jnz     .new_x
  1537. ; add line
  1538.         add     edx, [drbar.line_inc_scr]
  1539.         add     ebp, [drbar.line_inc_map]
  1540. ; drawing gradient bars
  1541.         test    bh, 0x80
  1542.         jz      @f
  1543.         test    al, al
  1544.         jz      @f
  1545.         dec     al
  1546. ;--------------------------------------
  1547. align 4
  1548. @@:
  1549.         dec     esi
  1550.         jnz     .new_y
  1551.         jmp     draw_bar_end_32.end
  1552. ;------------------------------------------------------------------------------
  1553. align 4
  1554. draw_bar_end_32_new:
  1555. ;--------------------------------------
  1556. align 4
  1557. .new_y:
  1558.         mov     edi, [drbar.real_sx]
  1559. ;--------------------------------------
  1560. align 4
  1561. .new_x:
  1562.         cmp     byte [ebp], bl
  1563.         jne     .skip
  1564. ;--------------------------------------
  1565.         mov     ecx, [drbar.real_sy_and_abs_cy]
  1566.         sub     ecx, esi
  1567. ;--------------------------------------
  1568. ; check for Y
  1569.         cmp     cx, [Y_UNDER_sub_CUR_hot_y_add_curh]
  1570.         jae     .no_mouse_area
  1571.  
  1572.         sub     cx, [Y_UNDER_subtraction_CUR_hot_y]
  1573.         jb      .no_mouse_area
  1574.  
  1575.         rol     ecx, 16
  1576.         add     ecx, [drbar.real_sx_and_abs_cx]
  1577.         sub     ecx, edi
  1578. ;--------------------------------------
  1579. ; check for X
  1580.         cmp     cx, [X_UNDER_sub_CUR_hot_x_add_curh]
  1581.         jae     .no_mouse_area
  1582.  
  1583.         sub     cx, [X_UNDER_subtraction_CUR_hot_x]
  1584.         jb      .no_mouse_area
  1585.  
  1586.         ror     ecx, 16
  1587. ;--------------------------------------
  1588. ; check mouse area for putpixel
  1589.         push    eax
  1590.         call    check_mouse_area_for_putpixel_new.1
  1591.         mov     [edx], eax
  1592.         pop     eax
  1593.         jmp     .skip
  1594. ; store to real LFB
  1595. ;--------------------------------------
  1596. align 4
  1597. .no_mouse_area:
  1598.         mov     [edx], eax
  1599. ;--------------------------------------
  1600. align 4
  1601. .skip:
  1602. ; add pixel
  1603.         add     edx, 4
  1604.         inc     ebp
  1605.         dec     edi
  1606.         jnz     .new_x
  1607. ; add line
  1608.         add     edx, [drbar.line_inc_scr]
  1609.         add     ebp, [drbar.line_inc_map]
  1610. ; drawing gradient bars
  1611.         test    bh, 0x80
  1612.         jz      @f
  1613.         test    al, al
  1614.         jz      @f
  1615.         dec     al
  1616. ;--------------------------------------
  1617. align 4
  1618. @@:
  1619.         dec     esi
  1620.         jnz     .new_y
  1621.         jmp     draw_bar_end_32.end
  1622. ;------------------------------------------------------------------------------
  1623. align 4
  1624. vesa20_drawbackground_tiled:
  1625.         pushad
  1626. ; External loop for all y from start to end
  1627.         mov     ebx, [draw_data+32+RECT.top]    ; y start
  1628. ;--------------------------------------
  1629. align 4
  1630. dp2:
  1631.         mov     ebp, [draw_data+32+RECT.left]   ; x start
  1632. ; 1) Calculate pointers in WinMapAddress (does pixel belong to OS thread?) [ebp]
  1633. ;                       and LFB data (output for our function) [edi]
  1634. ;        mov     eax, [BytesPerScanLine]
  1635. ;        mul     ebx
  1636.         mov     eax, [BPSLine_calc_area+ebx*4]
  1637.         xchg    ebp, eax
  1638.         add     ebp, eax
  1639.         add     ebp, eax
  1640.         add     ebp, eax
  1641.         cmp     byte [_display.bpp], 24    ; 24 or 32 bpp ? - x size
  1642.         jz      @f
  1643.         add     ebp, eax
  1644. ;--------------------------------------
  1645. align 4
  1646. @@:
  1647.         add     ebp, LFB_BASE
  1648. ; ebp:=Y*BytesPerScanLine+X*BytesPerPixel+AddrLFB
  1649.         call    calculate_edi
  1650.         xchg    edi, ebp
  1651.         add     ebp, [_WinMapAddress]
  1652. ; Now eax=x, ebx=y, edi->output, ebp=offset in WinMapAddress
  1653. ; 2) Calculate offset in background memory block
  1654.         push    eax
  1655.         xor     edx, edx
  1656.         mov     eax, ebx
  1657.         div     dword [BgrDataHeight]   ; edx := y mod BgrDataHeight
  1658.         pop     eax
  1659.         push    eax
  1660.         mov     ecx, [BgrDataWidth]
  1661.         mov     esi, edx
  1662.         imul    esi, ecx                ; esi := (y mod BgrDataHeight) * BgrDataWidth
  1663.         xor     edx, edx
  1664.         div     ecx             ; edx := x mod BgrDataWidth
  1665.         sub     ecx, edx
  1666.         add     esi, edx        ; esi := (y mod BgrDataHeight)*BgrDataWidth + (x mod BgrDataWidth)
  1667.         pop     eax
  1668.         lea     esi, [esi*3]
  1669.         add     esi, [img_background]
  1670.         xor     edx, edx
  1671.         inc     edx
  1672. ; 3) Loop through redraw rectangle and copy background data
  1673. ; Registers meaning:
  1674. ; eax = x, ebx = y (screen coordinates)
  1675. ; ecx = deltax - number of pixels left in current tile block
  1676. ; edx = 1
  1677. ; esi -> bgr memory, edi -> output
  1678. ; ebp = offset in WinMapAddress
  1679. ;--------------------------------------
  1680. align 4
  1681. dp3:
  1682.         cmp     [ebp], dl
  1683.         jnz     nbgp
  1684. ;--------------------------------------
  1685.         push    eax ecx
  1686.  
  1687.         mov     ecx, eax
  1688.         shl     ecx, 16
  1689.         add     ecx, ebx
  1690.  
  1691.         mov     eax, [esi]
  1692.  
  1693. ; check for hardware cursor
  1694.         cmp     [_display.select_cursor], select_cursor
  1695.         je      @f
  1696.         cmp     [_display.select_cursor], 0
  1697.         jne     .no_mouseunder
  1698. ;--------------------------------------
  1699. align 4
  1700. @@:
  1701.         and     eax, 0xffffff
  1702. ; check mouse area for putpixel
  1703.         call    [_display.check_mouse]
  1704. ;--------------------------------------
  1705. align 4
  1706. .no_mouseunder:
  1707. ; store to real LFB
  1708.         mov     [edi], ax
  1709.         shr     eax, 16
  1710.         mov     [edi+2], al
  1711.  
  1712.         pop     ecx eax
  1713. ;--------------------------------------
  1714. align 4
  1715. nbgp:
  1716.         add     esi, 3
  1717.         add     edi, 3
  1718. ;--------------------------------------
  1719. align 4
  1720. @@:
  1721.         cmp     byte [_display.bpp], 25    ; 24 or 32 bpp?
  1722.         sbb     edi, -1         ; +1 for 32 bpp
  1723. ; I do not use 'inc eax' because this is slightly slower then 'add eax,1'
  1724.         add     ebp, edx
  1725.         add     eax, edx
  1726.         cmp     eax, [draw_data+32+RECT.right]
  1727.         ja      dp4
  1728.         sub     ecx, edx
  1729.         jnz     dp3
  1730. ; next tile block on x-axis
  1731.         mov     ecx, [BgrDataWidth]
  1732.         sub     esi, ecx
  1733.         sub     esi, ecx
  1734.         sub     esi, ecx
  1735.         jmp     dp3
  1736. ;--------------------------------------
  1737. align 4
  1738. dp4:
  1739. ; next scan line
  1740.         inc     ebx
  1741.         cmp     ebx, [draw_data+32+RECT.bottom]
  1742.         jbe     dp2
  1743.         popad
  1744.         mov     [EGA_counter], 1
  1745.         cmp     [SCR_MODE], 0x12
  1746.         jne     @f
  1747.         call    VGA_drawbackground
  1748. ;--------------------------------------
  1749. align 4
  1750. @@:
  1751.         ret
  1752. ;------------------------------------------------------------------------------
  1753. align 4
  1754. vesa20_drawbackground_stretch:
  1755.         pushad
  1756. ; Helper variables
  1757. ; calculate 2^32*(BgrDataWidth-1) mod (ScreenWidth-1)
  1758.         mov     eax, [BgrDataWidth]
  1759.         dec     eax
  1760.         xor     edx, edx
  1761.         div     dword [Screen_Max_X]
  1762.         push    eax     ; high
  1763.         xor     eax, eax
  1764.         div     dword [Screen_Max_X]
  1765.         push    eax     ; low
  1766. ; the same for height
  1767.         mov     eax, [BgrDataHeight]
  1768.         dec     eax
  1769.         xor     edx, edx
  1770.         div     dword [Screen_Max_Y]
  1771.         push    eax     ; high
  1772.         xor     eax, eax
  1773.         div     dword [Screen_Max_Y]
  1774.         push    eax     ; low
  1775. ; External loop for all y from start to end
  1776.         mov     ebx, [draw_data+32+RECT.top]    ; y start
  1777.         mov     ebp, [draw_data+32+RECT.left]   ; x start
  1778. ; 1) Calculate pointers in WinMapAddress (does pixel belong to OS thread?) [ebp]
  1779. ;                       and LFB data (output for our function) [edi]
  1780. ;        mov     eax, [BytesPerScanLine]
  1781. ;        mul     ebx
  1782.         mov     eax, [BPSLine_calc_area+ebx*4]
  1783.         xchg    ebp, eax
  1784.         add     ebp, eax
  1785.         add     ebp, eax
  1786.         add     ebp, eax
  1787.         cmp     byte [_display.bpp], 24    ; 24 or 32 bpp ? - x size
  1788.         jz      @f
  1789.         add     ebp, eax
  1790. ;--------------------------------------
  1791. align 4
  1792. @@:
  1793. ; ebp:=Y*BytesPerScanLine+X*BytesPerPixel+AddrLFB
  1794.         call    calculate_edi
  1795.         xchg    edi, ebp
  1796. ; Now eax=x, ebx=y, edi->output, ebp=offset in WinMapAddress
  1797.         push    ebx
  1798.         push    eax
  1799. ; 2) Calculate offset in background memory block
  1800.         mov     eax, ebx
  1801.         imul    ebx, dword [esp+12]
  1802.         mul     dword [esp+8]
  1803.         add     edx, ebx        ; edx:eax = y * 2^32*(BgrDataHeight-1)/(ScreenHeight-1)
  1804.         mov     esi, edx
  1805.         imul    esi, [BgrDataWidth]
  1806.         push    edx
  1807.         push    eax
  1808.         mov     eax, [esp+8]
  1809.         mul     dword [esp+28]
  1810.         push    eax
  1811.         mov     eax, [esp+12]
  1812.         mul     dword [esp+28]
  1813.         add     [esp], edx
  1814.         pop     edx             ; edx:eax = x * 2^32*(BgrDataWidth-1)/(ScreenWidth-1)
  1815.         add     esi, edx
  1816.         lea     esi, [esi*3]
  1817.         add     esi, [img_background]
  1818.         push    eax
  1819.         push    edx
  1820.         push    esi
  1821. ; 3) Smooth horizontal
  1822. ;--------------------------------------
  1823. align 4
  1824. bgr_resmooth0:
  1825.         mov     ecx, [esp+8]
  1826.         mov     edx, [esp+4]
  1827.         mov     esi, [esp]
  1828.         push    edi
  1829.         mov     edi, bgr_cur_line
  1830.         call    smooth_line
  1831. ;--------------------------------------
  1832. align 4
  1833. bgr_resmooth1:
  1834.         mov     eax, [esp+16+4]
  1835.         inc     eax
  1836.         cmp     eax, [BgrDataHeight]
  1837.         jae     bgr.no2nd
  1838.         mov     ecx, [esp+8+4]
  1839.         mov     edx, [esp+4+4]
  1840.         mov     esi, [esp+4]
  1841.         add     esi, [BgrDataWidth]
  1842.         add     esi, [BgrDataWidth]
  1843.         add     esi, [BgrDataWidth]
  1844.         mov     edi, bgr_next_line
  1845.         call    smooth_line
  1846. ;--------------------------------------
  1847. align 4
  1848. bgr.no2nd:
  1849.         pop     edi
  1850. ;--------------------------------------
  1851. align 4
  1852. sdp3:
  1853.         xor     esi, esi
  1854.         mov     ecx, [esp+12]
  1855. ; 4) Loop through redraw rectangle and copy background data
  1856. ; Registers meaning:
  1857. ; esi = offset in current line, edi -> output
  1858. ; ebp = offset in WinMapAddress
  1859. ; dword [esp] = offset in bgr data
  1860. ; qword [esp+4] = x * 2^32 * (BgrDataWidth-1) / (ScreenWidth-1)
  1861. ; qword [esp+12] = y * 2^32 * (BgrDataHeight-1) / (ScreenHeight-1)
  1862. ; dword [esp+20] = x
  1863. ; dword [esp+24] = y
  1864. ; precalculated constants:
  1865. ; qword [esp+28] = 2^32*(BgrDataHeight-1)/(ScreenHeight-1)
  1866. ; qword [esp+36] = 2^32*(BgrDataWidth-1)/(ScreenWidth-1)
  1867. ;--------------------------------------
  1868. align 4
  1869. sdp3a:
  1870.         mov     eax, [_WinMapAddress]
  1871.         cmp     [ebp+eax], byte 1
  1872.         jnz     snbgp
  1873.         mov     eax, [bgr_cur_line+esi]
  1874.         test    ecx, ecx
  1875.         jz      .novert
  1876.         mov     ebx, [bgr_next_line+esi]
  1877.         call    [overlapping_of_points_ptr]
  1878. ;--------------------------------------
  1879. align 4
  1880. .novert:
  1881.         push    ecx
  1882. ; check for hardware cursor
  1883.         cmp     [_display.select_cursor], select_cursor
  1884.         je      @f
  1885.         cmp     [_display.select_cursor], 0
  1886.         jne     .no_mouseunder
  1887. ;--------------------------------------
  1888. align 4
  1889. @@:
  1890.         mov     ecx, [esp+20+4]        ;x
  1891.         shl     ecx, 16
  1892.         add     ecx, [esp+24+4]        ;y
  1893. ; check mouse area for putpixel
  1894.         call    [_display.check_mouse]
  1895. ;--------------------------------------
  1896. align 4
  1897. .no_mouseunder:
  1898. ; store to real LFB
  1899.         mov     [LFB_BASE+edi], ax
  1900.         shr     eax, 16
  1901.         mov     [LFB_BASE+edi+2], al
  1902.         pop     ecx
  1903. ;--------------------------------------
  1904. align 4
  1905. snbgp:
  1906.         cmp     byte [_display.bpp], 25
  1907.         sbb     edi, -4
  1908.         add     ebp, 1
  1909.         mov     eax, [esp+20]
  1910.         add     eax, 1
  1911.         mov     [esp+20], eax
  1912.         add     esi, 4
  1913.         cmp     eax, [draw_data+32+RECT.right]
  1914.         jbe     sdp3a
  1915. ;--------------------------------------
  1916. align 4
  1917. sdp4:
  1918. ; next y
  1919.         mov     ebx, [esp+24]
  1920.         add     ebx, 1
  1921.         mov     [esp+24], ebx
  1922.         cmp     ebx, [draw_data+32+RECT.bottom]
  1923.         ja      sdpdone
  1924. ; advance edi, ebp to next scan line
  1925.         sub     eax, [draw_data+32+RECT.left]
  1926.         sub     ebp, eax
  1927.         add     ebp, [_display.width]
  1928.         sub     edi, eax
  1929.         sub     edi, eax
  1930.         sub     edi, eax
  1931.         cmp     byte [_display.bpp], 24
  1932.         jz      @f
  1933.         sub     edi, eax
  1934. ;--------------------------------------
  1935. align 4
  1936. @@:
  1937.         add     edi, [_display.pitch]
  1938. ; restore ecx,edx; advance esi to next background line
  1939.         mov     eax, [esp+28]
  1940.         mov     ebx, [esp+32]
  1941.         add     [esp+12], eax
  1942.         mov     eax, [esp+16]
  1943.         adc     [esp+16], ebx
  1944.         sub     eax, [esp+16]
  1945.         mov     ebx, eax
  1946.         lea     eax, [eax*3]
  1947.         imul    eax, [BgrDataWidth]
  1948.         sub     [esp], eax
  1949.         mov     eax, [draw_data+32+RECT.left]
  1950.         mov     [esp+20], eax
  1951.         test    ebx, ebx
  1952.         jz      sdp3
  1953.         cmp     ebx, -1
  1954.         jnz     bgr_resmooth0
  1955.         push    edi
  1956.         mov     esi, bgr_next_line
  1957.         mov     edi, bgr_cur_line
  1958.         mov     ecx, [_display.width]
  1959.         rep movsd
  1960.         jmp     bgr_resmooth1
  1961. ;--------------------------------------
  1962. align 4
  1963. sdpdone:
  1964.         add     esp, 44
  1965.         popad
  1966.         mov     [EGA_counter], 1
  1967.         cmp     [SCR_MODE], 0x12
  1968.         jne     @f
  1969.         call    VGA_drawbackground
  1970. ;--------------------------------------
  1971. align 4
  1972. @@:
  1973.         ret
  1974.  
  1975. uglobal
  1976. ;--------------------------------------
  1977. align 4
  1978. bgr_cur_line    rd      1920    ; maximum width of screen
  1979. bgr_next_line   rd      1920
  1980. ;--------------------------------------
  1981. endg
  1982. ;--------------------------------------
  1983. align 4
  1984. smooth_line:
  1985.         mov     al, [esi+2]
  1986.         shl     eax, 16
  1987.         mov     ax, [esi]
  1988.         test    ecx, ecx
  1989.         jz      @f
  1990.         mov     ebx, [esi+2]
  1991.         shr     ebx, 8
  1992.         call    [overlapping_of_points_ptr]
  1993. ;--------------------------------------
  1994. align 4
  1995. @@:
  1996.         stosd
  1997.         mov     eax, [esp+20+8]
  1998.         add     eax, 1
  1999.         mov     [esp+20+8], eax
  2000.         cmp     eax, [draw_data+32+RECT.right]
  2001.         ja      @f
  2002.         add     ecx, [esp+36+8]
  2003.         mov     eax, edx
  2004.         adc     edx, [esp+40+8]
  2005.         sub     eax, edx
  2006.         lea     eax, [eax*3]
  2007.         sub     esi, eax
  2008.         jmp     smooth_line
  2009. ;--------------------------------------
  2010. align 4
  2011. @@:
  2012.         mov     eax, [draw_data+32+RECT.left]
  2013.         mov     [esp+20+8], eax
  2014.         ret
  2015. ;------------------------------------------------------------------------------
  2016. align 16
  2017. overlapping_of_points:
  2018. if 0
  2019. ; this version of procedure works, but is slower than next version
  2020.         push    ecx edx
  2021.         mov     edx, eax
  2022.         push    esi
  2023.         shr     ecx, 24
  2024.         mov     esi, ecx
  2025.         mov     ecx, ebx
  2026.         movzx   ebx, dl
  2027.         movzx   eax, cl
  2028.         sub     eax, ebx
  2029.         movzx   ebx, dh
  2030.         imul    eax, esi
  2031.         add     dl, ah
  2032.         movzx   eax, ch
  2033.         sub     eax, ebx
  2034.         imul    eax, esi
  2035.         add     dh, ah
  2036.         ror     ecx, 16
  2037.         ror     edx, 16
  2038.         movzx   eax, cl
  2039.         movzx   ebx, dl
  2040.         sub     eax, ebx
  2041.         imul    eax, esi
  2042.         pop     esi
  2043.         add     dl, ah
  2044.         mov     eax, edx
  2045.         pop     edx
  2046.         ror     eax, 16
  2047.         pop     ecx
  2048.         ret
  2049. else
  2050.         push    ecx edx
  2051.         mov     edx, eax
  2052.         push    esi
  2053.         shr     ecx, 26
  2054.         mov     esi, ecx
  2055.         mov     ecx, ebx
  2056.         shl     esi, 9
  2057.         movzx   ebx, dl
  2058.         movzx   eax, cl
  2059.         sub     eax, ebx
  2060.         movzx   ebx, dh
  2061.         add     dl, [BgrAuxTable+(eax+0x100)+esi]
  2062.         movzx   eax, ch
  2063.         sub     eax, ebx
  2064.         add     dh, [BgrAuxTable+(eax+0x100)+esi]
  2065.         ror     ecx, 16
  2066.         ror     edx, 16
  2067.         movzx   eax, cl
  2068.         movzx   ebx, dl
  2069.         sub     eax, ebx
  2070.         add     dl, [BgrAuxTable+(eax+0x100)+esi]
  2071.         pop     esi
  2072.         mov     eax, edx
  2073.         pop     edx
  2074.         ror     eax, 16
  2075.         pop     ecx
  2076.         ret
  2077. end if
  2078.  
  2079. iglobal
  2080. ;--------------------------------------
  2081. align 4
  2082. overlapping_of_points_ptr       dd      overlapping_of_points
  2083. ;--------------------------------------
  2084. endg
  2085. ;------------------------------------------------------------------------------
  2086. align 4
  2087. init_background:
  2088.         mov     edi, BgrAuxTable
  2089.         xor     edx, edx
  2090. ;--------------------------------------
  2091. align 4
  2092. .loop2:
  2093.         mov     eax, edx
  2094.         shl     eax, 8
  2095.         neg     eax
  2096.         mov     ecx, 0x200
  2097. ;--------------------------------------
  2098. align 4
  2099. .loop1:
  2100.         mov     byte [edi], ah
  2101.         inc     edi
  2102.         add     eax, edx
  2103.         loop    .loop1
  2104.         add     dl, 4
  2105.         jnz     .loop2
  2106.         test    byte [cpu_caps+(CAPS_MMX/8)], 1 shl (CAPS_MMX mod 8)
  2107.         jz      @f
  2108.         mov     [overlapping_of_points_ptr], overlapping_of_points_mmx
  2109. ;--------------------------------------
  2110. align 4
  2111. @@:
  2112.         ret
  2113. ;------------------------------------------------------------------------------
  2114. align 16
  2115. overlapping_of_points_mmx:
  2116.         movd    mm0, eax
  2117.         movd    mm4, eax
  2118.         movd    mm1, ebx
  2119.         pxor    mm2, mm2
  2120.         punpcklbw mm0, mm2
  2121.         punpcklbw mm1, mm2
  2122.         psubw   mm1, mm0
  2123.         movd    mm3, ecx
  2124.         psrld   mm3, 24
  2125.         packuswb mm3, mm3
  2126.         packuswb mm3, mm3
  2127.         pmullw  mm1, mm3
  2128.         psrlw   mm1, 8
  2129.         packuswb mm1, mm2
  2130.         paddb   mm4, mm1
  2131.         movd    eax, mm4
  2132.         ret
  2133. ;------------------------------------------------------------------------------
  2134.