Subversion Repositories Kolibri OS

Rev

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

Rev 1776 Rev 6619
1
;TEX_X = 512
1
;TEX_X = 512
2
;TEX_Y = 512
2
;TEX_Y = 512
3
;ROUND equ 8
3
;ROUND equ 8
4
;SIZE_X = 512
4
;SIZE_X = 512
5
;SIZE_Y = 512
5
;SIZE_Y = 512
6
;TEX_SHIFT = 9
6
;TEX_SHIFT = 9
7
CATMULL_SHIFT equ 8
7
CATMULL_SHIFT equ 8
8
 
8
 
9
;------------------------------------------------------------------------
9
;------------------------------------------------------------------------
10
;- Procedure drawing textured triangle using Catmull Z-buffer algorithm -
10
;- Procedure drawing textured triangle using Catmull Z-buffer algorithm -
11
;------------------------------------------------------------------------
11
;------------------------------------------------------------------------
12
tex_triangle_z:
12
tex_triangle_z:
13
;----------in - eax - x1 shl 16 + y1
13
;----------in - eax - x1 shl 16 + y1
14
;-------------- ebx - x2 shl 16 + y2
14
;-------------- ebx - x2 shl 16 + y2
15
;---------------ecx - x3 shl 16 + y3
15
;---------------ecx - x3 shl 16 + y3
16
;---------------edx - pointer to Z-buffer
16
;---------------edx - pointer to Z-buffer
17
;---------------esi - pointer to texture buffer
17
;---------------esi - pointer to texture buffer
18
;---------------edi - pointer to screen buffer
18
;---------------edi - pointer to screen buffer
19
;-------------stack - texture coordinates
19
;-------------stack - texture coordinates
20
;------------------ - z coordinates
20
;------------------ - z coordinates
21
.tex_x1 equ  ebp+4
21
.tex_x1 equ  ebp+4
22
.tex_y1 equ  ebp+6
22
.tex_y1 equ  ebp+6
23
.tex_x2 equ  ebp+8
23
.tex_x2 equ  ebp+8
24
.tex_y2 equ  ebp+10
24
.tex_y2 equ  ebp+10
25
.tex_x3 equ  ebp+12
25
.tex_x3 equ  ebp+12
26
.tex_y3 equ  ebp+14
26
.tex_y3 equ  ebp+14
27
.z1	equ  word[ebp+16]
27
.z1	equ  word[ebp+16]
28
.z2	equ  word[ebp+18]
28
.z2	equ  word[ebp+18]
29
.z3	equ  word[ebp+20]
29
.z3	equ  word[ebp+20]
30
 
30
 
31
.tex_ptr equ dword[ebp-4]	 ; pointer to texture
31
.tex_ptr equ dword[ebp-4]	 ; pointer to texture
32
.z_ptr	 equ dword[ebp-8]	 ; pointer to z-buffer
32
.z_ptr	 equ dword[ebp-8]	 ; pointer to z-buffer
33
.x1	 equ word[ebp-10]
33
.x1	 equ word[ebp-10]
34
.y1	 equ word[ebp-12]
34
.y1	 equ word[ebp-12]
35
.x2	 equ word[ebp-14]
35
.x2	 equ word[ebp-14]
36
.y2	 equ word[ebp-16]
36
.y2	 equ word[ebp-16]
37
.x3	 equ word[ebp-18]
37
.x3	 equ word[ebp-18]
38
.y3	 equ word[ebp-20]
38
.y3	 equ word[ebp-20]
39
 
39
 
40
.dx12	  equ dword[ebp-24]
40
.dx12	  equ dword[ebp-24]
41
.tex_dx12 equ dword[ebp-28]
41
.tex_dx12 equ dword[ebp-28]
42
.tex_dy12 equ dword[ebp-32]
42
.tex_dy12 equ dword[ebp-32]
43
.dz12	  equ dword[ebp-36]
43
.dz12	  equ dword[ebp-36]
44
 
44
 
45
.dx13	  equ dword[ebp-40]
45
.dx13	  equ dword[ebp-40]
46
.tex_dx13 equ dword[ebp-44]
46
.tex_dx13 equ dword[ebp-44]
47
.tex_dy13 equ dword[ebp-48]
47
.tex_dy13 equ dword[ebp-48]
48
.dz13	  equ dword[ebp-52]
48
.dz13	  equ dword[ebp-52]
49
 
49
 
50
.dx23	  equ dword[ebp-56]
50
.dx23	  equ dword[ebp-56]
51
.tex_dx23 equ dword[ebp-60]
51
.tex_dx23 equ dword[ebp-60]
52
.tex_dy23 equ dword[ebp-64]
52
.tex_dy23 equ dword[ebp-64]
53
.dz23	  equ dword[ebp-68]
53
.dz23	  equ dword[ebp-68]
54
 
54
 
55
.scan_x1  equ dword[ebp-72]
55
.scan_x1  equ dword[ebp-72]
56
.scan_x2  equ dword[ebp-76]
56
.scan_x2  equ dword[ebp-76]
57
.scan_y1  equ dword[ebp-80]
57
.scan_y1  equ dword[ebp-80]
58
.scan_y2  equ dword[ebp-84]
58
.scan_y2  equ dword[ebp-84]
59
.cz1	  equ dword[ebp-88]
59
.cz1	  equ dword[ebp-88]
60
.cz2	  equ dword[ebp-92]
60
.cz2	  equ dword[ebp-92]
61
 
61
 
62
	mov	ebp,esp
