Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2881 leency 1
;-procedure draws smooth shaded lines (I mean interpolation 24 bit--
2
;-color), with z coord interpolation--------------------------------
3
;-author: Maciej Guba (www.macgub.hekko.pl)-------------------------
4
;-in : -------------------------------------------------------------
5
;----- edi - pointer to screen buffer ------------------------------
6
;----- esi - pointer to Z buffer -----------------------------------
7
;------ constans : SIZE_X, SIZE_Y - screen width and height---------
8
;----------------- ROUND - fixed point shift------------------------
9
;------ other parameters via stack----------------------------------
10
smooth_line:
11
.x1  equ  ebp+4
12
.y1  equ  ebp+6
13
.z1  equ  ebp+8
14
.r1  equ  ebp+10
15
.g1  equ  ebp+12
16
.b1  equ  ebp+14
17
.x2  equ  ebp+16
18
.y2  equ  ebp+18
19
.z2  equ  ebp+20
20
.r2  equ  ebp+22
21
.g2  equ  ebp+24
22
.b2  equ  ebp+26
23
 
24
 
25
.line_lenght	equ ebp-2
26
.delta		equ ebp-6
27
.delta_x	equ ebp-10
28
.delta_y	equ ebp-14
29
.dr		equ ebp-18
30
.dg		equ ebp-22
31
.db		equ ebp-26
32
.dz		equ ebp-30
33
.cr		equ ebp-34
34
.cg		equ ebp-38
35
.cb		equ ebp-42
36
.cz		equ ebp-46
37
 
38
;.line_lenght    equ ebp-48
39
.screen 	equ ebp-52
40
.zbuffer	equ ebp-56
41
.ccoord 	equ ebp-60  ;current coordinate
42
.czbuf		equ ebp-64
43
.cscr		equ ebp-68
6619 leency 44
.xres		equ ebp-72
45
.yres		equ ebp-76
46
.xresm1 	equ ebp-80
47
.yresm1 	equ ebp-84
48
.xresp1 	equ ebp-88
49
.yresp1 	equ ebp-92
50
.xres3		equ ebp-96
51
.xres4		equ ebp-100
52
 
2881 leency 53
macro .update_cur_var
54
{
55
if Ext=NON
56
     mov	 ebx,[.dz]
57
     add	 [.cz],ebx
58
     mov	 ebx,[.dr]
59
     add	 [.cr],ebx
60
     mov	 ebx,[.dg]
61
     add	 [.cg],ebx
62
     mov	 ebx,[.db]
63
     add	 [.cb],ebx
64
elseif Ext=MMX
65
     movq	 mm0,[.cz]
66
     movq	 mm1,[.cg]
67
     paddd	 mm0,mm2 ;[.dz]
68
     paddd	 mm1,mm3 ;[.dg]
69
     movq	 [.cz],mm0
70
     movq	 [.cg],mm1
71
elseif Ext >= SSE2
2984 leency 72
;     movups      xmm1,[.cz]
2881 leency 73
     paddd	 xmm1,xmm0
2984 leency 74
;     movups      [.cz],xmm1
2881 leency 75
end if
76
}
77
macro .draw_pixel
78
{
79
    mov 	[esi],ebx	       ; actualize Z buffer
6769 IgorA 80
if Ext>=SSE2
2984 leency 81
    movaps	xmm7,xmm1 ;[.cb] ;;xmm1
82
    shufps	xmm7,xmm7,00111001b
83
    psrld	xmm7,ROUND
84
    packssdw	xmm7,xmm7
85
    packuswb	xmm7,xmm7
86
    pand	xmm7,xmm6 ;[.mask]
87
    movd	[edi],xmm7
88
else
2881 leency 89
 
90
    mov 	eax,[.cb]
91
    sar 	eax,ROUND
92
    mov 	[edi],al
93
;    and         eax,0x000000ff         ; clean unused bits
94
    mov 	ebx,[.cg]
95
    sar 	ebx,ROUND
96
    mov 	[edi+1],bl
97
;    mov         ah,bl
98
    mov 	edx,[.cr]
99
    sar 	edx,ROUND
100
    mov 	[edi+2],dl
2984 leency 101
end if
2881 leency 102
;    shl         ebx,16
103
;    or          eax,ebx
104
;    mov         [edi],eax
105
}
106
macro .sort
107
{
108
 
109
if Ext >= MMX
110
    movq	mm0,[.x1]
111
    movq	mm1,[.x2]
112
    movq	[.x1],mm1
113
    movq	[.x2],mm0
114
else
115
    mov 	edx,[.x1]
116
    xchg	edx,[.x2]
117
    mov 	[.x1],edx
118
    mov 	edx,[.z1]
119
    xchg	edx,[.z2]
120
    mov 	[.z1],edx
121
end if
122
    mov 	edx,[.g1]
123
    xchg	edx,[.g2]
124
    mov 	[.g1],edx
125
}
126
 
