Subversion Repositories Kolibri OS

Rev

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

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