Subversion Repositories Kolibri OS

Rev

Details | 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
44
;.lasty          equ ebp-72
45
macro .update_cur_var
46
{
47
if Ext=NON
48
     mov	 ebx,[.dz]
49
     add	 [.cz],ebx
50
     mov	 ebx,[.dr]
51
     add	 [.cr],ebx
52
     mov	 ebx,[.dg]
53
     add	 [.cg],ebx
54
     mov	 ebx,[.db]
55
     add	 [.cb],ebx
56
elseif Ext=MMX
57
     movq	 mm0,[.cz]
58
     movq	 mm1,[.cg]
59
     paddd	 mm0,mm2 ;[.dz]
60
     paddd	 mm1,mm3 ;[.dg]
61
     movq	 [.cz],mm0
62
     movq	 [.cg],mm1
63
elseif Ext >= SSE2
64
     movups	 xmm1,[.cz]
65
     paddd	 xmm1,xmm0
66
     movups	 [.cz],xmm1
67
end if
68
}
69
macro .draw_pixel
70
{
71
    mov 	[esi],ebx	       ; actualize Z buffer
72
;if Ext=SSE2
73
;    movups      xmm2,[.cb]
74
   ; shufps      xmm1,xmm1,11000110b
75
   ; pand        xmm1,[.mask]
76
;    psrld       xmm2,ROUND
77
;    packssdw    xmm2,xmm2
78
;    packuswb    xmm2,xmm2
79
;    movss       [edi],xmm2
80
;else
81
 
82
    mov 	eax,[.cb]
83
    sar 	eax,ROUND
84
    mov 	[edi],al
85
;    and         eax,0x000000ff         ; clean unused bits
86
    mov 	ebx,[.cg]
87
    sar 	ebx,ROUND
88
    mov 	[edi+1],bl
89
;    mov         ah,bl
90
    mov 	edx,[.cr]
91
    sar 	edx,ROUND
92
    mov 	[edi+2],dl
93
;end if
94
;    shl         ebx,16
95
;    or          eax,ebx
96
;    mov         [edi],eax
97
}
98
macro .sort
99
{
100
 
101
if Ext >= MMX
102
    movq	mm0,[.x1]
103
    movq	mm1,[.x2]
104
    movq	[.x1],mm1
105
    movq	[.x2],mm0
106
else
107
    mov 	edx,[.x1]
108
    xchg	edx,[.x2]
109
    mov 	[.x1],edx
110
    mov 	edx,[.z1]
111
    xchg	edx,[.z2]
112
    mov 	[.z1],edx
113
end if
114
    mov 	edx,[.g1]
115
    xchg	edx,[.g2]
116
    mov 	[.g1],edx
117
}
118
 
119
 
120
 
121
    emms
122
    mov 	ebp,esp
123
    sub 	esp,128
124
    mov 	eax,[.x1]      ; check if parameters exceedes screen area
125
    mov 	ebx,[.x2]
126
    or		eax,ebx
127
    test	eax,80008000h
128
    jne 	.end_line
129
    cmp 	word[.x1],SIZE_X
130
    jg		.end_line
131
    cmp 	word[.x2],SIZE_X
132
    jg		.end_line
133
    cmp 	word[.y1],SIZE_Y
134
    jg		.end_line
135
    cmp 	word[.y2],SIZE_Y
136
    jg		.end_line
137
 
138
 
139
    mov 	[.screen],edi
140
    mov 	cx,[.x1]
141
    cmp 	cx,[.x2]
142
    je		.vertical_l
143
    mov 	cx,[.y1]
144
    cmp 	cx,[.y2]
145
    je		.horizontal_l
146
    mov 	ax,[.x1]
147
    sub 	ax,[.x2]
148
    cmp 	ax,0
149
    jg		@f
150
    neg 	ax    ; calc absolute value
151
 @@:
152
    mov 	[.delta_x],ax
153
    mov 	bx,[.y1]
154
    sub 	bx,[.y2]
155
    cmp 	bx,0
156
    jg		@f
157
    neg 	bx
158
 @@:
159
    mov 	[.delta_y],bx
160
    cmp 	ax,bx
161
    je		.deg45_l
162
    jl		.more_vertical_l
163
    jg		.more_horizon_l
164
    jmp 	.end_line
165
								  ;
166
.horizontal_l:
167
    mov 	ax,[.x1]
