Subversion Repositories Kolibri OS

Rev

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

  1. ROUND2 equ 10
  2.  
  3. stencil_tri:
  4. ;  procedure calculate triangle in stencil buffer
  5. ;  ----------------in - eax - x1 shl 16 + y1 ----------------------
  6. ;  -------------------- ebx - x2 shl 16 + y2 ----------------------
  7. ;  -------------------- ecx - x3 shl 16 + y3 ----------------------
  8. ;  -------------------- esi - pointer to s-buffer -----------------
  9. ;  -------------------- xmm0 - lo -> hi z1, z2, z3 as dword float
  10.  
  11. .x1     equ [ebp-2]
  12. .y1     equ [ebp-4]
  13. .x2     equ [ebp-6]
  14. .y2     equ [ebp-8]
  15. .x3     equ [ebp-10]
  16. .y3     equ [ebp-12]
  17.  
  18. .dx12   equ dword[ebp-20]
  19. .dz12   equ dword[ebp-24]
  20. .dx13   equ dword[ebp-28]
  21. .dz13   equ dword[ebp-32]
  22. .dx23   equ dword[ebp-36]
  23. .dz23   equ dword[ebp-40]
  24. .zz2    equ [ebp-44]
  25. .zz1    equ [ebp-48]
  26. .z3     equ [ebp-56]
  27. .z2     equ [ebp-60]
  28. .z1     equ [ebp-64]
  29. ;.s_buff equ [ebp-68]
  30.  
  31.        push    ebp
  32.        mov     ebp,esp
  33.      ;  sub     esp,128
  34.      ;  and     ebp,0xfffffff0
  35.       .sort2:
  36.         cmp     ax,bx
  37.         jle     .sort1
  38.         xchg    eax,ebx
  39.         shufps  xmm0,xmm0,11100001b
  40.       .sort1:
  41.         cmp     bx,cx
  42.         jle     .sort3
  43.         xchg    ebx,ecx
  44.         shufps  xmm0,xmm0,11011000b
  45.         jmp     .sort2
  46.       .sort3:
  47.       ;  mov     .y1,eax            ; store triangle coordinates in user friendly variables
  48.       ;  mov     .y2,ebx
  49.       ;  mov     .y3,ecx
  50.         push     eax
  51.         push     ebx
  52.         push     ecx
  53.         sub      esp,60
  54.  
  55.  
  56.     ;   mov     edx,100.11
  57.     ;   movd    xmm0,edx
  58.     ;   shufps  xmm0,xmm0,11100000b
  59.  
  60.         movups  .z1,xmm0
  61.     ;    mov     dword .z1,edx
  62.     ;    mov     .z2,edx
  63.     ;    mov     .z3,edx
  64.  ;       mov     .s_buff,esi
  65.  
  66.          mov      edx,80008000h  ; eax,ebx,ecx are ANDd together into edx which means that
  67.          and      edx,ebx        ; if *all* of them are negative a sign flag is raised
  68.          and      edx,ecx
  69.          and      edx,eax
  70.          test     edx,80008000h  ; Check both X&Y at once
  71.          jne      .loop2_end
  72.  
  73.         mov     bx,.y2       ; calc delta 12
  74.         sub     bx,.y1
  75.         jnz     .dx12_make
  76.         mov     .dx12,0
  77.         mov     .dz12,0
  78.         jmp     .dx12_done
  79.    .dx12_make:
  80.         mov     ax,.x2
  81.         sub     ax,.x1
  82.         cwde
  83.         movsx   ebx,bx
  84.         shl     eax,ROUND2
  85.         cdq
  86.         idiv    ebx
  87.         mov     .dx12,eax
  88.  
  89.         movss    xmm1,.z2
  90.         cvtsi2ss xmm2,ebx
  91.         subss    xmm1,.z1
  92.         divss    xmm1,xmm2
  93.         movss    .dz12,xmm1
  94.      ;  mov      .dz12, dword 0.11
  95.  
  96.   .dx12_done:
  97.         mov     bx,.y3       ; calc delta 13
  98.         sub     bx,.y1
  99.         jnz     .dx13_make
  100.         mov     .dx13,0
  101.         mov     .dz13,0
  102.         jmp     .dx13_done
  103.    .dx13_make:
  104.         mov     ax,.x3
  105.         sub     ax,.x1
  106.         cwde
  107.         movsx   ebx,bx
  108.         shl     eax,ROUND2
  109.         cdq
  110.         idiv    ebx
  111.         mov     .dx13,eax
  112.  
  113.         movss    xmm1,.z3
  114.         cvtsi2ss xmm2,ebx
  115.         subss    xmm1,.z1
  116.         divss    xmm1,xmm2
  117.         movss    .dz13,xmm1
  118.     ;    mov  .dz13, dword 0.11
  119.  
  120.     .dx13_done:
  121.         mov     bx,.y3       ; calc delta 23
  122.         sub     bx,.y2
  123.         jnz     .dx23_make
  124.         mov     .dx23,0
  125.         mov     .dz23,0
  126.         jmp     .dx23_done
  127.    .dx23_make:
  128.         mov     ax,.x3
  129.         sub     ax,.x2
  130.         cwde
  131.         movsx   ebx,bx
  132.         shl     eax,ROUND2
  133.         cdq
  134.         idiv    ebx
  135.         mov     .dx23,eax
  136.  
  137.         movss    xmm1,.z3
  138.         cvtsi2ss xmm2,ebx
  139.         subss    xmm1,.z2
  140.         divss    xmm1,xmm2
  141.         movss    .dz23,xmm1
  142.  
  143.     .dx23_done:
  144.         mov     edx,.z1
  145.  
  146.         mov     .zz1,edx
  147.         mov     .zz2,edx
  148.         movsx   eax,word .x1
  149.         shl     eax,ROUND2    ; eax - cur x1
  150.         mov     ebx,eax       ; ebx - cur x2
  151.  
  152.         mov     cx,.y1
  153.         cmp     cx,.y2
  154.         jge     .loop1_end
  155.      .loop1:
  156.  
  157.         pushad
  158.         sar     ebx,ROUND2
  159.         sar     eax,ROUND2
  160.      ;   movq    xmm0,.zz1
  161.         movlps  xmm0,.zz1
  162.    ;     mov     edx,0.11
  163.    ;     movd    xmm0,edx
  164.    ;     shufps  xmm0,xmm0,11100000b
  165. ;        mov     esi,.s_buff
  166.  
  167.         call    stencil_line
  168.  
  169.         popad
  170.         add     eax,.dx13
  171.         add     ebx,.dx12
  172.  
  173.         movss   xmm1,.zz1
  174.         movss   xmm2,.zz2
  175.         addss   xmm1,.dz13
  176.         addss   xmm2,.dz12
  177.         movss   .zz1,xmm1
  178.         movss   .zz2,xmm2
  179.  
  180.         add     cx,1
  181.         cmp     cx,.y2
  182.         jl      .loop1
  183.  
  184.     .loop1_end:
  185.  
  186.         mov     edx,.z2
  187.         mov     .zz2,edx
  188.         movsx   ebx,word .x2
  189.         shl     ebx,ROUND2
  190.  
  191.         mov     cx,.y2
  192.         cmp     cx,.y3
  193.         jge     .loop2_end
  194.      .loop2:
  195.         pushad
  196.  
  197.         sar     ebx,ROUND2
  198.         sar     eax,ROUND2
  199.         movlps  xmm0,.zz1
  200. ;        mov     esi,.s_buff
  201.  
  202.  
  203.         call    stencil_line
  204.  
  205.         popad
  206.  
  207.         add     eax,.dx13
  208.         add     ebx,.dx23
  209.  
  210.         movss   xmm1,.zz1
  211.         movss   xmm2,.zz2
  212.         addss   xmm1,.dz13
  213.         addss   xmm2,.dz23
  214.         movss   .zz1,xmm1
  215.         movss   .zz2,xmm2
  216.  
  217.  
  218.         add     cx,1
  219.         cmp     cx,.y3
  220.         jl      .loop2
  221.      .loop2_end:
  222.  
  223.         mov  esp,ebp
  224.         pop  ebp
  225.  
  226. ret
  227.  
  228. stencil_line:
  229. ;----------------------------------------------------
  230. ;-------------in xmm0 - lo -> hi z1, z2
  231. ;--------------- eax - x1 ---------------------------
  232. ;--------------- ebx - x2 ---------------------------
  233. ;--------------- ecx - y-----------------------------
  234. ;--------------- esi - pointer to s-buffer
  235.  
  236.  
  237. .dz equ  [ebp-4]
  238. .z2 equ  [ebp-8]
  239. .z1 equ  [ebp-12]
  240. .x2 equ  [ebp-16]
  241. .x1 equ  [ebp-20]
  242. .s_buf  equ [ebp-24]
  243. ;     cmp        eax,ebx
  244. ;     je  @f
  245. ;     int3
  246. ;   @@:
  247.      push       ebp
  248.      mov        ebp,esp
  249.      sub        esp,64
  250.   ;   cmp        eax,0
  251.   ;   jg         @f
  252.   ;
  253.   ; @@:
  254.      or         cx,cx
  255.      jle        .l_quit
  256.  
  257.      cmp        cx,[size_y_var]
  258.      jge        .l_quit
  259.  
  260.      movzx      ecx,cx
  261.      mov        .s_buf,esi
  262.      cmp        eax,ebx
  263.      je         .l_quit
  264.      jl         .l_ok
  265.  
  266.      xchg       eax,ebx
  267.      shufps     xmm0,xmm0,11100001b
  268.    .l_ok:
  269.  
  270.      cmp        ax,[size_x_var]
  271.      jge        .l_quit
  272.      cmp        bx,0
  273.      jle        .l_quit
  274.  
  275.      movlps     .z1,xmm0
  276.      mov        .x1,eax
  277.      mov        .x2,ebx
  278.  
  279.      sub        ebx,eax
  280.      movss      xmm0,.z2
  281.      cvtsi2ss   xmm1,ebx
  282.      subss      xmm0,.z1
  283.      divss      xmm0,xmm1
  284.      movss      .dz,xmm0
  285.  
  286.      movzx      edx,word[size_x_var]
  287.      cmp        eax,1
  288.      jge        @f
  289.      mov        eax,.x1
  290.      neg        eax
  291.      cvtsi2ss   xmm2,eax
  292.      mulss      xmm2,.dz
  293.      addss      xmm2,.z1
  294.      movss      .z1,xmm2
  295.      mov        dword .x1,0
  296.      movzx      edx,word[size_x_var]
  297.      sub        edx,1
  298.    @@:
  299.      cmp        .x2,edx
  300.      jl         @f
  301.      mov        .x2,edx
  302.  
  303.     @@:
  304.  ;   mov         eax,.x1
  305.  ;   cmp         .x2,eax
  306.  ;   je          .l_quit
  307.      movzx      edx,word[size_x_var]
  308.      mov        esi,.s_buf
  309.      mov        eax,ecx  ; y
  310.      mul        edx
  311.      add        eax,.x1
  312.  
  313.      shl        eax,2
  314.      add        esi,eax
  315.  
  316.      mov        ecx,.x2
  317.      sub        ecx,.x1
  318.      movss      xmm2,.z1   ; cz
  319.    .ccalc:
  320.    ;  movss     xmm1,xmm2
  321.    ;  cmpltss   xmm1,dword[esi]
  322.    ;  movd      eax,xmm1
  323.    ;  cmp       eax,-1
  324.      comiss    xmm2,[esi]
  325.      ja        @f
  326.      movss     dword[esi],xmm2
  327.     @@:
  328.      add       esi,4
  329.      addss     xmm2,.dz
  330. ;     sub       ecx,1
  331. ;     jnz       .ccalc
  332.     loop       .ccalc
  333.   .l_quit:
  334.      mov       esp,ebp
  335.      pop       ebp
  336. ret
  337.