Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1245 hidnplayr 1
;---------------------------------------------------------------------
2
;--------------------textured triangle procedure----------------------
3
;---------------------------------------------------------------------
4
 
5
tex_triangle:
6
;----------in - eax - x1 shl 16 + y1
7
;-------------- ebx - x2 shl 16 + y2
8
;---------------ecx - x3 shl 16 + y3
9
;---------------edx - nothing
10
;---------------esi - pointer to texture buffer
11
;---------------edi - pointer to screen buffer
12
;-------------stack - texture coordinates
13
.tex_x1 equ  ebp+4
14
.tex_y1 equ  ebp+6
15
.tex_x2 equ  ebp+8
16
.tex_y2 equ  ebp+10
17
.tex_x3 equ  ebp+12
18
.tex_y3 equ  ebp+14
19
 
20
.x1 equ ebp-2 ;dw ?
21
.y1 equ ebp-4 ;dw ?
22
.x2 equ ebp-6 ;dw ?
23
.y2 equ ebp-8 ;dw ?
24
.x3 equ ebp-10 ;dw ?
25
.y3 equ ebp-12 ;dw ?
26
.dx12 equ ebp-16 ;dd ?
27
.dx13 equ ebp-20 ;dd ?
28
.dx23 equ ebp-24 ;dd ?
29
.tex_dx12 equ ebp-28 ;dd ?
30
.tex_dy12 equ ebp-32 ;dd ?
31
.tex_dx13 equ ebp-36 ;dd ?
32
.tex_dy13 equ ebp-40 ;dd ?
33
.tex_dx23 equ ebp-44 ;dd ?
34
.tex_dy23 equ ebp-48 ;dd ?
35
.tex_ptr equ ebp-52 ;dd ?
36
 
37
.scan_x2 equ ebp-56 ;dd ?
38
.scan_y2 equ ebp-60 ;dd ?
39
.scan_x1 equ ebp-64 ;dd ?
40
.scan_y1 equ ebp-68 ;dd ?
41
 
42
  mov ebp,esp
43
  sub esp,68
44
;if  Ext = MMX
45
;  emms
46
;end if
47
  mov edx,dword[.tex_x1]		  ; check all parameters
48
  or dx,dx
49
  jl .tt_end
50
  cmp dx,TEX_X-1
51
  jg .tt_end
52
  shr edx,16
53
  or dx,dx
54
  jl .tt_end
55
  cmp dx,TEX_Y-1
56
  jg .tt_end
57
 
58
  mov edx,dword[.tex_x2]
59
  or dx,dx
60
  jl .tt_end
61
  cmp dx,TEX_X-1
62
  jg .tt_end
63
  shr edx,16
64
  or dx,dx
65
  jl .tt_end
66
  cmp dx,TEX_Y-1
67
  jg .tt_end
68
 
69
  mov edx,dword[.tex_x3]
70
  or dx,dx
71
  jl .tt_end
72
  cmp dx,TEX_X-1
73
  jg .tt_end
74
  shr edx,16
75
  cmp dx,TEX_Y-1
76
  jg .tt_end
77
  or dx,dx
78
  jl .tt_end
79
 
80
  mov edx,eax	 ; check X&Y triangle coordinate
81
  or edx,ebx
82
  or edx,ecx
83
  test edx,80008000h
84
  jne .tt_end
6619 leency 85
  mov  dx,[size_x_var]
1245 hidnplayr 86
 ; or ax,ax
87
 ; jl .tt_end
6619 leency 88
;  cmp ax,SIZE_Y
89
;  jg .tt_end
1245 hidnplayr 90
  ror eax,16
91
 ; or ax,ax
92
 ; jl .tt_end
6619 leency 93
  cmp ax,dx  ;SIZE_X
1245 hidnplayr 94
  jg .tt_end
95
  rol eax,16
96
 
97
 ; or bx,bx
98
 ; jl .tt_end
6619 leency 99
;  cmp bx,SIZE_Y
100
;  jg .tt_end
1245 hidnplayr 101
  ror ebx,16
102
 ; or bx,bx
103
 ; jl .tt_end
6619 leency 104
  cmp bx,dx ;SIZE_X
1245 hidnplayr 105
  jg .tt_end
106
  rol ebx,16
107
 
108
 ; or cx,cx
109
 ; jl .tt_end
6619 leency 110
;  cmp cx,SIZE_Y
111
;  jg .tt_end
1245 hidnplayr 112
  ror ecx,16
113
 ; or cx,cx
114
 ; jl .tt_end
6619 leency 115
  cmp cx,dx  ;SIZE_X
1245 hidnplayr 116
  jg .tt_end
117
  rol ecx,16		       ; uff.. parameters was checked
118
 
119
  cmp ax,bx			    ;sort all parameters
120
  jle .tt_sort1