62
	mov	ebp,esp
63
	push	esi		  ; store memory pointers
63
	push	esi		  ; store memory pointers
64
	push	edx
64
	push	edx
65
.tt_sort3:
65
.tt_sort3:
66
	cmp	ax,bx			  ;sort all parameters
66
	cmp	ax,bx			  ;sort all parameters
67
	jle	.tt_sort1
67
	jle	.tt_sort1
68
	xchg	eax,ebx
68
	xchg	eax,ebx
69
	mov	edx,dword [.tex_x1]
69
	mov	edx,dword [.tex_x1]
70
	xchg	edx,dword [.tex_x2]
70
	xchg	edx,dword [.tex_x2]
71
	mov	dword[.tex_x1],edx
71
	mov	dword[.tex_x1],edx
72
	mov	dx,.z1
72
	mov	dx,.z1
73
	xchg	dx,.z2
73
	xchg	dx,.z2
74
	mov	.z1,dx
74
	mov	.z1,dx
75
.tt_sort1:
75
.tt_sort1:
76
	cmp	bx,cx
76
	cmp	bx,cx
77
	jle	.tt_sort2
77
	jle	.tt_sort2
78
	xchg	ebx,ecx
78
	xchg	ebx,ecx
79
	mov	edx,dword [.tex_x2]
79
	mov	edx,dword [.tex_x2]
80
	xchg	edx,dword [.tex_x3]
80
	xchg	edx,dword [.tex_x3]
81
	mov	dword [.tex_x2],edx
81
	mov	dword [.tex_x2],edx
82
	mov	dx,.z2
82
	mov	dx,.z2
83
	xchg	dx,.z3
83
	xchg	dx,.z3
84
	mov	.z2,dx
84
	mov	.z2,dx
85
	jmp	.tt_sort3
85
	jmp	.tt_sort3
86
.tt_sort2:
86
.tt_sort2:
87
 
87
 
88
	push	eax	; and store to user friendly variables
88
	push	eax	; and store to user friendly variables
89
	push	ebx
89
	push	ebx
90
	push	ecx
90
	push	ecx
91
 
91
 
92
	mov	 edx,80008000h	; eax,ebx,ecx are ANDd together into edx which means that
92
	mov	 edx,80008000h	; eax,ebx,ecx are ANDd together into edx which means that
93
	and	 edx,ebx	; if *all* of them are negative a sign flag is raised
93
	and	 edx,ebx	; if *all* of them are negative a sign flag is raised
94
	and	 edx,ecx
94
	and	 edx,ecx
95
	and	 edx,eax
95
	and	 edx,eax
96
	test	 edx,80008000h	; Check both X&Y at once
96
	test	 edx,80008000h	; Check both X&Y at once
97
	jne	 .tt_loop2_end
97
	jne	 .tt_loop2_end
98
	cmp	 ax,SIZE_Y
98
    ;    cmp      ax,SIZE_Y
99
	jl	 @f
99
    ;    jl       @f
100
	cmp	 bx,SIZE_Y
100
    ;    cmp      bx,SIZE_Y
101
	jl	 @f
101
    ;    jl       @f
102
	cmp	 cx,SIZE_Y
102
    ;    cmp      cx,SIZE_Y
103
	jl	 @f
103
    ;    jl       @f
104
	ror	 eax,16
104
	ror	 eax,16
105
	ror	 ebx,16
105
	ror	 ebx,16
106
	ror	 ecx,16
106
	ror	 ecx,16
107
	cmp	 ax,SIZE_X
107
    ;    cmp      ax,SIZE_X
108
	jl	 @f
108
    ;    jl       @f
109
	cmp	 bx,SIZE_X
109
    ;    cmp      bx,SIZE_X
110
	jl	 @f
110
    ;    jl       @f
111
	cmp	 cx,SIZE_X
111
    ;    cmp      cx,SIZE_X
112
	jl	 @f
112
    ;    jl       @f
113
	jmp	 .tt_loop2_end
113
    ;    jmp      .tt_loop2_end
114
     @@:
114
     @@:
115
	mov	 eax,dword[.tex_x1] ; texture coords must be in [0..TEX_X(Y)]
115
	mov	 eax,dword[.tex_x1] ; texture coords must be in [0..TEX_X(Y)]
116
	mov	 ebx,dword[.tex_x2]
116
	mov	 ebx,dword[.tex_x2]
117
	mov	 ecx,dword[.tex_x3]
117
	mov	 ecx,dword[.tex_x3]
118
	mov	 edx,eax
118
	mov	 edx,eax
119
	or	 edx,ebx
119
	or	 edx,ebx
120
	or	 edx,ecx
120
	or	 edx,ecx
121
	test	 edx,80008000h
121
	test	 edx,80008000h
122
	jne	 .tt_loop2_end
122
	jne	 .tt_loop2_end
123
	cmp	 ax,TEX_X
123
	cmp	 ax,TEX_X
124
	jge	 .tt_loop2_end
124
	jge	 .tt_loop2_end
125
	cmp	 bx,TEX_X
125
	cmp	 bx,TEX_X
126
	jge	 .tt_loop2_end
126
	jge	 .tt_loop2_end
127
	cmp	 cx,TEX_X
127
	cmp	 cx,TEX_X
128
	jge	 .tt_loop2_end
128
	jge	 .tt_loop2_end
129
	ror	 eax,16
129
	ror	 eax,16
130
	ror	 ebx,16
130
	ror	 ebx,16
