Subversion Repositories Kolibri OS

Rev

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

  1. ;------- Big thanks to majuma (www.majuma.xt.pl) for absolutelly great--
  2. ;------- 13h mode demos ------------------------------------------------
  3.  
  4. bump_triangle:
  5. ;------------------in - eax - x1 shl 16 + y1 -----------
  6. ;---------------------- ebx - x2 shl 16 + y2 -----------
  7. ;---------------------- ecx - x3 shl 16 + y3 -----------
  8. ;---------------------- edx - pointer to bump map ------
  9. ;---------------------- esi - pointer to environment map
  10. ;---------------------- edi - pointer to screen buffer--
  11. ;---------------------- stack : bump coordinates--------
  12. ;----------------------         environment coordinates-
  13. .b_x1 equ ebp+4     ; procedure don't save registers !!!
  14. .b_y1 equ ebp+6     ; each coordinate as word
  15. .b_x2 equ ebp+8
  16. .b_y2 equ ebp+10
  17. .b_x3 equ ebp+12
  18. .b_y3 equ ebp+14
  19. .e_x1 equ ebp+16
  20. .e_y1 equ ebp+18
  21. .e_x2 equ ebp+20
  22. .e_y2 equ ebp+22
  23. .e_x3 equ ebp+24
  24. .e_y3 equ ebp+26
  25.  
  26. .t_bmap equ dword[ebp-4]
  27. .t_emap equ dword[ebp-8]
  28. .x1     equ word[ebp-10]
  29. .y1     equ word[ebp-12]
  30. .x2     equ word[ebp-14]
  31. .y2     equ word[ebp-16]
  32. .x3     equ word[ebp-18]
  33. .y3     equ word[ebp-20]
  34.  
  35. .dx12  equ dword[ebp-24]
  36. .dbx12 equ dword[ebp-28]
  37. .dby12 equ dword[ebp-32]
  38. .dex12 equ dword[ebp-36]
  39. .dey12 equ dword[ebp-40]
  40.  
  41. .dx13  equ dword[ebp-44]
  42. .dbx13 equ dword[ebp-48]
  43. .dby13 equ dword[ebp-52]
  44. .dex13 equ dword[ebp-56]
  45. .dey13 equ dword[ebp-60]
  46.  
  47. .dx23  equ dword[ebp-64]
  48. .dbx23 equ dword[ebp-68]
  49. .dby23 equ dword[ebp-72]
  50. .dex23 equ dword[ebp-76]
  51. .dey23 equ dword[ebp-80]
  52.  
  53. .cx1   equ dword[ebp-84]   ; current variables
  54. .cx2   equ dword[ebp-88]
  55. .cbx1  equ dword[ebp-92]
  56. .cbx2  equ dword[ebp-96]
  57. .cby1  equ dword[ebp-100]
  58. .cby2  equ dword[ebp-104]
  59. .cex1  equ dword[ebp-108]
  60. .cex2  equ dword[ebp-112]
  61. .cey1  equ dword[ebp-116]
  62. .cey2  equ dword[ebp-120]
  63.  
  64.        mov     ebp,esp
  65.        push    edx        ; store bump map
  66.        push    esi        ; store e. map
  67.      ; sub     esp,120
  68.  .sort3:                  ; sort triangle coordinates...
  69.        cmp     ax,bx
  70.        jle     .sort1
  71.        xchg    eax,ebx
  72.        mov     edx,dword[.b_x1]
  73.        xchg    edx,dword[.b_x2]
  74.        mov     dword[.b_x1],edx
  75.        mov     edx,dword[.e_x1]
  76.        xchg    edx,dword[.e_x2]
  77.        mov     dword[.e_x1],edx
  78.  .sort1:
  79.        cmp      bx,cx
  80.        jle      .sort2
  81.        xchg     ebx,ecx
  82.        mov      edx,dword[.b_x2]
  83.        xchg     edx,dword[.b_x3]
  84.        mov      dword[.b_x2],edx
  85.        mov      edx,dword[.e_x2]
  86.        xchg     edx,dword[.e_x3]
  87.        mov      dword[.e_x2],edx
  88.        jmp      .sort3
  89.  .sort2:
  90.        push     eax     ; store triangle coords in variables
  91.        push     ebx
  92.        push     ecx
  93.  
  94.        mov     edx,eax         ; eax,ebx,ecx are ORd together into edx which means that
  95.        or      edx,ebx         ; if any *one* of them is negative a sign flag is raised
  96.        or      edx,ecx
  97.        test    edx,80000000h   ; Check only X
  98.        jne     .loop23_done
  99.  
  100.        cmp     .x1,SIZE_X    ; {
  101.        jg      .loop23_done
  102.        cmp     .x2,SIZE_X     ; This can be optimized with effort
  103.        jg      .loop23_done
  104.        cmp     .x3,SIZE_X
  105.        jg      .loop23_done    ; {
  106.  
  107.  
  108.        mov      bx,.y2       ; calc delta 12
  109.        sub      bx,.y1
  110.        jnz      .bt_dx12_make
  111.        mov      ecx,5
  112.        xor      edx,edx
  113.      @@:
  114.        push     edx   ;dword 0
  115.        loop     @b
  116.        jmp      .bt_dx12_done
  117.  .bt_dx12_make:
  118.        mov      ax,.x2
  119.        sub      ax,.x1
  120.        cwde
  121.        movsx    ebx,bx
  122.        shl      eax,ROUND
  123.        cdq
  124.        idiv     ebx
  125.  ;      mov      .dx12,eax
  126.        push      eax
  127.  
  128.        mov      ax,word[.b_x2]
  129.        sub      ax,word[.b_x1]
  130.        cwde
  131.        shl      eax,ROUND
  132.        cdq
  133.        idiv     ebx
  134.  ;      mov      .dbx12,eax
  135.        push      eax
  136.  
  137.        mov      ax,word[.b_y2]
  138.        sub      ax,word[.b_y1]
  139.        cwde
  140.        shl      eax,ROUND
  141.        cdq
  142.        idiv     ebx
  143.  ;      mov      .dby12,eax
  144.        push      eax
  145.  
  146.        mov      ax,word[.e_x2]
  147.        sub      ax,word[.e_x1]
  148.        cwde
  149.        shl      eax,ROUND
  150.        cdq
  151.        idiv     ebx
  152.  ;      mov      .dex12,eax
  153.        push      eax
  154.  
  155.        mov      ax,word[.e_y2]
  156.        sub      ax,word[.e_y1]
  157.        cwde
  158.        shl      eax,ROUND
  159.        cdq
  160.        idiv     ebx
  161.  ;      mov      .dey12,eax
  162.        push      eax
  163.    .bt_dx12_done:
  164.  
  165.        mov      bx,.y3       ; calc delta13
  166.        sub      bx,.y1
  167.        jnz      .bt_dx13_make
  168.        mov      ecx,5
  169.        xor      edx,edx
  170.      @@:
  171.        push     edx   ;dword 0
  172.        loop     @b
  173.        jmp      .bt_dx13_done
  174.  .bt_dx13_make:
  175.        mov      ax,.x3
  176.        sub      ax,.x1
  177.        cwde
  178.        movsx    ebx,bx
  179.        shl      eax,ROUND
  180.        cdq
  181.        idiv     ebx
  182.  ;      mov      .dx13,eax
  183.        push      eax
  184.  
  185.        mov      ax,word[.b_x3]
  186.        sub      ax,word[.b_x1]
  187.        cwde
  188.        shl      eax,ROUND
  189.        cdq
  190.        idiv     ebx
  191.  ;      mov      .dbx13,eax
  192.        push      eax
  193.  
  194.        mov      ax,word[.b_y3]
  195.        sub      ax,word[.b_y1]
  196.        cwde
  197.        shl      eax,ROUND
  198.        cdq
  199.        idiv     ebx
  200.  ;      mov      .dby13,eax
  201.        push      eax
  202.  
  203.        mov      ax,word[.e_x3]
  204.        sub      ax,word[.e_x1]
  205.        cwde
  206.        shl      eax,ROUND
  207.        cdq
  208.        idiv     ebx
  209.  ;      mov      .dex13,eax
  210.        push      eax
  211.  
  212.        mov      ax,word[.e_y3]
  213.        sub      ax,word[.e_y1]
  214.        cwde
  215.        shl      eax,ROUND
  216.        cdq
  217.        idiv     ebx
  218.  ;      mov      .dey13,eax
  219.        push      eax
  220.    .bt_dx13_done:
  221.  
  222.        mov      bx,.y3       ; calc delta23
  223.        sub      bx,.y2
  224.        jnz      .bt_dx23_make
  225.        mov      ecx,5
  226.        xor      edx,edx
  227.      @@:
  228.        push     edx   ;dword 0
  229.        loop     @b
  230.        jmp      .bt_dx23_done
  231.  .bt_dx23_make:
  232.        mov      ax,.x3
  233.        sub      ax,.x2
  234.        cwde
  235.        movsx    ebx,bx
  236.        shl      eax,ROUND
  237.        cdq
  238.        idiv     ebx
  239.  ;      mov      .dx23,eax
  240.        push      eax
  241.  
  242.        mov      ax,word[.b_x3]
  243.        sub      ax,word[.b_x2]
  244.        cwde
  245.        shl      eax,ROUND
  246.        cdq
  247.        idiv     ebx
  248.  ;      mov      .dbx23,eax
  249.        push      eax
  250.  
  251.        mov      ax,word[.b_y3]
  252.        sub      ax,word[.b_y2]
  253.        cwde
  254.        shl      eax,ROUND
  255.        cdq
  256.        idiv     ebx
  257.  ;      mov      .dby23,eax
  258.        push      eax
  259.  
  260.        mov      ax,word[.e_x3]
  261.        sub      ax,word[.e_x2]
  262.        cwde
  263.        shl      eax,ROUND
  264.        cdq
  265.        idiv     ebx
  266.  ;      mov      .dex23,eax
  267.        push      eax
  268.  
  269.        mov      ax,word[.e_y3]
  270.        sub      ax,word[.e_y2]
  271.        cwde
  272.        shl      eax,ROUND
  273.        cdq
  274.        idiv     ebx
  275.  ;      mov      .dey23,eax
  276.        push      eax
  277.  
  278.       ;  sub     esp,40
  279.    .bt_dx23_done:
  280.  
  281.        movsx    eax,.x1
  282.        shl      eax,ROUND
  283.      ; mov      .cx1,eax
  284.      ; mov      .cx2,eax
  285.        push     eax
  286.        push     eax
  287.  
  288.        movsx    eax,word[.b_x1]
  289.        shl      eax,ROUND
  290.      ; mov      .cbx1,eax
  291.      ; mov      .cbx2,eax
  292.        push     eax
  293.        push     eax
  294.  
  295.        movsx    eax,word[.b_y1]
  296.        shl      eax,ROUND
  297.      ; mov      .cby1,eax
  298.      ; mov      .cby2,eax
  299.        push     eax
  300.        push     eax
  301.  
  302.        movsx    eax,word[.e_x1]
  303.        shl      eax,ROUND
  304.       ;mov      .cex1,eax
  305.       ;mov      .cex2,eax
  306.        push     eax
  307.        push     eax
  308.  
  309.        movsx    eax,word[.e_y1]
  310.        shl      eax,ROUND
  311.       ;mov      .cey1,eax
  312.       ;mov      .cey2,eax
  313.        push     eax
  314.        push     eax
  315.  
  316.        movzx    ecx,.y1
  317.        cmp      cx,.y2
  318.        jge      .loop12_done
  319.   .loop12:
  320.        call     .call_bump_line
  321.  
  322.        mov      eax,.dx13
  323.        add      .cx1,eax
  324.        mov      eax,.dx12
  325.        add      .cx2,eax
  326.  
  327.        mov      eax,.dbx13
  328.        add      .cbx1,eax
  329.        mov      eax,.dbx12
  330.        add      .cbx2,eax
  331.        mov      eax,.dby13
  332.        add      .cby1,eax
  333.        mov      eax,.dby12
  334.        add      .cby2,eax
  335.  
  336.        mov      eax,.dex13
  337.        add      .cex1,eax
  338.        mov      eax,.dex12
  339.        add      .cex2,eax
  340.        mov      eax,.dey13
  341.        add      .cey1,eax
  342.        mov      eax,.dey12
  343.        add      .cey2,eax
  344.  
  345.        inc      ecx
  346.        cmp      cx,.y2
  347.        jl       .loop12
  348.    .loop12_done:
  349.        movzx    ecx,.y2
  350.        cmp      cx,.y3
  351.        jge      .loop23_done
  352.  
  353.        movzx    eax,.x2
  354.        shl      eax,ROUND
  355.        mov      .cx2,eax
  356.  
  357.        movzx    eax,word[.b_x2]
  358.        shl      eax,ROUND
  359.        mov      .cbx2,eax
  360.  
  361.        movzx    eax,word[.b_y2]
  362.        shl      eax,ROUND
  363.        mov      .cby2,eax
  364.  
  365.        movzx    eax,word[.e_x2]
  366.        shl      eax,ROUND
  367.        mov      .cex2,eax
  368.  
  369.        movzx    eax,word[.e_y2]
  370.        shl      eax,ROUND
  371.        mov      .cey2,eax
  372.  
  373.      .loop23:
  374.        call     .call_bump_line
  375.  
  376.        mov      eax,.dx13
  377.        add      .cx1,eax
  378.        mov      eax,.dx23
  379.        add      .cx2,eax
  380.  
  381.        mov      eax,.dbx13
  382.        add      .cbx1,eax
  383.        mov      eax,.dbx23
  384.        add      .cbx2,eax
  385.        mov      eax,.dby13
  386.        add      .cby1,eax
  387.        mov      eax,.dby23
  388.        add      .cby2,eax
  389.  
  390.        mov      eax,.dex13
  391.        add      .cex1,eax
  392.        mov      eax,.dex23
  393.        add      .cex2,eax
  394.        mov      eax,.dey13
  395.        add      .cey1,eax
  396.        mov      eax,.dey23
  397.        add      .cey2,eax
  398.  
  399.        inc      ecx
  400.        cmp      cx,.y3
  401.        jl       .loop23
  402.     .loop23_done:
  403.        mov      esp,ebp
  404. ret   24
  405.  
  406. .call_bump_line:
  407.  
  408.       ; push     ebp
  409.       ; push     ecx
  410.        pushad
  411.  
  412.        push     .t_emap
  413.        push     .t_bmap
  414.        push     .cey2
  415.        push     .cex2
  416.        push     .cey1
  417.        push     .cex1
  418.        push     .cby2
  419.        push     .cbx2
  420.        push     .cby1
  421.        push     .cbx1
  422.        push     ecx
  423.  
  424.        mov      eax,.cx1
  425.        sar      eax,ROUND
  426.        mov      ebx,.cx2
  427.        sar      ebx,ROUND
  428.  
  429.        call     bump_line
  430.  
  431.        popad
  432. ret
  433. bump_line:
  434. ;--------------in: eax - x1
  435. ;--------------    ebx - x2
  436. ;--------------    edi - pointer to screen buffer
  437. ;stack - another parameters :
  438. .y    equ dword [ebp+4]
  439. .bx1  equ       [ebp+8]   ;   ---
  440. .by1  equ dword [ebp+12]  ;       |
  441. .bx2  equ       [ebp+16]  ;       |
  442. .by2  equ dword [ebp+20]  ;       |>   bump and env coords
  443. .ex1  equ       [ebp+24]  ;       |>   shifted shl ROUND
  444. .ey1  equ dword [ebp+28]  ;       |
  445. .ex2  equ       [ebp+32]  ;       |
  446. .ey2  equ dword [ebp+36]  ;   ---
  447. .bmap equ dword [ebp+40]
  448. .emap equ dword [ebp+44]
  449.  
  450. .x1   equ dword [ebp-4]
  451. .x2   equ dword [ebp-8]
  452. .dbx  equ dword [ebp-12]
  453. .dby  equ       [ebp-16]
  454. .dex  equ dword [ebp-20]
  455. .dey  equ       [ebp-24]
  456. .cbx  equ dword [ebp-28]
  457. .cby  equ       [ebp-32]
  458. .cex  equ dword [ebp-36]
  459. .cey  equ       [ebp-40]
  460.         mov     ebp,esp
  461.  
  462.         mov     ecx,.y
  463.         or      ecx,ecx
  464.         jl      .bl_end
  465.         cmp     ecx,SIZE_Y
  466.         jge     .bl_end
  467.  
  468.         cmp     eax,ebx
  469.         jl      .bl_ok
  470.         je      .bl_end
  471.  
  472.         xchg    eax,ebx
  473. if Ext = NON
  474.         mov     edx,.bx1
  475.         xchg    edx,.bx2
  476.         mov     .bx1,edx
  477.         mov     edx,.by1
  478.         xchg    edx,.by2
  479.         mov     .by1,edx
  480.  
  481.         mov     edx,.ex1
  482.         xchg    edx,.ex2
  483.         mov     .ex1,edx
  484.         mov     edx,.ey1
  485.         xchg    edx,.ey2
  486.         mov     .ey1,edx
  487. else
  488.         movq    mm0,.bx1
  489.         movq    mm1,.bx2
  490.         movq    mm2,.ex1
  491.         movq    mm3,.ex2
  492.         movq    .bx2,mm0
  493.         movq    .bx1,mm1
  494.         movq    .ex1,mm3
  495.         movq    .ex2,mm2
  496. end if
  497.   .bl_ok:
  498.         push    eax
  499.         push    ebx           ;store x1, x2
  500.  
  501.         mov     eax,SIZE_X*3
  502.         mov     ebx,.y
  503.         mul     ebx
  504.         mov     ecx,.x1
  505.         lea     ecx,[ecx*3]
  506.         add     eax,ecx
  507.         add     edi,eax
  508.  
  509.         mov     ecx,.x2
  510.         sub     ecx,.x1
  511.  
  512.         mov     eax,.bx2       ; calc .dbx
  513.         sub     eax,.bx1
  514.         cdq
  515.         idiv    ecx
  516.         push    eax
  517.  
  518.         mov     eax,.by2       ; calc .dby
  519.         sub     eax,.by1
  520.         cdq
  521.         idiv    ecx
  522.         push    eax
  523.  
  524.         mov     eax,.ex2       ; calc .dex
  525.         sub     eax,.ex1
  526.         cdq
  527.         idiv    ecx
  528.         push    eax
  529.  
  530.         mov     eax,.ey2       ; calc .dey
  531.         sub     eax,.ey1
  532.         cdq
  533.         idiv    ecx
  534.         push    eax
  535.  
  536.         push    dword .bx1
  537.         push    .by1
  538.         push    dword .ex1
  539.         push    .ey1
  540.      .draw:
  541.     ; if TEX = SHIFTING   ;bump drawing only in shifting mode
  542.  
  543.         mov     eax,.cby
  544.         sar     eax,ROUND
  545.         shl     eax,TEX_SHIFT
  546.         mov     esi,.cbx
  547.         sar     esi,ROUND
  548.         add     esi,eax
  549.  
  550.         mov     ebx,esi
  551.         dec     ebx
  552.         and     ebx,TEXTURE_SIZE
  553.         add     ebx,.bmap
  554.         movzx   eax,byte [ebx]
  555.  
  556.         mov     ebx,esi
  557.         inc     ebx
  558.         and     ebx,TEXTURE_SIZE
  559.         add     ebx,.bmap
  560.         movzx   ebx,byte [ebx]
  561.         sub     eax,ebx
  562.  
  563.         mov     ebx,esi
  564.         sub     ebx,TEX_X
  565.         and     ebx,TEXTURE_SIZE
  566.         add     ebx,.bmap
  567.         movzx   edx,byte [ebx]
  568.  
  569.         mov     ebx,esi
  570.         add     ebx,TEX_X
  571.         and     ebx,TEXTURE_SIZE
  572.         add     ebx,.bmap
  573.         movzx   ebx,byte [ebx]
  574.         sub     edx,ebx
  575.  
  576.         mov     ebx,.cex       ;.cex - current env map X
  577.         sar     ebx,ROUND
  578.         add     eax,ebx        ; eax - modified x coord
  579.  
  580.         mov     ebx,.cey       ;.cey - current  env map y
  581.         sar     ebx,ROUND
  582.         add     edx,ebx        ; edx - modified y coord
  583.  
  584.         or      eax,eax
  585.         jl      .black
  586.         cmp     eax,TEX_X
  587.         jg      .black
  588.         or      edx,edx
  589.         jl      .black
  590.         cmp     edx,TEX_Y
  591.         jg      .black
  592.  
  593.         shl     edx,TEX_SHIFT
  594.         add     edx,eax
  595.         lea     edx,[edx*3]
  596.         add     edx,.emap
  597.         mov     eax,dword[edx]
  598.         jmp     .put_pixel
  599.      .black:
  600.         xor     eax,eax
  601.      .put_pixel:
  602.         stosd
  603.         dec     edi
  604. ;if Ext >= MMX
  605. ;        movq    mm0,.cby
  606. ;        movq    mm1,.cey
  607. ;        paddd   mm0,.dby
  608. ;        paddd   mm1,.dey
  609. ;        movq    .cby,mm0
  610. ;        movq    .cey,mm1
  611. ;else
  612.         mov     eax,.dbx
  613.         add     .cbx,eax
  614.         mov     eax,.dby
  615.         add     .cby,eax
  616.         mov     eax,.dex
  617.         add     .cex,eax
  618.         mov     eax,.dey
  619.         add     .cey,eax
  620. ;end if
  621.         dec     ecx
  622.         jnz     .draw
  623.    ;   end if
  624.   .bl_end:
  625.         mov     esp,ebp
  626. ret 44