Subversion Repositories Kolibri OS

Rev

Rev 9454 | Rev 9516 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9454 Rev 9512
Line 1... Line 1...
1
; application : View3ds ver. 0.075 - tiny .3ds and .asc files viewer
1
; application : View3ds ver. 0.076 - tiny .3ds and .asc files viewer
2
;               with a few graphics effects demonstration.
2
;               with a few graphics effects demonstration.
3
; compiler    : FASM
3
; compiler    : FASM
4
; system      : KolibriOS
4
; system      : KolibriOS
5
; author      : Macgub aka Maciej Guba
5
; author      : Macgub aka Maciej Guba
6
; email       : macgub3@wp.pl
6
; email       : macgub3@wp.pl
7
; web         : http://macgub.co.pl, http://macgub.j.pl
7
; web         : http://macgub.co.pl
8
; Fell free to use this intro in your own distribution of KolibriOS.
8
; Fell free to use this intro in your own distribution of KolibriOS.
9
; Special greetings to KolibriOS team .
9
; Special greetings to KolibriOS team .
10
; I hope because my demos Christian Belive will be near to each of You.
10
; I hope because my demos Christian Belive will be near to each of You.
Line 16... Line 16...
16
; can be:
16
; can be:
17
; 1) Read from a file (*.3DS standard)
17
; 1) Read from a file (*.3DS standard)
18
; 2) Written in manually (at the end of the code) ; now not exist
18
; 2) Written in manually (at the end of the code) ; now not exist
19
 
19
 
Line 20... Line -...
20
format binary as ""
-
 
Line 21... Line 20...
21
 
20
 
22
SIZE_X equ 512
21
SIZE_X equ 512
23
SIZE_Y equ 512                               ;      /////     I want definitely
22
SIZE_Y equ 512                               ;      /////     I want definitely
24
TIMEOUT equ 10                               ;     ------     say:
23
TIMEOUT equ 10                               ;     ------     say:
Line 37... Line 36...
37
SSE   =   2
36
SSE   =   2
38
SSE2  =   3
37
SSE2  =   3
39
SSE3  =   4
38
SSE3  =   4
40
Ext   =   SSE3           ;Ext={ NON | MMX | SSE | SSE2 | SSE3 }
39
Ext   =   SSE3          ;Ext={ NON | MMX | SSE | SSE2 | SSE3 }
41
; For now correct only SSE2 and SSE3 versions. if you have older CPU
40
 
-
 
41
; For now correct only SSE2 and SSE3 versions. if you have older CPU
42
; use older versions of app. Probably ver 005 will be OK but it need
42
; use older versions of app. Probably ver 005 will be OK but it need
43
; re-edit to support new Kolibri features.
43
; re-edit to support new Kolibri features.
44
 
44
 
Line 45... Line -...
45
; 0 for short names (Menuet-compatible), 1 for long names (Kolibri features)
-
 
46
USE_LFN = 1  ; App is Kolibri only now.
-
 
47
 
-
 
48
use32
45
use32
49
        org    0x0
46
        org    0x0
50
        db     'MENUET01'       ; 8 byte id
47
        db     'MENUET01'       ; 8 byte id
51
        dd     0x01             ; header version
48
        dd     0x01             ; header version
52
        dd     START            ; start of code
49
        dd     START            ; start of code
Line 96... Line 93...
96
                                    ;  to be in <-1.0,1.0>
93
                                    ;  to be in <-1.0,1.0>
97
        call   normalize_all_light_vectors
94
        call   normalize_all_light_vectors
98
        call   copy_lights ; to aligned float
95
        call   copy_lights ; to aligned float
99
        call   init_triangles_normals2
96
        call   init_triangles_normals2
100
        call   init_point_normals
97
 
-
 
98
     if Ext >= SSE2
-
 
99
        call   detect_chunks
-
 
100
        mov    [chunks_number],ecx
-
 
101
        mov    [chunks_ptr],ebx
-
 
102
 
-
 
103
     ;   esi -   tri_ch
-
 
104
     ;   edi -   t_ptr - every vertice index  - pointer to to all triangles
-
 
105
     ;           that have this index
-
 
106
     end if
-
 
107
 
-
 
108
        call   init_point_normals
101
        call   init_envmap2
109
 
-
 
110
        call   init_envmap2
102
        call   init_envmap_cub
111
        call   init_envmap_cub
103
        call   generate_texture2
112
        call   generate_texture2
104
        call   init_sincos_tab
113
        call   init_sincos_tab
105
        call   do_color_buffer   ; intit color_map
114
        call   do_color_buffer   ; intit color_map
106
     if Ext >= SSE3
115
     if Ext >= SSE3
Line 116... Line 125...
116
        mov     eax,1
125
        mov     eax,1
117
        cpuid
126
        cpuid
118
        bt      ecx,0  ; is sse3 on board?
127
        bt      ecx,0  ; is sse3 on board?
119
        jc      @f
128
        jc      @f
120
        mov     [max_dr_flg],12
129
        mov     byte[max_dr_flg],12
121
        mov     [isSSE3],0
130
        mov     [isSSE3],0
122
       @@:
131
       @@:
123
     end if
132
     end if
124
 
133
 
Line -... Line 134...
-
 
134
 
125
still:
135
 still:
126
        cmp    [edit_flag],1
136
        cmp    [edit_flag],1
127
        jne    @f
137
        jne    @f
128
        mov    eax,40         ; set events mask
138
        mov    eax,40         ; set events mask
129
        mov    ebx,1100000000000000000000000100111b
139
        mov    ebx,1100000000000000000000000100111b