127
 
128
 
129
    emms
130
    mov 	ebp,esp
131
    sub 	esp,128
132
    mov 	eax,[.x1]      ; check if parameters exceedes screen area
133
    mov 	ebx,[.x2]
134
    or		eax,ebx
135
    test	eax,80008000h
136
    jne 	.end_line
6619 leency 137
    movzx	edx,word [size_x_var]
138
    mov 	[.xres],edx
6769 IgorA 139
    dec 	edx
6619 leency 140
    movzx	ecx,word [size_y_var]
141
    mov 	[.yres],ecx
6769 IgorA 142
    dec 	ecx
6619 leency 143
    cmp 	word[.x1],dx  ;SIZE_X
2881 leency 144
    jg		.end_line
6619 leency 145
    cmp 	word[.x2],dx  ;SIZE_X
2881 leency 146
    jg		.end_line
6619 leency 147
    cmp 	word[.y1],cx  ;SIZE_Y
2881 leency 148
    jg		.end_line
6619 leency 149
    cmp 	word[.y2],cx  ;SIZE_Y
2881 leency 150
    jg		.end_line
151
 
6619 leency 152
    mov 	edx,[.xres]
153
    shl 	edx,2
154
    mov 	[.xres4],edx
155
    shr 	edx,2
156
    lea 	edx,[edx*3]
157
    mov 	[.xres3],edx
158
    mov 	edx,[.xres]
159
    mov 	ecx,[.yres]
160
    dec 	edx
161
    dec 	ecx
162
    mov 	[.xresm1],edx
163
    mov 	[.yresm1],ecx
164
    add 	edx,2
165
    add 	ecx,2
166
    mov 	[.xresp1],edx
167
    mov 	[.yresp1],ecx
2881 leency 168
 
169
    mov 	[.screen],edi
170
    mov 	cx,[.x1]
171
    cmp 	cx,[.x2]
172
    je		.vertical_l
173
    mov 	cx,[.y1]
174
    cmp 	cx,[.y2]
175
    je		.horizontal_l
176
    mov 	ax,[.x1]
177
    sub 	ax,[.x2]
178
    cmp 	ax,0
179
    jg		@f
180
    neg 	ax    ; calc absolute value
181
 @@:
182
    mov 	[.delta_x],ax
183
    mov 	bx,[.y1]
184
    sub 	bx,[.y2]
185
    cmp 	bx,0
186
    jg		@f
187
    neg 	bx
188
 @@:
189
    mov 	[.delta_y],bx
190
    cmp 	ax,bx
191
    je		.deg45_l
192
    jl		.more_vertical_l
193
    jg		.more_horizon_l
194
    jmp 	.end_line
195
								  ;
196
.horizontal_l:
197
    mov 	ax,[.x1]
198
    mov 	bx,[.x2]
199
    cmp 	bx,ax
200
    jge 	@f
201
 
202
    .sort
203
@@:
204
 
205
    mov 	bx,[.x2]
206
    sub 	bx,[.x1]
207
    movsx	ebx,bx
208
    cmp 	ebx,0	 ;line lenght equql 0
209
    je		.end_line
210
    mov 	[.delta_x],ebx
211
 
212
    call	.calc_delta
213
 
6769 IgorA 214
    mov 	eax,[.xres]  ;SIZE_X
2881 leency 215
    movsx	ebx,word[.y1]
216
    mul 	ebx
217
    add 	esi,eax
218
    lea 	eax,[eax*3]
219
    add 	esi,eax
220
    add 	edi,eax
221
    movsx	eax,word[.x1]
222
    add 	esi,eax
223
    lea 	eax,[eax*3]
224
    add 	edi,eax
225
    add 	esi,eax
226
 
227
    mov 	ecx,[.delta_x]
228
 
229
    movsx	ebx,word[.r1]
230
    shl 	ebx,ROUND
231
    mov 	[.cr],ebx
232
    movsx	ebx,word[.g1]
233
    shl 	ebx,ROUND
234
    mov 	[.cg],ebx
235
    movsx	ebx,word[.b1]
236
    shl 	ebx,ROUND
237
    mov 	[.cb],ebx
