Subversion Repositories Kolibri OS

Rev

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