121
  xchg eax,ebx
122
  mov edx,dword [.tex_x1]
123
  xchg edx,dword [.tex_x2]
124
  mov dword[.tex_x1],edx
125
.tt_sort1:
126
  cmp ax,cx
127
  jle .tt_sort2
128
  xchg eax,ecx
129
  mov edx,dword [.tex_x1]
130
  xchg edx,dword [.tex_x3]
131
  mov dword [.tex_x1],edx
132
.tt_sort2:
133
  cmp bx,cx
134
  jle .tt_sort3
135
  xchg ebx,ecx
136
  mov edx,dword [.tex_x2]
137
  xchg edx,dword [.tex_x3]
138
  mov dword [.tex_x2],edx
139
.tt_sort3:
140
  mov [.y1],ax	   ; and store to user friendly variables
141
  shr eax,16
142
  mov [.x1],ax
143
  mov [.y2],bx
144
  shr ebx,16
145
  mov [.x2],bx
146
  mov [.y3],cx
147
  shr ecx,16
148
  mov [.x3],cx
149
  mov [.tex_ptr],esi
150
 
151
  movsx ebx,word[.y2]
152
  sub bx,[.y1]
153
  jnz .tt_dx12_make
154
 
155
  mov dword[.dx12],0
156
  mov dword[.tex_dx12],0
157
  mov dword[.tex_dy12],0
158
  jmp .tt_dx12_done
159
.tt_dx12_make:
160
  mov ax,[.x2]
161
  sub ax,[.x1]
162
  cwde
163
  shl eax,ROUND
164
  cdq
165
  idiv ebx
166
  mov [.dx12],eax				      ; dx12 = (x2-x1)/(y2-y1)
167
 
168
  mov ax,word[.tex_x2]
169
  sub ax,word[.tex_x1]
170
  cwde
171
  shl eax,ROUND
172
  cdq
173
  idiv ebx
174
  mov [.tex_dx12],eax			  ; tex_dx12 = (tex_x2-tex_x1)/(y2-y1)
175
 
176
  mov ax,word[.tex_y2]
177
  sub ax,word[.tex_y1]
178
  cwde
179
  shl eax,ROUND
180
  cdq
181
  idiv ebx
182
  mov [.tex_dy12],eax			  ; tex_dy12 = (tex_y2-tex_y1)/(y2-y1)
183
.tt_dx12_done:
184
 
185
  movsx ebx,word[.y3]
186
  sub bx,word[.y1]
187
  jnz .tt_dx13_make
188
 
189
  mov dword [.dx13],0
190
  mov dword [.tex_dx13],0
191
  mov dword [.tex_dy13],0
192
  jmp .tt_dx13_done
193
.tt_dx13_make:
194
  mov ax,[.x3]
195
  sub ax,[.x1]
196
  cwde
197
  shl eax,ROUND
198
  cdq
199
  idiv ebx
200
  mov [.dx13],eax				  ; dx13 = (x3-x1)/(y3-y1)
201
 
202
  mov ax,word[.tex_x3]
203
  sub ax,word[.tex_x1]
204
  cwde
205
  shl eax,ROUND
206
  cdq
207
  idiv ebx
208
  mov [.tex_dx13],eax			    ; tex_dx13 = (tex_x3-tex_x1)/(y3-y1)
209
 
210
  mov ax,word[.tex_y3]
211
  sub ax,word[.tex_y1]
212
  cwde
213
  shl eax,ROUND
214
  cdq
215
  idiv ebx
216
  mov [.tex_dy13],eax			    ; tex_dy13 = (tex_y3-tex_y1)/(y3-y1)
217
.tt_dx13_done:
218
 
219
  movsx ebx,word[.y3]
220
  sub bx,word[.y2]
221
  jnz .tt_dx23_make
222
 
223
  mov dword [.dx23],0
224
  mov dword [.tex_dx23],0
225
  mov dword [.tex_dy23],0
226
  jmp .tt_dx23_done
227
.tt_dx23_make:
228
  mov ax,[.x3]
229
  sub ax,[.x2]
230
  cwde
231
  shl eax,ROUND
232
  cdq
233
  idiv ebx
234
  mov [.dx23],eax				  ; dx23 = (x3-x2)/(y3-y2)
235
 
236
  mov ax,word[.tex_x3]
237
  sub ax,word[.tex_x2]
238
  cwde
239
  shl eax,ROUND
240
  cdq
241
  idiv ebx
242
  mov [.tex_dx23],eax			 ; tex_dx23 = (tex_x3-tex_x2)/(y3-y2)
243
 
244
  mov ax,word[.tex_y3]
245
  sub ax,word[.tex_y2]
246
  cwde
247
  shl eax,ROUND
248
  cdq
249
  idiv ebx
