Subversion Repositories Kolibri OS

Rev

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