Subversion Repositories Kolibri OS

Rev

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

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