Subversion Repositories Kolibri OS

Rev

Rev 2984 | 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
2984 leency 80
if Ext=SSE2
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
139
    movzx	ecx,word [size_y_var]
140
    mov 	[.yres],ecx
141
    cmp 	word[.x1],dx  ;SIZE_X
2881 leency 142
    jg		.end_line
6619 leency 143
    cmp 	word[.x2],dx  ;SIZE_X
2881 leency 144
    jg		.end_line
6619 leency 145
    cmp 	word[.y1],cx  ;SIZE_Y
2881 leency 146
    jg		.end_line
6619 leency 147
    cmp 	word[.y2],cx  ;SIZE_Y
2881 leency 148
    jg		.end_line
149
 
6619 leency 150
    mov 	edx,[.xres]
151
    shl 	edx,2
152
    mov 	[.xres4],edx
153
    shr 	edx,2
154
    lea 	edx,[edx*3]
155
    mov 	[.xres3],edx
156
    mov 	edx,[.xres]
157
    mov 	ecx,[.yres]
158
    dec 	edx
159
    dec 	ecx
160
    mov 	[.xresm1],edx
161
    mov 	[.yresm1],ecx
162
    add 	edx,2
163
    add 	ecx,2
164
    mov 	[.xresp1],edx
165
    mov 	[.yresp1],ecx
2881 leency 166
 
167
    mov 	[.screen],edi
168
    mov 	cx,[.x1]
169
    cmp 	cx,[.x2]
170
    je		.vertical_l
171
    mov 	cx,[.y1]
172
    cmp 	cx,[.y2]
173
    je		.horizontal_l
174
    mov 	ax,[.x1]
175
    sub 	ax,[.x2]
176
    cmp 	ax,0
177
    jg		@f
178
    neg 	ax    ; calc absolute value
179
 @@:
180
    mov 	[.delta_x],ax
181
    mov 	bx,[.y1]
182
    sub 	bx,[.y2]
183
    cmp 	bx,0
184
    jg		@f
185
    neg 	bx
186
 @@:
187
    mov 	[.delta_y],bx
188
    cmp 	ax,bx
189
    je		.deg45_l
190
    jl		.more_vertical_l
191
    jg		.more_horizon_l
192
    jmp 	.end_line
193
								  ;
194
.horizontal_l:
195
    mov 	ax,[.x1]
196
    mov 	bx,[.x2]
197
    cmp 	bx,ax
198
    jge 	@f
199
 
200
    .sort
201
@@:
202
 
203
    mov 	bx,[.x2]
204
    sub 	bx,[.x1]
205
    movsx	ebx,bx
206
    cmp 	ebx,0	 ;line lenght equql 0
207
    je		.end_line
208
    mov 	[.delta_x],ebx
209
 
210
    call	.calc_delta
211
 
6619 leency 212
    movzx	eax,word [size_x_var]  ;SIZE_X
2881 leency 213
    movsx	ebx,word[.y1]
214
    mul 	ebx
215
    add 	esi,eax
216
    lea 	eax,[eax*3]
217
    add 	esi,eax
218
    add 	edi,eax
219
    movsx	eax,word[.x1]
220
    add 	esi,eax
221
    lea 	eax,[eax*3]
222
    add 	edi,eax
223
    add 	esi,eax
224
 
225
    mov 	ecx,[.delta_x]
226
 
227
    movsx	ebx,word[.r1]
228
    shl 	ebx,ROUND
229
    mov 	[.cr],ebx
230
    movsx	ebx,word[.g1]
231
    shl 	ebx,ROUND
232
    mov 	[.cg],ebx
233
    movsx	ebx,word[.b1]
234
    shl 	ebx,ROUND
235
    mov 	[.cb],ebx
236
    movsx	ebx,word[.z1]
237
    shl 	ebx,ROUND
238
    mov 	[.cz],ebx
2984 leency 239
if Ext = SSE2
240
    movups	xmm1,[.cz]
241
end if
2881 leency 242
.hdraw:
2984 leency 243
if Ext = SSE2
244
    movd	ebx,xmm1
245
else
2881 leency 246
    mov 	ebx,[.cz]
2984 leency 247
end if
2881 leency 248
    cmp 	[esi],ebx
249
    jle 	.skip
250
 
251
    .draw_pixel
252
 
253
.skip:
254
    add 	edi,3
