Subversion Repositories Kolibri OS

Rev

Rev 9237 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2.  
  3. CATMULL_SHIFT  equ 8
  4. ROUND equ 8
  5. ;NON=0
  6. ;MMX=1
  7. ;SSE=2
  8. ;SSE2=3
  9.  
  10. ;Ext=SSE2
  11.  
  12.  
  13. ;TEX_SIZE=0x3fff
  14. ;SIZE_X equ 512
  15. ;SIZE_Y equ 512
  16. ;ROUND = 8
  17.  ; TEX_SHIFT equ 6
  18.  ; TEXTURE_SIZE = 0xFFFFF
  19.  
  20. ; procedure drawing textured triangle with Gouraud shading
  21. ; Z-buffer alghoritm included, Z coord interpolation ----
  22. ; I set the color by this way -- (col1 * col2)/256 ------
  23. ;------------------in - eax - x1 shl 16 + y1 ------------
  24. ;---------------------- ebx - x2 shl 16 + y2 ------------
  25. ;---------------------- ecx - x3 shl 16 + y3 ------------
  26. ;---------------------- esi - pointer to Z-buffer--------
  27. ;---------------------- edx - pointer to texture---------
  28. ;---------------------- Z-buffer filled with dd variables
  29. ;---------------------- shifted CATMULL_SHIFT------------
  30. ;---------------------- edi - pointer to screen buffer---
  31. ;---------------------- stack : colors-------------------
  32.  
  33.  
  34.  
  35. tex_plus_grd_triangle:
  36. ; parameters :
  37.    .tex_y3  equ [ebp+38]   ; 36 bytes through stack
  38.    .tex_x3  equ [ebp+36]
  39.    .tex_y2  equ [ebp+34]
  40.    .tex_x2  equ [ebp+32]
  41.    .tex_y1  equ [ebp+30]
  42.    .tex_x1  equ [ebp+28]
  43.  
  44.    .z3      equ [ebp+26]
  45.    .col3b   equ [ebp+24]
  46.    .col3g   equ [ebp+22]
  47.    .col3r   equ [ebp+20]
  48.  
  49.    .z2      equ [ebp+18]
  50.    .col2b   equ [ebp+16]
  51.    .col2g   equ [ebp+14]
  52.    .col2r   equ [ebp+12]
  53.  
  54.    .z1      equ [ebp+10]
  55.    .col1b   equ [ebp+8]
  56.    .col1g   equ [ebp+6]
  57.    .col1r   equ [ebp+4]
  58.  
  59. ; local variables:
  60.  
  61.    .tex_ptr   equ dword[ebp-4]
  62.    .z_ptr     equ dword[ebp-8]
  63.    .scr_buff  equ dword[ebp-12]
  64.  
  65.    .x1        equ  word[ebp-14] ;dw ? ;equ word[ebp-10]
  66.    .y1        equ  word[ebp-16] ;dw ? ;equ word[ebp-12]
  67.    .x2        equ  word[ebp-18] ;dw ? ;equ word[ebp-14]
  68.    .y2        equ  word[ebp-20] ;dw ? ;equ word[ebp-16]
  69.    .x3        equ  word[ebp-22] ;dw ? ;equ word[ebp-18]
  70.    .y3        equ  word[ebp-24] ;dw ? ;equ word[ebp-20]
  71.  
  72.    .dx12      equ  dword[ebp-28] ;dd ?
  73.    .tex_dy12  equ       [ebp-32] ;dd ?
  74.    .tex_dx12  equ       [ebp-36] ;dd ?
  75.    .dz12      equ  dword[ebp-40] ;dd ?
  76.    .dc12r     equ       [ebp-44] ;dd ?
  77.    .dc12g     equ  dword[ebp-48] ;dd ?
  78.    .dc12b     equ       [ebp-52] ;dd ?
  79.  
  80.    .dx23      equ  dword[ebp-56] ;dd ?
  81.    .tex_dy23  equ       [ebp-60] ;dd ?
  82.    .tex_dx23  equ       [ebp-64] ;dd ?
  83.    .dz23      equ  dword[ebp-68] ;dd ?
  84.    .dc23r     equ       [ebp-72] ;dd ?
  85.    .dc23g     equ  dword[ebp-76] ;dd ?
  86.    .dc23b     equ       [ebp-80] ;dword[ebp-8]dd ?
  87.  
  88.    .dx13      equ  dword[ebp-84] ;dd ?
  89.    .tex_dy13  equ       [ebp-88] ;dd ?
  90.    .tex_dx13  equ       [ebp-92] ;dd ?
  91.    .dz13      equ  dword[ebp-96] ;dd ?
  92.    .dc13r     equ       [ebp-100] ;dd ?
  93.    .dc13g     equ  dword[ebp-104] ;dd ?
  94.    .dc13b     equ       [ebp-108] ;dd ?
  95.  
  96.    .scan_y1   equ       [ebp-112] ;dd ?
  97.    .scan_x1   equ       [ebp-116] ;dd ?
  98.    .zz1       equ  dword[ebp-120] ;dw ?
  99.    .cur1r     equ       [ebp-124] ;dw ?
  100.    .cur1g     equ       [ebp-128] ;dw ?
  101.    .cur1b     equ       [ebp-132] ;dw ?
  102.  
  103.    .scan_y2   equ       [ebp-136] ;dd ?
  104.    .scan_x2   equ       [ebp-140] ;dd ?
  105.    .zz2       equ       [ebp-144] ;dw ?
  106.    .cur2r     equ       [ebp-148] ;dw ?
  107.    .cur2g     equ       [ebp-152] ;dw ?
  108.    .cur2b     equ       [ebp-156] ;dw ?
  109.  
  110.  
  111.        mov    ebp,esp
  112.  
  113.          push    edx esi edi
  114.  
  115.          mov      edx,80008000h  ; eax,ebx,ecx are ANDd together into edx which means that
  116.          and      edx,ebx        ; if *all* of them are negative a sign flag is raised
  117.          and      edx,ecx
  118.          and      edx,eax
  119.          test     edx,80008000h  ; Check both X&Y at once
  120.          jne      .loop2_end
  121.  
  122.    .sort3:
  123.        cmp     ax,bx
  124.        jle     .sort1
  125.        xchg    eax,ebx
  126. if Ext>=MMX
  127.        movq    mm0, .col1r       ; exchange r, g, b, z
  128.        movq    mm1, .col2r
  129.        movq    .col1r ,mm1
  130.        movq    .col2r ,mm0
  131. else
  132.        mov     edx,dword .col1r   ; exchange both r and g
  133.        xchg    edx,dword .col2r
  134.        mov     dword .col1r ,edx
  135.  
  136.        mov     edx,dword .col1b   ; b and z
  137.        xchg    edx,dword .col2b
  138.        mov     dword .col1b ,edx
  139. end if
  140.  
  141.        mov     edx,dword .tex_x1
  142.        xchg    edx,dword .tex_x2
  143.        mov     dword .tex_x1 ,edx
  144.  
  145.  .sort1:
  146.        cmp      bx,cx
  147.        jle      .sort2
  148.        xchg    ebx,ecx
  149.  
  150. if Ext>=MMX
  151.        movq    mm0, .col2r       ; exchange r, g, b, z
  152.        movq    mm1, .col3r
  153.        movq    .col3r ,mm0
  154.        movq    .col2r ,mm1
  155. else
  156.  
  157.        mov     edx,dword .col2r  ; r, g
  158.        xchg    edx,dword .col3r
  159.        mov     dword .col2r,edx
  160.  
  161.        mov     edx,dword .col2b  ; b, z
  162.        xchg    edx,dword .col3b
  163.        mov     dword .col2b,edx
  164. end if
  165.  
  166.        mov     edx,dword .tex_x2
  167.        xchg    edx,dword .tex_x3
  168.        mov     dword .tex_x2,edx
  169.  
  170.        jmp .sort3
  171.  
  172.  .sort2:
  173.  
  174.        push     eax ebx ecx         ; store in variables
  175.   ;     push     ebx
  176.   ;     push     ecx
  177.  
  178. ;****************** delta computng zone **************
  179. ;+++++++++ first zone
  180.        mov      bx,.y2       ; calc delta12
  181.        sub      bx,.y1
  182.        jnz      .dx12_make
  183.        mov      ecx,7
  184.      @@:
  185.        push     dword 0
  186.        loop     @b
  187.        jmp      .dx12_done
  188.   .dx12_make:
  189.      ;  sub      esp,7*4
  190.  
  191.        movsx    ebx,bx
  192.        mov      eax,1 shl 15
  193.        cdq
  194.        idiv     ebx
  195.     ;   push     eax
  196.        mov      ebx,eax
  197.  
  198.  
  199.        mov      ax,.x2
  200.        sub      ax,.x1
  201.        cwde
  202.        imul     ebx
  203.        sar      eax,15 - ROUND
  204.        push     eax
  205.     ;   mov      .dx12,eax
  206.  
  207.        sub       esp,6*4
  208.        movd      xmm0,ebx
  209.        pshuflw   xmm0,xmm0,0
  210.     ;   pshufd    xmm0,xmm0,0
  211.        movlhps   xmm0,xmm0
  212.        movq      xmm1,.col1r
  213.        movq      xmm2,.col2r
  214.        movhps    xmm1,.tex_x1
  215.        movhps    xmm2,.tex_x2
  216.        psubw     xmm2,xmm1
  217.        movdqa    xmm3,xmm2
  218.        pmullw    xmm2,xmm0
  219.        pmulhw    xmm3,xmm0
  220.        movhlps   xmm4,xmm2
  221.        movhlps   xmm5,xmm3
  222.        punpcklwd xmm2,xmm3
  223.        punpcklwd xmm4,xmm5
  224.        psrad     xmm2,15 - ROUND
  225.        psrad     xmm4,15 - ROUND
  226.        pshufd    xmm2,xmm2,11000110b
  227.        movdqu    .dc12b,xmm2
  228.    ;    punpcklwd xmm4,xmm5
  229.     ;   psrad     xmm4,15 - ROUND
  230.        movq      .tex_dx12,xmm4
  231.  
  232.  
  233. ;+++++++++++++++++ second zone +++++++++++++
  234.    .dx12_done:
  235.  
  236.        mov      bx,.y3       ; calc delta23
  237.        sub      bx,.y2
  238.        jnz      .dx23_make
  239.        mov      ecx,7
  240.     @@:
  241.        push     dword 0
  242.        loop     @b
  243.        jmp      .dx23_done
  244.  
  245.   .dx23_make:
  246.        movsx    ebx,bx
  247.        mov      eax,1 shl 15
  248.        cdq
  249.        idiv     ebx
  250.        mov      ebx,eax
  251.  
  252.  
  253.        mov      ax,.x3
  254.        sub      ax,.x2
  255.        cwde
  256.        imul     ebx
  257.        sar      eax,15 - ROUND
  258.        push     eax
  259.  
  260.        sub       esp,6*4
  261.        movd      xmm0,ebx
  262.        pshuflw   xmm0,xmm0,0
  263.        movlhps   xmm0,xmm0
  264.        movq      xmm1,.col2r
  265.        movq      xmm2,.col3r
  266.        movhps    xmm1,.tex_x2
  267.        movhps    xmm2,.tex_x3
  268.        psubw     xmm2,xmm1
  269.        movdqa    xmm3,xmm2
  270.        pmullw    xmm2,xmm0
  271.        pmulhw    xmm3,xmm0
  272.        movhlps   xmm4,xmm2
  273.        movhlps   xmm5,xmm3
  274.        punpcklwd xmm2,xmm3
  275.        punpcklwd xmm4,xmm5
  276.        psrad     xmm2,15 - ROUND
  277.        psrad     xmm4,15 - ROUND
  278.        pshufd    xmm2,xmm2,11000110b
  279.        movdqu    .dc23b,xmm2
  280.        movq      .tex_dx23,xmm4
  281.  
  282.  
  283.    .dx23_done:
  284. ;++++++++++++++++++third zone++++++++++++++++++++++++
  285.        mov      bx,.y3       ; calc delta13
  286.        sub      bx,.y1
  287.        jnz      .dx13_make
  288.        mov      ecx,7
  289.      @@:
  290.        push     dword 0
  291.        loop     @b
  292.        jmp      .dx13_done
  293.   .dx13_make:
  294.        movsx    ebx,bx
  295.        mov      eax,1 shl 15
  296.        cdq
  297.        idiv     ebx
  298.        mov      ebx,eax
  299.  
  300.  
  301.        mov      ax,.x3
  302.        sub      ax,.x1
  303.        cwde
  304.        imul     ebx
  305.        sar      eax,15 - ROUND
  306.        push     eax
  307.  
  308.        sub       esp,6*4
  309.        movd      xmm0,ebx
  310.        pshuflw   xmm0,xmm0,0
  311.        movlhps   xmm0,xmm0
  312.        movq      xmm1,.col1r
  313.        movq      xmm2,.col3r
  314.        movhps    xmm1,.tex_x1
  315.        movhps    xmm2,.tex_x3
  316.        psubw     xmm2,xmm1
  317.        movdqa    xmm3,xmm2
  318.        pmullw    xmm2,xmm0
  319.        pmulhw    xmm3,xmm0
  320.        movhlps   xmm4,xmm2
  321.        movhlps   xmm5,xmm3
  322.        punpcklwd xmm2,xmm3
  323.        punpcklwd xmm4,xmm5
  324.        psrad     xmm2,15 - ROUND
  325.        psrad     xmm4,15 - ROUND
  326.        pshufd    xmm2,xmm2,11000110b
  327.        movdqu    .dc13b,xmm2
  328.        movq      .tex_dx13,xmm4
  329.    .dx13_done:
  330.  
  331. ; <<<<<<<  ::delta zone end+++++++++++++++++++++ >>>>>>>>
  332.  
  333.        sub      esp,(12*4)
  334.  
  335.        movsx    eax,.x1                    ; eax - cur x1
  336.        shl      eax,ROUND                  ; ebx - cur x2
  337.        mov      ebx,eax
  338.  
  339.  
  340.        movzx    edi,word .tex_x1
  341.        shl      edi,ROUND
  342.        mov      .scan_x1,edi
  343.        mov      .scan_x2,edi
  344.     ;   push     edi
  345.     ;   push     edi
  346.        movzx    edx,word .tex_y1
  347.        shl      edx,ROUND
  348.   ;     push     edx
  349.   ;     push     edx
  350.        mov      .scan_y1,edx
  351.        mov      .scan_y2,edx
  352.  
  353.        movsx    edx,word .z1
  354.        shl      edx,CATMULL_SHIFT
  355.    ;    push     edx
  356.    ;    push     edx
  357.        mov      .zz1,edx
  358.        mov      .zz2,edx
  359.  
  360.        movzx    edi,word .col1r
  361.        shl      edi,ROUND
  362.        mov      .cur1r,edi
  363.        mov      .cur2r,edi
  364.        movzx    esi,word .col1g
  365.        shl      esi,ROUND
  366.        mov      .cur1g,esi
  367.        mov      .cur2g,esi
  368.        movzx    edx,word .col1b
  369.        shl      edx,ROUND
  370.        mov      .cur1b,edx
  371.        mov      .cur2b,edx
  372.  
  373.  
  374.        mov      cx,.y1
  375.        cmp      cx,.y2
  376.        jge      .loop1_end
  377.     .loop_1:
  378.  
  379.        pushad
  380.  
  381.        push     .tex_ptr
  382.        push     .scr_buff
  383.        push     .z_ptr
  384.        push     cx
  385.  
  386.        push     dword .zz2
  387.  
  388.        push     dword .cur2b
  389.        push     dword .cur2g
  390.        push     dword .cur2r
  391.        push     dword .scan_x2
  392.        push     dword .scan_y2
  393.  
  394.        push      .zz1
  395.  
  396.        push     dword .cur1b
  397.        push     dword .cur1g
  398.        push     dword .cur1r
  399.        push     dword .scan_x1
  400.        push     dword .scan_y1
  401.  
  402.        sar      eax,ROUND
  403.        sar      ebx,ROUND
  404.        call     horizontal_tex_grd_line
  405.  
  406.  
  407.        popad
  408.  
  409.  
  410.        movups   xmm0,.cur1b
  411.        movups   xmm1,.dc13b
  412.        movups   xmm2,.cur2b
  413.        movups   xmm3,.dc12b
  414.        movq     mm2,.scan_x1
  415.        movq     mm5,.scan_x2
  416.        paddd    xmm0,xmm1
  417.        paddd    xmm2,xmm3
  418.        paddd    mm2,.tex_dx13
  419.        paddd    mm5,.tex_dx12
  420.        movq     .scan_x1,mm2
  421.        movq     .scan_x2,mm5
  422.        movups   .cur1b,xmm0
  423.        movups   .cur2b,xmm2
  424.  
  425.  
  426.        add      eax,.dx13
  427.        add      ebx,.dx12
  428.        inc      cx
  429.        cmp      cx,.y2
  430.        jl      .loop_1
  431.  .loop1_end:
  432.        movzx    ecx,.y2
  433.        cmp      cx,.y3
  434.        jge      .loop2_end
  435.  
  436.        movsx    ebx,.x2                    ; eax - cur x1
  437.        shl      ebx,ROUND                  ; ebx - cur x2
  438.  
  439.        movsx    edx,word .z2
  440.        shl      edx,CATMULL_SHIFT
  441. ;       mov      .zz1,edx
  442.        mov      .zz2,edx
  443.  
  444.        movzx    edi,word .col2r
  445.        shl      edi,ROUND
  446.    ;    mov      .cur1r,edi
  447.        mov      .cur2r,edi
  448.        movzx    esi,word .col2g
  449.        shl      esi,ROUND
  450.    ;    mov      .cur1g,esi
  451.        mov      .cur2g,esi
  452.        movzx    edx,word .col2b
  453.        shl      edx,ROUND
  454.    ;    mov      .cur1b,edx
  455.        mov      .cur2b,edx
  456.  
  457.        movzx    edi,word .tex_x2
  458.        shl      edi,ROUND
  459.  ;      mov      .scan_x1,edi
  460.        mov      .scan_x2,edi
  461.        movzx    edx,word .tex_y2
  462.        shl      edx,ROUND
  463.  ;      mov      .scan_y1,edx
  464.        mov      .scan_y2,edx
  465.  
  466.   .loop_2:
  467.        pushad
  468.  
  469.        push     .tex_ptr
  470.        push     .scr_buff
  471.        push     .z_ptr
  472.        push     cx
  473.  
  474.        push     dword .zz2
  475.  
  476.        push     dword .cur2b
  477.        push     dword .cur2g
  478.        push     dword .cur2r
  479.        push     dword .scan_x2
  480.        push     dword .scan_y2
  481.  
  482.        push      .zz1
  483.  
  484.        push     dword .cur1b
  485.        push     dword .cur1g
  486.        push     dword .cur1r
  487.        push     dword .scan_x1
  488.        push     dword .scan_y1
  489.  
  490.        sar      eax,ROUND
  491.        sar      ebx,ROUND
  492.        call     horizontal_tex_grd_line
  493.  
  494.        popad
  495.  
  496.  
  497.        movups   xmm0,.cur1b
  498.        movups   xmm1,.dc13b
  499.        movups   xmm2,.cur2b
  500.        movups   xmm3,.dc23b
  501.        movq     mm2,.scan_x1
  502.        movq     mm5,.scan_x2
  503.        paddd    xmm0,xmm1
  504.        paddd    xmm2,xmm3
  505.        paddd    mm2,.tex_dx13
  506.        paddd    mm5,.tex_dx23
  507.        movq     .scan_x1,mm2
  508.        movq     .scan_x2,mm5
  509.        movups   .cur1b,xmm0
  510.        movups   .cur2b,xmm2
  511.  
  512.        add      eax,.dx13
  513.        add      ebx,.dx23
  514.        inc      cx
  515.        cmp      cx,.y3
  516.        jl       .loop_2
  517.  
  518. .loop2_end:
  519.        mov      esp,ebp
  520. ret 36
  521. horizontal_tex_grd_line:
  522. ;in:
  523. ; eax : x1, ebx : x2
  524.  
  525. .tex_ptr  equ [ebp+62]
  526. .screen   equ [ebp+58]
  527. .z_buffer equ [ebp+54]
  528. .y        equ [ebp+52]
  529.  
  530. .z2     equ [ebp+48]
  531. .b2     equ [ebp+44]
  532. .g2     equ [ebp+40]
  533. .r2     equ [ebp+36]
  534. .tex_x2 equ [ebp+32]
  535. .tex_y2 equ [ebp+28]
  536.  
  537.  
  538. .z1     equ [ebp+24]
  539. .b1     equ [ebp+20]
  540. .g1     equ [ebp+16]
  541. .r1     equ [ebp+12]
  542. .tex_x1 equ [ebp+8]
  543. .tex_y1 equ [ebp+4]
  544.  
  545.  
  546. .x1 equ  word[ebp-2]
  547. .x2 equ  word[ebp-4]
  548. .dz equ dword[ebp-8]
  549. .db equ [ebp-12]
  550. .dg equ dword[ebp-16]
  551. .dr equ [ebp-20]
  552. .dtex_x equ dword[ebp-24]
  553. .dtex_y equ [ebp-28]
  554.  
  555.         mov     ebp,esp
  556.  
  557.  
  558.         mov     cx,word .y
  559.         or      cx,cx
  560.         jl      .quit_l
  561.  
  562.         cmp     cx,word[size_y_var]  ;SIZE_Y
  563.         jge     .quit_l
  564.  
  565.         cmp     ax,bx
  566.         je      .quit_l
  567.         jl      @f
  568.  
  569.         xchg    eax,ebx
  570.  
  571.  
  572.        movdqu  xmm0,.tex_y1
  573.        movdqu  xmm1,.tex_y2
  574.        movdqu  .tex_y1,xmm1
  575.        movdqu  .tex_y2,xmm0
  576.        movq    xmm4,.b1    ; x, z
  577.        movq    xmm5,.b2
  578.        movq    .b1,xmm5
  579.        movq    .b2,xmm4
  580.  
  581.  
  582.     @@:
  583.         or      bx,bx
  584.         jle     .quit_l
  585.         cmp     ax,word[size_x_var]  ;SIZE_X
  586.         jge     .quit_l
  587.  
  588.         push    ax
  589.         push    bx
  590. if 1
  591.         mov     bx,.x2
  592.         sub     bx,.x1
  593.  
  594.         movsx    ebx,bx
  595.         mov      eax,1 shl 15
  596.         cdq
  597.         idiv     ebx
  598.         mov      ebx,eax
  599.  
  600.  
  601.         mov     eax,.z2            ; delta zone************
  602.         sub     eax,.z1
  603.         imul    ebx
  604.         sar     eax,15
  605.         push    eax  ; .dz
  606.  
  607.         mov     eax,.b2
  608.         sub     eax,.b1
  609.         imul    ebx
  610.         sar     eax,15
  611.         push    eax
  612.  
  613.         mov     eax,.g2
  614.         sub     eax,.g1
  615.         imul    ebx
  616.         sar     eax,15
  617.         push    eax  ; .dz
  618.  
  619.         mov     eax,.r2
  620.         sub     eax,.r1
  621.         imul    ebx
  622.         sar     eax,15
  623.         push    eax
  624.  
  625.         mov     eax,.tex_x2
  626.         sub     eax,.tex_x1
  627.         imul    ebx
  628.         sar     eax,15
  629.         push    eax
  630.  
  631.         mov     eax,.tex_y2
  632.         sub     eax,.tex_y1
  633.         imul    ebx
  634.         sar     eax,15
  635.         push    eax
  636.  
  637.  
  638. end if
  639. if 0
  640.        sub       esp,6*4
  641.        movd      xmm0,ebx
  642.        pshuflw   xmm0,xmm0,0
  643.        movlhps   xmm0,xmm0
  644.        movdqu    xmm1,.tex_y1
  645.        movdqu    xmm2,.tex_y2
  646.        movq      xmm3,.b1
  647.        movq      xmm4,.b2
  648.        psubd     xmm4,xmm3
  649.        psubd     xmm2,xmm1
  650.        packssdw  xmm2,xmm4
  651.   ;     packlssdw  xmm2,xmm2
  652.    ;    movlhps   xmm2,xmm4
  653.  
  654.  
  655.    ;    psubw     xmm2,xmm1
  656.        movdqa    xmm3,xmm2
  657.        pmullw    xmm2,xmm0
  658.        pmulhw    xmm3,xmm0
  659.        movhlps   xmm4,xmm2
  660.        movhlps   xmm5,xmm3
  661.        punpcklwd xmm2,xmm3
  662.        punpcklwd xmm4,xmm5
  663.        psrad     xmm2,15 - ROUND
  664.        psrad     xmm4,15 - ROUND
  665.    ;    pshufd    xmm2,xmm2,11000110b
  666.        movdqu    .dtex_y,xmm2
  667.        movq      .db,xmm4
  668.  
  669.  
  670. end if
  671.  
  672.         cmp     .x1,0
  673.         jg      @f
  674.  
  675.         mov     eax,.dz     ; clipping
  676.         movsx   ebx,.x1
  677.         neg     ebx
  678.         imul    ebx
  679.         add     .z1,eax
  680.         mov     .x1,0
  681.  
  682.         mov    eax,.dr
  683.         imul   ebx
  684.         add    .r1,eax
  685. ;if  Ext=NON
  686.         mov    eax,.dg
  687.         imul   ebx
  688.         add    .g1,eax
  689.  
  690.         mov    eax,.db
  691.         imul   ebx
  692.         add    .b1,eax
  693.  
  694.         mov    eax,.dtex_x
  695.         imul   ebx
  696.         add    .tex_x1,eax
  697.  
  698.         mov    eax,.dtex_y
  699.         imul   ebx
  700.         add    .tex_y1,eax
  701.    @@:
  702.         movsx     edx,word[size_x_var]  ;SIZE_X
  703.         cmp       .x2,dx
  704.         jl        @f
  705.         mov       .x2,dx
  706.     @@:
  707. ; calc line addres begin in screen and Z buffer
  708.         movsx     eax,word .y
  709.         mul       edx
  710.         movsx     edx,.x1
  711.         add       eax,edx
  712.  
  713.         mov       esi,eax
  714.         shl       esi,2
  715.         add       esi,.z_buffer
  716.  
  717.         lea       eax,[eax*3]
  718.         mov       edi,.screen
  719.         add       edi,eax
  720.  
  721.         mov       cx,.x2
  722.         sub       cx,.x1
  723.         movzx     ecx,cx
  724.  
  725. ; init current variables
  726.         movdqu    xmm0,.r1
  727.         movdqu    xmm1,.dr
  728.         pxor      xmm2,xmm2
  729.         movq      xmm4,.dtex_y
  730.         movq      xmm5,.tex_y1
  731.  
  732.         mov       ebx,.z1
  733.       .ddraw:
  734.         cmp       ebx,dword[esi]
  735.         jge       @f
  736.         movdqa    xmm6,xmm5
  737.         psrld     xmm6,ROUND
  738.         movd      eax,xmm6
  739.         psrldq    xmm6,4
  740.         movd      edx,xmm6
  741.         shl       eax,TEX_SHIFT
  742.  
  743.    ; calc texture pixel mem addres
  744.  
  745.        add       eax,edx
  746.        and       eax,TEXTURE_SIZE   ; cutting
  747.        lea       eax,[3*eax]
  748.        add       eax,.tex_ptr
  749.        mov       dword[esi],ebx
  750.  
  751.        movd      xmm7,[eax]
  752.        punpcklbw xmm7,xmm2
  753.        movdqa    xmm3,xmm0   ; calc col
  754.        psrld     xmm3,ROUND  ;
  755.        packssdw  xmm3,xmm3
  756.        pmullw    xmm7,xmm3
  757.        psrlw     xmm7,8
  758.        packuswb  xmm7,xmm7
  759.        movd      [edi],xmm7
  760.  
  761.        mov        dword[esi],ebx
  762.      @@:
  763.        add        edi,3
  764.        add        esi,4
  765.        add        ebx,.dz
  766.        paddd      xmm5,xmm4
  767.        paddd      xmm0,xmm1
  768.  
  769.        loop     .ddraw
  770.  
  771.   .quit_l:
  772.  
  773.         mov     esp,ebp
  774. ret 42+20  ; horizontal line
  775. ;the_zero:
  776. ;size_y_var:
  777. ;size_x_var:
  778.  
  779.