Line 826... Line 836...
826
 
836
 
Line -... Line 837...
-
 
837
 
827
 
838
   jmp     still
828
   jmp     still
839
 
829
 
840
 
830
;--------------------------------------------------------------------------------
841
;--------------------------------------------------------------------------------
831
;-------------------------PROCEDURES---------------------------------------------
842
;-------------------------PROCEDURES---------------------------------------------
832
;--------------------------------------------------------------------------------
843
;--------------------------------------------------------------------------------
833
include "flat_cat.inc"
844
include "flat_cat.inc"
834
include "tex_cat.inc"
845
include "tex_cat.inc"
835
include "bump_cat.inc"
846
include "bump_cat.inc"
836
include "3dmath.inc"
847
include "3dmath.inc"
-
 
848
include "grd_line.inc"
837
include "grd_line.inc"
849
include "b_procs.inc"
838
include "b_procs.inc"
850
include "a_procs.inc"
839
include "a_procs.inc"
851
include "chunks.inc"
840
include "grd_cat.inc"
852
include "grd_cat.inc"
841
include "bump_tex.inc"
853
include "bump_tex.inc"
Line 877... Line 889...
877
        movzx  edx,word[size_x_var]
889
        movzx  edx,word[size_x_var]
878
        imul   edx,ecx
890
        imul   edx,ecx
879
        add    ebx,edx
891
        add    ebx,edx
880
        push   ebx
892
        push   ebx
881
        lea    ecx,[ebx*2]
893
        mov    ecx,ebx
-
 
894
        shl     ecx,2
-
 
895
       ; lea    ecx,[ebx*2]
882
        lea    ebx,[ebx*3]
896
        lea    ebx,[ebx*3]
883
 
897
 
Line 884... Line 898...
884
        cmp    [dr_flag],12
898
        cmp    [dr_flag],12
885
        jl    @f
899
        jl    @f
886
        add    ebx,[esp]
900
        add    ebx,[esp]
Line 929... Line 943...
929
 
943
 
930
        check_bar
944
        check_bar
931
        jne    .no_edit
945
        jne    .no_edit
932
        add    ecx,[vertices_index_ptr]
946
        add    ecx,[vertices_index_ptr]
933
        mov    cx,word[ecx]
947
        mov    ecx,[ecx]
-
 
948
      ;  cmp    ecx,-1
Line 934... Line 949...
934
        inc    cx
949
      ;  je     .no_edit
Line 935... Line 950...
935
 
950
 
936
 
951
 
937
        mov    [vertex_edit_no],cx ;if vert_edit_no = 0, no vertex selected
952
        mov    [vertex_edit_no],ecx ;if vert_edit_no = -1, no vertex selected
938
 
953
 
Line 947... Line 962...
947
       ; jne    .no_edit
962
       ; jne    .no_edit
948
       ; add    ecx,[vertices_index_ptr]
963
       ; add    ecx,[vertices_index_ptr]
949
       ; mov    cx,[ecx]
964
       ; mov    cx,[ecx]
950
       ; inc    cx
965
       ; inc    cx
951
        cmp    [vertex_edit_no],0 ; cx  ; vertex number
966
        cmp    [vertex_edit_no],-1 ; cx  ; vertex number
952
        je     .end
967
        je     .end
953
        push   dword[.x_coord]
968
        push   dword[.x_coord]
954
        pop    dword[edit_end_x]
969
        pop    dword[edit_end_x]
955
        jmp    .end
970
        jmp    .end
956
      .not_held:
971
      .not_held:
957
        shr    [mouse_state],16
972
        shr    [mouse_state],16
Line 959... Line 974...
959
        jz     .end
974
        jz     .end
960
        check_bar
975
        check_bar
961
        jne    .end
976
        jne    .end
962
 
977
 
Line 963... Line 978...
963
        movzx  esi,[vertex_edit_no]
978
        mov    esi,[vertex_edit_no]
964
        dec    esi
979
    ;    dec    esi
965
        lea    esi,[esi*3]
980
        lea    esi,[esi*3]
966
        add    esi,esi
981
        add    esi,esi
967
        add    esi,[points_translated_ptr]
982
        add    esi,[points_translated_ptr]
968
        emms
983
        emms
Line 994... Line 1009...
994
        mov     ecx,1
1009
        mov     ecx,1
995
        call    rotary
1010
        call    rotary
996
 
1011
 
Line 997... Line 1012...
997
   ;    inject into vertex list
1012
   ;    inject into vertex list
998
        movzx   edi,[vertex_edit_no]
1013
        mov     edi,[vertex_edit_no]
999
        dec     edi
1014
    ;    dec     edi
1000
        lea     edi,[edi*3]
1015
        lea     edi,[edi*3]
1001
        shl     edi,2
1016
        shl     edi,2
1002
        add     edi,[points_ptr]
1017
        add     edi,[points_ptr]
1003
        lea     esi,[.points_rotated]
1018
        lea     esi,[.points_rotated]
1004
        cld
1019
        cld
Line 1010... Line 1025...
1010
     ;   rep     movsd
1025
     ;   rep     movsd
1011
 
1026
 
Line 1012... Line 1027...
1012
 
1027
 
1013
        mov    dword[edit_end_x],0
1028
        mov    dword[edit_end_x],0
Line 1014... Line 1029...
1014
        mov    [vertex_edit_no],0
1029
        mov    [vertex_edit_no],-1
1015
 
1030
 
1016
      .no_edit:
1031
      .no_edit:
1017
      .end:
1032
      .end:
Line 1053... Line 1068...
1053
    mov      [Zbuffer_ptr],eax