238
    movsx	ebx,word[.z1]
239
    shl 	ebx,ROUND
240
    mov 	[.cz],ebx
2984 leency 241
if Ext = SSE2
242
    movups	xmm1,[.cz]
243
end if
2881 leency 244
.hdraw:
2984 leency 245
if Ext = SSE2
246
    movd	ebx,xmm1
247
else
2881 leency 248
    mov 	ebx,[.cz]
2984 leency 249
end if
2881 leency 250
    cmp 	[esi],ebx
251
    jle 	.skip
252
 
253
    .draw_pixel
254
 
255
.skip:
256
    add 	edi,3
257
    add 	esi,4
258
 
259
    .update_cur_var
260
 
261
    loop	.hdraw
262
    jmp 	.end_line
263
 
264
.vertical_l:
265
    mov 	ax,[.y1]
266
    cmp 	[.y2],ax
267
    jge 	@f
268
 
269
    .sort
270
@@:
271
    mov 	bx,[.y2]
272
    sub 	bx,[.y1]
273
    movsx	ebx,bx
274
    cmp 	ebx,0
275
    je		.end_line
276
    mov 	[.delta_y],ebx
277
 
278
    call	.calc_delta
279
 
6769 IgorA 280
    mov 	eax,[.xres]  ;SIZE_X
2881 leency 281
    movsx	ebx,word[.y1]
282
    mul 	ebx
283
    add 	esi,eax
284
    lea 	eax,[eax*3]
285
    add 	edi,eax
286
    add 	esi,eax
287
    movsx	eax,word[.x1]
288
    add 	esi,eax
289
    lea 	eax,[eax*3]
290
    add 	esi,eax
291
    add 	edi,eax
292
 
293
    mov 	ecx,[.delta_y]
294
 
295
    movsx	ebx,word[.r1]
296
    shl 	ebx,ROUND
297
    mov 	[.cr],ebx
298
    movsx	ebx,word[.g1]
299
    shl 	ebx,ROUND
300
    mov 	[.cg],ebx
301
    movsx	ebx,word[.b1]
302
    shl 	ebx,ROUND
303
    mov 	[.cb],ebx
304
    movsx	ebx,word[.z1]
305
    shl 	ebx,ROUND
306
    mov 	[.cz],ebx
2984 leency 307
if Ext = SSE2
308
    movups	xmm1,[.cz]
309
end if
310
 
2881 leency 311
.v_draw:
2984 leency 312
if Ext = SSE2
313
    movd	ebx,xmm1
314
else
2881 leency 315
    mov 	ebx,[.cz]
2984 leency 316
end if
2881 leency 317
    cmp 	[esi],ebx
318
    jle 	@f
319
 
320
    .draw_pixel
321
 
322
@@:
6619 leency 323
    add 	edi,[.xres3]
324
    add 	esi,[.xres4]
2881 leency 325
 
326
    .update_cur_var
327
 
328
    loop	.v_draw
329
    jmp 	.end_line
330
.deg45_l:
331
    mov 	word[.line_lenght],ax
332
    mov 	ax,[.x1]
333
    cmp 	[.x2],ax
334
    jge 	@f
335
 
336
    .sort
337
@@:
338
    mov 	bx,[.y2]
339
    sub 	bx,[.y1]
340
    movsx	ebx,bx
341
    cmp 	ebx,0
342
    je		.end_line
343
    mov 	[.delta_y],ebx
344
    mov 	bx,[.x2]
345
    sub 	bx,[.x1]
346
    movsx	ebx,bx
347
    mov 	[.delta_x],ebx
348
 
349
    call	.calc_delta
350
 
6619 leency 351
    mov 	eax,[.xres]
2881 leency 352
    movsx	ebx,word[.y1] ;calc begin values in screen and Z buffers
353
    mul 	ebx
354
    lea 	ebx,[3*eax]
355
    add 	edi,ebx
356
    shl 	eax,2
357
    add 	esi,eax
358
    movsx	eax,word[.x1]
359
    lea 	ebx,[eax*3]
360
    add 	edi,ebx
361
    shl 	eax,2
362
    add 	esi,eax
363
 
364
    movzx	ecx,word[.line_lenght]
365
 
366
    movsx	ebx,word[.r1]
367
    shl 	ebx,ROUND
368
    mov 	[.cr],ebx
369
    movsx	ebx,word[.g1]
370
    shl 	ebx,ROUND
371
    mov 	[.cg],ebx
372
    movsx	ebx,word[.b1]
373
    shl 	ebx,ROUND
