Subversion Repositories Kolibri OS

Rev

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

  1. $Revision: 425 $
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;                                                        ;;
  4. ;;  VESA20.INC                                            ;;
  5. ;;                                                        ;;
  6. ;;  Vesa 2.0 functions for MenuetOS                       ;;
  7. ;;                                                        ;;
  8. ;;  Copyright 2002 Ville Turjanmaa                        ;;
  9. ;;  Alexey, kgaz@crosswindws.net                          ;;
  10. ;;  - Voodoo compatible graphics                          ;;
  11. ;;  Juan M. Caravaca                                      ;;
  12. ;;  - Graphics optimimizations eg. drawline               ;;
  13. ;;                                                        ;;
  14. ;;  See file COPYING for details                          ;;
  15. ;;                                                        ;;
  16. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  17.  
  18. ; If you're planning to write your own video driver I suggest
  19. ; you replace the VESA12.INC file and see those instructions.
  20.  
  21. ;ScreenWidth             equ     0xfe00
  22. ;ScreenHeight            equ     0xfe04
  23. ;BytesPerScanLine        equ     0xfe08
  24. ;LFBAddress              equ     0xfe80
  25. ;ScreenBPP               equ     0xfbf1
  26. ;WinMapAddress           equ     0x460000
  27.  
  28.  
  29.  
  30. ;*************************************************
  31. ; getpixel
  32. ;
  33. ; in:
  34. ; eax = x coordinate
  35. ; ebx = y coordinate
  36. ;
  37. ; ret:
  38. ; ecx = 00 RR GG BB
  39.  
  40. getpixel:
  41.         push    eax ebx edx edi
  42.         call    dword [GETPIXEL]
  43.         pop     edi edx ebx eax
  44.         ret
  45.  
  46. Vesa20_getpixel24:
  47.         ; eax = x
  48.         ; ebx = y
  49.         imul    ebx, [BytesPerScanLine]    ; ebx = y * y multiplier
  50.         lea     edi, [eax+eax*2] ; edi = x*3
  51.         add     edi, ebx         ; edi = x*3+(y*y multiplier)
  52.         add     edi, [LFBAddress]    ; ebx = where pixel is in memory
  53.         mov     ecx, [edi]
  54.         and     ecx, 0xffffff
  55.         ret
  56.  
  57.  
  58. Vesa20_getpixel32:
  59.         imul    ebx, [BytesPerScanLine]    ; ebx = y * y multiplier
  60.         lea     edi, [ebx+eax*4] ; edi = x*4+(y*y multiplier)
  61.         add     edi, [LFBAddress]    ; ebx = where pixel is in memory
  62.         mov     ecx, [edi]
  63.         and     ecx, 0xffffff
  64.         ret
  65.  
  66. ;*************************************************
  67.  
  68. virtual at esp
  69.  putimg:
  70.    .real_sx        dd ?
  71.    .real_sy        dd ?
  72.    .image_sx       dd ?
  73.    .image_sy       dd ?
  74.    .image_cx       dd ?
  75.    .image_cy       dd ?
  76.    .pti            dd ?
  77.    .abs_cx         dd ?
  78.    .abs_cy         dd ?
  79.    .line_increment dd ?
  80.    .winmap_newline dd ?
  81.    .screen_newline dd ?
  82.    .stack_data = 4*12
  83.    .edi         dd      ?
  84.    .esi         dd      ?
  85.    .ebp         dd      ?
  86.    .esp         dd      ?
  87.    .ebx         dd      ?
  88.    .edx         dd      ?
  89.    .ecx         dd      ?
  90.    .eax         dd      ?
  91.    .ret_addr    dd      ?
  92.    .arg_0       dd      ?
  93. end virtual
  94.  
  95. align 16
  96. ; ebx = pointer
  97. ; ecx = size [x|y]
  98. ; edx = coordinates [x|y]
  99. ; ebp = pointer to 'get' function
  100. ; esi = pointer to 'init' function
  101. ; edi = parameter for 'get' function
  102. vesa20_putimage:
  103.         pushad
  104.         call    [disable_mouse]
  105.  
  106.         sub     esp, putimg.stack_data
  107.  
  108.         ; save pointer to image
  109.         mov     [putimg.pti], ebx
  110.  
  111.         ; unpack the size
  112.         mov     eax, ecx
  113.         and     ecx, 0xFFFF
  114.         shr     eax, 16
  115.         mov     [putimg.image_sx], eax
  116.         mov     [putimg.image_sy], ecx
  117.  
  118.         ; unpack the coordinates
  119.         mov     eax, edx
  120.         and     edx, 0xFFFF
  121.         shr     eax, 16
  122.         mov     [putimg.image_cx], eax
  123.         mov     [putimg.image_cy], edx
  124.  
  125.         ; calculate absolute (i.e. screen) coordinates
  126.         mov     eax, [TASK_BASE]
  127.         mov     ebx, [eax-twdw + WDATA.box.left]
  128.         add     ebx, [putimg.image_cx]
  129.         mov     [putimg.abs_cx], ebx
  130.         mov     ebx, [eax-twdw + WDATA.box.top]
  131.         add     ebx, [putimg.image_cy]
  132.         mov     [putimg.abs_cy], ebx
  133.  
  134.         ; real_sx = MIN(wnd_sx-image_cx, image_sx);
  135.         mov     ebx, [eax-twdw + WDATA.box.width] ; ebx = wnd_sx
  136. ; \begin{diamond}[20.08.2006]
  137. ; note that WDATA.box.width is one pixel less than real window x-size
  138.         inc     ebx
  139. ; \end{diamond}[20.08.2006]
  140.         sub     ebx, [putimg.image_cx]
  141.         ja      @f
  142.         add     esp, putimg.stack_data
  143.         popad
  144.         ret
  145.       @@:
  146.         cmp     ebx, [putimg.image_sx]
  147.         jbe     .end_x
  148.         mov     ebx, [putimg.image_sx]
  149.       .end_x:
  150.         mov     [putimg.real_sx], ebx
  151.  
  152.         ; init real_sy
  153.         mov     ebx, [eax-twdw + WDATA.box.height] ; ebx = wnd_sy
  154. ; \begin{diamond}[20.08.2006]
  155.         inc     ebx
  156. ; \end{diamond}[20.08.2006]
  157.         sub     ebx, [putimg.image_cy]
  158.         ja      @f
  159.         add     esp, putimg.stack_data
  160.         popad
  161.         ret
  162.       @@:
  163.         cmp     ebx, [putimg.image_sy]
  164.         jbe     .end_y
  165.         mov     ebx, [putimg.image_sy]
  166.       .end_y:
  167.         mov     [putimg.real_sy], ebx
  168.  
  169.         ; line increment
  170.         mov     eax, [putimg.image_sx]
  171.         sub     eax, [putimg.real_sx]
  172. ;;        imul    eax, [putimg.source_bpp]
  173. ;        lea     eax, [eax + eax * 2]
  174.         call    esi
  175.         add     eax, [putimg.arg_0]
  176.         mov     [putimg.line_increment], eax
  177.  
  178.         ; winmap new line increment
  179.         mov     eax, [ScreenWidth]
  180.         inc     eax
  181.         sub     eax, [putimg.real_sx]
  182.         mov     [putimg.winmap_newline], eax
  183.  
  184.         ; screen new line increment
  185.         mov     eax, [BytesPerScanLine]
  186.         mov     ecx, [putimg.real_sx]
  187.         movzx   ebx, byte [ScreenBPP]
  188.         shr     ebx, 3
  189.         imul    ecx, ebx
  190.         sub     eax, ecx
  191.         mov     [putimg.screen_newline], eax
  192.  
  193.         ; pointer to image
  194.         mov     esi, [putimg.pti]
  195.  
  196.         ; pointer to screen
  197.         mov     edx, [putimg.abs_cy]
  198.         imul    edx, [BytesPerScanLine]
  199.         mov     eax, [putimg.abs_cx]
  200.         movzx   ebx, byte [ScreenBPP]
  201.         shr     ebx, 3
  202.         imul    eax, ebx
  203.         add     edx, eax
  204.         add     edx, [LFBAddress]
  205.  
  206.         ; pointer to pixel map
  207.         mov     eax, [putimg.abs_cy]
  208.         imul    eax, [ScreenWidth]
  209.         add     eax, [putimg.abs_cy]
  210.         add     eax, [putimg.abs_cx]
  211.         add     eax, WinMapAddress
  212.         xchg    eax, ebp
  213.  
  214.         ; get process number
  215.         mov     ebx, [CURRENT_TASK]
  216.  
  217.         cmp     byte [ScreenBPP], 32
  218.         je      put_image_end_32
  219.  
  220. ;put_image_end_24:
  221.         mov     edi, [putimg.real_sy]
  222.         align   4
  223.       .new_line:
  224.         mov     ecx, [putimg.real_sx]
  225.  
  226. ;        push    ebp edx
  227.         align   4
  228.           .new_x:
  229.  
  230.                 push    [putimg.edi]
  231.                 mov     eax, [putimg.ebp+4]
  232.                 call    eax
  233.                 cmp     [ebp], bl
  234.                 jne     .skip
  235. ;                mov     eax, [esi]        ; eax = RRBBGGRR
  236.                 mov     [edx], ax
  237.                 shr     eax, 16
  238.                 mov     [edx+2], al
  239.               .skip:
  240.  
  241. ;            add     esi, 3 ;[putimg.source_bpp]
  242.             add     edx, 3
  243.             inc     ebp
  244.  
  245.             dec     ecx
  246.             jnz     .new_x
  247. ;        pop     edx ebp
  248.  
  249.         add     esi, [putimg.line_increment]
  250.         add     edx, [putimg.screen_newline] ;[BytesPerScanLine]
  251.         add     ebp, [putimg.winmap_newline] ;[ScreenWidth]
  252.         ;inc     ebp
  253.  
  254.         dec     edi
  255.         jnz     .new_line
  256.    .finish:
  257.         add     esp, putimg.stack_data
  258.         popad
  259. ret
  260.  
  261. put_image_end_32:
  262.         mov     edi, [putimg.real_sy]
  263.         align   4
  264.       .new_line:
  265.         mov     ecx, [putimg.real_sx]
  266.  
  267. ;        push    ebp edx
  268.         align   4
  269.           .new_x:
  270.  
  271.                 push    [putimg.edi]
  272.                 mov     eax, [putimg.ebp+4]
  273.                 call    eax
  274.                 cmp     [ebp], bl
  275.                 jne     .skip
  276. ;                mov     eax, [esi]        ; ecx = RRBBGGRR
  277.                 mov     [edx], eax
  278.               .skip:
  279.  
  280. ;            add     esi, [putimg.source_bpp]
  281.             add     edx, 4
  282.             inc     ebp
  283.  
  284.             dec     ecx
  285.             jnz     .new_x
  286. ;        pop     edx ebp
  287.  
  288.         add     esi, [putimg.line_increment]
  289.         add     edx, [putimg.screen_newline] ;[BytesPerScanLine]
  290.         add     ebp, [putimg.winmap_newline] ;[ScreenWidth]
  291.         ;inc     ebp
  292.  
  293.         dec     edi
  294.         jnz     .new_line
  295.    .finish:
  296.         add     esp, putimg.stack_data
  297.         popad
  298.         call   VGA__putimage
  299.         mov     [EGA_counter],1
  300. ret
  301.  
  302.  
  303. ;*************************************************
  304. align 4
  305. __sys_putpixel:
  306.  
  307. ; eax = x coordinate
  308. ; ebx = y coordinate
  309. ; ecx = ?? RR GG BB    ; 0x01000000 negation
  310. ; edi = 0x00000001 force
  311.  
  312. ;;;        mov  [novesachecksum], dword 0
  313.  
  314.         pushad
  315.         test  edi,1                 ; force ?
  316.         jnz   .forced
  317.       ; not forced:
  318.         push  ecx               ; save 24th bit in case negative pixel wanted
  319.         call  checkpixel
  320.         test  ecx,ecx
  321.         pop   ecx
  322.         jnz   .exit
  323.       .forced:
  324.         cmp   [ScreenWidth], eax
  325.         jb    .exit
  326.         cmp   [ScreenHeight], ebx
  327.         jb    .exit
  328.       .ok:
  329.         ; check if negation
  330.         test  ecx,0x01000000
  331.         jz    .noneg
  332.         call  getpixel
  333.         not   ecx
  334.         mov   [esp+32-8],ecx
  335.       .noneg:
  336.         ; OK to set pixel
  337.         call  dword [PUTPIXEL]    ; call the real put_pixel function
  338.       .exit:
  339.         popad
  340.  
  341.         ret
  342.  
  343. align 4
  344. Vesa20_putpixel24:
  345.  
  346.         ; eax = x
  347.         ; ebx = y
  348.  
  349.         imul    ebx, [BytesPerScanLine]     ; ebx = y * y multiplier
  350.         lea     edi, [eax+eax*2]  ; edi = x*3
  351.         mov     eax, [esp+32-8+4]
  352.         add     edi, [LFBAddress]
  353.         add     edi, ebx          ; ebx = where to put pixel in memory
  354.         mov     [edi], ax
  355.         shr     eax, 16
  356.         mov     [edi+2], al
  357.  
  358.         ret
  359.  
  360.  
  361. align 4
  362. Vesa20_putpixel32:
  363.  
  364.         ; eax = x
  365.         ; ebx = y
  366.  
  367.         imul    ebx, [BytesPerScanLine]     ; ebx = y * y multiplier
  368.         lea     edi, [ebx+eax*4]  ; edi = x*4+(y*y multiplier)
  369.         mov     eax, [esp+32-8+4] ; eax = color
  370.         add     edi, [LFBAddress]     ; ebx = where to put pixel in memory
  371.         mov     [edi], eax
  372.  
  373.         ret
  374.  
  375.  
  376. ;*************************************************
  377.  
  378. ;align 4
  379. calculate_edi:
  380.         mov     edi, ebx
  381.         imul    edi, [ScreenWidth]
  382.         add     edi, ebx
  383.         add     edi, eax
  384. ret
  385.  
  386. ;*************************************************
  387.  
  388. ; DRAWLINE
  389.  
  390. align 4
  391. __sys_draw_line:
  392. ;     inc   [mouse_pause]
  393.         call    [disable_mouse]
  394.  
  395. ; draw a line
  396. ; eax = HIWORD = x1
  397. ;       LOWORD = x2
  398. ; ebx = HIWORD = y1
  399. ;       LOWORD = y2
  400. ; ecx = color
  401. ; edi = force ?
  402.         pusha
  403.  
  404. dl_x1 equ esp+20
  405. dl_y1 equ esp+16
  406. dl_x2 equ esp+12
  407. dl_y2 equ esp+8
  408. dl_dx equ esp+4
  409. dl_dy equ esp+0
  410.  
  411.         xor     edx, edx      ; clear edx
  412.         xor     esi, esi      ; unpack arguments
  413.         xor     ebp, ebp
  414.         mov     si, ax        ; esi = x2
  415.         mov     bp, bx        ; ebp = y2
  416.         shr     eax, 16       ; eax = x1
  417.         shr     ebx, 16       ; ebx = y1
  418.  
  419.         push    eax           ; save x1
  420.         push    ebx           ; save y1
  421.         push    esi           ; save x2
  422.         push    ebp           ; save y2
  423.  
  424.         ; checking x-axis...
  425.         sub     esi, eax      ; esi = x2-x1
  426.         push    esi           ; save y2-y1
  427.         jl      .x2lx1        ; is x2 less than x1 ?
  428.         jg      .no_vline     ; x1 > x2 ?
  429.         mov     edx, ebp      ; else (if x1=x2)
  430.         call    vline
  431.         push    edx    ; necessary to rightly restore stack frame at .exit
  432.         jmp     .exit
  433. .x2lx1:
  434.         neg     esi            ; get esi absolute value
  435. .no_vline:
  436.  
  437.         ; checking y-axis...
  438.         sub     ebp, ebx       ; ebp = y2-y1
  439.         push    ebp            ; save y2-y1
  440.         jl      .y2ly1         ; is y2 less than y1 ?
  441.         jg      .no_hline      ; y1 > y2 ?
  442.         mov     edx, [dl_x2]   ; else (if y1=y2)
  443.         call    hline
  444.         jmp     .exit
  445. .y2ly1:
  446.         neg     ebp            ; get ebp absolute value
  447. .no_hline:
  448.  
  449.  
  450.         cmp     ebp, esi
  451.         jle     .x_rules       ; |y2-y1| < |x2-x1|  ?
  452.  
  453.         cmp     [dl_y2], ebx   ; make sure y1 is at the begining
  454.         jge     .no_reverse1
  455.  
  456.         neg     dword [dl_dx]
  457.         mov     edx, [dl_x2]
  458.         mov     [dl_x2], eax
  459.         mov     [dl_x1], edx
  460.         mov     edx, [dl_y2]
  461.         mov     [dl_y2], ebx
  462.         mov     [dl_y1], edx
  463.  
  464. .no_reverse1:
  465.  
  466.         mov     eax, [dl_dx]
  467.         cdq                    ; extend eax sing to edx
  468.         shl     eax, 16        ; using 16bit fix-point maths
  469.         idiv    ebp            ; eax = ((x2-x1)*65536)/(y2-y1)
  470.         mov     edx, ebp       ; edx = counter (number of pixels to draw)
  471.         mov     ebp, 1 *65536  ; <<16   ; ebp = dy = 1.0
  472.         mov     esi, eax       ; esi = dx
  473.  
  474.         jmp     .y_rules
  475. .x_rules:
  476.  
  477.         cmp     [dl_x2], eax    ; make sure x1 is at the begining
  478.         jge     .no_reverse2
  479.  
  480.         neg     dword [dl_dy]
  481.         mov     edx, [dl_x2]
  482.         mov     [dl_x2], eax
  483.         mov     [dl_x1], edx
  484.         mov     edx, [dl_y2]
  485.         mov     [dl_y2], ebx
  486.         mov     [dl_y1], edx
  487.  
  488. .no_reverse2:
  489.  
  490.         xor     edx, edx
  491.         mov     eax, [dl_dy]
  492.         cdq                    ; extend eax sing to edx
  493.         shl     eax, 16        ; using 16bit fix-point maths
  494.         idiv    esi            ; eax = ((y2-y1)*65536)/(x2-x1)
  495.         mov     edx, esi       ; edx = counter (number of pixels to draw)
  496.         mov     esi, 1 *65536  ;<< 16   ; esi = dx = 1.0
  497.         mov     ebp, eax       ; ebp = dy
  498.  
  499. .y_rules:
  500.  
  501.         mov     eax, [dl_x1]
  502.         mov     ebx, [dl_y1]
  503.         shl     eax, 16
  504.         shl     ebx, 16
  505.  
  506. align 4
  507.  
  508. .draw:
  509.         push    eax ebx
  510.         shr     eax, 16
  511.         shr     ebx, 16
  512.         call    [putpixel]
  513.         pop     ebx eax
  514.  
  515.         add     ebx, ebp        ; y = y+dy
  516.         add     eax, esi        ; x = x+dx
  517.  
  518.         dec     edx
  519.         jnz     .draw
  520.  
  521.         ; force last drawn pixel to be at (x2,y2)
  522.         mov     eax, [dl_x2]
  523.         mov     ebx, [dl_y2]
  524.         call    [putpixel]
  525. .exit:
  526.         add     esp, 6*4
  527.         popa
  528. ;     dec   [mouse_pause]
  529.      call   [draw_pointer]
  530. ret
  531.  
  532.  
  533. hline:
  534. ; draw an horizontal line
  535. ; eax = x1
  536. ; edx = x2
  537. ; ebx = y
  538. ; ecx = color
  539. ; edi = force ?
  540.         push    eax edx
  541.  
  542.         cmp     edx, eax      ; make sure x2 is above x1
  543.         jge     @f
  544.         xchg    eax, edx
  545.         align   4
  546.    @@:
  547.         call    [putpixel]
  548.         inc     eax
  549.         cmp     eax, edx
  550.         jle     @b
  551.  
  552.         pop     edx eax
  553. ret
  554.  
  555.  
  556. vline:
  557. ; draw a vertical line
  558. ; eax = x
  559. ; ebx = y1
  560. ; edx = y2
  561. ; ecx = color
  562. ; edi = force ?
  563.         push    ebx edx
  564.  
  565.         cmp     edx, ebx      ; make sure y2 is above y1
  566.         jge     @f
  567.         xchg    ebx, edx
  568.         align   4
  569.    @@:
  570.         call    [putpixel]
  571.         inc     ebx
  572.         cmp     ebx, edx
  573.         jle     @b
  574.  
  575.         pop     edx ebx
  576. ret
  577.  
  578.  
  579. ;*************************************************
  580.  
  581.  
  582. virtual at esp
  583.       drbar:
  584.         .bar_sx       dd ?
  585.         .bar_sy       dd ?
  586.         .bar_cx       dd ?
  587.         .bar_cy       dd ?
  588.         .abs_cx       dd ?
  589.         .abs_cy       dd ?
  590.         .real_sx      dd ?
  591.         .real_sy      dd ?
  592.         .color        dd ?
  593.         .line_inc_scr dd ?
  594.         .line_inc_map dd ?
  595.         .stack_data = 4*11
  596. end virtual
  597.  
  598. align 4
  599. ; eax   cx
  600. ; ebx   cy
  601. ; ecx   xe
  602. ; edx   ye
  603. ; edi   color
  604. vesa20_drawbar:
  605.  
  606.         pushad
  607.         call    [disable_mouse]
  608.  
  609.         sub     esp, drbar.stack_data
  610.  
  611.         mov     [drbar.color], edi
  612.  
  613.         sub     edx, ebx
  614.         jle     .exit          ;// mike.dld, 2005-01-29
  615.         sub     ecx, eax
  616.         jle     .exit          ;// mike.dld, 2005-01-29
  617.         mov     [drbar.bar_sy], edx
  618.         mov     [drbar.bar_sx], ecx
  619.  
  620.         mov     [drbar.bar_cx], eax
  621.         mov     [drbar.bar_cy], ebx
  622.  
  623.         mov     edi, [TASK_BASE]
  624.         add     eax, [edi-twdw + WDATA.box.left] ; win_cx
  625.         add     ebx, [edi-twdw + WDATA.box.top] ; win_cy
  626.         mov     [drbar.abs_cx], eax
  627.         mov     [drbar.abs_cy], ebx
  628.  
  629.         ; real_sx = MIN(wnd_sx-bar_cx, bar_sx);
  630.         mov     ebx, [edi-twdw + WDATA.box.width] ; ebx = wnd_sx
  631. ; \begin{diamond}[20.08.2006]
  632. ; note that WDATA.box.width is one pixel less than real window x-size
  633.         inc     ebx
  634. ; \end{diamond}[20.08.2006]
  635.         sub     ebx, [drbar.bar_cx]
  636.         ja      @f
  637.   .exit:                       ;// mike.dld, 2005-01-29
  638.         add     esp, drbar.stack_data
  639.         popad
  640.         xor     eax, eax
  641.         inc     eax
  642.  
  643.         ret
  644.       @@:
  645.         cmp     ebx, [drbar.bar_sx]
  646.         jbe     .end_x
  647.         mov     ebx, [drbar.bar_sx]
  648.       .end_x:
  649.         mov     [drbar.real_sx], ebx
  650.  
  651.         ; real_sy = MIN(wnd_sy-bar_cy, bar_sy);
  652.         mov     ebx, [edi-twdw + WDATA.box.height] ; ebx = wnd_sy
  653. ; \begin{diamond}[20.08.2006]
  654.         inc     ebx
  655. ; \end{diamond}
  656.         sub     ebx, [drbar.bar_cy]
  657.         ja      @f
  658.         add     esp, drbar.stack_data
  659.         popad
  660.         xor     eax, eax
  661.         inc     eax
  662.  
  663.         ret
  664.       @@:
  665.         cmp     ebx, [drbar.bar_sy]
  666.         jbe     .end_y
  667.         mov     ebx, [drbar.bar_sy]
  668.       .end_y:
  669.         mov     [drbar.real_sy], ebx
  670.  
  671.         ; line_inc_map
  672.         mov     eax, [ScreenWidth]
  673.         sub     eax, [drbar.real_sx]
  674.         inc     eax
  675.         mov     [drbar.line_inc_map], eax
  676.  
  677.         ; line_inc_scr
  678.         mov     eax, [drbar.real_sx]
  679.         movzx   ebx, byte [ScreenBPP]
  680.         shr     ebx, 3
  681.         imul    eax, ebx
  682.         neg     eax
  683.         add     eax, [BytesPerScanLine]
  684.         mov     [drbar.line_inc_scr], eax
  685.  
  686.         ; pointer to screen
  687.         mov     edx, [drbar.abs_cy]
  688.         imul    edx, [BytesPerScanLine]
  689.         mov     eax, [drbar.abs_cx]
  690. ;        movzx   ebx, byte [ScreenBPP]
  691. ;        shr     ebx, 3
  692.         imul    eax, ebx
  693.         add     edx, eax
  694.         add     edx, [LFBAddress]
  695.  
  696.         ; pointer to pixel map
  697.         mov     eax, [drbar.abs_cy]
  698.         imul    eax, [ScreenWidth]
  699.         add     eax, [drbar.abs_cy]
  700.         add     eax, [drbar.abs_cx]
  701.         add     eax, WinMapAddress
  702.         xchg    eax, ebp
  703.  
  704.         ; get process number
  705.         mov     ebx, [CURRENT_TASK]
  706.  
  707.         cmp     byte [ScreenBPP], 24
  708.         jne     draw_bar_end_32
  709. draw_bar_end_24:
  710.         mov     eax, [drbar.color]    ;; BBGGRR00
  711.         mov     bh, al                ;; bh  = BB
  712.         shr     eax, 8                ;; eax = RRGG
  713. ; eax - color high   RRGG
  714. ; bl - process num
  715. ; bh - color low    BB
  716. ; ecx - temp
  717. ; edx - pointer to screen
  718. ; esi - counter
  719. ; edi - counter
  720.  
  721.         mov     esi, [drbar.real_sy]
  722.         align   4
  723.      .new_y:
  724.         mov     edi, [drbar.real_sx]
  725.         align   4
  726.      .new_x:
  727.  
  728.         cmp     byte [ebp], bl
  729.         jne     .skip
  730.         mov     [edx], bh
  731.         mov     [edx + 1], ax
  732.       .skip:
  733.  
  734.         ; add pixel
  735.         add     edx, 3
  736.         inc     ebp
  737.  
  738.         dec     edi
  739.         jnz     .new_x
  740.  
  741.         ; add line
  742.         add     edx, [drbar.line_inc_scr]
  743.         add     ebp, [drbar.line_inc_map]
  744.  
  745.     ; <Ivan 15.10.04> drawing gradient bars
  746.         test    eax, 0x00800000
  747.         jz      @f
  748.         test    bh, bh
  749.         jz      @f
  750.         dec     bh
  751.       @@:
  752.     ; </Ivan 15.10.04>
  753.  
  754.         dec     esi
  755.         jnz     .new_y
  756.  
  757.         add     esp, drbar.stack_data
  758.         popad
  759.         xor     eax, eax
  760. ret
  761.  
  762. draw_bar_end_32:
  763.         mov     eax, [drbar.color]    ;; BBGGRR00
  764.  
  765.         mov     esi, [drbar.real_sy]
  766.         align   4
  767.      .new_y:
  768.         mov     edi, [drbar.real_sx]
  769.         align   4
  770.      .new_x:
  771.  
  772.         cmp     byte [ebp], bl
  773.         jne     .skip
  774.         mov     [edx], eax
  775.       .skip:
  776.  
  777.         ; add pixel
  778.         add     edx, 4
  779.         inc     ebp
  780.  
  781.         dec     edi
  782.         jnz     .new_x
  783.  
  784.         ; add line
  785.         add     edx, [drbar.line_inc_scr]
  786.         add     ebp, [drbar.line_inc_map]
  787.  
  788.     ; <Ivan 15.10.04> drawing gradient bars
  789.         test    eax, 0x80000000
  790.         jz      @f
  791.         test    al, al
  792.         jz      @f
  793.         dec     al
  794.       @@:
  795.     ; </Ivan 15.10.04>
  796.  
  797.         dec     esi
  798.         jnz     .new_y
  799.  
  800.         add     esp, drbar.stack_data
  801.         popad
  802.         call    VGA_draw_bar
  803.         xor     eax, eax
  804.         mov     [EGA_counter],1
  805. ret
  806.  
  807.  
  808. ;voodoodbcplimit:
  809.  
  810. ; ebp:=(y+Ywin)*(ScreenXSize+1)+(x+Xwin)+AddrBuffer
  811.  
  812.  
  813. ;     pusha
  814.  
  815. ;     xor edx,edx
  816. ;     mov eax,ebp
  817. ;     mov ebx,[ScreenWidth] ; Screen_X_size
  818. ;     inc ebx   ; +1
  819. ;     sub eax,WinMapAddress ; -AddrBuffer
  820. ;     div ebx ;
  821. ;     mov ebx,eax ; ebx:=Y
  822. ;     mov eax,edx ; eax:=X
  823. ;     call cplimit
  824.  
  825. ;     test ecx,ecx
  826. ;     jne  dbcpl12
  827. ;     popa
  828. ;     clc
  829. ;     ret
  830. ;   dbcpl12:
  831. ;     popa
  832. ;     stc
  833. ;     ret
  834.  
  835.  
  836.  
  837.  
  838. ;dbcplimit:
  839.  
  840. ;        pusha
  841.  
  842. ;        xor  edx,edx
  843. ;        mov  ebx,[ScreenWidth]
  844. ;        inc  ebx
  845. ;        sub  eax,WinMapAddress
  846. ;        div  ebx
  847. ;        mov  ebx,eax
  848. ;        mov  eax,edx
  849. ;        call cplimit
  850.  
  851. ;        test ecx,ecx
  852. ;        jne  dbcpl1
  853. ;        popa
  854. ;        clc
  855. ;        ret
  856. ;     dbcpl1:
  857. ;        popa
  858. ;        stc
  859. ;        ret
  860.  
  861.  
  862.  
  863.  
  864.  
  865.  
  866. ;--------------vbe voodoo ------------------------------------------------
  867. vesa20_drawbackground_tiled:
  868.  
  869.      call [disable_mouse]
  870.  
  871.      push ebp
  872.      push eax
  873.      push ebx
  874.      push ecx
  875.      push edx
  876.  
  877.      mov edx,dword [WinMapAddress-8] ; B
  878.      add edx,dword [WinMapAddress-8] ; +B
  879.      add edx,dword [WinMapAddress-8] ; +B
  880.      push edx
  881.  
  882.      mov ebp,[draw_data+32+RECT.left] ; x start:=(x+Xwin)
  883.      mov ebx,[draw_data+32+RECT.top] ; y start:=(y+Ywin)
  884.  
  885.      mov eax,[BytesPerScanLine]
  886.      mul ebx
  887.      xchg ebp, eax  ; BytesPerScanLine*(Ywin+y)
  888.      add ebp, eax   ; +X
  889.      add ebp, eax   ; +X
  890.      add ebp, eax   ; +X
  891.  
  892.      cmp [ScreenBPP],byte 24 ; 24 or 32 bpp ? - x size
  893.      jz @f
  894.      add ebp,eax ; +X
  895.    @@:
  896.      add ebp,[LFBAddress]  ; +LFB
  897.  
  898.      ; ebp:=Y*BytesPerScanLine+X*BytesPerPixel+AddrLFB
  899.  
  900.      call calculate_edi
  901.  
  902.  
  903.    dp3:                             ; MAIN LOOP
  904.  
  905.      cmp [edi+WinMapAddress],byte 1 ; ptrBuffer^<>byte(1)
  906. ;     je  ybgp
  907. ;
  908. ;     jmp nbgp
  909. ;
  910. ;   ybgp:
  911.      jne nbgp
  912.  
  913.      push eax
  914.      push ebx
  915.  
  916.      mov ecx,dword [WinMapAddress-8]    ; B
  917.      xor edx,edx                   ; edx:=0
  918.      div ecx                       ; Xstart/B
  919.  
  920.      ; eax=Int(qn) edx:=Rem
  921.  
  922.      lea esi,[edx+edx*2]           ; esi:=edx*3
  923.  
  924.      mov ecx,dword [WinMapAddress-4]    ; ecx:=H
  925.      mov eax,[esp+0]               ; eax:=Ystart
  926.      xor edx,edx                   ;
  927.      div ecx                       ; Ystart/H
  928.  
  929.      mov eax,edx                   ; eax:=Rem
  930.      xor edx,edx                   ;
  931.      mov ebx,[esp+8]               ; ebx:=B*3
  932.      mul ebx                       ;
  933.      add esi,eax                   ;
  934.      mov eax,[esi+IMG_BACKGROUND]
  935.      and eax,0xffffff
  936.  
  937.      xchg edi, ebp
  938.      stosw
  939.      shr eax,16
  940.      stosb
  941.      xchg ebp, edi                 ; ebp+=3
  942.      cmp [ScreenBPP],byte 24       ; 24 or 32 bpp ? - x size
  943.      jz @f
  944.      inc ebp ; +1
  945.    @@:
  946.  
  947.      pop ebx
  948.      pop eax
  949.  
  950.      jmp hook1
  951.  
  952.    nbgp:
  953.      add ebp,3                     ; +3
  954.      cmp [ScreenBPP],byte 24       ; 24 or 32 bpp ? - x size
  955.      jz  @f
  956.      inc ebp ; +1
  957.    @@:
  958.  
  959.    hook1:
  960.  
  961.      inc edi                       ; ptrBuffer++
  962.      add esi,3                     ; ptrImage+=3
  963.      inc eax
  964.      cmp eax,[draw_data+32+RECT.right]         ; X > xend?
  965. ;     jg nodp3
  966. ;     jmp dp3
  967. ;
  968. ;   nodp3:
  969.      jle dp3
  970.  
  971.      mov ebp,[draw_data+32+RECT.left]
  972.  
  973.      inc ebx
  974.  
  975.      mov  eax,[BytesPerScanLine]
  976.      mul  ebx
  977.      xchg ebp, eax                 ; BytesPerScanLine*(Ywin+y)
  978.      add  ebp, eax                 ; +X
  979.      add  ebp, eax                 ; +X=X*2
  980.      add  ebp, eax                 ; +X=X*3
  981.      cmp  [ScreenBPP],byte 24      ; 24 or 32 bpp ? - x size
  982.      jz   @f
  983.      add  ebp,eax                  ; +X=X*4
  984.    @@:
  985.      add ebp,[LFBAddress]          ; +LFB
  986.  
  987.      ; ebp:=Y*BytesPerScanLine+X*BytesPerPixel+AddrLFB
  988.  
  989.      call calculate_edi
  990.  
  991.      cmp ebx,[draw_data+32+RECT.bottom]
  992. ;     jg  dp4
  993. ;
  994. ;     jmp dp3
  995. ;
  996. ;   dp4:
  997.      jle dp3
  998.  
  999.      add esp,4
  1000.  
  1001.      pop edx
  1002.      pop ecx
  1003.      pop ebx
  1004.      pop eax
  1005.      pop ebp
  1006.      mov     [EGA_counter],1
  1007.      call  VGA_drawbackground
  1008.      ret
  1009.  
  1010. ; ----------
  1011.  
  1012.  
  1013. vesa20_drawbackground_stretch:
  1014.  
  1015.      call  [disable_mouse]
  1016.  
  1017.      push ebp
  1018.      push eax
  1019.      push ebx
  1020.      push ecx
  1021.      push edx
  1022.  
  1023.      mov edx,dword [WinMapAddress-8] ; B
  1024.      add edx,dword [WinMapAddress-8] ; +B
  1025.      add edx,dword [WinMapAddress-8] ; +B
  1026.      push edx
  1027.  
  1028.      mov ebp,[draw_data+32+RECT.left] ; x start:=(x+Xwin)
  1029.      mov ebx,[draw_data+32+RECT.top] ; y start:=(y+Ywin)
  1030.  
  1031.      mov eax,[BytesPerScanLine]
  1032.      mul ebx
  1033.      xchg ebp, eax  ; BytesPerScanLine*(Ywin+y)
  1034.      add ebp, eax   ; +X
  1035.      add ebp, eax   ; +X
  1036.      add ebp, eax   ; +X
  1037.  
  1038.      cmp [ScreenBPP],byte 24 ; 24 or 32 bpp ? - x size
  1039.      jz  @f
  1040.      add ebp,eax ; +X
  1041.    @@:
  1042.      add ebp,[LFBAddress] ; +LFB
  1043.  
  1044.      ; ebp:=Y*BytesPerScanLine+X*BytesPerPixel+AddrLFB
  1045.  
  1046.      call calculate_edi
  1047.  
  1048.  
  1049. sdp3: ; MAIN LOOP
  1050. cmp [edi+WinMapAddress],byte 1 ; ptrBuffer^<>byte(1)
  1051. jne snbgp
  1052. push eax
  1053. push ebx
  1054. mov eax,dword [WinMapAddress-8]
  1055. imul eax, [esp+4] ;4
  1056. xor edx,edx
  1057. mov ebx,[ScreenWidth]
  1058. div ebx
  1059. mov cx,dx
  1060. lea esi,[eax+eax*2]
  1061. mov eax,dword [WinMapAddress-4]
  1062. imul eax, [esp+0] ;0
  1063. xor edx,edx
  1064. mov ebx,[ScreenHeight]
  1065. div ebx
  1066. shl ecx,16
  1067. mov cx,dx
  1068. imul eax, [esp+8] ;8
  1069. add esi,eax
  1070. mov eax,[esi+IMG_BACKGROUND]
  1071. push eax
  1072. ror ecx,16
  1073. xor eax,eax
  1074. mov ax,cx
  1075. shl eax,1 ; óìíîæåíèå íà 2
  1076. lea eax,[eax+eax*4] ; óìíîæåíèå íà 5
  1077. xor edx,edx
  1078. mov ebx,[ScreenWidth]
  1079. div ebx
  1080. cmp eax,5
  1081. pop eax
  1082. jb @f
  1083. mov ebx,[esi+IMG_BACKGROUND+3]
  1084. call overlapping_of_points
  1085. @@:
  1086. push eax
  1087. ror ecx,16
  1088. xor eax,eax
  1089. mov ax,cx
  1090. shl eax,1 ; óìíîæåíèå íà 2
  1091. lea eax,[eax+eax*4] ; óìíîæåíèå íà
  1092. xor edx,edx
  1093. mov ebx,[ScreenHeight]
  1094. div ebx
  1095. cmp eax,5
  1096. pop eax
  1097. jb @f
  1098. mov ebx,[display_data-8]
  1099. shl ebx,1
  1100. add ebx,[display_data-8]
  1101. add ebx,IMG_BACKGROUND
  1102. add ebx,esi
  1103. mov ebx,[ebx]
  1104. call overlapping_of_points
  1105. @@:
  1106. and eax,0xffffff
  1107. xchg edi, ebp
  1108. stosw
  1109. shr eax,16
  1110. stosb
  1111. xchg ebp, edi ; ebp+=3
  1112. cmp [ScreenBPP],byte 24 ; 24 or 32 bpp ? - x size
  1113. jz @f
  1114. inc ebp ; +1
  1115. @@:
  1116. pop ebx
  1117. pop eax
  1118. jmp shook1
  1119.  
  1120. overlapping_of_points:
  1121. push ecx edi
  1122. mov ecx,eax
  1123. mov edx,ebx
  1124. xor eax,eax
  1125. mov al,cl
  1126. xor ebx,ebx
  1127. mov bl,dl
  1128. add eax,ebx
  1129. rcr eax,1
  1130. xor edi,edi
  1131. mov di,ax
  1132. xor eax,eax
  1133. mov al,ch
  1134. xor ebx,ebx
  1135. mov bl,dh
  1136. add eax,ebx
  1137. rcr eax,1
  1138. ror edi,8
  1139. add edi,eax
  1140. ror ecx,8
  1141. ror edx,8
  1142. xor eax,eax
  1143. mov al,ch
  1144. xor ebx,ebx
  1145. mov bl,dh
  1146. add eax,ebx
  1147. rcr eax,1
  1148. ror edi,8
  1149. add eax,edi
  1150. ror eax,16
  1151. pop edi ecx
  1152. ret
  1153.  
  1154.    snbgp:
  1155.      add  ebp,3                     ; +3
  1156.      cmp [ScreenBPP],byte 24        ; 24 or 32 bpp ? - x size
  1157.      jz  @f
  1158.      inc ebp ; +1
  1159.    @@:
  1160.  
  1161.    shook1:
  1162.  
  1163.      inc edi                       ; ptrBuffer++
  1164.      add esi,3                     ; ptrImage+=3
  1165.      inc eax
  1166.      cmp eax,[draw_data+32+RECT.right]         ; X > xend?
  1167.      jle sdp3
  1168.  
  1169.      mov ebp,[draw_data+32+RECT.left]
  1170.  
  1171.      inc ebx
  1172.  
  1173.      mov  eax,[BytesPerScanLine]
  1174.      mul  ebx
  1175.      xchg ebp, eax                 ; BytesPerScanLine*(Ywin+y)
  1176.      add  ebp, eax                 ; +X
  1177.      add  ebp, eax                 ; +X=X*2
  1178.      add  ebp, eax                 ; +X=X*3
  1179.      cmp  [ScreenBPP],byte 24      ; 24 or 32 bpp ? - x size
  1180.      jz   @f
  1181.      add  ebp,eax                  ; +X=X*4
  1182.    @@:
  1183.      add ebp,[LFBAddress]          ; +LFB
  1184.  
  1185.      ; ebp:=Y*BytesPerScanLine+X*BytesPerPixel+AddrLFB
  1186.  
  1187.      call calculate_edi
  1188.  
  1189.      cmp ebx,[draw_data+32+RECT.bottom]
  1190.      jle sdp3
  1191.  
  1192.      add esp,4
  1193.  
  1194.      pop edx
  1195.      pop ecx
  1196.      pop ebx
  1197.      pop eax
  1198.      pop ebp
  1199.      mov     [EGA_counter],1
  1200.      call  VGA_drawbackground
  1201.      ret
  1202.