Subversion Repositories Kolibri OS

Rev

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