168
    mov 	bx,[.x2]
169
    cmp 	bx,ax
170
    jge 	@f
171
 
172
    .sort
173
@@:
174
 
175
    mov 	bx,[.x2]
176
    sub 	bx,[.x1]
177
    movsx	ebx,bx
178
    cmp 	ebx,0	 ;line lenght equql 0
179
    je		.end_line
180
    mov 	[.delta_x],ebx
181
 
182
    call	.calc_delta
183
 
184
    mov 	eax,SIZE_X
185
    movsx	ebx,word[.y1]
186
    mul 	ebx
187
    add 	esi,eax
188
    lea 	eax,[eax*3]
189
    add 	esi,eax
190
    add 	edi,eax
191
    movsx	eax,word[.x1]
192
    add 	esi,eax
193
    lea 	eax,[eax*3]
194
    add 	edi,eax
195
    add 	esi,eax
196
 
197
    mov 	ecx,[.delta_x]
198
 
199
    movsx	ebx,word[.r1]
200
    shl 	ebx,ROUND
201
    mov 	[.cr],ebx
202
    movsx	ebx,word[.g1]
203
    shl 	ebx,ROUND
204
    mov 	[.cg],ebx
205
    movsx	ebx,word[.b1]
206
    shl 	ebx,ROUND
207
    mov 	[.cb],ebx
208
    movsx	ebx,word[.z1]
209
    shl 	ebx,ROUND
210
    mov 	[.cz],ebx
211
.hdraw:
212
    mov 	ebx,[.cz]
213
    cmp 	[esi],ebx
214
    jle 	.skip
215
 
216
    .draw_pixel
217
 
218
.skip:
219
    add 	edi,3
220
    add 	esi,4
221
 
222
    .update_cur_var
223
 
224
    loop	.hdraw
225
    jmp 	.end_line
226
 
227
.vertical_l:
228
    mov 	ax,[.y1]
229
    cmp 	[.y2],ax
230
    jge 	@f
231
 
232
    .sort
233
@@:
234
    mov 	bx,[.y2]
235
    sub 	bx,[.y1]
236
    movsx	ebx,bx
237
    cmp 	ebx,0
238
    je		.end_line
239
    mov 	[.delta_y],ebx
240
 
241
    call	.calc_delta
242
 
243
    mov 	eax,SIZE_X
244
    movsx	ebx,word[.y1]
245
    mul 	ebx
246
    add 	esi,eax
247
    lea 	eax,[eax*3]
248
    add 	edi,eax
249
    add 	esi,eax
250
    movsx	eax,word[.x1]
251
    add 	esi,eax
252
    lea 	eax,[eax*3]
253
    add 	esi,eax
254
    add 	edi,eax
255
 
256
    mov 	ecx,[.delta_y]
257
 
258
    movsx	ebx,word[.r1]
259
    shl 	ebx,ROUND
260
    mov 	[.cr],ebx
261
    movsx	ebx,word[.g1]
262
    shl 	ebx,ROUND
263
    mov 	[.cg],ebx
264
    movsx	ebx,word[.b1]
265
    shl 	ebx,ROUND
266
    mov 	[.cb],ebx
267
    movsx	ebx,word[.z1]
268
    shl 	ebx,ROUND
269
    mov 	[.cz],ebx
270
.v_draw:
271
    mov 	ebx,[.cz]
272
    cmp 	[esi],ebx
273
    jle 	@f
274
 
275
    .draw_pixel
276
 
277
@@:
278
    add 	edi,SIZE_X*3
279
    add 	esi,SIZE_X*4
280
 
281
    .update_cur_var
282
 
283
    loop	.v_draw
284
    jmp 	.end_line
285
.deg45_l:
286
    mov 	word[.line_lenght],ax
287
    mov 	ax,[.x1]
288
    cmp 	[.x2],ax
289
    jge 	@f
290
 
291
    .sort
292
@@:
293
    mov 	bx,[.y2]
294
    sub 	bx,[.y1]
295
    movsx	ebx,bx
296
    cmp 	ebx,0
297
    je		.end_line
298
    mov 	[.delta_y],ebx
299
    mov 	bx,[.x2]
300
    sub 	bx,[.x1]
301
    movsx	ebx,bx
302
    mov 	[.delta_x],ebx
303
 