131
	ror	 ecx,16
131
	ror	 ecx,16
132
	cmp	 ax,TEX_Y
132
	cmp	 ax,TEX_Y
133
	jge	 .tt_loop2_end
133
	jge	 .tt_loop2_end
134
	cmp	 bx,TEX_Y
134
	cmp	 bx,TEX_Y
135
	jge	 .tt_loop2_end
135
	jge	 .tt_loop2_end
136
	cmp	 cx,TEX_Y
136
	cmp	 cx,TEX_Y
137
	jge	 .tt_loop2_end
137
	jge	 .tt_loop2_end
138
 
138
 
139
 
139
 
140
	movsx	 ebx,.y2    ; calc delta
140
	movsx	 ebx,.y2    ; calc delta
141
	sub	 bx,.y1
141
	sub	 bx,.y1
142
	jnz	 .tt_dx12_make
142
	jnz	 .tt_dx12_make
143
	xor	 edx,edx
143
	xor	 edx,edx
144
	mov	 ecx,4
144
	mov	 ecx,4
145
    @@:
145
    @@:
146
	push	 edx
146
	push	 edx
147
	loop	 @b
147
	loop	 @b
148
	jmp	 .tt_dx12_done
148
	jmp	 .tt_dx12_done
149
    .tt_dx12_make:
149
    .tt_dx12_make:
150
	mov	 ax,.x2
150
	mov	 ax,.x2
151
	sub	 ax,.x1
151
	sub	 ax,.x1
152
	cwde
152
	cwde
153
	shl	 eax,ROUND
153
	shl	 eax,ROUND
154
	cdq
154
	cdq
155
	idiv	 ebx
155
	idiv	 ebx
156
       ; mov      .dx12,eax                      ; dx12 = (x2-x1)/(y2-y1)
156
       ; mov      .dx12,eax                      ; dx12 = (x2-x1)/(y2-y1)
157
	push	 eax
157
	push	 eax
158
 
158
 
159
	mov	 ax,word[.tex_x2]
159
	mov	 ax,word[.tex_x2]
160
	sub	 ax,word[.tex_x1]
160
	sub	 ax,word[.tex_x1]
161
	cwde
161
	cwde
162
	shl	 eax,ROUND
162
	shl	 eax,ROUND
163
	cdq
163
	cdq
164
	idiv	 ebx
164
	idiv	 ebx
165
       ; mov     [.tex_dx12],eax               ; tex_dx12 = (tex_x2-tex_x1)/(y2-y1)
165
       ; mov     [.tex_dx12],eax               ; tex_dx12 = (tex_x2-tex_x1)/(y2-y1)
166
	push	 eax
166
	push	 eax
167
 
167
 
168
	mov	 ax,word[.tex_y2]
168
	mov	 ax,word[.tex_y2]
169
	sub	 ax,word[.tex_y1]
169
	sub	 ax,word[.tex_y1]
170
	cwde
170
	cwde
171
	shl	 eax,ROUND
171
	shl	 eax,ROUND
172
	cdq
172
	cdq
173
	idiv	 ebx
173
	idiv	 ebx
174
     ;   mov    [.tex_dy12],eax              ; tex_dy12 = (tex_y2-tex_y1)/(y2-y1)
174
     ;   mov    [.tex_dy12],eax              ; tex_dy12 = (tex_y2-tex_y1)/(y2-y1)
175
	push	 eax
175
	push	 eax
176
 
176
 
177
	mov	 ax,.z2
177
	mov	 ax,.z2
178
	sub	 ax,.z1
178
	sub	 ax,.z1
179
	cwde
179
	cwde
180
	shl	 eax,CATMULL_SHIFT
180
	shl	 eax,CATMULL_SHIFT
181
	cdq
181
	cdq
182
	idiv	 ebx
182
	idiv	 ebx
183
	push	 eax
183
	push	 eax
184
   .tt_dx12_done:
184
   .tt_dx12_done:
185
 
185
 
186
	movsx	 ebx,.y3    ; calc delta
186
	movsx	 ebx,.y3    ; calc delta
187
	sub	 bx,.y1
187
	sub	 bx,.y1
188
	jnz	 .tt_dx13_make
188
	jnz	 .tt_dx13_make
189
	xor	 edx,edx
189
	xor	 edx,edx
190
	mov	 ecx,4
190
	mov	 ecx,4
191
    @@:
191
    @@:
192
	push	 edx
192
	push	 edx
193
	loop	 @b
193
	loop	 @b
194
	jmp	 .tt_dx13_done
194
	jmp	 .tt_dx13_done
195
    .tt_dx13_make:
195
    .tt_dx13_make:
196
	mov	 ax,.x3
196
	mov	 ax,.x3
197
	sub	 ax,.x1
197
	sub	 ax,.x1
198
	cwde
198
	cwde
199
	shl	 eax,ROUND
199
	shl	 eax,ROUND
200
	cdq
200
	cdq
201
	idiv	 ebx
201
	idiv	 ebx
202
       ; mov      .dx12,eax                      ; dx13 = (x3-x1)/(y3-y1)
202
       ; mov      .dx12,eax                      ; dx13 = (x3-x1)/(y3-y1)
203
	push	  eax
203
	push	  eax
204
 
204
 
205
	mov	 ax,word[.tex_x3]
205
	mov	 ax,word[.tex_x3]
206
	sub	 ax,word[.tex_x1]
206
	sub	 ax,word[.tex_x1]
207
	cwde
207
	cwde
208
	shl	 eax,ROUND
