Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ; We draw a triangle with various interpolations
  3. ;
  4.         t dd ? ;ZBufferPoint*
  5.         pr1 dd ? ;ZBufferPoint*
  6.         pr2 dd ? ;ZBufferPoint*
  7.         l1 dd ? ;ZBufferPoint*
  8.         l2 dd ? ;ZBufferPoint*
  9.         fdx1 dd ? ;float
  10.         fdx2 dd ? ;float
  11.         fdy1 dd ? ;float
  12.         fdy2 dd ? ;float
  13.         fz dd ? ;float
  14.         d1 dd ? ;float
  15.         d2 dd ? ;float
  16.         pz1 dd ? ;unsigned short*
  17.         pp1 dd ? ;PIXEL*
  18.         part dd ?
  19.         update_left dd ?
  20.         update_right dd ?
  21.  
  22.         nb_lines dd ? ;число горизонтальных линий в половине треугольника
  23.         dx1 dd ?
  24.         dy1 dd ?
  25.         ;dx2 dd ?
  26.         dy2 dd ?
  27.  
  28.         error dd ? ;int
  29.         derror dd ? ;int
  30.         x1 dd ? ;int
  31.         dxdy_min dd ? ;int
  32.         dxdy_max dd ? ;int
  33.         ; warning: x2 is multiplied by 2^16
  34.         x2 dd ? ;int
  35.         dx2dy2 dd ? ;int
  36.  
  37. if INTERP_Z eq 1
  38.         z1 dd ? ;int
  39.         dzdx dd ? ;int
  40.         dzdy dd ? ;int
  41.         dzdl_min dd ? ;int
  42.         dzdl_max dd ? ;int
  43. end if
  44. if INTERP_RGB eq 1
  45.         r1 dd ? ;int
  46.         drdx dd ?
  47.         drdy dd ?
  48.         drdl_min dd ?
  49.         drdl_max dd ?
  50.         g1 dd ?
  51.         dgdx dd ?
  52.         dgdy dd ?
  53.         dgdl_min dd ?
  54.         dgdl_max dd ?
  55.         b1 dd ?
  56.         dbdx dd ?
  57.         dbdy dd ?
  58.         dbdl_min dd ?
  59.         dbdl_max dd ?
  60. end if
  61. if INTERP_ST eq 1
  62.         s1 dd ? ;int
  63.         dsdx dd ? ;int
  64.         dsdy dd ? ;int
  65.         dsdl_min dd ? ;int
  66.         dsdl_max dd ? ;int
  67.         t1 dd ? ;int
  68.         dtdx dd ? ;int
  69.         dtdy dd ? ;int
  70.         dtdl_min dd ? ;int
  71.         dtdl_max dd ? ;int
  72. end if
  73. if INTERP_STZ eq 1
  74.         sz1 dd ? ;float
  75.         dszdx dd ? ;float
  76.         dszdy dd ? ;float
  77.         dszdl_min dd ? ;float
  78.         dszdl_max dd ? ;float
  79.         tz1 dd ? ;float
  80.         dtzdx dd ? ;float
  81.         dtzdy dd ? ;float
  82.         dtzdl_min dd ? ;float
  83.         dtzdl_max dd ? ;float
  84. end if
  85.  
  86.  
  87. if DRAW_LINE_M eq 1
  88.         DRAW_LINE 0 ;переменные делаются в макросе
  89. else
  90.         n dd ? ;int - длинна горизонтальной линии в пикселях
  91. if INTERP_Z eq 1
  92.         pz dd ? ;unsigned short *
  93.         z dd ? ;uint
  94.         zz dd ? ;uint
  95. end if
  96. if INTERP_RGB eq 1
  97.         or1 dd ? ;uint
  98.         og1 dd ? ;uint
  99.         ob1 dd ? ;uint
  100. end if
  101. if INTERP_ST eq 1
  102.         s dd ? ;uint
  103.         t dd ? ;uint
  104. end if
  105. if INTERP_STZ eq 1
  106.         s_z dd ? ;float
  107.         t_z dd ? ;float
  108. end if
  109. end if
  110.  
  111. endl
  112. pushad
  113.  
  114. if DEBUG ;(1)
  115. stdcall dbg_print,f_fill_tr,m_1
  116. end if
  117.  
  118.         ; we sort the vertex with increasing y
  119.         mov ebx,[p0]
  120.         mov ecx,[p1]
  121.         mov edx,[p2]
  122.         mov eax,[edx+offs_zbup_y]
  123.         cmp [ecx+offs_zbup_y],eax ;(2-1)
  124.         jle @f
  125.                 xchg edx,ecx
  126.         @@:
  127.         mov eax,[ecx+offs_zbup_y]
  128.         cmp [ebx+offs_zbup_y],eax ;(1-0)
  129.         jle @f
  130.                 xchg ecx,ebx
  131.         @@:
  132.         mov eax,[edx+offs_zbup_y]
  133.         cmp [ecx+offs_zbup_y],eax ;(2-1)
  134.         jle @f
  135.                 xchg edx,ecx
  136.         @@:
  137.         mov [p0],ebx
  138.         mov [p1],ecx
  139.         mov [p2],edx
  140.  
  141.         ; we compute dXdx and dXdy for all interpolated values
  142.         mov eax,[ecx+offs_zbup_x]
  143.         sub eax,[ebx+offs_zbup_x]
  144.         mov [fdx1],eax ;p1.x - p0.x
  145.         mov eax,[ecx+offs_zbup_y]
  146.         sub eax,[ebx+offs_zbup_y]
  147.         mov [fdy1],eax ;p1.y - p0.y
  148.  
  149.         mov eax,[edx+offs_zbup_x]
  150.         sub eax,[ebx+offs_zbup_x]
  151.         mov [fdx2],eax ;p2.x - p0.x
  152.         mov eax,[edx+offs_zbup_y]
  153.         sub eax,[ebx+offs_zbup_y]
  154.         mov [fdy2],eax ;p2.y - p0.y
  155.  
  156.         fild dword[fdx1]
  157.         fst dword[fdx1]
  158.         fild dword[fdy2]
  159.         fst dword[fdy2]
  160.         fmulp
  161.         fild dword[fdx2]
  162.         fst dword[fdx2]
  163.         fild dword[fdy1]
  164.         fst dword[fdy1]
  165.         fmulp
  166.         fsubp ;st0 = st1-st0
  167.         fst dword[fz] ;fz = fdx1 * fdy2 - fdx2 * fdy1
  168.         fldz
  169.         fcompp ;if (fz == 0) return
  170.         fstsw ax
  171.         sahf
  172.         je .end_f
  173.  
  174.         fld1
  175.         fdiv dword[fz] ;fz = 1.0 / fz
  176.         fst dword[fz]  ;st0 = fz
  177.  
  178.         fld dword[fdx1]
  179.         fmul st0,st1
  180.         fstp dword[fdx1] ;fdx1 *= fz
  181.         fld dword[fdy1]
  182.         fmul st0,st1
  183.         fstp dword[fdy1] ;fdy1 *= fz
  184.         fld dword[fdx2]
  185.         fmul st0,st1
  186.         fstp dword[fdx2] ;fdx2 *= fz
  187.         fld dword[fdy2]
  188.         fmul st0,st1
  189.         fstp dword[fdy2] ;fdy2 *= fz
  190.         ffree st0
  191.         fincstp
  192.  
  193. if INTERP_Z eq 1
  194.         mov eax,[ecx+offs_zbup_z]
  195.         sub eax,[ebx+offs_zbup_z]
  196.         mov [d1],eax
  197.         mov eax,[edx+offs_zbup_z]
  198.         sub eax,[ebx+offs_zbup_z]
  199.         mov [d2],eax
  200.         fild dword[d1] ;d1 = p1.z - p0.z
  201.         fild dword[d2] ;d2 = p2.z - p0.z
  202.  
  203.         fld dword[fdy2]
  204.         fmul st0,st2
  205.         fld dword[fdy1]
  206.         fmul st0,st2
  207.         fsubp
  208.         fistp dword[dzdx] ;dzdx = (int) (fdy2*d1 - fdy1*d2)
  209.         fld dword[fdx1]
  210.         fmul st0,st1
  211.         fld dword[fdx2]
  212.         fmul st0,st3
  213.         fsubp
  214.         fistp dword[dzdy] ;dzdy = (int) (fdx1*d2 - fdx2*d1)
  215.         ffree st0 ;free d2
  216.         fincstp
  217.         ffree st0 ;free d1
  218.         fincstp
  219. end if
  220.  
  221. if INTERP_RGB eq 1
  222.         mov eax,[ecx+offs_zbup_r]
  223.         sub eax,[ebx+offs_zbup_r]
  224.         mov [d1],eax
  225.         mov eax,[edx+offs_zbup_r]
  226.         sub eax,[ebx+offs_zbup_r]
  227.         mov [d2],eax
  228.         fild dword[d1] ;d1 = p1.r - p0.r
  229.         fild dword[d2] ;d2 = p2.r - p0.r
  230.  
  231.         fld dword[fdy2]
  232.         fmul st0,st2
  233.         fld dword[fdy1]
  234.         fmul st0,st2
  235.         fsubp
  236.         fistp dword[drdx] ;drdx = (int) (fdy2*d1 - fdy1*d2)
  237.         fld dword[fdx1]
  238.         fmul st0,st1
  239.         fld dword[fdx2]
  240.         fmul st0,st3
  241.         fsubp
  242.         fistp dword[drdy] ;drdy = (int) (fdx1*d2 - fdx2*d1)
  243.         ffree st0 ;free d2
  244.         fincstp
  245.         ffree st0 ;free d1
  246.         fincstp
  247.  
  248.         mov eax,[ecx+offs_zbup_g]
  249.         sub eax,[ebx+offs_zbup_g]
  250.         mov [d1],eax
  251.         mov eax,[edx+offs_zbup_g]
  252.         sub eax,[ebx+offs_zbup_g]
  253.         mov [d2],eax
  254.         fild dword[d1] ;d1 = p1.g - p0.g
  255.         fild dword[d2] ;d2 = p2.g - p0.g
  256.  
  257.         fld dword[fdy2]
  258.         fmul st0,st2
  259.         fld dword[fdy1]
  260.         fmul st0,st2
  261.         fsubp
  262.         fistp dword[dgdx] ;dgdx = (int) (fdy2*d1 - fdy1*d2)
  263.         fld dword[fdx1]
  264.         fmul st0,st1
  265.         fld dword[fdx2]
  266.         fmul st0,st3
  267.         fsubp
  268.         fistp dword[dgdy] ;dgdy = (int) (fdx1*d2 - fdx2*d1)
  269.         ffree st0 ;free d2
  270.         fincstp
  271.         ffree st0 ;free d1
  272.         fincstp
  273.  
  274.         mov eax,[ecx+offs_zbup_b]
  275.         sub eax,[ebx+offs_zbup_b]
  276.         mov [d1],eax
  277.         mov eax,[edx+offs_zbup_b]
  278.         sub eax,[ebx+offs_zbup_b]
  279.         mov [d2],eax
  280.         fild dword[d1] ;d1 = p1.b - p0.b
  281.         fild dword[d2] ;d2 = p2.b - p0.b
  282.  
  283.         fld dword[fdy2]
  284.         fmul st0,st2
  285.         fld dword[fdy1]
  286.         fmul st0,st2
  287.         fsubp
  288.         fistp dword[dbdx] ;dbdx = (int) (fdy2*d1 - fdy1*d2)
  289.         fld dword[fdx1]
  290.         fmul st0,st1
  291.         fld dword[fdx2]
  292.         fmul st0,st3
  293.         fsubp
  294.         fistp dword[dbdy] ;dbdy = (int) (fdx1*d2 - fdx2*d1)
  295.         ffree st0 ;free d2
  296.         fincstp
  297.         ffree st0 ;free d1
  298.         fincstp
  299. end if
  300.  
  301. if INTERP_ST eq 1
  302.         mov eax,[ecx+offs_zbup_s]
  303.         sub eax,[ebx+offs_zbup_s]
  304.         mov [d1],eax
  305.         mov eax,[edx+offs_zbup_s]
  306.         sub eax,[ebx+offs_zbup_s]
  307.         mov [d2],eax
  308.         fild dword[d1] ;d1 = p1.s - p0.s
  309.         fild dword[d2] ;d2 = p2.s - p0.s
  310.  
  311.         fld dword[fdy2]
  312.         fmul st0,st2
  313.         fld dword[fdy1]
  314.         fmul st0,st2
  315.         fsubp
  316.         fistp dword[dsdx] ;dsdx = (int) (fdy2*d1 - fdy1*d2)
  317.         fld dword[fdx2]
  318.         fmul st0,st2
  319.         fld dword[fdx1]
  320.         fmul st0,st2
  321.         fsub st0,st1
  322.         fistp dword[dsdy] ;dsdy = (int) (fdx1*d2 - fdx2*d1)
  323.         ffree st0
  324.         fincstp
  325.         ffree st0 ;free d2
  326.         fincstp
  327.         ffree st0 ;free d1
  328.         fincstp
  329.  
  330.         mov eax,[ecx+offs_zbup_t]
  331.         sub eax,[ebx+offs_zbup_t]
  332.         mov [d1],eax
  333.         mov eax,[edx+offs_zbup_t]
  334.         sub eax,[ebx+offs_zbup_t]
  335.         mov [d2],eax
  336.         fild dword[d1] ;d1 = p1.t - p0.t
  337.         fild dword[d2] ;d2 = p2.t - p0.t
  338.  
  339.         fld dword[fdy1]
  340.         fmul st0,st1
  341.         fld dword[fdy2]
  342.         fmul st0,st3
  343.         fsub st0,st1
  344.         fistp dword[dtdx] ;dtdx = (int) (fdy2*d1 - fdy1*d2)
  345.         ffree st0
  346.         fincstp
  347.         fld dword[fdx2]
  348.         fmul st0,st2
  349.         fld dword[fdx1]
  350.         fmul st0,st2
  351.         fsub st0,st1
  352.         fistp dword[dtdy] ;dtdy = (int) (fdx1*d2 - fdx2*d1)
  353.         ffree st0
  354.         fincstp
  355.         ffree st0 ;free d2
  356.         fincstp
  357.         ffree st0 ;free d1
  358.         fincstp
  359. end if
  360.  
  361. if INTERP_STZ eq 1
  362.         fild dword[ebx+offs_zbup_z]
  363.         fild dword[ebx+offs_zbup_s]
  364.         fmul st0,st1
  365.         fstp dword[ebx+offs_zbup_sz] ;p0.sz = (float) p0.s * p0.z
  366.         fild dword[ebx+offs_zbup_t]
  367.         fmulp
  368.         fstp dword[ebx+offs_zbup_tz] ;p0.tz = (float) p0.t * p0.z
  369.  
  370.         fild dword[ecx+offs_zbup_z]
  371.         fild dword[ecx+offs_zbup_s]
  372.         fmul st0,st1
  373.         fstp dword[ecx+offs_zbup_sz] ;p1.sz = (float) p1.s * p1.z
  374.         fild dword[ecx+offs_zbup_t]
  375.         fmulp
  376.         fstp dword[ecx+offs_zbup_tz] ;p1.tz = (float) p1.t * p1.z
  377.  
  378.         fild dword[edx+offs_zbup_z]
  379.         fild dword[edx+offs_zbup_s]
  380.         fmul st0,st1
  381.         fstp dword[edx+offs_zbup_sz] ;p2.sz = (float) p2.s * p2.z
  382.         fild dword[edx+offs_zbup_t]
  383.         fmulp
  384.         fstp dword[edx+offs_zbup_tz] ;p2.tz = (float) p2.t * p2.z
  385.  
  386.         fld dword[ecx+offs_zbup_sz]
  387.         fsub dword[ebx+offs_zbup_sz] ;d1 = p1.sz - p0.sz
  388.         fld dword[edx+offs_zbup_sz]
  389.         fsub dword[ebx+offs_zbup_sz] ;d2 = p2.sz - p0.sz
  390.  
  391.         fld dword[fdy2]
  392.         fmul st0,st2
  393.         fld dword[fdy1]
  394.         fmul st0,st2
  395.         fsubp
  396.         fstp dword[dszdx] ;dszdx = (fdy2*d1 - fdy1*d2)
  397.         fld dword[fdx2]
  398.         fmul st0,st2
  399.         fld dword[fdx1]
  400.         fmul st0,st2
  401.         fsub st0,st1
  402.         fstp dword[dszdy] ;dszdy = (fdx1*d2 - fdx2*d1)
  403.         ffree st0
  404.         fincstp
  405.         ffree st0 ;free d2
  406.         fincstp
  407.         ffree st0 ;free d1
  408.         fincstp
  409.  
  410.         fld dword[ecx+offs_zbup_tz]
  411.         fsub dword[ebx+offs_zbup_tz] ;d1 = p1.tz - p0.tz
  412.         fld dword[edx+offs_zbup_tz]
  413.         fsub dword[ebx+offs_zbup_tz] ;d2 = p2.tz - p0.tz
  414.  
  415.         fld dword[fdy1]
  416.         fmul st0,st1
  417.         fld dword[fdy2]
  418.         fmul st0,st3
  419.         fsub st0,st1
  420.         fstp dword[dtzdx] ;dtzdx = (fdy2*d1 - fdy1*d2)
  421.         ffree st0
  422.         fincstp
  423.         fld dword[fdx2]
  424.         fmul st0,st2
  425.         fld dword[fdx1]
  426.         fmul st0,st2
  427.         fsub st0,st1
  428.         fstp dword[dtzdy] ;dtzdy = (fdx1*d2 - fdx2*d1)
  429.         ffree st0
  430.         fincstp
  431.         ffree st0 ;free d2
  432.         fincstp
  433.         ffree st0 ;free d1
  434.         fincstp
  435. end if
  436.  
  437.         ; screen coordinates
  438.         mov eax,[zb]
  439.         mov edx,[eax+offs_zbuf_linesize]
  440.         imul edx,[ebx+offs_zbup_y]
  441.         add edx,[eax+offs_zbuf_pbuf]
  442.         mov [pp1],edx ;pp1 = zb.pbuf + zb.linesize * p0.y
  443.         mov edx,[eax+offs_zbuf_xsize]
  444.         imul edx,[ebx+offs_zbup_y]
  445.         shl edx,1
  446.         add edx,[eax+offs_zbuf_zbuf]
  447.         mov [pz1],edx ;pz1 = zb.zbuf + zb.xsize * p0.y
  448.  
  449.         DRAW_INIT
  450.  
  451.         mov dword[part],0
  452.         .cycle_0:
  453.                 mov ebx,[p0]
  454.                 mov ecx,[p1]
  455.                 mov edx,[p2]
  456.                 cmp dword[part],0 ;if (part == 0)
  457.                 jne .els_0
  458.                         mov dword[update_left],1
  459.                         mov dword[update_right],1
  460.                         mov [l1],ebx
  461.                         mov [pr1],ebx
  462.                         fldz
  463.                         fld dword[fz]
  464.                         fcompp ;if (fz > 0)
  465.                         fstsw ax
  466.                         sahf
  467.                         jbe .els_1
  468.                                 mov [l2],edx
  469.                                 mov [pr2],ecx
  470.                                 jmp .end_1
  471.                         .els_1:
  472.                                 mov [l2],ecx
  473.                                 mov [pr2],edx
  474.                         .end_1:
  475.                         mov eax,[ecx+offs_zbup_y]
  476.                         sub eax,[ebx+offs_zbup_y]
  477.                         mov [nb_lines],eax ;nb_lines = p1.y - p0.y
  478.                         jmp .end_0
  479.                 .els_0:
  480.                         ; second part
  481.                         fldz
  482.                         fld dword[fz]
  483.                         fcompp ;if (fz > 0)
  484.                         fstsw ax
  485.                         sahf
  486.                         jbe .els_2
  487.                                 mov dword[update_left],0
  488.                                 mov dword[update_right],1
  489.                                 mov [pr1],ecx
  490.                                 mov [pr2],edx
  491.                                 jmp .end_2
  492.                         .els_2:
  493.                                 mov dword[update_left],1
  494.                                 mov dword[update_right],0
  495.                                 mov [l1],ecx
  496.                                 mov [l2],edx
  497.                         .end_2:
  498.                         mov eax,[edx+offs_zbup_y]
  499.                         sub eax,[ecx+offs_zbup_y]
  500.                         inc eax
  501.                         mov [nb_lines],eax ;nb_lines = p2.y - p1.y + 1
  502.                 .end_0:
  503.  
  504.         ; compute the values for the left edge
  505.         cmp dword[update_left],0 ;if (update_left)
  506.         je .end_upd_l
  507.                 mov ebx,[l1]
  508.                 mov ecx,[l2]
  509.                 mov edx,[ecx+offs_zbup_y]
  510.                 sub edx,[ebx+offs_zbup_y]
  511.                 mov [dy1],edx ;dy1 = l2.y - l1.y
  512.                 mov eax,[ecx+offs_zbup_x]
  513.                 sub eax,[ebx+offs_zbup_x]
  514.                 mov [dx1],eax ;dx1 = l2.x - l1.x
  515.                 cmp edx,0 ;if (dy1 > 0)
  516.                 jle .els_3
  517.                         xor edx,edx
  518.                         cmp eax,0
  519.                         jl .otr_dx1
  520.                         shl eax,16
  521.                         div dword[dy1] ;eax = (dx1 << 16) / dy1
  522.                         jmp .end_3
  523.                         .otr_dx1:
  524.                         neg eax
  525.                         inc eax
  526.                         shl eax,16
  527.                         div dword[dy1] ;eax = (-dx1 << 16) / dy1
  528.                         neg eax
  529.                         inc eax
  530.                         jmp .end_3
  531.                 .els_3:
  532.                         xor eax,eax
  533.                 .end_3:
  534.                 mov edx,[ebx+offs_zbup_x]
  535.                 mov [x1],edx ;x1 = l1.x
  536.                 mov dword[error],0 ;error = 0
  537.                 mov dword[derror],eax
  538.                 and dword[derror],0xffff ;derror = eax & 0x0000ffff
  539.                 shr eax,16
  540.                 bt eax,15
  541.                 jnc @f
  542.                         or eax,0xffff0000
  543.                 @@:
  544.                 mov [dxdy_min],eax ;dxdy_min = eax >> 16
  545.                 inc eax
  546.                 mov [dxdy_max],eax
  547.  
  548. if INTERP_Z eq 1
  549.         mov eax,[l1]
  550.         mov eax,[eax+offs_zbup_z]
  551.         mov [z1],eax ;z1 = l1.z
  552.         mov eax,[dzdx]
  553.         imul eax,[dxdy_min]
  554.         add eax,[dzdy]
  555.         mov [dzdl_min],eax ;dzdl_min = (dzdy +dzdx*dxdy_min)
  556.         add eax,[dzdx]
  557.         mov [dzdl_max],eax ;dzdl_max = dzdl_min +dzdx
  558. end if
  559. if INTERP_RGB eq 1
  560.         mov ebx,[l1]
  561.         mov eax,[ebx+offs_zbup_r]
  562.         mov [r1],eax ;r1 = l1.r
  563.         mov eax,[drdx]
  564.         imul eax,[dxdy_min]
  565.         add eax,[drdy]
  566.         mov [drdl_min],eax ;drdl_min = (drdy +drdx*dxdy_min)
  567.         add eax,[drdx]
  568.         mov [drdl_max],eax ;drdl_max = drdl_min +drdx
  569.  
  570.         mov eax,[ebx+offs_zbup_g]
  571.         mov [g1],eax ;g1 = l1.g
  572.         mov eax,[dgdx]
  573.         imul eax,[dxdy_min]
  574.         add eax,[dgdy]
  575.         mov [dgdl_min],eax ;dgdl_min = (dgdy +dgdx*dxdy_min)
  576.         add eax,[dgdx]
  577.         mov [dgdl_max],eax ;dgdl_max = dgdl_min +dgdx
  578.  
  579.         mov eax,[ebx+offs_zbup_b]
  580.         mov [b1],eax ;b1 = l1.b
  581.         mov eax,[dbdx]
  582.         imul eax,[dxdy_min]
  583.         add eax,[dbdy]
  584.         mov [dbdl_min],eax ;dbdl_min = (dbdy +dbdx*dxdy_min)
  585.         add eax,[dbdx]
  586.         mov [dbdl_max],eax ;dbdl_max = dbdl_min +dbdx
  587. end if
  588. if INTERP_ST eq 1
  589.         mov ebx,[l1]
  590.         mov eax,[ebx+offs_zbup_s]
  591.         mov [s1],eax ;s1 = l1.s
  592.         mov eax,[dsdx]
  593.         imul eax,[dxdy_min]
  594.         add eax,[dsdy]
  595.         mov [dsdl_min],eax ;dsdl_min = (dsdy +dsdx*dxdy_min)
  596.         add eax,[dsdx]
  597.         mov [dsdl_max],eax ;dsdl_max = dsdl_min +dsdx
  598.  
  599.         mov eax,[ebx+offs_zbup_t]
  600.         mov [t1],eax ;t1 = l1.t
  601.         mov eax,[dtdx]
  602.         imul eax,[dxdy_min]
  603.         add eax,[dtdy]
  604.         mov [dtdl_min],eax ;dtdl_min = (dtdy +dtdx*dxdy_min)
  605.         add eax,[dtdx]
  606.         mov [dtdl_max],eax ;dtdl_max = dtdl_min +dtdx
  607. end if
  608. if INTERP_STZ eq 1
  609.         mov ebx,[l1]
  610.         mov eax,[ebx+offs_zbup_sz]
  611.         mov [sz1],eax ;sz1 = l1.sz - преобразований нет, потому без сопроцессора
  612.         fild dword[dxdy_min]
  613.         fmul dword[dszdx]
  614.         fadd dword[dszdy]
  615.         fst dword[dszdl_min] ;dszdl_min = (dszdy +dszdx*dxdy_min)
  616.         fadd dword[dszdx]
  617.         fstp dword[dszdl_max] ;dszdl_max = dszdl_min +dszdx
  618.  
  619.         mov eax,[ebx+offs_zbup_tz]
  620.         mov [tz1],eax ;tz1 = l1.tz - преобразований нет, потому без сопроцессора
  621.         fild dword[dxdy_min]
  622.         fmul dword[dtzdx]
  623.         fadd dword[dtzdy]
  624.         fst dword[dtzdl_min] ;dtzdl_min = (dtzdy +dtzdx*dxdy_min)
  625.         fadd dword[dtzdx]
  626.         fstp dword[dtzdl_max] ;dtzdl_max = dtzdl_min +dtzdx
  627. end if
  628.         .end_upd_l:
  629.  
  630.         ; compute values for the right edge
  631.  
  632.         cmp dword[update_right],0 ;if(update_right)
  633.         je .end_upd_r
  634.                 mov ebx,[pr1]
  635.                 mov ecx,[pr2]
  636.                 mov edx,[ebx+offs_zbup_x]
  637.                 mov eax,[ecx+offs_zbup_x]
  638.                 sub eax,edx
  639.                 ;mov [dx2],eax ;dx2 = pr2.x - pr1.x
  640.                 shl edx,16
  641.                 mov [x2],edx ; x2 = pr1.x << 16
  642.                 mov edx,[ecx+offs_zbup_y]
  643.                 sub edx,[ebx+offs_zbup_y]
  644.                 mov [dy2],edx ;dy2 = pr2.y - pr1.y
  645.                 cmp edx,0 ;if (dy2 > 0)
  646.                 jle .els_4
  647.                         xor edx,edx
  648.                         cmp eax,0
  649.                         jl .otr_dx2
  650.                         shl eax,16
  651.                         div dword[dy2] ;eax = (dx2 << 16) / dy2
  652.                         jmp .end_4
  653.                         .otr_dx2:
  654.                         neg eax
  655.                         inc eax ;dx2 *= -1
  656.                         shl eax,16
  657.                         div dword[dy2] ;eax = (-dx2 << 16) / dy2
  658.                         neg eax
  659.                         inc eax
  660.                         jmp .end_4
  661.                 .els_4:
  662.                         xor eax,eax
  663.                 .end_4:
  664.                 mov [dx2dy2],eax
  665.         .end_upd_r:
  666.  
  667.         ; we draw all the scan line of the part
  668. if DEBUG ;[nb_lines]
  669. push ecx edi
  670.         mov eax,[nb_lines]
  671.         mov ecx,80
  672.         lea edi,[buf_param]
  673.         stdcall convert_int_to_str,ecx
  674.  
  675.         stdcall str_n_cat,edi,txt_nl,2
  676.         stdcall dbg_print,f_fill_tr_nl,buf_param
  677. pop edi ecx
  678. end if
  679.  
  680.         .beg_w_lin:
  681.         cmp dword[nb_lines],0 ;while (nb_lines>0)
  682.         jle .end_w_lin
  683.                 dec dword[nb_lines]
  684. if DRAW_LINE_M eq 1
  685.                 DRAW_LINE 1
  686. else
  687.                 ; generic draw line
  688.                 mov eax,[x2]
  689.                 shr eax,16
  690.                 mov edi,[x1]
  691.                 sub eax,edi
  692.                 mov [n],eax ;n = (x2 >> 16) - x1
  693.                 imul edi,PSZB
  694.                 add edi,[pp1] ;pp = pp1 + x1 * PSZB
  695.  
  696. if DEBUG ;[n], [x1], [x2]>>16
  697. push ecx edi
  698.         mov eax,[n]
  699.         mov ecx,80
  700.         lea edi,[buf_param]
  701.         stdcall convert_int_to_str,ecx
  702.         stdcall str_n_cat,edi,txt_zp_sp,2
  703.         stdcall str_len,edi
  704.         add edi,eax
  705.         sub ecx,eax
  706.  
  707.         mov eax,[x1]
  708.         stdcall convert_int_to_str,ecx
  709.         stdcall str_n_cat,edi,txt_zp_sp,2
  710.         stdcall str_len,edi
  711.         add edi,eax
  712.         sub ecx,eax
  713.  
  714.         mov eax,[x2]
  715.         shr eax,16
  716.         stdcall convert_int_to_str,ecx
  717.  
  718.         stdcall str_n_cat,edi,txt_nl,2
  719.         stdcall dbg_print,f_fill_tr_nll,buf_param
  720. pop edi ecx
  721. end if
  722.  
  723. if INTERP_Z eq 1
  724.                 mov eax,[x1]
  725.                 shl eax,1
  726.                 add eax,[pz1]
  727.                 mov [pz],eax
  728.                 mov eax,[z1]
  729.                 mov [z],eax
  730. end if
  731. if INTERP_RGB eq 1
  732.                 mov eax,[r1]
  733.                 mov [or1],eax
  734.                 mov eax,[g1]
  735.                 mov [og1],eax
  736.                 mov eax,[b1]
  737.                 mov [ob1],eax
  738. end if
  739. if INTERP_ST eq 1
  740.                 mov eax,[s1]
  741.                 mov [s],eax
  742.                 mov eax,[t1]
  743.                 mov [t],eax
  744. end if
  745. if INTERP_STZ eq 1
  746.                 mov eax,[sz1]
  747.                 mov [s_z],eax
  748.                 mov eax,[tz1]
  749.                 mov [t_z],eax
  750. end if
  751.  
  752. align 4
  753.                 .cycle_1: ;while (n>=3)
  754.                 cmp dword[n],3
  755.                 jl .cycle_2
  756.                         PUT_PIXEL 0
  757.                         PUT_PIXEL 1
  758.                         PUT_PIXEL 2
  759.                         PUT_PIXEL 3
  760. if INTERP_Z eq 1
  761.                         add dword[pz],8 ;=4*sizeof(uint)
  762. end if
  763.                         add edi,4*PSZB
  764.                         sub dword[n],4
  765.                 jmp .cycle_1
  766.                 .cycle_2: ;while (n>=0)
  767.                 cmp dword[n],0
  768.                 jl .cycle_2_end
  769.                         PUT_PIXEL 0
  770. if INTERP_Z eq 1
  771.                         add dword[pz],2 ;=sizeof(uint)
  772. end if
  773.                         add edi,PSZB
  774.                         dec dword[n]
  775.                 jmp .cycle_2
  776.                 .cycle_2_end:
  777. end if ;проверка от макроса DRAW_LINE
  778.  
  779.         ; left edge
  780.         mov eax,[derror]
  781.         add [error],eax
  782.         cmp dword[error],0 ;if (error > 0)
  783.         jle .els_er
  784.                 sub dword[error],0x10000
  785.                 mov eax,[dxdy_max]
  786.                 add [x1],eax
  787. if INTERP_Z eq 1
  788.                 mov eax,[dzdl_max]
  789.                 add [z1],eax
  790. end if      
  791. if INTERP_RGB eq 1
  792.                 mov eax,[drdl_max]
  793.                 add [r1],eax
  794.                 mov eax,[dgdl_max]
  795.                 add [g1],eax
  796.                 mov eax,[dbdl_max]
  797.                 add [b1],eax
  798. end if
  799. if INTERP_ST eq 1
  800.                 mov eax,[dsdl_max]
  801.                 add [s1],eax
  802.                 mov eax,[dtdl_max]
  803.                 add [t1],eax
  804. end if
  805. if INTERP_STZ eq 1
  806.                 fld dword[dszdl_max]
  807.                 fadd dword[sz1]
  808.                 fstp dword[sz1]
  809.                 fld dword[dtzdl_max]
  810.                 fadd dword[tz1]
  811.                 fstp dword[tz1]
  812. end if
  813.                 jmp .end_er
  814.         .els_er:
  815.                 mov eax,[dxdy_min]
  816.                 add [x1],eax
  817. if INTERP_Z eq 1
  818.                 mov eax,[dzdl_min]
  819.                 add [z1],eax
  820. end if
  821. if INTERP_RGB eq 1
  822.                 mov eax,[drdl_min]
  823.                 add [r1],eax
  824.                 mov eax,[dgdl_min]
  825.                 add [g1],eax
  826.                 mov eax,[dbdl_min]
  827.                 add [b1],eax
  828. end if
  829. if INTERP_ST eq 1
  830.                 mov eax,[dsdl_min]
  831.                 add [s1],eax
  832.                 mov eax,[dtdl_min]
  833.                 add [t1],eax
  834. end if
  835. if INTERP_STZ eq 1
  836.                 fld dword[dszdl_min]
  837.                 fadd dword[sz1]
  838.                 fstp dword[sz1]
  839.                 fld dword[dtzdl_min]
  840.                 fadd dword[tz1]
  841.                 fstp dword[tz1]
  842. end if
  843.         .end_er:
  844.  
  845.                         ; right edge
  846.                         mov eax,[dx2dy2]
  847.                         add [x2],eax
  848.  
  849.                         ; screen coordinates
  850.                         mov ebx,[zb]
  851.                         mov eax,[ebx+offs_zbuf_linesize]
  852.                         add [pp1],eax
  853.                         mov eax,[ebx+offs_zbuf_xsize]
  854.                         shl eax,1
  855.                         add [pz1],eax
  856.                         jmp .beg_w_lin
  857.                 .end_w_lin:
  858.                 inc dword[part]
  859.                 cmp dword[part],2
  860.                 jl .cycle_0
  861.         .end_f:
  862. popad
  863.         ret
  864. endp
  865.  
  866. restore INTERP_Z
  867. restore INTERP_RGB
  868. restore INTERP_ST
  869. restore INTERP_STZ
  870. restore DRAW_LINE_M
  871.  
  872. purge DRAW_INIT
  873. purge DRAW_LINE
  874. purge PUT_PIXEL
  875.