Subversion Repositories Kolibri OS

Rev

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

  1. CATMULL_SHIFT equ 16
  2.  
  3.  
  4. flat_triangle_z:
  5. ;  procedure drawing triangle with Z cordinate interpolation ------
  6. ;  (Catmull  alghoritm)--------------------------------------------
  7. ;  ----------------in - eax - x1 shl 16 + y1 ----------------------
  8. ;  -------------------- ebx - x2 shl 16 + y2 ----------------------
  9. ;  -------------------- ecx - x3 shl 16 + y3 ----------------------
  10. ;  -------------------- edx - color 0x00RRGGBB --------------------
  11. ;  -------------------- esi - pointer to Z-buffer -----------------
  12. ;  -------------------- edi - pointer to screen buffer-------------
  13. ;  -------------------- stack : z coordinates
  14. ;  -------------------- Z-buffer : each z variable as dword
  15. ;  -------------------- (Z coor. as word) shl CATMULL_SHIFT
  16. .z1     equ word[ebp+4]
  17. .z2     equ word[ebp+6]    ; each z coordinate as word integer
  18. .z3     equ word[ebp+8]
  19.  
  20. .col    equ dword[ebp-4]
  21. .x1     equ word[ebp-6]
  22. .y1     equ word[ebp-8]
  23. .x2     equ word[ebp-10]
  24. .y2     equ word[ebp-12]
  25. .x3     equ word[ebp-14]
  26. .y3     equ word[ebp-16]
  27.  
  28. .dx12   equ dword[ebp-20]
  29. .dz12   equ dword[ebp-24]
  30. .dx13   equ dword[ebp-28]
  31. .dz13   equ dword[ebp-32]
  32. .dx23   equ dword[ebp-36]
  33. .dz23   equ dword[ebp-40]
  34. .zz1    equ dword[ebp-44]
  35. .zz2    equ dword[ebp-48]
  36.  
  37.         mov     ebp,esp
  38.  
  39.         push    edx            ; store edx in variable .col
  40.       .sort2:
  41.         cmp     ax,bx
  42.         jle     .sort1
  43.         xchg    eax,ebx
  44.         mov     dx,.z1
  45.         xchg    dx,.z2
  46.         mov     .z1,dx
  47.       .sort1:
  48.         cmp     bx,cx
  49.         jle     .sort3
  50.         xchg    ebx,ecx
  51.         mov     dx,.z2
  52.         xchg    dx,.z3
  53.         mov     .z2,dx
  54.         jmp     .sort2
  55.       .sort3:
  56.         push    eax            ; store triangle coordinates in user friendly variables
  57.         push    ebx
  58.         push    ecx
  59.          mov      edx,80008000h  ; eax,ebx,ecx are ANDd together into edx which means that
  60.          and      edx,ebx        ; if *all* of them are negative a sign flag is raised
  61.          and      edx,ecx
  62.          and      edx,eax
  63.          test     edx,80008000h  ; Check both X&Y at once
  64.          jne      .ft_loop2_end
  65.        ;  cmp      ax,SIZE_Y
  66.        ;  jle      @f
  67.        ;  cmp      bx,SIZE_Y
  68.        ;  jle      @f
  69.        ;  cmp      cx,SIZE_Y
  70.        ;  jge      @f
  71.        ;  ror      eax,16
  72.        ;  ror      ebx,16
  73.        ;  ror      ecx,16
  74.        ;  cmp      ax,SIZE_X
  75.        ;  jle      @f
  76.        ;  cmp      bx,SIZE_X
  77.        ;  jle      @f
  78.        ;  cmp      cx,SIZE_X
  79.        ;  jle      @f
  80.        ;  jmp      .ft_loop2_end
  81.        ;@@:
  82.   ;      sub     esp,52-12
  83.  
  84.         mov     bx,.y2       ; calc delta 12
  85.         sub     bx,.y1
  86.         jnz     .ft_dx12_make
  87.         push    dword 0
  88.         push    dword 0
  89.         jmp     .ft_dx12_done
  90.    .ft_dx12_make:
  91.         mov     ax,.x2
  92.         sub     ax,.x1
  93.         cwde
  94.         movsx   ebx,bx
  95.         shl     eax,ROUND
  96.         cdq
  97.         idiv    ebx
  98.         push    eax
  99.  
  100.         mov     ax,.z2
  101.         sub     ax,.z1
  102.         cwde
  103.         shl     eax,CATMULL_SHIFT
  104.         cdq
  105.         idiv    ebx
  106.         push    eax
  107.   .ft_dx12_done:
  108.         mov     bx,.y3       ; calc delta 13
  109.         sub     bx,.y1
  110.         jnz     .ft_dx13_make
  111.         push    dword 0
  112.         push    dword 0
  113.         jmp     .ft_dx13_done
  114.    .ft_dx13_make:
  115.         mov     ax,.x3
  116.         sub     ax,.x1
  117.         cwde
  118.         movsx   ebx,bx
  119.         shl     eax,ROUND
  120.         cdq
  121.         idiv    ebx
  122.         push    eax
  123.  
  124.         mov     ax,.z3
  125.         sub     ax,.z1
  126.         cwde
  127.         shl     eax,CATMULL_SHIFT
  128.         cdq
  129.         idiv    ebx
  130.         push    eax
  131.  
  132.     .ft_dx13_done:
  133.     ;    sub     esp,48
  134.         mov     bx,.y3       ; calc delta 23
  135.         sub     bx,.y2
  136.         jnz     .gt_dx23_make
  137.         push    dword 0
  138.         push    dword 0
  139.     ;    mov     .dx23,0
  140.     ;    mov     .dz23,0
  141.         jmp     .gt_dx23_done
  142.    .gt_dx23_make:
  143.         mov     ax,.x3
  144.         sub     ax,.x2
  145.         cwde
  146.         movsx   ebx,bx
  147.         shl     eax,ROUND
  148.         cdq
  149.         idiv    ebx
  150.         push    eax
  151.  
  152.         mov     ax,.z3
  153.         sub     ax,.z2
  154.         cwde
  155.         shl     eax,CATMULL_SHIFT
  156.         cdq
  157.         idiv    ebx
  158.         push    eax
  159.     ;    mov     .dz23,eax
  160.     .gt_dx23_done:
  161.  
  162.         movsx   edx,.z1
  163.         shl     edx,CATMULL_SHIFT
  164.         push    edx
  165.         push    edx
  166.  
  167.         movsx   eax,.x1
  168.         shl     eax,ROUND    ; eax - x1
  169.         mov     ebx,eax      ; ebx - x2
  170.         mov     cx,.y1
  171.         cmp     cx,.y2
  172.         jge     .ft_loop1_end
  173.      .ft_loop1:
  174.  
  175.         pushad
  176.  
  177.         push    .col
  178.         push    cx          ; y
  179.         sar     ebx,ROUND
  180.         push    bx          ; x2
  181.         sar     eax,ROUND
  182.         push    ax          ; x1
  183.         push    .zz2        ; z2 shl CATMULL_SHIFT
  184.         push    .zz1        ; z1 shl CATMULL_SHIFT
  185.  
  186.         call    flat_line_z
  187.  
  188.         popad
  189.  
  190.         add     eax,.dx13
  191.         add     ebx,.dx12
  192.  
  193.         mov     edx,.dz13
  194.         add     .zz1,edx
  195.         mov     edx,.dz12
  196.         add     .zz2,edx
  197. ;end if
  198.         inc     cx
  199.         cmp     cx,.y2
  200.         jl      .ft_loop1
  201.     .ft_loop1_end:
  202.  
  203.         movsx   edx,.z2
  204.         shl     edx,CATMULL_SHIFT
  205.         mov     .zz2,edx
  206.         movsx   ebx,.x2
  207.         shl     ebx,ROUND
  208.  
  209.         mov     cx,.y2
  210.         cmp     cx,.y3
  211.         jge     .ft_loop2_end
  212.      .ft_loop2:
  213.         pushad
  214.  
  215.         push    .col
  216.         push    cx
  217.         sar     ebx,ROUND
  218.         push    bx
  219.         sar     eax,ROUND
  220.         push    ax          ; x1
  221.  
  222.         push    .zz2        ; z2 shl CATMULL_SHIFT
  223.         push    .zz1        ; z1 shl CATMULL_SHIFT
  224.  
  225.         call    flat_line_z
  226.  
  227.         popad
  228.  
  229.         add     eax,.dx13
  230.         add     ebx,.dx23
  231.  
  232.         mov     edx,.dz13
  233.         add     .zz1,edx
  234.         mov     edx,.dz23
  235.         add     .zz2,edx
  236.  
  237.         inc     cx
  238.         cmp     cx,.y3
  239.         jl      .ft_loop2
  240.      .ft_loop2_end:
  241.  
  242.         mov esp,ebp
  243. ret 6
  244.  
  245. flat_line_z:
  246. ;----------------
  247. ;-------------in edi - pointer to screen buffer ----------------------------------
  248. ;--------------- esi - pointer to z-buffer (each Z varible dword)-----------------
  249. ;----------stack - (each z coordinate shifted shl CATMULL_SHIFT)------------------
  250. .z1 equ dword [ebp+4]
  251. .z2 equ dword [ebp+8]
  252. .x1 equ word  [ebp+12]
  253. .x2 equ word  [ebp+14]
  254. .y  equ word  [ebp+16]
  255. .col equ dword [ebp+18]
  256.  
  257. .dz equ dword [ebp-4]
  258.  
  259.      mov        ebp,esp
  260. ;;     sub        esp,4
  261.      mov        ax,.y
  262.      or         ax,ax
  263.      jl         .fl_quit
  264.      mov        bx,[size_y_var]
  265.      dec        bx
  266.      cmp        ax,bx ;[size_y_var]
  267.   ;   cmp        ax,SIZE_Y-1
  268.      jg         .fl_quit
  269.  
  270.  ;    cmp        .x1,0
  271.  ;    jge        .fl_ok1
  272.  ;    cmp        .x2,0
  273.  ;    jl         .fl_quit
  274.  ;  .fl_ok1:
  275.  ;    cmp        .x1,SIZE_X
  276.  ;    jle        .fl_ok2
  277.  ;    cmp        .x2,SIZE_X
  278.  ;    jg         .fl_quit
  279.  ;  .fl_ok2:
  280.      mov        ax,.x1
  281.      cmp        ax,.x2
  282.      je         .fl_quit
  283.      jl         .fl_ok
  284.  
  285.      xchg       ax,.x2
  286.      mov        .x1,ax
  287.      mov        edx,.z1
  288.      xchg       edx,.z2
  289.      mov        .z1,edx
  290.    .fl_ok:
  291.      mov        bx,[size_x_var]
  292.      dec        bx
  293.      cmp        .x1,bx ;SIZE_X-1
  294.      jg         .fl_quit
  295.      cmp        .x2,0
  296.      jle        .fl_quit
  297.  
  298.      mov        eax,.z2
  299.      sub        eax,.z1
  300.      cdq
  301.      mov        bx,.x2
  302.      sub        bx,.x1
  303.      movsx      ebx,bx
  304.      idiv       ebx
  305. ;;     mov        .dz,eax                ; calculated delta - shifted .dz
  306.      push       eax
  307.  
  308.      cmp        .x1,0
  309.      jge        @f
  310.      movsx      ebx,.x1
  311.      neg        ebx
  312.      imul       ebx
  313.      add        .z1,eax
  314.      mov        .x1,0
  315.     @@:
  316.      movzx      edx,word[size_x_var]
  317.      cmp        .x2,dx ;[size_x_var] ;SIZE_X
  318.      jl         @f
  319.      mov        .x2,dx ;[size_x_var] ;SIZE_X
  320.     @@:
  321.  ;    movzx      edx,[size_x_var] ;SIZE_X
  322.      movsx      eax,.y
  323.      mul        edx                  ; edi = edi + (SIZE_X * y + x1)*3
  324.      movsx      edx,.x1
  325.      add        eax,edx
  326.      push       eax
  327.      lea        eax,[eax*3]
  328.      add        edi,eax              ; esi = esi + (SIZE_X * y + x1)*4
  329.      pop        eax
  330.      shl        eax,2
  331.      add        esi,eax
  332.  
  333.      mov        cx,.x2
  334.      sub        cx,.x1
  335.      movzx      ecx,cx
  336.  
  337.      mov        eax,.col
  338.      mov        ebx,.z1  ; ebx : curr. z
  339.      mov        edx,.dz
  340.      dec        ecx
  341.      jecxz      .draw_last
  342.    .ddraw:
  343.      cmp        ebx,dword[esi]
  344.   ;   cmovl      [edi],eax
  345.   ;   cmovl      [esi],ebx
  346.      jge        @f
  347.      mov        [edi],eax
  348.      mov        [esi],ebx
  349.   ;   stosd          ; less branches
  350.   ;   dec        edi
  351.   ;   mov        dword[esi],ebx
  352.   ;   jmp        .no_skip
  353.    @@:
  354.      add        edi,3
  355.   ; .no_skip:
  356.      add        esi,4
  357.      add        ebx,edx
  358.      loop       .ddraw
  359.  
  360.    .draw_last:
  361.      cmp        ebx,dword[esi]
  362.      jge        .fl_quit
  363.      stosw
  364.      shr        eax,16
  365.      stosb
  366.      mov        dword[esi],ebx
  367.  
  368.    .fl_quit:
  369.  
  370.      mov   esp,ebp
  371. ret 18
  372.