208
	shl	 eax,ROUND
209
	cdq
209
	cdq
210
	idiv	 ebx
210
	idiv	 ebx
211
       ; mov     [.tex_dx12],eax               ; tex_dx13 = (tex_x3-tex_x1)/(y3-y1)
211
       ; mov     [.tex_dx12],eax               ; tex_dx13 = (tex_x3-tex_x1)/(y3-y1)
212
	push	 eax
212
	push	 eax
213
 
213
 
214
	mov	 ax,word[.tex_y3]
214
	mov	 ax,word[.tex_y3]
215
	sub	 ax,word[.tex_y1]
215
	sub	 ax,word[.tex_y1]
216
	cwde
216
	cwde
217
	shl	 eax,ROUND
217
	shl	 eax,ROUND
218
	cdq
218
	cdq
219
	idiv	 ebx
219
	idiv	 ebx
220
     ;   mov    [.tex_dy12],eax              ; tex_dy13 = (tex_y3-tex_y1)/(y3-y1)
220
     ;   mov    [.tex_dy12],eax              ; tex_dy13 = (tex_y3-tex_y1)/(y3-y1)
221
	push	 eax
221
	push	 eax
222
 
222
 
223
	mov	 ax,.z3
223
	mov	 ax,.z3
224
	sub	 ax,.z1
224
	sub	 ax,.z1
225
	cwde
225
	cwde
226
	shl	 eax,CATMULL_SHIFT
226
	shl	 eax,CATMULL_SHIFT
227
	cdq
227
	cdq
228
	idiv	 ebx
228
	idiv	 ebx
229
	push	 eax
229
	push	 eax
230
   .tt_dx13_done:
230
   .tt_dx13_done:
231
 
231
 
232
	mov	 bx,.y3    ; calc delta
232
	mov	 bx,.y3    ; calc delta
233
	sub	 bx,.y2
233
	sub	 bx,.y2
234
	jnz	 .tt_dx23_make
234
	jnz	 .tt_dx23_make
235
	xor	 edx,edx
235
	xor	 edx,edx
236
	mov	 ecx,4
236
	mov	 ecx,4
237
    @@:
237
    @@:
238
	push	 edx
238
	push	 edx
239
	loop	 @b
239
	loop	 @b
240
	jmp	 .tt_dx23_done
240
	jmp	 .tt_dx23_done
241
    .tt_dx23_make:
241
    .tt_dx23_make:
242
	mov	 ax,.x3
242
	mov	 ax,.x3
243
	sub	 ax,.x2
243
	sub	 ax,.x2
244
	cwde
244
	cwde
245
	shl	 eax,ROUND
245
	shl	 eax,ROUND
246
	cdq
246
	cdq
247
	movzx	 ebx,bx
247
	movzx	 ebx,bx
248
	idiv	 ebx
248
	idiv	 ebx
249
       ; mov      .dx23,eax                      ; dx23 = (x3-x2)/(y3-y2)
249
       ; mov      .dx23,eax                      ; dx23 = (x3-x2)/(y3-y2)
250
	push	  eax
250
	push	  eax
251
 
251
 
252
	mov	 ax,word[.tex_x3]
252
	mov	 ax,word[.tex_x3]
253
	sub	 ax,word[.tex_x2]
253
	sub	 ax,word[.tex_x2]
254
	cwde
254
	cwde
255
	shl	 eax,ROUND
255
	shl	 eax,ROUND
256
	cdq
256
	cdq
257
	idiv	 ebx
257
	idiv	 ebx
258
       ; mov     [.tex_dx23],eax               ; tex_dx23 = (tex_x3-tex_x2)/(y3-y2)
258
       ; mov     [.tex_dx23],eax               ; tex_dx23 = (tex_x3-tex_x2)/(y3-y2)
259
	push	 eax
259
	push	 eax
260
 
260
 
261
	mov	 ax,word[.tex_y3]
261
	mov	 ax,word[.tex_y3]
262
	sub	 ax,word[.tex_y2]
262
	sub	 ax,word[.tex_y2]
263
	cwde
263
	cwde
264
	shl	 eax,ROUND
264
	shl	 eax,ROUND
265
	cdq
265
	cdq
266
	idiv	 ebx
266
	idiv	 ebx
267
     ;   mov    [.tex_dy23],eax              ; tex_dy23 = (tex_y3-tex_y2)/(y3-y2)
267
     ;   mov    [.tex_dy23],eax              ; tex_dy23 = (tex_y3-tex_y2)/(y3-y2)
268
	push	 eax
268
	push	 eax
269
 
269
 
270
	mov	 ax,.z3
270
	mov	 ax,.z3
271
	sub	 ax,.z2
271
	sub	 ax,.z2
272
	cwde
272
	cwde
273
	shl	 eax,CATMULL_SHIFT
273
	shl	 eax,CATMULL_SHIFT
274
	cdq
274
	cdq
275
	idiv	 ebx
275
	idiv	 ebx
276
	push	 eax
276
	push	 eax
277
   .tt_dx23_done:
277
   .tt_dx23_done:
278
 
278
 
279
	movsx	 eax,.x1     ;eax - cur x1
279
	movsx	 eax,.x1     ;eax - cur x1
280
	shl	 eax,ROUND   ;ebx - cur x2
280
	shl	 eax,ROUND   ;ebx - cur x2
281
	mov	 ebx,eax
281
	mov	 ebx,eax
282
 
282
 
283
	movsx	 edx, word[.tex_x1]
