Subversion Repositories Kolibri OS

Rev

Rev 8014 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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