Subversion Repositories Kolibri OS

Rev

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