283
	movsx	 edx, word[.tex_x1]
284
	shl	 edx,ROUND
284
	shl	 edx,ROUND
285
      ;  mov [.scan_x1],edx
285
      ;  mov [.scan_x1],edx
286
      ;  mov [.scan_x2],edx
286
      ;  mov [.scan_x2],edx
287
	push	 edx
287
	push	 edx
288
	push	 edx
288
	push	 edx
289
	movsx	 edx, word[.tex_y1]
289
	movsx	 edx, word[.tex_y1]
290
	shl	 edx,ROUND
290
	shl	 edx,ROUND
291
       ; mov [.scan_y1],edx
291
       ; mov [.scan_y1],edx
292
       ; mov [.scan_y2],edx
292
       ; mov [.scan_y2],edx
293
	push	 edx
293
	push	 edx
294
	push	 edx
294
	push	 edx
295
	movsx	 edx,.z1
295
	movsx	 edx,.z1
296
	shl	 edx,CATMULL_SHIFT
296
	shl	 edx,CATMULL_SHIFT
297
	push	 edx
297
	push	 edx
298
	push	 edx
298
	push	 edx
299
	mov	 cx,.y1
299
	mov	 cx,.y1
300
	cmp	 cx,.y2
300
	cmp	 cx,.y2
301
	jge	 .tt_loop1_end
301
	jge	 .tt_loop1_end
302
 
302
 
303
   .tt_loop1:
303
   .tt_loop1:
304
	pushad
304
	pushad
305
 
305
 
306
	push	.z_ptr
306
	push	.z_ptr
307
	push	.cz1	  ; z coords shifted shl catmull_shift
307
	push	.cz1	  ; z coords shifted shl catmull_shift
308
	push	.cz2
308
	push	.cz2
309
	push	.scan_y2
309
	push	.scan_y2
310
	push	.scan_x2
310
	push	.scan_x2
311
	push	.scan_y1
311
	push	.scan_y1
312
	push	.scan_x1
312
	push	.scan_x1
313
	push	esi		  ;[.tex_ptr]
313
	push	esi		  ;[.tex_ptr]
314
 
314
 
315
	push	cx
315
	push	cx
316
	sar	ebx,ROUND
316
	sar	ebx,ROUND
317
	push	bx
317
	push	bx
318
	sar	eax,ROUND
318
	sar	eax,ROUND
319
	push	ax
319
	push	ax
320
	call	textured_line_z
320
	call	textured_line_z
321
 
321
 
322
	popad
322
	popad
323
	mov	edx,.dz13
323
	mov	edx,.dz13
324
	add	.cz1,edx
324
	add	.cz1,edx
325
	mov	edx,.dz12
325
	mov	edx,.dz12
326
	add	.cz2,edx
326
	add	.cz2,edx
327
 
327
 
328
	mov	edx, .tex_dx13
328
	mov	edx, .tex_dx13
329
	add	.scan_x1, edx
329
	add	.scan_x1, edx
330
	mov	edx, .tex_dx12
330
	mov	edx, .tex_dx12
331
	add	.scan_x2, edx
331
	add	.scan_x2, edx
332
	mov	edx, .tex_dy13
332
	mov	edx, .tex_dy13
333
	add	.scan_y1, edx
333
	add	.scan_y1, edx
334
	mov	edx, .tex_dy12
334
	mov	edx, .tex_dy12
335
	add	.scan_y2, edx
335
	add	.scan_y2, edx
336
 
336
 
337
	add	eax, .dx13
337
	add	eax, .dx13
338
	add	ebx, .dx12
338
	add	ebx, .dx12
339
	inc	cx
339
	inc	cx
340
	cmp	cx,.y2
340
	cmp	cx,.y2
341
	jl	.tt_loop1
341
	jl	.tt_loop1
342
 
342
 
343
  .tt_loop1_end:
343
  .tt_loop1_end:
344
 
344
 
345
 
345
 
346
	mov	cx,.y2
346
	mov	cx,.y2
347
	cmp	cx,.y3
347
	cmp	cx,.y3
348
	jge	.tt_loop2_end
348
	jge	.tt_loop2_end
349
 
349
 
350
	movsx	ebx,.x2
350
	movsx	ebx,.x2
351
	shl	ebx,ROUND
351
	shl	ebx,ROUND
352
	movsx	edx,.z2
352
	movsx	edx,.z2
353
	shl	edx,CATMULL_SHIFT
353
	shl	edx,CATMULL_SHIFT
354
	mov	.cz2,edx
354
	mov	.cz2,edx
355
	movzx	edx, word [.tex_x2]
355
	movzx	edx, word [.tex_x2]
356
	shl	edx,ROUND
356
	shl	edx,ROUND
357
	mov	.scan_x2,edx
357
	mov	.scan_x2,edx
358
	movzx	edx, word[.tex_y2]
358
	movzx	edx, word[.tex_y2]
359
	shl	edx,ROUND
359
	shl	edx,ROUND
360
	mov	.scan_y2,edx
360
	mov	.scan_y2,edx
361
 
361
 
362
.tt_loop2:
362
.tt_loop2:
363
 
363
 
364
	pushad
364
	pushad
365
 
365
 
366
	push	.z_ptr
366
	push	.z_ptr
367
	push	.cz1	  ; z coords shifted shl catmull_shift
367
	push	.cz1	  ; z coords shifted shl catmull_shift
368
	push	.cz2
368
	push	.cz2
369
 
369
 
370
	push	.scan_y2