1068
    mov      [Zbuffer_ptr],eax
1054
 
1069
 
Line 1055... Line 1070...
1055
 
1070
 
1056
    mov      ecx,[.temp]
1071
    mov      ecx,[.temp]
1057
    add      ecx,ecx
1072
    shl      ecx,2
1058
    add      ecx,256
1073
    add      ecx,256
1059
    mov      eax,68
1074
    mov      eax,68
1060
    mov      ebx,20
1075
    mov      ebx,20
1061
    mov      edx,[vertices_index_ptr]
1076
    mov      edx,[vertices_index_ptr]
Line 1475... Line 1490...
1475
ret
1490
ret
1476
 
1491
 
Line 1477... Line 1492...
1477
if   Ext >= SSE2
1492
if   Ext >= SSE2
1478
init_point_normals:
1493
init_point_normals:
-
 
1494
;in:
-
 
1495
;    esi - tri_ch
-
 
1496
;    edi - t_ptr
1479
.z equ dword [ebp-8]
1497
.z equ dword [ebp-8]
1480
.y equ dword [ebp-12]
1498
.y equ dword [ebp-12]
1481
.x equ [ebp-16]
1499
.x equ [ebp-16]
1482
.point_number equ dword [ebp-28]
1500
.point_number equ dword [ebp-28]
1483
.hit_faces    equ dword [ebp-32]
1501
.hit_faces    equ dword [ebp-32]
-
 
1502
.t_ptr        equ dword [ebp-36]
-
 
1503
.tri_ch       equ dword [ebp-40]
-
 
1504
.max_val      equ dword [ebp-44]
Line 1484... Line 1505...
1484
 
1505
 
1485
        push      ebp
1506
        push      ebp
1486
        mov       ebp,esp
1507
        mov       ebp,esp
1487
        sub       esp,64
1508
        sub       esp,64
-
 
1509
        and       ebp,-16
-
 
1510
        mov       .t_ptr,edi
-
 
1511
        mov       .tri_ch,esi
-
 
1512
 
-
 
1513
 
-
 
1514
 
-
 
1515
 
-
 
1516
 
-
 
1517
 
-
 
1518
        mov       ecx,[triangles_count_var]
-
 
1519
        shl       ecx,3
-
 
1520
        lea       ecx,[ecx*3]
-
 
1521
        add       ecx,.tri_ch
-
 
1522
        mov       .max_val,ecx
-
 
1523
        xor       edx,edx
-
 
1524
 
-
 
1525
     .lp1:
-
 
1526
        mov       ebx,edx
-
 
1527
        shl       ebx,2
-
 
1528
        add       ebx,.t_ptr
-
 
1529
        mov       esi,[ebx]
-
 
1530
        or        esi,esi
-
 
1531
        jz        .old
-
 
1532
 
-
 
1533
        xorps     xmm1,xmm1
-
 
1534
        xor       ecx,ecx
-
 
1535
     @@:
-
 
1536
        mov       eax,[esi+4] ; eax - tri index
-
 
1537
        mov       ebx,[esi]
-
 
1538
        imul      eax,[i12]
-
 
1539
        add       eax,[triangles_normals_ptr]
-
 
1540
        movups    xmm0,[eax]
-
 
1541
        inc       ecx
-
 
1542
        addps     xmm1,xmm0
-
 
1543
        add       esi,8
-
 
1544
        cmp       esi,.max_val   ; some objects need this check
-
 
1545
        ja        .old           ;old method
-
 
1546
        cmp       ebx,[esi]
-
 
1547
        je        @b
-
 
1548
 
-
 
1549
        cvtsi2ss xmm2,ecx
-
 
1550
        rcpss    xmm2,xmm2
-
 
1551
        shufps   xmm2,xmm2,0
-
 
1552
        mulps    xmm1,xmm2
-
 
1553
        mov      edi,edx
-
 
1554
        imul     edi,[i12]
-
 
1555
        add      edi,[points_normals_ptr]
-
 
1556
        movlps   [edi],xmm1
-
 
1557
        movhlps  xmm1,xmm1
-
 
1558
        movss    [edi+8],xmm1
-
 
1559
        call      normalize_vector
-
 
1560
 
-
 
1561
        inc      edx
-
 
1562
        cmp      edx,[points_count_var]
-
 
1563
        jnz      .lp1
-
 
1564
 
-
 
1565
        jmp      .end
-
 
1566
 
-
 
1567
 
-
 
1568
      .old:
1488
        and       ebp,-16
1569
 
1489
        mov       edi,[points_normals_ptr]
1570
        mov       edi,[points_normals_ptr]
1490
        mov       .point_number,0
1571
        mov       .point_number,edx
1491
    .ipn_loop:
1572
    .ipn_loop:
1492
        movd      xmm0,.point_number
1573
        movd      xmm0,.point_number
1493
        pshufd    xmm0,xmm0,0
1574
        pshufd    xmm0,xmm0,0
1494
        mov       .hit_faces,0
1575
        mov       .hit_faces,0
Line 1545... Line 1626...
1545
        inc       .point_number
1626
        inc       .point_number
1546
        mov       edx,.point_number
1627
        mov       edx,.point_number
1547
        cmp       edx,[points_count_var]
1628
        cmp       edx,[points_count_var]
1548
        jne       .ipn_loop
1629
        jne       .ipn_loop
1549
 
1630
     .end:
-
 
1631
 
-
 
1632
        mov     eax,68
-
 
1633
        mov     ebx,13
-
 
1634
        mov     ecx,.t_ptr
-
 
1635
        int     0x40
-
 
1636
 
-
 
