Subversion Repositories Kolibri OS

Rev

Rev 7280 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7280 Rev 8014
Line 10... Line 10...
10
;        add esi,511*3
10
;        add esi,511*3
11
;        add eax,3
11
;        add eax,3
12
;        cmp eax,511*3
12
;        cmp eax,511*3
13
;        jl  @b
13
;        jl  @b
14
;ret
14
;ret
15
init_envmap_cub:	 ; create 512x512 env map
15
init_envmap_cub:         ; create 512x512 env map
16
.temp equ word [ebp-2]
16
.temp equ word [ebp-2]
17
	 push	  ebp
17
         push     ebp
18
	 mov	  ebp,esp
18
         mov      ebp,esp
19
	 sub	  esp,2
19
         sub      esp,2
20
	 mov	  edi,envmap_cub
20
         mov      edi,envmap_cub
21
	 fninit
21
         fninit
Line 22... Line 22...
22
 
22
 
23
	 mov	  cx,-256
23
         mov      cx,-256
24
    .ie_hor:
24
    .ie_hor:
25
	 mov	  .temp,cx
25
         mov      .temp,cx
26
	 fild	  .temp
26
         fild     .temp
27
	 fabs
27
         fabs
28
  ;      fmul     st,st0
28
  ;      fmul     st,st0
29
  ;      fsqrt
29
  ;      fsqrt
30
	 mov	  .temp,255
30
         mov      .temp,255
31
	 fisubr   .temp
31
         fisubr   .temp
32
	 fmul	  [env_const]
32
         fmul     [env_const]
33
	 fistp	  .temp
33
         fistp    .temp
34
	 mov	  ax,.temp
34
         mov      ax,.temp
35
 
35
 
36
	 or	 ax,ax
36
         or      ax,ax
37
	 jge	 .ie_ok1
37
         jge     .ie_ok1
38
	 xor	 ax,ax
38
         xor     ax,ax
39
	 jmp	 .ie_ok2
39
         jmp     .ie_ok2
40
  .ie_ok1:
40
  .ie_ok1:
41
	 cmp	 ax,255
41
         cmp     ax,255
42
	 jle	 .ie_ok2
42
         jle     .ie_ok2
43
	 mov	 ax,255
43
         mov     ax,255
44
  .ie_ok2:
44
  .ie_ok2:
45
	 stosb
45
         stosb
46
	 stosb
46
         stosb
47
	 stosb
47
         stosb
48
 
48
 
49
	 inc	 cx
49
         inc     cx
50
	 cmp	 cx,256
50
         cmp     cx,256
Line 51... Line 51...
51
	 jne	 .ie_hor
51
         jne     .ie_hor
52
 
52
 
53
	 mov	 esp,ebp
53
         mov     esp,ebp
Line 54... Line 54...
54
	 pop	 ebp
54
         pop     ebp
55
ret
55
ret
56
 
56
 
57
calc_one_col:
57
calc_one_col:
58
; procedure don't save registers !!!
58
; procedure don't save registers !!!
59
; in -   st - dot_product
59
; in -   st - dot_product
60
;        stack - other parameters
60
;        stack - other parameters
61
; out - eax - 0x00rrggbb
61
; out - eax - 0x00rrggbb
62
.dot_prd   equ dword[ebp+4]	      ; dot product   - cos x  - not now
62
.dot_prd   equ dword[ebp+4]           ; dot product   - cos x  - not now
63
.min_col_r equ word[ebp+8]	      ; minimum color - ambient
63
.min_col_r equ word[ebp+8]            ; minimum color - ambient
64
.min_col_g equ word[ebp+10]
64
.min_col_g equ word[ebp+10]
65
.min_col_b equ word[ebp+12]
65
.min_col_b equ word[ebp+12]
66
.max_col_r equ word[ebp+14]	      ; maximum color - specular
66
.max_col_r equ word[ebp+14]           ; maximum color - specular
67
.max_col_g equ word[ebp+16]
67
.max_col_g equ word[ebp+16]
68
.max_col_b equ word[ebp+18]
68
.max_col_b equ word[ebp+18]
69
.org_col_r equ word[ebp+20]	      ; orginal color - diffuse
69
.org_col_r equ word[ebp+20]           ; orginal color - diffuse
70
.org_col_g equ word[ebp+22]
70
.org_col_g equ word[ebp+22]
71
.org_col_b equ word[ebp+24]
71
.org_col_b equ word[ebp+24]
72
.n	   equ word[ebp+26]	      ; shines - not implemented
72
.n         equ word[ebp+26]           ; shines - not implemented
73
.temp	   equ word[ebp-2]
73
.temp      equ word[ebp-2]
74
.color_sum_r equ dword[ebp-6]
74
.color_sum_r equ dword[ebp-6]
75
.color_sum_g equ dword[ebp-10]
75
.color_sum_g equ dword[ebp-10]
76
.color_sum_b equ dword[ebp-14]
76
.color_sum_b equ dword[ebp-14]
Line 77... Line 77...
77
; color = ambient+cos(x)*diffuse+(cos(x)^n)*specular
77
; color = ambient+cos(x)*diffuse+(cos(x)^n)*specular
78
	 mov	 ebp,esp
78
         mov     ebp,esp
79
	 sub	 esp,14
79
         sub     esp,14
80
 
80
 
81
	 mov	  ax,.min_col_r
81
         mov      ax,.min_col_r
82
	 add	  ax,.max_col_r
82
         add      ax,.max_col_r
83
	 add	  ax,.org_col_r
83
         add      ax,.org_col_r
84
	 cwde
84
         cwde
85
	 mov	  .color_sum_r,eax
85
         mov      .color_sum_r,eax
86
 
86
 
87
	 mov	  ax,.min_col_g
87
         mov      ax,.min_col_g
88
	 add	  ax,.max_col_g
88
         add      ax,.max_col_g
89
	 add	  ax,.org_col_g
89
         add      ax,.org_col_g
90
	 cwde
90
         cwde
91
	 mov	  .color_sum_g,eax
91
         mov      .color_sum_g,eax
92
 
92
 
93
	 mov	  ax,.min_col_b
93
         mov      ax,.min_col_b
Line 94... Line 94...
94
	 add	  ax,.max_col_b
94
         add      ax,.max_col_b
95
	 add	  ax,.org_col_b
95
         add      ax,.org_col_b
96
	 cwde
96
         cwde
Line 104... Line 104...
104
       ;  fyl2x                     ;
104
       ;  fyl2x                     ;
105
       ;  f2xm1
105
       ;  f2xm1
106
       ;  fld1
106
       ;  fld1
107
       ;  faddp        ; st =  dot_product ^ n
107
       ;  faddp        ; st =  dot_product ^ n
Line 108... Line 108...
108
 
108
 
109
	 fld	 st	       ; copy dot pr
109
         fld     st            ; copy dot pr
110
	 fmul	 st,st0
110
         fmul    st,st0
111
	 fmul	 st,st0
111
         fmul    st,st0
112
	 fmul	 st,st0
112
         fmul    st,st0
113
	 cmp	 .n,255 	   ; .n = 255 -> spot light
113
         cmp     .n,255            ; .n = 255 -> spot light
114
	 jne	 @f
114
         jne     @f
115
	 fmul	 st,st0
115
         fmul    st,st0
116
	 fmul	 st,st0
116
         fmul    st,st0
117
	 fmul	 st,st0
117
         fmul    st,st0
118
      @@:
118
      @@:
119
	 fld	 st	       ; st0=st1=dot_pr^n, st2=dot_pr
119
         fld     st            ; st0=st1=dot_pr^n, st2=dot_pr
120
	 fimul	 .max_col_b
120
         fimul   .max_col_b
121
	 fild	 .org_col_b
121
         fild    .org_col_b
122
	 fmul	 st,st3
122
         fmul    st,st3
123
	 faddp		       ; st0=first piece of col, st1=dot_pr^n..
123
         faddp                 ; st0=first piece of col, st1=dot_pr^n..
124
	 fiadd	 .min_col_b
124
         fiadd   .min_col_b
125
	 fimul	 .max_col_b
125
         fimul   .max_col_b
126
	 fidiv	 .color_sum_b
126
         fidiv   .color_sum_b
127
	 fistp	 .temp
127
         fistp   .temp
128
	 movzx	 eax,.temp
128
         movzx   eax,.temp
129
	 shl	 eax,16
129
         shl     eax,16
130
 
130
 
131
	 fld	 st
131
         fld     st
132
	 fimul	 .max_col_g
132
         fimul   .max_col_g
133
	 fild	 .org_col_g
133
         fild    .org_col_g
134
	 fmul	 st,st3
134
         fmul    st,st3
135
	 faddp
135
         faddp
136
	 fiadd	 .min_col_g
136
         fiadd   .min_col_g
137
	 fimul	 .max_col_g
137
         fimul   .max_col_g
138
	 fidiv	 .color_sum_g
138
         fidiv   .color_sum_g
139
	 fistp	 .temp
139
         fistp   .temp
140
	 mov	 ax,.temp
140
         mov     ax,.temp
141
	 mov	 ah,al
141
         mov     ah,al
142
	 shl	 eax,8
142
         shl     eax,8
143
 
143
 
144
	 fimul	 .max_col_r
144
         fimul   .max_col_r
145
	 fild	 .org_col_r
145
         fild    .org_col_r
146
	 fmulp	 st2,st
146
         fmulp   st2,st
147
	 faddp
147
         faddp
148
	 fiadd	 .min_col_r
148
         fiadd   .min_col_r
149
	 fimul	 .max_col_r
149
         fimul   .max_col_r
150
	 fidiv	 .color_sum_r
150
         fidiv   .color_sum_r
151
	 fistp	 .temp
151
         fistp   .temp
152
	 mov	 ax,.temp	   ;eax -  0xbbgg00rr
152
         mov     ax,.temp          ;eax -  0xbbgg00rr
153
     ;   mov     ah,al
153
     ;   mov     ah,al
154
	 ror	 eax,16
154
         ror     eax,16
155
	 xchg	 al,ah		   ; eax - 0x00rrggbb
155
         xchg    al,ah             ; eax - 0x00rrggbb
156
	 mov	 esp,ebp
156
         mov     esp,ebp
Line 157... Line 157...
157
ret 24
157
ret 24
158
 
158
 
Line 159... Line 159...
159
calc_bumpmap:		 ; calculate random bumpmap
159
calc_bumpmap:            ; calculate random bumpmap
Line 160... Line 160...
160
;--------------in edi _ pointer to TEX_X x TEX_Y bumpmap
160
;--------------in edi _ pointer to TEX_X x TEX_Y bumpmap
161
 
161
 