370
	push	.scan_y2
371
	push	.scan_x2
371
	push	.scan_x2
372
	push	.scan_y1
372
	push	.scan_y1
373
	push	.scan_x1
373
	push	.scan_x1
374
	push	esi		  ;[.tex_ptr]
374
	push	esi		  ;[.tex_ptr]
375
 
375
 
376
	push	cx
376
	push	cx
377
	sar	ebx,ROUND
377
	sar	ebx,ROUND
378
	push	bx
378
	push	bx
379
	sar	eax,ROUND
379
	sar	eax,ROUND
380
	push	ax
380
	push	ax
381
	call	textured_line_z
381
	call	textured_line_z
382
 
382
 
383
	popad
383
	popad
384
 
384
 
385
 
385
 
386
	mov	edx,.dz13
386
	mov	edx,.dz13
387
	add	.cz1,edx
387
	add	.cz1,edx
388
	mov	edx,.dz23
388
	mov	edx,.dz23
389
	add	.cz2,edx
389
	add	.cz2,edx
390
 
390
 
391
	mov	edx, .tex_dx13
391
	mov	edx, .tex_dx13
392
	add	.scan_x1, edx
392
	add	.scan_x1, edx
393
	mov	edx, .tex_dx23
393
	mov	edx, .tex_dx23
394
	add	.scan_x2, edx
394
	add	.scan_x2, edx
395
	mov	edx, .tex_dy13
395
	mov	edx, .tex_dy13
396
	add	.scan_y1, edx
396
	add	.scan_y1, edx
397
	mov	edx, .tex_dy23
397
	mov	edx, .tex_dy23
398
	add	.scan_y2, edx
398
	add	.scan_y2, edx
399
 
399
 
400
	add	eax, .dx13
400
	add	eax, .dx13
401
	add	ebx, .dx23
401
	add	ebx, .dx23
402
	inc	cx
402
	inc	cx
403
	cmp	cx,.y3
403
	cmp	cx,.y3
404
	jl	.tt_loop2
404
	jl	.tt_loop2
405
 
405
 
406
.tt_loop2_end:
406
.tt_loop2_end:
407
 
407
 
408
.tt_end:
408
.tt_end:
409
	mov esp,ebp
409
	mov esp,ebp
410
ret 18
410
ret 18
411
 
411
 
412
textured_line_z:
412
textured_line_z:
413
;-----in -edi screen buffer pointer
413
;-----in -edi screen buffer pointer
414
;------------ stack:
414
;------------ stack:
415
  .x1 equ word [ebp+4]
415
  .x1 equ word [ebp+4]
416
  .x2 equ word [ebp+6]
416
  .x2 equ word [ebp+6]
417
  .y  equ word [ebp+8]
417
  .y  equ word [ebp+8]
418
 
418
 
419
  .tex_ptr equ dword [ebp+10]
419
  .tex_ptr equ dword [ebp+10]
420
  .tex_x1  equ ebp+14
420
  .tex_x1  equ ebp+14
421
  .tex_y1  equ ebp+18
421
  .tex_y1  equ ebp+18
422
  .tex_x2  equ ebp+22
422
  .tex_x2  equ ebp+22
423
  .tex_y2  equ ebp+26
423
  .tex_y2  equ ebp+26
424
  .z2	   equ dword [ebp+30]	  ;z1, z2  coords shifted shl CATMULL_SHIFT
424
  .z2	   equ dword [ebp+30]	  ;z1, z2  coords shifted shl CATMULL_SHIFT
425
  .z1	   equ dword [ebp+34]
425
  .z1	   equ dword [ebp+34]
426
  .z_ptr   equ dword [ebp+38]
426
  .z_ptr   equ dword [ebp+38]
427
 
427
 
428
  .tex_dy  equ dword [ebp-4]
428
  .tex_dy  equ dword [ebp-4]
429
  .tex_dx  equ dword [ebp-8]
429
  .tex_dx  equ dword [ebp-8]
430
  .dz	   equ dword [ebp-12]
430
  .dz	   equ dword [ebp-12]
431
  .cz	   equ dword [ebp-16]
431
  .cz	   equ dword [ebp-16]
432
  .c_tex_x equ dword [ebp-20]  ; current tex x
432
  .c_tex_x equ dword [ebp-20]  ; current tex x
433
  .m_sft1 equ ebp-28
433
  .m_sft1 equ ebp-28
434
  .m_sft2 equ ebp-32
434
  .m_sft2 equ ebp-32
435
;  .c_tex_xM equ ebp+14
435
;  .c_tex_xM equ ebp+14
436
  .tex_dxM  equ ebp-8
436
  .tex_dxM  equ ebp-8
437
 
437
 
438
	mov	ebp,esp
438
	mov	ebp,esp
439
 
439
 
440
	mov	ax,.y
440
	mov	ax,.y
441
	or	ax,ax
441
	or	ax,ax
442
	jl	.tl_quit
442
	jl	.tl_quit
-
 
443
	mov	bx,[size_y_var]
-
 
444
	dec	bx
443
	cmp	ax,SIZE_Y
445
	cmp	ax,bx  ;SIZE_Y
444
	jge	.tl_quit
446
	jge	.tl_quit
445
 
447
 
446
	mov	ax,.x1
448
	mov	ax,.x1
447
	cmp	ax,.x2
449
	cmp	ax,.x2
448
	je	.tl_quit
450
	je	.tl_quit
449
	jl	.tl_ok
451
	jl	.tl_ok