1637
        mov     eax,68
-
 
1638
        mov     ebx,13
-
 
1639
        mov     ecx,.tri_ch
-
 
1640
        int     0x40
-
 
1641
 
-
 
1642
 
-
 
1643
 
-
 
1644
 
Line 1550... Line 1645...
1550
        add       esp,64
1645
        add       esp,64
1551
        pop       ebp
1646
        pop       ebp
1552
ret
1647
ret
1553
else
1648
else
Line 1774... Line 1869...
1774
 
1869
 
Line 1775... Line 1870...
1775
 
1870
 
1776
        emms
1871
        emms
1777
      ;  update translated list  MMX required
1872
      ;  update translated list  MMX required
1778
        cmp     [vertex_edit_no],0
1873
        cmp     [vertex_edit_no],-1
1779
        je      @f
1874
        je      @f
1780
        movzx   eax,[vertex_edit_no]
1875
        mov     eax,[vertex_edit_no]
1781
        dec     eax
1876
      ;  dec     eax
1782
        movd    mm0,[edit_end_x]
1877
        movd    mm0,[edit_end_x]
1783
        psubw   mm0,[edit_start_x]
1878
        psubw   mm0,[edit_start_x]
1784
        lea     eax,[eax*3]
1879
        lea     eax,[eax*3]
1785
        add     eax,eax
1880
        add     eax,eax
Line 2381... Line 2476...
2381
        push    word .zz3
2476
        push    word .zz3
2382
        push    word .zz2
2477
        push    word .zz2
2383
        push    word .zz1
2478
        push    word .zz1
Line 2384... Line -...
2384
 
-
 
2385
        mov    esi, .point_index3      ; tex map coords
2479
 
2386
        shl    esi,2
-
 
2387
        add    esi,[tex_points_ptr]
-
 
2388
        push   dword[esi]
-
 
2389
        mov    esi, .point_index2
-
 
2390
        shl    esi,2
-
 
2391
        add    esi,[tex_points_ptr]
-
 
2392
        push   dword[esi]
-
 
2393
        mov    esi, .point_index1
-
 
2394
        shl    esi,2
-
 
2395
        add    esi,[tex_points_ptr]
-
 
2396
        push   dword[esi]
-
 
2397
 
2480
        fninit
2398
        lea     esi, .point_index1     ; env coords
-
 
2399
        sub     esp,12
2481
        lea     esi, .point_index3     ; env coords
-
 
2482
        mov     edi,esp
2400
        mov     edi,esp
2483
        sub     esp,24
2401
        mov     ecx,3
2484
        mov     ecx,3
2402
      @@:
2485
      @@:
2403
        mov     eax,dword[esi]
-
 
2404
        lea     eax,[eax*3]
2486
        mov     eax,dword[esi]
-
 
2487
        shl     eax,2
-
 
2488
        mov     ebx,eax
-
 
2489
  ;      mov     ebx,eax
-
 
2490
        add     ebx,[tex_points_ptr]
-
 
2491
        mov     ebx,[ebx]
-
 
2492
        mov     [edi-8],ebx
2405
        shl     eax,2
2493
        lea     eax,[eax*3]
2406
        add     eax,[points_normals_rot_ptr]
2494
        add     eax,[points_normals_rot_ptr]
2407
        ; texture x=(rotated point normal -> x * 255)+255
2495
        ; texture x=(rotated point normal -> x * 255)+255
2408
        fld     dword[eax]
2496
        fld     dword[eax]
2409
        fimul   [correct_tex]
2497
        fimul   [correct_tex]
2410
        fiadd   [correct_tex]
2498
        fiadd   [correct_tex]
2411
        fistp   word[edi]
-
 
-
 
2499
        fistp   word[edi-4]
2412
 
2500
        and     word[edi-4],0x7fff   ; some objects need it
2413
        ; texture y=(rotated point normal -> y * 255)+255
2501
        ; texture y=(rotated point normal -> y * 255)+255
2414
        fld     dword[eax+4]
2502
        fld     dword[eax+4]
2415
        fimul   [correct_tex]
2503
        fimul   [correct_tex]
2416
        fiadd   [correct_tex]
2504
        fiadd   [correct_tex]
2417
        fistp   word[edi+2]
2505
        fistp   word[edi-2]
-
 
2506
        and     word[edi-2],0x7fff  ; some objects need it
2418
        and     word[edi+2],0x7fff  ; some objects need it
2507
 
2419
        add     edi,4
2508
        sub     edi,8
2420
        add     esi,4
2509
        sub     esi,4
Line 2421... Line 2510...
2421
        loop    @b
2510
        loop    @b
2422
 
2511
 
2423
        mov     eax, .xx1
2512
        mov     eax, .xx1
Line 2432... Line 2521...
2432
        jmp     .end_draw
2521
        jmp     .end_draw
2433
 
2522
 
Line 2434... Line 2523...
2434
   .bump_tex:
2523
   .bump_tex:
2435
        push   ebp
2524
        push   ebp
2436
        mov    esi, .point_index3      ; tex map coords
-
 
2437
        shl    esi,2
2525
        fninit
2438
        add    esi,[tex_points_ptr]
-
 
2439
        push   dword[esi]
-
 
2440
        mov    esi, .point_index2
-
 
2441
        shl    esi,2
-
 
2442
        add    esi,[tex_points_ptr]
-
 
2443
        push   dword[esi]
-
 
2444
        mov    esi, .point_index1
-
 
2445
        shl    esi,2
-
 
2446
        add    esi,[tex_points_ptr]
-
 
2447
        push   dword[esi]
-
 