374
    mov 	[.cb],ebx
375
    movsx	ebx,word[.z1]
376
    shl 	ebx,ROUND
377
    mov 	[.cz],ebx
378
.d45_draw:
2984 leency 379
if Ext = SSE2
380
    movd	ebx,xmm1
381
else
2881 leency 382
    mov 	ebx,[.cz]
2984 leency 383
end if
2881 leency 384
    cmp 	[esi],ebx
385
    jle 	@f
386
 
387
    .draw_pixel
388
 
389
@@:
390
    cmp 	dword[.delta_y],0
391
    jl		@f
6619 leency 392
    add 	edi,[.xres3]  ;SIZE_X*3+3
393
    add 	edi,3
394
    add 	esi,[.xres4]  ;SIZE_X*4+4
395
    add 	esi,4
2881 leency 396
    jmp 	.d45_1
397
@@:
6619 leency 398
    sub 	edi,[.xres3]  ;(SIZE_X*3)-3
399
    sub 	edi,3
400
    sub 	esi,[.xres4]  ;(SIZE_X*4)-4
401
    sub 	esi,4
2881 leency 402
.d45_1:
403
    .update_cur_var
404
 
405
    loop	.d45_draw
406
    jmp 	.end_line
407
 
408
.more_vertical_l:
409
    mov 	word[.line_lenght],bx
410
    mov 	ax,[.y1]
411
    cmp 	[.y2],ax
412
    jge 	@f
413
    .sort
414
@@:
415
    mov 	bx,[.y2]
416
    sub 	bx,[.y1]
417
    movsx	ebx,bx
418
    cmp 	ebx,0
419
    je		.end_line   ;=======================
420
    mov 	[.delta_y],ebx
421
 
422
    mov 	ax,[.x2]
423
    sub 	ax,[.x1]
424
    cwde
425
    shl 	eax,ROUND
426
    cdq
427
    idiv	ebx
428
    mov 	[.delta],eax
429
 
430
    call	.calc_delta
431
 
6619 leency 432
    mov 	eax,[.xres] ;SIZE_X
2881 leency 433
    movsx	ebx,word[.y1] ;calc begin values in screen and Z buffers
434
    mul 	ebx
435
    lea 	ebx,[3*eax]
436
    add 	esi,ebx
437
    add 	esi,eax
438
    add 	edi,ebx
439
    mov 	[.cscr],edi
440
    mov 	[.czbuf],esi
441
 
442
    movzx	ecx,word[.line_lenght]
443
 
444
    movsx	ebx,word[.r1]
445
    shl 	ebx,ROUND
446
    mov 	[.cr],ebx
447
    movsx	ebx,word[.g1]
448
    shl 	ebx,ROUND
449
    mov 	[.cg],ebx
450
    movsx	ebx,word[.b1]
451
    shl 	ebx,ROUND
452
    mov 	[.cb],ebx
453
    movsx	ebx,word[.z1]
454
    shl 	ebx,ROUND
455
    mov 	[.cz],ebx
2984 leency 456
if Ext = SSE2
457
    movups	xmm1,[.cz]
458
end if
2881 leency 459
    movsx	ebx,word[.x1]
460
    shl 	ebx,ROUND
461
    mov 	[.ccoord],ebx	 ; .ccoord -> x coordinate
462
.draw_m_v:
463
    mov 	edi,[.cscr]
464
    mov 	esi,[.czbuf]
465
    mov 	eax,[.ccoord]
466
    sar 	eax,ROUND
467
    lea 	ebx,[eax*3]
468
    add 	edi,ebx
469
    add 	esi,ebx
470
    add 	esi,eax
2984 leency 471
if Ext = SSE2
472
    movd	ebx,xmm1
473
else
2881 leency 474
    mov 	ebx,[.cz]
2984 leency 475
end if
2881 leency 476
    cmp 	[esi],ebx
477
    jle 	@f
478
 
479
    .draw_pixel
480
 
481
@@:
482
    mov 	eax,[.delta]
6619 leency 483
    mov 	ebx,[.xres3]
2881 leency 484
    add 	[.ccoord],eax
6619 leency 485
    mov 	eax,[.xres4]
486
    add 	dword[.cscr],ebx  ;SIZE_X*3  ;
487
    add 	dword[.czbuf],eax  ;SIZE_X*4
2881 leency 488
.d_m_v1:
489
 
490
    .update_cur_var
491
 
492
    dec 	ecx
493
    jnz 	.draw_m_v
494
    jmp 	.end_line
495
 