255
    add 	esi,4
256
 
257
    .update_cur_var
258
 
259
    loop	.hdraw
260
    jmp 	.end_line
261
 
262
.vertical_l:
263
    mov 	ax,[.y1]
264
    cmp 	[.y2],ax
265
    jge 	@f
266
 
267
    .sort
268
@@:
269
    mov 	bx,[.y2]
270
    sub 	bx,[.y1]
271
    movsx	ebx,bx
272
    cmp 	ebx,0
273
    je		.end_line
274
    mov 	[.delta_y],ebx
275
 
276
    call	.calc_delta
277
 
6619 leency 278
    movzx	eax,word[size_x_var]  ;SIZE_X
2881 leency 279
    movsx	ebx,word[.y1]
280
    mul 	ebx
281
    add 	esi,eax
282
    lea 	eax,[eax*3]
283
    add 	edi,eax
284
    add 	esi,eax
285
    movsx	eax,word[.x1]
286
    add 	esi,eax
287
    lea 	eax,[eax*3]
288
    add 	esi,eax
289
    add 	edi,eax
290
 
291
    mov 	ecx,[.delta_y]
292
 
293
    movsx	ebx,word[.r1]
294
    shl 	ebx,ROUND
295
    mov 	[.cr],ebx
296
    movsx	ebx,word[.g1]
297
    shl 	ebx,ROUND
298
    mov 	[.cg],ebx
299
    movsx	ebx,word[.b1]
300
    shl 	ebx,ROUND
301
    mov 	[.cb],ebx
302
    movsx	ebx,word[.z1]
303
    shl 	ebx,ROUND
304
    mov 	[.cz],ebx
2984 leency 305
if Ext = SSE2
306
    movups	xmm1,[.cz]
307
end if
308
 
2881 leency 309
.v_draw:
2984 leency 310
if Ext = SSE2
311
    movd	ebx,xmm1
312
else
2881 leency 313
    mov 	ebx,[.cz]
2984 leency 314
end if
2881 leency 315
    cmp 	[esi],ebx
316
    jle 	@f
317
 
318
    .draw_pixel
319
 
320
@@:
6619 leency 321
    add 	edi,[.xres3]
322
    add 	esi,[.xres4]
2881 leency 323
 
324
    .update_cur_var
325
 
326
    loop	.v_draw
327
    jmp 	.end_line
328
.deg45_l:
329
    mov 	word[.line_lenght],ax
330
    mov 	ax,[.x1]
331
    cmp 	[.x2],ax
332
    jge 	@f
333
 
334
    .sort
335
@@:
336
    mov 	bx,[.y2]
337
    sub 	bx,[.y1]
338
    movsx	ebx,bx
339
    cmp 	ebx,0
340
    je		.end_line
341
    mov 	[.delta_y],ebx
342
    mov 	bx,[.x2]
343
    sub 	bx,[.x1]
344
    movsx	ebx,bx
345
    mov 	[.delta_x],ebx
346
 
347
    call	.calc_delta
348
 
6619 leency 349
    mov 	eax,[.xres]
2881 leency 350
    movsx	ebx,word[.y1] ;calc begin values in screen and Z buffers
351
    mul 	ebx
352
    lea 	ebx,[3*eax]
353
    add 	edi,ebx
354
    shl 	eax,2
355
    add 	esi,eax
356
    movsx	eax,word[.x1]
357
    lea 	ebx,[eax*3]
358
    add 	edi,ebx
359
    shl 	eax,2
360
    add 	esi,eax
361
 
362
    movzx	ecx,word[.line_lenght]
363
 
364
    movsx	ebx,word[.r1]
365
    shl 	ebx,ROUND
366
    mov 	[.cr],ebx
367
    movsx	ebx,word[.g1]
368
    shl 	ebx,ROUND
369
    mov 	[.cg],ebx
370
    movsx	ebx,word[.b1]
371
    shl 	ebx,ROUND
372
    mov 	[.cb],ebx
373
    movsx	ebx,word[.z1]
374
    shl 	ebx,ROUND
375
    mov 	[.cz],ebx
376
.d45_draw:
2984 leency 377
if Ext = SSE2
378
    movd	ebx,xmm1
379
else
2881 leency 380
    mov 	ebx,[.cz]
2984 leency 381
end if
2881 leency 382
    cmp 	[esi],ebx