Line 2448... Line 2526...
2448
 
2526
 
Line 2449... Line 2527...
2449
        push  dword texmap
2527
        push  dword texmap
Line 2450... Line 2528...
2450
 
2528
 
2451
        push  [Zbuffer_ptr]
2529
        push  [Zbuffer_ptr]
2452
 
2530
 
Line -... Line 2531...
-
 
2531
        push    word .zz3
2453
        push    word .zz3
2532
        push    word .zz2
2454
        push    word .zz2
2533
        push    word .zz1
2455
        push    word .zz1
2534
 
2456
 
2535
 
2457
        lea     esi, .index1x12     ; env coords
2536
        lea     ebx, .point_index1
2458
        sub     esp,12
2537
        sub     esp,36
-
 
2538
        mov     edi,esp
-
 
2539
        mov     ecx,3
-
 
2540
      @@:
-
 
2541
        mov     eax,[ebx]
-
 
2542
        shl     eax,2
-
 
2543
        mov     esi,eax
-
 
2544
        lea     esi,[esi*3]
-
 
2545
        add     eax,[tex_points_ptr]
-
 
2546
        mov     eax,[eax]
2459
        mov     edi,esp
2547
        ror     eax,16
2460
        mov     ecx,3
2548
        mov     [edi],eax
2461
      @@:
2549
        mov     [edi+8],eax
2462
        mov     eax,dword[esi]
2550
 
2463
        add     eax,[points_normals_rot_ptr]
2551
        add     esi,[points_normals_rot_ptr]
2464
        ; texture x=(rotated point normal -> x * 255)+255
2552
        ; texture x=(rotated point normal -> x * 255)+255
2465
        fld     dword[eax]
2553
        fld     dword[esi]
2466
        fimul   [correct_tex]
2554
        fimul   [correct_tex]
2467
        fiadd   [correct_tex]
2555
        fiadd   [correct_tex]
2468
        fistp   word[edi]
2556
        fistp   word[edi+6]             ; env coords
2469
        ; texture y=(rotated point normal -> y * 255)+255
2557
        ; texture y=(rotated point normal -> y * 255)+255
2470
        fld     dword[eax+4]
-
 
2471
        fimul   [correct_tex]
2558
        fld     dword[esi+4]
2472
        fiadd   [correct_tex]
2559
        fimul   [correct_tex]
2473
        fistp   word[edi+2]
2560
        fiadd   [correct_tex]
Line 2474... Line -...
2474
 
-
 
2475
        add     edi,4
-
 
2476
        add     esi,4
-
 
2477
        loop    @b
-
 
2478
 
-
 
2479
        mov    esi, .point_index3      ; bump map coords
-
 
2480
        shl    esi,2
-
 
2481
        add    esi,[tex_points_ptr]
-
 
2482
        push   dword[esi]
-
 
2483
        mov    esi, .point_index2
-
 
2484
        shl    esi,2
-
 
2485
        add    esi,[tex_points_ptr]
-
 
2486
        push   dword[esi]
-
 
2487
        mov    esi, .point_index1
2561
        fistp   word[edi+4]
2488
        shl    esi,2
2562
        add     ebx,4
2489
        add    esi,[tex_points_ptr]
2563
        add     edi,12
2490
        push   dword[esi]
2564
        loop    @b
2491
 
2565
 
Line 2859... Line 2933...
2859
 
2933
 
Line 2860... Line 2934...
2860
ret
2934
ret
Line 2861... Line -...
2861
 
-
 
2862
 
-
 
2863
 
-
 
2864
 
-
 
2865
 
-
 
2866
 
2935
 
-
 
2936
 
2867
 
2937
draw_handlers:
2868
draw_handlers:
2938
 
2869
       ;  in eax - render model
2939
       ;  in eax - render model
2870
       push  ebp
2940
        push  ebp
2871
       mov   ebp,esp
2941
        mov   ebp,esp
2872
 
2942
;        emms
2873
       .counter  equ ebp-16
2943
       .fac         equ  dword[ebp-16]
2874
       .xres3m18 equ ebp-8
2944
       .xplus_scr    equ ebp-8
Line 2875... Line -...
2875
       .xres2m12 equ ebp-12
-
 
2876
       .dr_model equ dword[ebp-4]
-
 
2877
 
2945
       .xplus_index  equ ebp-12
2878
 
-
 
2879
     ; init counter
2946
       .dr_model equ dword[ebp-4]
-
 
2947
 
2880
       sub   esp,12
2948
       sub     esp,16
2881
       push  dword 0
2949
       mov     .dr_model,eax
2882
       mov   .dr_model,eax
2950
 
2883
       movzx eax,word[size_x_var]
2951
       movzx   eax,word[size_x_var]
2884
       cmp    .dr_model,12
2952
       cmp    .dr_model,12
2885
       jge    @f
-
 
2886
       lea   ebx,[eax*3]
-
 
2887
       sub   ebx,18
2953
       jge     @f
2888
       add   eax,eax
2954
       lea    ebx,[eax*3]
2889
       sub   eax,12
2955
       sub    ebx,3*6
2890
       mov   [.xres3m18],ebx
2956
       mov    [.xplus_scr],ebx   ; for scr 1st cause
2891
       mov   [.xres2m12],eax
2957
       mov    .fac,3
2892
       jmp   .f
2958
       jmp    .in_r
2893
     @@:
-
 
2894
       lea   ebx,[eax*4]
-
 
2895
       sub   ebx,4*6
2959
    @@:
2896
       add   eax,eax
2960
       lea    ebx,[eax*4]       ; for scr 2cond cause
