Subversion Repositories Kolibri OS

Rev

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

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