162
	 push	 edi
162
         push    edi
163
 
163
 
164
	 cmp	 [bumps_flag],0
164
         cmp     [bumps_flag],0
165
	 je	 .random_bump_map
165
         je      .random_bump_map
166
	 ; else bumps according to texture
166
         ; else bumps according to texture
167
	 mov	 esi,texmap
167
         mov     esi,texmap
168
	 mov	 ecx,TEXTURE_SIZE
168
         mov     ecx,TEXTURE_SIZE
169
      @@:
169
      @@:
170
	 movzx	 ax,byte[esi]
170
         movzx   ax,byte[esi]
171
	 movzx	 bx,byte[esi+1]
171
         movzx   bx,byte[esi+1]
172
	 movzx	 dx,byte[esi+2]
172
         movzx   dx,byte[esi+2]
173
	 add	 ax,bx
173
         add     ax,bx
174
	 add	 ax,dx
174
         add     ax,dx
175
	 cwd
175
         cwd
176
	 div	 [i3]
176
         div     [i3]
177
	 stosb
177
         stosb
178
	 add	 esi,3
178
         add     esi,3
179
	 loop	 @b
179
         loop    @b
180
	 jmp	 .blur_map
180
         jmp     .blur_map
181
;         push    ecx
181
;         push    ecx
Line 187... Line 187...
187
;         rep     stosd
187
;         rep     stosd
188
;         pop     ecx
188
;         pop     ecx
189
;         loop    @b
189
;         loop    @b
190
  .random_bump_map:
190
  .random_bump_map:
Line 191... Line 191...
191
 
191
 
192
	 mov	 ecx,TEXTURE_SIZE
192
         mov     ecx,TEXTURE_SIZE
193
      @@:
193
      @@:
194
	 push	 ecx
194
         push    ecx
195
	 xor	 ecx,ecx
195
         xor     ecx,ecx
196
	 mov	 edx,255
196
         mov     edx,255
197
	 call	 random
197
         call    random
198
	 stosb
198
         stosb
199
	 pop	ecx
199
         pop    ecx
Line 200... Line 200...
200
	 loop	@b
200
         loop   @b
201
 
201
 
202
      .blur_map:
202
      .blur_map:
203
	 pop	edi
203
         pop    edi
204
	 movzx	ecx,[bumps_deep_flag]
204
         movzx  ecx,[bumps_deep_flag]
205
	 inc	cx
205
         inc    cx
206
      .blur:
206
      .blur:
207
	 xor	esi,esi
207
         xor    esi,esi
208
	 mov	edx,TEXTURE_SIZE
208
         mov    edx,TEXTURE_SIZE
209
	 xor	eax,eax
209
         xor    eax,eax
210
	 xor	ebx,ebx
210
         xor    ebx,ebx
211
      @@:
211
      @@:
212
	 mov	ebp,esi
212
         mov    ebp,esi
213
	 dec	ebp
213
         dec    ebp
214
	 and	ebp,TEXTURE_SIZE
214
         and    ebp,TEXTURE_SIZE
215
	 mov	al,byte[ebp+edi]
215
         mov    al,byte[ebp+edi]
216
 
216
 
217
	 mov	ebp,esi
217
         mov    ebp,esi
218
	 inc	ebp
218
         inc    ebp
219
	 and	ebp,TEXTURE_SIZE
219
         and    ebp,TEXTURE_SIZE
220
	 mov	bl,byte[ebp+edi]
220
         mov    bl,byte[ebp+edi]
221
	 add	eax,ebx
221
         add    eax,ebx
222
 
222
 
223
	 mov	ebp,esi
223
         mov    ebp,esi
224
	 sub	ebp,TEX_X
224
         sub    ebp,TEX_X
225
	 and	ebp,TEXTURE_SIZE
225
         and    ebp,TEXTURE_SIZE
226
	 mov	bl,byte[ebp+edi]
226
         mov    bl,byte[ebp+edi]
227
	 add	eax,ebx
227
         add    eax,ebx
228
 
228
 
229
	 mov	ebp,esi
229
         mov    ebp,esi
230
	 add	ebp,TEX_X
230
         add    ebp,TEX_X
231
	 and	ebp,TEXTURE_SIZE
231
         and    ebp,TEXTURE_SIZE
232
	 mov	bl,byte[ebp+edi]
232
         mov    bl,byte[ebp+edi]
233
	 add	eax,ebx
233
         add    eax,ebx
234
 
234
 
235
	 shr	eax,2
235
         shr    eax,2
236
	 mov	byte[esi+edi],al
236
         mov    byte[esi+edi],al
237
 
237
 
238
	 inc	esi
238
         inc    esi
Line 239... Line 239...
239
	 dec	edx
239
         dec    edx
240
	 jnz	@b
240
         jnz    @b
241
 
241
 
242
	 loop	.blur
242
         loop   .blur
243
ret
243
ret
244
random:
244
random:
245
;  in  - ecx - min
245
;  in  - ecx - min
246
;        edx - max
246
;        edx - max
247
;  out - eax - random number
247
;  out - eax - random number
248
	 mov	bx,[rand_seed]
248
         mov    bx,[rand_seed]
249
	 add	bx,0x9248
249
         add    bx,0x9248
250
	 ror	bx,3
250
         ror    bx,3
251
	 mov	[rand_seed],bx
251
         mov    [rand_seed],bx
252
 
252
 
253
	 mov	ax,dx
253
         mov    ax,dx
254
	 sub	ax,cx
254
         sub    ax,cx
255
	 mul	bx
255
         mul    bx
256
	 mov	ax,dx
256
         mov    ax,dx
Line 257... Line 257...
257
	 add	ax,cx
257
         add    ax,cx
258
	 cwde
258
         cwde
259
ret
259
ret
260
 
260
 
261
optimize_object1:	 ; setting   point (0,0,0) in center of object
261
optimize_object1:        ; setting   point (0,0,0) in center of object
262
			 ; recalculate all coords , scale object,
262
                         ; recalculate all coords , scale object,
263
			 ;the coords in <-1.0,1.0>
263
                         ;the coords in <-1.0,1.0>
264
;in :  real_points - table filled of real float dd coordinates (x,y,z), end mark  dd -1
264
;in :  real_points - table filled of real float dd coordinates (x,y,z), end mark  dd -1
Line 270... Line 270...
270
.max   equ dword[ebp-4]
270
.max   equ dword[ebp-4]
271
.min   equ dword[ebp-8]
271
.min   equ dword[ebp-8]
272
.maxxx equ dword[ebp-12]
272
.maxxx equ dword[ebp-12]
273
.center equ dword[ebp-16]
273
.center equ dword[ebp-16]
Line 274... Line 274...
274
 
274
 
275
	mov	ebp,esp
275
        mov     ebp,esp
276
	sub	esp,16
276
        sub     esp,16
277
	fninit
277
        fninit
278
	mov	.maxxx,0
278
        mov     .maxxx,0
279
	mov	ecx,3
279
        mov     ecx,3
280
	xor	ebx,ebx 	; ebx - x,y,z coord in real_points list
280
        xor     ebx,ebx         ; ebx - x,y,z coord in real_points list
281
    .next_c:			; max/min/center x,y,z
281
    .next_c:                    ; max/min/center x,y,z
282
	mov	edi,[points_ptr]      ; in real_point list minimum two points
282
        mov     edi,[points_ptr]      ; in real_point list minimum two points
283
	mov	dx,[points_count_var]
283
        mov     edx,[points_count_var]
284
	fld	dword[edi+ebx]
284
        fld     dword[edi+ebx]
285
	fst	.max
285
        fst     .max
286
	fstp	.min
286
        fstp    .min
287
	add	edi,12
287
        add     edi,12
288
	dec	dx
288
        dec     edx
289
    .next_coord:	       ; next coord from real_points list
289
    .next_coord:               ; next coord from real_points list
290
	fld	dword [edi+ebx]   ; real_points -> x,y,z
290
        fld     dword [edi+ebx]   ; real_points -> x,y,z
291
	fcom	.max	; max_x,y,z
291
        fcom    .max    ; max_x,y,z
292
	fstsw	ax
292
        fstsw   ax
293
	sahf
293
        sahf
294
	jbe	@f	       ; jmp less equal
294
        jbe     @f             ; jmp less equal
295
	fstp	.max	; new max_x,y,z
295
        fstp    .max    ; new max_x,y,z
296
	jmp	.end_coords
296
        jmp     .end_coords
297
     @@:
297
     @@:
298
	fcom	.min	; min_x,y,z
298
        fcom    .min    ; min_x,y,z
299
	fstsw	ax
299
        fstsw   ax
300
	sahf
300
        sahf
301
	jnbe	@f		; jmp greater
301
        jnbe    @f              ; jmp greater
302
	fst	.min   ; new min_x
302
        fst     .min   ; new min_x
303
    @@:
303
    @@:
304
	ffree	st
304
        ffree   st
305
    .end_coords:
305
    .end_coords:
306
	add	edi,12
306
        add     edi,12
307
   ;     cmp     dword[edi],-1   ; cmp with end mark
307
   ;     cmp     dword[edi],-1   ; cmp with end mark
308
	dec	 dx
308
        dec      edx
309
	jnz	.next_coord
309
        jnz     .next_coord
310
	; ok after this we found max_coord and min_coord
310
        ; ok after this we found max_coord and min_coord
311
	fld	.max	      ; find center point
311
        fld     .max          ; find center point
312
	fadd	.min
312
        fadd    .min
313
	fld1
313
        fld1
314
	fld1
314
        fld1
315
	faddp
315
        faddp
316
	fdivp	st1,st	      ; st0 - center coord
316
        fdivp   st1,st        ; st0 - center coord
317
	fstp	.center
317
        fstp    .center
318
 
318
 
319
	fld	.max
319
        fld     .max
320
	fsub	.center      ; st = .max - .center
320
        fsub    .center      ; st = .max - .center
321
	fcom	.maxxx	    ; maximum of all .max
321
        fcom    .maxxx      ; maximum of all .max
322
	fstsw	ax
322
        fstsw   ax
323
	sahf
323
        sahf
324
	jbe	@f	    ; jmp lower
324
        jbe     @f          ; jmp lower
325
	fst	.maxxx	    ; new maxx
325
        fst     .maxxx      ; new maxx
326
    @@:
326
    @@:
327
	ffree	st
327
        ffree   st
328
	mov	edi,[points_ptr]
328
        mov     edi,[points_ptr]
329
	mov	dx,[points_count_var]	; substraction all coords - center point
329
        mov     edx,[points_count_var]   ; substraction all coords - center point
330
    @@:
330
    @@:
331
	fld	dword[edi+ebx]