2897
       sub   eax,3*4
2961
       sub    ebx,4*6
Line -... Line 2962...
-
 
2962
       mov    [.xplus_scr],ebx
-
 
2963
       mov    .fac,4
-
 
2964
     .in_r:
Line -... Line 2965...
-
 
2965
 
-
 
2966
       lea    ebx,[eax*4]
-
 
2967
       sub    ebx,4*6
-
 
2968
       mov    [.xplus_index],ebx  ; index
-
 
2969
 
-
 
2970
       xor    ecx,ecx
Line 2898... Line -...
2898
       mov   [.xres3m18],ebx
-
 
2899
       mov   [.xres2m12],eax
2971
       mov    eax,4 shl 16 + 4
2900
     .f:
2972
       movd   xmm0,[size_y_var]
2901
 
-
 
2902
 
2973
       movd   xmm1,eax
2903
 
2974
       psubw  xmm0,xmm1
2904
       mov   esi,[points_translated_ptr]
2975
       pshuflw xmm0,xmm0,00000001b
2905
     .loop:
2976
 
2906
       push  esi
2977
     .l:
2907
                                         ; DO culling AT FIRST
2978
       push    ecx
2908
        cmp     [culling_flag],1         ; (if culling_flag = 1)
-
 
2909
        jne     .no_culling
2979
       cmp     [culling_flag],1         ; (if culling_flag = 1)
2910
        mov     edi,[.counter]           ; *********************************
-
 
2911
        lea     edi,[edi*3]
2980
       jne     .no_culling
2912
        shl     edi,2
2981
       mov     edi,ecx           ; *********************************
2913
        add     edi,[points_normals_rot_ptr]
2982
       lea     edi,[edi*3]
2914
        mov     eax,[edi+8]              ; check sign of z coof
-
 
2915
        shr     eax,31
-
 
2916
        cmp     eax,1
-
 
2917
        jnz     .skip
2983
       shl     edi,2
2918
    .no_culling:
2984
       add     edi,[points_normals_rot_ptr]
2919
       mov   eax,[esi]
2985
       bt      dword[edi+8],31
2920
       movzx ebx,ax         ; ebx - x
2986
       jnc     .skip
2921
       shr   eax,16         ; eax - y
2987
     .no_culling:
2922
       cmp   eax,4          ; check if markers not exceedes screen
2988
       mov     esi,ecx
2923
       jle   .skip
2989
       lea     esi,[esi*3]
2924
       cmp   ebx,4
2990
       add     esi,esi
2925
       jle   .skip
2991
       add     esi,[points_translated_ptr]
2926
       movzx edx,word[size_x_var]
2992
       movd    xmm2,[esi]
2927
       sub   edx,4
2993
       movd    xmm3,[esi]
Line -... Line 2994...
-
 
2994
       pcmpgtw xmm2,xmm0
-
 
2995
       pcmpgtw xmm3,xmm1
-
 
2996
       pxor    xmm3,xmm2
-
 
2997
       movd     eax,xmm3
2928
       movzx ecx,word[size_y_var]
2998
       cmp      eax,-1
2929
       sub   ecx,4
-
 
2930
       cmp   ebx,edx
-
 
2931
       jge   .skip
2999
       jne      .skip
2932
       cmp   eax,ecx
3000
 
2933
       jge   .skip
-
 
2934
 
3001
       movzx   eax,word[esi]
2935
       movzx edx,word[size_x_var]
-
 
2936
    ;   sub   ebx,3
-
 
2937
    ;   sub   eax,3
3002
       movzx   ebx,word[esi+2]
2938
       imul  eax,edx
-
 
2939
       add   eax,ebx
3003
       sub     eax,2
2940
       push   eax
-
 
2941
       lea   edi,[eax*3]
-
 
2942
       cmp    .dr_model,12
3004
       sub     ebx,2
2943
       jl    @f
3005
       movzx   edx, word[size_x_var]
2944
       add    edi,[esp]
-
 
2945
      @@:
-
 
2946
       add    esp,4
-
 
2947
       lea   eax,[eax*2]
-
 
2948
       ; draw bar 6x6
3006
       imul    ebx,edx
-
 
3007
       add     ebx,eax
2949
       add   edi,[screen_ptr]
3008
       mov     edi,ebx
2950
       add   eax,dword[vertices_index_ptr]
-
 
2951
 
3009
       imul    ebx,.fac
2952
 
3010
       shl     edi,2
2953
 
3011
       add     ebx,[screen_ptr]
2954
 
-
 
2955
       mov   edx,[.counter]
3012
       add     edi,[vertices_index_ptr]
2956
       mov   ecx,6
3013
       mov     eax,ecx
2957
 
3014
       cld
2958
     .oop:
-
 
2959
       push  ecx
-
 
2960
       mov   ecx,6
-
 
2961
 
-
 
2962
     .do:
-
 
2963
       mov   word[edi],0x0000 ;ax
3015
       mov     ecx,6
2964
       mov   byte[edi+2],0xff   ;al
-
 
2965
       mov   word[eax],dx
-
 
2966
       add   eax,2
3016
    .l2:
2967
       cmp   .dr_model,12
3017
       push    ecx
2968
       jl    @f
-
 
2969
       add   edi,4
3018
       mov     ecx,6       ; draw bar
2970
       loop  .do
3019
    .l1:
2971
       jmp   .ad
3020
       mov     word[ebx],0
2972
      @@:
3021
       mov     byte[ebx+2],0xff
2973
       add   edi,3
-
 
2974
       loop  .do
3022
       stosd
2975
      .ad:
3023
       add     ebx,.fac