304
    call	.calc_delta
305
 
306
    mov 	eax,SIZE_X
307
    movsx	ebx,word[.y1] ;calc begin values in screen and Z buffers
308
    mul 	ebx
309
    lea 	ebx,[3*eax]
310
    add 	edi,ebx
311
    shl 	eax,2
312
    add 	esi,eax
313
    movsx	eax,word[.x1]
314
    lea 	ebx,[eax*3]
315
    add 	edi,ebx
316
    shl 	eax,2
317
    add 	esi,eax
318
 
319
    movzx	ecx,word[.line_lenght]
320
 
321
    movsx	ebx,word[.r1]
322
    shl 	ebx,ROUND
323
    mov 	[.cr],ebx
324
    movsx	ebx,word[.g1]
325
    shl 	ebx,ROUND
326
    mov 	[.cg],ebx
327
    movsx	ebx,word[.b1]
328
    shl 	ebx,ROUND
329
    mov 	[.cb],ebx
330
    movsx	ebx,word[.z1]
331
    shl 	ebx,ROUND
332
    mov 	[.cz],ebx
333
.d45_draw:
334
    mov 	ebx,[.cz]
335
    cmp 	[esi],ebx
336
    jle 	@f
337
 
338
    .draw_pixel
339
 
340
@@:
341
    cmp 	dword[.delta_y],0
342
    jl		@f
343
    add 	edi,SIZE_X*3+3
344
    add 	esi,SIZE_X*4+4
345
    jmp 	.d45_1
346
@@:
347
    sub 	edi,(SIZE_X*3)-3
348
    sub 	esi,(SIZE_X*4)-4
349
.d45_1:
350
    .update_cur_var
351
 
352
    loop	.d45_draw
353
    jmp 	.end_line
354
 
355
.more_vertical_l:
356
    mov 	word[.line_lenght],bx
357
    mov 	ax,[.y1]
358
    cmp 	[.y2],ax
359
    jge 	@f
360
    .sort
361
@@:
362
    mov 	bx,[.y2]
363
    sub 	bx,[.y1]
364
    movsx	ebx,bx
365
    cmp 	ebx,0
366
    je		.end_line   ;=======================
367
    mov 	[.delta_y],ebx
368
 
369
    mov 	ax,[.x2]
370
    sub 	ax,[.x1]
371
    cwde
372
    shl 	eax,ROUND
373
    cdq
374
    idiv	ebx
375
    mov 	[.delta],eax
376
 
377
    call	.calc_delta
378
 
379
    mov 	eax,SIZE_X
380
    movsx	ebx,word[.y1] ;calc begin values in screen and Z buffers
381
    mul 	ebx
382
    lea 	ebx,[3*eax]
383
    add 	esi,ebx
384
    add 	esi,eax
385
    add 	edi,ebx
386
    mov 	[.cscr],edi
387
    mov 	[.czbuf],esi
388
 
389
    movzx	ecx,word[.line_lenght]
390
 
391
    movsx	ebx,word[.r1]
392
    shl 	ebx,ROUND
393
    mov 	[.cr],ebx
394
    movsx	ebx,word[.g1]
395
    shl 	ebx,ROUND
396
    mov 	[.cg],ebx
397
    movsx	ebx,word[.b1]
398
    shl 	ebx,ROUND
399
    mov 	[.cb],ebx
400
    movsx	ebx,word[.z1]
401
    shl 	ebx,ROUND
402
    mov 	[.cz],ebx
403
    movsx	ebx,word[.x1]
404
    shl 	ebx,ROUND
405
    mov 	[.ccoord],ebx	 ; .ccoord -> x coordinate
406
.draw_m_v:
407
    mov 	edi,[.cscr]
408
    mov 	esi,[.czbuf]
409
    mov 	eax,[.ccoord]
410
    sar 	eax,ROUND
411
    lea 	ebx,[eax*3]
412
    add 	edi,ebx
413
    add 	esi,ebx
414
    add 	esi,eax
415
    mov 	ebx,[.cz]
416
    cmp 	[esi],ebx
417
    jle 	@f
418
 
419
    .draw_pixel
420
 
421
@@:
422
    mov 	eax,[.delta]
423
    add 	[.ccoord],eax
424
    add 	dword[.cscr],SIZE_X*3  ;
425
    add 	dword[.czbuf],SIZE_X*4
