Subversion Repositories Kolibri OS

Rev

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

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