Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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