2976
       add   edi,[.xres3m18]
3024
       loop    .l1
2977
       add   eax,[.xres2m12]
-
 
2978
       pop   ecx
-
 
2979
       loop  .oop
3025
       add     ebx,[.xplus_scr]
2980
 
3026
       add     edi,[.xplus_index]
Line 2981... Line 3027...
2981
    .skip:
3027
       pop     ecx
2982
       pop   esi
3028
       loop    .l2
2983
       add   esi,6
-
 
2984
       inc   dword[.counter]
3029
     .skip:
Line -... Line 3030...
-
 
3030
       pop      ecx
2985
       mov   ecx,[.counter]
3031
       inc      ecx
2986
       cmp   ecx,[points_count_var]
3032
       cmp      ecx,[points_count_var]
2987
       jng   .loop
3033
       jna      .l
2988
 
3034
 
2989
       mov   esp,ebp
3035
       mov      esp,ebp
Line 3031... Line 3077...
3031
        xor     ebx,ebx
3077
        xor     ebx,ebx
3032
        xor     ebp,ebp
3078
        xor     ebp,ebp
3033
        mov     [points_count_var],ebx
3079
        mov     [points_count_var],ebx
3034
        mov     [triangles_count_var],ebx
3080
        mov     [triangles_count_var],ebx
3035
   if USE_LFN = 0
3081
        mov     esi,[fptr]
3036
        mov     esi,SourceFile
-
 
3037
   else
-
 
3038
        mov     esi,[fptr]
-
 
3039
   end if
3082
 
3040
 
-
 
Line 3041... Line 3083...
3041
        cmp     [esi],word 4D4Dh
3083
        cmp     [esi],word 4D4Dh
3042
        je      @f ;Must be legal .3DS file
3084
        je      @f ;Must be legal .3DS file
3043
        xor     eax,eax
3085
        xor     eax,eax
3044
        ret
3086
        ret
Line 3094... Line 3136...
3094
 
3136
 
Line 3095... Line 3137...
3095
        mov     edx,ecx
3137
        mov     edx,ecx
3096
        add     esi,8
3138
        add     esi,8
3097
     @@:
3139
     @@:
3098
 
-
 
-
 
3140
        lea     ecx,[ecx*3]
-
 
3141
        add     ecx,ecx
3099
        add     ebx,6
3142
        add     ebx,ecx
-
 
3143
        add     ecx,ecx
3100
        add     esi,12
3144
        add     esi,ecx
3101
     ;   dec     ecx
3145
     ;   dec     ecx
3102
        loop     @b
3146
      ;  loop     @b
3103
      @@:
3147
      @@:
Line 3104... Line 3148...
3104
 
3148
 
3105
      @@:
3149
      @@:
3106
        cmp     [esi],word 4120h
3150
        cmp     [esi],word 4120h
Line 3112... Line 3156...
3112
        add     [triangles_count_var],ecx
3156
        add     [triangles_count_var],ecx
3113
        add     esi,8
3157
        add     esi,8
3114
 
3158
 
Line 3115... Line 3159...
3115
      @@:
3159
      @@:
-
 
3160
        shl     ecx,3
3116
        add     esi,8
3161
        add     esi,ecx
3117
        dec     ecx
3162
       ; dec     ecx
3118
        jnz     @b
3163
       ; jnz     @b
-
 
3164
       ; loop    @b
3119
;        xor     ecx,ecx
3165
;        xor     ecx,ecx
3120
        add     ebp,edx
3166
        add     ebp,edx
3121
        jmp     .find4k
3167
        jmp     .find4k
3122
        mov     eax,-1 ;<---mark if OK
3168
        mov     eax,-1 ;<---mark if OK
3123
      .exit:
3169
      .exit:
Line 3196... Line 3242...
3196
        pop     edi
3242
        pop     edi
3197
 
3243
 
Line 3198... Line 3244...
3198
        add     ebx,6
3244
        add     ebx,6
3199
        add     esi,12
3245
        add     esi,12
3200
        dec     ecx
3246
       ; dec     ecx
3201
        jnz     @b
3247
       ; jnz     @b
-
 
3248
        loop    @b
3202
      @@:
3249
      @@:
3203
  ;      mov     dword[points+ebx],-1
3250
  ;      mov     dword[points+ebx],-1
3204
        push    edi
3251
        push    edi
3205
        mov     edi,[points_ptr]
3252
        mov     edi,[points_ptr]
3206
        mov     dword[edi+ebx*2],-1        ; end mark (not always in use)
3253
        mov     dword[edi+ebx*2],-1        ; end mark (not always in use)
Line 3225... Line 3272...
3225
        add     dword[edi-12],ebp
3272
        add     dword[edi-12],ebp
3226
        add     dword[edi-8],ebp
3273
        add     dword[edi-8],ebp
3227
        add     dword[edi-4],ebp
3274
        add     dword[edi-4],ebp
3228
        add     esi,8
3275
        add     esi,8
3229
        dec     ecx
3276
    ;    dec     ecx
3230
        jnz     @b
3277
    ;    jnz     @b
3231
        add     ebp,edx
3278
        loop    @b
-
 
3279
        add     ebp,edx
3232
        jmp     .find4k
3280
        jmp     .find4k
3233
        mov     eax,-1 ;<---mark if OK
3281
        mov     eax,-1 ;<---mark if OK
3234
      .exit:
3282
      .exit:
3235
        mov     dword[edi],-1
3283
        mov     dword[edi],-1
3236
ret
3284
ret
3237
alloc_mem_for_tp:
3285
 
-
 
3286
 
-
 