426
.d_m_v1:
427
 
428
    .update_cur_var
429
 
430
    dec 	ecx
431
    jnz 	.draw_m_v
432
    jmp 	.end_line
433
 
434
.more_horizon_l:
435
    mov 	word[.line_lenght],ax
436
    mov 	ax,[.x1]
437
    cmp 	[.x2],ax
438
    jge 	@f
439
 
440
    .sort
441
@@:
442
    mov 	bx,[.x2]
443
    sub 	bx,[.x1]
444
    movsx	ebx,bx
445
    cmp 	ebx,0;=======================
446
    je		.end_line
447
    mov 	[.delta_x],ebx
448
 
449
    mov 	ax,[.y2]
450
    sub 	ax,[.y1]
451
    cwde
452
    shl 	eax,ROUND
453
    cdq
454
    idiv	ebx
455
    mov 	[.delta],eax
456
 
457
    call	.calc_delta
458
 
459
 ;calc begin values in screen and Z buffers
460
    movsx	ebx,word[.x1]
461
    mov 	eax,ebx
462
    add 	esi,ebx
463
    lea 	ebx,[3*ebx]
464
    add 	esi,ebx
465
    add 	edi,ebx
466
    mov 	[.cscr],edi
467
    mov 	[.czbuf],esi
468
 
469
    movzx	ecx,word[.line_lenght]
470
 
471
    movsx	ebx,word[.r1]
472
    shl 	ebx,ROUND
473
    mov 	[.cr],ebx
474
    movsx	ebx,word[.g1]
475
    shl 	ebx,ROUND
476
    mov 	[.cg],ebx
477
    movsx	ebx,word[.b1]
478
    shl 	ebx,ROUND
479
    mov 	[.cb],ebx
480
    movsx	ebx,word[.z1]
481
    shl 	ebx,ROUND
482
    mov 	[.cz],ebx
483
    movsx	ebx,word[.y1]
484
    shl 	ebx,ROUND
485
    mov 	[.ccoord],ebx	 ; .ccoord -> y coordinate
486
 
487
.draw_m_h:
488
    mov 	edi,[.cscr]
489
    mov 	esi,[.czbuf]
490
    mov 	eax,[.ccoord]	 ; ccoord - cur y coordinate
491
    sar 	eax,ROUND
492
    mov 	ebx,SIZE_X
493
    mul 	ebx
494
    add 	esi,eax
495
    lea 	eax,[eax*3]
496
    add 	esi,eax
497
    add 	edi,eax
498
    mov 	ebx,[.cz]
499
    cmp 	[esi],ebx
500
    jle 	@f
501
 
502
    .draw_pixel
503
 
504
@@:
505
    mov 	eax,[.delta]
506
    add 	[.ccoord],eax
507
    add 	dword[.cscr],3	;
508
    add 	dword[.czbuf],4
509
 
510
    .update_cur_var
511
 
512
    dec 	ecx
513
    jnz 	.draw_m_h
514
 
515
.end_line:
516
     mov       esp,ebp
517
     ret       24
518
 
519
.calc_delta:
520
    mov 	ax,[.z2]
521
    sub 	ax,[.z1]
522
    cwde
523
    shl 	eax,ROUND
524
    cdq
525
    idiv	ebx
526
    mov 	[.dz],eax
527
 
528
    mov 	ax,[.r2]
529
    sub 	ax,[.r1]
530
    cwde
531
    shl 	eax,ROUND
532
    cdq
533
    idiv	ebx
534
    mov 	[.dr],eax
535
 
536
    mov 	ax,[.g2]
537
    sub 	ax,[.g1]
538
    cwde
539
    shl 	eax,ROUND
540
    cdq
541
    idiv	ebx
542
    mov 	[.dg],eax
543
 
544
    mov 	ax,[.b2]
545
    sub 	ax,[.b1]
546
    cwde
547
    shl 	eax,ROUND
548
    cdq
549
    idiv	ebx
550
    mov 	[.db],eax
551
if Ext=MMX | Ext = SSE
552
    movq	mm2,[.dz]
553
    movq	mm3,[.dg]
554
else if Ext >= SSE2
555
    movups	xmm0,[.dz]
556
end if
557
ret
558
;align 16
559
;.mask:
560
;           dq 0xffffffffffffffff
561
;           dq 0xffffffff00000000
562