331
        fld     dword[edi+ebx]
332
	fsub	.center
332
        fsub    .center
333
	fstp	dword[edi+ebx]
333
        fstp    dword[edi+ebx]
334
	add	edi,12
334
        add     edi,12
335
;        cmp     dword[edi],-1
335
;        cmp     dword[edi],-1
336
;        jne     @b
336
;        jne     @b
337
	dec	 dx
337
        dec      edx
Line 338... Line 338...
338
	jnz	 @b
338
        jnz      @b
339
 
339
 
340
	add	ebx,4		    ; ebx - x,y,z cooficientes in list real_points
340
        add     ebx,4               ; ebx - x,y,z cooficientes in list real_points
341
	dec	ecx
341
        dec     ecx
342
	jnz	.next_c
342
        jnz     .next_c
343
 
343
 
344
	fld	.maxxx
344
        fld     .maxxx
345
	mov	edi,[points_ptr]   ; create all coords in <-1.0,1.0>
345
        mov     edi,[points_ptr]   ; create all coords in <-1.0,1.0>
346
	movzx	ecx,[points_count_var]
346
        mov     ecx,[points_count_var]
347
     @@:
347
     @@:
348
	fld	dword[edi]
348
        fld     dword[edi]
349
	fdiv	.maxxx
349
        fdiv    .maxxx
350
	fstp	dword[edi]
350
        fstp    dword[edi]
351
	fld	dword[edi+4]
351
        fld     dword[edi+4]
352
	fdiv	.maxxx
352
        fdiv    .maxxx
353
	fstp	dword[edi+4]
353
        fstp    dword[edi+4]
354
	fld	dword[edi+8]
354
        fld     dword[edi+8]
355
	fdiv	.maxxx
355
        fdiv    .maxxx
356
	fstp	dword[edi+8]
356
        fstp    dword[edi+8]
357
	add	edi,12
357
        add     edi,12
Line 358... Line 358...
358
	loop	@b
358
        loop    @b
Line 359... Line 359...
359
     ;   cmp     dword[edi],-1
359
     ;   cmp     dword[edi],-1
360
 
360
 
Line 361... Line 361...
361
     ;   jne     @b
361
     ;   jne     @b
362
 
362
 
363
	mov	esp,ebp
363
        mov     esp,ebp
364
ret
364
ret
365
 
365
 
366
generate_object:	 ; generate node
366
generate_object:         ; generate node
367
.N	   equ 32
367
.N         equ 32
368
.x	   equ word[ebp-2]
368
.x         equ word[ebp-2]
369
.Ndiv2	   equ word[ebp-10]
369
.Ndiv2     equ word[ebp-10]
370
.MthickSqr equ dword[ebp-14]   ; diameter^2
370
.MthickSqr equ dword[ebp-14]   ; diameter^2
371
.temp	   equ dword[ebp-18]   ; variable for x <-1;1>
371
.temp      equ dword[ebp-18]   ; variable for x <-1;1>
Line 372... Line 372...
372
.Hthick    equ dword[ebp-22]
372
.Hthick    equ dword[ebp-22]
373
.cos_temp  equ dword[ebp-26]
373
.cos_temp  equ dword[ebp-26]
Line 374... Line 374...
374
.next_const  equ dword[ebp-30]
374
.next_const  equ dword[ebp-30]
375
.a	     equ dword[ebp-34]
375
.a           equ dword[ebp-34]
376
.Pi2	     equ       ebp-38
376
.Pi2         equ       ebp-38
377
 
377
 
378
 
378
 
379
 
379
 
380
       mov	ebp,esp
380
       mov      ebp,esp
381
       sub	esp,42
381
       sub      esp,42
382
 
382
 
383
       mov	.Ndiv2,.N/2
383
       mov      .Ndiv2,.N/2
384
       fninit
384
       fninit
385
       fldpi
385
       fldpi
Line 386... Line 386...
386
       fadd	st,st
386
       fadd     st,st
Line 387... Line 387...
387
       fst	dword[.Pi2]
387
       fst      dword[.Pi2]
388
       fidiv	.Ndiv2
388
       fidiv    .Ndiv2
389
       fst	.a			 ; .Ndiv2*.a=2Pi => .a=2pi/.Ndiv2
389
       fst      .a                       ; .Ndiv2*.a=2Pi => .a=2pi/.Ndiv2
390
 
390
 
391
       fld	[.Mthick]	    ; inside diameter, (outside daiameter = 1)
391
       fld      [.Mthick]           ; inside diameter, (outside daiameter = 1)
Line 392... Line 392...
392
       fmul	st,st0
392
       fmul     st,st0
393
       fstp	.MthickSqr
393
       fstp     .MthickSqr
Line 394... Line 394...
394
       fld1
394
       fld1
395
 
395
 
396
       fsub	 [.Mthick]
396
       fsub      [.Mthick]
397
 
397
 
398
       fst	.Hthick 	   ; Hthick = 1 - Mthick
398
       fst      .Hthick            ; Hthick = 1 - Mthick
399
       fld	st
399
       fld      st
400
       fadd	st,st
400
       fadd     st,st
401
       faddp
401
       faddp
402
       fstp	.next_const	    ; next_const = Hthick * 3
402
       fstp     .next_const         ; next_const = Hthick * 3
403
 
403
 
404
 
404
 
405
    ;init triangles list
405
    ;init triangles list
406
       mov	edi,[triangles_ptr]
406
       mov      edi,[triangles_ptr]
407
 
407
 
408
       xor	si,si
408
       xor      esi,esi
409
       xor	ax,ax
409
       xor      eax,eax
410
       mov	bx,.N+1
410
       mov      ebx,.N+1
411
       mov	cx,(.N*2)+2  ;--
411
       mov      ecx,(.N*2)+2  ;--
412
       mov	dx,(.N*3)+3  ;---
412
       mov      edx,(.N*3)+3  ;---
413
       mov	[triangles_count_var],0
413
       mov      [triangles_count_var],0
414
     .again_tri:
414
     .again_tri:
415
       stosw				 ; main wave
415
       stosd                             ; main wave
416
       mov	word[edi],bx
416
       mov      dword[edi],ebx
417
       inc	ax
417
       inc      eax
418
       add	edi,2
418
       add      edi,4
419
       stosw
419
       stosd
420
       stosw
420
       stosd
421
       mov	word[edi],bx
421
       mov      dword[edi],ebx
422
       inc	bx
422
       inc      ebx
423
       mov	word[edi+2],bx
423
       mov      dword[edi+4],ebx
424
 
424
 
425
 
425
 
426
       add	edi,4
426
       add      edi,8
427
 
427
 
428
       mov	word[edi],cx	  ;----   ;     n2+2        ;    xor      ax,ax
428
       mov      dword[edi],ecx      ;----   ;     n2+2        ;    xor      ax,ax
429
       inc	cx			  ;     n2+3        ;    mov      bx,.N+1
429
       inc      ecx                        ;     n2+3        ;    mov      bx,.N+1
430
       mov	word[edi+2],dx		  ;                 ;    mov      cx,(.N*2)+2  ;--
430
       mov      dword[edi+4],edx            ;                 ;    mov      cx,(.N*2)+2  ;--
431
       mov	word[edi+4],cx		  ;     n3+3        ;    mov      dx,(.N*3)+3  ;---
431
       mov      dword[edi+8],ecx            ;     n3+3        ;    mov      dx,(.N*3)+3  ;---
432
       mov	word[edi+6],dx		  ;     n3+3        ;
432
       mov      dword[edi+12],edx            ;     n3+3        ;
433
       inc	dx			  ;                 ;
433
       inc      edx                        ;                 ;
434
       mov	word[edi+8],dx		  ;     n2+3        ;
434
       mov      dword[edi+16],edx            ;     n2+3        ;
435
       mov	word[edi+10],cx 	  ;     n3+4
435
       mov      dword[edi+20],ecx           ;     n3+4
436
       add	edi,12		    ;----
436
       add      edi,24              ;----
437
 
437
 
438
       dec	ax	    ; border of wave
438
       dec      eax          ; border of wave
439
       dec	bx
439
       dec      ebx
440
       dec	cx
440
       dec      ecx
441
       dec	dx
441
       dec      edx
442
 
442
 
443
       stosw			  ; first border
443
       stosd                      ; first border
444
       inc	ax
444
       inc      eax
445
       stosw
445
       stosd
446
       mov	word[edi],dx
446
       mov      dword[edi],edx
447
       add	edi,2
447
       add      edi,4
448
 
448
 
449
       mov	word[edi],dx
449
       mov      dword[edi],edx
450
       add	edi,2
450
       add      edi,4
451
       stosw
451
       stosd
452
       inc	dx
452
       inc      edx
453
       mov	word[edi],dx
453
       mov      dword[edi],edx
454
 
454
 
455
       mov     word[edi+2],bx	   ; second border
455
       mov     dword[edi+4],ebx      ; second border
456
       mov     word[edi+4],cx
456
       mov     dword[edi+8],ecx
457
       inc     bx
457
       inc     ebx
458
       mov     word[edi+6],bx
458
       mov     dword[edi+12],ebx
459
 
459
 
460
       mov     word[edi+8],bx
460
       mov     dword[edi+16],ebx
461
       mov     word[edi+10],cx
461
       mov     dword[edi+20],ecx
462
       inc     cx
462
       inc     ecx
463
       mov     word[edi+12],cx
463
       mov     dword[edi+24],ecx
Line 464... Line 464...
464
       add     edi,14
464
       add     edi,28
Line 465... Line 465...
465
 
465
 
466
       add	[triangles_count_var],8     ;10
466
       add      [triangles_count_var],8     ;10
467
       inc	si
467
       inc      esi
468
       cmp	si,.N
468
       cmp      esi,.N
469
       jne	.again_tri
469
       jne      .again_tri
470
 
470
 
471
       add	ax,((.N+1)*3)+1
471
       add      eax,((.N+1)*3)+1
472
       add	bx,((.N+1)*3)+1
472
       add      ebx,((.N+1)*3)+1
473
       add	cx,((.N+1)*3)+1
473
       add      ecx,((.N+1)*3)+1
Line 474... Line 474...
474
       add	dx,((.N+1)*3)+1
474
       add      edx,((.N+1)*3)+1
475
       xor	si,si
475
       xor      esi,esi
476
       cmp	ax,(.N*13)+13	 ;;;(.N*23)+23                ; ax,(.N*13)+13
476
       cmp      eax,(.N*13)+13    ;;;(.N*23)+23                ; ax,(.N*13)+13
Line 504... Line 504...
504
       .R_P14 equ edi+(14*12*(.N+1))