250
  mov [.tex_dy23],eax			; tex_dy23 = (tex_y3-tex_y2)/(y3-y2)
251
.tt_dx23_done:
252
 
253
  movsx eax,word[.x1]
254
  shl eax,ROUND
255
  mov ebx,eax
256
 
257
  movsx edx, word[.tex_x1]
258
  shl edx,ROUND
259
  mov [.scan_x1],edx
260
  mov [.scan_x2],edx
261
  movsx edx, word[.tex_y1]
262
  shl edx,ROUND
263
  mov [.scan_y1],edx
264
  mov [.scan_y2],edx
265
 
266
  mov cx,[.y1]
267
  cmp cx, [.y2]
268
  jge .tt_loop1_end
269
.tt_loop1:
270
  push edi
271
  push eax
272
  push ebx
273
  push cx
274
  push ebp
275
;; Madis
276
;if Ext=MMX                          ; With MMX enabled it reverse light vectors ????
277
;  mov   dword[esp-8],ROUND
278
;  mov   dword[esp-4],0 ; Is this a bug? Explanation down 3 lines
279
;  movq  mm0,qword[.scan_y1]
280
;  movq  mm1,qword[.scan_y2]
281
;  psrad mm0,[esp-8] ;This instr. won't allow modifiers BYTE, WORD, etc.
282
;  psrad mm1,[esp-8] ;It always defaults to QWORD
283
;  packssdw mm0,mm1
284
;  movq  [esp-8],mm0
285
;  sub   esp,8
286
;else
287
 
288
   push     dword[.scan_y2]  ; now I push variables on stack without shifting
289
   push     dword[.scan_x2]
290
   push     dword[.scan_y1]
291
   push     dword[.scan_x1]
292
 
293
;end if
294
 
295
 
296
 
297
  push	dword[.tex_ptr]
298
 
299
  push	cx
300
  mov	edx,ebx
301
  sar	edx,ROUND
302
  push	dx
303
  mov	edx,eax
304
  sar	edx,ROUND
305
  push	dx
306
  call	textured_line
307
 
308
  pop	ebp
309
  pop	cx
310
  pop	ebx
311
  pop	eax
312
  pop	edi
313
 
314
  mov	edx, [.tex_dx13]
315
  add	[.scan_x1], edx
316
  mov	edx, [.tex_dx12]
317
  add	[.scan_x2], edx
318
  mov	edx, [.tex_dy13]
319
  add	[.scan_y1], edx
320
  mov	edx, [.tex_dy12]
321
  add	[.scan_y2], edx
322
 
323
  add	eax, [.dx13]
324
  add	ebx, [.dx12]
325
  inc	cx
326
  cmp	cx,[.y2]
327
  jl	.tt_loop1
328
 
329
.tt_loop1_end:
330
 
331
 
332
  mov	cx, [.y2]
333
  cmp	cx, [.y3]
334
  jge	.tt_loop2_end
335
 
336
  movsx ebx,word[.x2]
337
  shl	ebx,ROUND
338
 
339
  movsx edx, word[.tex_x2]
340
  shl	edx,ROUND
341
  mov	[.scan_x2],edx
342
  movsx edx, word[.tex_y2]
343
  shl	edx,ROUND
344
  mov	[.scan_y2],edx
345
 
346
.tt_loop2:
347
  push	edi
348
  push	eax
349
  push	ebx
350
  push	cx
351
  push	ebp
352
;; Madis
353
;if Ext=MMX
354
;  mov   dword[esp-8],ROUND
355
;  mov   dword[esp-4],0 ; Is this a bug? Explanation down 3 lines
356
;  movq  mm0,qword[.scan_y1]
357
;  movq  mm1,qword[.scan_y2]
358
;  psrad mm0,[esp-8] ;This instr. won't allow modifiers BYTE, WORD, etc.
359
;  psrad mm1,[esp-8] ;It always defaults to QWORD
360
;  packssdw mm0,mm1
361
;  movq  [esp-8],mm0
362
;  sub   esp,8
363
;else
364
 
365
;end if
366
  push	dword[.scan_y2]
367
  push	dword[.scan_x2]
368
  push	dword[.scan_y1]
369
  push	dword[.scan_x1]
370
 
371
 
372
 
373
  push	dword[.tex_ptr]
374
 
375
  push	cx
376
  mov	edx,ebx
377
  sar	edx,ROUND
378
  push	dx
379
  mov	edx,eax
380
  sar	edx,ROUND
381
  push	dx
382
  call	textured_line
383
 
384
  pop	ebp
385
  pop	cx
386
  pop	ebx
387
  pop	eax
388
  pop	edi
389
 
390
  mov	edx, [.tex_dx13]
391
  add	[.scan_x1], edx
392
  mov	edx, [.tex_dx23]
393
  add	[.scan_x2], edx