383
    jle 	@f
384
 
385
    .draw_pixel
386
 
387
@@:
388
    cmp 	dword[.delta_y],0
389
    jl		@f
6619 leency 390
    add 	edi,[.xres3]  ;SIZE_X*3+3
391
    add 	edi,3
392
    add 	esi,[.xres4]  ;SIZE_X*4+4
393
    add 	esi,4
2881 leency 394
    jmp 	.d45_1
395
@@:
6619 leency 396
    sub 	edi,[.xres3]  ;(SIZE_X*3)-3
397
    sub 	edi,3
398
    sub 	esi,[.xres4]  ;(SIZE_X*4)-4
399
    sub 	esi,4
2881 leency 400
.d45_1:
401
    .update_cur_var
402
 
403
    loop	.d45_draw
404
    jmp 	.end_line
405
 
406
.more_vertical_l:
407
    mov 	word[.line_lenght],bx
408
    mov 	ax,[.y1]
409
    cmp 	[.y2],ax
410
    jge 	@f
411
    .sort
412
@@:
413
    mov 	bx,[.y2]
414
    sub 	bx,[.y1]
415
    movsx	ebx,bx
416
    cmp 	ebx,0
417
    je		.end_line   ;=======================
418
    mov 	[.delta_y],ebx
419
 
420
    mov 	ax,[.x2]
421
    sub 	ax,[.x1]
422
    cwde
423
    shl 	eax,ROUND
424
    cdq
425
    idiv	ebx
426
    mov 	[.delta],eax
427
 
428
    call	.calc_delta
429
 
6619 leency 430
    mov 	eax,[.xres] ;SIZE_X
2881 leency 431
    movsx	ebx,word[.y1] ;calc begin values in screen and Z buffers
432
    mul 	ebx
433
    lea 	ebx,[3*eax]
434
    add 	esi,ebx
435
    add 	esi,eax
436
    add 	edi,ebx
437
    mov 	[.cscr],edi
438
    mov 	[.czbuf],esi
439
 
440
    movzx	ecx,word[.line_lenght]
441
 
442
    movsx	ebx,word[.r1]
443
    shl 	ebx,ROUND
444
    mov 	[.cr],ebx
445
    movsx	ebx,word[.g1]
446
    shl 	ebx,ROUND
447
    mov 	[.cg],ebx
448
    movsx	ebx,word[.b1]
449
    shl 	ebx,ROUND
450
    mov 	[.cb],ebx
451
    movsx	ebx,word[.z1]
452
    shl 	ebx,ROUND
453
    mov 	[.cz],ebx
2984 leency 454
if Ext = SSE2
455
    movups	xmm1,[.cz]
456
end if
2881 leency 457
    movsx	ebx,word[.x1]
458
    shl 	ebx,ROUND
459
    mov 	[.ccoord],ebx	 ; .ccoord -> x coordinate
460
.draw_m_v:
461
    mov 	edi,[.cscr]
462
    mov 	esi,[.czbuf]
463
    mov 	eax,[.ccoord]
464
    sar 	eax,ROUND
465
    lea 	ebx,[eax*3]
466
    add 	edi,ebx
467
    add 	esi,ebx
468
    add 	esi,eax
2984 leency 469
if Ext = SSE2
470
    movd	ebx,xmm1
471
else
2881 leency 472
    mov 	ebx,[.cz]
2984 leency 473
end if
2881 leency 474
    cmp 	[esi],ebx
475
    jle 	@f
476
 
477
    .draw_pixel
478
 
479
@@:
480
    mov 	eax,[.delta]
6619 leency 481
    mov 	ebx,[.xres3]
2881 leency 482
    add 	[.ccoord],eax
6619 leency 483
    mov 	eax,[.xres4]
484
    add 	dword[.cscr],ebx  ;SIZE_X*3  ;
485
    add 	dword[.czbuf],eax  ;SIZE_X*4
2881 leency 486
.d_m_v1:
487
 
488
    .update_cur_var
489
 
490
    dec 	ecx
491
    jnz 	.draw_m_v
492
    jmp 	.end_line
493
 
494
.more_horizon_l:
495
    mov 	word[.line_lenght],ax
496
    mov 	ax,[.x1]
497
    cmp 	[.x2],ax
498
    jge 	@f
499
 
500
    .sort