504
       .R_P14 equ edi+(14*12*(.N+1))
505
       .R_P15 equ edi+(15*12*(.N+1))
505
       .R_P15 equ edi+(15*12*(.N+1))
Line 506... Line 506...
506
 
506
 
507
     @@:
507
     @@:
508
       ; x coordinate
508
       ; x coordinate
509
       fild	.x
509
       fild     .x
510
       fld	st
510
       fld      st
511
;;       fmul     .a                  ; st = <-2pi;2pi>  when mul .a
511
;;       fmul     .a                  ; st = <-2pi;2pi>  when mul .a
512
       fidiv	.Ndiv2
512
       fidiv    .Ndiv2
Line 513... Line 513...
513
       fst	.temp		      ; temporary x in <-1.0;1.0>
513
       fst      .temp                 ; temporary x in <-1.0;1.0>
514
 
514
 
515
       fst	dword[edi]		;x coordinate of point
515
       fst      dword[edi]              ;x coordinate of point
516
       fst	dword[esi]
516
       fst      dword[esi]
517
       fst	dword[eax]		;--
517
       fst      dword[eax]              ;--
518
 
518
 
519
 
519
 
520
       fst	dword[.R_P4]
520
       fst      dword[.R_P4]
521
       fst	dword[.R_P5]
521
       fst      dword[.R_P5]
522
       fst	dword[.R_P6]
522
       fst      dword[.R_P6]
523
       fst	dword[.R_P7]
523
       fst      dword[.R_P7]
524
 
524
 
525
       fst	dword[.R_P8]
525
       fst      dword[.R_P8]
526
       fst	dword[.R_P9]
526
       fst      dword[.R_P9]
527
       fst	dword[.R_P10]
527
       fst      dword[.R_P10]
528
       fst	dword[.R_P11]
528
       fst      dword[.R_P11]
529
 
529
 
530
       fst	dword[.R_P12]
530
       fst      dword[.R_P12]
531
       fst	dword[.R_P13]
531
       fst      dword[.R_P13]
Line 532... Line 532...
532
       fst	dword[.R_P14]
532
       fst      dword[.R_P14]
533
       fst	dword[.R_P15]
533
       fst      dword[.R_P15]
534
 
534
 
535
       fstp	dword[ebx]  ;pop
535
       fstp     dword[ebx]  ;pop
536
      ;*******y coord               dword[offset + 4]
536
      ;*******y coord               dword[offset + 4]
537
       fmul	 .a	 ;  st  = <-2pi;2pi>
537
       fmul      .a      ;  st  = <-2pi;2pi>
538
       fsincos
538
       fsincos
539
       fmul	.next_const
539
       fmul     .next_const
540
       fst	dword[edi+4]		; y coordinate of point
540
       fst      dword[edi+4]            ; y coordinate of point
541
       fst	dword[esi+4]
541
       fst      dword[esi+4]
542
       fst	dword[.R_P4+4]
542
       fst      dword[.R_P4+4]
543
       fst	dword[.R_P5+4]
543
       fst      dword[.R_P5+4]
544
       fld	.Hthick
544
       fld      .Hthick
545
       faddp
545
       faddp
546
       fst	dword[.R_P6+4]
546
       fst      dword[.R_P6+4]
Line 547... Line 547...
547
       fst	dword[.R_P7+4]
547
       fst      dword[.R_P7+4]
548
       fst	dword[eax+4]
548
       fst      dword[eax+4]
549
       fst	dword[ebx+4]
549
       fst      dword[ebx+4]
550
 
550
 
551
       fchs
551
       fchs
552
       fst	dword[.R_P10+4]
552
       fst      dword[.R_P10+4]
553
       fst	dword[.R_P11+4]
553
       fst      dword[.R_P11+4]
554
       fst	dword[.R_P14+4]
554
       fst      dword[.R_P14+4]
555
       fst	dword[.R_P15+4]
555
       fst      dword[.R_P15+4]
556
       fadd	.Hthick
556
       fadd     .Hthick
557
       fadd	.Hthick
557
       fadd     .Hthick
Line 558... Line 558...
558
       fst	dword[.R_P8+4]
558
       fst      dword[.R_P8+4]
559
       fst	dword[.R_P9+4]
559
       fst      dword[.R_P9+4]
560
       fst	dword[.R_P12+4]
560
       fst      dword[.R_P12+4]
Line 561... Line 561...
561
       fstp	dword[.R_P13+4]
561
       fstp     dword[.R_P13+4]
562
 
562
 
563
 
563
 
564
       fmul	.Hthick
564
       fmul     .Hthick
565
       fmul	.next_const
565
       fmul     .next_const
566
       fstp	.cos_temp	    ; cos_temp = Hthick^2 * 3
566
       fstp     .cos_temp           ; cos_temp = Hthick^2 * 3
567
 
567
 
568
     ;***************z coord
568
     ;***************z coord
569
       fld	.temp
569
       fld      .temp
570
       fld	st
570
       fld      st
571
       fmul	st,st0			; z coords
571
       fmul     st,st0                  ; z coords
572
       fchs
572
       fchs
573
       fld1
573
       fld1
574
       faddp
574
       faddp
575
       fabs
575
       fabs
576
       fsqrt
576
       fsqrt
577
;       fld      st
577
;       fld      st
578
;       fsub
578
;       fsub
579
       fld	st
579
       fld      st
580
       fsub	.cos_temp
580
       fsub     .cos_temp
581
       fst	dword[esi+8]
581
       fst      dword[esi+8]
582
       fstp	dword[eax+8]		;--
582
       fstp     dword[eax+8]            ;--
583
       fld	st
583
       fld      st
584
       fadd	.cos_temp
584
       fadd     .cos_temp
585
       fst	dword[.R_P9+8]
585
       fst      dword[.R_P9+8]
586
       fstp	dword[.R_P10+8]
586
       fstp     dword[.R_P10+8]
587
       fchs
587
       fchs
Line 588... Line 588...
588
       fld	st
588
       fld      st
589
       fsub	.cos_temp
589
       fsub     .cos_temp
590
       fst	dword[.R_P6+8]
590
       fst      dword[.R_P6+8]
591
       fstp	dword[.R_P5+8]
591
       fstp     dword[.R_P5+8]
592
       fadd	.cos_temp
592
       fadd     .cos_temp
593
       fst	dword[.R_P13+8]
593
       fst      dword[.R_P13+8]
594
       fstp	dword[.R_P14+8]
594
       fstp     dword[.R_P14+8]
595
 
595
 
596
       fmul	[.Mthick]
596
       fmul     [.Mthick]
597
       fmul	st,st0
597
       fmul     st,st0
598
       fchs
598
       fchs
599
       fld	.MthickSqr
599
       fld      .MthickSqr
600
       faddp
600
       faddp
601
       fabs
601
       fabs
602
       fsqrt
602
       fsqrt
603
       fld	st
603
       fld      st
604
       fsub	.cos_temp
604
       fsub     .cos_temp
605
       fst	dword[edi+8]		;  z coordinate
605
       fst      dword[edi+8]            ;  z coordinate
606
       fstp	dword[ebx+8]		;--
606
       fstp     dword[ebx+8]            ;--
607
       fld	st
607
       fld      st
608
       fadd	.cos_temp
608
       fadd     .cos_temp
609
       fst	dword[.R_P8+8]
609
       fst      dword[.R_P8+8]
610
       fstp	dword[.R_P11+8]
610
       fstp     dword[.R_P11+8]
611
       fchs
611
       fchs
612
       fld	st
612
       fld      st
613
       fsub	.cos_temp
613
       fsub     .cos_temp
614
       fst	dword[.R_P7+8]
614
       fst      dword[.R_P7+8]
615
       fstp	dword[.R_P4+8]
615
       fstp     dword[.R_P4+8]
616
       fadd	.cos_temp
616
       fadd     .cos_temp
617
       fst	dword[.R_P12+8]
617
       fst      dword[.R_P12+8]
618
       fstp	dword[.R_P15+8]
618
       fstp     dword[.R_P15+8]
619
 
619
 
620
       add	edi,12
620
       add      edi,12
621
       add	esi,12
621
       add      esi,12
622
       add	eax,12			;--
622
       add      eax,12                  ;--
623
       add	ebx,12			;---
623
       add      ebx,12                  ;---
624
       add	[points_count_var],24	      ;16
624
       add      [points_count_var],24         ;16
Line 625... Line 625...
625
       inc	.x
625
       inc      .x
626
       cmp	.x,.N/2
626
       cmp      .x,.N/2
627
       jng	@b
627
       jng      @b
628
;       mov      dword[esi],-1       ; <-- end mark
628
;       mov      dword[esi],-1       ; <-- end mark
629
       mov	 [culling_flag],0
629
       mov       [culling_flag],0
630
       mov     esp,ebp
630
       mov     esp,ebp
631
ret
631
ret
632
.Mthick dd  0.85     ; size-thickness
632
.Mthick dd  0.85     ; size-thickness
633
 
633
 
634
make_random_lights:
634
make_random_lights:
635
  .temp1  equ ebp-4
635
  .temp1  equ ebp-4
636
  .temp2  equ ebp-8	;  - light vector generate variables
636
  .temp2  equ ebp-8     ;  - light vector generate variables
637
  .temp3  equ ebp-12
637
  .temp3  equ ebp-12
638
  .max equ 800
638
  .max equ 800
Line 639... Line 639...
639
	RDTSC
639
        RDTSC
640
	mov    [rand_seed],ax
640
        mov    [rand_seed],ax
641
	push	ebp
641
        push    ebp
642
	mov	ebp,esp
642
        mov     ebp,esp
643
	sub	esp,12
643
        sub     esp,12
644
	mov	edi,lights
644
        mov     edi,lights
645
	fninit
645
        fninit
646
	mov	dword[.temp2],.max
646
        mov     dword[.temp2],.max
647
	mov	dword[.temp3],.max/2
647
        mov     dword[.temp3],.max/2
648
 
648
 
649
    .again:
649
    .again:
650
	xor	esi,esi
650
        xor     esi,esi
651
     @@:
651
     @@:
652
	mov	edx,.max
652
        mov     edx,.max
Line 653... Line 653...
653
	xor	ecx,ecx
653
        xor     ecx,ecx
654
	call	random
654
        call    random
655
	sub	eax,.max/2
655
        sub     eax,.max/2
656
	mov	dword[.temp1],eax
656
        mov     dword[.temp1],eax
657
	fild	dword[.temp1]
657
        fild    dword[.temp1]
658
	fidiv	dword[.temp3]
658
        fidiv   dword[.temp3]
659
	fstp	dword[edi+esi*4]