3287
alloc_mem_for_tp:
3238
        mov     eax, 68
3288
        mov     eax, 68
3239
        cmp     [re_alloc_flag],1
3289
        cmp     [re_alloc_flag],1
3240
        jz      @f
3290
        jz      @f
3241
        mov     ebx, 12
3291
        mov     ebx, 12
3242
        jmp     .alloc
3292
        jmp     .alloc
Line 3263... Line 3313...
3263
                                            ; ststic  memory
3313
                                            ; ststic  memory
Line 3264... Line 3314...
3264
 
3314
 
3265
        mov     eax, 68
3315
        mov     eax, 68
3266
        mov     ecx, [triangles_count_var]
3316
        mov     ecx, [triangles_count_var]
3267
        lea     ecx, [3+ecx*3]
3317
        lea     ecx, [6+ecx*3]
3268
        shl     ecx, 2
3318
        shl     ecx, 2
3269
        mov     edx,[triangles_normals_ptr]
3319
        mov     edx,[triangles_normals_ptr]
3270
        int     0x40                           ;  -> allocate memory for triangles normals
3320
        int     0x40                           ;  -> allocate memory for triangles normals
Line 3271... Line 3321...
3271
        mov     [triangles_normals_ptr], eax   ;  -> eax = pointer to allocated mem
3321
        mov     [triangles_normals_ptr], eax   ;  -> eax = pointer to allocated mem
3272
 
3322
 
3273
 
3323
 
3274
        mov     eax, 68
3324
        mov     eax, 68
3275
        mov     ecx, [points_count_var]
3325
        mov     ecx, [points_count_var]
3276
        lea     ecx,[3+ecx*3]
3326
        lea     ecx,[6+ecx*3]
3277
        shl     ecx, 2
3327
        shl     ecx, 2
Line 3278... Line 3328...
3278
        mov     edx,[points_normals_ptr]
3328
        mov     edx,[points_normals_ptr]
3279
        int     0x40
3329
        int     0x40
3280
        mov     [points_normals_ptr], eax
3330
        mov     [points_normals_ptr], eax
3281
 
3331
 
3282
 
3332
 
3283
        mov     eax, 68
3333
        mov     eax, 68
3284
    ;    mov     ebx, 12
3334
    ;    mov     ebx, 12
3285
        mov     ecx, [points_count_var]
3335
        mov     ecx, [points_count_var]
Line 3286... Line 3336...
3286
        lea     ecx,[3+ecx*3]
3336
        lea     ecx,[10+ecx*3]
-
 
3337
        shl     ecx, 2
3287
        shl     ecx, 2
3338
        mov     edx,[points_normals_rot_ptr]
3288
        mov     edx,[points_normals_rot_ptr]
3339
        int     0x40
3289
        int     0x40
3340
        mov     [points_normals_rot_ptr], eax
Line 3290... Line 3341...
3290
        mov     [points_normals_rot_ptr], eax
3341
 
Line 3302... Line 3353...
3302
        mov     eax, 68
3353
        mov     eax, 68
3303
        mov     ebx, 12
3354
        mov     ebx, 12
3304
        mov     ecx, [points_count_var]
3355
        mov     ecx, [points_count_var]
3305
        shl     ecx,2
3356
        shl     ecx,2
-
 
3357
        add     ecx,32
3306
        mov     edx,[tex_points_ptr]
3358
        mov     edx,[tex_points_ptr]
3307
        int     0x40
3359
        int     0x40
3308
        mov     [tex_points_ptr], eax
3360
        mov     [tex_points_ptr], eax
Line 3309... Line 3361...
3309
 
3361
 
3310
        mov     eax, 68
3362
        mov     eax, 68
3311
        mov     ecx, [points_count_var]
3363
        mov     ecx, [points_count_var]
3312
        inc     ecx
3364
        add     ecx,10
3313
        shl     ecx, 3
3365
        shl     ecx, 3
3314
        mov     edx,[points_translated_ptr]
3366
        mov     edx,[points_translated_ptr]
3315
        int     0x40
3367
        int     0x40
3316
        mov     [points_translated_ptr], eax
3368
        mov     [points_translated_ptr], eax
Line 3415... Line 3467...
3415
        mov     eax,13
3467
        mov     eax,13
3416
        mov     bx,[size_x_var]
3468
        mov     bx,[size_x_var]
3417
        shl     ebx,16
3469
        shl     ebx,16
3418
        add     ebx,120*65536+70   ; [x start] *65536 + [y start]
3470
        add     ebx,120*65536+70   ; [x start] *65536 + [y start]
3419
        mov     ecx,30 shl 16 + 100
3471
        mov     ecx,30 shl 16 + 150
3420
        xor     edx,edx
3472
        xor     edx,edx
3421
        int     0x40
3473
        int     0x40
3422
 
3474
 
Line 3423... Line 3475...
3423
 
3475
 
Line 3465... Line 3517...
3465
        mov  esi,10                    ; text length
3517
        mov  esi,10                    ; text length
3466
        int  40h
3518
        int  40h
3467
        pop  esi
3519
        pop  esi
3468
        add  esi,4
3520
        add  esi,4
3469
        cmp  esi,12
3521
        cmp  esi,16
3470
        jnz  .nxxx
3522
        jnz  .nxxx
3471
ret
3523
ret
3472
;   *********************************************
3524
;   *********************************************
3473
;   *******  WINDOW DEFINITIONS AND DRAW ********
3525
;   *******  WINDOW DEFINITIONS AND DRAW ********
3474
;   *********************************************
3526
;   *********************************************
3475
    draw_window:
3527
    draw_window: