Subversion Repositories Kolibri OS

Rev

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

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