Subversion Repositories Kolibri OS

Rev

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

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