501
@@:
502
    mov 	bx,[.x2]
503
    sub 	bx,[.x1]
504
    movsx	ebx,bx
505
    cmp 	ebx,0;=======================
506
    je		.end_line
507
    mov 	[.delta_x],ebx
508
 
509
    mov 	ax,[.y2]
510
    sub 	ax,[.y1]
511
    cwde
512
    shl 	eax,ROUND
513
    cdq
514
    idiv	ebx
515
    mov 	[.delta],eax
516
 
517
    call	.calc_delta
518
 
519
 ;calc begin values in screen and Z buffers
520
    movsx	ebx,word[.x1]
521
    mov 	eax,ebx
522
    add 	esi,ebx
523
    lea 	ebx,[3*ebx]
524
    add 	esi,ebx
525
    add 	edi,ebx
526
    mov 	[.cscr],edi
527
    mov 	[.czbuf],esi
528
 
529
    movzx	ecx,word[.line_lenght]
530
 
531
    movsx	ebx,word[.r1]
532
    shl 	ebx,ROUND
533
    mov 	[.cr],ebx
534
    movsx	ebx,word[.g1]
535
    shl 	ebx,ROUND
536
    mov 	[.cg],ebx
537
    movsx	ebx,word[.b1]
538
    shl 	ebx,ROUND
539
    mov 	[.cb],ebx
540
    movsx	ebx,word[.z1]
541
    shl 	ebx,ROUND
542
    mov 	[.cz],ebx
2984 leency 543
if Ext = SSE2
544
    movups	xmm1,[.cz]
545
end if
2881 leency 546
    movsx	ebx,word[.y1]
547
    shl 	ebx,ROUND
548
    mov 	[.ccoord],ebx	 ; .ccoord -> y coordinate
549
 
550
.draw_m_h:
551
    mov 	edi,[.cscr]
552
    mov 	esi,[.czbuf]
553
    mov 	eax,[.ccoord]	 ; ccoord - cur y coordinate
554
    sar 	eax,ROUND
6619 leency 555
    mov 	ebx,[.xres]  ;SIZE_X
2881 leency 556
    mul 	ebx
557
    add 	esi,eax
558
    lea 	eax,[eax*3]
559
    add 	esi,eax
560
    add 	edi,eax
2984 leency 561
if Ext = SSE2
562
    movd	ebx,xmm1
563
else
2881 leency 564
    mov 	ebx,[.cz]
2984 leency 565
end if
2881 leency 566
    cmp 	[esi],ebx
567
    jle 	@f
568
 
569
    .draw_pixel
570
 
571
@@:
572
    mov 	eax,[.delta]
573
    add 	[.ccoord],eax
574
    add 	dword[.cscr],3	;
575
    add 	dword[.czbuf],4
576
 
577
    .update_cur_var
578
 
579
    dec 	ecx
580
    jnz 	.draw_m_h
581
 
582
.end_line:
583
     mov       esp,ebp
584
     ret       24
585
 
586
.calc_delta:
587
    mov 	ax,[.z2]
588
    sub 	ax,[.z1]
589
    cwde
590
    shl 	eax,ROUND
591
    cdq
592
    idiv	ebx
593
    mov 	[.dz],eax
594
 
595
    mov 	ax,[.r2]
596
    sub 	ax,[.r1]
597
    cwde
598
    shl 	eax,ROUND
599
    cdq
600
    idiv	ebx
601
    mov 	[.dr],eax
602
 
603
    mov 	ax,[.g2]
604
    sub 	ax,[.g1]
605
    cwde
606
    shl 	eax,ROUND
607
    cdq
608
    idiv	ebx
609
    mov 	[.dg],eax
610
 
611
    mov 	ax,[.b2]
612
    sub 	ax,[.b1]
613
    cwde
614
    shl 	eax,ROUND
615
    cdq
616
    idiv	ebx
617
    mov 	[.db],eax
618
if Ext=MMX | Ext = SSE
619
    movq	mm2,[.dz]
620
    movq	mm3,[.dg]
621
else if Ext >= SSE2
622
    movups	xmm0,[.dz]
2984 leency 623
    movups	xmm6,[.mask]
2881 leency 624
end if
625
ret
2984 leency 626
.mask:
627
	   dq 0xffffffff00ffffff
628
	   dq 0xffffffffffffffff
2881 leency 629