Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ;---------------------------------------------------------------------
  2. ;--------------------textured triangle procedure----------------------
  3. ;---------------------------------------------------------------------
  4.  
  5. tex_triangle:
  6. ;----------in - eax - x1 shl 16 + y1
  7. ;-------------- ebx - x2 shl 16 + y2
  8. ;---------------ecx - x3 shl 16 + y3
  9. ;---------------edx - nothing
  10. ;---------------esi - pointer to texture buffer
  11. ;---------------edi - pointer to screen buffer
  12. ;-------------stack - texture coordinates
  13. .tex_x1 equ  ebp+4
  14. .tex_y1 equ  ebp+6
  15. .tex_x2 equ  ebp+8
  16. .tex_y2 equ  ebp+10
  17. .tex_x3 equ  ebp+12
  18. .tex_y3 equ  ebp+14
  19.  
  20. .x1 equ ebp-2 ;dw ?
  21. .y1 equ ebp-4 ;dw ?
  22. .x2 equ ebp-6 ;dw ?
  23. .y2 equ ebp-8 ;dw ?
  24. .x3 equ ebp-10 ;dw ?
  25. .y3 equ ebp-12 ;dw ?
  26. .dx12 equ ebp-16 ;dd ?
  27. .dx13 equ ebp-20 ;dd ?
  28. .dx23 equ ebp-24 ;dd ?
  29. .tex_dx12 equ ebp-28 ;dd ?
  30. .tex_dy12 equ ebp-32 ;dd ?
  31. .tex_dx13 equ ebp-36 ;dd ?
  32. .tex_dy13 equ ebp-40 ;dd ?
  33. .tex_dx23 equ ebp-44 ;dd ?
  34. .tex_dy23 equ ebp-48 ;dd ?
  35. .tex_ptr equ ebp-52 ;dd ?
  36.  
  37. .scan_x2 equ ebp-56 ;dd ?
  38. .scan_y2 equ ebp-60 ;dd ?
  39. .scan_x1 equ ebp-64 ;dd ?
  40. .scan_y1 equ ebp-68 ;dd ?
  41.  
  42.   mov ebp,esp
  43.   sub esp,68
  44. ;if  Ext = MMX
  45. ;  emms
  46. ;end if
  47.   mov edx,dword[.tex_x1]                  ; check all parameters
  48.   or dx,dx
  49.   jl .tt_end
  50.   cmp dx,TEX_X-1
  51.   jg .tt_end
  52.   shr edx,16
  53.   or dx,dx
  54.   jl .tt_end
  55.   cmp dx,TEX_Y-1
  56.   jg .tt_end
  57.  
  58.   mov edx,dword[.tex_x2]
  59.   or dx,dx
  60.   jl .tt_end
  61.   cmp dx,TEX_X-1
  62.   jg .tt_end
  63.   shr edx,16
  64.   or dx,dx
  65.   jl .tt_end
  66.   cmp dx,TEX_Y-1
  67.   jg .tt_end
  68.  
  69.   mov edx,dword[.tex_x3]
  70.   or dx,dx
  71.   jl .tt_end
  72.   cmp dx,TEX_X-1
  73.   jg .tt_end
  74.   shr edx,16
  75.   cmp dx,TEX_Y-1
  76.   jg .tt_end
  77.   or dx,dx
  78.   jl .tt_end
  79.  
  80.   mov edx,eax    ; check X&Y triangle coordinate
  81.   or edx,ebx
  82.   or edx,ecx
  83.   test edx,80008000h
  84.   jne .tt_end
  85.  
  86.  ; or ax,ax
  87.  ; jl .tt_end
  88.   cmp ax,SIZE_Y
  89.   jg .tt_end
  90.   ror eax,16
  91.  ; or ax,ax
  92.  ; jl .tt_end
  93.   cmp ax,SIZE_X
  94.   jg .tt_end
  95.   rol eax,16
  96.  
  97.  ; or bx,bx
  98.  ; jl .tt_end
  99.   cmp bx,SIZE_Y
  100.   jg .tt_end
  101.   ror ebx,16
  102.  ; or bx,bx
  103.  ; jl .tt_end
  104.   cmp bx,SIZE_X
  105.   jg .tt_end
  106.   rol ebx,16
  107.  
  108.  ; or cx,cx
  109.  ; jl .tt_end
  110.   cmp cx,SIZE_Y
  111.   jg .tt_end
  112.   ror ecx,16
  113.  ; or cx,cx
  114.  ; jl .tt_end
  115.   cmp cx,SIZE_X
  116.   jg .tt_end
  117.   rol ecx,16                   ; uff.. parameters was checked
  118.  
  119.   cmp ax,bx                         ;sort all parameters
  120.   jle .tt_sort1
  121.   xchg eax,ebx
  122.   mov edx,dword [.tex_x1]
  123.   xchg edx,dword [.tex_x2]
  124.   mov dword[.tex_x1],edx
  125. .tt_sort1:
  126.   cmp ax,cx
  127.   jle .tt_sort2
  128.   xchg eax,ecx
  129.   mov edx,dword [.tex_x1]
  130.   xchg edx,dword [.tex_x3]
  131.   mov dword [.tex_x1],edx
  132. .tt_sort2:
  133.   cmp bx,cx
  134.   jle .tt_sort3
  135.   xchg ebx,ecx
  136.   mov edx,dword [.tex_x2]
  137.   xchg edx,dword [.tex_x3]
  138.   mov dword [.tex_x2],edx
  139. .tt_sort3:
  140.   mov [.y1],ax     ; and store to user friendly variables
  141.   shr eax,16
  142.   mov [.x1],ax
  143.   mov [.y2],bx
  144.   shr ebx,16
  145.   mov [.x2],bx
  146.   mov [.y3],cx
  147.   shr ecx,16
  148.   mov [.x3],cx
  149.   mov [.tex_ptr],esi
  150.  
  151.   movsx ebx,word[.y2]
  152.   sub bx,[.y1]
  153.   jnz .tt_dx12_make
  154.  
  155.   mov dword[.dx12],0
  156.   mov dword[.tex_dx12],0
  157.   mov dword[.tex_dy12],0
  158.   jmp .tt_dx12_done
  159. .tt_dx12_make:
  160.   mov ax,[.x2]
  161.   sub ax,[.x1]
  162.   cwde
  163.   shl eax,ROUND
  164.   cdq
  165.   idiv ebx
  166.   mov [.dx12],eax                                     ; dx12 = (x2-x1)/(y2-y1)
  167.  
  168.   mov ax,word[.tex_x2]
  169.   sub ax,word[.tex_x1]
  170.   cwde
  171.   shl eax,ROUND
  172.   cdq
  173.   idiv ebx
  174.   mov [.tex_dx12],eax                     ; tex_dx12 = (tex_x2-tex_x1)/(y2-y1)
  175.  
  176.   mov ax,word[.tex_y2]
  177.   sub ax,word[.tex_y1]
  178.   cwde
  179.   shl eax,ROUND
  180.   cdq
  181.   idiv ebx
  182.   mov [.tex_dy12],eax                     ; tex_dy12 = (tex_y2-tex_y1)/(y2-y1)
  183. .tt_dx12_done:
  184.  
  185.   movsx ebx,word[.y3]
  186.   sub bx,word[.y1]
  187.   jnz .tt_dx13_make
  188.  
  189.   mov dword [.dx13],0
  190.   mov dword [.tex_dx13],0
  191.   mov dword [.tex_dy13],0
  192.   jmp .tt_dx13_done
  193. .tt_dx13_make:
  194.   mov ax,[.x3]
  195.   sub ax,[.x1]
  196.   cwde
  197.   shl eax,ROUND
  198.   cdq
  199.   idiv ebx
  200.   mov [.dx13],eax                                 ; dx13 = (x3-x1)/(y3-y1)
  201.  
  202.   mov ax,word[.tex_x3]
  203.   sub ax,word[.tex_x1]
  204.   cwde
  205.   shl eax,ROUND
  206.   cdq
  207.   idiv ebx
  208.   mov [.tex_dx13],eax                       ; tex_dx13 = (tex_x3-tex_x1)/(y3-y1)
  209.  
  210.   mov ax,word[.tex_y3]
  211.   sub ax,word[.tex_y1]
  212.   cwde
  213.   shl eax,ROUND
  214.   cdq
  215.   idiv ebx
  216.   mov [.tex_dy13],eax                       ; tex_dy13 = (tex_y3-tex_y1)/(y3-y1)
  217. .tt_dx13_done:
  218.  
  219.   movsx ebx,word[.y3]
  220.   sub bx,word[.y2]
  221.   jnz .tt_dx23_make
  222.  
  223.   mov dword [.dx23],0
  224.   mov dword [.tex_dx23],0
  225.   mov dword [.tex_dy23],0
  226.   jmp .tt_dx23_done
  227. .tt_dx23_make:
  228.   mov ax,[.x3]
  229.   sub ax,[.x2]
  230.   cwde
  231.   shl eax,ROUND
  232.   cdq
  233.   idiv ebx
  234.   mov [.dx23],eax                                 ; dx23 = (x3-x2)/(y3-y2)
  235.  
  236.   mov ax,word[.tex_x3]
  237.   sub ax,word[.tex_x2]
  238.   cwde
  239.   shl eax,ROUND
  240.   cdq
  241.   idiv ebx
  242.   mov [.tex_dx23],eax                    ; tex_dx23 = (tex_x3-tex_x2)/(y3-y2)
  243.  
  244.   mov ax,word[.tex_y3]
  245.   sub ax,word[.tex_y2]
  246.   cwde
  247.   shl eax,ROUND
  248.   cdq
  249.   idiv ebx
  250.   mov [.tex_dy23],eax                   ; tex_dy23 = (tex_y3-tex_y2)/(y3-y2)
  251. .tt_dx23_done:
  252.  
  253.   movsx eax,word[.x1]
  254.   shl eax,ROUND
  255.   mov ebx,eax
  256.  
  257.   movsx edx, word[.tex_x1]
  258.   shl edx,ROUND
  259.   mov [.scan_x1],edx
  260.   mov [.scan_x2],edx
  261.   movsx edx, word[.tex_y1]
  262.   shl edx,ROUND
  263.   mov [.scan_y1],edx
  264.   mov [.scan_y2],edx
  265.  
  266.   mov cx,[.y1]
  267.   cmp cx, [.y2]
  268.   jge .tt_loop1_end
  269. .tt_loop1:
  270.   push edi
  271.   push eax
  272.   push ebx
  273.   push cx
  274.   push ebp
  275. ;; Madis
  276. ;if Ext=MMX                          ; With MMX enabled it reverse light vectors ????
  277. ;  mov   dword[esp-8],ROUND
  278. ;  mov   dword[esp-4],0 ; Is this a bug? Explanation down 3 lines
  279. ;  movq  mm0,qword[.scan_y1]
  280. ;  movq  mm1,qword[.scan_y2]
  281. ;  psrad mm0,[esp-8] ;This instr. won't allow modifiers BYTE, WORD, etc.
  282. ;  psrad mm1,[esp-8] ;It always defaults to QWORD
  283. ;  packssdw mm0,mm1
  284. ;  movq  [esp-8],mm0
  285. ;  sub   esp,8
  286. ;else
  287.  
  288.    push     dword[.scan_y2]  ; now I push variables on stack without shifting
  289.    push     dword[.scan_x2]
  290.    push     dword[.scan_y1]
  291.    push     dword[.scan_x1]
  292.  
  293. ;end if
  294.  
  295.  
  296.  
  297.   push  dword[.tex_ptr]
  298.  
  299.   push  cx
  300.   mov   edx,ebx
  301.   sar   edx,ROUND
  302.   push  dx
  303.   mov   edx,eax
  304.   sar   edx,ROUND
  305.   push  dx
  306.   call  textured_line
  307.  
  308.   pop   ebp
  309.   pop   cx
  310.   pop   ebx
  311.   pop   eax
  312.   pop   edi
  313.  
  314.   mov   edx, [.tex_dx13]
  315.   add   [.scan_x1], edx
  316.   mov   edx, [.tex_dx12]
  317.   add   [.scan_x2], edx
  318.   mov   edx, [.tex_dy13]
  319.   add   [.scan_y1], edx
  320.   mov   edx, [.tex_dy12]
  321.   add   [.scan_y2], edx
  322.  
  323.   add   eax, [.dx13]
  324.   add   ebx, [.dx12]
  325.   inc   cx
  326.   cmp   cx,[.y2]
  327.   jl    .tt_loop1
  328.  
  329. .tt_loop1_end:
  330.  
  331.  
  332.   mov   cx, [.y2]
  333.   cmp   cx, [.y3]
  334.   jge   .tt_loop2_end
  335.  
  336.   movsx ebx,word[.x2]
  337.   shl   ebx,ROUND
  338.  
  339.   movsx edx, word[.tex_x2]
  340.   shl   edx,ROUND
  341.   mov   [.scan_x2],edx
  342.   movsx edx, word[.tex_y2]
  343.   shl   edx,ROUND
  344.   mov   [.scan_y2],edx
  345.  
  346. .tt_loop2:
  347.   push  edi
  348.   push  eax
  349.   push  ebx
  350.   push  cx
  351.   push  ebp
  352. ;; Madis
  353. ;if Ext=MMX
  354. ;  mov   dword[esp-8],ROUND
  355. ;  mov   dword[esp-4],0 ; Is this a bug? Explanation down 3 lines
  356. ;  movq  mm0,qword[.scan_y1]
  357. ;  movq  mm1,qword[.scan_y2]
  358. ;  psrad mm0,[esp-8] ;This instr. won't allow modifiers BYTE, WORD, etc.
  359. ;  psrad mm1,[esp-8] ;It always defaults to QWORD
  360. ;  packssdw mm0,mm1
  361. ;  movq  [esp-8],mm0
  362. ;  sub   esp,8
  363. ;else
  364.  
  365. ;end if
  366.   push  dword[.scan_y2]
  367.   push  dword[.scan_x2]
  368.   push  dword[.scan_y1]
  369.   push  dword[.scan_x1]
  370.  
  371.  
  372.  
  373.   push  dword[.tex_ptr]
  374.  
  375.   push  cx
  376.   mov   edx,ebx
  377.   sar   edx,ROUND
  378.   push  dx
  379.   mov   edx,eax
  380.   sar   edx,ROUND
  381.   push  dx
  382.   call  textured_line
  383.  
  384.   pop   ebp
  385.   pop   cx
  386.   pop   ebx
  387.   pop   eax
  388.   pop   edi
  389.  
  390.   mov   edx, [.tex_dx13]
  391.   add   [.scan_x1], edx
  392.   mov   edx, [.tex_dx23]
  393.   add   [.scan_x2], edx
  394.   mov   edx, [.tex_dy13]
  395.   add   [.scan_y1], edx
  396.   mov   edx, [.tex_dy23]
  397.   add   [.scan_y2], edx
  398.  
  399.   add   eax, [.dx13]
  400.   add   ebx, [.dx23]
  401.   inc   cx
  402.   cmp   cx,[.y3]
  403.   jl    .tt_loop2
  404.  
  405. .tt_loop2_end:
  406.  
  407. .tt_end:
  408.  mov    esp,ebp
  409.  
  410. ret 12
  411.  
  412.  
  413. textured_line:
  414. ;-----in -edi screen buffer pointer
  415. ;------------ stack:
  416.   .x1 equ word [ebp+4]
  417.   .x2 equ word [ebp+6]
  418.   .y  equ word [ebp+8]
  419.  
  420.   .tex_ptr equ dword [ebp+10]
  421.   .tex_x1  equ  [ebp+14]
  422.   .tex_y1  equ  [ebp+18]
  423.   .tex_x2  equ  [ebp+22]
  424.   .tex_y2  equ  [ebp+26]
  425.  
  426.   .tex_dx equ ebp-4 ;dd ?
  427.   .tex_dy equ ebp-8 ;dd ?
  428.  
  429.   mov   ebp,esp
  430.   sub   esp,8
  431.  
  432.   mov   ax,.y
  433.   or    ax,ax
  434.   jl    .tl_quit
  435.   cmp   ax,SIZE_Y
  436.   jg    .tl_quit
  437.  
  438.   mov   ax,.x1
  439.   cmp   ax,.x2
  440.   je    .tl_quit
  441.   jl    .tl_ok
  442.  
  443.   xchg  ax,.x2
  444.   mov   .x1,ax
  445.  
  446. if Ext >= MMX
  447.   movq    mm0,.tex_x1
  448.   movq    mm1,.tex_x2
  449.   movq    .tex_x2,mm0
  450.   movq    .tex_x1,mm1
  451.  
  452. else
  453.  
  454.   mov   eax,.tex_x1
  455.   xchg  eax,.tex_x2
  456.   mov   .tex_x1,eax
  457.  
  458.   mov   eax,.tex_y1
  459.   xchg  eax,.tex_y2
  460.   mov   .tex_y1,eax
  461.  
  462. end if
  463.  
  464.  .tl_ok:
  465.  
  466.   mov   ebx,edi
  467.   movsx edi,.y
  468.   mov   eax,SIZE_X*3
  469.   mul   edi
  470.   mov   edi,eax
  471.   movsx eax,.x1
  472.   add   edi,eax
  473.   shl   eax,1
  474.   add   edi,eax
  475.   add   edi,ebx
  476.  
  477.   mov   cx,.x2
  478.   sub   cx,.x1
  479.   movsx ecx,cx
  480.  
  481.   mov   eax,.tex_x2
  482.   sub   eax,.tex_x1
  483.   cdq
  484.   idiv  ecx
  485.   mov   [.tex_dx],eax           ; tex_dx=(tex_x2-tex_x1)/(x2-x1)
  486.  
  487.   mov   eax,.tex_y2
  488.   sub   eax,.tex_y1
  489.   cdq
  490.   idiv  ecx
  491.   mov   [.tex_dy],eax                  ; tex_dy = (tex_y2-tex_y1)/(x2-x1)
  492.  
  493.   mov   eax,.tex_x1
  494.   mov   ebx,.tex_y1
  495.   cld
  496.  .tl_loop:
  497.   mov   edx,eax    ; eax - cur x
  498.   mov   esi,ebx    ; ebx - cur y
  499.   shr   edx,ROUND
  500.   shr   esi,ROUND
  501.  macro .fluent
  502.  {
  503.   push  eax
  504.   push  edx
  505.   mov   eax,TEX_X*3
  506.   mul   esi
  507.   mov   esi,eax
  508.   pop   edx
  509.   pop   eax
  510.  }
  511.  macro .shift
  512.  {
  513.   shl   esi,TEX_SHIFT
  514.   lea   esi,[esi*3]
  515.   ;push edx
  516.   ;mov edx,esi
  517.   ;shl esi,1
  518.   ;add esi,edx
  519.   ;pop edx
  520.  }
  521.   if TEX = FLUENTLY
  522.     .fluent
  523.   end if
  524.   if TEX = SHIFTING
  525.     .shift
  526.   end if
  527.   lea   edx,[edx*3]
  528.   add   esi,edx
  529.  ; shl edx,1
  530.  ; add esi,edx
  531.   add   esi,.tex_ptr
  532.   movsd
  533.   dec   edi
  534.   add   eax,[.tex_dx]
  535.   add   ebx,[.tex_dy]
  536.   loop .tl_loop
  537.  
  538.  .tl_quit:
  539.   mov esp,ebp
  540.  
  541. ret 18+8
  542. ;  .tex_dx dd ?
  543. ;  .tex_dy dd ?
  544.