Subversion Repositories Kolibri OS

Rev

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

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