450
 
452
 
451
	xchg	ax,.x2	  ; sort params
453
	xchg	ax,.x2	  ; sort params
452
	mov	.x1,ax
454
	mov	.x1,ax
453
if Ext >= MMX
455
if Ext >= MMX
454
	movq	mm0,[.tex_x1]
456
	movq	mm0,[.tex_x1]
455
	movq	mm1,[.tex_x2]
457
	movq	mm1,[.tex_x2]
456
	movq	[.tex_x2],mm0
458
	movq	[.tex_x2],mm0
457
	movq	[.tex_x1],mm1
459
	movq	[.tex_x1],mm1
458
 
460
 
459
else
461
else
460
	mov	eax,dword[.tex_x1]
462
	mov	eax,dword[.tex_x1]
461
	xchg	eax,dword[.tex_x2]
463
	xchg	eax,dword[.tex_x2]
462
	mov	dword[.tex_x1],eax
464
	mov	dword[.tex_x1],eax
463
 
465
 
464
	mov	eax,dword[.tex_y1]
466
	mov	eax,dword[.tex_y1]
465
	xchg	eax,dword[.tex_y2]
467
	xchg	eax,dword[.tex_y2]
466
	mov	dword[.tex_y1],eax
468
	mov	dword[.tex_y1],eax
467
 
469
 
468
end if
470
end if
469
 
471
 
470
	mov	eax,.z1
472
	mov	eax,.z1
471
	xchg	eax,.z2
473
	xchg	eax,.z2
472
	mov	.z1,eax
474
	mov	.z1,eax
473
 
475
 
474
     .tl_ok:
476
     .tl_ok:
-
 
477
	mov	cx,[size_x_var]
-
 
478
	dec	cx
475
	cmp	.x1,SIZE_X
479
	cmp	.x1,cx	 ;SIZE_X
476
	jge	.tl_quit
480
	jge	.tl_quit
477
	cmp	.x2,0
481
	cmp	.x2,0
478
	jle	.tl_quit
482
	jle	.tl_quit
479
 
483
 
480
	mov	bx,.x2
484
	mov	bx,.x2
481
	sub	bx,.x1
485
	sub	bx,.x1
482
	movsx	ebx,bx
486
	movsx	ebx,bx
483
 
487
 
484
	mov	eax,dword[.tex_y2]	 ; calc .dty
488
	mov	eax,dword[.tex_y2]	 ; calc .dty
485
	sub	eax,dword[.tex_y1]
489
	sub	eax,dword[.tex_y1]
486
	cdq
490
	cdq
487
	idiv	ebx
491
	idiv	ebx
488
	push	eax
492
	push	eax
489
 
493
 
490
	mov	eax,dword[.tex_x2]	 ; calc .dtx
494
	mov	eax,dword[.tex_x2]	 ; calc .dtx
491
	sub	eax,dword[.tex_x1]
495
	sub	eax,dword[.tex_x1]
492
	cdq
496
	cdq
493
	idiv	ebx
497
	idiv	ebx
494
	push	eax
498
	push	eax
495
 
499
 
496
	mov	eax,.z2       ; calc .dz
500
	mov	eax,.z2       ; calc .dz
497
	sub	eax,.z1
501
	sub	eax,.z1
498
	cdq
502
	cdq
499
	idiv	ebx
503
	idiv	ebx
500
	push	eax
504
	push	eax
501
 
505
 
502
	cmp    .x1,0	      ; clipping
506
	cmp    .x1,0	      ; clipping
503
	jg     @f
507
	jg     @f
504
 
508
 
505
	movsx	ebx,.x1
509
	movsx	ebx,.x1
506
	neg	ebx
510
	neg	ebx
507
	imul	ebx	      ; eax = .dz * abs(.x1)
511
	imul	ebx	      ; eax = .dz * abs(.x1)
508
	add	.z1,eax
512
	add	.z1,eax
509
	mov	.x1,0
513
	mov	.x1,0
510
 
514
 
511
	mov	eax,.tex_dy
515
	mov	eax,.tex_dy
512
	imul	ebx
516
	imul	ebx
513
	add	dword[.tex_y1],eax
517
	add	dword[.tex_y1],eax
514
 
518
 
515
	mov	eax,.tex_dx
519
	mov	eax,.tex_dx
516
	imul	ebx
520
	imul	ebx
517
	add	dword[.tex_x1],eax
521
	add	dword[.tex_x1],eax
518
 
522
 
519
      @@:
523
      @@:
520
	cmp	.x2,SIZE_X
524
	cmp	.x2,cx ;SIZE_X
521
	jl	@f
525
	jl	@f
522
	mov	.x2,SIZE_X
526
	mov	.x2,cx	;SIZE_X
523
      @@:
527
      @@:
524
 
528
 
525
	movsx	ebx,.y	      ; calc mem begin in buffers
529
	movsx	ebx,.y	      ; calc mem begin in buffers
526
	mov	eax,SIZE_X
530
	movzx	eax,word[size_x_var]  ;SIZE_X
527
	mul	ebx
531
	mul	ebx
528
	movsx	ebx,.x1
532
	movsx	ebx,.x1
529
	add	eax,ebx
533
	add	eax,ebx
530
	mov	ebx,eax
534
	mov	ebx,eax
531
 
535
 
532
	lea	eax,[eax*3]
536
	lea	eax,[eax*3]
533
	add	edi,eax 	      ; edi - scr buff
537
	add	edi,eax 	      ; edi - scr buff