394
  mov	edx, [.tex_dy13]
395
  add	[.scan_y1], edx
396
  mov	edx, [.tex_dy23]
397
  add	[.scan_y2], edx
398
 
399
  add	eax, [.dx13]
400
  add	ebx, [.dx23]
401
  inc	cx
402
  cmp	cx,[.y3]
403
  jl	.tt_loop2
404
 
405
.tt_loop2_end:
406
 
407
.tt_end:
408
 mov	esp,ebp
409
 
410
ret 12
411
 
412
 
413
textured_line:
414
;-----in -edi screen buffer pointer
415
;------------ stack:
416
  .x1 equ word [ebp+4]
417
  .x2 equ word [ebp+6]
418
  .y  equ word [ebp+8]
419
 
420
  .tex_ptr equ dword [ebp+10]
421
  .tex_x1  equ	[ebp+14]
422
  .tex_y1  equ	[ebp+18]
423
  .tex_x2  equ	[ebp+22]
424
  .tex_y2  equ	[ebp+26]
425
 
426
  .tex_dx equ ebp-4 ;dd ?
427
  .tex_dy equ ebp-8 ;dd ?
428
 
429
  mov	ebp,esp
430
  sub	esp,8
431
 
432
  mov	ax,.y
433
  or	ax,ax
434
  jl	.tl_quit
6619 leency 435
  mov	dx,[size_y_var]
436
  cmp	ax,dx ;SIZE_Y
1245 hidnplayr 437
  jg	.tl_quit
438
 
439
  mov	ax,.x1
440
  cmp	ax,.x2
441
  je	.tl_quit
442
  jl	.tl_ok
443
 
444
  xchg	ax,.x2
445
  mov	.x1,ax
446
 
447
if Ext >= MMX
448
  movq	  mm0,.tex_x1
449
  movq	  mm1,.tex_x2
450
  movq	  .tex_x2,mm0
451
  movq	  .tex_x1,mm1
452
 
453
else
454
 
455
  mov	eax,.tex_x1
456
  xchg	eax,.tex_x2
457
  mov	.tex_x1,eax
458
 
459
  mov	eax,.tex_y1
460
  xchg	eax,.tex_y2
461
  mov	.tex_y1,eax
462
 
463
end if
464
 
465
 .tl_ok:
466
 
467
  mov	ebx,edi
468
  movsx edi,.y
6619 leency 469
  movzx eax,word[size_x_var]
470
  lea	eax,[eax*3]
471
;  mov   eax,SIZE_X*3
1245 hidnplayr 472
  mul	edi
473
  mov	edi,eax
474
  movsx eax,.x1
475
  add	edi,eax
476
  shl	eax,1
477
  add	edi,eax
478
  add	edi,ebx
479
 
480
  mov	cx,.x2
481
  sub	cx,.x1
482
  movsx ecx,cx
483
 
484
  mov	eax,.tex_x2
485
  sub	eax,.tex_x1
486
  cdq
487
  idiv	ecx
488
  mov	[.tex_dx],eax		; tex_dx=(tex_x2-tex_x1)/(x2-x1)
489
 
490
  mov	eax,.tex_y2
491
  sub	eax,.tex_y1
492
  cdq
493
  idiv	ecx
494
  mov	[.tex_dy],eax		       ; tex_dy = (tex_y2-tex_y1)/(x2-x1)
495
 
496
  mov	eax,.tex_x1
497
  mov	ebx,.tex_y1
498
  cld
499
 .tl_loop:
500
  mov	edx,eax    ; eax - cur x
501
  mov	esi,ebx    ; ebx - cur y
502
  shr	edx,ROUND
503
  shr	esi,ROUND
504
 macro .fluent
505
 {
506
  push	eax
507
  push	edx
508
  mov	eax,TEX_X*3
509
  mul	esi
510
  mov	esi,eax
511
  pop	edx
512
  pop	eax
513
 }
514
 macro .shift
515
 {
516
  shl	esi,TEX_SHIFT
517
  lea	esi,[esi*3]
518
  ;push edx
519
  ;mov edx,esi
520
  ;shl esi,1
521
  ;add esi,edx
522
  ;pop edx
523
 }
524
  if TEX = FLUENTLY
525
    .fluent
526
  end if
527
  if TEX = SHIFTING
528
    .shift
529
  end if
530
  lea	edx,[edx*3]
531
  add	esi,edx
532
 ; shl edx,1
533
 ; add esi,edx
534
  add	esi,.tex_ptr
535
  movsd
536
  dec	edi
537
  add	eax,[.tex_dx]
538
  add	ebx,[.tex_dy]
539
  loop .tl_loop
540
 
541
 .tl_quit:
542
  mov esp,ebp
543
 
544
ret 18+8
545
;  .tex_dx dd ?
546
;  .tex_dy dd ?