Subversion Repositories Kolibri OS

Rev

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

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