Subversion Repositories Kolibri OS

Rev

Rev 6769 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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