Subversion Repositories Kolibri OS

Rev

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

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