496
.more_horizon_l:
497
    mov 	word[.line_lenght],ax
498
    mov 	ax,[.x1]
499
    cmp 	[.x2],ax
500
    jge 	@f
501
 
502
    .sort
503
@@:
504
    mov 	bx,[.x2]
505
    sub 	bx,[.x1]
506
    movsx	ebx,bx
507
    cmp 	ebx,0;=======================
508
    je		.end_line
509
    mov 	[.delta_x],ebx
510
 
511
    mov 	ax,[.y2]
512
    sub 	ax,[.y1]
513
    cwde
514
    shl 	eax,ROUND
515
    cdq
516
    idiv	ebx
517
    mov 	[.delta],eax
518
 
519
    call	.calc_delta
520
 
521
 ;calc begin values in screen and Z buffers
522
    movsx	ebx,word[.x1]
523
    mov 	eax,ebx
524
    add 	esi,ebx
525
    lea 	ebx,[3*ebx]
526
    add 	esi,ebx
527
    add 	edi,ebx
528
    mov 	[.cscr],edi
529
    mov 	[.czbuf],esi
530
 
531
    movzx	ecx,word[.line_lenght]
532
 
533
    movsx	ebx,word[.r1]
534
    shl 	ebx,ROUND
535
    mov 	[.cr],ebx
536
    movsx	ebx,word[.g1]
537
    shl 	ebx,ROUND
538
    mov 	[.cg],ebx
539
    movsx	ebx,word[.b1]
540
    shl 	ebx,ROUND
541
    mov 	[.cb],ebx
542
    movsx	ebx,word[.z1]
543
    shl 	ebx,ROUND
544
    mov 	[.cz],ebx
2984 leency 545
if Ext = SSE2
546
    movups	xmm1,[.cz]
547
end if
2881 leency 548
    movsx	ebx,word[.y1]
549
    shl 	ebx,ROUND
550
    mov 	[.ccoord],ebx	 ; .ccoord -> y coordinate
551
 
552
.draw_m_h:
553
    mov 	edi,[.cscr]
554
    mov 	esi,[.czbuf]
555
    mov 	eax,[.ccoord]	 ; ccoord - cur y coordinate
556
    sar 	eax,ROUND
6619 leency 557
    mov 	ebx,[.xres]  ;SIZE_X
2881 leency 558
    mul 	ebx
559
    add 	esi,eax
560
    lea 	eax,[eax*3]
561
    add 	esi,eax
562
    add 	edi,eax
2984 leency 563
if Ext = SSE2
564
    movd	ebx,xmm1
565
else
2881 leency 566
    mov 	ebx,[.cz]
2984 leency 567
end if
2881 leency 568
    cmp 	[esi],ebx
569
    jle 	@f
570
 
571
    .draw_pixel
572
 
573
@@:
574
    mov 	eax,[.delta]
575
    add 	[.ccoord],eax
576
    add 	dword[.cscr],3	;
577
    add 	dword[.czbuf],4
578
 
579
    .update_cur_var
580
 
581
    dec 	ecx
582
    jnz 	.draw_m_h
583
 
584
.end_line:
585
     mov       esp,ebp
586
     ret       24
587
 
588
.calc_delta:
589
    mov 	ax,[.z2]
590
    sub 	ax,[.z1]
591
    cwde
592
    shl 	eax,ROUND
593
    cdq
594
    idiv	ebx
595
    mov 	[.dz],eax
596
 
597
    mov 	ax,[.r2]
598
    sub 	ax,[.r1]
599
    cwde
600
    shl 	eax,ROUND
601
    cdq
602
    idiv	ebx
603
    mov 	[.dr],eax
604
 
605
    mov 	ax,[.g2]
606
    sub 	ax,[.g1]
607
    cwde
608
    shl 	eax,ROUND
609
    cdq
610
    idiv	ebx
611
    mov 	[.dg],eax
612
 
613
    mov 	ax,[.b2]
614
    sub 	ax,[.b1]
615
    cwde
616
    shl 	eax,ROUND
617
    cdq
618
    idiv	ebx
619
    mov 	[.db],eax
620
if Ext=MMX | Ext = SSE
621
    movq	mm2,[.dz]
622
    movq	mm3,[.dg]
623
else if Ext >= SSE2
624
    movups	xmm0,[.dz]
2984 leency 625
    movups	xmm6,[.mask]
2881 leency 626
end if
627
ret
2984 leency 628
.mask:
629
	   dq 0xffffffff00ffffff
630
	   dq 0xffffffffffffffff
2881 leency 631