Subversion Repositories Kolibri OS

Rev

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

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