659
        fstp    dword[edi+esi*4]
660
	inc	esi
660
        inc     esi
661
	cmp	esi,2
661
        cmp     esi,2
662
	jne	@b
662
        jne     @b
Line 663... Line 663...
663
 
663
 
664
  .max1 equ 1000
664
  .max1 equ 1000
665
	mov	dword[.temp2],.max1/2
665
        mov     dword[.temp2],.max1/2
666
	mov	edx,.max1
666
        mov     edx,.max1
667
	xor	ecx,ecx
667
        xor     ecx,ecx
668
	call	random
668
        call    random
669
	mov	dword[.temp1],eax
669
        mov     dword[.temp1],eax
670
	fild	dword[.temp1]
670
        fild    dword[.temp1]
671
	fchs
671
        fchs
Line 672... Line 672...
672
	fidiv	dword[.temp2]
672
        fidiv   dword[.temp2]
673
	fstp	dword[edi+8]
673
        fstp    dword[edi+8]
674
 
674
 
675
	xor	esi,esi
675
        xor     esi,esi
676
     @@:
676
     @@:
677
	mov	ecx,220 	   ; max colors and shine  , ecx = 200 - more bright shading
677
        mov     ecx,220            ; max colors and shine  , ecx = 200 - more bright shading
678
	mov	edx,255
678
        mov     edx,255
679
	call	random
679
        call    random
680
	mov	byte[edi+18+esi],al
680
        mov     byte[edi+18+esi],al
Line 681... Line 681...
681
	inc	esi
681
        inc     esi
682
	cmp	esi,4
682
        cmp     esi,4
683
	jne	@b
683
        jne     @b
684
 
684
 
685
 
685
 
686
	xor	esi,esi
686
        xor     esi,esi
687
     @@:
687
     @@:
688
	mov	ecx,100 	     ; orginal colors
688
        mov     ecx,100              ; orginal colors
689
	movzx	edx,byte[edi+18+esi]
689
        movzx   edx,byte[edi+18+esi]
690
	call	random
690
        call    random
691
	mov	byte[edi+12+esi],al
691
        mov     byte[edi+12+esi],al
692
	inc	esi
692
        inc     esi
693
	cmp	esi,3
693
        cmp     esi,3
Line 694... Line 694...
694
	jne	@b
694
        jne     @b
695
 
695
 
696
	xor	esi,esi
696
        xor     esi,esi
Line 697... Line 697...
697
     @@:
697
     @@:
698
	mov	ecx,1		    ; min cols
698
        mov     ecx,1               ; min cols
699
	movzx	edx,byte[edi+12+esi]
699
        movzx   edx,byte[edi+12+esi]
700
	call	random
700
        call    random
701
	mov	byte[edi+15+esi],al
701
        mov     byte[edi+15+esi],al
702
	inc	esi
702
        inc     esi
703
	cmp	esi,3
703
        cmp     esi,3
704
	jne	@b
704
        jne     @b
705
 
705
 
706
	add	edi,LIGHT_SIZE ;22
706
        add     edi,LIGHT_SIZE ;22
707
	cmp	edi,lightsend	  ; see file View3ds,asm
707
        cmp     edi,lightsend     ; see file View3ds,asm
708
	jne	.again
708
        jne     .again
709
 
709
 
710
	mov	esp,ebp
710
        mov     esp,ebp
711
	pop	ebp
711
        pop     ebp
712
ret
712
ret
713
 
713
 
714
generate_texture2:
714
generate_texture2:
715
.const equ 32
715
.const equ 32
716
	mov	edi,texmap
716
        mov     edi,texmap
717
	xor	bx,bx
717
        xor     bx,bx
718
     .next_line:
718
     .next_line:
719
	xor	dx,dx
719
        xor     dx,dx
Line 720... Line 720...
720
     .next2stripes:
720
     .next2stripes:
721
	mov	eax,-1
721
        mov     eax,-1
722
	mov	ecx,(TEX_X/.const)*3/4
722
        mov     ecx,(TEX_X/.const)*3/4
723
	rep	stosd
723
        rep     stosd
724
	mov	eax,0x00ff0000
724
        mov     eax,0x00ff0000
725
	mov	ecx,(TEX_X/.const)
725
        mov     ecx,(TEX_X/.const)
726
     @@:
726
     @@:
727
	stosd
727
        stosd
728
	dec	edi
728
        dec     edi
729
	loop	@b
729
        loop    @b
730
	inc	dx
730
        inc     dx
731
	cmp	dx,.const/2
731
        cmp     dx,.const/2
732
	jl	.next2stripes
732
        jl      .next2stripes
733
	inc	bx
733
        inc     bx
734
	cmp	bx,TEX_Y
734
        cmp     bx,TEX_Y
735
	jl	.next_line
735
        jl      .next_line
Line 736... Line 736...
736
ret
736
ret
737
 
737
 
738
blur_screen:	;blur n times  ; blur or fire
738
blur_screen:    ;blur n times  ; blur or fire
739
;in - ecx  times count
739
;in - ecx  times count
740
;.counter equ dword[esp-4]
740
;.counter equ dword[esp-4]
741
.counter1 equ dword[esp-8]
741
.counter1 equ dword[esp-8]
742
if Ext>=SSE2
742
if Ext>=SSE2
743
	 push	    ebp
743
         push       ebp
744
	 mov	    ebp,esp
744
         mov        ebp,esp
745
	 push	    dword 0x01010101
745
         push       dword 0x01010101
746
	 movss	    xmm5,[esp]
746
         movss      xmm5,[esp]
747
	 shufps     xmm5,xmm5,0
747
         shufps     xmm5,xmm5,0
748
     .again_blur:
748
     .again_blur:
749
	 push	    ecx
749
         push       ecx
750
	 mov	    edi,[screen_ptr]
750
         mov        edi,[screen_ptr]
751
	 movzx	    ecx,word[size_x_var]  ;SIZE_X*3/4
751
         movzx      ecx,word[size_x_var]  ;SIZE_X*3/4
752
	 lea	    ecx,[ecx*3+1]
752
         lea        ecx,[ecx*3+1]
753
	 shr	    ecx,2
753
         shr        ecx,2
754
 
754
 
755
   ;      mov        ecx,SIZE_X*3/4
755
   ;      mov        ecx,SIZE_X*3/4
756
	 xor	    eax,eax
756
         xor        eax,eax
757
	 rep	    stosd
757
         rep        stosd
758
   if 1
758
   if 1
759
	 movzx	    ebx,word[size_x_var]
759
         movzx      ebx,word[size_x_var]
760
	 movzx	    ecx,word[size_y_var]
760
         movzx      ecx,word[size_y_var]
761
	 sub	    ecx,3
761
         sub        ecx,3
762
	 imul	    ecx,ebx
762
         imul       ecx,ebx
763
	 lea	    ecx,[ecx*3]
763
         lea        ecx,[ecx*3]
764
	 shr	    ecx,4
764
         shr        ecx,4
765
	 lea	    ebx,[ebx*3]
765
         lea        ebx,[ebx*3]
766
       ;  mov        ecx,(SIZE_X*(SIZE_Y-3))*3/16
766
       ;  mov        ecx,(SIZE_X*(SIZE_Y-3))*3/16
767
     .blr:
767
     .blr:
768
     @@:
768
     @@:
769
	 push	    ecx
769
         push       ecx
770
	 movups     xmm0,[edi+ebx]
770
         movups     xmm0,[edi+ebx]
771
	 mov	    ecx,edi
771
         mov        ecx,edi
772
	 sub	    ecx,ebx
772
         sub        ecx,ebx
773
	 movups     xmm1,[ecx]
773
         movups     xmm1,[ecx]
774
	 movups     xmm2,[edi-3]
774
         movups     xmm2,[edi-3]
775
	 movups     xmm3,[edi+3]
775
         movups     xmm3,[edi+3]
776
 
776
 
777
	 pavgb	    xmm0,xmm1
777
         pavgb      xmm0,xmm1
778
	 pavgb	    xmm2,xmm3
778
         pavgb      xmm2,xmm3
779
	 pavgb	    xmm0,xmm2
779
         pavgb      xmm0,xmm2
780
 
780
 
Line 781... Line 781...
781
	 psubusb    xmm0,xmm5  ; importand if fire
781
         psubusb    xmm0,xmm5  ; importand if fire
782
 
782
 
783
	 movups     [edi],xmm0
783
         movups     [edi],xmm0
784
	 add	    edi,16
784
         add        edi,16
785
	 add	    esi,16
785
         add        esi,16
786
	 pop	    ecx
786
         pop        ecx
787
	 loop	    .blr
787
         loop       .blr
788
    end if
788
    end if
789
	 xor	    eax,eax
789
         xor        eax,eax
790
	 movzx	    ecx,word[size_x_var]
790
         movzx      ecx,word[size_x_var]
791
	 lea	    ecx,[ecx*3]
791
         lea        ecx,[ecx*3]
792
	 shr	    ecx,2
792
         shr        ecx,2
793
    ;     mov        ecx,SIZE_X*3/4
793
    ;     mov        ecx,SIZE_X*3/4
794
	 rep	    stosd
794
         rep        stosd
795
	 pop	    ecx
795
         pop        ecx
796
	 loop	    .again_blur
796
         loop       .again_blur
797
	 mov	    esp,ebp
797
         mov        esp,ebp
798
	 pop	    ebp
798
         pop        ebp
799
end if
799
end if
800
 
800
 
801
if Ext=SSE
801
if Ext=SSE
802
	 emms
802
         emms
803
	 push	    ebp
803
         push       ebp
804
	 mov	    ebp,esp
804
         mov        ebp,esp
805
	 push	    dword 0x01010101
805
         push       dword 0x01010101
806
	 push	    dword 0x01010101
806
         push       dword 0x01010101
807
	 movq	    mm4,[esp]
-
 
808
     .again_blur:
-
 
809
	 push	    ecx
-
 
810
	 mov	    edi,[screen_ptr]
807
         movq       mm4,[esp]
811
	 movzx	    ecx,word[size_x_var]  ;SIZE_X*3/4
808
     .again_blur:
812
	 lea	    ecx,[ecx*3]
809
         push       ecx
813
	 shr	    ecx,2
810
         mov        edi,[screen_ptr]
814
     ;    pxor       mm5,mm5
811
         movzx      ecx,word[size_x_var]  ;SIZE_X*3/4
815
	 xor	    eax,eax
812
         lea        ecx,[ecx*3]
816
	 rep	    stosd
813
         shr        ecx,2
817
	 movzx	    ebx,word[size_x_var]
814
     ;    pxor       mm5,mm5
818
	 movzx	    ecx,word[size_y_var]
