Subversion Repositories Kolibri OS

Rev

Rev 8719 | Rev 9512 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2.  
  3. if Ext > SSE2
  4.  ;--------------------------------------------------------------------
  5. init_point_lights:
  6.   ;      mov       eax,1000
  7.   ;      cvtsi2ss  xmm1,eax
  8.   ;      shufps    xmm1,xmm1,11000000b
  9.   ;      mov       esi,lights_aligned
  10.   ;      mov       edi,point_light_coords
  11.   ;      mov       ecx,3
  12.   ;    @@:
  13.   ;      movaps    xmm0,[esi]
  14.   ;      addps     xmm0,[f05xz]
  15.   ;      mulps     xmm0,xmm1
  16.   ;      movaps    [edi],xmm0
  17.   ;      add       esi,64
  18.    ;     add       edi,16
  19.    ;     loop      @b
  20.       mov       ecx,3
  21.       mov       edi,point_light_coords
  22.     @@:
  23.       push      ecx
  24.       xor       ecx,ecx
  25.       movzx     edx,word[size_x_var]
  26.       call      random
  27.       cvtsi2ss  xmm0,eax
  28.       movss     [edi],xmm0
  29.       xor       ecx,ecx
  30.       movzx     edx,word[size_x_var]
  31.       call      random
  32.       cvtsi2ss  xmm0,eax
  33.       movss     [edi+4],xmm0
  34.    ;   movzx     ebx,word[size_x_var]
  35.    ;   shl       ebx,2
  36.    ;   neg       ebx
  37.       mov       ecx,-1900
  38.    ;   sub       ecx,100
  39.       mov       edx,-600
  40.       call      random
  41.       cvtsi2ss  xmm0,eax
  42.       movss     [edi+8],xmm0
  43.    ;   mov       dword[edi+8],-1700.0
  44.       mov       [edi+12],dword 0
  45.       add       edi,16
  46.       pop       ecx
  47.       loop      @b
  48.  
  49. ret
  50.  
  51. ;------------------------------------------------------------------
  52. intersect_tri: ; Moeller-Trumbore method
  53. ; in:
  54. ;     xmm0 - ray direction  ; should be normalized
  55. ;     xmm1 - ray orgin
  56. ;     xmm2 - tri vert1
  57. ;     xmm3 - tri vert2
  58. ;     xmm4 - tri vert3
  59. ;     if  eax = 1 - intersction with edge
  60. ;        xmm6 - edge lenght
  61. ;     if  eax = 0 - intersect with ray (classic)
  62. ; out:
  63. ;     eax  = 1 - intersection occured
  64. ;     xmm0 - float lo -> hi = t, v, u, ...
  65.       push    ebp
  66.       mov     ebp,esp
  67.       and     ebp,-16
  68.       sub     esp,220
  69.  
  70.        .dir    equ [ebp-16]
  71.        .origin equ [ebp-32]
  72.        .ta     equ [ebp-48]
  73.        .tb     equ [ebp-64]
  74.        .tc     equ [ebp-80]
  75.        .tvec   equ [ebp-96]
  76.        .pvec   equ [ebp-112]
  77.        .qvec   equ [ebp-128]
  78.        .e1     equ [ebp-128-16]
  79.        .ift    equ dword[ebp-152]
  80.        .invdet equ [ebp-156]
  81.        .det    equ [ebp-160]
  82.        .ed_l   equ [ebp-164]
  83.        .u      equ [ebp-168]
  84.        .v      equ [ebp-172]
  85.        .t      equ [ebp-176]
  86.        .e2     equ [ebp-192]
  87.  
  88.       movaps   .dir,xmm0
  89.       movaps   .origin,xmm1
  90.       movaps   .ta,xmm2
  91.       movaps   .tb,xmm3
  92.       movaps   .tc,xmm4
  93.       mov      .ift,eax
  94.       movss    .ed_l,xmm6
  95.       subps    xmm3,xmm2
  96.       subps    xmm4,xmm2
  97.       andps    xmm3,[zero_hgst_dd]
  98.       andps    xmm4,[zero_hgst_dd]
  99.       movaps   .e1,xmm3
  100.       movaps   .e2,xmm4
  101.  
  102.       lea      esi,.dir
  103.       lea      edi,.e2
  104.       lea      ebx,.pvec
  105.       call     cross_aligned
  106.  
  107.       movaps   xmm0,.e1
  108.       mulps    xmm0,.pvec
  109.  ;     andps    xmm0,[zero_hgst_dd]
  110.       haddps   xmm0,xmm0
  111.       haddps   xmm0,xmm0
  112.       movss    .det,xmm0
  113. ;      cmpnless xmm0,[eps]
  114. ;      movd     eax,xmm0
  115. ;      or       eax,eax
  116. ;      jz       @f
  117.       comiss   xmm0,[eps]
  118.       jl       @f
  119.  
  120.       rcpss    xmm0,.det
  121.       movss    .invdet,xmm0
  122.  
  123.       movaps   xmm0,.origin
  124.       subps    xmm0,.ta
  125.       andps    xmm0,[zero_hgst_dd]
  126.       movaps   .tvec,xmm0
  127.  
  128.       mulps    xmm0,.pvec
  129.       haddps   xmm0,xmm0
  130.       haddps   xmm0,xmm0
  131.       mulss    xmm0,.invdet
  132.       movss    xmm1,xmm0
  133.       movss    .u,xmm0
  134.       cmpnless xmm1,[epsone]
  135.       cmpnless xmm0,[epsminus]
  136.       pxor     xmm1,xmm0
  137.       movd     eax,xmm1
  138.       or       eax,eax
  139.       jz       @f
  140.  
  141.       lea      esi,.tvec
  142.       lea      edi,.e1
  143.       lea      ebx,.qvec
  144.       call     cross_aligned
  145.  
  146.       movaps   xmm0,.dir
  147.       mulps    xmm0,.qvec
  148.       haddps   xmm0,xmm0
  149.       haddps   xmm0,xmm0
  150.       mulss    xmm0,.invdet
  151.       movss    .v,xmm0
  152.       movss    xmm1,xmm0
  153.       addss    xmm1,.u
  154.       cmpnless xmm1,[epsone]
  155.       cmpnless xmm0,[epsminus]
  156.       pxor     xmm1,xmm0
  157.       movd     eax,xmm1
  158.       or       eax,eax
  159.       jz       @f
  160.  
  161.       movaps   xmm1,.e2
  162.       mulps    xmm1,.qvec
  163.       haddps   xmm1,xmm1
  164.       haddps   xmm1,xmm1
  165.       mulss    xmm1,.invdet
  166.       movss    .t,xmm1
  167.    ;   cmpnless xmm1,[eps]
  168.    ;   movmskps eax,xmm1
  169.    ;   test     eax,1
  170.    ;   jz       @f
  171.       comiss   xmm1,[eps]
  172.       jl       @f
  173.  
  174.       mov      eax,1
  175.       cmp      .ift,0
  176.       je       .end       ; ok intersect occured, no edge cause
  177.  
  178.       movss    xmm0,.t      ; else check with edge lenght
  179.     ;  movss    xmm1,.t
  180.       cmpnless xmm0,[eps]
  181.       cmpnless xmm1,.ed_l
  182.       xorps    xmm0,xmm1
  183.       movd     ebx,xmm0
  184.       or       ebx,ebx
  185.       jz       @f
  186.  
  187.  ;     mov      eax,1
  188.  ;     movaps   xmm0,.t
  189.       jmp      .end
  190.    @@:
  191.       xor      eax,eax
  192.     .end:
  193.       movaps   xmm0,.t
  194.       add      esp,220
  195.       pop      ebp
  196. ret
  197. end if
  198. ;===============================================================
  199. do_edges_list:
  200.     push    ebp
  201.     mov     ebp,esp
  202.     sub     esp,32
  203.  
  204.     .ed_cnt   equ [ebp-4]
  205.     .edd_ptr  equ [ebp-8]
  206.     .counter  equ [ebp-12]
  207.  
  208.  
  209.     mov     ebx,[edges_ptr]
  210.     mov     eax,[triangles_ptr]
  211.     mov     ecx,[triangles_count_var]
  212.   @@:
  213.     movdqu  xmm0,[eax]
  214.     movq    [ebx],xmm0
  215.     pshufd  xmm0,xmm0,11001001b
  216.     movq    [ebx+8],xmm0
  217.     pshufd  xmm0,xmm0,11001001b
  218.     movq    [ebx+16],xmm0
  219.     add     ebx,24
  220.     add     eax,12
  221.     loop    @b
  222.  
  223.  
  224.     mov     ebx,[edges_ptr]
  225.     mov     ecx,[triangles_count_var]
  226.     lea     ecx,[ecx*3]
  227.   .mxd:
  228.     mov     eax,[ebx]
  229.     cmp     eax,[ebx+4]
  230.     jl      @f
  231.     movq    xmm0,[ebx]
  232.     pshufd  xmm0,xmm0,11100001b
  233.     movq    [ebx],xmm0
  234.   @@:
  235.     add     ebx,8
  236.     loop    .mxd
  237.  
  238.  
  239.    ; insert sort
  240.    mov    ebx,[edges_ptr]
  241.    mov    ecx,[triangles_count_var]
  242.    lea    ecx,[ecx*3]
  243.  
  244.    mov    esi,ecx
  245.    shl    esi,3
  246.    add    esi,ebx
  247.  
  248.  .ccc:
  249.    mov    eax,[ebx+8]
  250.    cmp    eax,[ebx]
  251.    jge    .g
  252.    movq   xmm0,[ebx+8]
  253.    push   ebx
  254.  .c:
  255.    cmp    ebx,esi
  256.    jge    .done
  257.    cmp    ebx,[edges_ptr]
  258.    jl     .done
  259.    cmp    eax,[ebx]
  260.    jge    .done
  261.    movq   xmm7,[ebx]
  262.    movq   [ebx+8],xmm7
  263.    sub    ebx,8
  264.    jnz    .c
  265.    add    ebx,8
  266.  .done:
  267.    movq   [ebx+8],xmm0
  268.  .p:
  269.    pop    ebx
  270.  .g:
  271.    add    ebx,8
  272.    dec    ecx
  273.    cmp    ecx,1
  274.    jnz    .ccc
  275.  
  276.  
  277.   ; insert sort again
  278.    mov    ebx,[edges_ptr]
  279.    mov    ecx,[triangles_count_var]
  280.    lea    ecx,[ecx*3]
  281.    mov    esi,ecx
  282.    shl    esi,3
  283.    add    esi,ebx
  284.  
  285.  .count:
  286.    push   ecx
  287.    push   ebx
  288.    xor    ecx,ecx
  289.    mov    eax,[ebx]          ; count
  290.  .aa:
  291.    inc    ecx
  292.    add    ebx,8
  293.    cmp    ebx,esi
  294.    jge    .br         ; break
  295.    cmp    eax,[ebx]
  296.    je     .aa
  297.    mov    .counter,ecx
  298.    pop    ebx
  299.    mov    edi,ebx
  300.    sub    edi,8
  301.    mov    edx,[ebx+8]
  302.  .ccc2:
  303.  
  304.    cmp    ebx,esi
  305.    jbe    @f
  306.    add    esp,4
  307.    jmp    .ff
  308.  @@:
  309.    mov    eax,[ebx+12]
  310.    mov    edx,[ebx+8]
  311.    cmp    eax,[ebx+4]
  312.    jge    .gg2
  313.    movq   xmm0,[ebx+8]
  314.    push   ebx
  315.  .c2:
  316.    cmp    eax,[ebx+4]
  317.    jge    .done2
  318.    movq   xmm7,[ebx]
  319.    movq   [ebx+8],xmm7
  320.  
  321.    sub    ebx,8
  322.    cmp    ebx,edi
  323.    jz     @f
  324.    cmp    [ebx+8],edx
  325.    jz     .c2
  326.  @@:
  327.  .done2:
  328.    add    ebx,8
  329.    movq   [ebx],xmm0
  330.  
  331.  .p2:
  332.    pop    ebx
  333.  .gg2:
  334.    add    ebx,8
  335.    dec    ecx
  336.    cmp    ecx,1
  337.    jnz    .ccc2
  338.  
  339.    pop    ecx
  340.    sub    ecx,.counter
  341.    add    ebx,8
  342.    ja     .count
  343.  
  344.    jmp    .ff
  345.  .br: ;break
  346.    add   esp,8
  347.  .ff:
  348.  
  349.    ; count edges
  350.    mov    ecx,0
  351.    mov    edx,[triangles_count_var]
  352.    lea    edx,[edx*3]
  353.    mov    ebx,[edges_ptr]
  354. ;   mov    esi,edx
  355. ;   shl    esi,3
  356. ;   add    esi,[edges_ptr]
  357.  .nx:
  358.    movq    xmm0,[ebx]
  359.    add     ebx,8
  360. ;   cmp     ebx,esi
  361. ;   jae     @f
  362.    movq    xmm1,[ebx]
  363. ; @@:
  364.    pcmpeqd xmm0,xmm1
  365.    pmovmskb eax,xmm0
  366.    and     eax,0xff
  367.    cmp     eax,0xff
  368.    jz      @f
  369.    inc     ecx
  370.   @@:
  371.    dec     edx
  372.    jnz     .nx
  373.  
  374.  
  375.     mov     .ed_cnt,ecx
  376.     lea     ecx,[ecx*3]
  377.     shl     ecx,2
  378.     add     ecx,65536
  379.     mov     ebx,12
  380.     mov     eax,68
  381.     mov     edx,.edd_ptr
  382.     int     0x40                   ;  -> allocate memory to triangles
  383.     mov     .edd_ptr, eax   ;  -> eax = pointer to allocated mem
  384.  
  385.  
  386.  
  387.    mov      ebx,[edges_ptr]
  388.    mov      ecx,[triangles_count_var]
  389.    lea      ecx,[ecx*3]
  390.   .seek:
  391.    movq     xmm0,[ebx]
  392.    movq     xmm1,[ebx+8]
  393.    pcmpeqd  xmm1,xmm0
  394.    pmovmskb edx,xmm1
  395.    and      edx,0xff
  396.    cmp      edx,0xff
  397.    je       @f
  398.    movq     [eax],xmm0
  399.    add      eax,8
  400.  @@:
  401.    add      ebx,8
  402.    loop     .seek
  403.  
  404.    mov       eax,68
  405.    mov       ebx,13
  406.    mov       ecx,[edges_ptr]
  407.    int       0x40          ; release old edges ptr
  408.  
  409.  
  410.    mov      eax,.edd_ptr
  411.    mov      ecx,.ed_cnt
  412.    mov      [edges_ptr],eax
  413.    mov      [edges_count],ecx
  414.  
  415.    mov      esp,ebp
  416.    pop      ebp
  417. ret
  418.  
  419. ;=======================
  420.  
  421.  
  422. do_sinus:
  423. ;in - ax - render mode
  424.    .x      equ  [ebp-8]
  425.    .y      equ  [ebp-12]
  426.    .new_y  equ  [ebp-16]
  427.    .temp   equ  [ebp-20]
  428.    .dr_f   equ  word[ebp-22]
  429.  
  430.    push    ebp
  431.    mov     ebp,esp
  432.    sub     esp,30
  433.    mov     .dr_f,ax
  434.  
  435.    mov     dword .x,0
  436.    mov     dword .y,0
  437.    mov     esi,[screen_ptr]
  438.    mov     edi,[Zbuffer_ptr]
  439.    push    edi
  440.    ;  clear Zbuffer temporally used as image buffer
  441.    movzx   ecx,word[size_x_var]
  442.    movzx   eax,word[size_y_var]
  443.    imul    ecx,eax  ;SIZE_X*SIZE_Y
  444.    xor     eax,eax
  445.    cld
  446.    rep     stosd
  447.    pop     edi
  448.    fninit
  449.  .again:
  450.    fild    dword .x
  451.    fmul    [sin_frq]
  452.    fistp   dword .temp
  453.    mov     eax, .temp
  454.  
  455.    and     eax, 0x000000ff
  456.  
  457.    fld     dword [sin_tab+eax*4]
  458.    fimul   dword [sin_amplitude]
  459.    fiadd   dword .y
  460.    fistp   dword .new_y
  461.  
  462.    mov     eax,.new_y
  463.    or      eax,eax
  464.    jl      .skip
  465.    movzx   ebx,word[size_y_var]
  466.    cmp     eax,ebx  ;SIZE_Y
  467.    jg      .skip
  468.    movzx   edx,word[size_x_var]
  469.    mul     edx
  470.    add     eax,dword .x
  471.  
  472.    lea     ebx,[eax*3]
  473.    cmp     .dr_f,12 ; 32 bit col cause
  474.    jb      @f
  475.    add     ebx,eax
  476.   @@:
  477.    mov     eax,[esi]
  478.    mov     [edi+ebx],eax
  479.  .skip:
  480.    add     esi,3
  481.    cmp     .dr_f,12
  482.    jb      @f
  483.    inc     esi
  484.   @@:
  485.    inc     dword .x
  486.    movzx   edx,word[size_x_var]
  487.    cmp     dword .x,edx  ;SIZE_X
  488.    jl      .again
  489.    mov     dword .x,0
  490.    inc     dword .y
  491.    movzx   edx,word[size_y_var]
  492.    cmp     dword .y,edx   ;SIZE_Y
  493.    jl      .again
  494.  
  495.    ; copy from temporary buffer -> Zbuffer to screen
  496.    mov     esi,[Zbuffer_ptr]
  497.    mov     edi,[screen_ptr]
  498.    movzx   ecx,word[size_x_var]
  499.    movzx   eax,word[size_y_var]
  500.    imul    ecx,eax
  501.    cmp     .dr_f,12
  502.    jae     @f
  503.    lea     ecx,[ecx*3]
  504.    shr     ecx,2
  505.  ;  mov     ecx,SIZE_X*SIZE_Y*3/4
  506.   @@:
  507.    cld
  508.    rep     movsd
  509.  
  510.  
  511.    mov     esp,ebp
  512.    pop     ebp
  513. ret
  514.  
  515.  
  516. draw_dots:
  517.    mov     esi,[points_translated_ptr]
  518.    mov     ecx,[points_count_var]
  519.  .drw:
  520.  @@:
  521.    lodsd
  522.    add     esi,2           ; skip z
  523.    movzx   ebx,ax
  524.    shr     eax,16          ; bx = x , ax = y
  525.    or      ax,ax
  526.    jl      @f
  527.    or      bx,bx
  528.    jl      @f
  529.    cmp     ax,[size_y_var]  ;SIZE_Y
  530.    jge     @f
  531.    cmp     bx,[size_x_var]  ;SIZE_X
  532.    jge     @f
  533.    movzx   edx,word[size_x_var]  ;SIZE_X      ; SIZE_X not only power of 2   -> 256,512,...
  534.    mul     edx
  535.    add     eax,ebx
  536.    mov     edi,[screen_ptr]
  537.    lea     eax,[eax*3]
  538.    add     edi,eax
  539.    xor     eax,eax
  540.    not     eax
  541.    stosd
  542.  @@:
  543.    loop    .drw
  544.  
  545. ret
  546.  
  547. do_emboss:   ; sse2 version only
  548. ; in ax - render model
  549.    push  ebp
  550.    mov   ebp,esp
  551.    sub   esp,4
  552.  
  553.    .dr_mod  equ word[ebp-2]
  554.  
  555.    mov    .dr_mod,ax
  556.  
  557. if Ext >= SSE2
  558.  
  559.  
  560.  
  561.  movzx ecx,[bumps_deep_flag]
  562.  inc   ecx
  563.  call  blur_screen    ;blur n times
  564.  
  565.  mov   eax,[size_y_var]  ;load both x, y
  566.  mov   ebx,eax
  567.  shr   ebx,16
  568.  cwde
  569.  mul   ebx
  570.  mov   ecx,eax
  571.  sub   ecx,ebx
  572.  sub   ecx,ebx
  573.  mov   esi,[screen_ptr]
  574.  mov   edi,[Zbuffer_ptr]
  575.  cmp   .dr_mod,11
  576.  jge   @f
  577.  lea   ebx,[ebx*3]
  578.  jmp   .gf
  579. @@:
  580.  shl   ebx,2
  581. .gf:
  582.  mov   edx,esi
  583.  add   esi,ebx
  584.  lea   ebx,[ebx+esi]
  585.  pxor  xmm0,xmm0
  586.  push  eax
  587. .emb:
  588.  cmp    .dr_mod ,11
  589.  jge   @f
  590.  movlps     xmm1,[esi+3]
  591.  movhps     xmm1,[esi+6]
  592.  movlps     xmm2,[esi-3]
  593.  movhps     xmm2,[esi]
  594.  movlps     xmm3,[ebx]
  595.  movhps     xmm3,[ebx+3]
  596.  movlps     xmm4,[edx]
  597.  movhps     xmm4,[edx+3]
  598.  jmp        .ff
  599. @@:
  600.  movlps     xmm1,[esi+4]
  601.  movhps     xmm1,[esi+8]
  602.  movlps     xmm2,[esi-4]
  603.  movhps     xmm2,[esi]
  604.  movlps     xmm3,[ebx]
  605.  movhps     xmm3,[ebx+4]
  606.  movlps     xmm4,[edx]
  607.  movhps     xmm4,[edx+4]
  608. .ff:
  609.  punpcklbw  xmm1,xmm0
  610.  punpcklbw  xmm2,xmm0
  611.  punpcklbw  xmm3,xmm0
  612.  punpcklbw  xmm4,xmm0
  613.  psubsw     xmm1,xmm2
  614.  paddw      xmm1,[emboss_bias]
  615.  psubsw     xmm3,xmm4
  616.  paddw      xmm3,[emboss_bias]
  617.  pmulhw     xmm1,xmm3
  618.  movaps      xmm7,xmm1
  619.  movaps      xmm6,xmm1
  620.  psrlq       xmm7,2*8
  621.  psrlq       xmm6,4*8
  622.  pmaxsw      xmm1,xmm7
  623.  pmaxsw      xmm1,xmm6
  624.  
  625.  
  626.  pmaxsw      xmm1,xmm3
  627.  
  628.  movd        eax,xmm1
  629.  movzx       eax,al
  630. ; cmp         [dr_flag],12
  631. ; je          @f
  632.  lea         eax,[eax*3+envmap_cub]
  633. ; jmp         .fff
  634. ;@@:
  635.  
  636.  mov         eax,[eax]
  637.  mov        [edi],eax  ;xmm1
  638.  psrldq     xmm1,8
  639.  movd       eax,xmm1
  640.  movzx      eax,al
  641.  lea        eax,[eax*3+envmap_cub]
  642.  mov        eax,[eax]
  643.  mov        [edi+4],eax
  644.  
  645.  cmp    .dr_mod,11
  646.  jl     @f
  647.  add    esi,2
  648.  add    ebx,2
  649.  add    edx,2
  650. @@:
  651.  
  652.  add    edi,8
  653.  add    esi,6
  654.  add    ebx,6
  655.  add    edx,6
  656.  sub    ecx,2
  657.  jnc    .emb
  658.  
  659.  
  660.  pop    ecx  ;,eax
  661.  mov    edi,[screen_ptr]
  662.  mov    esi,[Zbuffer_ptr]
  663.  cmp    .dr_mod,11
  664.  jge    .e
  665. @@:
  666.  movsd
  667.  dec    edi
  668.  loop   @b
  669. .e:
  670.  rep    movsd
  671.  
  672. end if
  673.  
  674.  
  675.  
  676.    mov   esp,ebp
  677.    pop   ebp
  678.  
  679. ret
  680.  
  681. ;align 16
  682. ; emboss_bias:
  683. ;    dw 128, 128, 128, 128, 128, 128, 128, 128
  684.  
  685. if 0  ; old emb proc
  686.  
  687.  ;  emboss -  after drawing all,
  688.  ;  transfer screen buffer into bump map
  689.  ;  and draw two bump triangles
  690.  ; *************************************
  691.         mov     esi,screen
  692.         mov     edi,bumpmap2
  693.         mov     ecx,TEXTURE_SIZE/3
  694.         cld
  695. if  Ext=NON
  696.         xor     eax,eax
  697.         xor     bh,bh
  698.         xor     dh,dh
  699.       @@:
  700.         lodsb
  701.         movzx   bx,al
  702.         lodsb
  703.         movzx   dx,al
  704.         lodsb
  705.         add     ax,bx
  706.         add     ax,dx
  707.       ;  cwd
  708.       ;  div     [i3]
  709.  ;;       push    ax
  710.  ;;       pop     bx
  711.  ;;       shr     bx,3
  712.  ;;       shr     ax,2
  713.  ;;       add     ax,bx
  714.  
  715.         lea      eax,[eax*5]
  716.         shr      ax,4
  717.  
  718.         stosb
  719.         loop    @b
  720. else
  721.         emms
  722.         pxor          mm1,mm1
  723.         mov           ebx,0x0000ffff
  724.       @@:
  725.         movd          mm0,[esi]
  726.         punpcklbw     mm0,mm1
  727.         movq          mm2,mm0
  728.         psrlq         mm2,16
  729.         movq          mm3,mm0
  730.         psrlq         mm3,32
  731.         paddw         mm0,mm2
  732.         paddw         mm0,mm3
  733.  
  734.  
  735.         movd          eax,mm0
  736.         and           eax,ebx
  737.         lea           eax,[eax*5]
  738.         shr           ax,4
  739.         stosb
  740.         add           esi,3
  741.         loop          @b
  742.  
  743. end if
  744.         push    ebp
  745.  
  746.         push    dword 0          ; env coords
  747.         push    word 0
  748.         push    word SIZE_X
  749.         push    word SIZE_Y
  750.         push    dword 0
  751.         push    dword 0          ; bump coords
  752.         push    word SIZE_X
  753.         push    word SIZE_Y
  754.         push    word 0
  755.         mov     eax,SIZE_Y
  756.         mov     ebx,SIZE_X*65536+0
  757.         xor     ecx,ecx
  758.         mov     edx,bumpmap2
  759.         mov     esi,envmap
  760.         mov     edi,screen
  761.         call    bump_triangle
  762.  
  763.         push    dword SIZE_X shl 16 + SIZE_Y       ; env coords
  764.         push    word 0
  765.         push    word SIZE_X
  766.         push    word SIZE_Y
  767.         push    word 0
  768.         push    dword SIZE_X shl 16 + SIZE_Y        ; bump coords
  769.         push    word 0
  770.         push    word SIZE_X
  771.         push    word SIZE_Y
  772.         push    word 0
  773.         mov     eax,SIZE_Y
  774.         mov     ebx,SIZE_X * 65536+0
  775.         mov     ecx,SIZE_X shl 16 + SIZE_Y
  776.         mov     edx,bumpmap2
  777.         mov     esi,envmap
  778.         mov     edi,screen
  779.         call    bump_triangle
  780.  
  781.         pop     ebp
  782. ret
  783. end if
  784. ;********************************EMBOSS DONE*******************************
  785.  
  786.  
  787. generate_object2:  ; torus
  788. ;in  ax - figure number       2=torus, 3=loop, 4=loop
  789. ;locals
  790. ;   counter dw ?
  791. ;   sin     dd ?
  792. ;   cos     dd ?
  793. ;endl
  794. .counter equ  word[ebp-2]
  795. .sin     equ  dword[ebp-6]
  796. .cos     equ  dword[ebp-10]
  797. .sin2    equ  dword[ebp-14]
  798. .cos2    equ  dword[ebp-18]
  799. .piD180m3 equ dword[ebp-22]
  800. .cD2      equ word[ebp-24]
  801.         push  ebp
  802.         mov   ebp,esp
  803.         sub   esp,24
  804.  
  805.         push  ax
  806.  
  807.         fninit
  808.         mov     edi,[points_ptr]
  809.         xor     eax,eax
  810.                                     ; init seed -> 4   3d points
  811.         mov     dword[edi],-1.0     ; x
  812.         add     edi,4
  813.         stosd                       ; y
  814.         stosd                       ; z
  815.         mov     dword[edi],-0.9     ; x1
  816.         mov     dword[edi+4],0.1    ; y1
  817.         add     edi,8
  818.         stosd                       ; z1
  819.         mov     dword[edi],-0.8
  820.         add     edi,4
  821.         stosd
  822.         stosd
  823.         mov     dword[edi],-0.9     ; x3
  824.         mov     dword[edi+4],-0.1   ; y3
  825.         add     edi,8
  826.         stosd                       ; z3
  827.         mov     [points_count_var],4
  828.  
  829.         fld     [piD180]
  830.         fidiv   [i3]
  831.         fstp    .piD180m3
  832.         mov     .cD2,5
  833.  
  834.         pop     ax
  835.         mov     ecx,1
  836.         mov     edx,9
  837.       .next:                      ; calc angle and rotate seed 4 points
  838.         mov     .counter,cx
  839.         mov     ebx,[points_ptr]
  840.         fld     .piD180m3
  841.         fimul   .counter
  842.         fld     st
  843.         fsincos
  844.         fstp    .sin
  845.         fstp    .cos
  846.         fadd    st,st0
  847.         fsincos
  848.         fstp    .sin2
  849.         fstp    .cos2
  850.  
  851.       .rotor:                          ; next 4
  852.         ; rotary y
  853.         fld     dword[ebx]         ; x
  854.         fld     .sin
  855.         fmul    dword[ebx+8]       ; z * sinbeta
  856.         fchs
  857.         fld     .cos
  858.         fmul    dword[ebx]         ; x * cosbeta
  859.         faddp
  860.         fstp    dword[edi]         ; new x
  861.         fmul    .sin             ; old x * sinbeta
  862.         fld     .cos
  863.         fmul    dword[ebx+8]       ; z * cosbeta
  864.         faddp
  865.         dec     dx
  866.         or      dx,dx
  867.         jnz     @f
  868. ;        mov     .counter,dx
  869.         fld     st
  870.         fidiv   [i3]
  871.         faddp
  872.     @@:
  873.         fstp    dword[edi+8]       ; new z
  874.         fld     dword[ebx+4]
  875.         or      dx,dx
  876.         jnz     @f
  877.   ;      fld1
  878.   ;      faddp
  879. ;        fld     st
  880.         fadd    st,st0
  881.         fadd    st,st0
  882. ;        fxch
  883. ;        fimul   [i3]
  884. ;        fsin
  885. ;        faddp
  886.         mov     dx,9
  887.     @@:
  888.         fstp    dword[edi+4]
  889.         ; rotary x
  890.         cmp     al,3
  891.         jl      .end_rot
  892.         fld     dword[edi+4]    ;y
  893.         fld     .sin2
  894.         fmul    dword[edi+8]    ;z
  895.         fld     .cos2
  896.         fmul    dword[edi+4]    ;y
  897.         faddp
  898.         fstp    dword[edi+4]    ; new y
  899.         fmul    .sin2       ; sinbeta * old y
  900.         fchs
  901.         fld     .cos2
  902.         fmul    dword[edi+8]
  903.         faddp
  904.         fstp    dword[edi+8]
  905.         ; rotary z
  906.         cmp     al,4
  907.         jl      .end_rot
  908.         fld     dword[edi]      ;x
  909.         fld     .sin
  910.         fmul    dword[edi+4]    ;y
  911.         fld     .cos
  912.         fmul    dword[edi]      ;x
  913.         faddp
  914.         fstp    dword[edi]      ;new x
  915.         fmul    .sin       ; sinbeta * old x
  916.         fchs
  917.         fld     .cos
  918.         fmul    dword[edi+4]         ; cosbeta * y
  919.         faddp
  920.         fstp    dword[edi+4]    ; new y
  921.  
  922.  
  923.  
  924.       .end_rot:
  925.  
  926.         add     edi,12
  927.         add     ebx,12
  928.         mov     esi,[points_ptr]
  929.         add     esi,12*4
  930.         cmp     ebx,esi
  931.         jl      .rotor
  932.  
  933.         add     [points_count_var],4
  934.         add     cx,18
  935.         cmp     cx,(18*21*3)+1
  936.         jle     .next
  937.  
  938.         mov     edi,[triangles_ptr]
  939.         mov     eax,4
  940.         mov     ebx,4+4
  941.         mov     [triangles_count_var],160*3    ;164*3   ;140
  942.  
  943.         mov     ecx,80*3  ;68
  944.       @@:
  945.         stosd                 ;----
  946.         mov     [edi],ebx      ;    |
  947.         add     edi,4         ;    |
  948.         inc     eax            ;    |
  949.         stosd                 ;    |repeat 4 times
  950.  
  951.         mov     [edi],ebx      ;    |
  952.         inc     ebx
  953.         add     edi,4
  954.         stosd                 ;    |
  955.         mov     [edi],ebx      ;    |
  956.         add     edi,4         ;----
  957.         loop     @b
  958.  
  959.  
  960.         mov     dword[edi],-1  ; < - end mark
  961.         mov       [culling_flag],0
  962.  
  963.         mov     esp,ebp
  964.         pop     ebp
  965.  
  966. ret
  967. generate_object3:  ; heart
  968. ;locals
  969. ;   counter dw ?
  970. ;   sin     dd ?
  971. ;   cos     dd ?
  972. ;endl
  973. .counter equ  word[ebp-2]
  974. .sin     equ  dword[ebp-6]
  975. .cos     equ  dword[ebp-10]
  976. .sin2    equ  dword[ebp-14]
  977. .cos2    equ  dword[ebp-18]
  978. .piD180m3 equ dword[ebp-22]
  979. .cD2      equ word[ebp-24]
  980.         push  ebp
  981.         mov   ebp,esp
  982.         sub   esp,24
  983.  
  984.         fninit
  985.         mov     edi,[points_ptr]
  986.         xor     eax,eax
  987.                                ; init seed -> eight   3d points
  988.         mov     dword[edi],2.0
  989.         add     edi,4
  990.         stosd
  991.         stosd
  992.  
  993.         mov     dword[edi],2.0
  994.         mov     dword[edi+4],-0.5
  995.         add     edi,8
  996.         stosd
  997.  
  998.         mov     dword[edi],1.5
  999.         mov     dword[edi+4],-1.5
  1000.         add     edi,8
  1001.         stosd
  1002.         mov     dword[edi],1.0
  1003.         mov     dword[edi+4],-2.0
  1004.         add     edi,8
  1005.         stosd
  1006.  
  1007.         stosd
  1008.         mov     dword[edi],-2.5
  1009.         add     edi,4
  1010.         stosd
  1011.  
  1012.         mov     [points_count_var],5
  1013.  
  1014.         mov     ecx,1
  1015.       .next:                      ; calc angle and rotate seed 4 points
  1016.         mov     .counter,cx
  1017.         mov     ebx,[points_ptr]
  1018.         fld     [piD180]
  1019.         fimul   .counter
  1020.         fsincos
  1021.         fstp    .sin
  1022.         fstp    .cos
  1023.  
  1024.       .rotor:                          ; next 4
  1025.         ; rotary y
  1026.         fld     dword[ebx]         ; x
  1027.         fld     .sin
  1028.         fmul    dword[ebx+8]       ; z * sinbeta
  1029.         fchs
  1030.         fld     .cos
  1031.         fmul    dword[ebx]         ; x * cosbeta
  1032.         faddp
  1033.         fidiv   [i3]
  1034.         fstp    dword[edi]         ; new x
  1035.         fmul    .sin               ; old x * sinbeta
  1036.         fld     .cos
  1037.         fmul    dword[ebx+8]       ; z * cosbeta
  1038.         faddp
  1039.         fstp    dword[edi+8]       ; new z
  1040.  
  1041.         fld     dword[ebx+4]   ;y
  1042.         fstp    dword[edi+4]
  1043.  
  1044.  
  1045.       .end_rot:
  1046.  
  1047.         add     edi,12
  1048.         add     ebx,12
  1049.         mov     esi,[points_ptr]
  1050.         add     esi,12*5
  1051.         cmp     ebx,esi  ;real_points + (12*5)
  1052.         jl      .rotor
  1053.  
  1054.         add     [points_count_var],5
  1055.         add     cx,18
  1056.         cmp     cx,(18*21)+1
  1057.         jle     .next
  1058. ;last points
  1059.  
  1060.         xor     eax,eax
  1061.  
  1062.         mov     dword[edi],0.22
  1063.         mov     dword[edi+4],0.77
  1064.         mov     dword[edi+8],1.25
  1065.         add     edi,12
  1066.  
  1067.         mov     dword[edi],0.22
  1068.         mov     dword[edi+4],0.77
  1069.         mov     dword[edi+8],-1.25
  1070.         add     edi,12
  1071.         stosd
  1072.  
  1073.         add     [points_count_var],2
  1074.  
  1075. ; init triangles list
  1076.  
  1077.         mov     edi,[triangles_ptr]
  1078.         mov     eax,5
  1079.         mov     ebx,5+5
  1080.         mov     [triangles_count_var],200  ;204
  1081.  
  1082.         mov     ecx,100
  1083.       @@:
  1084.         stosd                 ;----
  1085.         mov     [edi],ebx      ;    |
  1086.         add     edi,4         ;    |
  1087.         inc     eax            ;    |
  1088.         stosd                 ;    |repeat
  1089.  
  1090.         mov     [edi],ebx      ;    |
  1091.         inc     ebx
  1092.         add     edi,4
  1093.         stosd                 ;    |
  1094.         mov     [edi],ebx      ;    |
  1095.         add     edi,4         ;----
  1096.         loop     @b
  1097.  
  1098.         mov     eax,5
  1099.         mov     ebx,[points_count_var]
  1100.         sub     ebx,2
  1101.         mov     dl,2
  1102.     .nx:
  1103.         mov     ecx,5
  1104.         add     [triangles_count_var],ecx
  1105.     @@:
  1106.         stosd
  1107.         add     eax,5
  1108.         stosd
  1109.         mov     dword[edi],ebx
  1110.         add     edi,4
  1111.         loop    @b
  1112.  
  1113.         cmp     dl,1
  1114.         je      @f
  1115.  
  1116.         inc     ebx
  1117.         jmp     .lab
  1118.      @@:
  1119.         dec     ebx
  1120.      .lab:
  1121.         mov     ecx,5
  1122.         add     [triangles_count_var],ecx
  1123.      @@:
  1124.         stosd
  1125.         add     eax,5
  1126.         stosd
  1127.         mov     dword[edi],ebx
  1128.         add     edi,4
  1129.         loop    @b
  1130.  
  1131.         dec     dl
  1132.         or      dl,dl
  1133.         jnz     .nx
  1134.  
  1135.         sub     eax,25
  1136.         stosd
  1137.         sub     eax,50
  1138.         stosd
  1139.         mov     dword[edi],ebx
  1140.         add     edi,4
  1141.  
  1142.         stosd
  1143.         add     eax,50
  1144.         stosd
  1145.         inc     ebx
  1146.         mov     dword[edi],ebx
  1147.         add     edi,4
  1148.         add     [triangles_count_var],2
  1149.  
  1150.         mov     dword[edi],-1  ; < - end mark
  1151.         mov     [culling_flag],0
  1152.  
  1153.         mov     esp,ebp
  1154.         pop     ebp
  1155.  
  1156. ret
  1157.  
  1158.  
  1159.  
  1160.