Subversion Repositories Kolibri OS

Rev

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

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