815
         xor        eax,eax
819
	 sub	    ecx,3
816
         rep        stosd
820
	 imul	    ecx,ebx
817
         movzx      ebx,word[size_x_var]
821
	 lea	    ecx,[ecx*3]
818
         movzx      ecx,word[size_y_var]
822
	 shr	    ecx,3
819
         sub        ecx,3
823
	 lea	    ebx,[ebx*3]
820
         imul       ecx,ebx
824
       ;  mov        ecx,(SIZE_X*(SIZE_Y-3))*3/8
821
         lea        ecx,[ecx*3]
825
     .blr:
822
         shr        ecx,3
826
     @@:
823
         lea        ebx,[ebx*3]
827
	 push	    ecx
824
       ;  mov        ecx,(SIZE_X*(SIZE_Y-3))*3/8
828
	 mov	    ecx,edi
825
     .blr:
829
	 sub	    ecx,ebx
826
     @@:
830
	 movq	    mm0,[edi+ebx]
827
         movq       mm0,[edi+ebx]
831
	 movq	    mm1,[ecx]
828
         movq       mm1,[edi-ebx]
832
	 movq	    mm2,[edi-3]
829
         movq       mm2,[edi-3]
833
	 movq	    mm3,[edi+3]
830
         movq       mm3,[edi+3]
834
 
831
 
835
	 pavgb	    mm0,mm1
832
         pavgb      mm0,mm1
836
	 pavgb	    mm2,mm3
833
         pavgb      mm2,mm3
837
	 pavgb	    mm0,mm2
834
         pavgb      mm0,mm2
Line 838... Line 835...
838
 
835
 
839
	 psubusb    mm0,mm4  ; importand if fire
836
         psubusb    mm0,mm4  ; importand if fire
840
 
837
 
841
	 movq	    [edi],mm0
838
         movq       [edi],mm0
842
	 add	     edi,8
839
         add         edi,8
843
	 add	     esi,8
840
         add         esi,8
844
	 pop	     ecx
841
 
845
	 loop	     .blr
842
         loop        .blr
846
 
843
 
847
	 xor	    eax,eax
844
         xor        eax,eax
848
	 mov	    ecx,[size_x_var]
845
         mov        ecx,[size_x_var]
849
	 lea	    ecx,[ecx*3]
846
         lea        ecx,[ecx*3]
850
	 shr	    ecx,2
847
         shr        ecx,2
Line 851... Line 848...
851
       ;  SIZE_X*3/4
848
       ;  SIZE_X*3/4
852
	 rep	    stosd
849
         rep        stosd
853
	 pop	     ecx
850
         pop         ecx
Line 854... Line 851...
854
	 loop	    .again_blur
851
         loop       .again_blur
855
	 mov	    esp,ebp
852
         mov        esp,ebp
856
	 pop	    ebp
853
         pop        ebp
857
end if
854
end if
858
 
855
 
859
if Ext=MMX
856
if Ext=MMX
860
	 emms
857
         emms
861
	 push	    ebp
858
         push       ebp
862
	 mov	    ebp,esp
859
         mov        ebp,esp
863
	 push	    dword 0x0
860
         push       dword 0x0
864
	 push	    dword 0x01010101
861
         push       dword 0x01010101
865
.again_blur:
862
.again_blur:
866
	 push	    ecx
863
         push       ecx
867
	 mov	    edi,[screen_ptr]
864
         mov        edi,[screen_ptr]
868
	 mov	    ecx,SIZE_X*3/4
865
         mov        ecx,SIZE_X*3/4
869
	 pxor	    mm5,mm5
866
         pxor       mm5,mm5
870
	 xor	    eax,eax
867
         xor        eax,eax
871
	 rep	    stosd
868
         rep        stosd
872
 
869
 
873
	 mov	    ecx,(SIZE_X*(SIZE_Y-3))*3/4
870
         mov        ecx,(SIZE_X*(SIZE_Y-3))*3/4
874
     .blr:
871
     .blr:
875
     @@:
872
     @@:
876
 
873
 
877
	 movd	    mm0,[edi+SIZE_X*3]
874
         movd       mm0,[edi+SIZE_X*3]
878
	 movd	    mm1,[edi-SIZE_X*3]
875
         movd       mm1,[edi-SIZE_X*3]
879
	 movd	    mm2,[edi-3]
876
         movd       mm2,[edi-3]
880
	 movd	    mm3,[edi+3]
877
         movd       mm3,[edi+3]
881
 
878
 
882
	 punpcklbw  mm0,mm5
879
         punpcklbw  mm0,mm5
883
	 punpcklbw  mm1,mm5
880
         punpcklbw  mm1,mm5
884
	 punpcklbw  mm2,mm5
881
         punpcklbw  mm2,mm5
885
	 punpcklbw  mm3,mm5
882
         punpcklbw  mm3,mm5
886
	 paddw	    mm0,mm1
883
         paddw      mm0,mm1
887
	 paddw	    mm0,mm2
884
         paddw      mm0,mm2
888
	 paddw	    mm0,mm3
885
         paddw      mm0,mm3
889
	 psrlw	    mm0,2
886
         psrlw      mm0,2
890
 
887
 
891
	 packuswb   mm0,mm5
888
         packuswb   mm0,mm5
892
	 psubusb    mm0,qword[esp]  ; importand if fire
889
         psubusb    mm0,qword[esp]  ; importand if fire
893
	 movd	    eax,mm0
890
         movd       eax,mm0
894
	 stosd
891
         stosd
Line 895... Line 892...
895
 
892
 
896
	 loop	     .blr
893
         loop        .blr
897
 
894
 
898
	 xor	    eax,eax
895
         xor        eax,eax
899
	 mov	    ecx,SIZE_X*3/4
896
         mov        ecx,SIZE_X*3/4
900
	 rep	    stosd
897
         rep        stosd
901
	 pop	     ecx
898
         pop         ecx
902
	 loop	    .again_blur
899
         loop       .again_blur
903
	 mov	    esp,ebp
900
         mov        esp,ebp
904
	 pop	    ebp
901
         pop        ebp
Line 905... Line 902...
905
end if
902
end if
906
if  Ext=NON
903
if  Ext=NON
907
      .blur:
904
      .blur:
908
	 push	ecx
905
         push   ecx
909
	 xor	ecx,ecx
906
         xor    ecx,ecx
910
      .next_col_coof:
907
      .next_col_coof:
911
	 xor	esi,esi
908
         xor    esi,esi
912
	 xor	eax,eax
909
         xor    eax,eax
913
	 xor	ebx,ebx
910
         xor    ebx,ebx
914
	 mov	edi,SIZE_X*SIZE_Y
911
         mov    edi,SIZE_X*SIZE_Y
915
      .next:
912
      .next:
916
	 mov	ebp,esi
913
         mov    ebp,esi
917
	 dec	ebp
914
         dec    ebp
918
 
915
 
919
	 cmp	ebp,SIZE_X*SIZE_Y-1   ; clipping
916
         cmp    ebp,SIZE_X*SIZE_Y-1   ; clipping
920
	 jl	@f
917
         jl     @f
921
	 mov	ebp,SIZE_X*SIZE_Y-1
918
         mov    ebp,SIZE_X*SIZE_Y-1
922
      @@:
919
      @@:
923
	 or	ebp,ebp
920
         or     ebp,ebp
924
	 jg	@f
921
         jg     @f
925
	 xor	ebp,ebp
922
         xor    ebp,ebp
926
      @@:
923
      @@:
927
	 lea	edx,[ebp*3+screen]
924
         lea    edx,[ebp*3+screen]
928
	 mov	al,byte[edx+ecx]
925
         mov    al,byte[edx+ecx]
929
 
926
 
930
	 mov	ebp,esi
927
         mov    ebp,esi
931
	 inc	ebp
928
         inc    ebp
932
	 cmp	ebp,SIZE_X*SIZE_Y-1   ; clipping
929
         cmp    ebp,SIZE_X*SIZE_Y-1   ; clipping
933
	 jl	@f
930
         jl     @f
934
	 mov	ebp,SIZE_X*SIZE_Y-1
931
         mov    ebp,SIZE_X*SIZE_Y-1
935
      @@:
932
      @@:
936
	 or	ebp,ebp
933
         or     ebp,ebp
937
	 jg	@f
934
         jg     @f
938
	 xor	ebp,ebp
935
         xor    ebp,ebp
939
      @@:
936
      @@:
940
	 lea	edx,[ebp*3+screen]
937
         lea    edx,[ebp*3+screen]
941
	 mov	bl,byte[edx+ecx]
938
         mov    bl,byte[edx+ecx]
942
	 add	eax,ebx
939
         add    eax,ebx
943
 
940
 
944
	 mov	ebp,esi
941
         mov    ebp,esi
945
	 sub	ebp,SIZE_X
942
         sub    ebp,SIZE_X
946
	 cmp	ebp,SIZE_X*SIZE_Y-1   ; clipping
943
         cmp    ebp,SIZE_X*SIZE_Y-1   ; clipping
947
	 jl	@f
944
         jl     @f
948
	 mov	ebp,SIZE_X*SIZE_Y-1
945
         mov    ebp,SIZE_X*SIZE_Y-1
949
      @@:
946
      @@:
950
	 or	ebp,ebp
947
         or     ebp,ebp
951
	 jg	@f
948
         jg     @f
952
	 xor	ebp,ebp
949
         xor    ebp,ebp
953
      @@:
950
      @@:
Line 954... Line 951...
954
	 lea	edx,[ebp*3+screen]
951
         lea    edx,[ebp*3+screen]
955
	 mov	bl,byte[edx+ecx]
952
         mov    bl,byte[edx+ecx]
956
	 add	eax,ebx
953
         add    eax,ebx
957
 
954
 
958
	 mov	ebp,esi
955
         mov    ebp,esi
959
	 add	ebp,SIZE_X
956
         add    ebp,SIZE_X
960
	 cmp	ebp,SIZE_X*SIZE_Y-1   ; clipping
957
         cmp    ebp,SIZE_X*SIZE_Y-1   ; clipping
961
	 jl	@f
958
         jl     @f
962
	 mov	ebp,SIZE_X*SIZE_Y-1
959
         mov    ebp,SIZE_X*SIZE_Y-1
963
      @@:
960
      @@:
964
	 or	ebp,ebp
961
         or     ebp,ebp
965
	 jg	@f
962
         jg     @f
Line 966... Line 963...
966
	 xor	ebp,ebp
963
         xor    ebp,ebp
967
      @@:
964
      @@:
968
	 lea	edx,[ebp*3+screen]
965
         lea    edx,[ebp*3+screen]
