Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. ; application : View3ds ver. 0.060 - tiny .3ds files viewer.
  3. ; compiler    : FASM
  4. ; system      : KolibriOS
  5. ; author      : Macgub aka Maciej Guba
  6. ; email       : macgub3@wp.pl
  7. ; web         : www.macgub.hekko.pl
  8. ; Fell free to use this intro in your own distribution of KolibriOS/MenuetOS.
  9. ; Special greetings to all MenuetOS maniax in the world.
  10. ; I hope because my intros Christian Belive will be near to each of You.
  11.  
  12.  
  13. ; Some adjustments made by Madis Kalme
  14. ; madis.kalme@mail.ee
  15. ; I tried optimizing it a bit, but don't know if it was successful. The objects
  16. ; can be:
  17. ; 1) Read from a file (*.3DS standard)
  18. ; 2) Written in manually (at the end of the code)
  19. ;include 'proc32.inc'
  20.  
  21. SIZE_X equ 512
  22. SIZE_Y equ 512                                 ;      /////     I want definitely
  23. TIMEOUT equ 10                                 ;     ------     say:
  24. ROUND equ 10                                   ;     \ @ @/     keep smiling every
  25. TEX_X equ 512     ; texture width              ;      \ ./    / day.
  26. TEX_Y equ 512     ;         height             ;       \/    /
  27. TEX_SHIFT equ 9  ; texture width shifting      ;     __||__ /
  28. TEXTURE_SIZE EQU (TEX_X * TEX_Y)-1             ;   /|      |
  29. TEX equ  SHIFTING ;  TEX={SHIFTING | FLUENTLY} ;  / \      /
  30. FLUENTLY = 0                                   ; /   |    |
  31. SHIFTING = 1                                   ;     ------
  32. CATMULL_SHIFT equ 8                            ;      |  |
  33. LIGHT_SIZE equ 22                              ;      |  |
  34. NON   =   0                                    ;     -/  \-
  35. MMX   =   1
  36. SSE   =   2
  37. SSE2  =   3
  38. Ext   =   MMX              ;Ext={ NON | MMX | SSE | SSE2 }
  39.  
  40. ; 0 for short names (Menuet-compatible), 1 for long names (Kolibri features)
  41. USE_LFN = 1
  42.  
  43. use32
  44.         org    0x0
  45.         db     'MENUET01'       ; 8 byte id
  46.         dd     0x01             ; header version
  47.         dd     START            ; start of code
  48.         dd     I_END            ; size of image
  49.         dd     MEM_END          ; memory for app
  50.         dd     MEM_END          ; esp
  51.         dd     I_Param          ; I_Param
  52.         dd     0x0              ; I_Icon
  53.  
  54. START:    ; start of execution
  55.         cld
  56.         call   alloc_buffer_mem
  57.         call   read_param
  58.         call   read_from_disk    ; read, if all is ok eax = 0
  59.         cmp    eax,0
  60.         jne    .gen
  61.         call   read_tp_variables ; init points and triangles count variables
  62.         cmp    eax,0
  63.         je     .gen
  64.         jmp    .malloc
  65.     .gen:
  66.      if USE_LFN
  67.         mov    [triangles_count_var],1000
  68.         mov    [points_count_var],1000
  69.         call   alloc_mem_for_tp
  70.      end if
  71.         call   generate_object
  72.         jmp    .opt
  73.     .malloc:
  74.      if USE_LFN
  75.         call   alloc_mem_for_tp
  76.      end if
  77.         call   read_from_file
  78.     .opt:
  79.         call   optimize_object1     ;  proc in file b_procs.asm
  80.                                     ;  set point(0,0,0) in center and  calc all coords
  81.                                     ;  to be in <-1.0,1.0>
  82.         call   normalize_all_light_vectors
  83.         call   init_triangles_normals2
  84.         call   init_point_normals
  85.         call   init_envmap2
  86.         call   init_envmap_cub
  87.         call   generate_texture2
  88.         call   init_sincos_tab
  89.  
  90.         call   do_color_buffer   ; intit color_map
  91.         mov    edi,bumpmap
  92.         call   calc_bumpmap
  93.         call   calc_bumpmap_coords   ; bump and texture mapping
  94.         call   draw_window
  95.  
  96.  
  97. still:
  98.  
  99.         mov     eax,23          ; wait here for event with timeout
  100.         mov     ebx,TIMEOUT
  101.         cmp     [speed_flag],1
  102.         jne     .skip
  103.         mov     eax,11
  104.     .skip:
  105.         int     0x40
  106.  
  107.         cmp     eax,1           ; redraw request ?
  108.         je      red
  109.         cmp     eax,2           ; key in buffer ?
  110.         je      key
  111.         cmp     eax,3           ; button in buffer ?
  112.         je      button
  113.  
  114.         jmp     noclose
  115.  
  116.     red:                        ; redraw
  117.         call    draw_window
  118.  
  119.         jmp     noclose
  120.  
  121.     key:                        ; key
  122.         mov     eax,2           ; just read it and ignore
  123.         int     0x40
  124.         jmp     noclose
  125.  
  126.     button:                     ; button
  127.         mov     eax,17          ; get id
  128.         int     0x40
  129.  
  130.         cmp     ah,1            ; button id=1 ?
  131.         jne     @f
  132.  
  133.         mov     eax,-1          ; close this program
  134.         int     0x40
  135.     @@:
  136.         cmp     ah,30
  137.         jge     add_vec_buttons
  138.         call    update_flags          ; update flags and write labels of flags
  139.  
  140.                                       ; do other operations according to flag
  141.         cmp     ah,3                  ; ah = 3 -> shading model
  142.         jne     .next_m6
  143.         cmp     [dr_flag],2
  144.         jne     @f
  145.    ;     call    init_envmap2    ;   <----! this don't works in env mode
  146.                                  ;          and more than ~18 kb objects
  147.  ;       call    init_envmap_cub2
  148.      @@:
  149.         cmp     [dr_flag],4
  150.         jne     @f
  151.         call    generate_texture2
  152.  
  153.      @@:
  154.      .next_m6:
  155.                                       ; ah = 5 -> scale-
  156.         cmp     ah,5
  157.         jne     @f
  158.         mov     [scale],0.7
  159.         fninit
  160.         fld     [rsscale]
  161.         fmul    [scale]
  162.         fstp    [rsscale]
  163.  
  164.       @@:
  165.         cmp     ah,6                 ; ah = 6 ->  scale+
  166.         jne     @f
  167.         mov     [scale],1.3
  168.         fninit
  169.         fld     [rsscale]
  170.         fmul    [scale]
  171.         fstp    [rsscale]
  172.  
  173.       @@:
  174.         cmp     ah,9    ; lights random                 ;    'flat'  0
  175.         jne     .next_m5                                ;    'grd '  1
  176.         call    make_random_lights                      ;    'env '  2
  177.         call    normalize_all_light_vectors             ;    'bump'  3
  178.         call    do_color_buffer   ; intit color_map     ;    'tex '  4
  179.       ;  cmp     [emboss_flag],1                         ;    'pos '  5
  180.       ;  je      @f                                      ;    'dots'  6
  181.       ;  cmp     [dr_flag],8
  182.       ;  jge     @f
  183.       ;  cmp     [dr_flag],2                             ;    'txgr'  7
  184.       ;  jl      .next_m5                            ;    '2tex'  8
  185.       ;  cmp     [dr_flag],3                             ;    'btex'  9
  186.       ;  jg      .next_m5
  187.     ; @@:
  188.         call    init_envmap2    ; update env map if shading model = environment or bump
  189.     .next_m5:
  190.         cmp      ah,11
  191.         je       @f
  192.         cmp      ah,12
  193.         je       @f
  194.         cmp      ah,13
  195.         jne      .next_m4
  196.       @@:
  197.         call     mirror
  198.      .next_m4:
  199.         cmp      ah,14
  200.         jne      @f
  201.         call     exchange
  202.      @@:
  203.         cmp      ah,15
  204.         jne      @f
  205.         cmp      [emboss_flag],1
  206.         call     init_envmap2
  207.      @@:
  208. ;        cmp      ah,17
  209. ;        jne      .next_m
  210. ;        cmp      [move_flag],2
  211. ;        jne      @f
  212. ;        call     draw_window             ; redraw other labels to navigation buttons
  213. ;      @@:
  214. ;        cmp      [move_flag],0
  215. ;        jne      .next_m
  216. ;        call     draw_window             ; redraw other labels to navigation buttons
  217.      .next_m:
  218.         cmp      ah,18
  219.         jne      .next_m2
  220.      if USE_LFN
  221.         mov      [re_alloc_flag],1       ; reallocate memory
  222.         mov      [triangles_count_var],1000
  223.         mov      [points_count_var],1000
  224.         call     alloc_mem_for_tp
  225.         mov      [re_alloc_flag],0
  226.      end if
  227.         mov      bl,[generator_flag]
  228.         or       bl,bl
  229.         jz       .next_m2
  230.         cmp      bl,1
  231.         jne      @f
  232.         call     generate_object
  233.         jmp      .calc_norm
  234.       @@:
  235.         cmp      bl,4
  236.         jg       @f
  237.         movzx    ax,bl                ; ax < - object number
  238.         call     generate_object2
  239.         jmp     .calc_norm
  240.       @@:
  241.         call    generate_object3
  242.       .calc_norm:
  243.         call    optimize_object1
  244.         call    init_triangles_normals2
  245.         call    init_point_normals
  246.         call    calc_bumpmap_coords   ; bump and texture mapping
  247.  
  248.      .next_m2:
  249.         cmp      ah,19
  250.         je       @f
  251.         cmp      ah,20
  252.         jne      .next_m3
  253.      @@:
  254.         mov      edi,bumpmap
  255.         call     calc_bumpmap
  256.      .next_m3:
  257.         cmp     ah,21            ; re map bumps, texture coordinates
  258.         jne     @f
  259.         call    calc_bumpmap_coords
  260.       @@:
  261.         jmp     noclose
  262.  
  263.  
  264.                                ; there are 6 navigation buttons each
  265.    add_vec_buttons:            ; can move: object, camera,.. list is open
  266.                                ;
  267.         cmp     ah,30
  268.         jne     .next
  269.         cmp     [move_flag],1
  270.         je      @f
  271. ;        cmp     [move_flag],2
  272. ;        je      .set_light1
  273.         sub     [vect_y],10
  274.         jmp     .next
  275.       @@:
  276.         sub     [yobs],10   ;  observator = camera position
  277.         jmp     .next
  278.  
  279. ;--------------------------------------------------
  280. ;      .set_light1:          ;  r -
  281. ;        movzx   ebx,[light_no_flag]  ; * 22
  282. ;        mov     ecx,ebx
  283. ;        shl     ebx,4
  284. ;        shl     ecx,1
  285. ;        add     ebx,ecx
  286. ;        shl     ecx,1
  287. ;        add     ebx,ecx
  288. ;        add     ebx,lights+6    ; 6 -> light vector size
  289. ;
  290. ;        movzx   ecx,[light_comp_flag]
  291. ;        lea     ecx,[ecx*3}
  292. ;        add     ebx,ecx         ; ebx ->  color to set
  293.  
  294. ;---------------------------------------------------
  295.       .next:
  296.         cmp     ah,31
  297.         jne     .next1
  298.         cmp     [move_flag],1
  299.         je      @f
  300.  
  301.         add     [vect_z],10
  302.         jmp     .next1
  303.       @@:
  304.         add     [zobs],10         ;  observator = camera position
  305.      .next1:
  306.         cmp     ah,33
  307.         jne     .next2
  308.         cmp     [move_flag],1
  309.         je      @f
  310.  
  311.         sub     [vect_x],10
  312.         jmp     .next2
  313.       @@:
  314.         sub     [xobs],10         ;  observator = camera position
  315.       .next2:
  316.         cmp     ah,32
  317.         jne     .next3
  318.         cmp     [move_flag],1
  319.         je      @f
  320.  
  321.         add     [vect_x],10
  322.         jmp     .next3
  323.       @@:
  324.         add     [xobs],10         ;  observator = camera position
  325.       .next3:
  326.         cmp     ah,34
  327.         jne     .next4
  328.         cmp     [move_flag],1
  329.         je      @f
  330.  
  331.         sub     [vect_z],10
  332.         jmp     .next4
  333.       @@:
  334.         sub     [zobs],10         ;  observator = camera position
  335.       .next4:
  336.         cmp     ah,35
  337.         jne     .next5
  338.         cmp     [move_flag],1
  339.         je      @f
  340.  
  341.       ;  call    add_vector
  342.         add     [vect_y],10
  343.         jmp     .next5
  344.       @@:
  345.         add     [yobs],10         ;  observator = camera position
  346.       .next5:
  347.  
  348.  
  349.  
  350.     noclose:
  351.  
  352.         cmp     [r_flag],2
  353.         jne     .no_x
  354.         inc     [angle_x]
  355.         and     [angle_x],0xff
  356.         mov     [angle_z],0
  357.         jmp     .end_rot
  358.  
  359.       .no_x:
  360.         cmp     [r_flag],0
  361.         jne     .no_y
  362.         inc     [angle_y]
  363.         and     [angle_y],0xff
  364.         mov     [angle_z],0
  365.         jmp     .end_rot
  366.  
  367.       .no_y:
  368.         cmp     [r_flag],1
  369.         jne     .end_rot
  370.         mov     cx,[angle_x]
  371.         inc     cx
  372.         and     cx,0xff
  373.         mov     [angle_z],0
  374.         mov     [angle_y],cx
  375.         mov     [angle_x],cx
  376.      .end_rot:
  377.  
  378.         mov     esi,angle_x
  379.         mov     edi,matrix
  380.         call    make_rotation_matrix
  381.     RDTSC
  382.     push eax
  383.         mov     esi,[points_normals_ptr]
  384.         mov     edi,[points_normals_rot_ptr]
  385.         mov     ebx,matrix
  386.         movzx   ecx,[points_count_var]
  387.         call    rotary
  388.  
  389.         mov     esi,matrix
  390.         call    add_scale_to_matrix
  391.  
  392.         mov     esi,[points_ptr]
  393.         mov     edi,[points_rotated_ptr]
  394.         mov     ebx,matrix
  395.         movzx   ecx,[points_count_var]
  396.         call    rotary
  397.  
  398. ;    RDTSC
  399. ;    pop    ebx
  400. ;    sub    eax,ebx
  401. ;    sub    eax,41
  402. ;    push   eax
  403.  
  404.         mov     esi,[points_rotated_ptr]
  405.         mov     edi,[points_translated_ptr]
  406.         movzx   ecx,[points_count_var]
  407.         call    translate_points
  408.  
  409. ;        cmp     [dr_flag],5
  410. ;        jne     @f
  411. ;        call    calc_attenuation_light
  412. ;     @@:
  413.         cmp     [fire_flag],0
  414.         jne     @f
  415.         call    clrscr          ; clear the screen
  416.      @@:
  417.         cmp     [catmull_flag],1  ;non sort if Catmull = on
  418.         je      .no_sort
  419.         call    sort_triangles
  420.       .no_sort:
  421.         cmp     [dr_flag],7       ; fill if 2tex and texgrd
  422.         jge     @f
  423.         cmp     [catmull_flag],0  ;non fill if Catmull = off
  424.         je      .non_f
  425.         cmp     [dr_flag],6       ; non fill if dots
  426.         je      .non_f
  427.       @@:
  428.         call    fill_Z_buffer     ; make background
  429.      .non_f:
  430. ;    RDTSC
  431. ;    push eax
  432.         cmp     [dr_flag],6
  433.         jne     @f
  434.         call     draw_dots
  435.         jmp      .blurrr
  436.       @@:
  437.         call    draw_triangles  ; draw all triangles from the list
  438.       .blurrr:
  439.         cmp     [fire_flag],0
  440.         jne     @f
  441.         cmp     [blur_flag],0
  442.         je      .no_blur  ; no blur, no fire
  443.         movzx   ecx,[blur_flag]
  444.         call    blur_screen    ; blur and fire
  445.         jmp     .no_blur
  446.     @@:
  447.         cmp     [emboss_flag],0
  448.         jne     .emb           ; if emboss=true -> no fire
  449.         movzx   ecx,[fire_flag]
  450.         call    blur_screen    ; blur and fire
  451.     .no_blur:                  ; no blur, no fire
  452.         cmp     [emboss_flag],0
  453.         je      @f
  454.      .emb:
  455.         call    do_emboss
  456.  
  457.       @@:
  458.  
  459.  
  460.     RDTSC
  461.     sub eax,[esp]
  462.     sub eax,41
  463. ;    pop     eax
  464.  
  465.     mov     ecx,10
  466.   .dc:
  467.     xor     edx,edx
  468.     mov     edi,10
  469.     div     edi
  470.     add     dl,30h
  471.     mov     [STRdata+ecx-1],dl
  472.     loop    .dc
  473.     pop eax
  474.  
  475.     mov     eax,7           ; put image
  476.     mov     ebx,screen
  477.     mov     ecx,SIZE_X shl 16 + SIZE_Y
  478.     mov     edx,5 shl 16 + 23
  479.     int     0x40
  480.  
  481.  
  482.     mov  eax,4                     ; function 4 : write text to window
  483.     mov  ebx,5*65536+23            ; [x start] *65536 + [y start]
  484.     mov  ecx,-1
  485.     mov  edx,STRdata               ; pointer to text beginning
  486.     mov  esi,10                    ; text length
  487.     int  40h
  488.  
  489.  
  490.  
  491.    jmp     still
  492.  
  493. ;--------------------------------------------------------------------------------
  494. ;-------------------------PROCEDURES---------------------------------------------
  495. ;--------------------------------------------------------------------------------
  496. include "TEX3.INC"
  497. include "FLAT_CAT.INC"
  498. include "TEX_CAT.INC"
  499. include "BUMP_CAT.INC"
  500. include "3DMATH.INC"
  501. include "GRD3.INC"
  502. include "FLAT3.INC"
  503. include "BUMP3.INC"
  504. include "B_PROCS.INC"
  505. include "A_PROCS.INC"
  506. include "GRD_CAT.INC"
  507. include "BUMP_TEX.INC"
  508. include "GRD_TEX.INC"
  509. include "TWO_TEX.INC"
  510.  
  511. alloc_buffer_mem:
  512.     movzx    ecx,[size_x]
  513.     movzx    eax,[size_y]
  514.     mul      ecx
  515.     lea      ecx,[eax*3]
  516.     push     ecx
  517.     shl      eax,2
  518.     add      ecx,eax
  519.     add      ecx,MEM_END
  520.     mov      ebx,1
  521.     mov      eax,64     ; allocate mem  - resize app mem
  522.     int      0x40
  523.     mov      [screen_ptr],MEM_END
  524.     mov      [Zbuffer_ptr],MEM_END
  525.     pop      ecx
  526.     add      [Zbuffer_ptr],ecx
  527. ret
  528.  
  529. update_flags:
  530. ; updates flags and writing flag description
  531. ; in    ah - button number
  532.         push    ax
  533.         mov     edi,menu
  534.       .ch_another:
  535.         cmp     ah,byte[edi]     ; ah = button id
  536.         jne     @f
  537.         mov     bl,byte[edi+11]  ; max_flag + 1
  538.         cmp     bl,255
  539.         je      .no_write
  540.         inc     byte[edi+12]     ; flag
  541.         cmp     byte[edi+12],bl
  542.         jne     .write
  543.         mov     byte[edi+12],0
  544.         jmp     .write
  545.       @@:
  546.         add     edi,17
  547.         cmp     byte[edi],-1
  548.         jne     .ch_another
  549.      .write:
  550. ;     clreol   {pascal never dies}
  551. ;          * eax = 13 - function number
  552. ;  * ebx = [coordinate on axis x]*65536 + [size on axis x]
  553. ;  * ecx = [coordinate on axis y]*65536 + [size on axis y]
  554. ;  * edx = color 0xRRGGBB or 0x80RRGGBB for gradient fill
  555.  
  556.         mov     eax,13                           ; function 13 write rectangle
  557.         movzx   ecx,byte[edi]
  558.         sub     cl,2
  559.         lea     ecx,[ecx*3]
  560.         lea     ecx,[ecx*5]
  561.         add     ecx,28
  562.         shl     ecx,16
  563.         add     ecx,14                          ;  ecx = [coord y]*65536 + [size y]
  564.         mov     ebx,(SIZE_X+12+70)*65536+25     ; [x start] *65536 + [size x]
  565.         mov     edx,0x00000000                  ;  color  0x00RRGGBB
  566.         int     0x40
  567.  
  568.         mov     eax,4                           ; function 4 : write text to window
  569.         movzx   ebx,byte[edi]
  570.         sub     bl,2
  571.         lea     ebx,[ebx*3]
  572.         lea     ebx,[ebx*5]
  573.         add     ebx,(SIZE_X+12+70)*65536+28     ; [x start] *65536 + [y start]
  574.         mov     ecx,0x20ddeeff                  ; font 1 & color ( 0xF0RRGGBB )
  575.         movzx   edx,byte[edi+12]                ; current flag
  576.         shl     edx,2                           ; * 4 = text length
  577.         add     edx,dword[edi+13]               ; pointer to text beginning
  578.         mov     esi,4                           ; text length -
  579.                                                 ; flag description 4 characters
  580.         int     0x40
  581.  
  582.      .no_write:
  583.         pop     ax
  584. ret
  585. normalize_all_light_vectors:
  586.         mov     edi,lights
  587.      @@:
  588.         call    normalize_vector           ;       3dmath.inc
  589.         add     edi,LIGHT_SIZE
  590.         cmp     edi,lightsend   ;ecx
  591.         jl      @b
  592. ret
  593.  
  594. calc_bumpmap_coords:      ; map texture, bump
  595. ;macro .comment222
  596. ;                                ; planar mapping
  597. ;        mov     esi,points
  598. ;        mov     edi,tex_points
  599. ;      @@:
  600. ;         add     esi,2
  601. ;         movsd
  602. ;         cmp     dword[esi],dword -1
  603. ;         jne     @b
  604.  
  605. ;      .Pi2  equ dword[ebp-4]
  606.  
  607. ;      mov   ebp,esp
  608. ;      sub   esp,4
  609.  
  610.       fninit
  611.       fldpi
  612.       fadd      st,st
  613.       mov       esi,[points_ptr]
  614.       mov       edi,tex_points
  615.       movzx     ecx,[points_count_var]
  616.       inc       ecx
  617. ;      cmp       [map_tex_flag],1
  618. ;      jne       .cylindric
  619.       ; spherical mapping around y axle
  620.  
  621.    @@:
  622.       fld       dword[esi]     ; x coord
  623.       fld       dword[esi+8]   ; z coord
  624.       fpatan                   ; arctg(st1/st)
  625. ;      fdiv      .Pi2
  626.       fdiv      st0,st1
  627.       fimul     [tex_x_div2]
  628.       fiadd     [tex_x_div2]
  629.       fistp     word[edi]      ; x
  630.  
  631.       fld       dword[esi+4]   ; y coord
  632.       fld       dword[esi]     ; x
  633.       fmul      st,st0
  634.       fld       dword[esi+4]   ; y
  635.       fmul      st,st0
  636.       fld       dword[esi+8]   ; z
  637.       fmul      st,st0
  638.       faddp
  639.       faddp
  640.       fsqrt
  641.       fpatan
  642.       fldpi
  643.       fdivp
  644.       fimul    [tex_y_div2]
  645.       fiadd    [tex_y_div2]
  646.       fistp    word[edi+2]     ; y
  647.  
  648.       add      esi,12
  649.       add      edi,4
  650.       loop     @b
  651.       ffree    st0
  652. ;      jmp      .end_map
  653. ;  .cylindric:
  654. ;       fld     dword[esi]     ; around y axle
  655. ;       fld     dword[esi+8]
  656. ;       fpatan
  657. ;       fdiv    st0,st1
  658. ;       fimul   [tex_x_div2]
  659. ;       fiadd   [tex_x_div2]
  660. ;       fistp   word[edi]
  661.  
  662. ;       fld     dword[esi+4]
  663. ;       fimul   [tex_y_div2]
  664. ;       fiadd   [tex_y_div2]
  665. ;       fistp   word[edi+2]
  666.  
  667. ;       add     esi,12
  668. ;       add     edi,4
  669. ;       loop    .cylindric
  670. ;       ffree    st0
  671. ;;      mov      esp,ebp
  672. ;   .end_map:
  673. ret
  674.  
  675.  
  676. init_envmap2:         ; do env_map using many light sources
  677. ;env_map 512 x 512 x 3 bytes
  678. .temp  equ word   [ebp-2]
  679. .nEy   equ word  [ebp-4]
  680. .nEx   equ word  [ebp-6]
  681. .col_r equ    [ebp-8]
  682. .col_g equ    [ebp-9]
  683. .col_b equ    [ebp-10]
  684.  
  685.          push     ebp
  686.          mov      ebp,esp
  687.          sub      esp,20
  688.          mov      edi,envmap
  689.          fninit
  690.  
  691.          mov      dx,- TEX_Y / 2 ;256   ; dx - vertical coordinate = y
  692.     .ie_ver:
  693.          mov      cx,- TEX_X / 2 ;256   ; cx - horizontal coord = x
  694.     .ie_hor:
  695.          xor      ebx,ebx
  696.          mov      dword .col_b, 0
  697.      .light:
  698.          lea      esi,[lights+ebx]
  699.          fld      dword[esi]     ; light vector x cooficient
  700.          fimul    [tex_x_div2] ;[i256]
  701.          mov      .temp,cx
  702.          fisubr   .temp
  703.          fistp    .nEx
  704.          fld      dword[esi+4]   ; light vector y cooficient
  705.          fimul    [tex_y_div2] ;[i256]
  706.          mov      .temp,dx
  707.          fisubr   .temp
  708.          fistp    .nEy
  709.  
  710.          cmp      .nEx,- TEX_X / 2 ;256
  711.          jl       .update_counters
  712.          cmp      .nEy,- TEX_Y / 2 ;256
  713.          jl       .update_counters
  714.          cmp      .nEx,TEX_X / 2 ;256
  715.          jg       .update_counters
  716.          cmp      .nEy,TEX_Y / 2 ;256
  717.          jg       .update_counters
  718.  
  719.          fild     .nEx
  720.          fmul     st,st0
  721.          fild     .nEy
  722.          fmul     st,st0
  723.          faddp
  724.          fsqrt
  725.          fisubr   [i256]
  726.          fmul     [env_const]
  727.          fidiv    [i256]   ; st - 'virtual' dot product
  728.  
  729.          fcom     [dot_max]
  730.          fstsw    ax
  731.          sahf
  732.          jb       @f
  733.          ffree    st
  734.          fld1     ;[dot_max]
  735.       @@:
  736.          fcom     [dot_min]
  737.          fstsw    ax
  738.          sahf
  739.          ja       @f
  740.          ffree    st
  741.          fldz     ;[dot_min]
  742.       @@:
  743.          push     ebp
  744.          movzx    ax,byte[esi+21]
  745.          push     ax  ;- shines
  746.          mov      al,byte[esi+14]   ; b    orginal color
  747.          push     ax
  748.          mov      al,byte[esi+13]   ; g
  749.          push     ax
  750.          mov      al,byte[esi+12]   ; r
  751.          push     ax
  752.          mov      al,byte[esi+20]   ; b     max color
  753.          push     ax
  754.          mov      al,byte[esi+19]   ; g
  755.          push     ax
  756.          mov      al,byte[esi+18]   ; r
  757.          push     ax
  758.          mov      al,byte[esi+17]   ; b    min col
  759.          push     ax
  760.          mov      al,byte[esi+16]   ; g
  761.          push     ax
  762.          mov      al,byte[esi+15]   ; r
  763.          push     ax
  764.          push     eax         ; earlier - dot pr
  765.       ;  fstp     .dot_product
  766.       ;  push     .dot_product
  767.          call     calc_one_col
  768.          pop      ebp
  769.          ; eax-0x00rrggbb
  770.          cmp      al,.col_b
  771.          jbe      @f
  772.          mov      .col_b,al
  773.    @@:                        ;  eax - ggbb00rr
  774.          shr      ax,8
  775.          cmp      al,.col_g
  776.          jbe      @f
  777.          mov      .col_g,al
  778.    @@:                        ;  eax - bb0000gg
  779.          shr      eax,16
  780.          cmp      al,.col_r
  781.          jbe      @f
  782.          mov      .col_r,al
  783.    @@:
  784.    .update_counters:                     ; update and jump when neccesery
  785.          add      ebx,LIGHT_SIZE
  786.          cmp      bx,[all_lights_size]
  787.          jl       .light    ; next_light
  788.          mov      eax,dword .col_b
  789.          stosd
  790.          dec      edi
  791.  
  792.          inc      cx
  793.          cmp      cx,TEX_X / 2 ;256
  794.          jne      .ie_hor
  795.  
  796.          inc      dx
  797.          cmp      dx,TEX_Y / 2 ;256
  798.          jne     .ie_ver
  799.  
  800.          mov     esp,ebp
  801.          pop     ebp
  802. ret
  803.  
  804.  
  805.  
  806. do_color_buffer:         ; do color buffer for Gouraud, flat shading
  807. ;env_map 512 x 512 x 3 bytes    ; many lights using
  808. .temp  equ word   [ebp-2]
  809. .nz    equ dword  [ebp-6]  ; dword
  810. .ny    equ dword  [ebp-10]
  811. .nx    equ dword  [ebp-14]
  812. .col_r equ    [ebp-16]
  813. .col_g equ    [ebp-17]
  814. .col_b equ    [ebp-18]
  815.  
  816.          push     ebp
  817.          mov      ebp,esp
  818.          sub      esp,20
  819.          mov      edi,color_map
  820.          fninit
  821.  
  822.          mov      dx,- TEX_Y / 2 ;-256   ; dx - vertical coordinate = y
  823.     .ie_ver:
  824.          mov      cx,- TEX_X / 2 ;256   ; cx - horizontal coord = x
  825.     .ie_hor:
  826.          mov      .temp,cx
  827.          fild     .temp
  828.          fidiv    [i256]   ;st = Nx - vector normal x cooficient
  829.          fst      .nx
  830.          fmul     st,st0
  831.          mov      .temp,dx
  832.          fild     .temp
  833.          fidiv    [i256]   ; st = Ny - vector normal y coeficient
  834.          fst      .ny
  835.          fmul     st,st0
  836.          faddp
  837.          fld1
  838.          fchs
  839.          faddp
  840.          fabs
  841.          fsqrt
  842.          fchs
  843.          fstp     .nz              ; st - Nz - vect normal z coeficient
  844.          xor      ebx,ebx
  845.          mov      dword .col_b, 0
  846.      .light:
  847.          push     edi   ;env_map
  848.          lea      esi,[lights+ebx]
  849.          lea      edi,.nx
  850.          call     dot_product
  851.          pop      edi
  852.          fcom     [dot_min]
  853.          fstsw    ax
  854.          sahf
  855.          ja       .env_ok1  ;compare with dot_max
  856.          ffree    st
  857.  
  858.         jmp       .update_counters
  859.       .env_ok1:
  860.          fcom    [dot_max]
  861.          fstsw   ax
  862.          sahf
  863.          jb      .env_ok2     ; calc col
  864.          ffree   st
  865.          jmp     .update_counters
  866.       .env_ok2:            ;calc col
  867.          push     ebp
  868.          movzx    ax,byte[esi+21]
  869.          push     ax  ;- shines
  870.          mov      al,byte[esi+14]   ; b    orginal color
  871.          push     ax
  872.          mov      al,byte[esi+13]   ; g
  873.          push     ax
  874.          mov      al,byte[esi+12]   ; r
  875.          push     ax
  876.          mov      al,byte[esi+20]   ; b     max color
  877.          push     ax
  878.          mov      al,byte[esi+19]   ; g
  879.          push     ax
  880.          mov      al,byte[esi+18]   ; r
  881.          push     ax
  882.          mov      al,byte[esi+17]   ; b    min col
  883.          push     ax
  884.          mov      al,byte[esi+16]   ; g
  885.          push     ax
  886.          mov      al,byte[esi+15]   ; r
  887.          push     ax
  888.          push     eax         ; earlier - dot pr
  889.       ;  fstp     .dot_product
  890.       ;  push     .dot_product
  891.          call     calc_one_col
  892.          pop      ebp
  893.          ; eax-0x00rrggbb
  894.          cmp      al,.col_b
  895.          jbe      @f
  896.          mov      .col_b,al
  897.    @@:
  898.          shr      ax,8
  899.          cmp      al,.col_g
  900.          jbe      @f
  901.          mov      .col_g,al
  902.    @@:
  903.          shr      eax,16
  904.          cmp      al,.col_r
  905.          jbe      @f
  906.          mov      .col_r,al
  907.   @@:
  908.  .update_counters:                                  ; update and jump when neccesery
  909.         add     ebx,LIGHT_SIZE
  910.         cmp     bx,[all_lights_size]
  911.         jl      .light    ; next_light
  912.         mov     eax,dword .col_b
  913.         stosd
  914.         dec     edi
  915.  
  916.         inc     cx
  917.         cmp     cx,TEX_X / 2 ;256
  918.         jne     .ie_hor
  919.  
  920.         inc     dx
  921.         cmp     dx,TEX_X / 2 ;256
  922.         jne     .ie_ver
  923.  
  924.     .env_done:
  925.          mov     esp,ebp
  926.          pop     ebp
  927. ret
  928. if 0
  929. init_triangles_normals:
  930.         mov     ebx,triangles_normals
  931.         mov     ebp,triangles
  932.      @@:
  933.         push    ebx
  934.         mov     ebx,vectors
  935.         movzx   esi,word[ebp]          ; first point index
  936.         lea     esi,[esi*3]
  937.         lea     esi,[points+esi*2]     ; esi - pointer to 1st 3d point
  938.         movzx   edi,word[ebp+2]        ; second point index
  939.         lea     edi,[edi*3]
  940.         lea     edi,[points+edi*2]     ; edi - pointer to 2nd 3d point
  941.         call    make_vector
  942.         add     ebx,12
  943.         mov     esi,edi
  944.         movzx   edi,word[ebp+4]        ; third point index
  945.         lea     edi,[edi*3]
  946.         lea     edi,[points+edi*2]
  947.         call    make_vector
  948.         mov     edi,ebx                 ; edi - pointer to 2nd vector
  949.         mov     esi,ebx
  950.         sub     esi,12                  ; esi - pointer to 1st vector
  951.         pop     ebx
  952.         call    cross_product
  953.         mov     edi,ebx
  954.         call    normalize_vector
  955.         add     ebp,6
  956.         add     ebx,12
  957.         cmp     dword[ebp],-1
  958.         jne     @b
  959. ret
  960. end if
  961. init_point_normals:
  962. .x equ dword [ebp-4]
  963. .y equ dword [ebp-8]
  964. .z equ dword [ebp-12]
  965. .point_number equ word [ebp-26]
  966. .hit_faces    equ word [ebp-28]
  967.  
  968.         fninit
  969.         mov       ebp,esp
  970.         sub       esp,28
  971.         mov       edi,[points_normals_ptr]
  972.         mov       .point_number,0
  973.     .ipn_loop:
  974.         mov       .hit_faces,0
  975.         mov       .x,0
  976.         mov       .y,0
  977.         mov       .z,0
  978.         mov       esi,[triangles_ptr]
  979.         xor       ecx,ecx              ; ecx - triangle number
  980.     .ipn_check_face:
  981.         xor       ebx,ebx              ; ebx - 'position' in one triangle
  982.     .ipn_check_vertex:
  983.         movzx     eax,word[esi+ebx]    ;  eax - point_number
  984.         cmp       ax,.point_number
  985.         jne       .ipn_next_vertex
  986.         push      esi
  987.         mov       esi,ecx
  988.         lea       esi,[esi*3]
  989.        ; lea       esi,[triangles_normals+esi*4]
  990.         shl       esi,2
  991.         add       esi,[triangles_normals_ptr]
  992.  
  993.         fld       .x
  994.         fadd      dword[esi+vec_x]       ; vec_x this defined in 3dmath.asm - x cooficient
  995.         fstp      .x                     ; of normal vactor
  996.         fld       .y
  997.         fadd      dword[esi+vec_y]
  998.         fstp      .y
  999.         fld       .z
  1000.         fadd      dword[esi+vec_z]
  1001.         fstp      .z
  1002.         pop       esi
  1003.         inc       .hit_faces
  1004.         jmp       .ipn_next_face
  1005.     .ipn_next_vertex:
  1006.         add       ebx,2
  1007.         cmp       ebx,6
  1008.         jne       .ipn_check_vertex
  1009.     .ipn_next_face:
  1010.         add       esi,6
  1011.         inc       ecx
  1012.         cmp       cx,[triangles_count_var]
  1013.         jne       .ipn_check_face
  1014.  
  1015.         fld       .x
  1016.         fidiv     .hit_faces
  1017.         fstp      dword[edi+vec_x]
  1018.         fld       .y
  1019.         fidiv     .hit_faces
  1020.         fstp      dword[edi+vec_y]
  1021.         fld       .z
  1022.         fidiv     .hit_faces
  1023.         fstp      dword[edi+vec_z]
  1024.         call      normalize_vector
  1025.         add       edi,12  ;type vector 3d
  1026.         inc       .point_number
  1027.         mov       dx,.point_number
  1028.         cmp       dx,[points_count_var]
  1029.         jne       .ipn_loop
  1030.  
  1031.         mov       esp,ebp
  1032. ret
  1033. ;===============================================================
  1034.  
  1035. init_triangles_normals2:
  1036.         mov     ebx,[triangles_normals_ptr]
  1037.         mov     ebp,[triangles_ptr]
  1038.      @@:
  1039.         push    ebx
  1040.         mov     ebx,vectors
  1041.         movzx   esi,word[ebp]          ; first point index
  1042.         lea     esi,[esi*3]
  1043. ;        lea     esi,[points+esi*2]     ; esi - pointer to 1st 3d point
  1044.         shl     esi,2
  1045.         add     esi,[points_ptr]
  1046.         movzx   edi,word[ebp+2]          ; first point index
  1047.         lea     edi,[edi*3]
  1048.         shl     edi,2
  1049.         add     edi,[points_ptr]
  1050. ;        movzx   edi,word[ebp+2]        ; second point index
  1051. ;        lea     edi,[edi*3]
  1052. ;        lea     edi,[points+edi*2]     ; edi - pointer to 2nd 3d point
  1053.         call    make_vector_r
  1054.         add     ebx,12
  1055.         mov     esi,edi
  1056.         movzx   edi,word[ebp+4]        ; third point index
  1057.         lea     edi,[edi*3]
  1058.         shl     edi,2
  1059.         add     edi,[points_ptr]
  1060. ;        lea     edi,[points+edi*2]
  1061.         call    make_vector_r
  1062.         mov     edi,ebx                 ; edi - pointer to 2nd vector
  1063.         mov     esi,ebx
  1064.         sub     esi,12                  ; esi - pointer to 1st vector
  1065.         pop     ebx
  1066.         call    cross_product
  1067.         mov     edi,ebx
  1068.         call    normalize_vector
  1069.         add     ebp,6
  1070.         add     ebx,12
  1071.         cmp     dword[ebp],-1
  1072.         jne     @b
  1073. ret
  1074.  
  1075.  
  1076. ;=================================================================
  1077. sort_triangles:
  1078.         mov     esi,[triangles_ptr]
  1079.         mov     edi,triangles_with_z
  1080.         mov     ebp,[points_translated_ptr]
  1081.  
  1082.     make_triangle_with_z:       ;makes list with triangles and z position
  1083.         movzx   eax,word[esi]
  1084.         lea     eax,[eax*3]
  1085.         movzx   ecx,word[ebp+eax*2+4]
  1086.  
  1087.         movzx   eax,word[esi+2]
  1088.         lea     eax,[eax*3]
  1089.         add     cx,word[ebp+eax*2+4]
  1090.  
  1091.         movzx   eax,word[esi+4]
  1092.         lea     eax,[eax*3]
  1093.         add     cx,word[ebp+eax*2+4]
  1094.  
  1095.         mov     ax,cx
  1096.        ; cwd
  1097.        ; idiv    word[i3]
  1098.         movsd                   ; store vertex coordinates
  1099.         movsw
  1100.         stosw                   ; middle vertex coordinate  'z' in triangles_with_z list
  1101.         cmp     dword[esi],-1
  1102.         jne     make_triangle_with_z
  1103.         movsd                   ; copy end mark
  1104.         mov     eax,4
  1105.         lea     edx,[edi-8-trizdd]
  1106.      ;   lea     edx, [edi-8]
  1107.      ;   sub     edx,[triangles_w_z_ptr]
  1108.         mov     [high],edx
  1109.         call    quicksort
  1110.         mov     eax,4
  1111.         mov     edx,[high]
  1112.         call    insertsort
  1113.         jmp     end_sort
  1114.  
  1115.     quicksort:
  1116.         mov     ecx,edx
  1117.         sub     ecx,eax
  1118.         cmp     ecx,32
  1119.         jc      .exit
  1120.         lea     ecx,[eax+edx]
  1121.         shr     ecx,4
  1122.         lea     ecx,[ecx*8-4];
  1123. ;        mov     edi,[triangles_w_z_ptr]
  1124. ;        mov     ebx,[edi+eax]
  1125. ;        mov     esi,[edi+ecx]
  1126. ;        mov     edi,[edi+edx]
  1127.         mov     ebx,[trizdd+eax]; trizdd[l]
  1128.         mov     esi,[trizdd+ecx]; trizdd[i]
  1129.         mov     edi,[trizdd+edx]; trizdd[h]
  1130.         cmp     ebx,esi
  1131.         jg      @f              ; direction NB! you need to negate these to invert the order
  1132.       if Ext=NON
  1133.         mov     [trizdd+eax],esi
  1134.         mov     [trizdd+ecx],ebx
  1135.         mov     ebx,[trizdd+eax-4]
  1136.         mov     esi,[trizdd+ecx-4]
  1137.         mov     [trizdd+eax-4],esi
  1138.         mov     [trizdd+ecx-4],ebx
  1139.         mov     ebx,[trizdd+eax]
  1140.         mov     esi,[trizdd+ecx]
  1141.       else
  1142. ;        push    ebx
  1143. ;        mov     ebx,[triangles_w_z_ptr]
  1144. ;        movq    mm0,[ebx+eax-4]
  1145. ;        movq    mm1,[ebx+ecx-4]
  1146. ;        movq    [ebx+ecx-4],mm0
  1147. ;        movq    [ebx+eax-4],mm1
  1148. ;        pop     ebx
  1149.         movq    mm0,[trizdq+eax-4]
  1150.         movq    mm1,[trizdq+ecx-4]
  1151.         movq    [trizdq+ecx-4],mm0
  1152.         movq    [trizdq+eax-4],mm1
  1153.         xchg    ebx,esi
  1154.       end if
  1155.       @@:
  1156.         cmp     ebx,edi
  1157.         jg      @f              ; direction
  1158.       if Ext=NON
  1159.         mov     [trizdd+eax],edi
  1160.         mov     [trizdd+edx],ebx
  1161.         mov     ebx,[trizdd+eax-4]
  1162.         mov     edi,[trizdd+edx-4]
  1163.         mov     [trizdd+eax-4],edi
  1164.         mov     [trizdd+edx-4],ebx
  1165.         mov     ebx,[trizdd+eax]
  1166.         mov     edi,[trizdd+edx]
  1167.       else
  1168. ;        push    ebx
  1169. ;        mov     ebx,[triangles_w_z_ptr]
  1170. ;        movq    mm0,[ebx+eax-4]
  1171. ;        movq    mm1,[ebx+edx-4]
  1172. ;        movq    [ebx+edx-4],mm0
  1173. ;        movq    [ebx+eax-4],mm1
  1174.         movq    mm0,[trizdq+eax-4]
  1175.         movq    mm1,[trizdq+edx-4]
  1176.         movq    [trizdq+edx-4],mm0
  1177.         movq    [trizdq+eax-4],mm1
  1178. ;        pop     ebx
  1179.         xchg    ebx,edi
  1180.       end if
  1181.       @@:
  1182.         cmp     esi,edi
  1183.         jg      @f              ; direction
  1184.       if Ext=NON
  1185.         mov     [trizdd+ecx],edi
  1186.         mov     [trizdd+edx],esi
  1187.         mov     esi,[trizdd+ecx-4]
  1188.         mov     edi,[trizdd+edx-4]
  1189.         mov     [trizdd+ecx-4],edi
  1190.         mov     [trizdd+edx-4],esi
  1191.       else
  1192. ;        push    ebx
  1193. ;        mov     ebx,[triangles_w_z_ptr]
  1194. ;        movq    mm0,[ebx+ecx-4]
  1195. ;        movq    mm1,[ebx+edx-4]
  1196. ;        movq    [ebx+edx-4],mm0
  1197. ;        movq    [ebx+ecx-4],mm1
  1198. ;        pop     ebx
  1199.  
  1200.         movq    mm0,[trizdq+ecx-4]
  1201.         movq    mm1,[trizdq+edx-4]
  1202.         movq    [trizdq+edx-4],mm0
  1203.         movq    [trizdq+ecx-4],mm1
  1204.         xchg    ebx,esi
  1205.       end if
  1206.       @@:
  1207.         mov     ebp,eax         ; direction
  1208.         add     ebp,8      ;   j
  1209.       if Ext=NON
  1210.         mov     esi,[trizdd+ebp]
  1211.         mov     edi,[trizdd+ecx]
  1212.         mov     [trizdd+ebp],edi
  1213.         mov     [trizdd+ecx],esi
  1214.         mov     esi,[trizdd+ebp-4]
  1215.         mov     edi,[trizdd+ecx-4]
  1216.         mov     [trizdd+ecx-4],esi
  1217.         mov     [trizdd+ebp-4],edi
  1218.       else
  1219. ;        push    ebx
  1220. ;        mov     ebx,[triangles_w_z_ptr]
  1221. ;        movq    mm0,[ebx+ebp-4]
  1222. ;        movq    mm1,[ebx+ecx-4]
  1223. ;        movq    [ebx+ecx-4],mm0
  1224. ;        movq    [ebx+ebp-4],mm1
  1225. ;        pop     ebx
  1226.  
  1227.         movq    mm0,[trizdq+ebp-4]
  1228.         movq    mm1,[trizdq+ecx-4]
  1229.         movq    [trizdq+ecx-4],mm0
  1230.         movq    [trizdq+ebp-4],mm1
  1231.       end if
  1232.         mov     ecx,edx    ;   i; direction
  1233.         mov     ebx,[trizdd+ebp]; trizdd[j]
  1234. ;        mov     ebx, [triangles_w_z_ptr]
  1235. ;        add     ebx, ebp
  1236.  
  1237.  ;       push    eax
  1238.  ;       mov     eax, [triangles_w_z_ptr]
  1239.       .loop:
  1240.         sub     ecx,8           ; direction
  1241.         cmp     [trizdd+ecx],ebx
  1242. ;        cmp     [eax+ecx],ebx
  1243.         jl      .loop           ; direction
  1244.       @@:
  1245.         add     ebp,8           ; direction
  1246.         cmp     [trizdd+ebp],ebx
  1247. ;        cmp     [eax+ebp],ebx
  1248.         jg      @b              ; direction
  1249.         cmp     ebp,ecx
  1250.         jge     @f              ; direction
  1251.       if Ext=NON
  1252.         mov     esi,[trizdd+ecx]
  1253.         mov     edi,[trizdd+ebp]
  1254.         mov     [trizdd+ebp],esi
  1255.         mov     [trizdd+ecx],edi
  1256.         mov     edi,[trizdd+ecx-4]
  1257.         mov     esi,[trizdd+ebp-4]
  1258.         mov     [trizdd+ebp-4],edi
  1259.         mov     [trizdd+ecx-4],esi
  1260.       else
  1261. ;        movq    mm0,[eax+ecx-4]
  1262. ;        movq    mm1,[eax+ebp-4]
  1263. ;        movq    [eax+ebp-4],mm0
  1264. ;        movq    [eax+ecx-4],mm1
  1265.         movq    mm0,[trizdq+ecx-4]
  1266.         movq    mm1,[trizdq+ebp-4]
  1267.         movq    [trizdq+ebp-4],mm0
  1268.         movq    [trizdq+ecx-4],mm1
  1269.       end if
  1270.         jmp     .loop
  1271. ;        pop     eax
  1272.       @@:
  1273.       if Ext=NON
  1274.         mov     esi,[trizdd+ecx]
  1275.         mov     edi,[trizdd+eax+8]
  1276.         mov     [trizdd+eax+8],esi
  1277.         mov     [trizdd+ecx],edi
  1278.         mov     edi,[trizdd+ecx-4]
  1279.         mov     esi,[trizdd+eax+4]
  1280.         mov     [trizdd+eax+4],edi
  1281.         mov     [trizdd+ecx-4],esi
  1282.       else
  1283. ;        push    edx
  1284. ;        mov     edx,[triangles_w_z_ptr]
  1285. ;        movq    mm0,[edx+ecx-4]
  1286. ;        movq    mm1,[edx+eax+4]; dir
  1287. ;        movq    [edx+eax+4],mm0; dir
  1288. ;        movq    [edx+ecx-4],mm1
  1289. ;        pop     edx
  1290.  
  1291.         movq    mm0,[trizdq+ecx-4]
  1292.         movq    mm1,[trizdq+eax+4]; dir
  1293.         movq    [trizdq+eax+4],mm0; dir
  1294.         movq    [trizdq+ecx-4],mm1
  1295.       end if
  1296.         add     ecx,8
  1297.         push    ecx edx
  1298.         mov     edx,ebp
  1299.         call    quicksort
  1300.         pop     edx eax
  1301.         call    quicksort
  1302.       .exit:
  1303.     ret
  1304.     insertsort:
  1305.         mov     esi,eax
  1306.       .start:
  1307.         add     esi,8
  1308.         cmp     esi,edx
  1309.         ja      .exit
  1310.         mov     ebx,[trizdd+esi]
  1311. ;        mov     ebx,[triangles_w_z_ptr]
  1312. ;        add     ebx,esi
  1313.       if Ext=NON
  1314.         mov     ecx,[trizdd+esi-4]
  1315.       else
  1316. ;        push    ebx
  1317. ;        mov     ebx,[triangles_w_z_ptr]
  1318. ;        movq    mm1,[ebx+esi-4]
  1319.         movq    mm1,[trizdq+esi-4]
  1320. ;        pop     ebx
  1321.       end if
  1322.         mov     edi,esi
  1323.       @@:
  1324.         cmp     edi,eax
  1325.         jna     @f
  1326. ;        push    eax
  1327. ;        mov     eax,[triangles_w_z_ptr]
  1328. ;        cmp     [eax+edi-8],ebx
  1329. ;        pop     eax
  1330.        cmp     [trizdd+edi-8],ebx
  1331.         jg      @f                 ; direction
  1332.       if Ext=NON
  1333.         mov     ebp,[trizdd+edi-8]
  1334.         mov     [trizdd+edi],ebp
  1335.         mov     ebp,[trizdd+edi-12]
  1336.         mov     [trizdd+edi-4],ebp
  1337.       else
  1338. ;        push    eax
  1339. ;        mov     eax,[triangles_w_z_ptr]
  1340. ;        movq    mm0,[eax+edi-12]
  1341. ;        movq    [eax+edi-4],mm0
  1342.         movq    mm0,[trizdq+edi-12]
  1343.         movq    [trizdq+edi-4],mm0
  1344. ;        pop     eax
  1345.       end if
  1346.         sub     edi,8
  1347.         jmp     @b
  1348.       @@:
  1349.       if Ext=NON
  1350.         mov     [trizdd+edi],ebx
  1351.         mov     [trizdd+edi-4],ecx
  1352.       else
  1353. ;        push    eax
  1354. ;        mov     eax,[triangles_w_z_ptr]
  1355. ;        movq    [eax+edi-4],mm1
  1356.         movq    [trizdq+edi-4],mm1
  1357. ;        pop     eax
  1358.       end if
  1359.         jmp     .start
  1360.       .exit:
  1361.     ret
  1362.    end_sort:
  1363.     ; translate triangles_with_z to sorted_triangles
  1364.         mov     esi,triangles_with_z
  1365. ;        mov      esi,[triangles_w_z_ptr]
  1366.       ;  mov     edi,sorted_triangles
  1367.         mov      edi,[triangles_ptr]
  1368.     again_copy:
  1369.       if Ext=NON
  1370.         movsd
  1371.         movsw
  1372.         add     esi,2
  1373.       else
  1374.         movq    mm0,[esi]
  1375.         movq    [edi],mm0
  1376.         add     esi,8
  1377.         add     edi,6
  1378.       end if
  1379.         cmp     dword[esi],-1
  1380.         jne     again_copy
  1381. ;      if Ext=MMX
  1382. ;        emms
  1383. ;      end if
  1384.         movsd  ; copy end mark too
  1385. ret
  1386.  
  1387. clrscr:
  1388.         mov     edi,screen
  1389.         mov     ecx,SIZE_X*SIZE_Y*3/4
  1390.         xor     eax,eax
  1391.       if Ext=NON
  1392.         rep     stosd
  1393.       else
  1394.         pxor    mm0,mm0
  1395.       @@:
  1396.         movq    [edi+00],mm0
  1397.         movq    [edi+08],mm0
  1398.         movq    [edi+16],mm0
  1399.         movq    [edi+24],mm0
  1400.         add     edi,32
  1401.         sub     ecx,8
  1402.         jnc     @b
  1403.       end if
  1404. ret
  1405.  
  1406.  
  1407. draw_triangles:
  1408.         mov esi,[triangles_ptr]
  1409.     .again_dts:
  1410.         mov ebp,[points_translated_ptr]
  1411.       if Ext=NON
  1412.         movzx   eax,word[esi]
  1413.         mov     [point_index1],ax
  1414.         lea     eax,[eax*3]
  1415.         add     eax,eax
  1416.         push    ebp
  1417.         add     ebp,eax
  1418.         mov     eax,[ebp]
  1419.         mov     dword[xx1],eax
  1420.         mov     eax,[ebp+4]
  1421.         mov     [zz1],ax
  1422.         pop     ebp
  1423.  
  1424.  
  1425.         movzx   eax,word[esi+2]
  1426.         mov     [point_index2],ax
  1427.         lea     eax,[eax*3]
  1428.         add     eax,eax
  1429.         push    ebp
  1430.         add     ebp,eax
  1431.         mov     eax,[ebp]
  1432.         mov     dword[xx2],eax
  1433.         mov     eax,[ebp+4]
  1434.         mov     [zz2],ax
  1435.         pop     ebp
  1436.  
  1437.  
  1438.         movzx   eax,word[esi+4]        ; xyz3 = [ebp+[esi+4]*6]
  1439.         mov     [point_index3],ax
  1440.         lea     eax,[eax*3]
  1441.         add     eax,eax
  1442.     ;    push    ebp
  1443.         add     ebp,eax
  1444.         mov     eax,[ebp]
  1445.         mov     dword[xx3],eax
  1446.         mov     eax,[ebp+4]
  1447.         mov     [zz3],ax
  1448.       else
  1449.         mov     eax,dword[esi]           ; don't know MMX
  1450.         mov     dword[point_index1],eax
  1451.        ; shr     eax,16
  1452.        ; mov     [point_index2],ax
  1453.         mov     ax,word[esi+4]
  1454.         mov     [point_index3],ax
  1455.         movq    mm0,[esi]
  1456.         pmullw  mm0,qword[const6]
  1457.         movd    eax,mm0
  1458.         psrlq   mm0,16
  1459.         movd    ebx,mm0
  1460.         psrlq   mm0,16
  1461.         movd    ecx,mm0
  1462.         and     eax,0FFFFh
  1463.         and     ebx,0FFFFh
  1464.         and     ecx,0FFFFh
  1465.         movq    mm0,[ebp+eax]
  1466.         movq    mm1,[ebp+ebx]
  1467.         movq    mm2,[ebp+ecx]
  1468.         movq    qword[xx1],mm0
  1469.         movq    qword[xx2],mm1
  1470.         movq    qword[xx3],mm2
  1471. ;        emms
  1472.       end if                              ; *********************************
  1473.         push esi                          ;
  1474.         fninit                            ; DO culling AT FIRST
  1475.         cmp     [culling_flag],1          ; (if culling_flag = 1)
  1476.         jne     .no_culling
  1477.         mov     esi,point_index1          ; *********************************
  1478.         mov     ecx,3                     ;
  1479.       @@:
  1480.         movzx   eax,word[esi]
  1481.         lea     eax,[eax*3]
  1482.         shl     eax,2
  1483.         add     eax,[points_normals_rot_ptr]
  1484. ;        lea     eax,[eax+point_normals_rotated]
  1485.         fld     dword[eax+8]             ; *****************************
  1486.         ftst                             ; CHECKING OF Z COOFICIENT OF
  1487.         fstsw   ax                       ; NORMAL VECTOR
  1488.         sahf
  1489.         jb      @f
  1490.         ffree   st
  1491.         loop    @b
  1492.         jmp     .end_draw   ; non visable
  1493.       @@:
  1494.         ffree   st  ;is visable
  1495.       .no_culling:
  1496.         cmp     [dr_flag],0               ; draw type flag
  1497.         je      .flat_draw
  1498.         cmp     [dr_flag],2
  1499.         je      .env_mapping
  1500.         cmp     [dr_flag],3
  1501.         je      .bump_mapping
  1502.         cmp     [dr_flag],4
  1503.         je      .tex_mapping
  1504.         cmp     [dr_flag],5
  1505.         je      .rainbow
  1506.         cmp     [dr_flag],7
  1507.         je      .grd_tex
  1508.         cmp     [dr_flag],8
  1509.         je      .two_tex
  1510.         cmp     [dr_flag],9
  1511.         je      .bump_tex
  1512.         cmp     [dr_flag],10
  1513.         je      .cubic_env_mapping
  1514.                                       ; ****************
  1515.         mov     esi,point_index3      ; do Gouraud shading
  1516.         mov     ecx,3
  1517.       .again_grd_draw:
  1518.         movzx   eax,word[esi]
  1519.         shl     eax,2
  1520.         lea     eax,[eax*3]
  1521.         add     eax,[points_normals_rot_ptr]
  1522.         ; texture x=(rotated point normal -> x * 255)+255
  1523.         fld     dword[eax]       ; x cooficient of normal vector
  1524.         fimul   [correct_tex]
  1525.         fiadd   [correct_tex]
  1526.         fistp   word[esp-2]
  1527.         ; texture y=(rotated point normal -> y * 255)+255
  1528.         fld     dword[eax+4]      ; y cooficient
  1529.         fimul   [correct_tex]
  1530.         fiadd   [correct_tex]
  1531.         fistp   word[esp-4]
  1532.  
  1533.         movzx    eax,word[esp-4]
  1534.         movzx    ebx,word[esp-2]
  1535.         shl      eax,TEX_SHIFT
  1536.         add      eax,ebx
  1537.         lea      eax,[eax*3+color_map]
  1538.         mov      eax,dword[eax]
  1539.         cmp     [catmull_flag],1      ; put on stack z coordinate if necessary
  1540.         jne      @f
  1541.         lea      edx,[ecx*3]
  1542.         push     word[edx*2+xx1-2]    ; zz1 ,2 ,3
  1543.       @@:
  1544.         ror      eax,16               ; eax -0xxxrrggbb -> 0xggbbxxrr
  1545.         xor      ah,ah
  1546.         push     ax         ;r
  1547.         rol      eax,8                ; eax-0xggbb00rr -> 0xbb00rrgg
  1548.         xor      ah,ah
  1549.         push     ax         ;g
  1550.         shr      eax,24
  1551.         push     ax         ;b
  1552.  
  1553.         sub      esi,2
  1554.         dec      cx
  1555.         jnz      .again_grd_draw
  1556.         jmp      .both_draw
  1557.  
  1558.    ;     movzx   edi,[point_index3]   ;gouraud shading according to light vector
  1559.    ;     lea     edi,[edi*3]
  1560.    ;     lea     edi,[4*edi+point_normals_rotated] ; edi - normal
  1561.    ;     mov     esi,light_vector
  1562.    ;     call    dot_product
  1563.    ;     fabs
  1564.    ;     fimul   [orginal_color_r]
  1565.    ;     fistp   [temp_col]
  1566.    ;     and     [temp_col],0x00ff
  1567.    ;     push    [temp_col]
  1568.    ;     push    [temp_col]
  1569.    ;     push    [temp_col]
  1570.  
  1571.    ;     movzx   edi,[point_index2]
  1572.    ;     lea     edi,[edi*3]
  1573.    ;     lea     edi,[4*edi+point_normals_rotated] ; edi - normal
  1574.    ;     mov     esi,light_vector
  1575.    ;     call    dot_product
  1576.    ;     fabs
  1577.    ;     fimul   [orginal_color_r]
  1578.    ;     fistp    [temp_col]
  1579.    ;     and     [temp_col],0x00ff
  1580.    ;     push    [temp_col]
  1581.    ;     push    [temp_col]
  1582.    ;     push    [temp_col]
  1583.  
  1584.    ;     movzx   edi,[point_index1]
  1585.    ;     lea     edi,[edi*3]
  1586.    ;     lea     edi,[4*edi+point_normals_rotated] ; edi - normal
  1587.    ;     mov     esi,light_vector
  1588.    ;     call    dot_product
  1589.    ;     fabs
  1590.    ;     fimul   [orginal_color_r]
  1591.    ;     fistp   [temp_col]
  1592.    ;     and     [temp_col],0x00ff
  1593.    ;     push    [temp_col]
  1594.    ;     push    [temp_col]
  1595.    ;     push    [temp_col]
  1596.    .rainbow:
  1597.         cmp     [catmull_flag],1      ; put on stack z coordinate if necessary
  1598.         jne      @f
  1599.         push     [zz3]
  1600.       @@:
  1601.         mov      eax,dword[yy3]
  1602.         mov      ebx,0x00ff00ff
  1603.         and      eax,ebx
  1604.         push     eax
  1605.         neg      al
  1606.         push     ax
  1607.         cmp     [catmull_flag],1
  1608.         jne      @f
  1609.         push     [zz2]
  1610.       @@:
  1611.         mov      eax,dword[yy2]
  1612.         and      eax,ebx
  1613.         push     eax
  1614.         neg      al
  1615.         push     ax
  1616.         cmp     [catmull_flag],1
  1617.         jne      @f
  1618.         push     [zz1]
  1619.       @@:
  1620.         mov      eax,dword[yy1]
  1621.         and      eax,ebx
  1622.         push     eax
  1623.         neg      al
  1624.         push     ax
  1625.     .both_draw:
  1626.         mov     eax,dword[xx1]
  1627.         ror     eax,16
  1628.         mov     ebx,dword[xx2]
  1629.         ror     ebx,16
  1630.         mov     ecx,dword[xx3]
  1631.         ror     ecx,16
  1632.         lea     edi,[screen]
  1633.         cmp     [catmull_flag],0
  1634.         je      @f
  1635.   ;      lea     esi,[Z_buffer]
  1636.         mov     esi,[Zbuffer_ptr]
  1637.         call    gouraud_triangle_z
  1638.         jmp     .end_draw
  1639.        @@:
  1640.         call    gouraud_triangle
  1641.         jmp     .end_draw
  1642.  
  1643.      .flat_draw:                     ;**************************
  1644.                                      ; FLAT DRAWING
  1645.         movzx   eax,[point_index1]
  1646.         movzx   ebx,[point_index2]
  1647.         movzx   ecx,[point_index3]
  1648.         shl     eax,2
  1649.         shl     ebx,2
  1650.         shl     ecx,2
  1651.         lea     eax,[eax*3]  ;+point_normals_rotated]
  1652.         add     eax,[points_normals_rot_ptr]
  1653.         lea     ebx,[ebx*3]  ;+point_normals_rotated]
  1654.         add     ebx,[points_normals_rot_ptr]
  1655.         lea     ecx,[ecx*3]  ;+point_normals_rotated]
  1656.         add     ecx,[points_normals_rot_ptr]
  1657.         fld     dword[eax]      ; x cooficient of normal vector
  1658.         fadd    dword[ebx]
  1659.         fadd    dword[ecx]
  1660.         fidiv   [i3]
  1661.         fimul   [correct_tex]
  1662.         fiadd   [correct_tex]
  1663.         fistp   dword[esp-4]    ; x temp variables
  1664.         fld     dword[eax+4]    ; y cooficient of normal vector
  1665.         fadd    dword[ebx+4]
  1666.         fadd    dword[ecx+4]
  1667.         fidiv   [i3]
  1668.         fimul   [correct_tex]
  1669.         fiadd   [correct_tex]
  1670.         fistp   dword[esp-8]   ;  y
  1671.         mov     edx,dword[esp-8]
  1672.         shl     edx,TEX_SHIFT
  1673.         add     edx,dword[esp-4]
  1674.         lea     eax,[3*edx+color_map]
  1675.         mov     edx,dword[eax]
  1676.  
  1677.         and     edx,0x00ffffff    ; edx = 0x00rrggbb
  1678.  
  1679.  
  1680.  
  1681.      ;   mov     ax,[zz1]      ; z position depend draw
  1682.      ;   add     ax,[zz2]
  1683.      ;   add     ax,[zz3]
  1684.      ;   cwd
  1685.      ;   idiv    [i3] ;    = -((a+b+c)/3+130)
  1686.      ;   add     ax,130
  1687.      ;   neg     al
  1688.      ;   xor     edx,edx
  1689.      ;   mov     ah,al           ;set color according to z position
  1690.      ;   shl     eax,8
  1691.      ;   mov     edx,eax
  1692.  
  1693.         mov     eax,dword[xx1]
  1694.         ror     eax,16
  1695.         mov     ebx,dword[xx2]
  1696.         ror     ebx,16
  1697.         mov     ecx,dword[xx3]
  1698.         ror     ecx,16
  1699.        ; mov     edi,screen
  1700.         lea     edi,[screen]
  1701.         cmp     [catmull_flag],0
  1702.         je      @f
  1703.    ;     lea     esi,[Z_buffer]
  1704.         mov     esi,[Zbuffer_ptr]
  1705.         push    word[zz3]
  1706.         push    word[zz2]
  1707.         push    word[zz1]
  1708.         call    flat_triangle_z
  1709.         jmp     .end_draw
  1710.       @@:
  1711.         call    draw_triangle
  1712.         jmp     .end_draw
  1713.       .env_mapping:
  1714.        ; fninit
  1715.         cmp     [catmull_flag],0
  1716.         je      @f
  1717.         push    [zz3]
  1718.         push    [zz2]
  1719.         push    [zz1]
  1720.       @@:
  1721.         mov     esi,point_index1
  1722.         sub     esp,12
  1723.         mov     edi,esp
  1724.         mov     ecx,3
  1725.       @@:
  1726.         movzx   eax,word[esi]
  1727.         lea     eax,[eax*3]
  1728.         shl     eax,2
  1729.         add     eax,[points_normals_rot_ptr]       ;point_normals_rotated
  1730. ; #
  1731. ;        fld     dword[eax]
  1732. ;        fmul    dword[eax+4]
  1733. ;        fld1
  1734. ;        fld1
  1735. ;        faddp
  1736. ;        fmulp
  1737. ;        fimul   [correct_tex]
  1738. ;        fiadd   [correct_tex]
  1739. ;        fistp   word[edi]
  1740. ;        mov     word[edi+2],0
  1741. ;;        fistp   word[edi+2]
  1742. ; # last change
  1743.         ; texture x=(rotated point normal -> x * 255)+255
  1744.         fld     dword[eax]
  1745.         fimul   [correct_tex]
  1746.         fiadd   [correct_tex]
  1747.         fistp   word[edi]
  1748.         ; texture y=(rotated point normal -> y * 255)+255
  1749.         fld     dword[eax+4]
  1750.         fimul   [correct_tex]
  1751.         fiadd   [correct_tex]
  1752.         fistp   word[edi+2]
  1753. ; # end of last ch.
  1754.         add     edi,4
  1755.         add     esi,2
  1756.         loop    @b
  1757.  
  1758.         mov     eax,dword[xx1]
  1759.         ror     eax,16
  1760.         mov     ebx,dword[xx2]
  1761.         ror     ebx,16
  1762.         mov     ecx,dword[xx3]
  1763.         ror     ecx,16
  1764.         mov     edi,screen
  1765.         mov     esi,envmap
  1766.         cmp     [catmull_flag],0
  1767.         je      @f
  1768.   ;      mov     edx,Z_buffer
  1769.         mov     edx,[Zbuffer_ptr]
  1770.         call    tex_triangle_z
  1771.         jmp     .end_draw
  1772.       @@:
  1773.         call    tex_triangle
  1774.         jmp     .end_draw
  1775. ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1776.      .cubic_env_mapping:
  1777.        ; fninit
  1778.         cmp     [catmull_flag],0
  1779.         je      @f
  1780.         push    [zz3]
  1781.         push    [zz2]
  1782.         push    [zz1]
  1783.       @@:
  1784.         mov     esi,point_index1
  1785.         sub     esp,12
  1786.         mov     edi,esp
  1787.         mov     ecx,3
  1788.       @@:
  1789.         movzx   eax,word[esi]
  1790.         lea     eax,[eax*3]
  1791.         shl     eax,2
  1792.         add     eax,[points_normals_rot_ptr]  ;point_normals_rotated
  1793. ; #
  1794.         fld     dword[eax]
  1795.         fmul    dword[eax+4]
  1796.         fld1
  1797.         fld1
  1798.         faddp
  1799.         fmulp
  1800.         fimul   [correct_tex]
  1801.         fiadd   [correct_tex]
  1802.         fistp   word[edi]
  1803.         mov     word[edi+2],0
  1804. ;        fistp   word[edi+2]
  1805. ; # last change
  1806. ;        ; texture x=(rotated point normal -> x * 255)+255
  1807. ;        fld     dword[eax]
  1808. ;        fimul   [correct_tex]
  1809. ;        fiadd   [correct_tex]
  1810. ;        fistp   word[edi]
  1811. ;        ; texture y=(rotated point normal -> y * 255)+255
  1812. ;        fld     dword[eax+4]
  1813. ;        fimul   [correct_tex]
  1814. ;        fiadd   [correct_tex]
  1815. ;        fistp   word[edi+2]
  1816. ; # end of last ch.
  1817.         add     edi,4
  1818.         add     esi,2
  1819.         loop    @b
  1820.  
  1821.         mov     eax,dword[xx1]
  1822.         ror     eax,16
  1823.         mov     ebx,dword[xx2]
  1824.         ror     ebx,16
  1825.         mov     ecx,dword[xx3]
  1826.         ror     ecx,16
  1827.         mov     edi,screen
  1828.         mov     esi,envmap_cub
  1829.         cmp     [catmull_flag],0
  1830.         je      @f
  1831.   ;      mov     edx,Z_buffer
  1832.         mov     edx,[Zbuffer_ptr]
  1833.         call    tex_triangle_z
  1834.         jmp     .end_draw
  1835.       @@:
  1836.         call    tex_triangle
  1837.         jmp     .end_draw
  1838.  
  1839. ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1840.  
  1841.       .bump_mapping:
  1842.         ; fninit
  1843.         cmp     [catmull_flag],0
  1844.         je      @f
  1845. ;        push    Z_buffer
  1846.         push    [Zbuffer_ptr]
  1847.         push    [zz3]
  1848.         push    [zz2]
  1849.         push    [zz1]
  1850.       @@:
  1851.         mov     esi,point_index1
  1852.         sub     esp,12
  1853.         mov     edi,esp
  1854.         mov     ecx,3
  1855.       @@:
  1856.         movzx   eax,word[esi]
  1857.         lea     eax,[eax*3]
  1858.         shl     eax,2
  1859.         add     eax,[points_normals_rot_ptr]  ;point_normals_rotated
  1860.         ; texture x=(rotated point normal -> x * 255)+255
  1861.         fld     dword[eax]
  1862.         fimul   [correct_tex]
  1863.         fiadd   [correct_tex]
  1864.         fistp   word[edi]
  1865.         ; texture y=(rotated point normal -> y * 255)+255
  1866.         fld     dword[eax+4]
  1867.         fimul   [correct_tex]
  1868.         fiadd   [correct_tex]
  1869.         fistp   word[edi+2]
  1870.  
  1871.         add     edi,4
  1872.         add     esi,2
  1873.         loop    @b
  1874.  
  1875.         movzx  esi,[point_index3]      ; bump map coords
  1876.         shl    esi,2
  1877.         add    esi,tex_points
  1878.         push   dword[esi]
  1879.         movzx  esi,[point_index2]
  1880.         shl    esi,2
  1881.         add    esi,tex_points
  1882. ;       lea    esi,[esi*3]
  1883. ;       lea    esi,[points+2+esi*2]
  1884.         push   dword[esi]
  1885.   ;     push   dword[xx2]
  1886.         movzx  esi,[point_index1]
  1887.         shl    esi,2
  1888.         add    esi,tex_points
  1889. ;       lea     esi,[esi*3]
  1890. ;       lea     esi,[points+2+esi*2]
  1891.         push   dword[esi]
  1892.    ;    push     dword[xx1]
  1893.  
  1894.         mov     eax,dword[xx1]
  1895.         ror     eax,16
  1896.         mov     ebx,dword[xx2]
  1897.         ror     ebx,16
  1898.         mov     ecx,dword[xx3]
  1899.         ror     ecx,16
  1900.         mov     edi,screen
  1901.         mov     esi,envmap
  1902.         mov     edx,bumpmap            ;BUMP_MAPPING
  1903.  
  1904.         cmp     [catmull_flag],0
  1905.         je      @f
  1906.         call    bump_triangle_z
  1907.         jmp     .end_draw
  1908.       @@:
  1909.         call    bump_triangle
  1910.         jmp     .end_draw
  1911.  
  1912.       .tex_mapping:
  1913.  
  1914.         ; fninit
  1915.         cmp     [catmull_flag],0
  1916.         je      @f
  1917.         push    [zz3]
  1918.         push    [zz2]
  1919.         push    [zz1]
  1920.       @@:
  1921.         movzx  esi,[point_index3]      ; tex map coords
  1922.         shl    esi,2
  1923.         add    esi,tex_points
  1924.         push   dword[esi]
  1925.         movzx  esi,[point_index2]
  1926.         shl    esi,2
  1927.         add    esi,tex_points
  1928.         push   dword[esi]
  1929.         movzx  esi,[point_index1]
  1930.         shl    esi,2
  1931.         add    esi,tex_points
  1932.         push   dword[esi]
  1933.  
  1934.         mov     eax,dword[xx1]
  1935.         ror     eax,16
  1936.         mov     ebx,dword[xx2]
  1937.         ror     ebx,16
  1938.         mov     ecx,dword[xx3]
  1939.         ror     ecx,16
  1940.         mov     edi,screen
  1941.         mov     esi,texmap
  1942.         cmp     [catmull_flag],0
  1943.         je      @f
  1944.    ;     mov     edx,Z_buffer
  1945.         mov     edx,[Zbuffer_ptr]
  1946.         call    tex_triangle_z
  1947.  ;       call    tex_plus_grd_trianlgle
  1948.         jmp     .end_draw
  1949.       @@:
  1950.         call    tex_triangle
  1951.         jmp     .end_draw
  1952. ;      .ray:
  1953. ;        grd_triangle according to points index
  1954. ;        cmp     [catmull_flag],0
  1955. ;        je      @f
  1956. ;        push    [zz3]                   ; spot light with attenuation
  1957. ;     @@:
  1958. ;        movzx   eax,[point_index3]      ; env_map - points color list
  1959. ;        shl     eax,1                   ; each color as word, 0x00rr00gg00bb..
  1960. ;        lea     eax,[3*eax+bumpmap]
  1961. ;        push    word[eax]
  1962. ;        push    word[eax+2]
  1963. ;        push    word[eax+4]
  1964. ;        cmp     [catmull_flag],0
  1965. ;        je      @f
  1966. ;        push    [zz2]
  1967. ;    @@:
  1968. ;        movzx   eax,[point_index2]      ; env_map - points color list
  1969. ;        shl     eax,1                   ; each color as word, 0x00rr00gg00bb..
  1970. ;        lea     eax,[eax*3+bumpmap]
  1971. ;        push    word[eax]
  1972. ;        push    word[eax+2]
  1973. ;        push    word[eax+4]
  1974. ;        cmp     [catmull_flag],0
  1975. ;        je      @f
  1976. ;        push    [zz1]
  1977. ;     @@:
  1978. ;        movzx   eax,[point_index1]      ; env_map - points color list
  1979. ;        shl     eax,1                   ; each color as word, 0xrr00gg00bb00..
  1980. ;        lea     eax,[eax*3+bumpmap]
  1981. ;        push    word[eax]
  1982. ;        push    word[eax+2]
  1983. ;        push    word[eax+4]
  1984. ;        jmp     .both_draw
  1985.  
  1986.      .grd_tex:            ; smooth shading + texture
  1987.          push   ebp
  1988.          mov    ebp,esp
  1989.          sub    esp,4
  1990.          push   ebp
  1991.  
  1992.          movzx  esi,[point_index3]      ; tex map coords
  1993.          shl    esi,2
  1994.          add    esi,tex_points
  1995.          push   dword[esi]              ; texture coords as first
  1996.          movzx  esi,[point_index2]      ; group of parameters
  1997.          shl    esi,2
  1998.          add    esi,tex_points
  1999.          push   dword[esi]
  2000.          movzx  esi,[point_index1]
  2001.          shl    esi,2
  2002.          add    esi,tex_points
  2003.          push   dword[esi]
  2004.  
  2005.          mov     esi,point_index3
  2006.          mov     ecx,3
  2007.  
  2008.       .aagain_grd_draw:
  2009.  
  2010.         lea      edx,[ecx*3]
  2011.         push     word[edx*2+xx1-2]    ; zz1 ,2 ,3
  2012.  
  2013.         movzx   eax,word[esi]
  2014.         shl     eax,2
  2015.         lea     eax,[eax*3] ;+point_normals_rotated]
  2016.         add     eax,[points_normals_rot_ptr]
  2017.         ; texture x=(rotated point normal -> x * 255)+255
  2018.         fld     dword[eax]       ; x cooficient of normal vector
  2019.         fimul   [correct_tex]
  2020.         fiadd   [correct_tex]
  2021.         fistp   word[ebp-2]
  2022.         ; texture y=(rotated point normal -> y * 255)+255
  2023.         fld     dword[eax+4]      ; y cooficient
  2024.         fimul   [correct_tex]
  2025.         fiadd   [correct_tex]
  2026.         fistp   word[ebp-4]
  2027.  
  2028.         movzx    eax,word[ebp-4]
  2029.         movzx    ebx,word[ebp-2]
  2030.         shl      eax,TEX_SHIFT
  2031.         add      eax,ebx
  2032.         lea      eax,[eax*3+color_map]
  2033.         mov      eax,dword[eax]
  2034.  
  2035.         ror      eax,16               ; eax -0xxxrrggbb -> 0xggbbxxrr
  2036.         xor      ah,ah
  2037.         push     ax         ;r
  2038.         rol      eax,8                ; eax-0xggbb00rr -> 0xbb00rrgg
  2039.         xor      ah,ah
  2040.         push     ax         ;g
  2041.         shr      eax,24
  2042.         push     ax         ;b
  2043.  
  2044.         sub      esi,2
  2045.         dec      cx
  2046.         jnz      .aagain_grd_draw
  2047.  
  2048.         mov     eax,dword[xx1]
  2049.         ror     eax,16
  2050.         mov     ebx,dword[xx2]
  2051.         ror     ebx,16
  2052.         mov     ecx,dword[xx3]
  2053.         ror     ecx,16
  2054.         mov     edi,screen
  2055.         mov     edx,texmap
  2056.         mov     esi,[Zbuffer_ptr]
  2057.  
  2058.         call    tex_plus_grd_triangle
  2059.  
  2060.         pop     ebp
  2061.         mov     esp,ebp
  2062.         pop     ebp
  2063.         jmp     .end_draw
  2064.  
  2065.       .two_tex:
  2066.         push    [Zbuffer_ptr]
  2067.  
  2068.         push    word[zz3]
  2069.         push    word[zz2]
  2070.         push    word[zz1]
  2071.  
  2072.         movzx  esi,[point_index3]      ; tex map coords
  2073.         shl    esi,2
  2074.         add    esi,tex_points
  2075.         push   dword[esi]
  2076.         movzx  esi,[point_index2]
  2077.         shl    esi,2
  2078.         add    esi,tex_points
  2079.         push   dword[esi]
  2080.         movzx  esi,[point_index1]
  2081.         shl    esi,2
  2082.         add    esi,tex_points
  2083.         push   dword[esi]
  2084.  
  2085.         mov     esi,point_index1     ; env coords
  2086.         sub     esp,12
  2087.         mov     edi,esp
  2088.         mov     ecx,3
  2089.       @@:
  2090.         movzx   eax,word[esi]
  2091.         lea     eax,[eax*3]
  2092.         shl     eax,2
  2093.         add     eax,[points_normals_rot_ptr]
  2094.         ; texture x=(rotated point normal -> x * 255)+255
  2095.         fld     dword[eax]
  2096.         fimul   [correct_tex]
  2097.         fiadd   [correct_tex]
  2098.         fistp   word[edi]
  2099.         ; texture y=(rotated point normal -> y * 255)+255
  2100.         fld     dword[eax+4]
  2101.         fimul   [correct_tex]
  2102.         fiadd   [correct_tex]
  2103.         fistp   word[edi+2]
  2104.  
  2105.         add     edi,4
  2106.         add     esi,2
  2107.         loop    @b
  2108.  
  2109.         mov     eax,dword[xx1]
  2110.         ror     eax,16
  2111.         mov     ebx,dword[xx2]
  2112.         ror     ebx,16
  2113.         mov     ecx,dword[xx3]
  2114.         ror     ecx,16
  2115.         mov     edi,screen
  2116.         mov     esi,texmap
  2117.         mov     edx,envmap
  2118.  
  2119.         call    two_tex_triangle_z
  2120.         jmp     .end_draw
  2121.  
  2122.    .bump_tex:
  2123.         movzx  esi,[point_index3]      ; tex map coords
  2124.         shl    esi,2
  2125.         add    esi,tex_points
  2126.         push   dword[esi]
  2127.         movzx  esi,[point_index2]
  2128.         shl    esi,2
  2129.         add    esi,tex_points
  2130.         push   dword[esi]
  2131.         movzx  esi,[point_index1]
  2132.         shl    esi,2
  2133.         add    esi,tex_points
  2134.         push   dword[esi]
  2135.  
  2136.         push  dword texmap
  2137.  
  2138.         push  [Zbuffer_ptr]
  2139.         xor   edi,edi
  2140.  
  2141.         push    word[zz3]
  2142.         push    word[zz2]
  2143.         push    word[zz1]
  2144.  
  2145.         mov     esi,point_index1     ; env coords
  2146.         sub     esp,12
  2147.         mov     edi,esp
  2148.         mov     ecx,3
  2149.       @@:
  2150.         movzx   eax,word[esi]
  2151.         lea     eax,[eax*3]
  2152.         shl     eax,2
  2153.         add     eax,[points_normals_rot_ptr]
  2154.         ; texture x=(rotated point normal -> x * 255)+255
  2155.         fld     dword[eax]
  2156.         fimul   [correct_tex]
  2157.         fiadd   [correct_tex]
  2158.         fistp   word[edi]
  2159.         ; texture y=(rotated point normal -> y * 255)+255
  2160.         fld     dword[eax+4]
  2161.         fimul   [correct_tex]
  2162.         fiadd   [correct_tex]
  2163.         fistp   word[edi+2]
  2164.  
  2165.         add     edi,4
  2166.         add     esi,2
  2167.         loop    @b
  2168.  
  2169. ;        push  dword 1 shl 16 + 1  ; emap coords
  2170. ;        push  dword 127 shl 16 + 1
  2171. ;        push  dword 127 shl 16 + 127
  2172.  
  2173.         movzx  esi,[point_index3]      ; bump map coords
  2174.         shl    esi,2
  2175.         add    esi,tex_points
  2176.         push   dword[esi]
  2177.         movzx  esi,[point_index2]
  2178.         shl    esi,2
  2179.         add    esi,tex_points
  2180.         push   dword[esi]
  2181.  
  2182.         movzx  esi,[point_index1]
  2183.         shl    esi,2
  2184.         add    esi,tex_points
  2185.         push   dword[esi]
  2186.  
  2187. ;        push  dword 1 shl 16 + 127
  2188. ;        push  dword 127 shl 16 + 127
  2189. ;        push  dword 1 shl 16 + 1  ; bump coords
  2190.  
  2191.         mov     eax,dword[xx1]
  2192.         ror     eax,16
  2193.         mov     ebx,dword[xx2]
  2194.         ror     ebx,16
  2195.         mov     ecx,dword[xx3]
  2196.         ror     ecx,16
  2197.         mov     edi,screen
  2198.         mov     esi,envmap
  2199.         mov     edx,bumpmap
  2200.  
  2201.         call bump_tex_triangle_z
  2202.  
  2203.       .end_draw:
  2204.         pop     esi
  2205.         add     esi,6
  2206.         cmp     dword[esi],-1
  2207.         jne     .again_dts
  2208. ret
  2209.  
  2210.  
  2211. fill_Z_buffer:
  2212.         mov     eax,0x70000000
  2213.       ;  mov     edi,Z_buffer
  2214.         mov     edi,[Zbuffer_ptr]
  2215.         mov     ecx,SIZE_X*SIZE_Y
  2216.         rep     stosd
  2217. ret
  2218.  
  2219. read_from_file:
  2220.         fninit
  2221.         mov     edi,[triangles_ptr]
  2222.         xor     ebx,ebx
  2223.         xor     ebp,ebp
  2224.         mov     [points_count_var],0
  2225.         mov     [triangles_count_var],0
  2226.    if USE_LFN = 0
  2227.         mov     esi,SourceFile
  2228.    else
  2229.         mov     esi,[fptr]
  2230.    end if
  2231.         cmp     [esi],word 4D4Dh
  2232.         jne     .exit ;Must be legal .3DS file
  2233. ;        cmp     dword[esi+2],EndFile-SourceFile
  2234. ;        jne     .exit ;This must tell the length
  2235.         mov     eax,dword[esi+2]
  2236.   ;      cmp     eax,[fsize]
  2237.   ;      jne     .exit
  2238.  
  2239.         add     eax,esi
  2240.         mov     [EndFile],eax    ;
  2241.  
  2242.         add     esi,6
  2243.       @@:
  2244.         cmp     [esi],word 3D3Dh
  2245.         je      @f
  2246.         add     esi,[esi+2]
  2247.         jmp     @b
  2248.       @@:
  2249.         add     esi,6
  2250.       .find4k:
  2251.         cmp     [esi],word 4000h
  2252.         je      @f
  2253.         add     esi,[esi+2]
  2254.         cmp     esi,[EndFile]
  2255.         jc      .find4k
  2256.         jmp     .exit
  2257.       @@:
  2258.         add     esi,6
  2259.       @@:
  2260.         cmp     [esi],byte 0
  2261.         je      @f
  2262.         inc     esi
  2263.         jmp     @b
  2264.       @@:
  2265.         inc     esi
  2266.       @@:
  2267.         cmp     [esi],word 4100h
  2268.         je      @f
  2269.         add     esi,[esi+2]
  2270.         jmp     @b
  2271.       @@:
  2272.         add     esi,6
  2273.       @@:
  2274.         cmp     [esi],word 4110h
  2275.         je      @f
  2276.         add     esi,[esi+2]
  2277.         jmp     @b
  2278.       @@:
  2279.         movzx   ecx,word[esi+6]
  2280.         add     [points_count_var],cx
  2281.  
  2282.         mov     edx,ecx
  2283.         add     esi,8
  2284.      @@:
  2285.         push    edi
  2286.         mov     edi,[points_ptr]
  2287.         push    dword[esi+4]
  2288.         pop     dword[edi+ebx*2+0]
  2289.         push    dword[esi+8]
  2290.         pop     dword[edi+ebx*2+4]
  2291.         push    dword[esi+0]
  2292.         pop     dword[edi+ebx*2+8]
  2293.         pop     edi
  2294. ;        fld     dword[esi+4]
  2295. ;        fstp    dword[real_points+ebx*2+0]  ; x
  2296. ;        fld     dword[esi+8]
  2297. ;        fstp   dword[real_points+ebx*2+4]  ; y
  2298. ;        fld     dword[esi+0]
  2299. ;        fstp   dword[real_points+ebx*2+8]  ; z
  2300.  
  2301.         add     ebx,6
  2302.         add     esi,12
  2303.         dec     ecx
  2304.         jnz     @b
  2305.       @@:
  2306.   ;      mov     dword[points+ebx],-1
  2307.         push    edi
  2308.         mov     edi,[points_ptr]
  2309.         mov     dword[edi+ebx*2],-1        ; end mark (not always in use)
  2310.         pop     edi
  2311.       @@:
  2312.         cmp     [esi],word 4120h
  2313.         je      @f
  2314.         add     esi,[esi+2]
  2315.         jmp     @b
  2316.       @@:
  2317.         movzx   ecx,word[esi+6]
  2318.         add     [triangles_count_var],cx
  2319.         add     esi,8
  2320.         ;mov     edi,triangles
  2321.       @@:
  2322.         movsd
  2323.         movsw
  2324.         add     word[edi-6],bp
  2325.         add     word[edi-4],bp
  2326.         add     word[edi-2],bp
  2327.         add     esi,2
  2328.         dec     ecx
  2329.         jnz     @b
  2330.         add     ebp,edx
  2331.         jmp     .find4k
  2332.         mov     eax,-1 ;<---mark if OK
  2333.       .exit:
  2334.         mov     dword[edi],-1
  2335. ret
  2336.  
  2337. read_tp_variables:            ; read [triangles_count_var] and  [points_count_var]
  2338.                               ; and  allocate memory
  2339.         xor     ebx,ebx
  2340.         xor     ebp,ebp
  2341.         mov     [points_count_var],bx
  2342.         mov     [triangles_count_var],bx
  2343.    if USE_LFN = 0
  2344.         mov     esi,SourceFile
  2345.    else
  2346.         mov     esi,[fptr]
  2347.    end if
  2348.  
  2349.         cmp     [esi],word 4D4Dh
  2350.         je      @f ;Must be legal .3DS file
  2351.         xor     eax,eax
  2352.         ret
  2353.     @@:
  2354.         mov     eax,dword[esi+2]
  2355.         cmp     eax,[fsize] ;This must tell the length
  2356.         je      @f
  2357.         xor     eax,eax
  2358.         ret
  2359.      @@:
  2360.         add     eax,esi
  2361.         mov     [EndFile],eax    ;
  2362.  
  2363.         add     esi,6
  2364.       @@:
  2365.         cmp     [esi],word 3D3Dh
  2366.         je      @f
  2367.         add     esi,[esi+2]
  2368.         jmp     @b
  2369.       @@:
  2370.         add     esi,6
  2371.       .find4k:
  2372.         cmp     [esi],word 4000h
  2373.         je      @f
  2374.         add     esi,[esi+2]
  2375.         cmp     esi,[EndFile]
  2376.         jc      .find4k
  2377.         jmp     .exit
  2378.       @@:
  2379.         add     esi,6
  2380.       @@:
  2381.         cmp     [esi],byte 0
  2382.         je      @f
  2383.         inc     esi
  2384.         jmp     @b
  2385.       @@:
  2386.         inc     esi
  2387.       @@:
  2388.         cmp     [esi],word 4100h
  2389.         je      @f
  2390.         add     esi,[esi+2]
  2391.         jmp     @b
  2392.       @@:
  2393.         add     esi,6
  2394.       @@:
  2395.         cmp     [esi],word 4110h
  2396.         je      @f
  2397.         add     esi,[esi+2]
  2398.         jmp     @b
  2399.       @@:
  2400.         movzx   ecx,word[esi+6]
  2401.         add     [points_count_var],cx
  2402.  
  2403.         mov     edx,ecx
  2404.         add     esi,8
  2405.      @@:
  2406.  
  2407.         add     ebx,6
  2408.         add     esi,12
  2409.      ;   dec     ecx
  2410.         loop     @b
  2411.       @@:
  2412.  
  2413.       @@:
  2414.         cmp     [esi],word 4120h
  2415.         je      @f
  2416.         add     esi,[esi+2]
  2417.         jmp     @b
  2418.       @@:
  2419.         movzx   ecx,word[esi+6]
  2420.         add     [triangles_count_var],cx
  2421.         add     esi,8
  2422.  
  2423.       @@:
  2424.         add     esi,8
  2425.         dec     ecx
  2426.         jnz     @b
  2427. ;        xor     ecx,ecx
  2428.         add     ebp,edx
  2429.         jmp     .find4k
  2430.         mov     eax,-1 ;<---mark if OK
  2431.       .exit:
  2432. ret
  2433.  
  2434. if USE_LFN
  2435. alloc_mem_for_tp:
  2436.         mov     eax, 68
  2437.         cmp     [re_alloc_flag],1
  2438.         jz      @f
  2439.         mov     ebx, 12
  2440.         jmp     .alloc
  2441.     @@:
  2442.         mov     ebx,20
  2443.     .alloc:
  2444.         movzx   ecx, [triangles_count_var]
  2445.         inc     ecx
  2446.         lea     ecx, [ecx*3]
  2447.         add     ecx, ecx
  2448.         mov     edx,[triangles_ptr]
  2449.         int     0x40                   ;  -> allocate memory to triangles
  2450.         mov     [triangles_ptr], eax   ;  -> eax = pointer to allocated mem
  2451.  
  2452. ;        mov     eax, 68
  2453. ;        mov     ebx, 12
  2454. ;        movzx   ecx, [triangles_count_var]
  2455. ;        shl     ecx, 4
  2456. ;        int     0x40
  2457. ;        mov     [triangles_w_z_ptr], eax   ; for trainagles_with_z list
  2458.                                             ; ststic  memory
  2459.  
  2460.         mov     eax, 68
  2461.         movzx   ecx, [triangles_count_var]
  2462.         lea     ecx, [3+ecx*3]
  2463.         shl     ecx, 2
  2464.         mov     edx,[triangles_normals_ptr]
  2465.         int     0x40                           ;  -> allocate memory for triangles normals
  2466.         mov     [triangles_normals_ptr], eax   ;  -> eax = pointer to allocated mem
  2467.  
  2468.         mov     eax, 68
  2469.         movzx   ecx, [points_count_var]
  2470.         lea     ecx,[3+ecx*3]
  2471.         shl     ecx, 2
  2472.         mov     edx,[points_normals_ptr]
  2473.         int     0x40
  2474.         mov     [points_normals_ptr], eax
  2475.  
  2476.         mov     eax, 68
  2477.     ;    mov     ebx, 12
  2478.         movzx   ecx, [points_count_var]
  2479.         lea     ecx,[3+ecx*3]
  2480.         shl     ecx, 2
  2481.         mov     edx,[points_normals_rot_ptr]
  2482.         int     0x40
  2483.         mov     [points_normals_rot_ptr], eax
  2484.  
  2485.         mov     eax, 68
  2486.         mov     edx,[points_ptr]
  2487.         int     0x40
  2488.         mov     [points_ptr], eax
  2489.  
  2490.         mov     eax, 68
  2491.         mov     edx,[points_rotated_ptr]
  2492.         int     0x40
  2493.         mov     [points_rotated_ptr], eax
  2494.  
  2495.         mov     eax, 68
  2496.         movzx   ecx, [points_count_var]
  2497.         inc     ecx
  2498.         shl     ecx, 3
  2499.         mov     edx,[points_translated_ptr]
  2500.         int     0x40
  2501.         mov     [points_translated_ptr], eax
  2502. ret
  2503. end if
  2504.  
  2505.  
  2506. read_from_disk:
  2507. if USE_LFN
  2508. ;-
  2509.     mov     eax, 70
  2510.     mov     ebx, file_info
  2511.     mov     dword[ebx], 5          ;  -> subfunction number
  2512.     int     0x40                   ;  -> read file size
  2513.     mov     ebx, [fptr]
  2514.     mov     ebx, dword[ebx+32]
  2515.     inc     ebx
  2516.     mov     [fsize], ebx
  2517.  
  2518.     mov     eax, 68
  2519.     mov     ebx, 11
  2520.     int     0x40                   ;  -> create heap
  2521.  
  2522.     mov     eax, 68
  2523.     mov     ebx, 12
  2524.     mov     ecx, [fsize]
  2525.     int     0x40                   ;  -> allocate memory for file
  2526.     mov     [fptr], eax            ;  -> eax = pointer to allocated mem
  2527.  
  2528.     mov     eax, 70
  2529.     mov     ebx, file_info
  2530.     mov     dword[ebx],0
  2531.     int     0x40                   ; -> read file
  2532.  
  2533.     mov     [fsize],ebx
  2534.  
  2535.     cmp     eax,6
  2536.     jnz     @f
  2537.     xor     eax,eax     ;;;;---
  2538.   @@:
  2539. else
  2540.     mov      eax,58
  2541.     mov      ebx,file_info
  2542.     int      0x40
  2543.  
  2544.     mov      eax,ebx
  2545.     shr      eax,9
  2546.     inc      eax
  2547.     mov      [fsize],eax
  2548. ;    mov      ecx,ebx
  2549. ;    add      ecx,MEM_END
  2550. ;    mov      ebx,1
  2551. ;    mov      eax,64     ; allocate mem  - resize app mem
  2552.                         ; for points and  triangles
  2553.     int      0x40
  2554.  
  2555.     mov      eax,58
  2556.     mov      ebx,file_info
  2557.     int      0x40
  2558. end if
  2559.   ;  eax = 0   -> ok file loaded
  2560. ret
  2561. read_param:
  2562.     mov        esi,I_Param
  2563.     cmp        dword[esi],0
  2564.     je         .end
  2565.     cmp        byte[esi],'/'
  2566.     je         .copy
  2567.     mov        edi,esi
  2568.     mov        ecx,25   ; 25 - would be enought
  2569.     repe       scasb
  2570.     jne        .end
  2571.     dec        edi
  2572.     mov        esi,edi
  2573.  .copy:
  2574.     mov         edi,file_name
  2575.     mov         ecx,50
  2576.     rep         movsd
  2577.  .end:
  2578. ret
  2579. buttons:                                      ; draw some buttons (all but navigation and close )
  2580.         mov     edi,menu
  2581.       .again:
  2582.         mov     eax,8                         ; function 8 : define and draw button
  2583.         mov     ebx,(SIZE_X+10)*65536+62      ; [x start] *65536 + [x size]
  2584.         movzx   ecx,byte[edi]                 ; button id = position+2
  2585.         sub     cl,2
  2586.         lea     ecx,[ecx*5]
  2587.         lea     ecx,[ecx*3]
  2588.         add     ecx,25
  2589.         shl     ecx,16
  2590.         add     ecx,12
  2591.         movzx   edx,byte[edi]                   ; button id
  2592.         mov     esi,0x6688dd                    ; button color RRGGBB
  2593.         int     0x40
  2594.          ; BUTTON  LABEL
  2595.         mov     eax,4                           ; function 4 : write text to window
  2596.         movzx   ebx,byte[edi]
  2597.         sub     bl,2                            ; button id, according to position
  2598.         lea     ebx,[ebx*3]
  2599.         lea     ebx,[ebx*5]
  2600.         add     ebx,(SIZE_X+12)*65536+28        ; [x start] *65536 + [y start]
  2601.         mov     ecx,0x20ddeeff                  ; font 1 & color ( 0xF0RRGGBB )
  2602.         lea     edx,[edi+1]                     ; pointer to text beginning
  2603.         mov     esi,10                          ; text length
  2604.         int     0x40
  2605.         cmp     byte[edi+11],255                ; if max_flag=255
  2606.         je      @f                              ; skip
  2607.         ; flag description
  2608. ;       mov     eax,4                           ; function 4 : write text to window
  2609. ;       movzx   ebx,byte[edi]
  2610. ;       sub     bl,2
  2611. ;       lea     ebx,[ebx*3]
  2612. ;       lea     ebx,[ebx*5]
  2613. ;       add     ebx,(SIZE_X+12+70)*65536+28     ; [x start] *65536 + [y start]
  2614.         add     ebx,70*65536
  2615. ;       mov     ecx,0x20ddeeff                  ; font 1 & color ( 0xF0RRGGBB )
  2616.         movzx   edx,byte[edi+12]                ; current flag
  2617.         shl     edx,2                           ; * 4 = text length
  2618.         add     edx,dword[edi+13]               ; pointer to text beginning
  2619.         mov     esi,4                           ; text length
  2620.         int     0x40
  2621.  
  2622.     @@:
  2623.         add     edi,17
  2624.         cmp     byte[edi],-1
  2625.         jnz     .again
  2626. ret
  2627. ;   *********************************************
  2628. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  2629. ;   *********************************************
  2630.     draw_window:
  2631.         mov     eax,12          ; function 12:tell os about windowdraw
  2632.         mov     ebx,1           ; 1, start of draw
  2633.         int     0x40
  2634.  
  2635.         ; DRAW WINDOW
  2636.         mov     eax,0           ; function 0 : define and draw window
  2637.         mov     ebx,100*65536;+SIZE_X;+80+30 ; [x start] *65536 + [x size]
  2638.         mov     ecx,100*65536;+SIZE_Y;+30    ; [y start] *65536 + [y size]
  2639.         mov     bx,[size_x]
  2640.         add     bx,110
  2641.         mov     cx,[size_y]
  2642.         add     cx,30
  2643.         mov     edx,0x14000000  ; color of work area RRGGBB,8->color gl
  2644.         mov     edi,labelt      ; WINDOW LABEL
  2645.         int     0x40
  2646.  
  2647.         call    buttons         ; more buttons
  2648.  
  2649.         .Y_ADD equ 1   ;-> offset of 'add vector' buttons
  2650.  
  2651.         ; ADD VECTOR LABEL      ; add vector buttons - 30 ++
  2652.         mov     eax,4           ; function 4 : write text to window
  2653.         mov     ebx,(SIZE_X+12)*65536+(168+15*(13+.Y_ADD))   ; [x start] *65536 + [y start]
  2654.         mov     ecx,0x20ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  2655.         mov     edx,labelvector      ; pointer to text beginning
  2656.         mov     esi,labelvectorend-labelvector     ; text length
  2657.     ;    cmp     [move_flag],2
  2658.     ;    jne     @f
  2659.     ;    add     edx,navigation_size
  2660.     ;  @@:
  2661.         int     0x40
  2662.          ; VECTOR Y- BUTTON
  2663.         mov     eax,8           ; function 8 : define and draw button
  2664.         mov     ebx,(SIZE_X+30)*65536+20     ; [x start] *65536 + [x size]
  2665.         mov     ecx,(165+15*(14+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  2666.         mov     edx,30           ; button id
  2667.         mov     esi,0x6688dd    ; button color RRGGBB
  2668.         int     0x40
  2669.         ;VECTOR Y- LABEL
  2670.         mov     eax,4           ; function 4 : write text to window
  2671.         mov     ebx,(SIZE_X+32)*65536+(168+15*(14+.Y_ADD))   ; [x start] *65536 + [y start]
  2672.         mov     ecx,0x20ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  2673.         mov     edx,labelyminus      ; pointer to text beginning
  2674.         mov     esi,labelyminusend-labelyminus     ; text length
  2675.         cmp     [move_flag],2
  2676.    ;     jne     @f
  2677.    ;     add     edx,navigation_size
  2678.    ;   @@:
  2679.         int     0x40
  2680.         ; VECTOR Z+ BUTTON
  2681.         mov     eax,8           ; function 8 : define and draw button
  2682.         mov     ebx,(SIZE_X+51)*65536+21     ; [x start] *65536 + [x size]
  2683.         mov     ecx,(165+15*(14+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  2684.         mov     edx,31           ; button id
  2685.         mov     esi,0x6688dd    ; button color RRGGBB
  2686.         int     0x40
  2687.         ;VECTOR Z+ LABEL
  2688.         mov     eax,4           ; function 4 : write text to window
  2689.         mov     ebx,(SIZE_X+53)*65536+(168+15*(14+.Y_ADD))   ; [x start] *65536 + [y start]
  2690.         mov     ecx,0x20ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  2691.         mov     edx,labelzplus      ; pointer to text beginning
  2692.         mov     esi,labelzplusend-labelzplus     ; text length
  2693.    ;     cmp     [move_flag],2
  2694.    ;     jne     @f
  2695.    ;     add     edx,navigation_size
  2696.    ;   @@:
  2697.  
  2698.         int     0x40
  2699.         ; VECTOR x- BUTTON
  2700.         mov     eax,8           ; function 8 : define and draw button
  2701.         mov     ebx,(SIZE_X+10)*65536+21     ; [x start] *65536 + [x size]
  2702.         mov     ecx,(165+15*(15+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  2703.         mov     edx,32           ; button id
  2704.         mov     esi,0x6688dd    ; button color RRGGBB
  2705.         int     0x40
  2706.         ;VECTOR x- LABEL
  2707.         mov     eax,4           ; function 4 : write text to window
  2708.         mov     ebx,(SIZE_X+12)*65536+(168+15*(15+.Y_ADD))   ; [x start] *65536 + [y start]
  2709.         mov     ecx,0x20ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  2710.         mov     edx,labelxminus      ; pointer to text beginning
  2711.         mov     esi,labelxminusend-labelxminus     ; text length
  2712.    ;     cmp     [move_flag],2
  2713.    ;     jne     @f
  2714.    ;     add     edx,navigation_size
  2715.    ;   @@:
  2716.         int     0x40
  2717.         ; VECTOR x+ BUTTON
  2718.         mov     eax,8           ; function 8 : define and draw button
  2719.         mov     ebx,(SIZE_X+51)*65536+21     ; [x start] *65536 + [x size]
  2720.         mov     ecx,(165+15*(15+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  2721.         mov     edx,33           ; button id
  2722.         mov     esi,0x6688dd    ; button color RRGGBB
  2723.         int     0x40
  2724.         ;VECTOR x+ LABEL
  2725.         mov     eax,4           ; function 4 : write text to window
  2726.         mov     ebx,(SIZE_X+53)*65536+(168+15*(15+.Y_ADD))   ; [x start] *65536 + [y start]
  2727.         mov     ecx,0x20ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  2728.         mov     edx,labelxplus      ; pointer to text beginning
  2729.         mov     esi,labelxplusend-labelxplus     ; text length
  2730.    ;     cmp     [move_flag],2
  2731.    ;     jne     @f
  2732.    ;     add     edx,navigation_size
  2733.    ;   @@:
  2734.         int     0x40
  2735.         ; VECTOR z- BUTTON
  2736.         mov     eax,8           ; function 8 : define and draw button
  2737.         mov     ebx,(SIZE_X+10)*65536+62-41     ; [x start] *65536 + [x size]
  2738.         mov     ecx,(25+140+15*(16+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  2739.         mov     edx,34           ; button id
  2740.         mov     esi,0x6688dd    ; button color RRGGBB
  2741.         int     0x40
  2742.         ;VECTOR z- LABEL
  2743.         mov     eax,4           ; function 4 : write text to window
  2744.         mov     ebx,(SIZE_X+12)*65536+(168+15*(16+.Y_ADD))   ; [x start] *65536 + [y start]
  2745.         mov     ecx,0x20ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  2746.         mov     edx,labelzminus      ; pointer to text beginning
  2747.         mov     esi,labelzminusend-labelzminus     ; text length
  2748.    ;     cmp     [move_flag],2
  2749.    ;     jne     @f
  2750.    ;     add     edx,navigation_size
  2751.    ;   @@:
  2752.         int     0x40
  2753.        ;VECTOR Y+ BUTTON
  2754.         mov     eax,8           ; function 8 : define and draw button
  2755.         mov     ebx,(SIZE_X+10+20)*65536+20     ; [x start] *65536 + [x size]
  2756.         mov     ecx,(165+15*(16+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
  2757.         mov     edx,35           ; button id
  2758.         mov     esi,0x6688dd    ; button color RRGGBB
  2759.         int     0x40
  2760.         ;VECTOR Y+ LABEL
  2761.         mov     eax,4           ; function 4 : write text to window
  2762.         mov     ebx,(SIZE_X+32)*65536+(168+15*(16+.Y_ADD))   ; [x start] *65536 + [y start]
  2763.         mov     ecx,0x20ddeeff  ; font 1 & color ( 0xF0RRGGBB )
  2764.         mov     edx,labelyplus      ; pointer to text beginning
  2765.         mov     esi,labelyplusend-labelyplus     ; text length
  2766.    ;     cmp     [move_flag],2
  2767.    ;     jne     @f
  2768.    ;     add     edx,navigation_size
  2769.    ;   @@:
  2770.         int     0x40
  2771.  
  2772.         mov     eax,12          ; function 12:tell os about windowdraw
  2773.         mov     ebx,2           ; 2, end of draw
  2774.         int     0x40
  2775.         ret
  2776.  
  2777.  
  2778.    ; DATA AREA  ************************************
  2779.  
  2780.    include 'DATA.INC'
  2781.  
  2782. MEM_END:
  2783.