Subversion Repositories Kolibri OS

Rev

Rev 8666 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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