969
	 mov	bl,byte[edx+ecx]
966
         mov    bl,byte[edx+ecx]
970
	 add	eax,ebx
967
         add    eax,ebx
971
 
968
 
972
	 shr	eax,2
969
         shr    eax,2
973
	 lea	edx,[esi*3+screen]
970
         lea    edx,[esi*3+screen]
974
	 or	al,al
971
         or     al,al
975
	 jz	@f
972
         jz     @f
976
	 dec	al		; not importand if fire
973
         dec    al              ; not importand if fire
977
	 mov	byte[edx+ecx],al
974
         mov    byte[edx+ecx],al
978
     @@:
975
     @@:
979
 
976
 
980
	 inc	esi
977
         inc    esi
981
	 dec	edi
978
         dec    edi
982
	 jnz	.next
979
         jnz    .next
983
 
980
 
984
	 inc	ecx
981
         inc    ecx
985
	 cmp	ecx,3
982
         cmp    ecx,3
986
	 jne	.next_col_coof
983
         jne    .next_col_coof
987
	 pop	ecx
984
         pop    ecx
988
	 dec	 ecx
985
         dec     ecx
989
	 jnz	.blur
986
         jnz    .blur
990
end if
987
end if
991
ret
988
ret
992
 
989
 
993
mirror: 			      ; mirror effect - loseless operation
990
mirror:                               ; mirror effect - loseless operation
994
; in ah - button id = 11, 12, 13
991
; in ah - button id = 11, 12, 13
995
	 mov	  edi,[points_ptr]     ; one real point - triple float
992
         mov      edi,[points_ptr]     ; one real point - triple float
996
	 mov	  esi,[points_normals_ptr]   ; one 3dvector - triple float dword x,y,z
993
         mov      esi,[points_normals_ptr]   ; one 3dvector - triple float dword x,y,z
997
	 fninit
994
         fninit
998
	 movzx	  ecx,[points_count_var]
995
         mov      ecx,[points_count_var]
999
 
996
 
1000
	 cmp	  ah,11
997
         cmp      ah,11
1001
	 je	  @f
998
         je       @f
1002
	 cmp	  ah,12
999
         cmp      ah,12
1003
	 je	  .yn
1000
         je       .yn
1004
	 cmp	  ah,13
1001
         cmp      ah,13
1005
	 je	  .zn
1002
         je       .zn
1006
 
1003
 
1007
       @@:				; neg x
1004
       @@:                              ; neg x
1008
	 fld	  dword[edi]	;x
1005
         fld      dword[edi]    ;x
1009
	 fchs
1006
         fchs
1010
	 fstp	  dword[edi]	;x
1007
         fstp     dword[edi]    ;x
1011
	 fld	  dword[esi]
1008
         fld      dword[esi]
1012
	 fchs
1009
         fchs
1013
	 fstp	  dword[esi]
1010
         fstp     dword[esi]
1014
	 add	  edi,12
1011
         add      edi,12
Line 1015... Line 1012...
1015
	 add	  esi,12
1012
         add      esi,12
1016
	 loop	  @b
1013
         loop     @b
1017
	 ret
1014
         ret
1018
       .yn:
1015
       .yn:
1019
	 fld	  dword[edi+4]	;y
1016
         fld      dword[edi+4]  ;y
1020
	 fchs
1017
         fchs
1021
	 fstp	  dword[edi+4]	;y
1018
         fstp     dword[edi+4]  ;y
1022
	 fld	  dword[esi+4]
1019
         fld      dword[esi+4]
1023
	 fchs
1020
         fchs
1024
	 fstp	  dword[esi+4]
1021
         fstp     dword[esi+4]
1025
 
1022
 
1026
	 add	  edi,12
1023
         add      edi,12
1027
	 add	  esi,12
1024
         add      esi,12
1028
	 loop	  .yn
1025
         loop     .yn
1029
	 ret
1026
         ret
1030
      .zn:
1027
      .zn:
1031
	 fld	  dword[edi+8]	  ;z
1028
         fld      dword[edi+8]    ;z
1032
	 fchs
1029
         fchs
1033
	 fstp	  dword[edi+8]	  ;z
1030
         fstp     dword[edi+8]    ;z
1034
	 fld	  dword[esi+8]
1031
         fld      dword[esi+8]
1035
	 fchs
1032
         fchs
1036
	 fstp	  dword[esi+8]
1033
         fstp     dword[esi+8]
1037
 
1034
 
1038
	 add	  edi,12
1035
         add      edi,12
1039
	 add	  esi,12
1036
         add      esi,12
1040
	 loop	  .zn
1037
         loop     .zn
1041
ret
1038
ret
1042
 
1039
 
1043
exchange:			      ; exchange some coords - loseless operation
1040
exchange:                             ; exchange some coords - loseless operation
1044
	 mov	  edi,[points_ptr]     ; one real point - triple float
1041
         mov      edi,[points_ptr]     ; one real point - triple float
1045
	 mov	  esi,[points_normals_ptr]  ; one 3dvector - triple float dword x,y,z
1042
         mov      esi,[points_normals_ptr]  ; one 3dvector - triple float dword x,y,z
1046
	 fninit 		      ; exchange both points and normal vactors coords/coofics
1043
         fninit                       ; exchange both points and normal vactors coords/coofics
1047
	 movzx	  ecx,[points_count_var]
1044
         mov      ecx,[points_count_var]
1048
 
1045
 
1049
	 cmp	  [xchg_flag],1
1046
         cmp      [xchg_flag],1
1050
	 je	  @f
1047
         je       @f
1051
	 cmp	  [xchg_flag],2
1048
         cmp      [xchg_flag],2
1052
	 je	  .zx
1049
         je       .zx
1053
	 cmp	  [xchg_flag],3
1050
         cmp      [xchg_flag],3
1054
	 je	  .yz
1051
         je       .yz
1055
       @@:
1052
       @@:
1056
	 fld	  dword[edi]	;x
1053
         fld      dword[edi]    ;x
1057
	 fld	  dword[edi+4]	;y
1054
         fld      dword[edi+4]  ;y
1058
	 fstp	  dword[edi]	;x
1055
         fstp     dword[edi]    ;x
1059
	 fstp	  dword[edi+4]	;y
1056
         fstp     dword[edi+4]  ;y
1060
	 fld	  dword[esi]	;x
1057
         fld      dword[esi]    ;x
1061
	 fld	  dword[esi+4]	;y
1058
         fld      dword[esi+4]  ;y
1062
	 fstp	  dword[esi]	;x
1059
         fstp     dword[esi]    ;x
1063
	 fstp	  dword[esi+4]	;y
1060
         fstp     dword[esi+4]  ;y
1064
 
1061
 
1065
	 add	  esi,12
1062
         add      esi,12
1066
	 add	  edi,12
1063
         add      edi,12
1067
	 loop	  @b
1064
         loop     @b
1068
	 ret
1065
         ret
Line 1069... Line 1066...
1069
       .zx:
1066
       .zx:
1070
	 fld	  dword[edi]	;x
1067
         fld      dword[edi]    ;x
1071
	 fld	  dword[edi+8]	;z
1068
         fld      dword[edi+8]  ;z
1072
	 fstp	  dword[edi]	;x
1069
         fstp     dword[edi]    ;x
1073
	 fstp	  dword[edi+8]	;z
1070
         fstp     dword[edi+8]  ;z
1074
	 fld	  dword[esi]	;x
1071
         fld      dword[esi]    ;x
1075
	 fld	  dword[esi+8]	;y
1072
         fld      dword[esi+8]  ;y
1076
	 fstp	  dword[esi]	;x
1073
         fstp     dword[esi]    ;x
1077
	 fstp	  dword[esi+8]	;y
1074
         fstp     dword[esi+8]  ;y
1078
 
1075
 
1079
	 add	  esi,12
1076
         add      esi,12
1080
	 add	  edi,12
1077
         add      edi,12
1081
	 loop	  .zx
1078
         loop     .zx
1082
	 ret
1079
         ret
1083
      .yz:
1080
      .yz:
1084
	 fld	  dword[edi+8]	  ;z
1081
         fld      dword[edi+8]    ;z
1085
	 fld	  dword[edi+4]	  ;y
1082
         fld      dword[edi+4]    ;y
1086
	 fstp	  dword[edi+8]	  ;z
1083
         fstp     dword[edi+8]    ;z
1087
	 fstp	  dword[edi+4]	  ;y
1084
         fstp     dword[edi+4]    ;y
1088
	 fld	  dword[esi+8]	  ;x
1085
         fld      dword[esi+8]    ;x
1089
	 fld	  dword[esi+4]	  ;y
1086
         fld      dword[esi+4]    ;y
1090
	 fstp	  dword[esi+8]	  ;x
1087
         fstp     dword[esi+8]    ;x
1091
	 fstp	  dword[esi+4]	  ;y
1088
         fstp     dword[esi+4]    ;y
1092
 
1089
 
1093
	 add	  edi,12
1090
         add      edi,12
1094
	 add	  esi,12
1091
         add      esi,12
1095
	 loop	  .yz
1092
         loop     .yz
1096
ret
1093
ret
1097
 
1094
 
1098
;#\\\\\\\\\\\\\\\\\\\\\\\\\comented///////////////////////////////
1095
;#\\\\\\\\\\\\\\\\\\\\\\\\\comented///////////////////////////////
1099
if 0
1096
if 0
1100
calc_attenuation_light: 	 ;; calculate point to spot_light distance
1097
calc_attenuation_light:          ;; calculate point to spot_light distance
1101
; spot light with attenuation    ;; and vector, normalize vector,
1098
; spot light with attenuation    ;; and vector, normalize vector,
1102
				 ;; calc dot_pr and unlinear color according
1099
                                 ;; calc dot_pr and unlinear color according
1103
				 ;; to dot_product, write to color buff
1100
                                 ;; to dot_product, write to color buff
1104
.distance equ dword[ebp-4]	 ;; color buff in bumpmap for save the mem
1101
.distance equ dword[ebp-4]       ;; color buff in bumpmap for save the mem
1105
.temp_col equ word[ebp-6]
1102
.temp_col equ word[ebp-6]
1106
.vector   equ [ebp-20]
1103
.vector   equ [ebp-20]
1107
.spot_light_ptr equ dword [ebp-24]
1104
.spot_light_ptr equ dword [ebp-24]
1108
	mov	ebp,esp
1105
        mov     ebp,esp
1109
	sub	esp,24
1106
        sub     esp,24
1110
	mov	edi,rotated_points_r  ;points_rotated
1107
        mov     edi,rotated_points_r  ;points_rotated
1111
	mov	edx,point_normals_rotated
1108
        mov     edx,point_normals_rotated
