Subversion Repositories Kolibri OS

Rev

Rev 5159 | Go to most recent revision | 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. if TGL_FEATURE_RENDER_BITS eq 24
  12.         r dd ? ;register unsigned int
  13.         g dd ?
  14.         b dd ?
  15. end if
  16. if INTERP_Z eq 1
  17.         pz dd ? ;register unsigned short *
  18.         zinc dd ?
  19.         z dd ? ;register int
  20.         zz dd ?
  21. end if
  22. endl
  23. pushad
  24.  
  25.         mov eax,[p1]
  26.         mov ebx,[p2]
  27.         mov ecx,[ebx+offs_zbup_y]
  28.         cmp [eax+offs_zbup_y], ecx ;if (p1.y > p2.y)
  29.         jg @f
  30.         jl .end_0 ;if (p1.y != p2.y)
  31.         mov ecx,[ebx+offs_zbup_x]
  32.         cmp [eax+offs_zbup_x], ecx ;if (p1.x > p2.x)
  33.         jle .end_0 ;if (p1.x <= p2.x)
  34.         @@: ;if (p1.y > p2.y || (p1.y == p2.y && p1.x > p2.x))
  35.                 mov [p1],ebx
  36.                 mov [p2],eax
  37.         .end_0:
  38.  
  39.         mov eax,[zb]
  40.         mov edx,[eax+offs_zbuf_xsize]
  41.         mov [sx],edx
  42.         mov ecx,[p1]
  43.         mov edi,[eax+offs_zbuf_linesize]
  44.         imul edi,[ecx+offs_zbup_y]
  45.         mov edx,[ecx+offs_zbup_x]
  46.         imul edx,PSZB
  47.         add edi,edx
  48.         add edi,[eax+offs_zbuf_pbuf] ;edi = (zb.pbuf + zb.linesize*p1.y + p1.x*PSZB)
  49. if INTERP_Z eq 1
  50.         mov edx,[ecx+offs_zbup_y]
  51.         imul edx,[sx]
  52.         add edx,[ecx+offs_zbup_x]
  53.         add edx,[eax+offs_zbuf_zbuf]
  54.         mov [pz],edx ;pz = zb.zbuf + (p1.y*sx + p1.x)
  55.         mov edx,[ecx+offs_zbup_z]
  56.         mov [z],edx ;z = p1.z
  57. end if
  58.  
  59.         mov ebx,[p2]
  60.         mov eax,[ebx+offs_zbup_x]
  61.         sub eax,[ecx+offs_zbup_x]
  62.         mov [d_x],eax ;d_x = p2.x - p1.x
  63.         mov eax,[ebx+offs_zbup_y]
  64.         sub eax,[ecx+offs_zbup_y]
  65.         mov [d_y],eax ;d_y = p2.y - p1.y
  66. if TGL_FEATURE_RENDER_BITS eq 24
  67.         ; for 24 bits, we store the colors in different variables
  68.         mov eax,[ebx+offs_zbup_r]
  69.         shr eax,8
  70.         mov [r],eax ;r = p2.r >> 8
  71.         mov eax,[ebx+offs_zbup_g]
  72.         shr eax,8
  73.         mov [g],eax ;g = p2.g >> 8
  74.         mov eax,[ebx+offs_zbup_b]
  75.         shr eax,8
  76.         mov [b],eax ;b = p2.b >> 8
  77. end if
  78.  
  79. macro RGBPIXEL
  80. {
  81. if TGL_FEATURE_RENDER_BITS eq 24
  82.         mov eax,[r]
  83.         mov byte[edi],al
  84.         mov eax,[g]
  85.         mov byte[edi+1],al
  86.         mov eax,[b]
  87.         mov byte[edi+2],al
  88. ;;;     else
  89. ;;;     mov eax,[color]
  90. ;;;     mov [edi],eax
  91. end if
  92. }
  93.  
  94. macro PUTPIXEL
  95. {
  96. if INTERP_Z eq 1
  97. local .end_0
  98.         mov eax,[z]
  99.         shr eax, ZB_POINT_Z_FRAC_BITS
  100.         mov [zz],eax
  101.         cmp eax,[pz]
  102.         jl .end_0
  103.                 RGBPIXEL
  104.                 mov eax,dword[zz]
  105.                 mov [pz],eax
  106.         .end_0:
  107. else ; INTERP_Z
  108.         RGBPIXEL
  109. end if ; INTERP_Z
  110. }
  111.  
  112. macro DRAWLINE d_x,d_y,inc_1,inc_2
  113. {
  114.         mov eax,d_x
  115.         mov [n],eax
  116. if INTERP_Z eq 1
  117.         mov ebx,[p1]
  118.         mov eax,[p2]
  119.         mov eax,[eax+offs_zbup_z]
  120.         sub eax,[ebx+offs_zbup_z]
  121.         xor edx,edx
  122.         div dword[n]
  123.         mov [zinc],eax ;zinc=(p2.z-p1.z)/n
  124. end if
  125.         shl dword d_y,1
  126.         mov eax, d_y
  127.         sub eax, d_x
  128.         mov [a],eax ;a=2*d_y-d_x
  129.         shl dword d_x,1
  130.         mov eax, d_y
  131.         sub d_x,eax
  132.         mov eax,inc_1
  133.         imul eax,PSZB
  134.         mov [pp_inc_1],eax ;pp_inc_1 = inc_1*PSZB
  135.         mov eax,inc_2
  136.         imul eax,PSZB
  137.         mov [pp_inc_2],eax ;pp_inc_2 = inc_2*PSZB
  138.  
  139. local .do_cycle
  140. local .els_0
  141. local .end_0
  142.  
  143. align 4
  144. .do_cycle:
  145.  
  146.         PUTPIXEL
  147. if INTERP_Z eq 1
  148.         mov eax,[zinc]
  149.         add [z],eax
  150. end if
  151.  
  152.         cmp dword[a],0
  153.         jle .els_0
  154.         add edi,[pp_inc_1]
  155. if INTERP_Z eq 1
  156.         mov eax,inc_1
  157.         add [pz],eax
  158. end if
  159.         mov eax,d_x
  160.         sub [a],eax
  161.         jmp .end_0
  162.  
  163. .els_0:
  164.         add edi,[pp_inc_2]
  165. if INTERP_Z eq 1
  166.         mov eax,inc_2
  167.         add [pz],eax
  168. end if
  169.         mov eax,d_y
  170.         add [a],eax
  171.  
  172. .end_0:
  173.         dec dword[n]
  174.         cmp dword[n],0
  175.         jge .do_cycle
  176. }
  177.  
  178. ; fin macro
  179.  
  180.         mov eax,[d_x]
  181.         cmp eax,0
  182.         jne .els_0
  183.         cmp dword[d_y],0
  184.         jne .els_0
  185.                 ;if (d_x==0 && d_y==0)
  186.                 PUTPIXEL
  187.                 jmp .end_2
  188.         .els_0:
  189.         cmp eax,0
  190.         jle .els_3
  191.                 ;if (d_x > 0)
  192.                 mov esi,[sx]
  193.                 inc esi
  194.                 cmp eax,[d_y]
  195.                 jl .els_2
  196.                         ;if (d_x >= d_y)
  197.                         DRAWLINE [d_x], [d_y], esi, 1
  198.                         jmp .end_2
  199.                 .els_2:
  200.                         DRAWLINE [d_y], [d_x], esi, [sx]
  201.                         jmp .end_2
  202.         .els_3:
  203.                 xor eax,eax
  204.                 sub eax,[d_x]
  205.                 mov [d_x],eax
  206.                 mov esi,[sx]
  207.                 dec esi
  208.                 cmp eax,[d_y]
  209.                 jl .els_4
  210.                         ;if (d_x >= d_y)
  211.                         DRAWLINE [d_x], [d_y], esi, -1
  212.                         jmp .end_2
  213.                 .els_4:
  214.                         DRAWLINE [d_y], [d_x], esi, [sx]
  215.         .end_2:
  216.  
  217. popad
  218.         ret
  219. endp
  220.  
  221. restore INTERP_Z
  222.  
  223. ; internal defines
  224. purge DRAWLINE
  225. purge PUTPIXEL
  226. purge RGBPIXEL
  227.