Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. ; application : View3ds ver. 0.077 - tiny .3ds and .asc files viewer
  3. ;               with a few graphics effects demonstration.
  4. ; compiler    : FASM
  5. ; system      : KolibriOS
  6. ; author      : Macgub aka Maciej Guba
  7. ; email       : macgub3@wp.pl
  8. ; web         : http://macgub.co.pl
  9. ; Fell free to use this intro in your own distribution of KolibriOS.
  10. ; Special greetings to KolibriOS team .
  11. ; I hope because my demos Christian Belive will be near to each of You.
  12.  
  13.  
  14. ; Some adjustments made by Madis Kalme
  15. ; madis.kalme@mail.ee
  16. ; I tried optimizing it a bit, but don't know if it was successful. The objects
  17. ; can be:
  18. ; 1) Read from a file (*.3DS standard)
  19. ; 2) Written in manually (at the end of the code) ; now not exist
  20.  
  21.  
  22. SIZE_X equ 512
  23. SIZE_Y equ 512                               ;      /////     I want definitely
  24. TIMEOUT equ 10                               ;     ------     say:
  25. ROUND equ 10                                 ;     \ @ @/     keep smiling every
  26. TEX_X equ 512    ; texture width             ;      \ ./    / day.
  27. TEX_Y equ 512    ;         height            ;       \/    /
  28. TEX_SHIFT equ 9  ; texture width shifting    ;     __||__ /
  29. TEXTURE_SIZE EQU (TEX_X * TEX_Y)-1           ;   /|      |
  30. TEX equ SHIFTING ; TEX={SHIFTING | FLUENTLY} ;  / \      /
  31. FLUENTLY = 0                                 ; /   |    |
  32. SHIFTING = 1                                 ;     ------
  33. CATMULL_SHIFT equ 8                          ;      |  |
  34. LIGHT_SIZE equ 22                            ;      |  |
  35. NON   =   0                                  ;     -/  \-
  36. MMX   =   1
  37. SSE   =   2
  38. SSE2  =   3
  39. SSE3  =   4
  40. Ext   =   SSE3          ;Ext={ NON | MMX | SSE | SSE2 | SSE3 }
  41.  
  42. ; For now correct only SSE2 and SSE3 versions. if you have older CPU
  43. ; use older versions of app. Probably ver 005 will be OK but it need
  44. ; re-edit to support new Kolibri features.
  45.  
  46. use32
  47.         org    0x0
  48.         db     'MENUET01'       ; 8 byte id
  49.         dd     0x01             ; header version
  50.         dd     START            ; start of code
  51.         dd     I_END            ; size of image
  52.         dd     MEM_END          ; memory for app
  53.         dd     MEM_END          ; esp
  54.         dd     I_Param          ; I_Param
  55.         dd     0x0              ; I_Icon
  56.  
  57. START:    ; start of execution
  58.         rdtsc
  59.         mov    [rand_seed],ax
  60.         cld
  61.         push   dword (SIZE_Y shr 3) * 3
  62.         fninit
  63.         fild   dword[esp]
  64.         fstp   [rsscale]
  65.         pop    ebx
  66.  
  67.         call    alloc_buffer_mem
  68.         call    read_param
  69.         call    read_from_disk    ; read, if all is ok eax = 0
  70.         btr     eax,31            ; mark 1
  71.         cmp     eax,0
  72.         jne     .gen
  73.         bts     eax,31            ; mark 2
  74.         mov     esi,[fptr]
  75.         cmp     [esi],word 4D4Dh
  76.         jne     .asc_gen
  77.         call    read_tp_variables ; init points and triangles count variables
  78.         cmp     eax,0
  79.         jne    .malloc
  80.         xor    eax,eax            ; if failed read -> generate
  81.     .gen:
  82.     .asc_gen:   ; read asc file or generate
  83.         push    eax
  84.      ; if no house.3ds on rd - generate
  85.         xor      bl,bl ; allocate memory
  86.         mov      [triangles_count_var],20000
  87.         mov      [points_count_var],20000
  88.         call     alloc_mem_for_tp
  89.         pop      eax
  90.         bt       eax,31
  91.         jc       .asc
  92.         mov      bl,[generator_flag]
  93.         call     generate_object
  94.         mov      ax,1  ;mark
  95.  
  96.         jmp      .opt
  97.     .asc:
  98.    ;     xor    bl,bl
  99.    ;     mov    [triangles_count_var],20000  ; to do: read asc header
  100.    ;     mov    [points_count_var],20000
  101.    ;     call   alloc_mem_for_tp
  102.         call   read_asc
  103.         xor    ax,ax
  104.         jmp    .opt
  105.     .malloc:
  106.         call   alloc_mem_for_tp
  107.         call   read_from_file
  108.     .opt:
  109.       if     Ext >= SSE2
  110.         push   ax
  111.       end if
  112.         call   optimize_object1     ;  proc in file b_procs.asm
  113.                                     ;  set point(0,0,0) in center and  calc all coords
  114.                                     ;  to be in <-1.0,1.0>
  115.         call   normalize_all_light_vectors
  116.         call   copy_lights ; to aligned float
  117.  ;       call   init_triangles_normals2
  118.  
  119.  
  120.      if Ext >= SSE2
  121.               ; if first byte of ax set -> old style normal vectors finding
  122.         call   detect_chunks
  123.         mov    [chunks_number],ecx
  124.         mov    [chunks_ptr],ebx
  125.         push   esi
  126.         push   edi
  127.         call   init_triangles_normals2
  128.      ;  esi -   tri_ch
  129.      ;  edi -   t_ptr - every vertice index  - pointer to to all triangles
  130.      ;          that have this index
  131.         pop    edi
  132.         pop    esi
  133.         pop    ax
  134.  
  135.      end if
  136.  
  137.         call   init_point_normals
  138.  
  139.         call   init_envmap2
  140.         call   init_envmap_cub
  141.         call   generate_texture2
  142.         call   init_sincos_tab
  143.         call   do_color_buffer   ; intit color_map
  144.      if Ext >= SSE3
  145.         call   init_point_lights
  146.      end if
  147.         mov    edi,bumpmap
  148.         call   calc_bumpmap
  149.         call   calc_bumpmap_coords   ; bump and texture mapping
  150.         call   do_edges_list
  151.         call   draw_window
  152.      if Ext > SSE2
  153.         mov     eax,1
  154.         cpuid
  155.         bt      ecx,0  ; is sse3 on board?
  156.         jc      @f
  157.         mov     byte[max_dr_flg],12
  158.         mov     [isSSE3],0
  159.        @@:
  160.      end if
  161.  
  162.  
  163.  still:
  164.         cmp    [edit_flag],1
  165.         jne    @f
  166.         mov    eax,40         ; set events mask
  167.         mov    ebx,1100000000000000000000000100111b
  168.         jmp    .int
  169.       @@:
  170.         mov    eax,40         ; set events mask
  171.         mov    ebx,111b
  172.       .int:
  173.         int    0x40
  174.       if Ext > SSE2
  175.         cmp    [ray_shd_flag],1
  176.         jne    @f
  177.         cmp    [isSSE3],1
  178.         jne    @f
  179.         mov    eax,10
  180.         jmp    .intt
  181.       end if
  182.  
  183.        @@:
  184.         mov     eax,23
  185.         mov     ebx,TIMEOUT
  186.         cmp     [speed_flag],0
  187.         je      .skip
  188.         mov     eax,11
  189.      .skip:
  190.         cmp     [edit_flag],1
  191.         jne     @f
  192.         mov     eax,10
  193.  
  194.       @@:
  195.       .intt:
  196.         int     0x40
  197.  
  198.         cmp     eax,1           ; redraw event ?
  199.         je      red
  200.         cmp     eax,2           ; key event ?
  201.         je      key
  202.         cmp     eax,3           ; button event ?
  203.         je      button
  204.  
  205.         mov     esi,eax
  206.         mov     eax,37
  207.         mov     ebx,7           ; get mouse scroll
  208.         int     0x40
  209.         and     eax, 0xFFFF     ; check only vertial
  210.         cmp     eax, 65535
  211.         je      button.zoom_in
  212.         cmp     eax, 1
  213.         je      button.zoom_out
  214.         mov     eax,esi
  215.  
  216.         cmp     eax,6           ; mouse event ?
  217.         jne     @f
  218.         cmp     [edit_flag],1   ; handle mouse only when edit is active
  219.         jne     @f
  220.         mov     eax,37
  221.         mov     ebx,3   ;read mouse state
  222.         int     0x40
  223.         mov     [mouse_state],eax
  224.         call    edit
  225.        @@:
  226.         jmp     noclose
  227.  
  228.     red:   ; redraw
  229.      ;   xor     edx,edx
  230.      ; @@:
  231.      ;   push    edx
  232.         mov     eax,9  ; get process info
  233.         mov     ebx,procinfo
  234.         or      ecx,-1
  235.         int     0x40
  236.      ;   pop     edx
  237.      ;   inc     edx
  238.      ;   cmp     dword[procinfo+26],50000000  ; ~ 10 Mbytes
  239.      ;   jb      @f
  240.      ;   cmp     edx,1
  241.      ;   je      @b
  242.  
  243.  
  244.     ; @@:
  245.         mov     eax,[procinfo+42]    ; read params of window
  246.         sub     eax,225
  247.         mov     [size_x_var],ax
  248.         shr     ax,1
  249.         mov     [vect_x],ax
  250. ;
  251.         mov     eax,[procinfo+46]
  252.         sub     eax,30
  253.         mov     [size_y_var],ax
  254.         shr     ax,1
  255.         mov     [vect_y],ax
  256.  
  257.         mov     eax,[procinfo+34]
  258.         mov     [x_start],ax
  259.         mov     eax,[procinfo+38]
  260.         mov     [y_start],ax
  261.         call    alloc_buffer_mem ;realloc mem for scr & z buffs
  262.         call    draw_window
  263.  
  264.         jmp     noclose
  265.  
  266.     key:                        ; key
  267.         mov     eax,2           ; just read it and ignore
  268.         int     0x40
  269.         shr     eax,16          ; use scancodes (al)
  270.  
  271.         cmp     al, 013 ;+
  272.         je      button.zoom_in
  273.         cmp     al, 012 ;-
  274.         je      button.zoom_out
  275.         cmp     al, 075 ;left
  276.         je      add_vec_buttons.x_minus
  277.         cmp     al, 077 ;right
  278.         je      add_vec_buttons.x_plus
  279.         cmp     al, 072 ;up
  280.         je      add_vec_buttons.y_minus
  281.         cmp     al, 080 ;down
  282.         je      add_vec_buttons.y_plus
  283.         cmp     al, 073 ;page up
  284.         je      .rot_inc_y
  285.         cmp     al, 081 ;page down
  286.         je      .rot_dec_y
  287.         cmp     al, 051 ;<
  288.         je      .rot_dec_x
  289.         cmp     al, 052 ;>
  290.         je      .rot_inc_x
  291.         cmp     al, 057 ;space
  292.         je      .rot_z
  293.  
  294.         jmp     noclose
  295.  
  296.         .rot_inc_x:
  297.         inc     [angle_x]
  298.         and     [angle_x],0xff
  299.         jmp     noclose.end_rot
  300.         .rot_dec_x:
  301.         dec     [angle_x]
  302.         and     [angle_x],0xff
  303.         jmp     noclose.end_rot
  304.         .rot_inc_y:
  305.         inc     [angle_y]
  306.         and     [angle_y],0xff
  307.         jmp     noclose.end_rot
  308.         .rot_dec_y:
  309.         dec     [angle_y]
  310.         and     [angle_y],0xff
  311.         jmp     noclose.end_rot
  312.         .rot_z:
  313.         inc     [angle_z]
  314.         and     [angle_z],0xff
  315.         jmp     noclose.end_rot
  316.  
  317.     button:                     ; button
  318.         mov     eax,17          ; get id
  319.         int     0x40
  320.  
  321.         cmp     ah,1            ; button id=1 ?
  322.         jne     @f
  323.  
  324.         mov     eax,-1          ; close this program
  325.         int     0x40
  326.     @@:
  327.         cmp     ah,30
  328.         jge     add_vec_buttons
  329.         call    update_flags          ; update flags and write labels of flags
  330.  
  331.                                       ; do other operations according to flag
  332. ;        cmp     ah,3                 ; ah = 3 -> shading model
  333. ;        jne     .next_m6
  334. ;        cmp     [dr_flag],2
  335. ;        jne     @f
  336.    ;     call    init_envmap2    ;   <----! this don't works in env mode
  337.                                  ;          and more than ~18 kb objects
  338.  ;       call    init_envmap_cub2
  339. ;     @@:
  340.         cmp     [dr_flag],4
  341.         jne     @f
  342.         call    generate_texture2
  343.  
  344.      @@:
  345.      .next_m6:
  346.                                       ; ah = 5 -> scale-
  347.         cmp     ah,5
  348.         jne     @f
  349.         .zoom_out:
  350.         mov     dword[scale],0.7
  351.         fninit
  352.         fld     [rsscale]
  353.         fmul    [scale]
  354.         fstp    [rsscale]
  355.        @@:
  356.         cmp     ah,6                 ; ah = 6 ->  scale+
  357.         jne     @f
  358.       .zoom_in:
  359.         mov     dword[scale],1.3
  360.         fninit
  361.         fld     [rsscale]
  362.         fmul    [scale]
  363.         fstp    [rsscale]
  364.        @@:
  365.         cmp     ah,9    ; lights random                 ;    'flat'  0
  366.         jne     .next_m5                                ;    'grd '  1
  367.         call    make_random_lights                      ;    'env '  2
  368.         call    normalize_all_light_vectors             ;    'bump'  3
  369.         call    copy_lights
  370.       if Ext >= SSE3
  371.         call   init_point_lights  ; for ex. ray casting
  372.       end if
  373.         call    do_color_buffer   ; intit color_map     ;    'tex '  4
  374.  
  375.         call    init_envmap2    ; update env map if shading model = environment or bump
  376.     .next_m5:
  377.         cmp      ah,11
  378.         je       @f
  379.         cmp      ah,12
  380.         je       @f
  381.         cmp      ah,13
  382.         jne      .next_m4
  383.       @@:
  384.         call     mirror
  385.      .next_m4:
  386.         cmp      ah,14
  387.         jne      @f
  388.                 .xchg:
  389.         call     exchange
  390.      @@:
  391.         cmp      ah,15
  392.         jne      @f
  393.         cmp      [emboss_flag],1
  394.      ;   call     init_envmap2
  395.         call     do_emboss
  396.      @@:
  397.  ;       cmp      ah,17
  398.  ;       jne      .next_m
  399.  ;       cmp      [move_flag],2
  400.  ;       jne      @f
  401.  ;       call     draw_window             ; redraw other labels to navigation buttons
  402.  ;     @@:
  403.  ;       cmp      [move_flag],0
  404.  ;       jne      .next_m
  405.  ;       call     draw_window             ; redraw other labels to navigation buttons
  406.      .next_m:
  407.         cmp      ah,18
  408.         jne      .next_m2
  409.  
  410.         mov      bl,1       ; reallocate memory
  411.         mov      [triangles_count_var],20000
  412.         mov      [points_count_var],20000
  413.         call     alloc_mem_for_tp
  414.  
  415.         mov      bl,[generator_flag]
  416.      ;   or       bl,bl
  417.      ;   jz       .next_m2
  418.         cmp      bl,1
  419.         jne      @f
  420.         call     generate_object
  421.         jmp      .calc_norm
  422.       @@:
  423.         cmp      bl,4
  424.         jg       @f
  425.         movzx    eax,bl                ; eax < - object number
  426.         call     generate_object2
  427.         jmp     .calc_norm
  428.       @@:
  429.         call    generate_object3
  430.       .calc_norm:
  431.         call    optimize_object1
  432.         call    init_triangles_normals2
  433.      if Ext >= SSE2
  434.         call   detect_chunks
  435.         mov    [chunks_number],ecx
  436.         mov    [chunks_ptr],ebx
  437.         mov    ax,1  ; - old style detecting normal vectors
  438.      ;   esi -   tri_ch
  439.      ;   edi -   t_ptr - every vertice index  - pointer to to all triangles
  440.      ;           that have this index
  441.      end if
  442.  
  443.         call    init_point_normals
  444.         call    calc_bumpmap_coords   ; bump and texture mapping
  445.         call    do_edges_list
  446.         call    write_info
  447.  
  448.      .next_m2:
  449.         cmp      ah,19
  450.         je       @f
  451.         cmp      ah,20
  452.         jne      .next_m3
  453.      @@:
  454.         mov      edi,bumpmap
  455.         call     calc_bumpmap
  456.      .next_m3:
  457.         cmp     ah,21            ; re map bumps, texture coordinates
  458.         jne     @f
  459.         call    calc_bumpmap_coords
  460.       @@:
  461.         jmp     noclose
  462.  
  463.  
  464.                                ; there are 6 navigation buttons each
  465.    add_vec_buttons:            ; can move: object, camera,.. list is open
  466.                                ;
  467.         cmp     ah,30
  468.         jne     .next
  469.         cmp     [move_flag],0
  470.         jne     @f
  471. ;        cmp     [move_flag],2
  472. ;        je      .set_light1
  473.         .y_minus:
  474.         sub     [vect_y],10
  475.         jmp     .next
  476.       @@:
  477.         cmp     [move_flag],1
  478.         jne     @f
  479.         sub     [yobs],10   ;  observator = camera position
  480.         jmp     .next
  481.       @@:
  482.         sub     [sin_amplitude],10
  483. ;--------------------------------------------------
  484. ;      .set_light1:          ;  r -
  485. ;        movzx   ebx,[light_no_flag]  ; * 22
  486. ;        mov     ecx,ebx
  487. ;        shl     ebx,4
  488. ;        shl     ecx,1
  489. ;        add     ebx,ecx
  490. ;        shl     ecx,1
  491. ;        add     ebx,ecx
  492. ;        add     ebx,lights+6    ; 6 -> light vector size
  493. ;
  494. ;        movzx   ecx,[light_comp_flag]
  495. ;        lea     ecx,[ecx*3}
  496. ;        add     ebx,ecx         ; ebx ->  color to set
  497.  
  498. ;---------------------------------------------------
  499.       .next:
  500.         cmp     ah,31
  501.         jne     .next1
  502.         cmp     [move_flag],1
  503.         je      @f
  504.         add     [vect_z],10
  505.         jmp     .next1
  506.       @@:
  507.         add     [zobs],10         ;  observator = camera position
  508.      .next1:
  509.         cmp     ah,33
  510.         jne     .next2
  511.         cmp     [move_flag],0
  512.         jne     @f
  513.         .x_minus:
  514.         sub     word[vect_x],10
  515.         jmp     .next2
  516.       @@:
  517.         cmp     [move_flag],1
  518.         jne     @f
  519.         sub     [xobs],10         ;  observator = camera position
  520.         jmp     .next2
  521.       @@:
  522.         fninit
  523.         fld     [sin_frq]
  524.         fsub    [sin_delta]
  525.         fstp    [sin_frq]
  526.       .next2:
  527.         cmp     ah,32
  528.         jne     .next3
  529.         cmp     [move_flag],0
  530.         jne     @f
  531.         .x_plus:
  532.         add     word[vect_x],10
  533.         jmp     .next3
  534.       @@:
  535.         cmp     [move_flag],1
  536.         jne     @f
  537.         add     [xobs],10         ;  observator = camera position
  538.         jmp     .next3
  539.       @@:
  540.         fninit
  541.         fld     [sin_frq]      ; change wave effect frequency
  542.         fadd    [sin_delta]
  543.         fstp    [sin_frq]
  544.       .next3:
  545.         cmp     ah,34
  546.         jne     .next4
  547.         cmp     [move_flag],1
  548.         je      @f
  549.  
  550.         sub     [vect_z],10
  551.         jmp     .next4
  552.       @@:
  553.         sub     [zobs],10         ;  observator = camera position
  554.       .next4:
  555.         cmp     ah,35
  556.         jne     .next5
  557.         cmp     [move_flag],0
  558.         jne      @f
  559.       ;  call    add_vector
  560.             .y_plus:
  561.         add     [vect_y],10
  562.         jmp     .next5
  563.       @@:
  564.         cmp     [move_flag],1
  565.         jne     @f
  566.         add     [yobs],10         ;  observator = camera position
  567.         jmp     .next5
  568.       @@:
  569.         add     [sin_amplitude],10
  570.       .next5:
  571.  
  572.  
  573.  
  574.     noclose:
  575.  
  576.         cmp     [edit_flag],1
  577.         jz      .end_rot
  578.         cmp     [r_flag],2
  579.         jne     .no_x
  580.         inc     [angle_x]
  581.         and     [angle_x],0xff
  582.         ;mov     [angle_z],0
  583.         jmp     .end_rot
  584.  
  585.       .no_x:
  586.         cmp     [r_flag],0
  587.         jne     .no_y
  588.         inc     [angle_y]
  589.         and     [angle_y],0xff
  590.         ;mov     [angle_z],0
  591.         jmp     .end_rot
  592.  
  593.       .no_y:
  594.         cmp     [r_flag],1
  595.         jne     .end_rot
  596.         mov     cx,[angle_x]
  597.         inc     cx
  598.         and     cx,0xff
  599.         ;mov     [angle_z],0
  600.         mov     [angle_y],cx
  601.         mov     [angle_x],cx
  602.      .end_rot:
  603.  
  604.         mov     esi,angle_x
  605.         mov     edi,matrix
  606.         call    make_rotation_matrix
  607.     RDTSC
  608.     push eax
  609.         mov     esi,[points_normals_ptr]
  610.         mov     edi,[points_normals_rot_ptr]
  611.         mov     ebx,matrix
  612.         mov     ecx,[points_count_var]
  613.         call    rotary
  614.  
  615.         mov     esi,matrix
  616.         call    add_scale_to_matrix
  617.  
  618.         mov     esi,[points_ptr]
  619.         mov     edi,[points_rotated_ptr]
  620.         mov     ebx,matrix
  621.         mov     ecx,[points_count_var]
  622.         call    rotary
  623.  
  624.  
  625.         mov     esi,[points_rotated_ptr]
  626.         mov     edi,[points_translated_ptr]
  627.         mov     ecx,[points_count_var]
  628.         call    translate_points
  629.  
  630.         cmp     [fire_flag],0
  631.         jne     @f
  632.         call    clrscr          ; clear the screen
  633.      @@:
  634.     ;    cmp     [catmull_flag],1  ;non sort if Catmull = on
  635.     ;    je      .no_sort
  636.     ; 64 indexes    call    sort_triangles
  637.       .no_sort:
  638.         cmp     [dr_flag],7       ; fill if 2tex and texgrd
  639.         jge     @f
  640.         cmp     [dr_flag],6       ; non fill if dots
  641.         je      .non_f
  642.       @@:
  643.         call    fill_Z_buffer     ; make background
  644.      .non_f:
  645.         cmp     [dr_flag],6
  646.         jne     @f
  647.         call     draw_dots
  648.         jmp      .blurrr
  649.       @@:
  650.       if Ext > SSE2
  651.         cmp     [ray_shd_flag],1  ;non fill if Catmull = off
  652.         jne     @f
  653.         cmp     [isSSE3],1
  654.         jne     @f
  655.         mov     ax,100
  656.         jmp     .dr
  657.        @@:
  658.       end if
  659.  
  660.         movzx   ax,[dr_flag]
  661.       .dr:
  662.         call    draw_triangles  ; draw all triangles from the list
  663.         cmp    [edit_flag],0
  664.         jz     .no_edit
  665.         call   clear_vertices_index
  666.         movzx eax,[dr_flag]
  667.         movzx ebx,[ray_shd_flag]
  668.         shl   ebx,10
  669.         or    eax,ebx
  670.          call   draw_handlers
  671.     ;    call   edit
  672.  
  673.  
  674.  
  675.     .no_edit:
  676.  
  677.       .blurrr:
  678.         movzx eax,[dr_flag]
  679.         movzx ebx,[ray_shd_flag]
  680.         shl   ebx,10
  681.         or    eax,ebx
  682.         cmp   [sinus_flag],0
  683.         je    .no_sin
  684.         movzx eax,[dr_flag]
  685.         movzx ebx,[ray_shd_flag]
  686.         shl   ebx,10
  687.         or    eax,ebx
  688.         call  do_sinus
  689.       ;  jmp   .finito
  690.       .no_sin:
  691.       @@:
  692.         movzx   ecx,[fire_flag]
  693.         cmp     [fire_flag],1
  694.         je      @f
  695.         cmp     [blur_flag],0
  696.         je      .no_blur  ; no blur, no fire
  697.         movzx   ecx,[blur_flag]
  698.       @@:
  699.         movzx   eax,[dr_flag]
  700.         movzx   ebx,[ray_shd_flag]
  701.         shl     ebx,10
  702.         or      eax,ebx
  703.         call    blur_screen    ; blur and fire
  704.      ;   jmp     .finito
  705.  
  706.     .no_blur:                  ; no blur, no fire
  707.         cmp     [emboss_flag],0
  708.         je      @f
  709.         movzx eax,[dr_flag]
  710.         movzx ebx,[ray_shd_flag]
  711.         shl   ebx,10
  712.         or    eax,ebx
  713.         call    do_emboss
  714.     .finito:
  715.      @@:
  716.  
  717.  
  718.     cmp     [inc_bright_flag],0           ; increase brightness
  719.     je      .no_inc_bright
  720.     movzx   ebx,[inc_bright_flag]
  721.     shl     ebx,4
  722.     mov     esi,[screen_ptr]
  723.     movzx   ecx,word[size_y_var]
  724.     movzx   eax,word[size_x_var]
  725.     mul     ecx
  726.     lea     ecx,[eax*4]
  727.  
  728. if (Ext = MMX)|(Ext = SSE)
  729.     emms
  730.     mov      bh,bl
  731.     push     bx
  732.     shl      ebx,16
  733.     pop      bx
  734.     push     ebx
  735.     push     ebx
  736.     movq     mm0,[esp]
  737.     add      esp,8
  738. else if Ext >= SSE2
  739.     mov      bh,bl
  740.     push     bx
  741.     shl      ebx,16
  742.     pop      bx
  743.     movd     xmm0,ebx
  744.     shufps   xmm0,xmm0,0
  745. end if
  746.   .oop:
  747. if Ext=NON
  748.     lodsb
  749.     add     al,bl
  750.     jnc     @f
  751.     mov     byte[esi-1],255
  752.     loop    .oop
  753.    @@:
  754.     mov     [esi-1],al
  755.     loop    .oop
  756. else if (Ext=MMX)|(Ext=SSE)
  757.     movq    mm1,[esi]
  758.     movq    mm2,[esi+8]
  759.     paddusb mm1,mm0
  760.     paddusb mm2,mm0
  761.     movq    [esi],mm1
  762.     movq    [esi+8],mm2
  763.     add     esi,16
  764.     sub     ecx,16
  765.     jnz     .oop
  766. else
  767.     movaps  xmm1,[esi]
  768.     paddusb xmm1,xmm0
  769.     movaps  [esi],xmm1
  770.     add     esi,16
  771.     sub     ecx,16
  772.     jnc     .oop
  773. end if
  774.  
  775. .no_inc_bright:
  776.  
  777.  
  778.     cmp     [dec_bright_flag],0
  779.     je      .no_dec_bright
  780.     movzx   ebx,[dec_bright_flag]
  781.     shl     ebx,4
  782.     mov     esi,[screen_ptr]
  783.     movzx   eax,word[size_x_var]
  784.     movzx   ecx,word[size_y_var]
  785.     mul     ecx
  786.     lea     ecx,[eax*4]
  787.  if (Ext = MMX)|(Ext = SSE)
  788.     mov      bh,bl
  789.     push     bx
  790.     shl      ebx,16
  791.     pop      bx
  792.     push     ebx
  793.     push     ebx
  794.     movq     mm0,[esp]
  795.     add      esp,8
  796. else if Ext >=SSE2
  797.     mov      bh,bl
  798.     push     bx
  799.     shl      ebx,16
  800.     pop      bx
  801.     movd     xmm0,ebx
  802.     shufps   xmm0,xmm0,0
  803. end if
  804.  .oop1:
  805. if Ext=NON
  806.     lodsb
  807.     sub     al,bl
  808.     jb      @f
  809.     mov     [esi-1],al
  810.     loop    .oop1
  811.    @@:
  812.     mov     byte[esi-1],0
  813.     loop    .oop1
  814. else if (Ext = MMX)|(Ext=SSE)
  815.     movq    mm1,[esi]
  816.     psubusb mm1,mm0
  817.     movq    [esi],mm1
  818.     add     esi,8
  819.     sub     ecx,8
  820.     jnz     .oop1
  821. else
  822.     movaps  xmm1,[esi]
  823.     psubusb xmm1,xmm0
  824.     movaps  [esi],xmm1
  825.     add     esi,16
  826.     sub     ecx,16
  827.     jnc     .oop1
  828. end if
  829.   .no_dec_bright:
  830.  
  831.  
  832.     RDTSC
  833.     sub eax,[esp]
  834.     sub eax,41
  835. ;    pop     eax
  836.  
  837.     mov     ecx,10
  838.   .dc:
  839.     xor     edx,edx
  840.     mov     edi,10
  841.     div     edi
  842.     add     dl,30h
  843.     mov     [STRdata+ecx-1],dl
  844.     loop    .dc
  845.     pop eax
  846.  
  847.  
  848.     mov     eax,7           ; put image
  849.     mov     ebx,[screen_ptr]
  850.     mov     ecx,[size_y_var]
  851.     mov     edx,[offset_y]
  852.     cmp     [ray_shd_flag],1
  853.     jge     .ff
  854.     cmp     [dr_flag],11
  855.     jge     .ff
  856.     int     0x40
  857.     jmp     .f
  858.   .ff:
  859.     mov     eax,65
  860.     mov     esi,32
  861.     xor     ebp,ebp
  862.     int     0x40
  863.    .f:
  864.     mov  eax,13
  865.     mov  bx,[size_x_var]
  866.     add  ebx,18
  867.     shl  ebx,16
  868.     mov  bx,60
  869.     mov  cx,[size_y_var]
  870.     sub  cx,2
  871.     shl  ecx,16
  872.     mov  cx,9
  873.     xor  edx,edx
  874.     int  40h
  875.  
  876.     mov  eax,4                     ; function 4 : write text to window
  877.     mov  bx,[size_x_var]
  878.     add  ebx,18
  879.     shl  ebx,16
  880.     mov  bx,[size_y_var]
  881.     sub  bx,2         ; [x start] *65536 + [y start]
  882.     mov  ecx,0x00888888
  883.     mov  edx,STRdata               ; pointer to text beginning
  884.     mov  esi,10                    ; text length
  885.     int  40h
  886.  
  887.  
  888.  
  889.    jmp     still
  890.  
  891.  
  892. ;--------------------------------------------------------------------------------
  893. ;-------------------------PROCEDURES---------------------------------------------
  894. ;--------------------------------------------------------------------------------
  895. include "flat_cat.inc"
  896. include "tex_cat.inc"
  897. include "bump_cat.inc"
  898. include "3dmath.inc"
  899. include "grd_line.inc"
  900. include "b_procs.inc"
  901. include "a_procs.inc"
  902. include "chunks.inc"
  903. include "grd_cat.inc"
  904. include "bump_tex.inc"
  905. include "grd_tex.inc"
  906. include "two_tex.inc"
  907. include "asc.inc"
  908. if Ext >= SSE3
  909. include "3r_phg.inc"
  910. include '3stencil.inc'
  911. include '3glass.inc'
  912. include '3glass_tex.inc'
  913. include '3ray_shd.inc'
  914. end if
  915. clear_vertices_index:
  916.     mov   edi,[vertices_index_ptr]
  917.     movzx eax,word[size_x_var]
  918.     movzx ecx,word[size_y_var]
  919.     imul  ecx,eax
  920.     xor   eax,eax
  921.  ;   shr   ecx,1
  922.     rep   stosd
  923. ret
  924.  
  925. edit:     ; mmx required, edit mesh by vertex
  926.         push   ebp
  927.         mov    ebp,esp
  928.         sub    esp,128
  929.  
  930.         .y_coord equ ebp-2
  931.         .x_coord equ ebp-4
  932.         .points_translated equ ebp-10
  933.         .points            equ ebp-26
  934.         .points_rotated    equ ebp-26-16
  935.         .mx                equ ebp-26-56
  936.  
  937.     macro check_bar
  938.     {
  939.         movzx  ebx,word[.x_coord]
  940.         movzx  ecx,word[.y_coord]
  941.         movzx  edx,word[size_x_var]
  942.         imul   edx,ecx
  943.         add    ebx,edx
  944.         mov    ecx,ebx
  945.         shl    ecx,2
  946.         lea    ebx,[ebx*3]
  947.         cmp    [dr_flag],10
  948.         cmovg  ebx,ecx
  949.         add    ebx,[screen_ptr]
  950.         mov    ebx,[ebx]
  951.         and    ebx,0x00ffffff
  952.         cmp    ebx,0x00ff0000 ; is handle bar  ?
  953.     }
  954.  
  955.         emms
  956.         mov     eax,37  ; get mouse state
  957.         mov     ebx,1   ; x = 5, y = 25 - offsets
  958.         int     0x40
  959.  
  960.         mov     ebx,[offset_y] ;5 shl 16 + 25
  961.         movd    mm0,ebx
  962.         movd    mm1,eax
  963.         movd    mm3,[size_y_var]
  964.         pcmpgtw mm0,mm1
  965.         pcmpgtw mm3,mm1
  966.         pxor    mm3,mm0
  967.         pmovmskb eax,mm3
  968.         and     eax,1111b
  969.  
  970.         or      ax,ax
  971.         jz      .no_edit
  972.  
  973.  
  974.         movd    mm0,ebx
  975.         psubw   mm1,mm0
  976.         movd    eax,mm1
  977.  
  978.       ; store both x and y coordinates
  979.         ror    eax,16
  980.         mov    [.x_coord],eax
  981.         test   word[mouse_state],100000000b
  982.         jz     .not_press  ; check if left mouse button press
  983.  
  984.         ;  left button  pressed
  985.  
  986.         check_bar
  987.         jne    .no_edit
  988.         add    ecx,[vertices_index_ptr]
  989.         mov    ecx,[ecx]
  990.       ;  cmp    ecx,-1
  991.       ;  je     .no_edit
  992.  
  993.  
  994.         mov    [vertex_edit_no],ecx ;if vert_edit_no = -1, no vertex selected
  995.  
  996.         mov    eax,dword[.x_coord]
  997.         mov    dword[edit_end_x],eax
  998.         mov    dword[edit_start_x],eax
  999.         jmp    .end
  1000.       .not_press:
  1001.         test   byte[mouse_state],1b       ; check if left button is held
  1002.         jz     .not_held
  1003.        ; check_bar
  1004.        ; jne    .no_edit
  1005.        ; add    ecx,[vertices_index_ptr]
  1006.        ; mov    cx,[ecx]
  1007.        ; inc    cx
  1008.         cmp    [vertex_edit_no],-1 ; cx  ; vertex number
  1009.         je     .end
  1010.         push   dword[.x_coord]
  1011.         pop    dword[edit_end_x]
  1012.         jmp    .end
  1013.       .not_held:
  1014.         shr    [mouse_state],16
  1015.         test   byte[mouse_state],1b  ; test if left button released
  1016.         jz     .end
  1017.         check_bar
  1018.         jne    .end
  1019.  
  1020.         movd        xmm0,[edit_end_x]
  1021.         punpcklwd   xmm0,[the_zero]
  1022.         movd        xmm1,[vect_x]
  1023.         punpcklwd   xmm1,[the_zero]
  1024.    ;     movd        xmm2,[offset_y]
  1025.    ;     punpcklwd   xmm2,[the_zero]
  1026.         psubd       xmm0,xmm1
  1027.    ;     psubd       xmm0,xmm2
  1028.         cvtdq2ps    xmm0,xmm0
  1029.         movups      [.points],xmm0
  1030.  
  1031.  
  1032.         mov     esi,matrix
  1033.         lea     edi,[.mx]
  1034.         call    reverse_mx_3x3
  1035.  
  1036.         lea     esi,[.points]
  1037.         lea     edi,[.points_rotated]
  1038.         lea     ebx,[.mx]
  1039.         mov     ecx,1
  1040.         call    rotary
  1041.  
  1042.    ;    inject into vertex list
  1043.         mov     edi,[vertex_edit_no]
  1044.       ;  dec     edi
  1045.         lea     edi,[edi*3]
  1046.         shl     edi,2
  1047.         add     edi,[points_ptr]
  1048.         lea     esi,[.points_rotated]
  1049.         cld
  1050.         movsd
  1051.         movsd
  1052.         movsd
  1053.  
  1054.         mov    dword[edit_start_x],0
  1055.         mov    dword[edit_end_x],0
  1056.         mov    [vertex_edit_no],-1
  1057.  
  1058.       .no_edit:
  1059.       .end:
  1060.       mov   esp,ebp
  1061.       pop   ebp
  1062. ret
  1063.  
  1064. alloc_buffer_mem:
  1065.     push    ebp
  1066.     mov     ebp,esp
  1067.     .temp   equ ebp-4
  1068.     push    dword 0
  1069.  
  1070.     mov     eax, 68
  1071.     mov     ebx, 11
  1072.     int     0x40    ;  -> create heap, to be sure
  1073.  
  1074.  
  1075.     movzx    ecx,word[size_x_var]
  1076.     movzx    eax,word[size_y_var]
  1077.     mul      ecx
  1078.  
  1079.     mov      [.temp],eax
  1080.     lea      ecx,[eax*4]    ; more mem for r_phg cause
  1081.     add      ecx,256
  1082.     mov      eax,68
  1083.     mov      ebx,20
  1084.     mov      edx,[screen_ptr]
  1085.     int      0x40
  1086.     mov      [screen_ptr],eax
  1087.  
  1088.     mov      ecx,[.temp]
  1089.     shl      ecx,2
  1090.     add      ecx,256
  1091.     mov      eax,68
  1092.     mov      ebx,20
  1093.     mov      edx,[Zbuffer_ptr]
  1094.     int      0x40
  1095.     mov      [Zbuffer_ptr],eax
  1096.  
  1097.  
  1098.     mov      ecx,[.temp]
  1099.     shl      ecx,2
  1100.     add      ecx,256
  1101.     mov      eax,68
  1102.     mov      ebx,20
  1103.     mov      edx,[vertices_index_ptr]
  1104.     int      0x40
  1105.     mov      [vertices_index_ptr],eax
  1106.  
  1107.     mov      esp,ebp
  1108.     pop      ebp
  1109. ret
  1110.  
  1111.  
  1112.  
  1113. update_flags:
  1114. ; updates flags and writing flag description
  1115. ; in    ah - button number
  1116.         push    ax
  1117.         mov     edi,menu
  1118.       .ch_another:
  1119.         cmp     ah,byte[edi]     ; ah = button id
  1120.         jne     @f
  1121.         mov     bl,byte[edi+11]  ; max_flag + 1
  1122.         cmp     bl,255
  1123.         je      .no_write
  1124.         inc     byte[edi+12]     ; flag
  1125.         cmp     byte[edi+12],bl
  1126.         jne     .write
  1127.         mov     byte[edi+12],0
  1128.         jmp     .write
  1129.       @@:
  1130.         add     edi,17
  1131.         cmp     byte[edi],-1
  1132.         jne     .ch_another
  1133.         jmp     .no_write
  1134.      .write:
  1135. ;     clreol   {pascal never dies}
  1136. ;          * eax = 13 - function number
  1137. ;  * ebx = [coordinate on axis x]*65536 + [size on axis x]
  1138. ;  * ecx = [coordinate on axis y]*65536 + [size on axis y]
  1139. ;  * edx = color 0xRRGGBB or 0x80RRGGBB for gradient fill
  1140.  
  1141.         mov     eax,13                           ; function 13 write rectangle
  1142.         movzx   ecx,byte[edi]
  1143.         sub     cl,2
  1144.         lea     ecx,[ecx*3]
  1145.         lea     ecx,[ecx*5]
  1146.         add     ecx,28
  1147.         shl     ecx,16
  1148.         add     ecx,14   ;  ecx = [coord y]*65536 + [size y]
  1149.         mov     bx,[size_x_var]
  1150.         shl     ebx,16
  1151.         add     ebx,(12+70)*65536+25     ; [x start] *65536 + [size x]
  1152.         mov     edx,0x00000000                  ;  color  0x00RRGGBB
  1153.         int     0x40
  1154.  
  1155.         mov     eax,4                           ; function 4 : write text to window
  1156.         movzx   ebx,byte[edi]
  1157.         sub     bl,2
  1158.         lea     ebx,[ebx*3]
  1159.         lea     ebx,[ebx*5]
  1160.         mov     cx,[size_x_var]
  1161.         shl     ecx,16
  1162.         add     ebx,ecx
  1163.         add     ebx,(12+70)*65536+28     ; [x start] *65536 + [y start]
  1164.         mov     ecx,0x00ddeeff                  ; font 1 & color ( 0xF0RRGGBB )
  1165.         movzx   edx,byte[edi+12]                ; current flag
  1166.         shl     edx,2                           ; * 4 = text length
  1167.         add     edx,dword[edi+13]               ; pointer to text beginning
  1168.         mov     esi,4                           ; text length -
  1169.                                                 ; flag description 4 characters
  1170.         int     0x40
  1171.  
  1172.      .no_write:
  1173.         pop     ax
  1174. ret
  1175. normalize_all_light_vectors:
  1176.         mov     edi,lights
  1177.      @@:
  1178.         call    normalize_vector           ;       3dmath.inc
  1179.         add     edi,LIGHT_SIZE
  1180.         cmp     edi,lightsend   ;ecx
  1181.         jl      @b
  1182. ret
  1183.  
  1184. calc_bumpmap_coords:      ; map texture, bump
  1185. ;macro .comment222
  1186. ;                                ; planar mapping
  1187. ;        mov     esi,points
  1188. ;        mov     edi,tex_points
  1189. ;      @@:
  1190. ;         add     esi,2
  1191. ;         movsd
  1192. ;         cmp     dword[esi],dword -1
  1193. ;         jne     @b
  1194.  
  1195. ;      .Pi2  equ dword[ebp-4]
  1196.  
  1197. ;      mov   ebp,esp
  1198. ;      sub   esp,4
  1199.  
  1200.       fninit
  1201.       fldpi
  1202.       fadd      st,st
  1203.       mov       esi,[points_ptr]
  1204.       mov       edi,[tex_points_ptr]
  1205.       mov       ecx,[points_count_var]
  1206.       inc       ecx
  1207. ;      cmp       [map_tex_flag],1
  1208. ;      jne       .cylindric
  1209.       ; spherical mapping around y axle
  1210.  
  1211.    @@:
  1212.       fld       dword[esi]     ; x coord
  1213.       fld       dword[esi+8]   ; z coord
  1214.       fpatan                   ; arctg(st1/st)
  1215. ;      fdiv      .Pi2
  1216.       fdiv      st0,st1
  1217.       fimul     [tex_x_div2]
  1218.       fiadd     [tex_x_div2]
  1219.       fistp     word[edi]      ; x
  1220.  
  1221.       fld       dword[esi+4]   ; y coord
  1222.       fld       dword[esi]     ; x
  1223.       fmul      st,st0
  1224.       fld       dword[esi+4]   ; y
  1225.       fmul      st,st0
  1226.       fld       dword[esi+8]   ; z
  1227.       fmul      st,st0
  1228.       faddp
  1229.       faddp
  1230.       fsqrt
  1231.       fpatan
  1232.       fldpi
  1233.       fdivp
  1234.       fimul    [tex_y_div2]
  1235.       fiadd    [tex_y_div2]
  1236.       fistp    word[edi+2]     ; y
  1237.  
  1238.       add      esi,12
  1239.       add      edi,4
  1240.       loop     @b
  1241.       ffree    st0
  1242. ;      jmp      .end_map
  1243. ;  .cylindric:
  1244. ;       fld     dword[esi]     ; around y axle
  1245. ;       fld     dword[esi+8]
  1246. ;       fpatan
  1247. ;       fdiv    st0,st1
  1248. ;       fimul   [tex_x_div2]
  1249. ;       fiadd   [tex_x_div2]
  1250. ;       fistp   word[edi]
  1251.  
  1252. ;       fld     dword[esi+4]
  1253. ;       fimul   [tex_y_div2]
  1254. ;       fiadd   [tex_y_div2]
  1255. ;       fistp   word[edi+2]
  1256.  
  1257. ;       add     esi,12
  1258. ;       add     edi,4
  1259. ;       loop    .cylindric
  1260. ;       ffree    st0
  1261. ;;      mov      esp,ebp
  1262. ;   .end_map:
  1263. ret
  1264.  
  1265.  
  1266. init_envmap2:         ; do env_map using many light sources
  1267. ;env_map 512 x 512 x 3 bytes
  1268. .temp  equ word   [ebp-2]
  1269. .nEy   equ word  [ebp-4]
  1270. .nEx   equ word  [ebp-6]
  1271. .col_r equ    [ebp-8]
  1272. .col_g equ    [ebp-9]
  1273. .col_b equ    [ebp-10]
  1274.  
  1275.          push     ebp
  1276.          mov      ebp,esp
  1277.          sub      esp,20
  1278.          mov      edi,envmap
  1279.          fninit
  1280.  
  1281.          mov      dx,- TEX_Y / 2 ;256   ; dx - vertical coordinate = y
  1282.     .ie_ver:
  1283.          mov      cx,- TEX_X / 2 ;256   ; cx - horizontal coord = x
  1284.     .ie_hor:
  1285.          xor      ebx,ebx
  1286.          mov      dword .col_b, 0
  1287.      .light:
  1288.          lea      esi,[lights+ebx]
  1289.          fld      dword[esi]     ; light vector x cooficient
  1290.          fimul    [tex_x_div2] ;[i256]
  1291.          mov      .temp,cx
  1292.          fisubr   .temp
  1293.          fistp    .nEx
  1294.          fld      dword[esi+4]   ; light vector y cooficient
  1295.          fimul    [tex_y_div2] ;[i256]
  1296.          mov      .temp,dx
  1297.          fisubr   .temp
  1298.          fistp    .nEy
  1299.  
  1300.          cmp      .nEx,- TEX_X / 2 ;256
  1301.          jl       .update_counters
  1302.          cmp      .nEy,- TEX_Y / 2 ;256
  1303.          jl       .update_counters
  1304.          cmp      .nEx,TEX_X / 2 ;256
  1305.          jg       .update_counters
  1306.          cmp      .nEy,TEX_Y / 2 ;256
  1307.          jg       .update_counters
  1308.  
  1309.          fild     .nEx
  1310.          fmul     st,st0
  1311.          fild     .nEy
  1312.          fmul     st,st0
  1313.          faddp
  1314.          fsqrt
  1315.          fisubr   [i256]
  1316.          fmul     [env_const]
  1317.          fidiv    [i256]   ; st - 'virtual' dot product
  1318.  
  1319.          fcom     [dot_max]
  1320.          fstsw    ax
  1321.          sahf
  1322.          jb       @f
  1323.          ffree    st
  1324.          fld1     ;[dot_max]
  1325.       @@:
  1326.          fcom     [dot_min]
  1327.          fstsw    ax
  1328.          sahf
  1329.          ja       @f
  1330.          ffree    st
  1331.          fldz     ;[dot_min]
  1332.       @@:
  1333.          push     ebp
  1334.          movzx    ax,byte[esi+21]
  1335.          push     ax  ;- shines
  1336.          mov      al,byte[esi+14]   ; b    orginal color
  1337.          push     ax
  1338.          mov      al,byte[esi+13]   ; g
  1339.          push     ax
  1340.          mov      al,byte[esi+12]   ; r
  1341.          push     ax
  1342.          mov      al,byte[esi+20]   ; b     max color
  1343.          push     ax
  1344.          mov      al,byte[esi+19]   ; g
  1345.          push     ax
  1346.          mov      al,byte[esi+18]   ; r
  1347.          push     ax
  1348.          mov      al,byte[esi+17]   ; b    min col
  1349.          push     ax
  1350.          mov      al,byte[esi+16]   ; g
  1351.          push     ax
  1352.          mov      al,byte[esi+15]   ; r
  1353.          push     ax
  1354.          push     eax         ; earlier - dot pr
  1355.       ;  fstp     .dot_product
  1356.       ;  push     .dot_product
  1357.          call     calc_one_col
  1358.          pop      ebp
  1359.          ; eax-0x00rrggbb
  1360.          cmp      al,.col_b
  1361.          jbe      @f
  1362.          mov      .col_b,al
  1363.    @@:                        ;  eax - ggbb00rr
  1364.          shr      ax,8
  1365.          cmp      al,.col_g
  1366.          jbe      @f
  1367.          mov      .col_g,al
  1368.    @@:                        ;  eax - bb0000gg
  1369.          shr      eax,16
  1370.          cmp      al,.col_r
  1371.          jbe      @f
  1372.          mov      .col_r,al
  1373.    @@:
  1374.    .update_counters:                     ; update and jump when neccesery
  1375.          add      ebx,LIGHT_SIZE
  1376.          cmp      bx,[all_lights_size]
  1377.          jl       .light    ; next_light
  1378.          mov      eax,dword .col_b
  1379.          stosd
  1380.          dec      edi
  1381.  
  1382.          inc      cx
  1383.          cmp      cx,TEX_X / 2 ;256
  1384.          jne      .ie_hor
  1385.  
  1386.          inc      dx
  1387.          cmp      dx,TEX_Y / 2 ;256
  1388.          jne     .ie_ver
  1389.  
  1390.          mov     esp,ebp
  1391.          pop     ebp
  1392. ret
  1393.  
  1394.  
  1395.  
  1396. do_color_buffer:         ; do color buffer for Gouraud, flat shading
  1397. ;env_map 512 x 512 x 3 bytes    ; many lights using
  1398. .temp  equ word   [ebp-2]
  1399. .nz    equ dword  [ebp-6]  ; dword
  1400. .ny    equ dword  [ebp-10]
  1401. .nx    equ dword  [ebp-14]
  1402. .col_r equ    [ebp-16]
  1403. .col_g equ    [ebp-17]
  1404. .col_b equ    [ebp-18]
  1405.  
  1406.          push     ebp
  1407.          mov      ebp,esp
  1408.          sub      esp,20
  1409.          mov      edi,color_map
  1410.          fninit
  1411.  
  1412.          mov      dx,- TEX_Y / 2 ;-256   ; dx - vertical coordinate = y
  1413.     .ie_ver:
  1414.          mov      cx,- TEX_X / 2 ;256   ; cx - horizontal coord = x
  1415.     .ie_hor:
  1416.          mov      .temp,cx
  1417.          fild     .temp
  1418.          fidiv    [i256]   ;st = Nx - vector normal x cooficient
  1419.          fst      .nx
  1420.          fmul     st,st0
  1421.          mov      .temp,dx
  1422.          fild     .temp
  1423.          fidiv    [i256]   ; st = Ny - vector normal y coeficient
  1424.          fst      .ny
  1425.          fmul     st,st0
  1426.          faddp
  1427.          fld1
  1428.          fchs
  1429.          faddp
  1430.          fabs
  1431.          fsqrt
  1432.          fchs
  1433.          fstp     .nz              ; st - Nz - vect normal z coeficient
  1434.          xor      ebx,ebx
  1435.          mov      dword .col_b, 0
  1436.      .light:
  1437.          push     edi   ;env_map
  1438.          lea      esi,[lights+ebx]
  1439.          lea      edi,.nx
  1440.          call     dot_product
  1441.          pop      edi
  1442.          fcom     [dot_min]
  1443.          fstsw    ax
  1444.          sahf
  1445.          ja       .env_ok1  ;compare with dot_max
  1446.          ffree    st
  1447.  
  1448.         jmp       .update_counters
  1449.       .env_ok1:
  1450.          fcom    [dot_max]
  1451.          fstsw   ax
  1452.          sahf
  1453.          jb      .env_ok2     ; calc col
  1454.          ffree   st
  1455.          jmp     .update_counters
  1456.       .env_ok2:            ;calc col
  1457.          push     ebp
  1458.          movzx    ax,byte[esi+21]
  1459.          push     ax  ;- shines
  1460.          mov      al,byte[esi+14]   ; b    orginal color
  1461.          push     ax
  1462.          mov      al,byte[esi+13]   ; g
  1463.          push     ax
  1464.          mov      al,byte[esi+12]   ; r
  1465.          push     ax
  1466.          mov      al,byte[esi+20]   ; b     max color
  1467.          push     ax
  1468.          mov      al,byte[esi+19]   ; g
  1469.          push     ax
  1470.          mov      al,byte[esi+18]   ; r
  1471.          push     ax
  1472.          mov      al,byte[esi+17]   ; b    min col
  1473.          push     ax
  1474.          mov      al,byte[esi+16]   ; g
  1475.          push     ax
  1476.          mov      al,byte[esi+15]   ; r
  1477.          push     ax
  1478.          push     eax         ; earlier - dot pr
  1479.       ;  fstp     .dot_product
  1480.       ;  push     .dot_product
  1481.          call     calc_one_col
  1482.          pop      ebp
  1483.          ; eax-0x00rrggbb
  1484.          cmp      al,.col_b
  1485.          jbe      @f
  1486.          mov      .col_b,al
  1487.    @@:
  1488.          shr      ax,8
  1489.          cmp      al,.col_g
  1490.          jbe      @f
  1491.          mov      .col_g,al
  1492.    @@:
  1493.          shr      eax,16
  1494.          cmp      al,.col_r
  1495.          jbe      @f
  1496.          mov      .col_r,al
  1497.   @@:
  1498.  .update_counters:                                  ; update and jump when neccesery
  1499.         add     ebx,LIGHT_SIZE
  1500.         cmp     bx,[all_lights_size]
  1501.         jl      .light    ; next_light
  1502.         mov     eax,dword .col_b
  1503.         stosd
  1504.         dec     edi
  1505.  
  1506.         inc     cx
  1507.         cmp     cx,TEX_X / 2 ;256
  1508.         jne     .ie_hor
  1509.  
  1510.         inc     dx
  1511.         cmp     dx,TEX_X / 2 ;256
  1512.         jne     .ie_ver
  1513.  
  1514.     .env_done:
  1515.          mov     esp,ebp
  1516.          pop     ebp
  1517. ret
  1518.  
  1519. if   Ext >= SSE2
  1520. init_point_normals:
  1521. ;in:
  1522. ;    esi - tri_ch
  1523. ;    edi - t_ptr
  1524. ;    ax =  1 -> old style finding normals
  1525. .z equ dword [ebp-8]
  1526. .y equ dword [ebp-12]
  1527. .x equ [ebp-16]
  1528. .point_number equ dword [ebp-28]
  1529. .hit_faces    equ dword [ebp-32]
  1530. .t_ptr        equ dword [ebp-36]
  1531. .tri_ch       equ dword [ebp-40]
  1532. .max_val      equ dword [ebp-44]
  1533. .mark         equ word  [ebp-45]
  1534.  
  1535.         push      ebp
  1536.         mov       ebp,esp
  1537.         sub       esp,64
  1538.         and       ebp,-16
  1539.         mov       .t_ptr,edi
  1540.         mov       .tri_ch,esi
  1541.  
  1542. ;        mov       .mark,ax
  1543.         bt        ax,0
  1544.         jc        .old1
  1545.  
  1546.  
  1547.         mov       ecx,[triangles_count_var]
  1548.         shl       ecx,3
  1549.         lea       ecx,[ecx*3]
  1550.         add       ecx,.tri_ch
  1551.         mov       .max_val,ecx
  1552.         xor       edx,edx
  1553.  
  1554.      .lp1:
  1555.         mov       ebx,edx
  1556.         shl       ebx,2
  1557.         add       ebx,.t_ptr
  1558.         mov       esi,[ebx]
  1559.         or        esi,esi
  1560.         jz        .old
  1561.  
  1562.         xorps     xmm1,xmm1
  1563.         xor       ecx,ecx
  1564.      @@:
  1565.         mov       eax,[esi+4] ; eax - tri index
  1566.         mov       ebx,[esi]
  1567.         imul      eax,[i12]
  1568.         add       eax,[triangles_normals_ptr]
  1569.         movups    xmm0,[eax]
  1570.         inc       ecx
  1571.         addps     xmm1,xmm0
  1572.         add       esi,8
  1573.         cmp       esi,.max_val   ; some objects need this check
  1574.         ja        .old           ;old method
  1575.         cmp       ebx,[esi]
  1576.         je        @b
  1577.  
  1578.         cvtsi2ss xmm2,ecx
  1579.         rcpss    xmm2,xmm2
  1580.         shufps   xmm2,xmm2,0
  1581.         mulps    xmm1,xmm2
  1582.         mov      edi,edx
  1583.         imul     edi,[i12]
  1584.         add      edi,[points_normals_ptr]
  1585.         movlps   [edi],xmm1
  1586.         movhlps  xmm1,xmm1
  1587.         movss    [edi+8],xmm1
  1588.         call      normalize_vector
  1589.  
  1590.         inc      edx
  1591.         cmp      edx,[points_count_var]
  1592.         jnz      .lp1
  1593.  
  1594.         jmp      .end
  1595.  
  1596.       .old1:
  1597.  
  1598.         xor     edx,edx
  1599.  
  1600.       .old:
  1601.  
  1602.         mov       edi,[points_normals_ptr]
  1603.         mov       .point_number,edx
  1604.     .ipn_loop:
  1605.         movd      xmm0,.point_number
  1606.         pshufd    xmm0,xmm0,0
  1607.         mov       .hit_faces,0
  1608.         mov       .x,dword 0
  1609.         mov       .y,0
  1610.         mov       .z,0
  1611.         mov       esi,[triangles_ptr]
  1612.         xor       ecx,ecx              ; ecx - triangle number
  1613.     .ipn_check_face:
  1614.         movdqu    xmm1,[esi]
  1615.         pcmpeqd   xmm1,xmm0
  1616.         pmovmskb  eax,xmm1
  1617.         and       eax,0xfff
  1618.         or        eax,eax
  1619.         jz        .ipn_next_face
  1620.         push      esi
  1621.         mov       esi,ecx
  1622.         lea       esi,[esi*3]
  1623.         shl       esi,2
  1624.         add       esi,[triangles_normals_ptr]
  1625.         movups    xmm7,[esi]
  1626.         addps     xmm7,.x
  1627.         movaps    .x,xmm7
  1628.         pop       esi
  1629.         inc       .hit_faces
  1630.  
  1631.      .ipn_next_face:
  1632.         add       esi,12
  1633.         inc       ecx
  1634.         cmp       ecx,[triangles_count_var]
  1635.         jne       .ipn_check_face
  1636.         cvtsi2ss  xmm6,.hit_faces
  1637.         movaps    xmm7,.x
  1638.  
  1639.         rcpss     xmm6,xmm6
  1640.         shufps    xmm6,xmm6,11000000b
  1641.         mulps     xmm7,xmm6
  1642.         movlps    [edi],xmm7
  1643.         movhlps   xmm7,xmm7
  1644.         movss     [edi+8],xmm7
  1645.         call      normalize_vector
  1646.     ;    movaps    xmm6,xmm7
  1647.     ;    mulps     xmm6,xmm6
  1648.     ;    andps     xmm6,[zero_hgst_dd]
  1649.     ;    haddps    xmm6,xmm6
  1650.     ;    haddps    xmm6,xmm6
  1651.     ;    rsqrtps    xmm6,xmm6
  1652.     ;    mulps     xmm7,xmm6
  1653.     ;    movlps    [edi],xmm7
  1654.     ;    movhlps   xmm7,xmm7
  1655.     ;    movss     [edi+8],xmm7
  1656.  
  1657.         add       edi,12
  1658.         inc       .point_number
  1659.         mov       edx,.point_number
  1660.         cmp       edx,[points_count_var]
  1661.         jne       .ipn_loop
  1662.  ;       cmp       .mark,1
  1663.  ;       je        .end1
  1664.  ;        always free if Ext>=SSE2
  1665.      .end:
  1666.  
  1667.         mov     eax,68
  1668.         mov     ebx,13
  1669.         mov     ecx,.t_ptr
  1670.         int     0x40
  1671.  
  1672.         mov     eax,68
  1673.         mov     ebx,13
  1674.         mov     ecx,.tri_ch
  1675.         int     0x40
  1676.  
  1677.   ;   .end1:
  1678.  
  1679.  
  1680.         add       esp,64
  1681.         pop       ebp
  1682. ret
  1683. else
  1684. init_point_normals:
  1685. .x equ dword [ebp-4]
  1686. .y equ dword [ebp-8]
  1687. .z equ dword [ebp-12]
  1688. .point_number equ dword [ebp-28]
  1689. .hit_faces    equ dword [ebp-32]
  1690.  
  1691.         fninit
  1692.         mov       ebp,esp
  1693.         sub       esp,32
  1694.         mov       edi,[points_normals_ptr]
  1695.         mov       .point_number,0
  1696.     .ipn_loop:
  1697.         mov       .hit_faces,0
  1698.         mov       .x,0
  1699.         mov       .y,0
  1700.         mov       .z,0
  1701.         mov       esi,[triangles_ptr]
  1702.         xor       ecx,ecx              ; ecx - triangle number
  1703.     .ipn_check_face:
  1704.         xor       ebx,ebx              ; ebx - 'position' in one triangle
  1705.     .ipn_check_vertex:
  1706.         mov       eax,dword[esi+ebx]    ;  eax - point_number
  1707.         cmp       eax,.point_number
  1708.         jne       .ipn_next_vertex
  1709.         push      esi
  1710.         mov       esi,ecx
  1711.         lea       esi,[esi*3]
  1712.        ; lea       esi,[triangles_normals+esi*4]
  1713.         shl       esi,2
  1714.         add       esi,[triangles_normals_ptr]
  1715.  
  1716.         fld       .x
  1717.         fadd      dword[esi+vec_x]       ; vec_x this defined in 3dmath.asm - x cooficient
  1718.         fstp      .x                     ; of normal vactor
  1719.         fld       .y
  1720.         fadd      dword[esi+vec_y]
  1721.         fstp      .y
  1722.         fld       .z
  1723.         fadd      dword[esi+vec_z]
  1724.         fstp      .z
  1725.         pop       esi
  1726.         inc       .hit_faces
  1727.         jmp       .ipn_next_face
  1728.     .ipn_next_vertex:
  1729.         add       ebx,4
  1730.         cmp       ebx,12
  1731.         jne       .ipn_check_vertex
  1732.     .ipn_next_face:
  1733.         add       esi,12
  1734.         inc       ecx
  1735.         cmp       ecx,[triangles_count_var]
  1736.         jne       .ipn_check_face
  1737.  
  1738.         fld       .x
  1739.         fidiv     .hit_faces
  1740.         fstp      dword[edi+vec_x]
  1741.         fld       .y
  1742.         fidiv     .hit_faces
  1743.         fstp      dword[edi+vec_y]
  1744.         fld       .z
  1745.         fidiv     .hit_faces
  1746.         fstp      dword[edi+vec_z]
  1747.         call      normalize_vector
  1748.         add       edi,12  ;type vector 3d
  1749.         inc       .point_number
  1750.         mov       edx,.point_number
  1751.         cmp       edx,[points_count_var]
  1752.         jne       .ipn_loop
  1753.  
  1754.         mov       esp,ebp
  1755. ret
  1756. ;===============================================================
  1757. end if
  1758. init_triangles_normals2:
  1759.         mov     ebx,[triangles_normals_ptr]
  1760.         mov     ebp,[triangles_ptr]
  1761.         mov     ecx,[triangles_count_var]
  1762.      @@:
  1763.         push    ecx
  1764.         push    ebx
  1765.         mov     ebx,vectors
  1766.         mov     esi,dword[ebp]          ; first point index
  1767.         lea     esi,[esi*3]
  1768. ;        lea     esi,[points+esi*2]     ; esi - pointer to 1st 3d point
  1769.         shl     esi,2
  1770.         add     esi,[points_ptr]
  1771.         mov     edi,dword[ebp+4]          ; first point index
  1772.         lea     edi,[edi*3]
  1773.         shl     edi,2
  1774.         add     edi,[points_ptr]
  1775. ;        movzx   edi,word[ebp+2]        ; second point index
  1776. ;        lea     edi,[edi*3]
  1777. ;        lea     edi,[points+edi*2]     ; edi - pointer to 2nd 3d point
  1778.         call    make_vector_r
  1779.         add     ebx,12
  1780.         mov     esi,edi
  1781.         mov     edi,dword[ebp+8]        ; third point index
  1782.         lea     edi,[edi*3]
  1783.         shl     edi,2
  1784.         add     edi,[points_ptr]
  1785. ;        lea     edi,[points+edi*2]
  1786.         call    make_vector_r
  1787.         mov     edi,ebx                 ; edi - pointer to 2nd vector
  1788.         mov     esi,ebx
  1789.         sub     esi,12                  ; esi - pointer to 1st vector
  1790.         pop     ebx
  1791.         call    cross_product
  1792.         mov     edi,ebx
  1793.         call    normalize_vector
  1794.         add     ebp,12
  1795.         add     ebx,12
  1796.         pop     ecx
  1797.         sub     ecx,1
  1798.         jnz     @b
  1799. ret
  1800.  
  1801.  
  1802. copy_lights: ; after normalising !
  1803.         mov      esi,lights
  1804.         mov      edi,lights_aligned
  1805.         mov      ecx,3
  1806.        .again:
  1807.         push     ecx
  1808.         mov      ecx,3
  1809.         cld
  1810.         rep      movsd
  1811.         xor      eax,eax
  1812.         stosd
  1813.         mov      ecx,3
  1814.       .b:
  1815.         push     ecx
  1816.         mov      ecx,3
  1817.       @@:
  1818.         movzx    ebx,byte[esi]
  1819.         cvtsi2ss xmm0,ebx
  1820.         movss    [edi],xmm0
  1821.         inc      esi
  1822.         add      edi,4
  1823.         loop     @b
  1824.         stosd
  1825.         pop      ecx
  1826.         loop     .b
  1827.         inc      esi  ; skip  shiness
  1828.         pop      ecx
  1829.         loop     .again
  1830. ret
  1831.  
  1832.  
  1833. clrscr:
  1834.         mov     edi,[screen_ptr]
  1835.         movzx   ecx,word[size_x_var]
  1836.         movzx   eax,word[size_y_var]
  1837.         imul    ecx,eax
  1838.         cld
  1839.         xor     eax,eax
  1840.   ;    if Ext=NON
  1841.         rep     stosd
  1842. ;      else if Ext = MMX
  1843. ;        pxor    mm0,mm0
  1844.  ;     @@:
  1845.  ;       movq    [edi+00],mm0
  1846. ;        movq    [edi+08],mm0
  1847. ;        movq    [edi+16],mm0
  1848.  ;       movq    [edi+24],mm0
  1849.  ;       add     edi,32
  1850.  ;       sub     ecx,8
  1851.  ;       jnc     @b
  1852.  ;     else
  1853.  ;       push    ecx
  1854.  ;       mov     ecx,edi
  1855.  ;       and     ecx,0x0000000f
  1856.  ;       rep     stosb
  1857.  ;       pop     ecx
  1858.  ;       and     ecx,0xfffffff0
  1859.  ;       xorps   xmm0,xmm0
  1860.  ;     @@:
  1861.  ;       movaps  [edi],xmm0
  1862.  ;       movaps  [edi+16],xmm0
  1863.  ;       movaps  [edi+32],xmm0
  1864.  ;       movaps  [edi+48],xmm0
  1865.  ;       add     edi,64
  1866.  ;       sub     ecx,16
  1867.  ;       jnz     @b
  1868.  ;     end if
  1869.  
  1870. ret
  1871.  
  1872.  
  1873. draw_triangles:
  1874. ;  in:  eax - render draw model
  1875.         .tri_no          equ dword[ebp-60]
  1876.         .point_index3    equ [ebp-8]
  1877.         .point_index2    equ [ebp-12]
  1878.         .point_index1    equ [ebp-16]
  1879.         .yy3             equ [ebp-18]
  1880.         .xx3             equ [ebp-20]
  1881.         .yy2             equ [ebp-22]
  1882.         .xx2             equ [ebp-24]
  1883.         .yy1             equ [ebp-26]
  1884.         .xx1             equ [ebp-28]
  1885.  
  1886.         .zz3             equ [ebp-30]
  1887.         .zz2             equ [ebp-32]
  1888.         .zz1             equ [ebp-34]
  1889.         .index3x12       equ [ebp-38]
  1890.         .index2x12       equ [ebp-42]
  1891.         .index1x12       equ [ebp-46]
  1892.         .temp1           equ dword[ebp-50]
  1893.         .temp2           equ dword[ebp-54]
  1894.         .dr_flag         equ word[ebp-56]
  1895.  
  1896.  
  1897.         push    ebp
  1898.         mov     ebp,esp
  1899.         sub     esp,64
  1900.  
  1901.  ;       movzx   ax,[dr_flag]
  1902.         mov     .dr_flag,ax
  1903.  
  1904.  
  1905.         emms
  1906.       ;  update translated list  MMX required
  1907.         cmp     [vertex_edit_no],-1
  1908.         je      @f
  1909.         mov     eax,[vertex_edit_no]
  1910.       ;  dec     eax
  1911.         movd    mm0,[edit_end_x]
  1912.         psubw   mm0,[edit_start_x]
  1913.         lea     eax,[eax*3]
  1914.         add     eax,eax
  1915.         add     eax,[points_translated_ptr]
  1916.         movd    mm1,dword[eax]
  1917.         paddw   mm1,mm0
  1918.         movd    dword[eax],mm1
  1919.      @@:
  1920.      if Ext >= SSE3
  1921.  
  1922.         cmp     .dr_flag,13
  1923.         jnge    .no_stencil
  1924.         mov     esi,[triangles_ptr]
  1925.         mov     ecx,[triangles_count_var]
  1926.      @@:
  1927.         push    esi
  1928.         push    ecx
  1929.  
  1930.         mov     eax,[esi]
  1931.         mov     ebx,[esi+4]
  1932.         mov     ecx,[esi+8]
  1933.         imul    eax,[i12]
  1934.         imul    ebx,[i12]
  1935.         imul    ecx,[i12]
  1936.         add     eax,[points_rotated_ptr]
  1937.         add     ebx,[points_rotated_ptr]
  1938.         add     ecx,[points_rotated_ptr]
  1939.         push    dword[ecx+8]
  1940.         push    dword[ebx+8]
  1941.         push    dword[eax+8]
  1942.         movups  xmm0,[esp]
  1943.         add     esp,12
  1944.         andps   xmm0,[zero_hgst_dd]
  1945.  
  1946.  
  1947.         mov     eax,[esi]
  1948.         mov     ebx,[esi+4]
  1949.         mov     ecx,[esi+8]
  1950.         shl     eax,1
  1951.         shl     ebx,1
  1952.         shl     ecx,1
  1953.         lea     eax,[eax*3]
  1954.         lea     ebx,[ebx*3]
  1955.         lea     ecx,[ecx*3]
  1956.         add     eax,[points_translated_ptr]
  1957.         add     ebx,[points_translated_ptr]
  1958.         add     ecx,[points_translated_ptr]
  1959.         mov     eax,[eax]
  1960.         mov     ebx,[ebx]
  1961.         mov     ecx,[ecx]
  1962.         ror     eax,16
  1963.         ror     ebx,16
  1964.         ror     ecx,16
  1965.  
  1966.  
  1967.         mov     esi,[Zbuffer_ptr]
  1968.  
  1969.         call    stencil_tri
  1970.  
  1971.         pop     ecx
  1972.         pop     esi
  1973.         add     esi,12
  1974.         dec     ecx
  1975.         jnz     @b
  1976.  
  1977.       .no_stencil:
  1978.       end if
  1979.  
  1980.  
  1981.         cmp     [dr_flag],11
  1982.         je      .draw_smooth_line
  1983.  
  1984.         mov esi,[triangles_ptr]
  1985.         xor ecx,ecx  ;mov ecx,[triangles_count_var]
  1986.     .again_dts:
  1987.        ; push    ebp
  1988.         push    esi
  1989.         push    ecx
  1990.         mov     .tri_no,ecx
  1991.  
  1992.         mov     eax,[esi]
  1993.         mov     ebx,[esi+4]
  1994.         mov     ecx,[esi+8]
  1995.  
  1996.         mov     .point_index1,eax
  1997.         mov     .point_index2,ebx
  1998.         mov     .point_index3,ecx
  1999.         imul    eax,[i12]
  2000.         imul    ebx,[i12]
  2001.         imul    ecx,[i12]
  2002.         mov     .index1x12,eax
  2003.         mov     .index2x12,ebx
  2004.         mov     .index3x12,ecx
  2005.  
  2006.         shr     eax,1
  2007.         shr     ebx,1
  2008.         shr     ecx,1
  2009.         add     eax,[points_translated_ptr]
  2010.         add     ebx,[points_translated_ptr]
  2011.         add     ecx,[points_translated_ptr]
  2012.         push    word[eax+4]
  2013.         push    word[ebx+4]
  2014.         push    word[ecx+4]
  2015.         pop     word .zz3
  2016.         pop     word .zz2
  2017.         pop     word .zz1
  2018.  
  2019.         mov     eax,[eax]
  2020.         mov     ebx,[ebx]
  2021.         mov     ecx,[ecx]
  2022.         ror     eax,16
  2023.         ror     ebx,16
  2024.         ror     ecx,16
  2025.         mov     .xx1,eax
  2026.         mov     .xx2,ebx
  2027.         mov     .xx3,ecx
  2028.  
  2029.  
  2030.  
  2031.       ;  push    esi
  2032.         fninit                            ; DO culling AT FIRST
  2033.         cmp     [culling_flag],1          ; (if culling_flag = 1)
  2034.         jne     .no_culling
  2035.         lea     esi,.point_index1          ; *********************************
  2036.         mov     ecx,3                     ;
  2037.       @@:
  2038.         mov     eax,dword[esi]
  2039.         lea     eax,[eax*3]
  2040.         shl     eax,2
  2041.         add     eax,[points_normals_rot_ptr]
  2042.         mov     eax,[eax+8]
  2043.         bt      eax,31
  2044.         jc      @f
  2045.                        ; *****************************
  2046.                        ; CHECKING OF Z COOFICIENT OF
  2047.                        ; NORMAL VECTOR
  2048.         add     esi,4
  2049.         loop    @b
  2050.         jmp     .end_draw   ; non visable
  2051.       @@:
  2052.  
  2053.       .no_culling:
  2054.         cmp     .dr_flag,0               ; draw type flag
  2055.         je      .flat_draw
  2056.         cmp     .dr_flag,2
  2057.         je      .env_mapping
  2058.         cmp     .dr_flag,3
  2059.         je      .bump_mapping
  2060.         cmp     .dr_flag,4
  2061.         je      .tex_mapping
  2062.         cmp     .dr_flag,5
  2063.         je      .rainbow
  2064.         cmp     .dr_flag,7
  2065.         je      .grd_tex
  2066.         cmp     .dr_flag,8
  2067.         je      .two_tex
  2068.         cmp     .dr_flag,9
  2069.         je      .bump_tex
  2070.         cmp     .dr_flag,10
  2071.         je      .cubic_env_mapping
  2072.         cmp     .dr_flag,11
  2073.         je      .draw_smooth_line
  2074.       if Ext >= SSE3
  2075.         cmp     .dr_flag,12
  2076.         je      .r_phg
  2077.         cmp     .dr_flag,13
  2078.         je      .glass
  2079.         cmp     .dr_flag,14
  2080.         je      .glass_tex
  2081.         cmp     .dr_flag,100
  2082.         je      .ray_shd
  2083.  
  2084.      end if
  2085.  
  2086.         push    ebp                    ; ****************
  2087.         lea     esi,.index3x12      ; do Gouraud shading
  2088.         lea     edi,.zz3
  2089.         mov     ecx,3
  2090.       .again_grd_draw:
  2091.         mov     eax,dword[esi]
  2092.         add     eax,[points_normals_rot_ptr]
  2093.         ; texture x=(rotated point normal -> x * 255)+255
  2094.         fld     dword[eax]       ; x cooficient of normal vector
  2095.         fimul   [correct_tex]
  2096.         fiadd   [correct_tex]
  2097.         fistp   .temp1
  2098.         ; texture y=(rotated point normal -> y * 255)+255
  2099.         fld     dword[eax+4]      ; y cooficient
  2100.         fimul   [correct_tex]
  2101.         fiadd   [correct_tex]
  2102.         fistp   .temp2
  2103.  
  2104.         mov      eax,.temp2
  2105.         mov      ebx,.temp1
  2106.         and      ebx,0xfffffff
  2107.         shl      eax,TEX_SHIFT
  2108.         add      eax,ebx
  2109.         lea      eax,[eax*3+color_map]
  2110.         mov      eax,dword[eax]
  2111.         push     word[edi]    ; zz1 ,2 ,3
  2112.  
  2113.         ror      eax,16               ; eax -0xxxrrggbb -> 0xggbbxxrr
  2114.         xor      ah,ah
  2115.         push     ax         ;r
  2116.         rol      eax,8                ; eax-0xggbb00rr -> 0xbb00rrgg
  2117.         xor      ah,ah
  2118.         push     ax         ;g
  2119.         shr      eax,24
  2120.         push     ax         ;b
  2121.  
  2122.         sub      esi,4
  2123.         sub      edi,2
  2124.         dec      cx
  2125.         jnz      .again_grd_draw
  2126.         jmp      .both_draw
  2127.  
  2128.    .rainbow:
  2129.         push     ebp
  2130.         push     word .zz3
  2131.  
  2132.         mov      eax, .xx3
  2133.         ror      eax,16
  2134.         mov      ebx,0x00ff00ff
  2135.         and      eax,ebx
  2136.         push     eax
  2137.         neg      al
  2138.         push     ax
  2139.         push     word .zz2
  2140.  
  2141.         mov      eax, .xx2
  2142.         ror      eax,16
  2143.         and      eax,ebx
  2144.         push     eax
  2145.         neg      al
  2146.         push     ax
  2147.         push     word .zz1
  2148.  
  2149.         mov      eax, .xx1
  2150.         ror      eax,16
  2151.         and      eax,ebx
  2152.         push     eax
  2153.         neg      al
  2154.         push     ax
  2155.     .both_draw:
  2156.         mov     eax, .xx1
  2157.         mov     ebx, .xx2
  2158.         mov     ecx, .xx3
  2159.         mov     edi,[screen_ptr]
  2160.         mov     esi,[Zbuffer_ptr]
  2161.         call    gouraud_triangle_z
  2162.         pop     ebp
  2163.         jmp     .end_draw
  2164.  
  2165.      .flat_draw:                     ;**************************
  2166.         fninit                             ; FLAT DRAWING
  2167.         mov     eax,.index1x12
  2168.         mov     ebx,.index2x12
  2169.         mov     ecx,.index3x12
  2170.         add     eax,[points_normals_rot_ptr]
  2171.         add     ebx,[points_normals_rot_ptr]
  2172.         add     ecx,[points_normals_rot_ptr]
  2173.         fld     dword[eax]      ; x cooficient of normal vector
  2174.         fadd    dword[ebx]
  2175.         fadd    dword[ecx]
  2176.         fidiv   [i3]
  2177.         fimul   [correct_tex]
  2178.         fiadd   [correct_tex]
  2179.         fistp   .temp1  ;dword[esp-4]    ; x temp variables
  2180.         fld     dword[eax+4]    ; y cooficient of normal vector
  2181.         fadd    dword[ebx+4]
  2182.         fadd    dword[ecx+4]
  2183.         fidiv   [i3]
  2184.         fimul   [correct_tex]
  2185.         fiadd   [correct_tex]
  2186.         fistp   .temp2  ;dword[esp-8]   ;  y
  2187.         mov     edx,.temp2 ;dword[esp-8]
  2188.         and     edx,0xfffffff
  2189.         and     .temp1,0xfffffff
  2190.         shl     edx,TEX_SHIFT
  2191.         add     edx,.temp1  ;dword[esp-4]
  2192.  
  2193.         lea     eax,[3*edx]
  2194.         add     eax,color_map
  2195.         mov     edx,dword[eax]
  2196.  
  2197.         and     edx,0x00ffffff    ; edx = 0x00rrggbb
  2198.  
  2199.  
  2200.  
  2201.      ;   mov     ax,[zz1]      ; z position depend draw
  2202.      ;   add     ax,[zz2]
  2203.      ;   add     ax,[zz3]
  2204.      ;   cwd
  2205.      ;   idiv    [i3] ;    = -((a+b+c)/3+130)
  2206.      ;   add     ax,130
  2207.      ;   neg     al
  2208.      ;   xor     edx,edx
  2209.      ;   mov     ah,al           ;set color according to z position
  2210.      ;   shl     eax,8
  2211.      ;   mov     edx,eax
  2212.  
  2213.         mov     eax,dword .xx1
  2214.         mov     ebx,dword .xx2
  2215.         mov     ecx,dword .xx3
  2216.         mov     edi,[screen_ptr]
  2217.  
  2218.         mov     esi,[Zbuffer_ptr]
  2219.         push    ebp
  2220.         push    word .zz3
  2221.         push    word .zz2
  2222.         push    word .zz1
  2223.         call    flat_triangle_z
  2224.         pop     ebp
  2225.         jmp     .end_draw
  2226.  
  2227.       .env_mapping:
  2228.         push    ebp
  2229.         push    word .zz3
  2230.         push    word .zz2
  2231.         push    word .zz1
  2232.  
  2233.         lea     esi, .index1x12
  2234.         sub     esp,12
  2235.         mov     edi,esp
  2236.         mov     ecx,3
  2237.       @@:
  2238.         mov     eax,dword[esi]
  2239.         add     eax,[points_normals_rot_ptr]       ;point_normals_rotated
  2240.         ; texture x=(rotated point normal -> x * 255)+255
  2241.         fld     dword[eax]
  2242.         fimul   [correct_tex]
  2243.         fiadd   [correct_tex]
  2244.         fistp   word[edi]
  2245.         ; texture y=(rotated point normal -> y * 255)+255
  2246.         fld     dword[eax+4]
  2247.         fimul   [correct_tex]
  2248.         fiadd   [correct_tex]
  2249.         fistp   word[edi+2]
  2250.  
  2251.         add     edi,4
  2252.         add     esi,4
  2253.         loop    @b
  2254.  
  2255.         mov     eax, .xx1
  2256.         mov     ebx,dword .xx2
  2257.         mov     ecx,dword .xx3
  2258.         mov     edi,[screen_ptr]
  2259.         mov     esi,envmap
  2260.  
  2261.         mov     edx,[Zbuffer_ptr]
  2262.         call    tex_triangle_z
  2263.         pop     ebp
  2264.         jmp     .end_draw
  2265. ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2266.      .cubic_env_mapping:
  2267.         push    ebp
  2268.         push    word .zz3
  2269.         push    word .zz2
  2270.         push    word .zz1
  2271.  
  2272.         lea     esi,.index1x12
  2273.         sub     esp,12
  2274.         mov     edi,esp
  2275.         mov     ecx,3
  2276.       @@:
  2277.         mov     eax,dword[esi]
  2278.         add     eax,[points_normals_rot_ptr]
  2279.  
  2280.         fld     dword[eax]
  2281.         fmul    dword[eax+4]
  2282.         fld1
  2283.         fld1
  2284.         faddp
  2285.         fmulp
  2286.         fimul   [correct_tex]
  2287.         fiadd   [correct_tex]
  2288.         fistp   word[edi]
  2289.         mov     word[edi+2],0
  2290. ;        fistp   word[edi+2]
  2291. ; # last change
  2292. ;        ; texture x=(rotated point normal -> x * 255)+255
  2293. ;        fld     dword[eax]
  2294. ;        fimul   [correct_tex]
  2295. ;        fiadd   [correct_tex]
  2296. ;        fistp   word[edi]
  2297. ;        ; texture y=(rotated point normal -> y * 255)+255
  2298. ;        fld     dword[eax+4]
  2299. ;        fimul   [correct_tex]
  2300. ;        fiadd   [correct_tex]
  2301. ;        fistp   word[edi+2]
  2302. ; # end of last ch.
  2303.         add     edi,4
  2304.         add     esi,4
  2305.         loop    @b
  2306.  
  2307.         mov     eax, .xx1
  2308.         mov     ebx, .xx2
  2309.         mov     ecx, .xx3
  2310.         mov     edi,[screen_ptr]
  2311.         mov     esi,envmap_cub
  2312.         mov     edx,[Zbuffer_ptr]
  2313.  
  2314.         call    tex_triangle_z
  2315.         pop     ebp
  2316.         jmp     .end_draw
  2317.  
  2318. ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2319.  
  2320.       .bump_mapping:
  2321.         push    ebp
  2322.         push    [Zbuffer_ptr]
  2323.         push    word .zz3
  2324.         push    word .zz2
  2325.         push    word .zz1
  2326.  
  2327.         lea     esi,.index1x12
  2328.         sub     esp,12
  2329.         mov     edi,esp
  2330.         mov     ecx,3
  2331.       @@:
  2332.         mov     eax,dword[esi]
  2333.         add     eax,[points_normals_rot_ptr]  ;point_normals_rotated
  2334.         ; texture x=(rotated point normal -> x * 255)+255
  2335.         fld     dword[eax]
  2336.         fimul   [correct_tex]
  2337.         fiadd   [correct_tex]
  2338.         fistp   word[edi]
  2339.         ; texture y=(rotated point normal -> y * 255)+255
  2340.         fld     dword[eax+4]
  2341.         fimul   [correct_tex]
  2342.         fiadd   [correct_tex]
  2343.         fistp   word[edi+2]
  2344.  
  2345.         add     edi,4
  2346.         add     esi,4
  2347.         loop    @b
  2348.  
  2349.         mov    esi, .point_index3      ; bump map coords
  2350.         shl    esi,2
  2351.         add    esi,[tex_points_ptr]
  2352.         push   dword[esi]
  2353.         mov    esi, .point_index2
  2354.         shl    esi,2
  2355.         add    esi,[tex_points_ptr]
  2356.         push   dword[esi]
  2357.         mov    esi, .point_index1
  2358.         shl    esi,2
  2359.         add    esi,[tex_points_ptr]
  2360.         push   dword[esi]
  2361.  
  2362.         mov     eax,dword .xx1
  2363.         mov     ebx,dword .xx2
  2364.         mov     ecx,dword .xx3
  2365.         mov     edi,[screen_ptr]
  2366.         mov     esi,envmap
  2367.         mov     edx,bumpmap            ;BUMP_MAPPING
  2368.  
  2369.         call    bump_triangle_z
  2370.         pop     ebp
  2371.         jmp     .end_draw
  2372.  
  2373.       .tex_mapping:
  2374.         push   ebp
  2375.         push   word .zz3
  2376.         push   word .zz2
  2377.         push   word .zz1
  2378.    ;   @@:
  2379.         mov    esi, .point_index3      ; tex map coords
  2380.         shl    esi,2
  2381.         add    esi,[tex_points_ptr]
  2382.         push   dword[esi]
  2383.         mov    esi, .point_index2
  2384.         shl    esi,2
  2385.         add    esi,[tex_points_ptr]
  2386.         push   dword[esi]
  2387.         mov    esi, .point_index1
  2388.         shl    esi,2
  2389.         add    esi,[tex_points_ptr]
  2390.         push   dword[esi]
  2391.  
  2392.         mov     eax,dword .xx1
  2393.         mov     ebx,dword .xx2
  2394.         mov     ecx,dword .xx3
  2395.         mov     edi,[screen_ptr]
  2396.         mov     esi,texmap
  2397.         mov     edx,[Zbuffer_ptr]
  2398.  
  2399.         call    tex_triangle_z
  2400.         pop     ebp
  2401.         jmp     .end_draw
  2402. ;      .ray:
  2403. ;        grd_triangle according to points index
  2404. ;        cmp     [catmull_flag],0
  2405. ;        je      @f
  2406. ;        push    [zz3]                   ; spot light with attenuation
  2407. ;     @@:
  2408. ;        movzx   eax,[point_index3]      ; env_map - points color list
  2409. ;        shl     eax,1                   ; each color as word, 0x00rr00gg00bb..
  2410. ;        lea     eax,[3*eax+bumpmap]
  2411. ;        push    word[eax]
  2412. ;        push    word[eax+2]
  2413. ;        push    word[eax+4]
  2414. ;        cmp     [catmull_flag],0
  2415. ;        je      @f
  2416. ;        push    [zz2]
  2417. ;    @@:
  2418. ;        movzx   eax,[point_index2]      ; env_map - points color list
  2419. ;        shl     eax,1                   ; each color as word, 0x00rr00gg00bb..
  2420. ;        lea     eax,[eax*3+bumpmap]
  2421. ;        push    word[eax]
  2422. ;        push    word[eax+2]
  2423. ;        push    word[eax+4]
  2424. ;        cmp     [catmull_flag],0
  2425. ;        je      @f
  2426. ;        push    [zz1]
  2427. ;     @@:
  2428. ;        movzx   eax,[point_index1]      ; env_map - points color list
  2429. ;        shl     eax,1                   ; each color as word, 0xrr00gg00bb00..
  2430. ;        lea     eax,[eax*3+bumpmap]
  2431. ;        push    word[eax]
  2432. ;        push    word[eax+2]
  2433. ;        push    word[eax+4]
  2434. ;        jmp     .both_draw
  2435.  
  2436.      .grd_tex:            ; smooth shading + texture
  2437.          push   ebp
  2438.  
  2439.          mov    esi, .point_index3      ; tex map coords
  2440.          shl    esi,2
  2441.          add    esi,[tex_points_ptr]
  2442.          push   dword[esi]              ; texture coords as first
  2443.          mov    esi, .point_index2      ; group of parameters
  2444.          shl    esi,2
  2445.          add    esi,[tex_points_ptr]
  2446.          push   dword[esi]
  2447.          mov    esi, .point_index1
  2448.          shl    esi,2
  2449.          add    esi,[tex_points_ptr]
  2450.          push   dword[esi]
  2451.  
  2452.          lea     esi, .index3x12
  2453.          lea     edi, .zz3
  2454.          mov     ecx,3
  2455.        .aagain_grd_draw:
  2456.  
  2457.         push     word[edi]    ; zz1 ,2 ,3
  2458.         fninit
  2459.         mov     eax,dword[esi]
  2460.         add     eax,[points_normals_rot_ptr]
  2461.         ; texture x=(rotated point normal -> x * 255)+255
  2462.         fld     dword[eax]       ; x cooficient of normal vector
  2463.         fimul   [correct_tex]
  2464.         fiadd   [correct_tex]
  2465.         fistp   .temp1  ;word[ebp-2]
  2466.         ; texture y=(rotated point normal -> y * 255)+255
  2467.         fld     dword[eax+4]      ; y cooficient
  2468.         fimul   [correct_tex]
  2469.         fiadd   [correct_tex]
  2470.         fistp   .temp2  ;word[ebp-4]
  2471.  
  2472.         mov      eax,.temp2
  2473.         mov      ebx,.temp1
  2474.         and      ebx,0xfffffff ; some onjects need this 'and'
  2475.         shl      eax,TEX_SHIFT
  2476.         add      eax,ebx
  2477.         lea      eax,[eax*3]
  2478.         add      eax,color_map
  2479.         mov      eax,dword[eax]
  2480.  
  2481.         ror      eax,16               ; eax -0xxxrrggbb -> 0xggbbxxrr
  2482.         xor      ah,ah
  2483.         push     ax         ;r
  2484.         rol      eax,8                ; eax-0xggbb00rr -> 0xbb00rrgg
  2485.         xor      ah,ah
  2486.         push     ax         ;g
  2487.         shr      eax,24
  2488.         push     ax         ;b
  2489.         sub      edi,2
  2490.         sub      esi,4
  2491.         dec      cx
  2492.         jnz      .aagain_grd_draw
  2493.  
  2494.         mov     eax, .xx1
  2495.         mov     ebx, .xx2
  2496.         mov     ecx, .xx3
  2497.         mov     edi,[screen_ptr]
  2498.         mov     edx,texmap
  2499.         mov     esi,[Zbuffer_ptr]
  2500.  
  2501.         call    tex_plus_grd_triangle
  2502.  
  2503.         pop     ebp
  2504.         jmp     .end_draw
  2505.  
  2506.       .two_tex:
  2507.         push     ebp
  2508.         push    [Zbuffer_ptr]
  2509.  
  2510.         push    word .zz3
  2511.         push    word .zz2
  2512.         push    word .zz1
  2513.  
  2514.         fninit
  2515.         lea     esi, .point_index3     ; env coords
  2516.         mov     edi,esp
  2517.         sub     esp,24
  2518.         mov     ecx,3
  2519.       @@:
  2520.         mov     eax,dword[esi]
  2521.         shl     eax,2
  2522.         mov     ebx,eax
  2523.   ;      mov     ebx,eax
  2524.         add     ebx,[tex_points_ptr]
  2525.         mov     ebx,[ebx]
  2526.         mov     [edi-8],ebx
  2527.         lea     eax,[eax*3]
  2528.         add     eax,[points_normals_rot_ptr]
  2529.         ; texture x=(rotated point normal -> x * 255)+255
  2530.         fld     dword[eax]
  2531.         fimul   [correct_tex]
  2532.         fiadd   [correct_tex]
  2533.         fistp   word[edi-4]
  2534.         and     word[edi-4],0x7fff   ; some objects need it
  2535.         ; texture y=(rotated point normal -> y * 255)+255
  2536.         fld     dword[eax+4]
  2537.         fimul   [correct_tex]
  2538.         fiadd   [correct_tex]
  2539.         fistp   word[edi-2]
  2540.         and     word[edi-2],0x7fff  ; some objects need it
  2541.  
  2542.         sub     edi,8
  2543.         sub     esi,4
  2544.         loop    @b
  2545.  
  2546.         mov     eax, .xx1
  2547.         mov     ebx, .xx2
  2548.         mov     ecx, .xx3
  2549.         mov     edi,[screen_ptr]
  2550.         mov     esi,texmap
  2551.         mov     edx,envmap
  2552.  
  2553.         call    two_tex_triangle_z
  2554.         pop     ebp
  2555.         jmp     .end_draw
  2556.  
  2557.    .bump_tex:
  2558.         push   ebp
  2559.         fninit
  2560.  
  2561.         push  dword texmap
  2562.  
  2563.         push  [Zbuffer_ptr]
  2564.  
  2565.         push    word .zz3
  2566.         push    word .zz2
  2567.         push    word .zz1
  2568.  
  2569.  
  2570.         lea     ebx, .point_index1
  2571.         sub     esp,36
  2572.         mov     edi,esp
  2573.         mov     ecx,3
  2574.       @@:
  2575.         mov     eax,[ebx]
  2576.         shl     eax,2
  2577.         mov     esi,eax
  2578.         lea     esi,[esi*3]
  2579.         add     eax,[tex_points_ptr]
  2580.         mov     eax,[eax]
  2581.         ror     eax,16
  2582.         mov     [edi],eax
  2583.         mov     [edi+8],eax
  2584.  
  2585.         add     esi,[points_normals_rot_ptr]
  2586.         ; texture x=(rotated point normal -> x * 255)+255
  2587.         fld     dword[esi]
  2588.         fimul   [correct_tex]
  2589.         fiadd   [correct_tex]
  2590.         fistp   word[edi+6]             ; env coords
  2591.         ; texture y=(rotated point normal -> y * 255)+255
  2592.         fld     dword[esi+4]
  2593.         fimul   [correct_tex]
  2594.         fiadd   [correct_tex]
  2595.         fistp   word[edi+4]
  2596.         add     ebx,4
  2597.         add     edi,12
  2598.         loop    @b
  2599.  
  2600.         mov     eax,dword .xx1
  2601.         mov     ebx,dword .xx2
  2602.         mov     ecx,dword .xx3
  2603.         mov     edi,[screen_ptr]
  2604.         mov     esi,envmap
  2605.         mov     edx,bumpmap
  2606.  
  2607.         call bump_tex_triangle_z
  2608.         pop     ebp
  2609.         jmp     .end_draw
  2610.  
  2611.  
  2612. if Ext >= SSE3
  2613.      .r_phg:
  2614.  
  2615.  
  2616.         movd      xmm5,[size_y_var]
  2617.         punpcklwd xmm5,[the_zero]
  2618.         pshufd    xmm5,xmm5,01110011b
  2619.  
  2620.  
  2621.         mov     eax, .index1x12
  2622.         mov     ebx, .index2x12
  2623.         mov     ecx, .index3x12
  2624.         add     eax,[points_normals_rot_ptr]
  2625.         add     ebx,[points_normals_rot_ptr]
  2626.         add     ecx,[points_normals_rot_ptr]
  2627.         movups  xmm0,[eax]
  2628.         movups  xmm1,[ebx]
  2629.         movups  xmm2,[ecx]
  2630.         andps   xmm0,[zero_hgst_dd]
  2631.         andps   xmm1,[zero_hgst_dd]
  2632.         andps   xmm2,[zero_hgst_dd]
  2633.         xorps   xmm3,xmm3
  2634.  
  2635.         mov     eax, .index1x12
  2636.         mov     ebx, .index2x12
  2637.         mov     ecx, .index3x12
  2638.         add     eax,[points_rotated_ptr]
  2639.         add     ebx,[points_rotated_ptr]
  2640.         add     ecx,[points_rotated_ptr]
  2641.         push    dword[ecx+8]
  2642.         push    dword[ebx+8]
  2643.         push    dword[eax+8]
  2644.         movups  xmm4,[esp]
  2645.         add     esp,12
  2646.         andps   xmm4,[zero_hgst_dd]
  2647.  
  2648.  
  2649.  
  2650.         mov     eax,dword .xx1
  2651.         mov     ebx,dword .xx2
  2652.         mov     ecx,dword .xx3
  2653.         mov     edi,[screen_ptr]
  2654.         mov     esi,[Zbuffer_ptr]
  2655.  
  2656.         call    real_phong_tri_z
  2657.  
  2658.         jmp     .end_draw
  2659.  
  2660.      .glass:
  2661.         movd      xmm5,[size_y_var]
  2662.         punpcklwd xmm5,[the_zero]
  2663.         pshufd    xmm5,xmm5,01110011b
  2664.  
  2665.  
  2666.         mov     eax, .index1x12
  2667.         mov     ebx, .index2x12
  2668.         mov     ecx, .index3x12
  2669.         add     eax,[points_normals_rot_ptr]
  2670.         add     ebx,[points_normals_rot_ptr]
  2671.         add     ecx,[points_normals_rot_ptr]
  2672.         movups  xmm0,[eax]
  2673.         movups  xmm1,[ebx]
  2674.         movups  xmm2,[ecx]
  2675.         andps   xmm0,[zero_hgst_dd]
  2676.         andps   xmm1,[zero_hgst_dd]
  2677.         andps   xmm2,[zero_hgst_dd]
  2678.         xorps   xmm3,xmm3
  2679.  
  2680.         mov     eax, .index1x12
  2681.         mov     ebx, .index2x12
  2682.         mov     ecx, .index3x12
  2683.         add     eax,[points_rotated_ptr]
  2684.         add     ebx,[points_rotated_ptr]
  2685.         add     ecx,[points_rotated_ptr]
  2686.         push    dword[ecx+8]
  2687.         push    dword[ebx+8]
  2688.         push    dword[eax+8]
  2689.         movups  xmm4,[esp]
  2690.         add     esp,12
  2691.         andps   xmm4,[zero_hgst_dd]
  2692.  
  2693.  
  2694.  
  2695.         mov     eax, .xx1
  2696.         mov     ebx, .xx2
  2697.         mov     ecx, .xx3
  2698.         mov     edi,[screen_ptr]
  2699.         mov     edx,[Zbuffer_ptr]
  2700.         mov     esi,[Zbuffer_ptr]
  2701.  
  2702.         call    glass_tri
  2703.         jmp     .end_draw
  2704.  
  2705.  
  2706.    .glass_tex:
  2707.         movd      xmm5,[size_y_var]
  2708.         punpcklwd xmm5,[the_zero]
  2709.         pshufd    xmm5,xmm5,01110011b
  2710.  
  2711.         mov     eax, .index1x12
  2712.         mov     ebx, .index2x12
  2713.         mov     ecx, .index3x12
  2714.         add     eax,[points_normals_rot_ptr]
  2715.         add     ebx,[points_normals_rot_ptr]
  2716.         add     ecx,[points_normals_rot_ptr]
  2717.         movups  xmm0,[eax]
  2718.         movups  xmm1,[ebx]
  2719.         movups  xmm2,[ecx]
  2720.         andps   xmm0,[zero_hgst_dd]
  2721.         andps   xmm1,[zero_hgst_dd]
  2722.         andps   xmm2,[zero_hgst_dd]
  2723.         xorps   xmm3,xmm3
  2724.  
  2725.         mov     eax, .index1x12
  2726.         mov     ebx, .index2x12
  2727.         mov     ecx, .index3x12
  2728.         add     eax,[points_rotated_ptr]
  2729.         add     ebx,[points_rotated_ptr]
  2730.         add     ecx,[points_rotated_ptr]
  2731.         push    dword[ecx+8]
  2732.         push    dword[ebx+8]
  2733.         push    dword[eax+8]
  2734.         movups  xmm4,[esp]
  2735.         add     esp,12
  2736.         andps   xmm4,[zero_hgst_dd]
  2737.  
  2738.         mov    esi,.point_index3      ; tex map coords
  2739.         shl    esi,2
  2740.         add    esi,[tex_points_ptr]
  2741.         push   dword[esi]
  2742.         mov    esi,.point_index2
  2743.         shl    esi,2
  2744.         add    esi,[tex_points_ptr]
  2745.         push   dword[esi]
  2746.         mov    esi,.point_index1
  2747.         shl    esi,2
  2748.         add    esi,[tex_points_ptr]
  2749.         push   dword[esi]
  2750.         movups xmm6,[esp]
  2751.         add    esp,12
  2752.      ;   pshuflw xmm6,xmm6,10110001b
  2753.      ;   pshufhw xmm6,xmm6,10110001b
  2754.  
  2755.         movzx  eax,word[size_x_var]
  2756.         andps  xmm6,[zero_hgst_dd]
  2757.         movd   xmm7,eax
  2758.         pslldq xmm7,12
  2759.         por    xmm6,xmm7
  2760.  
  2761.  
  2762.         mov     eax,dword .xx1
  2763.         mov     ebx,dword .xx2
  2764.         mov     ecx,dword .xx3
  2765.         mov     edx,texmap
  2766.         mov     edi,[screen_ptr]
  2767.         mov     esi,[Zbuffer_ptr]
  2768.  
  2769.         call    glass_tex_tri
  2770.         jmp     .end_draw
  2771.  
  2772.    .ray_shd:
  2773.         emms
  2774.         movd      xmm5,[size_y_var]
  2775.         punpcklwd xmm5,[the_zero]
  2776.         pshufd    xmm5,xmm5,01110011b
  2777.  
  2778.         mov     eax, .index1x12
  2779.         mov     ebx, .index2x12
  2780.         mov     ecx, .index3x12
  2781.         add     eax,[points_normals_rot_ptr]
  2782.         add     ebx,[points_normals_rot_ptr]
  2783.         add     ecx,[points_normals_rot_ptr]
  2784.         movups  xmm0,[eax]
  2785.         movups  xmm1,[ebx]
  2786.         movups  xmm2,[ecx]
  2787.         andps   xmm0,[zero_hgst_dd]
  2788.         andps   xmm1,[zero_hgst_dd]
  2789.         andps   xmm2,[zero_hgst_dd]
  2790.         xorps   xmm3,xmm3
  2791.  
  2792.    ;     mov     ebx,.tri_no
  2793.    ;     cmp     ebx,0
  2794.    ;     je      @f
  2795.    ;     int3
  2796.    ;   @@:
  2797.  
  2798.         mov     eax, .index1x12
  2799.         mov     ebx, .index2x12
  2800.         mov     ecx, .index3x12
  2801.         add     eax,[points_rotated_ptr]
  2802.         add     ebx,[points_rotated_ptr]
  2803.         add     ecx,[points_rotated_ptr]
  2804.         push    dword[ecx+8]
  2805.         push    dword[ebx+8]
  2806.         push    dword[eax+8]
  2807.         movups  xmm4,[esp]
  2808.         add     esp,12
  2809.         andps   xmm4,[zero_hgst_dd]
  2810.  
  2811.         movd    mm7,.tri_no
  2812.  
  2813.    ;     mm7 - intialised
  2814.  
  2815.  
  2816.         mov     eax,dword .xx1
  2817.         mov     ebx,dword .xx2
  2818.         mov     ecx,dword .xx3
  2819.         mov     edx,texmap
  2820.         mov     edi,[screen_ptr]
  2821.         mov     esi,[Zbuffer_ptr]
  2822.  
  2823.         call    ray_shad
  2824.  
  2825.  
  2826.  
  2827. end if
  2828.  
  2829.       .end_draw:
  2830.     ;    pop     ebp
  2831.         pop     ecx
  2832.         pop     esi
  2833.  
  2834.         add     esi,12
  2835.         inc     ecx
  2836.         cmp     ecx,[triangles_count_var]
  2837.         jnz     .again_dts
  2838.  
  2839.         jmp     .eend
  2840.  
  2841.  
  2842.  
  2843.    .draw_smooth_line:
  2844.         mov     esi,[edges_ptr]
  2845.         xor     ecx,ecx
  2846.     .again_s_line:
  2847.         push    ecx
  2848.         push    esi
  2849.  
  2850.         mov     ecx,2
  2851.      .aga_n:
  2852.         mov     eax,[esi]
  2853.         shl     eax,2
  2854.         lea     eax,[eax*3]
  2855.         add     eax,[points_normals_rot_ptr]
  2856.         movups   xmm0,[eax]
  2857.         xorps    xmm1,xmm1
  2858.         mov      edx,lights_aligned
  2859.     .again_cc:
  2860.         movaps    xmm3,xmm0   ;.cnv
  2861.         mulps     xmm3,[edx]
  2862.         andps     xmm3,[zero_hgst_dd]
  2863.    ;     haddps    xmm3,xmm3
  2864.    ;     haddps    xmm3,xmm3   ; xmm3 - dot pr
  2865.         movhlps   xmm2,xmm3
  2866.         addps     xmm3,xmm2
  2867.         movdqa    xmm2,xmm3
  2868.         shufps    xmm2,xmm2,01010101b
  2869.         addps     xmm3,xmm2
  2870.         shufps    xmm3,xmm3,0
  2871.         movaps    xmm6,xmm3   ;xmm7
  2872.         mulps     xmm6,xmm6
  2873.         mulps     xmm6,xmm6
  2874.         mulps     xmm6,xmm6
  2875.         mulps     xmm6,xmm6
  2876.         mulps     xmm6,xmm6
  2877.         mulps     xmm6,[edx+48]
  2878.         movaps    xmm7,xmm3
  2879.         mulps     xmm7,[edx+16]
  2880.         addps     xmm7,xmm6
  2881.         addps     xmm7,[edx+32]
  2882.         minps     xmm7,[mask_255f]   ; global
  2883.  
  2884.         maxps     xmm1,xmm7
  2885.         add       edx,64     ; size of one light in aligned list
  2886.         cmp       edx,lights_aligned_end
  2887.         jl        .again_cc
  2888.         sub       esp,16
  2889.         movups    [esp],xmm1
  2890.         add       esi,4
  2891.         dec       ecx
  2892.         jnz      .aga_n
  2893.  
  2894.         movups    xmm0,[esp]
  2895.         movups    xmm1,[esp+16]
  2896.         add       esp,32
  2897.         sub       esi,8
  2898.  
  2899.         mov     ecx,[esi]
  2900.         mov     edx,[esi+4]
  2901.         imul    ecx,[i6]
  2902.         imul    edx,[i6]
  2903.         add     ecx,[points_translated_ptr]
  2904.         add     edx,[points_translated_ptr]
  2905.  
  2906.         movd    xmm7,[ecx]
  2907.         movhps  xmm7,[edx]
  2908.         pshufd  xmm7,xmm7,11101000b
  2909.         movdqa  xmm6,xmm7
  2910.         movdqa  xmm3,xmm7
  2911.         movdqa  xmm4,xmm7
  2912.         movd    xmm5,[size_y_var]
  2913.         pshuflw xmm5,xmm5,00010001b
  2914.         pcmpeqw xmm3,xmm5
  2915.         pcmpeqw xmm4,[the_zero]
  2916.         pcmpgtw xmm7,xmm5
  2917.         pcmpgtw xmm6,[the_zero]
  2918.         pxor    xmm7,xmm6
  2919.         pxor    xmm3,xmm4
  2920.         pxor    xmm7,xmm3
  2921.         pmovmskb eax,xmm7
  2922.         cmp     al,-1
  2923.         jnz      .skp
  2924.  
  2925.  
  2926.  
  2927.  
  2928.         mov     eax,[esi]
  2929.         mov     ebx,[esi+4]
  2930.         imul    eax,[i12]
  2931.         imul    ebx,[i12]
  2932.         add     eax,[points_rotated_ptr]
  2933.         add     ebx,[points_rotated_ptr]
  2934.         movss   xmm2,[eax+8]
  2935.         movss   xmm3,[ebx+8]
  2936.  
  2937.  
  2938.         movzx   eax,word[ecx]
  2939.         movzx   ebx,word[ecx+2]
  2940.         movzx   ecx,word[edx]
  2941.         movzx   edx,word[edx+2]
  2942.  
  2943.         emms
  2944.         movd    mm1,[screen_ptr]
  2945.         movd    mm0,[Zbuffer_ptr]
  2946.         movzx   esi,word[size_x_var]
  2947.         movd    mm2,esi
  2948.  
  2949.         push    ebp
  2950.         call    line_grd
  2951.         pop     ebp
  2952.       .skp:
  2953.         pop     esi
  2954.         pop     ecx
  2955.         add     esi,8
  2956.         inc     ecx
  2957.         cmp     ecx,[edges_count]
  2958.         jnz     .again_s_line
  2959.  
  2960.  
  2961.  
  2962.  
  2963.  
  2964.  
  2965.    .eend:
  2966.         add      esp,64
  2967.         pop      ebp
  2968.  
  2969. ret
  2970.  
  2971.  
  2972. draw_handlers:
  2973.  
  2974.        ;  in eax - render model
  2975.         push  ebp
  2976.         mov   ebp,esp
  2977.         emms
  2978.        .fac         equ  dword[ebp-16]
  2979.        .xplus_scr    equ ebp-8
  2980.        .xplus_index  equ ebp-12
  2981.        .dr_model equ dword[ebp-4]
  2982.  
  2983.        sub     esp,16
  2984.        mov     .dr_model,eax
  2985.  
  2986.        movzx   eax,word[size_x_var]
  2987.        cmp    .dr_model,10
  2988.        jg     @f
  2989.        lea    ebx,[eax*3]
  2990.        sub    ebx,3*6
  2991.        mov    [.xplus_scr],ebx   ; for scr 1st cause
  2992.        mov    .fac,3
  2993.        jmp    .in_r
  2994.     @@:
  2995.        lea    ebx,[eax*4]       ; for scr 2cond cause
  2996.        sub    ebx,4*6
  2997.        mov    [.xplus_scr],ebx
  2998.        mov    .fac,4
  2999.      .in_r:
  3000.  
  3001.        lea    ebx,[eax*4]
  3002.        sub    ebx,4*6
  3003.        mov    [.xplus_index],ebx  ; index
  3004.  
  3005.        xor    ecx,ecx
  3006.        mov    eax,4 shl 16 + 4
  3007.        movd   xmm0,[size_y_var]
  3008.        movd   xmm1,eax
  3009.        psubw  xmm0,xmm1
  3010.        pshuflw xmm0,xmm0,00000001b
  3011.  
  3012.      .l:
  3013.        push    ecx
  3014.        cmp     [culling_flag],1         ; (if culling_flag = 1)
  3015.        jne     .no_culling
  3016.        mov     edi,ecx           ; *********************************
  3017.        lea     edi,[edi*3]
  3018.        shl     edi,2
  3019.        add     edi,[points_normals_rot_ptr]
  3020.        bt      dword[edi+8],31
  3021.        jnc     .skip
  3022.      .no_culling:
  3023.        mov     esi,ecx
  3024.        lea     esi,[esi*3]
  3025.        add     esi,esi
  3026.        add     esi,[points_translated_ptr]
  3027.        movd    xmm2,[esi]
  3028.        movd    xmm3,[esi]
  3029.        pcmpgtw xmm2,xmm0
  3030.        pcmpgtw xmm3,xmm1
  3031.        pxor    xmm3,xmm2
  3032.        movd     eax,xmm3
  3033.        cmp      eax,-1
  3034.        jne      .skip
  3035.  
  3036.        movzx   eax,word[esi]
  3037.        movzx   ebx,word[esi+2]
  3038.        sub     eax,2
  3039.        sub     ebx,2
  3040.        movzx   edx, word[size_x_var]
  3041.        imul    ebx,edx
  3042.        add     ebx,eax
  3043.        mov     edi,ebx
  3044.        imul    ebx,.fac
  3045.        shl     edi,2
  3046.        add     ebx,[screen_ptr]
  3047.        add     edi,[vertices_index_ptr]
  3048.        mov     eax,ecx
  3049.        cld
  3050.        mov     ecx,6
  3051.     .l2:
  3052.        push    ecx
  3053.        mov     ecx,6       ; draw bar
  3054.     .l1:
  3055.        mov     word[ebx],0
  3056.        mov     byte[ebx+2],0xff
  3057.        stosd
  3058.        add     ebx,.fac
  3059.        loop    .l1
  3060.        add     ebx,[.xplus_scr]
  3061.        add     edi,[.xplus_index]
  3062.        pop     ecx
  3063.        loop    .l2
  3064.      .skip:
  3065.        pop      ecx
  3066.        inc      ecx
  3067.        cmp      ecx,[points_count_var]
  3068.        jna      .l
  3069.  
  3070.        mov      esp,ebp
  3071.        pop      ebp
  3072. ret
  3073.  
  3074.  
  3075.  
  3076. fill_Z_buffer:
  3077.         mov     eax,0x70000000
  3078.         cmp     [dr_flag],11
  3079.         jl      @f
  3080.         mov     eax,60000.1
  3081.     @@:
  3082.         mov     edi,[Zbuffer_ptr]
  3083.         movzx   ecx,word[size_x_var]
  3084.         movzx   ebx,word[size_y_var]
  3085.         imul    ecx,ebx
  3086.       if     Ext>=SSE2
  3087.         movd    xmm0,eax
  3088.         shufps  xmm0,xmm0,0
  3089.         push    ecx
  3090.         mov     ecx,edi
  3091.         and     edi,0xffffff00
  3092.         and     ecx,0x000000ff
  3093.         mov     edx,ecx
  3094.         rep     stosd
  3095.         pop     ecx
  3096.         sub     ecx,edx
  3097.       @@:
  3098.         movaps  [edi],xmm0
  3099.         movaps  [edi+16],xmm0
  3100.         movaps  [edi+32],xmm0
  3101.         movaps  [edi+48],xmm0
  3102.         add     edi,64
  3103.         sub     ecx,16
  3104.         jnc     @b
  3105.       else
  3106.         rep     stosd
  3107.       end if
  3108. ret
  3109.  
  3110. read_tp_variables:            ; read [triangles_count_var] and  [points_count_var]
  3111.                               ; and  allocate memory
  3112.         xor     ebx,ebx
  3113.         xor     ebp,ebp
  3114.         mov     [points_count_var],ebx
  3115.         mov     [triangles_count_var],ebx
  3116.         mov     esi,[fptr]
  3117.  
  3118.         cmp     [esi],word 4D4Dh
  3119.         je      @f ;Must be legal .3DS file
  3120.         xor     eax,eax
  3121.         ret
  3122.     @@:
  3123.         mov     eax,dword[esi+2]
  3124.         cmp     eax,[fsize] ;This must tell the length
  3125.         je      @f
  3126.         xor     eax,eax
  3127.         ret
  3128.      @@:
  3129.         add     eax,esi
  3130.         mov     [EndFile],eax    ;
  3131.  
  3132.         add     esi,6
  3133.       @@:
  3134.         cmp     [esi],word 3D3Dh
  3135.         je      @f
  3136.         add     esi,[esi+2]
  3137.         jmp     @b
  3138.       @@:
  3139.         add     esi,6
  3140.       .find4k:
  3141.         cmp     [esi],word 4000h
  3142.         je      @f
  3143.         add     esi,[esi+2]
  3144.         cmp     esi,[EndFile]
  3145.         jc      .find4k
  3146.         jmp     .exit
  3147.       @@:
  3148.         add     esi,6
  3149.       @@:
  3150.         cmp     [esi],byte 0
  3151.         je      @f
  3152.         inc     esi
  3153.         jmp     @b
  3154.       @@:
  3155.         inc     esi
  3156.       @@:
  3157.         cmp     [esi],word 4100h
  3158.         je      @f
  3159.         add     esi,[esi+2]
  3160.         jmp     @b
  3161.       @@:
  3162.         add     esi,6
  3163.       @@:
  3164.         cmp     [esi],word 4110h
  3165.         je      @f
  3166.         add     esi,[esi+2]
  3167.         jmp     @b
  3168.       @@:
  3169.         movzx   ecx,word[esi+6]
  3170.         add     [points_count_var],ecx
  3171.  
  3172.         mov     edx,ecx
  3173.         add     esi,8
  3174.      @@:
  3175.         lea     ecx,[ecx*3]
  3176.         add     ecx,ecx
  3177.         add     ebx,ecx
  3178.         add     ecx,ecx
  3179.         add     esi,ecx
  3180.      ;   dec     ecx
  3181.       ;  loop     @b
  3182.       @@:
  3183.  
  3184.       @@:
  3185.         cmp     [esi],word 4120h
  3186.         je      @f
  3187.         add     esi,[esi+2]
  3188.         jmp     @b
  3189.       @@:
  3190.         movzx   ecx,word[esi+6]
  3191.         add     [triangles_count_var],ecx
  3192.         add     esi,8
  3193.  
  3194.       @@:
  3195.         shl     ecx,3
  3196.         add     esi,ecx
  3197.        ; dec     ecx
  3198.        ; jnz     @b
  3199.        ; loop    @b
  3200. ;        xor     ecx,ecx
  3201.         add     ebp,edx
  3202.         jmp     .find4k
  3203.         mov     eax,-1 ;<---mark if OK
  3204.       .exit:
  3205. ret
  3206.  
  3207. read_from_file:
  3208.         fninit
  3209.         mov     edi,[triangles_ptr]
  3210.         xor     ebx,ebx
  3211.         xor     ebp,ebp
  3212.         mov     [points_count_var],0
  3213.         mov     [triangles_count_var],0
  3214.         mov     esi,[fptr]
  3215.         cmp     [esi],word 4D4Dh
  3216.         jne     .exit ;Must be legal .3DS file
  3217. ;        cmp     dword[esi+2],EndFile-SourceFile
  3218. ;        jne     .exit ;This must tell the length
  3219.         mov     eax,dword[esi+2]
  3220.   ;      cmp     eax,[fsize]
  3221.   ;      jne     .exit
  3222.  
  3223.         add     eax,esi
  3224.         mov     [EndFile],eax    ;
  3225.  
  3226.         add     esi,6
  3227.       @@:
  3228.         cmp     [esi],word 3D3Dh
  3229.         je      @f
  3230.         add     esi,[esi+2]
  3231.         jmp     @b
  3232.       @@:
  3233.         add     esi,6
  3234.       .find4k:
  3235.         cmp     [esi],word 4000h
  3236.         je      @f
  3237.         add     esi,[esi+2]
  3238.         cmp     esi,[EndFile]
  3239.         jc      .find4k
  3240.         jmp     .exit
  3241.       @@:
  3242.         add     esi,6
  3243.       @@:
  3244.         cmp     [esi],byte 0
  3245.         je      @f
  3246.         inc     esi
  3247.         jmp     @b
  3248.       @@:
  3249.         inc     esi
  3250.       @@:
  3251.         cmp     [esi],word 4100h
  3252.         je      @f
  3253.         add     esi,[esi+2]
  3254.         jmp     @b
  3255.       @@:
  3256.         add     esi,6
  3257.       @@:
  3258.         cmp     [esi],word 4110h
  3259.         je      @f
  3260.         add     esi,[esi+2]
  3261.         jmp     @b
  3262.       @@:
  3263.         movzx   ecx,word[esi+6]
  3264.         add     [points_count_var],ecx
  3265.  
  3266.         mov     edx,ecx
  3267.         add     esi,8
  3268.      @@:
  3269.         push    edi
  3270.         mov     edi,[points_ptr]
  3271.         push    dword[esi+0]
  3272.         pop     dword[edi+ebx*2+0]
  3273.         push    dword[esi+4]
  3274.         pop     dword[edi+ebx*2+4]
  3275.         push    dword[esi+8]
  3276.         pop     dword[edi+ebx*2+8]
  3277.         pop     edi
  3278.  
  3279.         add     ebx,6
  3280.         add     esi,12
  3281.        ; dec     ecx
  3282.        ; jnz     @b
  3283.         loop    @b
  3284.       @@:
  3285.   ;      mov     dword[points+ebx],-1
  3286.         push    edi
  3287.         mov     edi,[points_ptr]
  3288.         mov     dword[edi+ebx*2],-1        ; end mark (not always in use)
  3289.         pop     edi
  3290.       @@:
  3291.         cmp     [esi],word 4120h
  3292.         je      @f
  3293.         add     esi,[esi+2]
  3294.         jmp     @b
  3295.       @@:
  3296.         movzx   ecx,word[esi+6]
  3297.         add     [triangles_count_var],ecx
  3298.         add     esi,8
  3299.         ;mov     edi,triangles
  3300.       @@:
  3301.         movzx   eax,word[esi]
  3302.         stosd
  3303.         movzx   eax,word[esi+2]
  3304.         stosd
  3305.         movzx   eax,word[esi+4]
  3306.         stosd
  3307.         add     dword[edi-12],ebp
  3308.         add     dword[edi-8],ebp
  3309.         add     dword[edi-4],ebp
  3310.         add     esi,8
  3311.     ;    dec     ecx
  3312.     ;    jnz     @b
  3313.         loop    @b
  3314.         add     ebp,edx
  3315.         jmp     .find4k
  3316.         mov     eax,-1 ;<---mark if OK
  3317.       .exit:
  3318.         mov     dword[edi],-1
  3319. ret
  3320.  
  3321.  
  3322. alloc_mem_for_tp:
  3323. ;in:        bl = 1 - realloc
  3324.         mov     eax, 68
  3325.         cmp     bl,1
  3326.         jz      @f
  3327.         mov     ebx, 12
  3328.         jmp     .alloc
  3329.     @@:
  3330.         mov     ebx,20
  3331.     .alloc:
  3332.  
  3333.         mov     ecx,[triangles_count_var]
  3334.         add     ecx,20
  3335.         lea     ecx, [ecx*3]
  3336.         shl     ecx,2
  3337.         mov     edx,[triangles_ptr]
  3338.         int     0x40                   ;  -> allocate memory to triangles
  3339.         mov     [triangles_ptr], eax   ;  -> eax = pointer to allocated mem
  3340.  
  3341. ;        mov     eax, 68
  3342. ;        mov     ecx,[triangles_count_var]
  3343. ;        imul    ecx,[i36]
  3344. ;        mov     edx,[edges_ptr]
  3345. ;        int     0x40                   ;  -> allocate memory to triangles
  3346. ;        mov     [edges_ptr], eax   ;  -> eax = pointer to allocated mem
  3347.  
  3348.  
  3349.                                             ; ststic  memory
  3350.  
  3351.         mov     eax, 68
  3352.         mov     ecx, [triangles_count_var]
  3353.         lea     ecx, [6+ecx*3]
  3354.         shl     ecx, 2
  3355.         mov     edx,[triangles_normals_ptr]
  3356.         int     0x40                           ;  -> allocate memory for triangles normals
  3357.         mov     [triangles_normals_ptr], eax   ;  -> eax = pointer to allocated mem
  3358.  
  3359.  
  3360.         mov     eax, 68
  3361.         mov     ecx, [points_count_var]
  3362.         lea     ecx,[6+ecx*3]
  3363.         shl     ecx, 2
  3364.         mov     edx,[points_normals_ptr]
  3365.         int     0x40
  3366.         mov     [points_normals_ptr], eax
  3367.  
  3368.  
  3369.         mov     eax, 68
  3370.     ;    mov     ebx, 12
  3371.         mov     ecx, [points_count_var]
  3372.         lea     ecx,[10+ecx*3]
  3373.         shl     ecx, 2
  3374.         mov     edx,[points_normals_rot_ptr]
  3375.         int     0x40
  3376.         mov     [points_normals_rot_ptr], eax
  3377.  
  3378.         mov     eax, 68
  3379.  
  3380.         mov     edx,[points_ptr]
  3381.         int     0x40
  3382.         mov     [points_ptr], eax
  3383.  
  3384.         mov     eax, 68
  3385.         mov     edx,[points_rotated_ptr]
  3386.         int     0x40
  3387.         mov     [points_rotated_ptr], eax
  3388.  
  3389.         mov     eax, 68
  3390.  ;       mov     ebx, 12
  3391.         mov     ecx, [points_count_var]
  3392.         shl     ecx,2
  3393.         add     ecx,32
  3394.         mov     edx,[tex_points_ptr]
  3395.         int     0x40
  3396.         mov     [tex_points_ptr], eax
  3397.  
  3398.         mov     eax, 68
  3399.         mov     ecx, [points_count_var]
  3400.         add     ecx,10
  3401.         shl     ecx, 3
  3402.         mov     edx,[points_translated_ptr]
  3403.         int     0x40
  3404.         mov     [points_translated_ptr], eax
  3405. ret
  3406.  
  3407.  
  3408. read_from_disk:
  3409.     mov     eax, 68
  3410.     mov     ebx, 11
  3411.     int     0x40                   ;  -> create heap
  3412.  
  3413.     ;load kpacked files by Leency
  3414.        mov     eax,68
  3415.        mov     ebx,27
  3416.        mov     ecx,file_name
  3417.        int     0x40
  3418.  
  3419.        mov     [fsize],edx
  3420.        mov     [file_info+16],eax
  3421.  
  3422.        test    eax,eax
  3423.        jnz     .open_opened_well
  3424.        mov     eax,6 ;otherwise => failed
  3425.        jmp     @f
  3426.        .open_opened_well:
  3427.        xor     eax,eax
  3428.     @@:
  3429.   ;  eax = 0   -> ok file loaded
  3430. ret
  3431. read_param:
  3432.     cld
  3433.     mov        esi,I_Param
  3434.     cmp        dword[esi],0
  3435.     je         .end
  3436.     cmp        byte[esi],'/'
  3437.     je         .copy
  3438.     mov        edi,esi
  3439.     mov        ecx,25   ; 25 - would be enought
  3440.     repe       scasb
  3441.     jne        .end
  3442.     dec        edi
  3443.     mov        esi,edi
  3444.  .copy:
  3445.     mov         edi,file_name
  3446.     mov         ecx,50
  3447.     rep         movsd
  3448.  .end:
  3449. ret
  3450. buttons:                                      ; draw some buttons (all but navigation and close )
  3451.         mov     edi,menu
  3452.       .again:
  3453.         mov     eax,8             ; function 8 : define and draw button
  3454.         movzx   ebx,word[size_x_var]
  3455.         shl     ebx,16
  3456.         add     ebx,(10)*65536+62      ; [x start] *65536 + [x size]
  3457.         movzx   ecx,byte[edi]                 ; button id = position+2
  3458.         sub     ecx,2
  3459.         lea     ecx,[ecx*5]
  3460.         lea     ecx,[ecx*3]
  3461.         add     ecx,25
  3462.         shl     ecx,16
  3463.         add     ecx,12
  3464.         movzx   edx,byte[edi]                   ; button id
  3465.         mov     esi,0x6688dd                    ; button color RRGGBB
  3466.         int     0x40
  3467.          ; BUTTON  LABEL
  3468.         mov     eax,4                           ; function 4 : write text to window
  3469.         movzx   ebx,byte[edi]
  3470.         sub     ebx,2                            ; button id, according to position
  3471.         lea     ebx,[ebx*3]
  3472.         lea     ebx,[ebx*5]
  3473.         movzx   ecx,word[size_x_var]
  3474.         shl     ecx,16
  3475.         add     ebx,ecx
  3476.         add     ebx,(12)*65536+28        ; [x start] *65536 + [y start]
  3477.         mov     ecx,0x00ddeeff                  ; font 1 & color ( 0xF0RRGGBB )
  3478.         lea     edx,[edi+1]                     ; pointer to text beginning
  3479.         mov     esi,10                          ; text length
  3480.         int     0x40
  3481.         cmp     byte[edi+11],255                ; if max_flag=255
  3482.         je      @f                              ; skip
  3483.         ; flag description
  3484. ;       mov     eax,4                           ; function 4 : write text to window
  3485. ;       movzx   ebx,byte[edi]
  3486. ;       sub     bl,2
  3487. ;       lea     ebx,[ebx*3]
  3488. ;       lea     ebx,[ebx*5]
  3489. ;       add     ebx,(SIZE_X+12+70)*65536+28     ; [x start] *65536 + [y start]
  3490.         add     ebx,70*65536
  3491. ;       mov     ecx,0x00ddeeff                  ; font 1 & color ( 0xF0RRGGBB )
  3492.         movzx   edx,byte[edi+12]                ; current flag
  3493.         shl     edx,2                           ; * 4 = text length
  3494.         add     edx,dword[edi+13]               ; pointer to text beginning
  3495.         mov     esi,4                           ; text length
  3496.         int     0x40
  3497.  
  3498.     @@:
  3499.         add     edi,17
  3500.         cmp     byte[edi],-1
  3501.         jnz     .again
  3502. ret
  3503. write_info:
  3504.         mov     eax,13
  3505.         mov     bx,[size_x_var]
  3506.         shl     ebx,16
  3507.         add     ebx,120*65536+70   ; [x start] *65536 + [y start]
  3508.         mov     ecx,30 shl 16 + 150
  3509.         xor     edx,edx
  3510.         int     0x40
  3511.  
  3512.  
  3513.         xor     esi,esi
  3514.         emms
  3515.         movd    mm7,esi
  3516.      .nxxx:
  3517.         push    esi
  3518.         movd    mm7,esi
  3519.  
  3520.         mov     eax,4           ; function 4 : write text to window
  3521.         movzx   ebx,word[size_x_var]
  3522.         shl     ebx,16
  3523.         add     ebx,120*65536   ; [x start] *65536 + [y start]
  3524.         mov     bx,si
  3525.         shl     bx,3
  3526.         add     ebx,30
  3527.         mov     ecx,0x00ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  3528.         movd    edx,mm7
  3529.         shl     edx,2
  3530.         add     edx,lab_vert      ; pointer to text beginning
  3531.         mov     esi,lab_vert_end-lab_vert     ; text length
  3532.         int     0x40
  3533.  
  3534.         movd    esi,mm7
  3535.         mov     eax,[points_count_var+esi]
  3536.         mov     ecx,10
  3537.    .dc:
  3538.         xor     edx,edx
  3539.         mov     edi,10
  3540.         div     edi
  3541.         add     dl,30h
  3542.         mov     [STRdata+ecx-1],dl
  3543.         loop    .dc
  3544.  
  3545.         mov  eax,4                     ; function 4 : write text to window
  3546.         mov  bx,[size_x_var]
  3547.         add  ebx,120
  3548.         shl  ebx,16
  3549.         mov  bx,si                     ; [x start] *65536 + [y start]
  3550.         shl  bx,3
  3551.         add  bx,45
  3552.         mov  ecx,0x00ddeeff
  3553.         mov  edx,STRdata               ; pointer to text beginning
  3554.         mov  esi,10                    ; text length
  3555.         int  40h
  3556.         pop  esi
  3557.         add  esi,4
  3558.         cmp  esi,16
  3559.         jnz  .nxxx
  3560. ret
  3561. ;   *********************************************
  3562. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  3563. ;   *********************************************
  3564.     draw_window:
  3565.         mov     eax,12          ; function 12:tell os about windowdraw
  3566.         mov     ebx,1           ; 1, start of draw
  3567.         int     0x40
  3568.  
  3569.         ; DRAW WINDOW
  3570.         mov     eax,0  ; function 0 : define and draw window
  3571.         mov     bx,[x_start]
  3572.         shl     ebx,16
  3573.         mov     cx,[y_start]
  3574.         shl     ecx,16
  3575. ;ebx -  [x start] *65536 + [x size]
  3576. ;ecx -  [y start] *65536 + [y size]
  3577.         mov     bx,[size_x_var]
  3578.         add     bx,225
  3579.         mov     cx,[size_y_var]
  3580.         add     cx,30
  3581.     ; @@:
  3582.         mov     edx,0x13000000  ; color of work area RRGGBB,8->color gl
  3583.         mov     edi,labelt      ; WINDOW LABEL
  3584.         int     0x40
  3585.  
  3586.         call    buttons         ; more buttons
  3587.  
  3588.         .Y_ADD equ 2   ;-> offset of 'add vector' buttons
  3589.  
  3590.      ;   mov     eax,47
  3591.      ;   mov     ebx,0000000000111000000000000000b
  3592.      ;   mov     ecx,[points_count_var]
  3593.      ;   movzx   edx,word[size_x_var]
  3594.      ;   shl     edx,16
  3595.      ;   add     edx,130*65536+60  ; [x start] *65536 + [y start]
  3596.      ;   mov     esi,0x00ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  3597.      ;   int     0x40
  3598.  
  3599.        call  write_info
  3600.  
  3601.         ; ADD VECTOR LABEL      ; add vector buttons - 30 ++
  3602.         mov     eax,4           ; function 4 : write text to window
  3603.         movzx   ebx,word[size_x_var]
  3604.         shl     ebx,16
  3605.         add     ebx,(12)*65536+(168+15*(13+.Y_ADD))   ; [x start] *65536 + [y start]
  3606.         mov     ecx,0x00ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  3607.         mov     edx,labelvector      ; pointer to text beginning
  3608.         mov     esi,labelvectorend-labelvector     ; text length
  3609.     ;    cmp     [move_flag],2
  3610.     ;    jne     @f
  3611.     ;    add     edx,navigation_size
  3612.     ;  @@:
  3613.         int     0x40
  3614.          ; VECTOR Y- BUTTON
  3615.         mov     eax,8           ; function 8 : define and draw button
  3616.         movzx   ebx,word[size_x_var]
  3617.         shl     ebx,16
  3618.         add     ebx,30*65536+20     ; [x start] *65536 + [x size]
  3619.         mov     ecx,(165+15*(14+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  3620.         mov     edx,30           ; button id
  3621.         mov     esi,0x6688dd    ; button color RRGGBB
  3622.         int     0x40
  3623.         ;VECTOR Y- LABEL
  3624.         mov     eax,4           ; function 4 : write text to window
  3625.         movzx   ebx,word[size_x_var]
  3626.         shl     ebx,16
  3627.         add     ebx,(32)*65536+(168+15*(14+.Y_ADD))   ; [x start] *65536 + [y start]
  3628.         mov     ecx,0x00ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  3629.         mov     edx,labelyminus      ; pointer to text beginning
  3630.         mov     esi,labelyminusend-labelyminus     ; text length
  3631.         cmp     [move_flag],2
  3632.    ;     jne     @f
  3633.    ;     add     edx,navigation_size
  3634.    ;   @@:
  3635.         int     0x40
  3636.         ; VECTOR Z+ BUTTON
  3637.         mov     eax,8           ; function 8 : define and draw button
  3638.         movzx   ebx,word[size_x_var]
  3639.         shl     ebx,16
  3640.         add     ebx,(51)*65536+21     ; [x start] *65536 + [x size]
  3641.         mov     ecx,(165+15*(14+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  3642.         mov     edx,31           ; button id
  3643.         mov     esi,0x6688dd    ; button color RRGGBB
  3644.         int     0x40
  3645.         ;VECTOR Z+ LABEL
  3646.         mov     eax,4           ; function 4 : write text to window
  3647.         movzx   ebx,word[size_x_var]
  3648.         shl     ebx,16
  3649.         add     ebx,(53)*65536+(168+15*(14+.Y_ADD))   ; [x start] *65536 + [y start]
  3650.         mov     ecx,0x00ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  3651.         mov     edx,labelzplus      ; pointer to text beginning
  3652.         mov     esi,labelzplusend-labelzplus     ; text length
  3653.    ;     cmp     [move_flag],2
  3654.    ;     jne     @f
  3655.    ;     add     edx,navigation_size
  3656.    ;   @@:
  3657.  
  3658.         int     0x40
  3659.         ; VECTOR x- BUTTON
  3660.         mov     eax,8           ; function 8 : define and draw button
  3661.         movzx   ebx,word[size_x_var]
  3662.         shl     ebx,16
  3663.         add     ebx,(10)*65536+21     ; [x start] *65536 + [x size]
  3664.         mov     ecx,(165+15*(15+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  3665.         mov     edx,32           ; button id
  3666.         mov     esi,0x6688dd    ; button color RRGGBB
  3667.         int     0x40
  3668.         ;VECTOR x- LABEL
  3669.         mov     eax,4           ; function 4 : write text to window
  3670.         movzx   ebx,word[size_x_var]
  3671.         shl     ebx,16
  3672.         add     ebx,(12)*65536+(168+15*(15+.Y_ADD))   ; [x start] *65536 + [y start]
  3673.         mov     ecx,0x00ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  3674.         mov     edx,labelxminus      ; pointer to text beginning
  3675.         mov     esi,labelxminusend-labelxminus     ; text length
  3676.    ;     cmp     [move_flag],2
  3677.    ;     jne     @f
  3678.    ;     add     edx,navigation_size
  3679.    ;   @@:
  3680.         int     0x40
  3681.         ; VECTOR x+ BUTTON
  3682.         mov     eax,8           ; function 8 : define and draw button
  3683.         movzx   ebx,word[size_x_var]
  3684.         shl     ebx,16
  3685.         add     ebx,(51)*65536+21     ; [x start] *65536 + [x size]
  3686.         mov     ecx,(165+15*(15+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  3687.         mov     edx,33           ; button id
  3688.         mov     esi,0x6688dd    ; button color RRGGBB
  3689.         int     0x40
  3690.         ;VECTOR x+ LABEL
  3691.         mov     eax,4           ; function 4 : write text to window
  3692.         movzx   ebx,word[size_x_var]
  3693.         shl     ebx,16
  3694.         add     ebx,(53)*65536+(168+15*(15+.Y_ADD))   ; [x start] *65536 + [y start]
  3695.         mov     ecx,0x00ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  3696.         mov     edx,labelxplus      ; pointer to text beginning
  3697.         mov     esi,labelxplusend-labelxplus     ; text length
  3698.    ;     cmp     [move_flag],2
  3699.    ;     jne     @f
  3700.    ;     add     edx,navigation_size
  3701.    ;   @@:
  3702.         int     0x40
  3703.         ; VECTOR z- BUTTON
  3704.         mov     eax,8           ; function 8 : define and draw button
  3705.         movzx   ebx,word[size_x_var]
  3706.         shl     ebx,16
  3707.         add     ebx,(10)*65536+62-41     ; [x start] *65536 + [x size]
  3708.         mov     ecx,(25+140+15*(16+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  3709.         mov     edx,34           ; button id
  3710.         mov     esi,0x6688dd    ; button color RRGGBB
  3711.         int     0x40
  3712.         ;VECTOR z- LABEL
  3713.         mov     eax,4           ; function 4 : write text to window
  3714.         movzx   ebx,word[size_x_var]
  3715.         shl     ebx,16
  3716.         add     ebx,(12)*65536+(168+15*(16+.Y_ADD))   ; [x start] *65536 + [y start]
  3717.         mov     ecx,0x00ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  3718.         mov     edx,labelzminus      ; pointer to text beginning
  3719.         mov     esi,labelzminusend-labelzminus     ; text length
  3720.    ;     cmp     [move_flag],2
  3721.    ;     jne     @f
  3722.    ;     add     edx,navigation_size
  3723.    ;   @@:
  3724.         int     0x40
  3725.        ;VECTOR Y+ BUTTON
  3726.         mov     eax,8           ; function 8 : define and draw button
  3727.         movzx   ebx,word[size_x_var]
  3728.         shl     ebx,16
  3729.         add     ebx,(10+20)*65536+20     ; [x start] *65536 + [x size]
  3730.         mov     ecx,(165+15*(16+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  3731.         mov     edx,35           ; button id
  3732.         mov     esi,0x6688dd    ; button color RRGGBB
  3733.         int     0x40
  3734.         ;VECTOR Y+ LABEL
  3735.         mov     eax,4           ; function 4 : write text to window
  3736.         movzx   ebx,word[size_x_var]
  3737.         shl     ebx,16
  3738.         add     ebx,(32)*65536+(168+15*(16+.Y_ADD))   ; [x start] *65536 + [y start]
  3739.         mov     ecx,0x00ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  3740.         mov     edx,labelyplus      ; pointer to text beginning
  3741.         mov     esi,labelyplusend-labelyplus     ; text length
  3742.    ;     cmp     [move_flag],2
  3743.    ;     jne     @f
  3744.    ;     add     edx,navigation_size
  3745.    ;   @@:
  3746.         int     0x40
  3747.  
  3748.         mov     eax,12          ; function 12:tell os about windowdraw
  3749.         mov     ebx,2           ; 2, end of draw
  3750.         int     0x40
  3751.       ;  pop     eax
  3752.       ;  mov     [fire_flag],al
  3753.         ret
  3754.  
  3755.  
  3756.    ; DATA AREA  ************************************
  3757.  
  3758.    include 'data.inc'
  3759.    align 16
  3760. MEM_END:
  3761.