534
	shl	ebx,2
538
	shl	ebx,2
535
	add	.z_ptr,ebx	      ; z buffer pointer
539
	add	.z_ptr,ebx	      ; z buffer pointer
536
 
540
 
537
	mov	cx,.x2
541
	mov	cx,.x2
538
	sub	cx,.x1
542
	sub	cx,.x1
539
	movzx	ecx,cx
543
	movzx	ecx,cx
540
 
544
 
541
;if Ext >= MMX
545
;if Ext >= MMX
542
;        movq    mm0,[.tex_x1]
546
;        movq    mm0,[.tex_x1]
543
;        movq    mm4,mm0
547
;        movq    mm4,mm0
544
;        movq    mm1,qword[.tex_dxM]
548
;        movq    mm1,qword[.tex_dxM]
545
;        mov     ebx,.z1
549
;        mov     ebx,.z1
546
;        mov     eax,.dz
550
;        mov     eax,.dz
547
;else
551
;else
548
	mov	eax,dword[.tex_x1]
552
	mov	eax,dword[.tex_x1]
549
	mov	ebx,dword[.tex_y1]
553
	mov	ebx,dword[.tex_y1]
550
	push	.z1	      ; .cz
554
	push	.z1	      ; .cz
551
	push	eax	      ;.c_tex_x
555
	push	eax	      ;.c_tex_x
552
;end if
556
;end if
553
	mov	edx,.z_ptr
557
	mov	edx,.z_ptr
554
 
558
 
555
     .tl_loop:
559
     .tl_loop:
556
 
560
 
557
;if Ext >= MMX
561
;if Ext >= MMX
558
;        cmp     ebx,[edx]                       ;  ebx - current z
562
;        cmp     ebx,[edx]                       ;  ebx - current z
559
;        jge     @f
563
;        jge     @f
560
;        movq    mm2,mm0
564
;        movq    mm2,mm0
561
;        psrad   mm2,ROUND
565
;        psrad   mm2,ROUND
562
;        movq    mm3,mm2
566
;        movq    mm3,mm2
563
;        psrlq   mm2,32-TEX_SHIFT
567
;        psrlq   mm2,32-TEX_SHIFT
564
;        paddd   mm3,mm2
568
;        paddd   mm3,mm2
565
;        movd    esi,mm3
569
;        movd    esi,mm3
566
;        mov     dword[edx],ebx    ; renew z buffer
570
;        mov     dword[edx],ebx    ; renew z buffer
567
;else
571
;else
568
							;  eax - temp
572
							;  eax - temp
569
	mov	eax,.cz 			;  ebx - cur tex y shl ROUND
573
	mov	eax,.cz 			;  ebx - cur tex y shl ROUND
570
	cmp	eax,[edx]			;  ecx - l.lenght
574
	cmp	eax,[edx]			;  ecx - l.lenght
571
	jge	@f	   ; ebx - cur tex_y ;  edx - temp
575
	jge	@f	   ; ebx - cur tex_y ;  edx - temp
572
	mov	esi,ebx 		;  edi - scr buff
576
	mov	esi,ebx 		;  edi - scr buff
573
	sar	esi,ROUND		;  esi - tex_ptr temp
577
	sar	esi,ROUND		;  esi - tex_ptr temp
574
	shl	esi,TEX_SHIFT		;  .z_ptr - cur pointer to z buff
578
	shl	esi,TEX_SHIFT		;  .z_ptr - cur pointer to z buff
575
	mov	eax,.c_tex_x		;  .cz - cur z coord shl CATMULL_SHIFT
579
	mov	eax,.c_tex_x		;  .cz - cur z coord shl CATMULL_SHIFT
576
	sar	eax,ROUND
580
	sar	eax,ROUND
577
	add	esi,eax
581
	add	esi,eax
578
	mov	eax,.cz
582
	mov	eax,.cz
579
	mov	dword[edx],eax	  ; renew z buffer
583
	mov	dword[edx],eax	  ; renew z buffer
580
;end if
584
;end if
581
	and	esi,TEXTURE_SIZE
585
	and	esi,TEXTURE_SIZE
582
	lea	esi,[esi*3]
586
	lea	esi,[esi*3]
583
	add	esi,.tex_ptr
587
	add	esi,.tex_ptr
584
	movsd
588
	movsd
585
	dec	edi
589
	dec	edi
586
	jmp	.no_skip
590
	jmp	.no_skip
587
      @@:
591
      @@:
588
	add	edi,3
592
	add	edi,3
589
     .no_skip:
593
     .no_skip:
590
	add	edx,4
594
	add	edx,4
591
;if Ext >= MMX
595
;if Ext >= MMX
592
;        add     ebx,eax
596
;        add     ebx,eax
593
;        paddd   mm0,mm1
597
;        paddd   mm0,mm1
594
;else
598
;else
595
	mov	eax,.dz
599
	mov	eax,.dz
596
	add	.cz,eax
600
	add	.cz,eax
597
	mov	eax,.tex_dx
601
	mov	eax,.tex_dx
598
	add	.c_tex_x,eax
602
	add	.c_tex_x,eax
599
	add	ebx,.tex_dy
603
	add	ebx,.tex_dy
600
;end if
604
;end if
601
	loop	.tl_loop
605
	loop	.tl_loop
602
 .tl_quit:
606
 .tl_quit:
603
 
607
 
604
	mov	esp,ebp
608
	mov	esp,ebp
605
 
609
 
606
ret 30+8
610
ret 30+8