Subversion Repositories Kolibri OS

Rev

Rev 7788 | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. ; application : View3ds ver. 0.069 - 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.         mov     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.         mov     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.         mov     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.     ; 64 indexes    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.       mov       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.         mov     esi,dword[ebp]              ; first point index
  1426.         lea     esi,[esi*3]
  1427.         lea     esi,[points+esi*2]     ; esi - pointer to 1st 3d point
  1428.         movzx   edi,dword[ebp+4]        ; 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,dword[ebp+8]        ; 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,12
  1446.         add     ebx,12
  1447.         cmp     dword[ebp],-1
  1448.         jne     @b
  1449. ret
  1450. end if
  1451.  
  1452. init_point_normals:
  1453. .x equ dword [ebp-4]
  1454. .y equ dword [ebp-8]
  1455. .z equ dword [ebp-12]
  1456. .point_number equ dword [ebp-28]
  1457. .hit_faces    equ dword [ebp-32]
  1458.  
  1459.         fninit
  1460.         mov       ebp,esp
  1461.         sub       esp,32
  1462.         mov       edi,[points_normals_ptr]
  1463.         mov       .point_number,0
  1464.     .ipn_loop:
  1465.         mov       .hit_faces,0
  1466.         mov       .x,0
  1467.         mov       .y,0
  1468.         mov       .z,0
  1469.         mov       esi,[triangles_ptr]
  1470.         xor       ecx,ecx              ; ecx - triangle number
  1471.     .ipn_check_face:
  1472.         xor       ebx,ebx              ; ebx - 'position' in one triangle
  1473.     .ipn_check_vertex:
  1474.         mov       eax,dword[esi+ebx]    ;  eax - point_number
  1475.         cmp       eax,.point_number
  1476.         jne       .ipn_next_vertex
  1477.         push      esi
  1478.         mov       esi,ecx
  1479.         lea       esi,[esi*3]
  1480.        ; lea       esi,[triangles_normals+esi*4]
  1481.         shl       esi,2
  1482.         add       esi,[triangles_normals_ptr]
  1483.  
  1484.         fld       .x
  1485.         fadd      dword[esi+vec_x]       ; vec_x this defined in 3dmath.asm - x cooficient
  1486.         fstp      .x                     ; of normal vactor
  1487.         fld       .y
  1488.         fadd      dword[esi+vec_y]
  1489.         fstp      .y
  1490.         fld       .z
  1491.         fadd      dword[esi+vec_z]
  1492.         fstp      .z
  1493.         pop       esi
  1494.         inc       .hit_faces
  1495.         jmp       .ipn_next_face
  1496.     .ipn_next_vertex:
  1497.         add       ebx,4
  1498.         cmp       ebx,12
  1499.         jne       .ipn_check_vertex
  1500.     .ipn_next_face:
  1501.         add       esi,12
  1502.         inc       ecx
  1503.         cmp       ecx,[triangles_count_var]
  1504.         jne       .ipn_check_face
  1505.  
  1506.         fld       .x
  1507.         fidiv     .hit_faces
  1508.         fstp      dword[edi+vec_x]
  1509.         fld       .y
  1510.         fidiv     .hit_faces
  1511.         fstp      dword[edi+vec_y]
  1512.         fld       .z
  1513.         fidiv     .hit_faces
  1514.         fstp      dword[edi+vec_z]
  1515.         call      normalize_vector
  1516.         add       edi,12  ;type vector 3d
  1517.         inc       .point_number
  1518.         mov       edx,.point_number
  1519.         cmp       edx,[points_count_var]
  1520.         jne       .ipn_loop
  1521.  
  1522.         mov       esp,ebp
  1523. ret
  1524. ;===============================================================
  1525.  
  1526. init_triangles_normals2:
  1527.         mov     ebx,[triangles_normals_ptr]
  1528.         mov     ebp,[triangles_ptr]
  1529.         mov     ecx,[triangles_count_var]
  1530.      @@:
  1531.         push    ecx
  1532.         push    ebx
  1533.         mov     ebx,vectors
  1534.         mov     esi,dword[ebp]          ; first point index
  1535.         lea     esi,[esi*3]
  1536. ;        lea     esi,[points+esi*2]     ; esi - pointer to 1st 3d point
  1537.         shl     esi,2
  1538.         add     esi,[points_ptr]
  1539.         mov     edi,dword[ebp+4]          ; first point index
  1540.         lea     edi,[edi*3]
  1541.         shl     edi,2
  1542.         add     edi,[points_ptr]
  1543. ;        movzx   edi,word[ebp+2]        ; second point index
  1544. ;        lea     edi,[edi*3]
  1545. ;        lea     edi,[points+edi*2]     ; edi - pointer to 2nd 3d point
  1546.         call    make_vector_r
  1547.         add     ebx,12
  1548.         mov     esi,edi
  1549.         mov     edi,dword[ebp+8]        ; third point index
  1550.         lea     edi,[edi*3]
  1551.         shl     edi,2
  1552.         add     edi,[points_ptr]
  1553. ;        lea     edi,[points+edi*2]
  1554.         call    make_vector_r
  1555.         mov     edi,ebx                 ; edi - pointer to 2nd vector
  1556.         mov     esi,ebx
  1557.         sub     esi,12                  ; esi - pointer to 1st vector
  1558.         pop     ebx
  1559.         call    cross_product
  1560.         mov     edi,ebx
  1561.         call    normalize_vector
  1562.         add     ebp,12
  1563.         add     ebx,12
  1564.         pop     ecx
  1565.         sub     ecx,1
  1566.         jnz     @b
  1567.        ; cmp     dword[ebp],-1
  1568.        ; jne     @b
  1569. ret
  1570. if 0 ; ind 64 but
  1571.  
  1572. ;=================================================================
  1573. sort_triangles:
  1574.         mov     esi,[triangles_ptr]
  1575.         mov     edi,triangles_with_z
  1576.         mov     ebp,[points_translated_ptr]
  1577.  
  1578.     make_triangle_with_z:       ;makes list with triangles and z position
  1579.         movzx   eax,word[esi]
  1580.         lea     eax,[eax*3]
  1581.         movzx   ecx,word[ebp+eax*2+4]
  1582.  
  1583.         movzx   eax,word[esi+2]
  1584.         lea     eax,[eax*3]
  1585.         add     cx,word[ebp+eax*2+4]
  1586.  
  1587.         movzx   eax,word[esi+4]
  1588.         lea     eax,[eax*3]
  1589.         add     cx,word[ebp+eax*2+4]
  1590.  
  1591.         mov     ax,cx
  1592.        ; cwd
  1593.        ; idiv    word[i3]
  1594.         movsd                   ; store vertex coordinates
  1595.         movsw
  1596.         stosw                   ; middle vertex coordinate  'z' in triangles_with_z list
  1597.         cmp     dword[esi],-1
  1598.         jne     make_triangle_with_z
  1599.         movsd                   ; copy end mark
  1600.         mov     eax,4
  1601.         lea     edx,[edi-8-trizdd]
  1602.      ;   lea     edx, [edi-8]
  1603.      ;   sub     edx,[triangles_w_z_ptr]
  1604.         mov     [high],edx
  1605.         call    quicksort
  1606.         mov     eax,4
  1607.         mov     edx,[high]
  1608.         call    insertsort
  1609.         jmp     end_sort
  1610.  
  1611.     quicksort:
  1612.         mov     ecx,edx
  1613.         sub     ecx,eax
  1614.         cmp     ecx,32
  1615.         jc      .exit
  1616.         lea     ecx,[eax+edx]
  1617.         shr     ecx,4
  1618.         lea     ecx,[ecx*8-4];
  1619. ;        mov     edi,[triangles_w_z_ptr]
  1620. ;        mov     ebx,[edi+eax]
  1621. ;        mov     esi,[edi+ecx]
  1622. ;        mov     edi,[edi+edx]
  1623.         mov     ebx,[trizdd+eax]; trizdd[l]
  1624.         mov     esi,[trizdd+ecx]; trizdd[i]
  1625.         mov     edi,[trizdd+edx]; trizdd[h]
  1626.         cmp     ebx,esi
  1627.         jg      @f              ; direction NB! you need to negate these to invert the order
  1628.       if Ext=NON
  1629.         mov     [trizdd+eax],esi
  1630.         mov     [trizdd+ecx],ebx
  1631.         mov     ebx,[trizdd+eax-4]
  1632.         mov     esi,[trizdd+ecx-4]
  1633.         mov     [trizdd+eax-4],esi
  1634.         mov     [trizdd+ecx-4],ebx
  1635.         mov     ebx,[trizdd+eax]
  1636.         mov     esi,[trizdd+ecx]
  1637.       else
  1638. ;        push    ebx
  1639. ;        mov     ebx,[triangles_w_z_ptr]
  1640. ;        movq    mm0,[ebx+eax-4]
  1641. ;        movq    mm1,[ebx+ecx-4]
  1642. ;        movq    [ebx+ecx-4],mm0
  1643. ;        movq    [ebx+eax-4],mm1
  1644. ;        pop     ebx
  1645.         movq    mm0,[trizdq+eax-4]
  1646.         movq    mm1,[trizdq+ecx-4]
  1647.         movq    [trizdq+ecx-4],mm0
  1648.         movq    [trizdq+eax-4],mm1
  1649.         xchg    ebx,esi
  1650.       end if
  1651.       @@:
  1652.         cmp     ebx,edi
  1653.         jg      @f              ; direction
  1654.       if Ext=NON
  1655.         mov     [trizdd+eax],edi
  1656.         mov     [trizdd+edx],ebx
  1657.         mov     ebx,[trizdd+eax-4]
  1658.         mov     edi,[trizdd+edx-4]
  1659.         mov     [trizdd+eax-4],edi
  1660.         mov     [trizdd+edx-4],ebx
  1661.         mov     ebx,[trizdd+eax]
  1662.         mov     edi,[trizdd+edx]
  1663.       else
  1664. ;        push    ebx
  1665. ;        mov     ebx,[triangles_w_z_ptr]
  1666. ;        movq    mm0,[ebx+eax-4]
  1667. ;        movq    mm1,[ebx+edx-4]
  1668. ;        movq    [ebx+edx-4],mm0
  1669. ;        movq    [ebx+eax-4],mm1
  1670.         movq    mm0,[trizdq+eax-4]
  1671.         movq    mm1,[trizdq+edx-4]
  1672.         movq    [trizdq+edx-4],mm0
  1673.         movq    [trizdq+eax-4],mm1
  1674. ;        pop     ebx
  1675.         xchg    ebx,edi
  1676.       end if
  1677.       @@:
  1678.         cmp     esi,edi
  1679.         jg      @f              ; direction
  1680.       if Ext=NON
  1681.         mov     [trizdd+ecx],edi
  1682.         mov     [trizdd+edx],esi
  1683.         mov     esi,[trizdd+ecx-4]
  1684.         mov     edi,[trizdd+edx-4]
  1685.         mov     [trizdd+ecx-4],edi
  1686.         mov     [trizdd+edx-4],esi
  1687.       else
  1688. ;        push    ebx
  1689. ;        mov     ebx,[triangles_w_z_ptr]
  1690. ;        movq    mm0,[ebx+ecx-4]
  1691. ;        movq    mm1,[ebx+edx-4]
  1692. ;        movq    [ebx+edx-4],mm0
  1693. ;        movq    [ebx+ecx-4],mm1
  1694. ;        pop     ebx
  1695.  
  1696.         movq    mm0,[trizdq+ecx-4]
  1697.         movq    mm1,[trizdq+edx-4]
  1698.         movq    [trizdq+edx-4],mm0
  1699.         movq    [trizdq+ecx-4],mm1
  1700.         xchg    ebx,esi
  1701.       end if
  1702.       @@:
  1703.         mov     ebp,eax         ; direction
  1704.         add     ebp,8      ;   j
  1705.       if Ext=NON
  1706.         mov     esi,[trizdd+ebp]
  1707.         mov     edi,[trizdd+ecx]
  1708.         mov     [trizdd+ebp],edi
  1709.         mov     [trizdd+ecx],esi
  1710.         mov     esi,[trizdd+ebp-4]
  1711.         mov     edi,[trizdd+ecx-4]
  1712.         mov     [trizdd+ecx-4],esi
  1713.         mov     [trizdd+ebp-4],edi
  1714.       else
  1715. ;        push    ebx
  1716. ;        mov     ebx,[triangles_w_z_ptr]
  1717. ;        movq    mm0,[ebx+ebp-4]
  1718. ;        movq    mm1,[ebx+ecx-4]
  1719. ;        movq    [ebx+ecx-4],mm0
  1720. ;        movq    [ebx+ebp-4],mm1
  1721. ;        pop     ebx
  1722.  
  1723.         movq    mm0,[trizdq+ebp-4]
  1724.         movq    mm1,[trizdq+ecx-4]
  1725.         movq    [trizdq+ecx-4],mm0
  1726.         movq    [trizdq+ebp-4],mm1
  1727.       end if
  1728.         mov     ecx,edx    ;   i; direction
  1729.         mov     ebx,[trizdd+ebp]; trizdd[j]
  1730. ;        mov     ebx, [triangles_w_z_ptr]
  1731. ;        add     ebx, ebp
  1732.  
  1733.  ;       push    eax
  1734.  ;       mov     eax, [triangles_w_z_ptr]
  1735.       .loop:
  1736.         sub     ecx,8           ; direction
  1737.         cmp     [trizdd+ecx],ebx
  1738. ;        cmp     [eax+ecx],ebx
  1739.         jl      .loop           ; direction
  1740.       @@:
  1741.         add     ebp,8           ; direction
  1742.         cmp     [trizdd+ebp],ebx
  1743. ;        cmp     [eax+ebp],ebx
  1744.         jg      @b              ; direction
  1745.         cmp     ebp,ecx
  1746.         jge     @f              ; direction
  1747.       if Ext=NON
  1748.         mov     esi,[trizdd+ecx]
  1749.         mov     edi,[trizdd+ebp]
  1750.         mov     [trizdd+ebp],esi
  1751.         mov     [trizdd+ecx],edi
  1752.         mov     edi,[trizdd+ecx-4]
  1753.         mov     esi,[trizdd+ebp-4]
  1754.         mov     [trizdd+ebp-4],edi
  1755.         mov     [trizdd+ecx-4],esi
  1756.       else
  1757. ;        movq    mm0,[eax+ecx-4]
  1758. ;        movq    mm1,[eax+ebp-4]
  1759. ;        movq    [eax+ebp-4],mm0
  1760. ;        movq    [eax+ecx-4],mm1
  1761.         movq    mm0,[trizdq+ecx-4]
  1762.         movq    mm1,[trizdq+ebp-4]
  1763.         movq    [trizdq+ebp-4],mm0
  1764.         movq    [trizdq+ecx-4],mm1
  1765.       end if
  1766.         jmp     .loop
  1767. ;        pop     eax
  1768.       @@:
  1769.       if Ext=NON
  1770.         mov     esi,[trizdd+ecx]
  1771.         mov     edi,[trizdd+eax+8]
  1772.         mov     [trizdd+eax+8],esi
  1773.         mov     [trizdd+ecx],edi
  1774.         mov     edi,[trizdd+ecx-4]
  1775.         mov     esi,[trizdd+eax+4]
  1776.         mov     [trizdd+eax+4],edi
  1777.         mov     [trizdd+ecx-4],esi
  1778.       else
  1779. ;        push    edx
  1780. ;        mov     edx,[triangles_w_z_ptr]
  1781. ;        movq    mm0,[edx+ecx-4]
  1782. ;        movq    mm1,[edx+eax+4]; dir
  1783. ;        movq    [edx+eax+4],mm0; dir
  1784. ;        movq    [edx+ecx-4],mm1
  1785. ;        pop     edx
  1786.  
  1787.         movq    mm0,[trizdq+ecx-4]
  1788.         movq    mm1,[trizdq+eax+4]; dir
  1789.         movq    [trizdq+eax+4],mm0; dir
  1790.         movq    [trizdq+ecx-4],mm1
  1791.       end if
  1792.         add     ecx,8
  1793.         push    ecx edx
  1794.         mov     edx,ebp
  1795.         call    quicksort
  1796.         pop     edx eax
  1797.         call    quicksort
  1798.       .exit:
  1799.     ret
  1800.     insertsort:
  1801.         mov     esi,eax
  1802.       .start:
  1803.         add     esi,8
  1804.         cmp     esi,edx
  1805.         ja      .exit
  1806.         mov     ebx,[trizdd+esi]
  1807. ;        mov     ebx,[triangles_w_z_ptr]
  1808. ;        add     ebx,esi
  1809.       if Ext=NON
  1810.         mov     ecx,[trizdd+esi-4]
  1811.       else
  1812. ;        push    ebx
  1813. ;        mov     ebx,[triangles_w_z_ptr]
  1814. ;        movq    mm1,[ebx+esi-4]
  1815.         movq    mm1,[trizdq+esi-4]
  1816. ;        pop     ebx
  1817.       end if
  1818.         mov     edi,esi
  1819.       @@:
  1820.         cmp     edi,eax
  1821.         jna     @f
  1822. ;        push    eax
  1823. ;        mov     eax,[triangles_w_z_ptr]
  1824. ;        cmp     [eax+edi-8],ebx
  1825. ;        pop     eax
  1826.        cmp     [trizdd+edi-8],ebx
  1827.         jg      @f                 ; direction
  1828.       if Ext=NON
  1829.         mov     ebp,[trizdd+edi-8]
  1830.         mov     [trizdd+edi],ebp
  1831.         mov     ebp,[trizdd+edi-12]
  1832.         mov     [trizdd+edi-4],ebp
  1833.       else
  1834. ;        push    eax
  1835. ;        mov     eax,[triangles_w_z_ptr]
  1836. ;        movq    mm0,[eax+edi-12]
  1837. ;        movq    [eax+edi-4],mm0
  1838.         movq    mm0,[trizdq+edi-12]
  1839.         movq    [trizdq+edi-4],mm0
  1840. ;        pop     eax
  1841.       end if
  1842.         sub     edi,8
  1843.         jmp     @b
  1844.       @@:
  1845.       if Ext=NON
  1846.         mov     [trizdd+edi],ebx
  1847.         mov     [trizdd+edi-4],ecx
  1848.       else
  1849. ;        push    eax
  1850. ;        mov     eax,[triangles_w_z_ptr]
  1851. ;        movq    [eax+edi-4],mm1
  1852.         movq    [trizdq+edi-4],mm1
  1853. ;        pop     eax
  1854.       end if
  1855.         jmp     .start
  1856.       .exit:
  1857.     ret
  1858.    end_sort:
  1859.     ; translate triangles_with_z to sorted_triangles
  1860.         mov     esi,triangles_with_z
  1861. ;        mov      esi,[triangles_w_z_ptr]
  1862.       ;  mov     edi,sorted_triangles
  1863.         mov      edi,[triangles_ptr]
  1864.     again_copy:
  1865.       if Ext=NON
  1866.         movsd
  1867.         movsw
  1868.         add     esi,2
  1869.       else
  1870.         movq    mm0,[esi]
  1871.         movq    [edi],mm0
  1872.         add     esi,8
  1873.         add     edi,6
  1874.       end if
  1875.         cmp     dword[esi],-1
  1876.         jne     again_copy
  1877. ;      if Ext=MMX
  1878. ;        emms
  1879. ;      end if
  1880.         movsd  ; copy end mark too
  1881. ret
  1882. end if ; 64 ind
  1883. clrscr:
  1884.         mov     edi,[screen_ptr]
  1885.         movzx   ecx,word[size_x_var]
  1886.         movzx   eax,word[size_y_var]
  1887.         imul    ecx,eax
  1888.         lea     ecx,[ecx*3]
  1889.         shr     ecx,2
  1890.         xor     eax,eax
  1891.       if Ext=NON
  1892.         rep     stosd
  1893.       else if Ext = MMX
  1894.         pxor    mm0,mm0
  1895.       @@:
  1896.         movq    [edi+00],mm0
  1897.         movq    [edi+08],mm0
  1898.         movq    [edi+16],mm0
  1899.         movq    [edi+24],mm0
  1900.         add     edi,32
  1901.         sub     ecx,8
  1902.         jnc     @b
  1903.       else
  1904.         push    ecx
  1905.         mov     ecx,edi
  1906.         and     ecx,0x0000000f
  1907.         rep     stosb
  1908.         pop     ecx
  1909.         and     ecx,0xfffffff0
  1910.         xorps   xmm0,xmm0
  1911.       @@:
  1912.         movaps  [edi],xmm0
  1913.         movaps  [edi+16],xmm0
  1914.         movaps  [edi+32],xmm0
  1915.         movaps  [edi+48],xmm0
  1916.         add     edi,64
  1917.         sub     ecx,16
  1918.         jnz     @b
  1919.       end if
  1920.  
  1921. ret
  1922.  
  1923.  
  1924. draw_triangles:
  1925.  
  1926.         emms
  1927.       ;  update translated list  MMX required
  1928.         cmp     [vertex_edit_no],0
  1929.         je      @f
  1930.         movzx   eax,[vertex_edit_no]
  1931.         dec     eax
  1932.         movd    mm0,[edit_end_x]
  1933.         psubw   mm0,[edit_start_x]
  1934.         lea     eax,[eax*3]
  1935.         add     eax,eax
  1936.         add     eax,[points_translated_ptr]
  1937.         movd    mm1,dword[eax]
  1938.         paddw   mm1,mm0
  1939.         movd    dword[eax],mm1
  1940.     @@:
  1941.  
  1942.  
  1943.  
  1944.         mov esi,[triangles_ptr]
  1945.         mov [edges_counter],0
  1946.         mov ecx,[triangles_count_var]
  1947.     .again_dts:
  1948.         push    ecx
  1949.         mov     ebp,[points_translated_ptr]
  1950.       if Ext >= SSE2
  1951.         mov     eax,dword[esi]
  1952.         mov     [point_index1],eax
  1953.         lea     eax,[eax*3]
  1954.         add     eax,eax
  1955.         push    ebp
  1956.         add     ebp,eax
  1957.         mov     eax,[ebp]
  1958.    ;     cmp     [vertex_edit_no],0
  1959.    ;     jne     @f
  1960.    ;
  1961.    ;   @@:
  1962.         mov     dword[xx1],eax
  1963.         mov     eax,[ebp+4]
  1964.         mov     [zz1],ax
  1965.  
  1966.         pop     ebp
  1967.  
  1968.  
  1969.         mov     eax,dword[esi+4]
  1970.         mov     [point_index2],eax
  1971.         lea     eax,[eax*3]
  1972.         add     eax,eax
  1973.         push    ebp
  1974.         add     ebp,eax
  1975.         mov     eax,[ebp]
  1976.         mov     dword[xx2],eax
  1977.         mov     eax,[ebp+4]
  1978.         mov     [zz2],ax
  1979.         pop     ebp
  1980.  
  1981.  
  1982.         mov     eax,dword[esi+8]        ; xyz3 = [ebp+[esi+4]*6]
  1983.         mov     [point_index3],eax
  1984.         lea     eax,[eax*3]
  1985.         add     eax,eax
  1986.     ;    push    ebp
  1987.         add     ebp,eax
  1988.         mov     eax,[ebp]
  1989.         mov     dword[xx3],eax
  1990.         mov     eax,[ebp+4]
  1991.         mov     [zz3],ax
  1992.       else
  1993.         movq    mm0,[esi]           ; don't know MMX
  1994.         mov     qword[point_index1],mm0
  1995.        ; shr     eax,16
  1996.        ; mov     [point_index2],ax
  1997.         mov     eax,dword[esi+8]
  1998.         mov     [point_index3],eax
  1999.         movdqu  xmm0,[esi]
  2000.         paddd   xmm0,xmm0
  2001.         movdqa  xmm1,xmm0
  2002.         paddd   xmm0,xmm0
  2003.         paddd   xmm0,xmm1
  2004.         movd    eax,xmm0
  2005.         psrldq  xmm0,4
  2006.         movd    ebx,xmm0
  2007.         psrldq  xmm0,4
  2008.         movd    ecx,xmm0
  2009.         and     eax,0FFFFh
  2010.         and     ebx,0FFFFh
  2011.         and     ecx,0FFFFh
  2012.         movq    mm0,[ebp+eax]
  2013.         movq    mm1,[ebp+ebx]
  2014.         movq    mm2,[ebp+ecx]
  2015.         movq    qword[xx1],mm0
  2016.         movq    qword[xx2],mm1
  2017.         movq    qword[xx3],mm2
  2018. ;        emms
  2019.       end if  ; *********************************
  2020.  if 0
  2021.         cmp     [vertex_edit_no],0
  2022.         jne     .no_edit
  2023.         mov     ax,[vertex_edit_no]
  2024.         dec     ax
  2025.         cmp     ax,[point_index1]
  2026.         jne     @f
  2027.         movd    mm0,[edit_start_x]
  2028.         psubw   mm0,[edit_end_x]
  2029.         movd    mm1,dword[xx1]
  2030.         paddw   mm1,mm0
  2031.         movd    dword[xx1],mm1
  2032.         jmp     .no_edit
  2033.        @@:
  2034.  
  2035.         cmp     ax,[point_index2]
  2036.         jne     @f
  2037.         movd    mm0,[edit_start_x]
  2038.         psubw   mm0,[edit_end_x]
  2039.         movd    mm1,dword[xx2]
  2040.         paddw   mm1,mm0
  2041.         movd    dword[xx2],mm1
  2042.         jmp     .no_edit
  2043.        @@:
  2044.  
  2045.         cmp     ax,[point_index3]
  2046.         jne     @f
  2047.         movd    mm0,[edit_start_x]
  2048.         psubw   mm0,[edit_end_x]
  2049.         movd    mm1,dword[xx3]
  2050.         paddw   mm1,mm0
  2051.         movd    dword[xx3],mm1
  2052.         jmp     .no_edit
  2053.        @@:
  2054.  
  2055.  
  2056.     .no_edit:
  2057. end if
  2058.         push esi                          ;
  2059.         fninit                            ; DO culling AT FIRST
  2060.         cmp     [culling_flag],1          ; (if culling_flag = 1)
  2061.         jne     .no_culling
  2062.         mov     esi,point_index1          ; *********************************
  2063.         mov     ecx,3                     ;
  2064.       @@:
  2065.         mov     eax,dword[esi]
  2066.         lea     eax,[eax*3]
  2067.         shl     eax,2
  2068.         add     eax,[points_normals_rot_ptr]
  2069. ;        lea     eax,[eax+point_normals_rotated]
  2070.         fld     dword[eax+8]             ; *****************************
  2071.         ftst                             ; CHECKING OF Z COOFICIENT OF
  2072.         fstsw   ax                       ; NORMAL VECTOR
  2073.         sahf
  2074.         jb      @f
  2075.         ffree   st
  2076.         loop    @b
  2077.         jmp     .end_draw   ; non visable
  2078.       @@:
  2079.         ffree   st  ;is visable
  2080.       .no_culling:
  2081.         cmp     [dr_flag],0               ; draw type flag
  2082.         je      .flat_draw
  2083.         cmp     [dr_flag],2
  2084.         je      .env_mapping
  2085.         cmp     [dr_flag],3
  2086.         je      .bump_mapping
  2087.         cmp     [dr_flag],4
  2088.         je      .tex_mapping
  2089.         cmp     [dr_flag],5
  2090.         je      .rainbow
  2091.         cmp     [dr_flag],7
  2092.         je      .grd_tex
  2093.         cmp     [dr_flag],8
  2094.         je      .two_tex
  2095.         cmp     [dr_flag],9
  2096.         je      .bump_tex
  2097.         cmp     [dr_flag],10
  2098.         je      .cubic_env_mapping
  2099.         cmp     [dr_flag],11
  2100.         je      .draw_smooth_line
  2101.                                       ; ****************
  2102.         mov     esi,point_index3      ; do Gouraud shading
  2103.         mov     ecx,3
  2104.       .again_grd_draw:
  2105.         mov     eax,dword[esi]
  2106.         shl     eax,2
  2107.         lea     eax,[eax*3]
  2108.         add     eax,[points_normals_rot_ptr]
  2109.         ; texture x=(rotated point normal -> x * 255)+255
  2110.         fld     dword[eax]       ; x cooficient of normal vector
  2111.         fimul   [correct_tex]
  2112.         fiadd   [correct_tex]
  2113.         fistp   word[esp-2]
  2114.         ; texture y=(rotated point normal -> y * 255)+255
  2115.         fld     dword[eax+4]      ; y cooficient
  2116.         fimul   [correct_tex]
  2117.         fiadd   [correct_tex]
  2118.         fistp   word[esp-4]
  2119.  
  2120.         movzx    eax,word[esp-4]
  2121.         movzx    ebx,word[esp-2]
  2122.         shl      eax,TEX_SHIFT
  2123.         add      eax,ebx
  2124.         lea      eax,[eax*3+color_map]
  2125.         mov      eax,dword[eax]
  2126.      ;   cmp     [catmull_flag],1      ; put on stack z coordinate if necessary
  2127.      ;   jne      @f
  2128.         lea      edx,[ecx*3]
  2129.         push     word[edx*2+xx1-2]    ; zz1 ,2 ,3
  2130.      ; @@:
  2131.         ror      eax,16               ; eax -0xxxrrggbb -> 0xggbbxxrr
  2132.         xor      ah,ah
  2133.         push     ax         ;r
  2134.         rol      eax,8                ; eax-0xggbb00rr -> 0xbb00rrgg
  2135.         xor      ah,ah
  2136.         push     ax         ;g
  2137.         shr      eax,24
  2138.         push     ax         ;b
  2139.  
  2140.         sub      esi,4
  2141.         dec      cx
  2142.         jnz      .again_grd_draw
  2143.         jmp      .both_draw
  2144.  
  2145.    ;     movzx   edi,[point_index3]   ;gouraud shading according to light vector
  2146.    ;     lea     edi,[edi*3]
  2147.    ;     lea     edi,[4*edi+point_normals_rotated] ; edi - normal
  2148.    ;     mov     esi,light_vector
  2149.    ;     call    dot_product
  2150.    ;     fabs
  2151.    ;     fimul   [orginal_color_r]
  2152.    ;     fistp   [temp_col]
  2153.    ;     and     [temp_col],0x00ff
  2154.    ;     push    [temp_col]
  2155.    ;     push    [temp_col]
  2156.    ;     push    [temp_col]
  2157.  
  2158.    ;     movzx   edi,[point_index2]
  2159.    ;     lea     edi,[edi*3]
  2160.    ;     lea     edi,[4*edi+point_normals_rotated] ; edi - normal
  2161.    ;     mov     esi,light_vector
  2162.    ;     call    dot_product
  2163.    ;     fabs
  2164.    ;     fimul   [orginal_color_r]
  2165.    ;     fistp    [temp_col]
  2166.    ;     and     [temp_col],0x00ff
  2167.    ;     push    [temp_col]
  2168.    ;     push    [temp_col]
  2169.    ;     push    [temp_col]
  2170.  
  2171.    ;     movzx   edi,[point_index1]
  2172.    ;     lea     edi,[edi*3]
  2173.    ;     lea     edi,[4*edi+point_normals_rotated] ; edi - normal
  2174.    ;     mov     esi,light_vector
  2175.    ;     call    dot_product
  2176.    ;     fabs
  2177.    ;     fimul   [orginal_color_r]
  2178.    ;     fistp   [temp_col]
  2179.    ;     and     [temp_col],0x00ff
  2180.    ;     push    [temp_col]
  2181.    ;     push    [temp_col]
  2182.    ;     push    [temp_col]
  2183.    .rainbow:
  2184.         cmp     [catmull_flag],1      ; put on stack z coordinate if necessary
  2185.         jne      @f
  2186.         push     [zz3]
  2187.       @@:
  2188.         mov      eax,dword[yy3]
  2189.         mov      ebx,0x00ff00ff
  2190.         and      eax,ebx
  2191.         push     eax
  2192.         neg      al
  2193.         push     ax
  2194.      ;   cmp     [catmull_flag],1
  2195.      ;   jne      @f
  2196.         push     [zz2]
  2197.      ; @@:
  2198.         mov      eax,dword[yy2]
  2199.         and      eax,ebx
  2200.         push     eax
  2201.         neg      al
  2202.         push     ax
  2203.       ;  cmp     [catmull_flag],1
  2204.       ;  jne      @f
  2205.         push     [zz1]
  2206.     ;  @@:
  2207.         mov      eax,dword[yy1]
  2208.         and      eax,ebx
  2209.         push     eax
  2210.         neg      al
  2211.         push     ax
  2212.     .both_draw:
  2213.         mov     eax,dword[xx1]
  2214.         ror     eax,16
  2215.         mov     ebx,dword[xx2]
  2216.         ror     ebx,16
  2217.         mov     ecx,dword[xx3]
  2218.         ror     ecx,16
  2219.         mov     edi,[screen_ptr]
  2220.   ;      cmp     [catmull_flag],0
  2221.   ;      je      @f
  2222.         mov     esi,[Zbuffer_ptr]
  2223.         call    gouraud_triangle_z
  2224.      ;   jmp     .end_draw
  2225.      ;  @@:
  2226.      ;   call    gouraud_triangle
  2227.         jmp     .end_draw
  2228.  
  2229.      .flat_draw:                     ;**************************
  2230.                                      ; FLAT DRAWING
  2231.         mov     eax,[point_index1]
  2232.         mov     ebx,[point_index2]
  2233.         mov     ecx,[point_index3]
  2234.         shl     eax,2
  2235.         shl     ebx,2
  2236.         shl     ecx,2
  2237.         lea     eax,[eax*3]  ;+point_normals_rotated]
  2238.         add     eax,[points_normals_rot_ptr]
  2239.         lea     ebx,[ebx*3]  ;+point_normals_rotated]
  2240.         add     ebx,[points_normals_rot_ptr]
  2241.         lea     ecx,[ecx*3]  ;+point_normals_rotated]
  2242.         add     ecx,[points_normals_rot_ptr]
  2243.         fld     dword[eax]      ; x cooficient of normal vector
  2244.         fadd    dword[ebx]
  2245.         fadd    dword[ecx]
  2246.         fidiv   [i3]
  2247.         fimul   [correct_tex]
  2248.         fiadd   [correct_tex]
  2249.         fistp   dword[esp-4]    ; x temp variables
  2250.         fld     dword[eax+4]    ; y cooficient of normal vector
  2251.         fadd    dword[ebx+4]
  2252.         fadd    dword[ecx+4]
  2253.         fidiv   [i3]
  2254.         fimul   [correct_tex]
  2255.         fiadd   [correct_tex]
  2256.         fistp   dword[esp-8]   ;  y
  2257.         mov     edx,dword[esp-8]
  2258.         shl     edx,TEX_SHIFT
  2259.         add     edx,dword[esp-4]
  2260.         lea     eax,[3*edx]
  2261.         add     eax,color_map
  2262.         mov     edx,dword[eax]
  2263.  
  2264.         and     edx,0x00ffffff    ; edx = 0x00rrggbb
  2265.  
  2266.  
  2267.  
  2268.      ;   mov     ax,[zz1]      ; z position depend draw
  2269.      ;   add     ax,[zz2]
  2270.      ;   add     ax,[zz3]
  2271.      ;   cwd
  2272.      ;   idiv    [i3] ;    = -((a+b+c)/3+130)
  2273.      ;   add     ax,130
  2274.      ;   neg     al
  2275.      ;   xor     edx,edx
  2276.      ;   mov     ah,al           ;set color according to z position
  2277.      ;   shl     eax,8
  2278.      ;   mov     edx,eax
  2279.  
  2280.         mov     eax,dword[xx1]
  2281.         ror     eax,16
  2282.         mov     ebx,dword[xx2]
  2283.         ror     ebx,16
  2284.         mov     ecx,dword[xx3]
  2285.         ror     ecx,16
  2286.         mov     edi,[screen_ptr]
  2287.   ;      cmp     [catmull_flag],0
  2288.   ;      je      @f
  2289.         mov     esi,[Zbuffer_ptr]
  2290.         push    word[zz3]
  2291.         push    word[zz2]
  2292.         push    word[zz1]
  2293.         call    flat_triangle_z
  2294.         jmp     .end_draw
  2295.   ;    @@:
  2296.   ;      call    draw_triangle
  2297.   ;      jmp     .end_draw
  2298.       .env_mapping:
  2299.        ; fninit
  2300.    ;     cmp     [catmull_flag],0
  2301.    ;     je      @f
  2302.         push    [zz3]
  2303.         push    [zz2]
  2304.         push    [zz1]
  2305.     ;  @@:
  2306.         mov     esi,point_index1
  2307.         sub     esp,12
  2308.         mov     edi,esp
  2309.         mov     ecx,3
  2310.       @@:
  2311.         mov     eax,dword[esi]
  2312.         lea     eax,[eax*3]
  2313.         shl     eax,2
  2314.         add     eax,[points_normals_rot_ptr]       ;point_normals_rotated
  2315. ; #
  2316. ;        fld     dword[eax]
  2317. ;        fmul    dword[eax+4]
  2318. ;        fld1
  2319. ;        fld1
  2320. ;        faddp
  2321. ;        fmulp
  2322. ;        fimul   [correct_tex]
  2323. ;        fiadd   [correct_tex]
  2324. ;        fistp   word[edi]
  2325. ;        mov     word[edi+2],0
  2326. ;;        fistp   word[edi+2]
  2327. ; # last change
  2328.         ; texture x=(rotated point normal -> x * 255)+255
  2329.         fld     dword[eax]
  2330.         fimul   [correct_tex]
  2331.         fiadd   [correct_tex]
  2332.         fistp   word[edi]
  2333.         ; texture y=(rotated point normal -> y * 255)+255
  2334.         fld     dword[eax+4]
  2335.         fimul   [correct_tex]
  2336.         fiadd   [correct_tex]
  2337.         fistp   word[edi+2]
  2338. ; # end of last ch.
  2339.         add     edi,4
  2340.         add     esi,4
  2341.         loop    @b
  2342.  
  2343.         mov     eax,dword[xx1]
  2344.         ror     eax,16
  2345.         mov     ebx,dword[xx2]
  2346.         ror     ebx,16
  2347.         mov     ecx,dword[xx3]
  2348.         ror     ecx,16
  2349.         mov     edi,[screen_ptr]
  2350.         mov     esi,envmap
  2351.   ;      cmp     [catmull_flag],0
  2352.   ;      je      @f
  2353.  
  2354.         mov     edx,[Zbuffer_ptr]
  2355.         call    tex_triangle_z
  2356.    ;     jmp     .end_draw
  2357.    ;   @@:
  2358.    ;     call    tex_triangle
  2359.         jmp     .end_draw
  2360. ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2361.      .cubic_env_mapping:
  2362.        ; fninit
  2363.     ;    cmp     [catmull_flag],0
  2364.     ;    je      @f
  2365.         push    [zz3]
  2366.         push    [zz2]
  2367.         push    [zz1]
  2368.     ;  @@:
  2369.         mov     esi,point_index1
  2370.         sub     esp,12
  2371.         mov     edi,esp
  2372.         mov     ecx,3
  2373.       @@:
  2374.         mov     eax,dword[esi]
  2375.         lea     eax,[eax*3]
  2376.         shl     eax,2
  2377.         add     eax,[points_normals_rot_ptr]  ;point_normals_rotated
  2378. ; #
  2379.         fld     dword[eax]
  2380.         fmul    dword[eax+4]
  2381.         fld1
  2382.         fld1
  2383.         faddp
  2384.         fmulp
  2385.         fimul   [correct_tex]
  2386.         fiadd   [correct_tex]
  2387.         fistp   word[edi]
  2388.         mov     word[edi+2],0
  2389. ;        fistp   word[edi+2]
  2390. ; # last change
  2391. ;        ; texture x=(rotated point normal -> x * 255)+255
  2392. ;        fld     dword[eax]
  2393. ;        fimul   [correct_tex]
  2394. ;        fiadd   [correct_tex]
  2395. ;        fistp   word[edi]
  2396. ;        ; texture y=(rotated point normal -> y * 255)+255
  2397. ;        fld     dword[eax+4]
  2398. ;        fimul   [correct_tex]
  2399. ;        fiadd   [correct_tex]
  2400. ;        fistp   word[edi+2]
  2401. ; # end of last ch.
  2402.         add     edi,4
  2403.         add     esi,4
  2404.         loop    @b
  2405.  
  2406.         mov     eax,dword[xx1]
  2407.         ror     eax,16
  2408.         mov     ebx,dword[xx2]
  2409.         ror     ebx,16
  2410.         mov     ecx,dword[xx3]
  2411.         ror     ecx,16
  2412.         mov     edi,[screen_ptr]
  2413.         mov     esi,envmap_cub
  2414.  ;       cmp     [catmull_flag],0
  2415.  ;       je      @f
  2416.         mov     edx,[Zbuffer_ptr]
  2417.         call    tex_triangle_z
  2418.  ;       jmp     .end_draw
  2419.  ;     @@:
  2420.  ;       call    tex_triangle
  2421.         jmp     .end_draw
  2422.  
  2423. ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2424.  
  2425.       .bump_mapping:
  2426.         ; fninit
  2427.   ;      cmp     [catmull_flag],0
  2428.   ;      je      @f
  2429.  
  2430.         push    [Zbuffer_ptr]
  2431.         push    [zz3]
  2432.         push    [zz2]
  2433.         push    [zz1]
  2434. ;      @@:
  2435.         mov     esi,point_index1
  2436.         sub     esp,12
  2437.         mov     edi,esp
  2438.         mov     ecx,3
  2439.       @@:
  2440.         mov     eax,dword[esi]
  2441.         lea     eax,[eax*3]
  2442.         shl     eax,2
  2443.         add     eax,[points_normals_rot_ptr]  ;point_normals_rotated
  2444.         ; texture x=(rotated point normal -> x * 255)+255
  2445.         fld     dword[eax]
  2446.         fimul   [correct_tex]
  2447.         fiadd   [correct_tex]
  2448.         fistp   word[edi]
  2449.         ; texture y=(rotated point normal -> y * 255)+255
  2450.         fld     dword[eax+4]
  2451.         fimul   [correct_tex]
  2452.         fiadd   [correct_tex]
  2453.         fistp   word[edi+2]
  2454.  
  2455.         add     edi,4
  2456.         add     esi,4
  2457.         loop    @b
  2458.  
  2459.         mov    esi,[point_index3]      ; bump map coords
  2460.         shl    esi,2
  2461.         add    esi,tex_points
  2462.         push   dword[esi]
  2463.         mov    esi,[point_index2]
  2464.         shl    esi,2
  2465.         add    esi,tex_points
  2466. ;       lea    esi,[esi*3]
  2467. ;       lea    esi,[points+2+esi*2]
  2468.         push   dword[esi]
  2469.   ;     push   dword[xx2]
  2470.         mov    esi,[point_index1]
  2471.         shl    esi,2
  2472.         add    esi,tex_points
  2473. ;       lea     esi,[esi*3]
  2474. ;       lea     esi,[points+2+esi*2]
  2475.         push   dword[esi]
  2476.    ;    push     dword[xx1]
  2477.  
  2478.         mov     eax,dword[xx1]
  2479.         ror     eax,16
  2480.         mov     ebx,dword[xx2]
  2481.         ror     ebx,16
  2482.         mov     ecx,dword[xx3]
  2483.         ror     ecx,16
  2484.         mov     edi,[screen_ptr]
  2485.         mov     esi,envmap
  2486.         mov     edx,bumpmap            ;BUMP_MAPPING
  2487.  
  2488.  ;       cmp     [catmull_flag],0
  2489.  ;       je      @f
  2490.         call    bump_triangle_z
  2491.  ;       jmp     .end_draw
  2492.  ;     @@:
  2493.  ;       call    bump_triangle
  2494.         jmp     .end_draw
  2495.  
  2496.       .tex_mapping:
  2497.  
  2498.         ; fninit
  2499.   ;      cmp     [catmull_flag],0
  2500.   ;      je      @f
  2501.         push    [zz3]
  2502.         push    [zz2]
  2503.         push    [zz1]
  2504.    ;   @@:
  2505.         mov    esi,[point_index3]      ; tex map coords
  2506.         shl    esi,2
  2507.         add    esi,tex_points
  2508.         push   dword[esi]
  2509.         mov    esi,[point_index2]
  2510.         shl    esi,2
  2511.         add    esi,tex_points
  2512.         push   dword[esi]
  2513.         mov    esi,[point_index1]
  2514.         shl    esi,2
  2515.         add    esi,tex_points
  2516.         push   dword[esi]
  2517.  
  2518.         mov     eax,dword[xx1]
  2519.         ror     eax,16
  2520.         mov     ebx,dword[xx2]
  2521.         ror     ebx,16
  2522.         mov     ecx,dword[xx3]
  2523.         ror     ecx,16
  2524.         mov     edi,[screen_ptr]
  2525.         mov     esi,texmap
  2526.    ;     cmp     [catmull_flag],0
  2527.    ;     je      @f
  2528.          mov     edx,[Zbuffer_ptr]
  2529.         call    tex_triangle_z
  2530. ;        jmp     .end_draw
  2531. ;      @@:
  2532. ;        call    tex_triangle
  2533.         jmp     .end_draw
  2534. ;      .ray:
  2535. ;        grd_triangle according to points index
  2536. ;        cmp     [catmull_flag],0
  2537. ;        je      @f
  2538. ;        push    [zz3]                   ; spot light with attenuation
  2539. ;     @@:
  2540. ;        movzx   eax,[point_index3]      ; env_map - points color list
  2541. ;        shl     eax,1                   ; each color as word, 0x00rr00gg00bb..
  2542. ;        lea     eax,[3*eax+bumpmap]
  2543. ;        push    word[eax]
  2544. ;        push    word[eax+2]
  2545. ;        push    word[eax+4]
  2546. ;        cmp     [catmull_flag],0
  2547. ;        je      @f
  2548. ;        push    [zz2]
  2549. ;    @@:
  2550. ;        movzx   eax,[point_index2]      ; env_map - points color list
  2551. ;        shl     eax,1                   ; each color as word, 0x00rr00gg00bb..
  2552. ;        lea     eax,[eax*3+bumpmap]
  2553. ;        push    word[eax]
  2554. ;        push    word[eax+2]
  2555. ;        push    word[eax+4]
  2556. ;        cmp     [catmull_flag],0
  2557. ;        je      @f
  2558. ;        push    [zz1]
  2559. ;     @@:
  2560. ;        movzx   eax,[point_index1]      ; env_map - points color list
  2561. ;        shl     eax,1                   ; each color as word, 0xrr00gg00bb00..
  2562. ;        lea     eax,[eax*3+bumpmap]
  2563. ;        push    word[eax]
  2564. ;        push    word[eax+2]
  2565. ;        push    word[eax+4]
  2566. ;        jmp     .both_draw
  2567.  
  2568.      .grd_tex:            ; smooth shading + texture
  2569.          push   ebp
  2570.          mov    ebp,esp
  2571.          sub    esp,4
  2572.          push   ebp
  2573.  
  2574.          mov    esi,[point_index3]      ; tex map coords
  2575.          shl    esi,2
  2576.          add    esi,tex_points
  2577.          push   dword[esi]              ; texture coords as first
  2578.          mov    esi,[point_index2]      ; group of parameters
  2579.          shl    esi,2
  2580.          add    esi,tex_points
  2581.          push   dword[esi]
  2582.          mov    esi,[point_index1]
  2583.          shl    esi,2
  2584.          add    esi,tex_points
  2585.          push   dword[esi]
  2586.  
  2587.          mov     esi,point_index3
  2588.          mov     ecx,3
  2589.  
  2590.       .aagain_grd_draw:
  2591.  
  2592.         lea      edx,[ecx*3]
  2593.         push     word[edx*2+xx1-2]    ; zz1 ,2 ,3
  2594.  
  2595.         mov     eax,dword[esi]
  2596.         shl     eax,2
  2597.         lea     eax,[eax*3] ;+point_normals_rotated]
  2598.         add     eax,[points_normals_rot_ptr]
  2599.         ; texture x=(rotated point normal -> x * 255)+255
  2600.         fld     dword[eax]       ; x cooficient of normal vector
  2601.         fimul   [correct_tex]
  2602.         fiadd   [correct_tex]
  2603.         fistp   word[ebp-2]
  2604.         ; texture y=(rotated point normal -> y * 255)+255
  2605.         fld     dword[eax+4]      ; y cooficient
  2606.         fimul   [correct_tex]
  2607.         fiadd   [correct_tex]
  2608.         fistp   word[ebp-4]
  2609.  
  2610.         movzx    eax,word[ebp-4]
  2611.         movzx    ebx,word[ebp-2]
  2612.         shl      eax,TEX_SHIFT
  2613.         add      eax,ebx
  2614.         lea      eax,[eax*3+color_map]
  2615.         mov      eax,dword[eax]
  2616.  
  2617.         ror      eax,16               ; eax -0xxxrrggbb -> 0xggbbxxrr
  2618.         xor      ah,ah
  2619.         push     ax         ;r
  2620.         rol      eax,8                ; eax-0xggbb00rr -> 0xbb00rrgg
  2621.         xor      ah,ah
  2622.         push     ax         ;g
  2623.         shr      eax,24
  2624.         push     ax         ;b
  2625.  
  2626.         sub      esi,4
  2627.         dec      cx
  2628.         jnz      .aagain_grd_draw
  2629.  
  2630.         mov     eax,dword[xx1]
  2631.         ror     eax,16
  2632.         mov     ebx,dword[xx2]
  2633.         ror     ebx,16
  2634.         mov     ecx,dword[xx3]
  2635.         ror     ecx,16
  2636.         mov     edi,[screen_ptr]
  2637.         mov     edx,texmap
  2638.         mov     esi,[Zbuffer_ptr]
  2639.  
  2640.         call    tex_plus_grd_triangle
  2641.  
  2642.         pop     ebp
  2643.         mov     esp,ebp
  2644.         pop     ebp
  2645.         jmp     .end_draw
  2646.  
  2647.       .two_tex:
  2648.         push    [Zbuffer_ptr]
  2649.  
  2650.         push    word[zz3]
  2651.         push    word[zz2]
  2652.         push    word[zz1]
  2653.  
  2654.         mov    esi,[point_index3]      ; tex map coords
  2655.         shl    esi,2
  2656.         add    esi,tex_points
  2657.         push   dword[esi]
  2658.         mov    esi,[point_index2]
  2659.         shl    esi,2
  2660.         add    esi,tex_points
  2661.         push   dword[esi]
  2662.         mov    esi,[point_index1]
  2663.         shl    esi,2
  2664.         add    esi,tex_points
  2665.         push   dword[esi]
  2666.  
  2667.         mov     esi,point_index1     ; env coords
  2668.         sub     esp,12
  2669.         mov     edi,esp
  2670.         mov     ecx,3
  2671.       @@:
  2672.         mov     eax,dword[esi]
  2673.         lea     eax,[eax*3]
  2674.         shl     eax,2
  2675.         add     eax,[points_normals_rot_ptr]
  2676.         ; texture x=(rotated point normal -> x * 255)+255
  2677.         fld     dword[eax]
  2678.         fimul   [correct_tex]
  2679.         fiadd   [correct_tex]
  2680.         fistp   word[edi]
  2681.         ; texture y=(rotated point normal -> y * 255)+255
  2682.         fld     dword[eax+4]
  2683.         fimul   [correct_tex]
  2684.         fiadd   [correct_tex]
  2685.         fistp   word[edi+2]
  2686.  
  2687.         add     edi,4
  2688.         add     esi,4
  2689.         loop    @b
  2690.  
  2691.         mov     eax,dword[xx1]
  2692.         ror     eax,16
  2693.         mov     ebx,dword[xx2]
  2694.         ror     ebx,16
  2695.         mov     ecx,dword[xx3]
  2696.         ror     ecx,16
  2697.         mov     edi,[screen_ptr]
  2698.         mov     esi,texmap
  2699.         mov     edx,envmap
  2700.  
  2701.         call    two_tex_triangle_z
  2702.         jmp     .end_draw
  2703.  
  2704.    .bump_tex:
  2705.         mov    esi,[point_index3]      ; tex map coords
  2706.         shl    esi,2
  2707.         add    esi,tex_points
  2708.         push   dword[esi]
  2709.         mov    esi,[point_index2]
  2710.         shl    esi,2
  2711.         add    esi,tex_points
  2712.         push   dword[esi]
  2713.         mov    esi,[point_index1]
  2714.         shl    esi,2
  2715.         add    esi,tex_points
  2716.         push   dword[esi]
  2717.  
  2718.         push  dword texmap
  2719.  
  2720.         push  [Zbuffer_ptr]
  2721.         xor   edi,edi
  2722.  
  2723.         push    word[zz3]
  2724.         push    word[zz2]
  2725.         push    word[zz1]
  2726.  
  2727.         mov     esi,point_index1     ; env coords
  2728.         sub     esp,12
  2729.         mov     edi,esp
  2730.         mov     ecx,3
  2731.       @@:
  2732.         mov     eax,dword[esi]
  2733.         lea     eax,[eax*3]
  2734.         shl     eax,2
  2735.         add     eax,[points_normals_rot_ptr]
  2736.         ; texture x=(rotated point normal -> x * 255)+255
  2737.         fld     dword[eax]
  2738.         fimul   [correct_tex]
  2739.         fiadd   [correct_tex]
  2740.         fistp   word[edi]
  2741.         ; texture y=(rotated point normal -> y * 255)+255
  2742.         fld     dword[eax+4]
  2743.         fimul   [correct_tex]
  2744.         fiadd   [correct_tex]
  2745.         fistp   word[edi+2]
  2746.  
  2747.         add     edi,4
  2748.         add     esi,4
  2749.         loop    @b
  2750.  
  2751. ;        push  dword 1 shl 16 + 1  ; emap coords
  2752. ;        push  dword 127 shl 16 + 1
  2753. ;        push  dword 127 shl 16 + 127
  2754.  
  2755.         mov    esi,[point_index3]      ; bump map coords
  2756.         shl    esi,2
  2757.         add    esi,tex_points
  2758.         push   dword[esi]
  2759.         mov    esi,[point_index2]
  2760.         shl    esi,2
  2761.         add    esi,tex_points
  2762.         push   dword[esi]
  2763.  
  2764.         mov    esi,[point_index1]
  2765.         shl    esi,2
  2766.         add    esi,tex_points
  2767.         push   dword[esi]
  2768.  
  2769. ;        push  dword 1 shl 16 + 127
  2770. ;        push  dword 127 shl 16 + 127
  2771. ;        push  dword 1 shl 16 + 1  ; bump coords
  2772.  
  2773.         mov     eax,dword[xx1]
  2774.         ror     eax,16
  2775.         mov     ebx,dword[xx2]
  2776.         ror     ebx,16
  2777.         mov     ecx,dword[xx3]
  2778.         ror     ecx,16
  2779.         mov     edi,[screen_ptr]
  2780.         mov     esi,envmap
  2781.         mov     edx,bumpmap
  2782.  
  2783.         call bump_tex_triangle_z
  2784.  
  2785.         jmp     .end_draw
  2786.  
  2787.       .draw_smooth_line:
  2788.         mov     esi,point_index3
  2789.         mov     ecx,3
  2790.       .again_line_param:
  2791.         mov     eax,dword[esi]
  2792.         shl     eax,2
  2793.         lea     eax,[eax*3]
  2794.         add     eax,[points_normals_rot_ptr]
  2795.         ; texture ;x=(rotated point normal -> x * 255)+255
  2796.         fld     dword[eax]       ; x cooficient of normal vector
  2797.         fimul   [correct_tex]
  2798.         fiadd   [correct_tex]
  2799.         fistp   word[esp-2]
  2800.         ; texture y=(rotated point normal -> y * 255)+255
  2801.         fld     dword[eax+4]      ; y cooficient
  2802.         fimul   [correct_tex]
  2803.         fiadd   [correct_tex]
  2804.         fistp   word[esp-4]
  2805.  
  2806.         movzx    eax,word[esp-4]
  2807.         movzx    ebx,word[esp-2]
  2808.         shl      eax,TEX_SHIFT
  2809.         add      eax,ebx
  2810.         lea      eax,[eax*3+color_map]
  2811.         mov      eax,dword[eax]
  2812.         lea      ebx,[ecx-1]
  2813.         shl      ebx,2
  2814.         mov      [ebx+col1],eax
  2815.  
  2816.         sub      esi,4
  2817.         dec      ecx
  2818.         jnz      .again_line_param
  2819.  
  2820. ;        mov     eax,[edges_ptr]         ;   this not works correctly
  2821. ;        add     eax,[edges_counter]     ;   I mean chosing overlapped  edges.
  2822. ;        mov     bl,[eax]                ;
  2823. ;        test    bl,00000001b            ;
  2824. ;        jz      @f                      ;
  2825.         mov     edi,[screen_ptr]
  2826.         mov     esi,[Zbuffer_ptr]
  2827.  
  2828.         mov     eax,[col1]
  2829.         movzx   bx,al
  2830.         push    bx                ; b
  2831.         movzx   bx,ah
  2832.         push    bx
  2833.         rol     eax,16
  2834.         xor     ah,ah
  2835.         push    ax
  2836.         push    [zz1]
  2837.         push    [yy1]
  2838.         push    [xx1]
  2839.  
  2840.         mov     eax,[col2]
  2841.         movzx   bx,al
  2842.         push    bx                ; b
  2843.         movzx   bx,ah
  2844.         push    bx
  2845.         rol     eax,16
  2846.         xor     ah,ah
  2847.         push    ax
  2848.         push    [zz2]
  2849.         push    [yy2]
  2850.         push    [xx2]
  2851.  
  2852.         call    smooth_line
  2853.      @@:
  2854. ;        mov     eax,[edges_ptr]       ;  this not works correctly
  2855. ;        add     eax,[edges_counter]
  2856. ;        mov     bl,[eax]
  2857. ;        test    bl,00000010b
  2858. ;        jz      @f
  2859.  
  2860.         mov     edi,[screen_ptr]
  2861.         mov     esi,[Zbuffer_ptr]
  2862.  
  2863.         mov     eax,[col1]
  2864.         movzx   bx,al
  2865.         push    bx                ; b
  2866.         movzx   bx,ah
  2867.         push    bx
  2868.         rol     eax,16
  2869.         xor     ah,ah
  2870.         push    ax
  2871.         push    [zz1]
  2872.         push    [yy1]
  2873.         push    [xx1]
  2874.  
  2875.         mov     eax,[col3]
  2876.         movzx   bx,al
  2877.         push    bx                ; b
  2878.         movzx   bx,ah
  2879.         push    bx
  2880.         rol     eax,16
  2881.         xor     ah,ah
  2882.         push    ax
  2883.         push    [zz3]
  2884.         push    [yy3]
  2885.         push    [xx3]
  2886.  
  2887.         call    smooth_line
  2888.       @@:
  2889.  
  2890. ;        mov     eax,[edges_ptr]        ;  this not works correctly
  2891. ;        add     eax,[edges_counter]    ;
  2892. ;        mov     bl,[eax]               ;
  2893. ;        test    bl,00000100b           ;
  2894. ;        jz      @f                     ;
  2895.  
  2896.         mov     edi,[screen_ptr]
  2897.         mov     esi,[Zbuffer_ptr]
  2898.  
  2899.         mov     eax,[col3]
  2900.         movzx   bx,al
  2901.         push    bx                ; b
  2902.         movzx   bx,ah
  2903.         push    bx
  2904.         rol     eax,16
  2905.         xor     ah,ah
  2906.         push    ax
  2907.         push    [zz3]
  2908.         push    [yy3]
  2909.         push    [xx3]
  2910.  
  2911.         mov     eax,[col2]
  2912.         movzx   bx,al
  2913.         push    bx                ; b
  2914.         movzx   bx,ah
  2915.         push    bx
  2916.         rol     eax,16
  2917.         xor     ah,ah
  2918.         push    ax
  2919.         push    [zz2]
  2920.         push    [yy2]
  2921.         push    [xx2]
  2922.  
  2923.         call    smooth_line
  2924.       @@:
  2925.  
  2926.       .end_draw:
  2927.         pop     esi
  2928.         add     esi,12
  2929.         inc     [edges_counter]
  2930.         pop     ecx
  2931.         sub     ecx,1
  2932.      ;   cmp     dword[esi],-1
  2933.         jnz     .again_dts
  2934. ret
  2935.  
  2936.  
  2937.  
  2938.  
  2939.  
  2940.  
  2941.  
  2942.  
  2943.  
  2944.  
  2945.  
  2946. draw_handlers:
  2947.  
  2948.        push  ebp
  2949.        mov   ebp,esp
  2950.  
  2951.        .counter  equ ebp-16
  2952.        .xres3m18 equ ebp-8
  2953.        .xres2m12 equ ebp-12
  2954.  
  2955.  
  2956.      ; init counter
  2957.        sub   esp,12
  2958.        push  dword 0
  2959.  
  2960.        movzx eax,word[size_x_var]
  2961.        lea   ebx,[eax*3]
  2962.        sub   ebx,18
  2963.        add   eax,eax
  2964.        sub   eax,12
  2965.        mov   [.xres3m18],ebx
  2966.        mov   [.xres2m12],eax
  2967.  
  2968.        mov   esi,[points_translated_ptr]
  2969.      .loop:
  2970.        push  esi
  2971.                                          ; DO culling AT FIRST
  2972.         cmp     [culling_flag],1         ; (if culling_flag = 1)
  2973.         jne     .no_culling
  2974.         mov     edi,[.counter]           ; *********************************
  2975.         lea     edi,[edi*3]
  2976.         shl     edi,2
  2977.         add     edi,[points_normals_rot_ptr]
  2978.         mov     eax,[edi+8]              ; check sign of z coof
  2979.         shr     eax,31
  2980.         cmp     eax,1
  2981.         jnz     .skip
  2982.     .no_culling:
  2983.        mov   eax,[esi]
  2984.        movzx ebx,ax         ; ebx - x
  2985.        shr   eax,16         ; eax - y
  2986.        cmp   eax,4          ; check if markers not exceedes screen
  2987.        jle   .skip
  2988.        cmp   ebx,4
  2989.        jle   .skip
  2990.        movzx edx,word[size_x_var]
  2991.        sub   edx,4
  2992.        movzx ecx,word[size_y_var]
  2993.        sub   ecx,4
  2994.        cmp   ebx,edx
  2995.        jge   .skip
  2996.        cmp   eax,ecx
  2997.        jge   .skip
  2998.  
  2999.        movzx edx,word[size_x_var]
  3000.     ;   sub   ebx,3
  3001.     ;   sub   eax,3
  3002.        imul  eax,edx
  3003.        add   eax,ebx
  3004.        lea   edi,[eax*3]
  3005.        lea   eax,[eax*2]
  3006.        ; draw bar 6x6
  3007.        add   edi,[screen_ptr]
  3008.        add   eax,dword[vertices_index_ptr]
  3009.  
  3010.  
  3011.  
  3012.  
  3013.        mov   edx,[.counter]
  3014.        mov   ecx,6
  3015.  
  3016.      .oop:
  3017.        push  ecx
  3018.        mov   ecx,6
  3019.  
  3020.      @@:
  3021.        mov   word[edi],0x0000 ;ax
  3022.        mov   byte[edi+2],0xff   ;al
  3023.        mov   word[eax],dx
  3024.        add   eax,2
  3025.        add   edi,3
  3026.        loop  @b
  3027.        add   edi,[.xres3m18]
  3028.        add   eax,[.xres2m12]
  3029.        pop   ecx
  3030.        loop  .oop
  3031.  
  3032.     .skip:
  3033.        pop   esi
  3034.        add   esi,6
  3035.        inc   dword[.counter]
  3036.        mov   ecx,[.counter]
  3037.        cmp   ecx,[points_count_var]
  3038.        jng   .loop
  3039.  
  3040.        mov   esp,ebp
  3041.        pop   ebp
  3042.  
  3043. ret
  3044.  
  3045.  
  3046. fill_Z_buffer:
  3047.         mov     eax,0x70000000
  3048.         mov     edi,[Zbuffer_ptr]
  3049.         movzx   ecx,word[size_x_var]
  3050.         movzx   ebx,word[size_y_var]
  3051.         imul    ecx,ebx
  3052.       if     Ext>=SSE2
  3053.         movd    xmm0,eax
  3054.         shufps  xmm0,xmm0,0
  3055.         push    ecx
  3056.         mov     ecx,edi
  3057.         and     edi,0xffffff00
  3058.         and     ecx,0x000000ff
  3059.         mov     edx,ecx
  3060.         rep     stosd
  3061.         pop     ecx
  3062.         sub     ecx,edx
  3063.       @@:
  3064.         movaps  [edi],xmm0
  3065.         movaps  [edi+16],xmm0
  3066.         movaps  [edi+32],xmm0
  3067.         movaps  [edi+48],xmm0
  3068.         add     edi,64
  3069.         sub     ecx,16
  3070.         jnc     @b
  3071.       else
  3072.         rep     stosd
  3073.       end if
  3074. ret
  3075.  
  3076. read_tp_variables:            ; read [triangles_count_var] and  [points_count_var]
  3077.                               ; and  allocate memory
  3078.         xor     ebx,ebx
  3079.         xor     ebp,ebp
  3080.         mov     [points_count_var],ebx
  3081.         mov     [triangles_count_var],ebx
  3082.    if USE_LFN = 0
  3083.         mov     esi,SourceFile
  3084.    else
  3085.         mov     esi,[fptr]
  3086.    end if
  3087.  
  3088.         cmp     [esi],word 4D4Dh
  3089.         je      @f ;Must be legal .3DS file
  3090.         xor     eax,eax
  3091.         ret
  3092.     @@:
  3093.         mov     eax,dword[esi+2]
  3094.         cmp     eax,[fsize] ;This must tell the length
  3095.         je      @f
  3096.         xor     eax,eax
  3097.         ret
  3098.      @@:
  3099.         add     eax,esi
  3100.         mov     [EndFile],eax    ;
  3101.  
  3102.         add     esi,6
  3103.       @@:
  3104.         cmp     [esi],word 3D3Dh
  3105.         je      @f
  3106.         add     esi,[esi+2]
  3107.         jmp     @b
  3108.       @@:
  3109.         add     esi,6
  3110.       .find4k:
  3111.         cmp     [esi],word 4000h
  3112.         je      @f
  3113.         add     esi,[esi+2]
  3114.         cmp     esi,[EndFile]
  3115.         jc      .find4k
  3116.         jmp     .exit
  3117.       @@:
  3118.         add     esi,6
  3119.       @@:
  3120.         cmp     [esi],byte 0
  3121.         je      @f
  3122.         inc     esi
  3123.         jmp     @b
  3124.       @@:
  3125.         inc     esi
  3126.       @@:
  3127.         cmp     [esi],word 4100h
  3128.         je      @f
  3129.         add     esi,[esi+2]
  3130.         jmp     @b
  3131.       @@:
  3132.         add     esi,6
  3133.       @@:
  3134.         cmp     [esi],word 4110h
  3135.         je      @f
  3136.         add     esi,[esi+2]
  3137.         jmp     @b
  3138.       @@:
  3139.         movzx   ecx,word[esi+6]
  3140.         add     [points_count_var],ecx
  3141.  
  3142.         mov     edx,ecx
  3143.         add     esi,8
  3144.      @@:
  3145.  
  3146.         add     ebx,6
  3147.         add     esi,12
  3148.      ;   dec     ecx
  3149.         loop     @b
  3150.       @@:
  3151.  
  3152.       @@:
  3153.         cmp     [esi],word 4120h
  3154.         je      @f
  3155.         add     esi,[esi+2]
  3156.         jmp     @b
  3157.       @@:
  3158.         movzx   ecx,word[esi+6]
  3159.         add     [triangles_count_var],ecx
  3160.         add     esi,8
  3161.  
  3162.       @@:
  3163.         add     esi,8
  3164.         dec     ecx
  3165.         jnz     @b
  3166. ;        xor     ecx,ecx
  3167.         add     ebp,edx
  3168.         jmp     .find4k
  3169.         mov     eax,-1 ;<---mark if OK
  3170.       .exit:
  3171. ret
  3172.  
  3173. read_from_file:
  3174.         fninit
  3175.         mov     edi,[triangles_ptr]
  3176.         xor     ebx,ebx
  3177.         xor     ebp,ebp
  3178.         mov     [points_count_var],0
  3179.         mov     [triangles_count_var],0
  3180.    if USE_LFN = 0
  3181.         mov     esi,SourceFile
  3182.    else
  3183.         mov     esi,[fptr]
  3184.    end if
  3185.         cmp     [esi],word 4D4Dh
  3186.         jne     .exit ;Must be legal .3DS file
  3187. ;        cmp     dword[esi+2],EndFile-SourceFile
  3188. ;        jne     .exit ;This must tell the length
  3189.         mov     eax,dword[esi+2]
  3190.   ;      cmp     eax,[fsize]
  3191.   ;      jne     .exit
  3192.  
  3193.         add     eax,esi
  3194.         mov     [EndFile],eax    ;
  3195.  
  3196.         add     esi,6
  3197.       @@:
  3198.         cmp     [esi],word 3D3Dh
  3199.         je      @f
  3200.         add     esi,[esi+2]
  3201.         jmp     @b
  3202.       @@:
  3203.         add     esi,6
  3204.       .find4k:
  3205.         cmp     [esi],word 4000h
  3206.         je      @f
  3207.         add     esi,[esi+2]
  3208.         cmp     esi,[EndFile]
  3209.         jc      .find4k
  3210.         jmp     .exit
  3211.       @@:
  3212.         add     esi,6
  3213.       @@:
  3214.         cmp     [esi],byte 0
  3215.         je      @f
  3216.         inc     esi
  3217.         jmp     @b
  3218.       @@:
  3219.         inc     esi
  3220.       @@:
  3221.         cmp     [esi],word 4100h
  3222.         je      @f
  3223.         add     esi,[esi+2]
  3224.         jmp     @b
  3225.       @@:
  3226.         add     esi,6
  3227.       @@:
  3228.         cmp     [esi],word 4110h
  3229.         je      @f
  3230.         add     esi,[esi+2]
  3231.         jmp     @b
  3232.       @@:
  3233.         movzx   ecx,word[esi+6]
  3234.         add     [points_count_var],ecx
  3235.  
  3236.         mov     edx,ecx
  3237.         add     esi,8
  3238.      @@:
  3239.         push    edi
  3240.         mov     edi,[points_ptr]
  3241.         push    dword[esi+0]
  3242.         pop     dword[edi+ebx*2+0]
  3243.         push    dword[esi+4]
  3244.         pop     dword[edi+ebx*2+4]
  3245.         push    dword[esi+8]
  3246.         pop     dword[edi+ebx*2+8]
  3247.         pop     edi
  3248.  
  3249.         add     ebx,6
  3250.         add     esi,12
  3251.         dec     ecx
  3252.         jnz     @b
  3253.       @@:
  3254.   ;      mov     dword[points+ebx],-1
  3255.         push    edi
  3256.         mov     edi,[points_ptr]
  3257.         mov     dword[edi+ebx*2],-1        ; end mark (not always in use)
  3258.         pop     edi
  3259.       @@:
  3260.         cmp     [esi],word 4120h
  3261.         je      @f
  3262.         add     esi,[esi+2]
  3263.         jmp     @b
  3264.       @@:
  3265.         movzx   ecx,word[esi+6]
  3266.         add     [triangles_count_var],ecx
  3267.         add     esi,8
  3268.         ;mov     edi,triangles
  3269.       @@:
  3270.         movzx   eax,word[esi]
  3271.         stosd
  3272.         movzx   eax,word[esi+2]
  3273.         stosd
  3274.         movzx   eax,word[esi+4]
  3275.         stosd
  3276.         add     dword[edi-12],ebp
  3277.         add     dword[edi-8],ebp
  3278.         add     dword[edi-4],ebp
  3279.         add     esi,8
  3280.         dec     ecx
  3281.         jnz     @b
  3282.         add     ebp,edx
  3283.         jmp     .find4k
  3284.         mov     eax,-1 ;<---mark if OK
  3285.       .exit:
  3286.         mov     dword[edi],-1
  3287. ret
  3288.  
  3289. if USE_LFN
  3290. alloc_mem_for_tp:
  3291.         mov     eax, 68
  3292.         cmp     [re_alloc_flag],1
  3293.         jz      @f
  3294.         mov     ebx, 12
  3295.         jmp     .alloc
  3296.     @@:
  3297.         mov     ebx,20
  3298.     .alloc:
  3299.  
  3300.         mov     ecx,[triangles_count_var]
  3301.         add     ecx,20
  3302.         lea     ecx, [ecx*3]
  3303.         shl     ecx,2
  3304.         mov     edx,[triangles_ptr]
  3305.         int     0x40                   ;  -> allocate memory to triangles
  3306.         mov     [triangles_ptr], eax   ;  -> eax = pointer to allocated mem
  3307.  
  3308. ;        mov     eax, 68
  3309. ;        movzx   ecx, [triangles_count_var]
  3310. ;        inc     ecx
  3311. ;        mov     edx,[edges_ptr]
  3312. ;        int     0x40                   ;  -> allocate memory to edges
  3313. ;        mov     [edges_ptr], eax   ;  -> eax = pointer to allocated mem
  3314.  
  3315. ;        mov     eax,-1                       ; fill edges list
  3316. ;        movzx   ecx,[triangles_count_var]    ; importand if object generated
  3317. ;        shr     ecx,2
  3318. ;        inc     ecx
  3319. ;        mov     edi,[edges_ptr]
  3320. ;        cld
  3321. ;        rep     stosd
  3322.  
  3323.  
  3324. ;        mov     eax, 68
  3325. ;        mov     ebx, 12
  3326. ;        movzx   ecx, [triangles_count_var]
  3327. ;        shl     ecx, 4
  3328. ;        int     0x40
  3329. ;        mov     [triangles_w_z_ptr], eax   ; for trainagles_with_z list
  3330.                                             ; ststic  memory
  3331.  
  3332.         mov     eax, 68
  3333.         mov     ecx, [triangles_count_var]
  3334.         lea     ecx, [3+ecx*3]
  3335.         shl     ecx, 2
  3336.         mov     edx,[triangles_normals_ptr]
  3337.         int     0x40                           ;  -> allocate memory for triangles normals
  3338.         mov     [triangles_normals_ptr], eax   ;  -> eax = pointer to allocated mem
  3339.  
  3340.    ;     mov     eax, 68
  3341.    ;     movzx   ecx,[points_count_var]
  3342.    ;     lea     ecx,[2+ecx*2]
  3343.    ;     mov     edx,dword [vertices_index_ptr]
  3344.    ;     int     0x40
  3345.    ;     mov     dword[vertices_index_ptr], eax
  3346.  
  3347.         mov     eax, 68
  3348.         mov     ecx, [points_count_var]
  3349.         lea     ecx,[3+ecx*3]
  3350.         shl     ecx, 2
  3351.         mov     edx,[points_normals_ptr]
  3352.         int     0x40
  3353.         mov     [points_normals_ptr], eax
  3354.       ;  int3
  3355.  
  3356.  
  3357.       ;  int3
  3358.  
  3359.  
  3360.         mov     eax, 68
  3361.     ;    mov     ebx, 12
  3362.         mov     ecx, [points_count_var]
  3363.         lea     ecx,[3+ecx*3]
  3364.         shl     ecx, 2
  3365.         mov     edx,[points_normals_rot_ptr]
  3366.         int     0x40
  3367.         mov     [points_normals_rot_ptr], eax
  3368.  
  3369.         mov     eax, 68
  3370.         mov     edx,[points_ptr]
  3371.         int     0x40
  3372.         mov     [points_ptr], eax
  3373.  
  3374.         mov     eax, 68
  3375.         mov     edx,[points_rotated_ptr]
  3376.         int     0x40
  3377.         mov     [points_rotated_ptr], eax
  3378.  
  3379.         mov     eax, 68
  3380.         mov     ecx, [points_count_var]
  3381.         inc     ecx
  3382.         shl     ecx, 3
  3383.         mov     edx,[points_translated_ptr]
  3384.         int     0x40
  3385.         mov     [points_translated_ptr], eax
  3386. ret
  3387. end if
  3388.  
  3389.  
  3390. read_from_disk:
  3391. if USE_LFN
  3392. ;-
  3393.     mov     eax, 68
  3394.     mov     ebx, 11
  3395.     int     0x40                   ;  -> create heap
  3396.  
  3397.  ;    mov     eax, 70
  3398.  ;    mov     ebx, file_info
  3399.  ;    mov     dword[ebx], 5          ;  -> subfunction number
  3400.  ;    int     0x40                   ;  -> read file size
  3401.  ;    mov     ebx, [fptr]
  3402.  ;    mov     ebx, dword[ebx+32]
  3403.  ;    inc     ebx
  3404.  ;    mov     [fsize], ebx
  3405.  
  3406.  
  3407.  
  3408.     ;   mov     eax, 68
  3409.     ;   mov     ebx, 12
  3410.     ;   mov     ecx, [fsize]
  3411.     ;   int     0x40                   ;  -> allocate memory for file
  3412.     ;   mov     [fptr], eax            ;  -> eax = pointer to allocated mem
  3413.  
  3414.  ;    mov     eax, 70
  3415.  ;    mov     ebx, file_info
  3416.  ;    mov     dword[ebx],0
  3417.  ;    int     0x40                   ; -> read file
  3418.    ;load kpacked files by Leency
  3419.        mov     eax,68
  3420.        mov     ebx,27
  3421.        mov     ecx,file_name
  3422.        int     0x40
  3423.  
  3424.        mov     [fsize],edx
  3425.        mov     [file_info+16],eax
  3426.  
  3427.        test    eax,eax
  3428.        jnz     .open_opened_well
  3429.        mov     eax,6 ;otherwise => failed
  3430.        jmp     @f
  3431.        .open_opened_well:
  3432.        xor     eax,eax
  3433.     @@:
  3434. else
  3435.     mov      eax,58
  3436.     mov      ebx,file_info
  3437.     int      0x40
  3438.  
  3439.     mov      eax,ebx
  3440.     shr      eax,9
  3441.     inc      eax
  3442.     mov      [fsize],eax
  3443.  
  3444.  
  3445.  
  3446. ;    mov      ecx,ebx
  3447. ;    add      ecx,MEM_END
  3448. ;    mov      ebx,1
  3449. ;    mov      eax,64     ; allocate mem  - resize app mem
  3450.                         ; for points and  triangles
  3451.     int      0x40
  3452.  
  3453.     mov      eax,58
  3454.     mov      ebx,file_info
  3455.     int      0x40
  3456. end if
  3457.   ;  eax = 0   -> ok file loaded
  3458. ret
  3459.   ;  eax = 0   -> ok file loaded
  3460. ret
  3461. read_param:
  3462.     mov        esi,I_Param
  3463.     cmp        dword[esi],0
  3464.     je         .end
  3465.     cmp        byte[esi],'/'
  3466.     je         .copy
  3467.     mov        edi,esi
  3468.     mov        ecx,25   ; 25 - would be enought
  3469.     repe       scasb
  3470.     jne        .end
  3471.     dec        edi
  3472.     mov        esi,edi
  3473.  .copy:
  3474.     mov         edi,file_name
  3475.     mov         ecx,50
  3476.     rep         movsd
  3477.  .end:
  3478. ret
  3479. buttons:                                      ; draw some buttons (all but navigation and close )
  3480.         mov     edi,menu
  3481.       .again:
  3482.         mov     eax,8             ; function 8 : define and draw button
  3483.         mov     bx,[size_x_var]
  3484.         shl     ebx,16
  3485.         add     ebx,(10)*65536+62      ; [x start] *65536 + [x size]
  3486.         movzx   ecx,byte[edi]                 ; button id = position+2
  3487.         sub     cl,2
  3488.         lea     ecx,[ecx*5]
  3489.         lea     ecx,[ecx*3]
  3490.         add     ecx,25
  3491.         shl     ecx,16
  3492.         add     ecx,12
  3493.         movzx   edx,byte[edi]                   ; button id
  3494.         mov     esi,0x6688dd                    ; button color RRGGBB
  3495.         int     0x40
  3496.          ; BUTTON  LABEL
  3497.         mov     eax,4                           ; function 4 : write text to window
  3498.         movzx   ebx,byte[edi]
  3499.         sub     bl,2                            ; button id, according to position
  3500.         lea     ebx,[ebx*3]
  3501.         lea     ebx,[ebx*5]
  3502.         mov     cx,[size_x_var]
  3503.         shl     ecx,16
  3504.         add     ebx,ecx
  3505.         add     ebx,(12)*65536+28        ; [x start] *65536 + [y start]
  3506.         mov     ecx,0x00ddeeff                  ; font 1 & color ( 0xF0RRGGBB )
  3507.         lea     edx,[edi+1]                     ; pointer to text beginning
  3508.         mov     esi,10                          ; text length
  3509.         int     0x40
  3510.         cmp     byte[edi+11],255                ; if max_flag=255
  3511.         je      @f                              ; skip
  3512.         ; flag description
  3513. ;       mov     eax,4                           ; function 4 : write text to window
  3514. ;       movzx   ebx,byte[edi]
  3515. ;       sub     bl,2
  3516. ;       lea     ebx,[ebx*3]
  3517. ;       lea     ebx,[ebx*5]
  3518. ;       add     ebx,(SIZE_X+12+70)*65536+28     ; [x start] *65536 + [y start]
  3519.         add     ebx,70*65536
  3520. ;       mov     ecx,0x00ddeeff                  ; font 1 & color ( 0xF0RRGGBB )
  3521.         movzx   edx,byte[edi+12]                ; current flag
  3522.         shl     edx,2                           ; * 4 = text length
  3523.         add     edx,dword[edi+13]               ; pointer to text beginning
  3524.         mov     esi,4                           ; text length
  3525.         int     0x40
  3526.  
  3527.     @@:
  3528.         add     edi,17
  3529.         cmp     byte[edi],-1
  3530.         jnz     .again
  3531. ret
  3532. ;   *********************************************
  3533. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  3534. ;   *********************************************
  3535.     draw_window:
  3536.         mov     eax,12          ; function 12:tell os about windowdraw
  3537.         mov     ebx,1           ; 1, start of draw
  3538.         int     0x40
  3539.  
  3540.         ; DRAW WINDOW
  3541.         mov     eax,0  ; function 0 : define and draw window
  3542.         mov     bx,[x_start]
  3543.         shl     ebx,16
  3544.         mov     cx,[y_start]
  3545.         shl     ecx,16
  3546. ;ebx -  [x start] *65536 + [x size]
  3547. ;ecx -  [y start] *65536 + [y size]
  3548.         mov     bx,[size_x_var]
  3549.         add     bx,115
  3550.         mov     cx,[size_y_var]
  3551.         add     cx,30
  3552.     ; @@:
  3553.         mov     edx,0x13000000  ; color of work area RRGGBB,8->color gl
  3554.         mov     edi,labelt      ; WINDOW LABEL
  3555.         int     0x40
  3556.  
  3557.         call    buttons         ; more buttons
  3558.  
  3559.         .Y_ADD equ 2   ;-> offset of 'add vector' buttons
  3560.  
  3561.         ; ADD VECTOR LABEL      ; add vector buttons - 30 ++
  3562.         mov     eax,4           ; function 4 : write text to window
  3563.         movzx   ebx,word[size_x_var]
  3564.         shl     ebx,16
  3565.         add     ebx,(12)*65536+(168+15*(13+.Y_ADD))   ; [x start] *65536 + [y start]
  3566.         mov     ecx,0x00ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  3567.         mov     edx,labelvector      ; pointer to text beginning
  3568.         mov     esi,labelvectorend-labelvector     ; text length
  3569.     ;    cmp     [move_flag],2
  3570.     ;    jne     @f
  3571.     ;    add     edx,navigation_size
  3572.     ;  @@:
  3573.         int     0x40
  3574.          ; VECTOR Y- BUTTON
  3575.         mov     eax,8           ; function 8 : define and draw button
  3576.         movzx   ebx,word[size_x_var]
  3577.         shl     ebx,16
  3578.         add     ebx,30*65536+20     ; [x start] *65536 + [x size]
  3579.         mov     ecx,(165+15*(14+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  3580.         mov     edx,30           ; button id
  3581.         mov     esi,0x6688dd    ; button color RRGGBB
  3582.         int     0x40
  3583.         ;VECTOR Y- LABEL
  3584.         mov     eax,4           ; function 4 : write text to window
  3585.         movzx   ebx,word[size_x_var]
  3586.         shl     ebx,16
  3587.         add     ebx,(32)*65536+(168+15*(14+.Y_ADD))   ; [x start] *65536 + [y start]
  3588.         mov     ecx,0x00ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  3589.         mov     edx,labelyminus      ; pointer to text beginning
  3590.         mov     esi,labelyminusend-labelyminus     ; text length
  3591.         cmp     [move_flag],2
  3592.    ;     jne     @f
  3593.    ;     add     edx,navigation_size
  3594.    ;   @@:
  3595.         int     0x40
  3596.         ; VECTOR Z+ BUTTON
  3597.         mov     eax,8           ; function 8 : define and draw button
  3598.         movzx   ebx,word[size_x_var]
  3599.         shl     ebx,16
  3600.         add     ebx,(51)*65536+21     ; [x start] *65536 + [x size]
  3601.         mov     ecx,(165+15*(14+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  3602.         mov     edx,31           ; button id
  3603.         mov     esi,0x6688dd    ; button color RRGGBB
  3604.         int     0x40
  3605.         ;VECTOR Z+ LABEL
  3606.         mov     eax,4           ; function 4 : write text to window
  3607.         movzx   ebx,word[size_x_var]
  3608.         shl     ebx,16
  3609.         add     ebx,(53)*65536+(168+15*(14+.Y_ADD))   ; [x start] *65536 + [y start]
  3610.         mov     ecx,0x00ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  3611.         mov     edx,labelzplus      ; pointer to text beginning
  3612.         mov     esi,labelzplusend-labelzplus     ; text length
  3613.    ;     cmp     [move_flag],2
  3614.    ;     jne     @f
  3615.    ;     add     edx,navigation_size
  3616.    ;   @@:
  3617.  
  3618.         int     0x40
  3619.         ; VECTOR x- BUTTON
  3620.         mov     eax,8           ; function 8 : define and draw button
  3621.         movzx   ebx,word[size_x_var]
  3622.         shl     ebx,16
  3623.         add     ebx,(10)*65536+21     ; [x start] *65536 + [x size]
  3624.         mov     ecx,(165+15*(15+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  3625.         mov     edx,32           ; button id
  3626.         mov     esi,0x6688dd    ; button color RRGGBB
  3627.         int     0x40
  3628.         ;VECTOR x- LABEL
  3629.         mov     eax,4           ; function 4 : write text to window
  3630.         movzx   ebx,word[size_x_var]
  3631.         shl     ebx,16
  3632.         add     ebx,(12)*65536+(168+15*(15+.Y_ADD))   ; [x start] *65536 + [y start]
  3633.         mov     ecx,0x00ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  3634.         mov     edx,labelxminus      ; pointer to text beginning
  3635.         mov     esi,labelxminusend-labelxminus     ; text length
  3636.    ;     cmp     [move_flag],2
  3637.    ;     jne     @f
  3638.    ;     add     edx,navigation_size
  3639.    ;   @@:
  3640.         int     0x40
  3641.         ; VECTOR x+ BUTTON
  3642.         mov     eax,8           ; function 8 : define and draw button
  3643.         movzx   ebx,word[size_x_var]
  3644.         shl     ebx,16
  3645.         add     ebx,(51)*65536+21     ; [x start] *65536 + [x size]
  3646.         mov     ecx,(165+15*(15+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  3647.         mov     edx,33           ; button id
  3648.         mov     esi,0x6688dd    ; button color RRGGBB
  3649.         int     0x40
  3650.         ;VECTOR x+ LABEL
  3651.         mov     eax,4           ; function 4 : write text to window
  3652.         movzx   ebx,word[size_x_var]
  3653.         shl     ebx,16
  3654.         add     ebx,(53)*65536+(168+15*(15+.Y_ADD))   ; [x start] *65536 + [y start]
  3655.         mov     ecx,0x00ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  3656.         mov     edx,labelxplus      ; pointer to text beginning
  3657.         mov     esi,labelxplusend-labelxplus     ; text length
  3658.    ;     cmp     [move_flag],2
  3659.    ;     jne     @f
  3660.    ;     add     edx,navigation_size
  3661.    ;   @@:
  3662.         int     0x40
  3663.         ; VECTOR z- BUTTON
  3664.         mov     eax,8           ; function 8 : define and draw button
  3665.         movzx   ebx,word[size_x_var]
  3666.         shl     ebx,16
  3667.         add     ebx,(10)*65536+62-41     ; [x start] *65536 + [x size]
  3668.         mov     ecx,(25+140+15*(16+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  3669.         mov     edx,34           ; button id
  3670.         mov     esi,0x6688dd    ; button color RRGGBB
  3671.         int     0x40
  3672.         ;VECTOR z- LABEL
  3673.         mov     eax,4           ; function 4 : write text to window
  3674.         movzx   ebx,word[size_x_var]
  3675.         shl     ebx,16
  3676.         add     ebx,(12)*65536+(168+15*(16+.Y_ADD))   ; [x start] *65536 + [y start]
  3677.         mov     ecx,0x00ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  3678.         mov     edx,labelzminus      ; pointer to text beginning
  3679.         mov     esi,labelzminusend-labelzminus     ; text length
  3680.    ;     cmp     [move_flag],2
  3681.    ;     jne     @f
  3682.    ;     add     edx,navigation_size
  3683.    ;   @@:
  3684.         int     0x40
  3685.        ;VECTOR Y+ BUTTON
  3686.         mov     eax,8           ; function 8 : define and draw button
  3687.         movzx   ebx,word[size_x_var]
  3688.         shl     ebx,16
  3689.         add     ebx,(10+20)*65536+20     ; [x start] *65536 + [x size]
  3690.         mov     ecx,(165+15*(16+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  3691.         mov     edx,35           ; button id
  3692.         mov     esi,0x6688dd    ; button color RRGGBB
  3693.         int     0x40
  3694.         ;VECTOR Y+ LABEL
  3695.         mov     eax,4           ; function 4 : write text to window
  3696.         movzx   ebx,word[size_x_var]
  3697.         shl     ebx,16
  3698.         add     ebx,(32)*65536+(168+15*(16+.Y_ADD))   ; [x start] *65536 + [y start]
  3699.         mov     ecx,0x00ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  3700.         mov     edx,labelyplus      ; pointer to text beginning
  3701.         mov     esi,labelyplusend-labelyplus     ; text length
  3702.    ;     cmp     [move_flag],2
  3703.    ;     jne     @f
  3704.    ;     add     edx,navigation_size
  3705.    ;   @@:
  3706.         int     0x40
  3707.  
  3708.         mov     eax,12          ; function 12:tell os about windowdraw
  3709.         mov     ebx,2           ; 2, end of draw
  3710.         int     0x40
  3711.         ret
  3712.  
  3713.  
  3714.    ; DATA AREA  ************************************
  3715.  
  3716.    include 'DATA.INC'
  3717.    align 16
  3718. MEM_END:
  3719.