1112
	mov	ecx,bumpmap	   ; mem area with temp points color list
1109
        mov     ecx,bumpmap        ; mem area with temp points color list
1113
	xor	ax,ax		   ; counter
1110
        xor     ax,ax              ; counter
1114
	mov	esi,spot_light_params
1111
        mov     esi,spot_light_params
1115
	mov	.spot_light_ptr,esi
1112
        mov     .spot_light_ptr,esi
1116
     .again_color:
1113
     .again_color:
1117
	push	eax
1114
        push    eax
1118
	lea	ebx,.vector
1115
        lea     ebx,.vector
1119
	mov	esi,.spot_light_ptr ; calc vector fom light to every point
1116
        mov     esi,.spot_light_ptr ; calc vector fom light to every point
1120
	call	make_vector_r
1117
        call    make_vector_r
1121
	; ebx - ptr to result vector
1118
        ; ebx - ptr to result vector
Line 1122... Line 1119...
1122
	fld	dword [ebx]
1119
        fld     dword [ebx]
1123
	fmul	st, st
1120
        fmul    st, st
1124
	fld	dword [ebx+4]
1121
        fld     dword [ebx+4]
Line 1125... Line 1122...
1125
	fmul	st, st
1122
        fmul    st, st
1126
	fld	dword [ebx+8]
1123
        fld     dword [ebx+8]
Line 1127... Line 1124...
1127
	fmul	st, st
1124
        fmul    st, st
1128
	faddp	st1, st
1125
        faddp   st1, st
Line 1129... Line 1126...
1129
	faddp	st1, st
1126
        faddp   st1, st
1130
	fsqrt
1127
        fsqrt
1131
	fstp	.distance
1128
        fstp    .distance
1132
	push	edi
1129
        push    edi
1133
	mov	edi,ebx
1130
        mov     edi,ebx
1134
	call	normalize_vector
1131
        call    normalize_vector
1135
	; edi - normalized distance vector
1132
        ; edi - normalized distance vector
1136
	mov	esi,edx
1133
        mov     esi,edx
1137
	call	dot_product  ; esi first vector, edi second vector
1134
        call    dot_product  ; esi first vector, edi second vector
1138
	; st0 - dot product
1135
        ; st0 - dot product
1139
	fabs	; why not ? - think about it
1136
        fabs    ; why not ? - think about it
1140
	pop	edi
1137
        pop     edi
1141
	fldz
1138
        fldz
1142
	fcomip	st1
1139
        fcomip  st1
1143
	jbe	@f	     ; st1>0
1140
        jbe     @f           ; st1>0
1144
	mov	dword[ecx],0
1141
        mov     dword[ecx],0
1145
	mov	word[ecx+4],0
1142
        mov     word[ecx+4],0
1146
	add	ecx,6
1143
        add     ecx,6
1147
	ffree	st0
1144
        ffree   st0
1148
	jmp	.update_counters
1145
        jmp     .update_counters
1149
  @@:
1146
  @@:
1150
     ;   pop     edi
1147
     ;   pop     edi
1151
 
1148
 
1152
	; calc color(with atenuation), write to buff
1149
        ; calc color(with atenuation), write to buff
1153
	; buff - color of points list
1150
        ; buff - color of points list
1154
	; color = ambient+cos(x)*diffuse+(cos(x)^n)*specular
1151
        ; color = ambient+cos(x)*diffuse+(cos(x)^n)*specular
1155
 
1152
 
1156
	push	edx
1153
        push    edx
1157
	push	edi
1154
        push    edi
1158
 
1155
 
1159
	push	ecx
1156
        push    ecx
Line 1160... Line 1157...
1160
	push	ebp
1157
        push    ebp
1161
 
1158
 
1162
;        mov     eax,spot_light_params
1159
;        mov     eax,spot_light_params
1163
	mov	eax,.spot_light_ptr
1160
        mov     eax,.spot_light_ptr
1164
	movzx	dx,byte[eax+15]
1161
        movzx   dx,byte[eax+15]
1165
	push	dx	       ; shines
1162
        push    dx             ; shines
1166
	movzx	dx,byte[eax+8] ; b
1163
        movzx   dx,byte[eax+8] ; b
1167
	push	dx	       ; orginal col
1164
        push    dx             ; orginal col
1168
	movzx	dx,byte[eax+7] ; g
1165
        movzx   dx,byte[eax+7] ; g
1169
	push	dx
1166
        push    dx
1170
	movzx	dx,byte[eax+6]	 ; r
1167
        movzx   dx,byte[eax+6]   ; r
1171
	push	dx
1168
        push    dx
1172
	movzx	dx,byte[eax+14] ; max col
1169
        movzx   dx,byte[eax+14] ; max col
1173
	push	dx
1170
        push    dx
1174
	movzx	dx,byte[eax+13]
1171
        movzx   dx,byte[eax+13]
1175
	push	dx
1172
        push    dx
1176
	movzx	dx,byte[eax+12]
1173
        movzx   dx,byte[eax+12]
1177
	push	dx
1174
        push    dx
1178
	movzx	dx,byte[eax+11] ; min col
1175
        movzx   dx,byte[eax+11] ; min col
1179
	push	dx
1176
        push    dx
1180
	movzx	dx,byte[eax+10]
1177
        movzx   dx,byte[eax+10]
1181
	push	dx
1178
        push    dx
1182
	movzx	dx,byte[eax+9]
1179
        movzx   dx,byte[eax+9]
1183
	push	dx
1180
        push    dx
1184
	push	eax	       ; dot pr.  (in st0)
1181
        push    eax            ; dot pr.  (in st0)
1185
	call	calc_one_col
1182
        call    calc_one_col
1186
	; eax - 0x00rrggbb
1183
        ; eax - 0x00rrggbb
1187
	; brightness = 1 - (distance/light.fadezero)^fogness
1184
        ; brightness = 1 - (distance/light.fadezero)^fogness
1188
	; if brightness  < 0, then brightness = 0
1185
        ; if brightness  < 0, then brightness = 0
1189
	; attenuetion equation taken from 3dica tutorial - 1/d^2 isn't perfect
1186
        ; attenuetion equation taken from 3dica tutorial - 1/d^2 isn't perfect
1190
	; color = color * brightness  ;  fogness = <0.5,2.0>
1187
        ; color = color * brightness  ;  fogness = <0.5,2.0>
1191
	pop	ebp
1188
        pop     ebp
Line 1192... Line 1189...
1192
	pop	ecx
1189
        pop     ecx
1193
 
1190
 
1194
	fld    .distance
1191
        fld    .distance
1195
	mov	esi,.spot_light_ptr
1192
        mov     esi,.spot_light_ptr
1196
;        fidiv   word[spot_light_params+16]   ; fadezero
1193
;        fidiv   word[spot_light_params+16]   ; fadezero
1197
	fidiv	word[esi+16]   ; fadezero
1194
        fidiv   word[esi+16]   ; fadezero
1198
      ;  fmul    st,st0       ; fogness = 2
1195
      ;  fmul    st,st0       ; fogness = 2
1199
	fabs		      ; to be sure
1196
        fabs                  ; to be sure
1200
	fchs
1197
        fchs
1201
	fld1
1198
        fld1
1202
	faddp
1199
        faddp
1203
	fld1
1200
        fld1
1204
	fcomip	st1
1201
        fcomip  st1
1205
	jnbe	@f
1202
        jnbe    @f
1206
	ffree	st0
1203
        ffree   st0
1207
	fld1
1204
        fld1
Line 1208... Line 1205...
1208
      @@:
1205
      @@:
1209
	fld	st	      ; st - brightness
1206
        fld     st            ; st - brightness
1210
	ror	eax,16
1207
        ror     eax,16
1211
	movzx	bx,al	     ; al - r
1208
        movzx   bx,al        ; al - r
1212
	mov	.temp_col,bx
1209
        mov     .temp_col,bx
1213
	fimul	.temp_col
1210
        fimul   .temp_col
1214
	fistp	word[ecx]
1211
        fistp   word[ecx]
1215
	cmp	word[ecx],0
1212
        cmp     word[ecx],0
1216
	jge	@f
1213
        jge     @f
1217
	mov	word[ecx],0
1214
        mov     word[ecx],0
1218
    @@:
1215
    @@:
1219
   ;     mov     edx,dword[spot_light_params+12]  ; max colors
1216
   ;     mov     edx,dword[spot_light_params+12]  ; max colors
1220
	mov	edx,dword[esi+12]  ; max colors
1217
        mov     edx,dword[esi+12]  ; max colors
1221
	movzx	bx,dl	      ; r max
1218
        movzx   bx,dl         ; r max
1222
	cmp	word[ecx],bx  ; choose the brightest for r, g, b
1219
        cmp     word[ecx],bx  ; choose the brightest for r, g, b
1223
	jl	@f
1220
        jl      @f
1224
	mov	word[ecx],bx
1221
        mov     word[ecx],bx
1225
    @@:
1222
    @@:
1226
 
1223
 
1227
	add	ecx,2
1224
        add     ecx,2
1228
	fld	st
1225
        fld     st
Line 1266... Line 1263...
1266
;        mov     word[ecx+2],bx
1263
;        mov     word[ecx+2],bx
1267
;        xor     ah,ah
1264
;        xor     ah,ah
1268
;        mov     word[ecx+4],ax
1265
;        mov     word[ecx+4],ax
1269
;        add     ecx,6
1266
;        add     ecx,6
Line 1270... Line 1267...
1270
 
1267
 
1271
	pop    edi
1268
        pop    edi
Line 1272... Line 1269...
1272
	pop    edx
1269
        pop    edx
1273
 
1270
 
1274
    .update_counters:
1271
    .update_counters:
Line 1275... Line 1272...
1275
	add	edx,12	; normal_size
1272
        add     edx,12  ; normal_size
1276
	add	edi,12	 ;6   ; 3d point_coord_size
1273
        add     edi,12   ;6   ; 3d point_coord_size
1277
 
1274
 
1278
	pop	eax
1275
        pop     eax
1279
	inc	ax
1276
        inc     ax
1280
	cmp	ax,[points_count_var]
1277
        cmp     ax,[points_count_var]
1281
	jne	.again_color
1278
        jne     .again_color
1282
 
1279
 
Line 1283... Line 1280...
1283
	add	.spot_light_ptr,18
1280
        add     .spot_light_ptr,18
1284
	cmp	.spot_light_ptr,spot_l_end
1281
        cmp     .spot_light_ptr,spot_l_end
1285
	jl	.again_color
1282
        jl      .again_color
1286
 
1283
 
1287
	mov	esp,ebp
1284
        mov     esp,ebp