Subversion Repositories Kolibri OS

Rev

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