Subversion Repositories Kolibri OS

Rev

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

  1. ;PUTPIXEL -> RGBPIXEL
  2.  
  3. locals
  4.         n dd ?
  5.         d_x dd ?
  6.         d_y dd ?
  7.         sx dd ? ;ширина буфера в пикселях
  8.         pp_inc_1 dd ?
  9.         pp_inc_2 dd ?
  10.         a dd ? ;register int
  11.         r dd ? ;register unsigned int
  12.         g dd ?
  13.         b dd ?
  14.         rinc dd ? ;register unsigned int
  15.         ginc dd ?
  16.         binc dd ?
  17. if INTERP_Z eq 1
  18.         pz dd ? ;register unsigned short *
  19.         zinc dd ?
  20.         z dd ? ;register int
  21.         zz dd ?
  22. end if
  23. endl
  24. pushad
  25.  
  26.         mov eax,[p1]
  27.         mov ebx,[p2]
  28.         mov ecx,[ebx+ZBufferPoint.y]
  29.         cmp [eax+ZBufferPoint.y], ecx ;if (p1.y > p2.y)
  30.         jg @f
  31.         jl .end_0 ;if (p1.y != p2.y)
  32.         mov ecx,[ebx+ZBufferPoint.x]
  33.         cmp [eax+ZBufferPoint.x], ecx ;if (p1.x > p2.x)
  34.         jle .end_0 ;if (p1.x <= p2.x)
  35.         @@: ;if (p1.y > p2.y || (p1.y == p2.y && p1.x > p2.x))
  36.                 mov [p1],ebx
  37.                 mov [p2],eax
  38.         .end_0:
  39.  
  40.         mov eax,[zb]
  41.         mov edx,[eax+ZBuffer.xsize]
  42.         mov [sx],edx
  43.         mov ecx,[p1]
  44.         mov edi,[eax+ZBuffer.linesize]
  45.         imul edi,[ecx+ZBufferPoint.y]
  46.         mov edx,[ecx+ZBufferPoint.x]
  47.         imul edx,PSZB
  48.         add edi,edx
  49.         add edi,[eax+ZBuffer.pbuf] ;edi = (zb.pbuf + zb.linesize*p1.y + p1.x*PSZB)
  50. if INTERP_Z eq 1
  51.         mov edx,[ecx+ZBufferPoint.y]
  52.         imul edx,[sx]
  53.         add edx,[ecx+ZBufferPoint.x]
  54.         shl edx,1
  55.         add edx,[eax+ZBuffer.zbuf]
  56.         mov [pz],edx ;pz = zb.zbuf + (p1.y*sx + p1.x)
  57.         mov edx,[ecx+ZBufferPoint.z]
  58.         mov [z],edx ;z = p1.z
  59. end if
  60.  
  61.         mov ebx,[p2]
  62.         mov eax,[ebx+ZBufferPoint.x]
  63.         sub eax,[ecx+ZBufferPoint.x]
  64.         mov [d_x],eax ;d_x = p2.x - p1.x
  65.         mov eax,[ebx+ZBufferPoint.y]
  66.         sub eax,[ecx+ZBufferPoint.y]
  67.         mov [d_y],eax ;d_y = p2.y - p1.y
  68.  
  69.         mov eax,[ecx+ZBufferPoint.r]
  70.         shl eax,8
  71.         mov [r],eax ;r = p1.r << 8
  72.         mov eax,[ecx+ZBufferPoint.g]
  73.         shl eax,8
  74.         mov [g],eax ;g = p1.g << 8
  75.         mov eax,[ecx+ZBufferPoint.b]
  76.         shl eax,8
  77.         mov [b],eax ;b = p1.b << 8
  78.  
  79. macro RGBPIXEL
  80. {
  81. if TGL_FEATURE_RENDER_BITS eq 24
  82.         mov eax,[r]
  83.         shr eax,16
  84.         mov byte[edi],al
  85.         mov eax,[g]
  86.         shr eax,16
  87.         mov byte[edi+1],al
  88.         mov eax,[b]
  89.         shr eax,16
  90.         mov byte[edi+2],al
  91. ;;;     else
  92. ;*pp = RGB_TO_PIXEL(r >> 8,g >> 8,b >> 8)
  93. end if
  94. }
  95.  
  96. macro PUTPIXEL
  97. {
  98. if INTERP_Z eq 1
  99. local .end_0
  100.         mov eax,[z]
  101.         shr eax, ZB_POINT_Z_FRAC_BITS
  102.         mov [zz],eax
  103.         mov ebx,[pz]
  104.         cmp ax,word[ebx]
  105.         jl .end_0
  106.                 RGBPIXEL
  107.                 mov eax,dword[zz]
  108.                 mov ebx,[pz]
  109.                 mov word[ebx],ax
  110.         .end_0:
  111. else
  112.         RGBPIXEL
  113. end if
  114. }
  115.  
  116. macro DRAWLINE d_x,d_y,inc_1,inc_2
  117. {
  118. local .mz_0
  119. local .mz_1
  120. local .mz_2
  121. local .mr_0
  122. local .mr_1
  123. local .mr_2
  124. local .mg_0
  125. local .mg_1
  126. local .mg_2
  127. local .mb_0
  128. local .mb_1
  129. local .mb_2
  130.  
  131.         mov eax,d_x
  132.         mov [n],eax
  133.  
  134.         mov ebx,[p1]
  135.         mov ecx,[p2]
  136. if INTERP_Z eq 1
  137.         mov eax,[ecx+ZBufferPoint.z]
  138.         cmp eax,[ebx+ZBufferPoint.z]
  139.         jg .mz_0
  140.         je .mz_1
  141.                 ;if(p2.z<p1.z)
  142.                 sub eax,[ebx+ZBufferPoint.z]
  143.                 neg eax
  144.                 inc eax
  145.                 xor edx,edx
  146.                 div dword[n]
  147.                 neg eax
  148.                 inc eax
  149.                 jmp .mz_2
  150.         .mz_0:
  151.         sub eax,[ebx+ZBufferPoint.z]
  152.         xor edx,edx
  153.         div dword[n]
  154.         jmp .mz_2
  155.         .mz_1:
  156.                 xor eax,eax
  157.         .mz_2:
  158.         mov [zinc],eax ;zinc=(p2.z-p1.z)/n
  159. end if
  160.  
  161.         ;ebx=&p1, ecx=&p2
  162.         mov eax,[ecx+ZBufferPoint.r]
  163.         cmp eax,[ebx+ZBufferPoint.r]
  164.         jg .mr_0
  165.         je .mr_1
  166.                 ;if(p2.r<p1.r)
  167.                 sub eax,[ebx+ZBufferPoint.r]
  168.                 neg eax
  169.                 inc eax
  170.                 shl eax,8
  171.                 xor edx,edx
  172.                 div dword[n]
  173.                 neg eax
  174.                 inc eax
  175.                 jmp .mr_2
  176.         .mr_0:
  177.         sub eax,[ebx+ZBufferPoint.r]
  178.         shl eax,8
  179.         xor edx,edx
  180.         div dword[n]
  181.         jmp .mr_2
  182.         .mr_1:
  183.                 xor eax,eax
  184.         .mr_2:
  185.         mov [rinc],eax ;rinc=((p2.r-p1.r)<<8)/n
  186.  
  187.         mov eax,[ecx+ZBufferPoint.g]
  188.         cmp eax,[ebx+ZBufferPoint.g]
  189.         jg .mg_0
  190.         je .mg_1
  191.                 ;if(p2.g<p1.g)
  192.                 sub eax,[ebx+ZBufferPoint.g]
  193.                 neg eax
  194.                 inc eax
  195.                 shl eax,8
  196.                 xor edx,edx
  197.                 div dword[n]
  198.                 neg eax
  199.                 inc eax
  200.                 jmp .mg_2
  201.         .mg_0:
  202.         sub eax,[ebx+ZBufferPoint.g]
  203.         shl eax,8
  204.         xor edx,edx
  205.         div dword[n]
  206.         jmp .mg_2
  207.         .mg_1:
  208.                 xor eax,eax
  209.         .mg_2:
  210.         mov [ginc],eax ;ginc=((p2.g-p1.g)<<8)/n
  211.  
  212.         mov eax,[ecx+ZBufferPoint.b]
  213.         cmp eax,[ebx+ZBufferPoint.b]
  214.         jg .mb_0
  215.         je .mb_1
  216.                 ;if(p2.b<p1.b)
  217.                 sub eax,[ebx+ZBufferPoint.b]
  218.                 neg eax
  219.                 inc eax
  220.                 shl eax,8
  221.                 xor edx,edx
  222.                 div dword[n]
  223.                 neg eax
  224.                 inc eax
  225.                 jmp .mb_2
  226.         .mb_0:
  227.         sub eax,[ebx+ZBufferPoint.b]
  228.         shl eax,8
  229.         xor edx,edx
  230.         div dword[n]
  231.         jmp .mb_2
  232.         .mb_1:
  233.                 xor eax,eax
  234.         .mb_2:
  235.         mov [binc],eax ;binc=((p2.b-p1.b)<<8)/n
  236.  
  237.         shl dword d_y,1
  238.         mov eax, d_y
  239.         sub eax, d_x
  240.         mov [a],eax ;a=2*d_y-d_x
  241.         shl dword d_x,1
  242.         mov eax, d_y
  243.         sub d_x,eax
  244.         mov eax,inc_1
  245.         imul eax,PSZB
  246.         mov [pp_inc_1],eax ;pp_inc_1 = inc_1*PSZB
  247.         mov eax,inc_2
  248.         imul eax,PSZB
  249.         mov [pp_inc_2],eax ;pp_inc_2 = inc_2*PSZB
  250.  
  251. local .do_cycle
  252. local .els_0
  253. local .end_0
  254.  
  255. align 4
  256. .do_cycle:
  257.  
  258.         PUTPIXEL
  259. if INTERP_Z eq 1
  260.         mov eax,[zinc]
  261.         add [z],eax
  262. end if
  263.         mov eax,[rinc]
  264.         add [r],eax
  265.         mov eax,[ginc]
  266.         add [g],eax
  267.         mov eax,[binc]
  268.         add [b],eax
  269.  
  270.         cmp dword[a],0
  271.         jle .els_0
  272.         add edi,[pp_inc_1]
  273. if INTERP_Z eq 1
  274.         mov eax,inc_1
  275.         shl eax,1
  276.         add [pz],eax
  277. end if
  278.         mov eax,d_x
  279.         sub [a],eax
  280.         jmp .end_0
  281.  
  282. .els_0:
  283.         add edi,[pp_inc_2]
  284. if INTERP_Z eq 1
  285.         mov eax,inc_2
  286.         shl eax,1
  287.         add [pz],eax
  288. end if
  289.         mov eax,d_y
  290.         add [a],eax
  291.  
  292. .end_0:
  293.         dec dword[n]
  294.         cmp dword[n],0
  295.         jge .do_cycle
  296. }
  297.  
  298. ; fin macro
  299.  
  300.         mov eax,[d_x]
  301.         cmp eax,0
  302.         jne .els_0
  303.         cmp dword[d_y],0
  304.         jne .els_0
  305.                 ;if (d_x==0 && d_y==0)
  306.                 PUTPIXEL
  307.                 jmp .end_2
  308.         .els_0:
  309.         cmp eax,0
  310.         jle .els_3
  311.                 ;if (d_x > 0)
  312.                 mov esi,[sx]
  313.                 inc esi
  314.                 cmp eax,[d_y]
  315.                 jl .els_2
  316.                         ;if (d_x >= d_y)
  317.                         DRAWLINE [d_x], [d_y], esi, 1
  318.                         jmp .end_2
  319.                 .els_2:
  320.                         DRAWLINE [d_y], [d_x], esi, [sx]
  321.                         jmp .end_2
  322.         .els_3:
  323.                 xor eax,eax
  324.                 sub eax,[d_x]
  325.                 mov [d_x],eax
  326.                 mov esi,[sx]
  327.                 dec esi
  328.                 cmp eax,[d_y]
  329.                 jl .els_4
  330.                         ;if (d_x >= d_y)
  331.                         DRAWLINE [d_x], [d_y], esi, -1
  332.                         jmp .end_2
  333.                 .els_4:
  334.                         DRAWLINE [d_y], [d_x], esi, [sx]
  335.         .end_2:
  336.  
  337. popad
  338.         ret
  339. endp
  340.  
  341. restore INTERP_Z
  342.  
  343. ; internal defines
  344. purge DRAWLINE
  345. purge PUTPIXEL
  346. purge RGBPIXEL
  347.