Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1245 hidnplayr 1
;------- Big thanks to majuma (www.majuma.xt.pl) for absolutelly great--
2
;------- 13h mode demos ------------------------------------------------
3
 
4
bump_triangle:
5
;------------------in - eax - x1 shl 16 + y1 -----------
6
;---------------------- ebx - x2 shl 16 + y2 -----------
7
;---------------------- ecx - x3 shl 16 + y3 -----------
8
;---------------------- edx - pointer to bump map ------
9
;---------------------- esi - pointer to environment map
10
;---------------------- edi - pointer to screen buffer--
11
;---------------------- stack : bump coordinates--------
12
;----------------------         environment coordinates-
13
.b_x1 equ ebp+4     ; procedure don't save registers !!!
14
.b_y1 equ ebp+6     ; each coordinate as word
15
.b_x2 equ ebp+8
16
.b_y2 equ ebp+10
17
.b_x3 equ ebp+12
18
.b_y3 equ ebp+14
19
.e_x1 equ ebp+16
20
.e_y1 equ ebp+18
21
.e_x2 equ ebp+20
22
.e_y2 equ ebp+22
23
.e_x3 equ ebp+24
24
.e_y3 equ ebp+26
25
 
26
.t_bmap equ dword[ebp-4]
27
.t_emap equ dword[ebp-8]
28
.x1	equ word[ebp-10]
29
.y1	equ word[ebp-12]
30
.x2	equ word[ebp-14]
31
.y2	equ word[ebp-16]
32
.x3	equ word[ebp-18]
33
.y3	equ word[ebp-20]
34
 
35
.dx12  equ dword[ebp-24]
36
.dbx12 equ dword[ebp-28]
37
.dby12 equ dword[ebp-32]
38
.dex12 equ dword[ebp-36]
39
.dey12 equ dword[ebp-40]
40
 
41
.dx13  equ dword[ebp-44]
42
.dbx13 equ dword[ebp-48]
43
.dby13 equ dword[ebp-52]
44
.dex13 equ dword[ebp-56]
45
.dey13 equ dword[ebp-60]
46
 
47
.dx23  equ dword[ebp-64]
48
.dbx23 equ dword[ebp-68]
49
.dby23 equ dword[ebp-72]
50
.dex23 equ dword[ebp-76]
51
.dey23 equ dword[ebp-80]
52
 
53
.cx1   equ dword[ebp-84]   ; current variables
54
.cx2   equ dword[ebp-88]
55
.cbx1  equ dword[ebp-92]
56
.cbx2  equ dword[ebp-96]
57
.cby1  equ dword[ebp-100]
58
.cby2  equ dword[ebp-104]
59
.cex1  equ dword[ebp-108]
60
.cex2  equ dword[ebp-112]
61
.cey1  equ dword[ebp-116]
62
.cey2  equ dword[ebp-120]
63
 
64
       mov     ebp,esp
65
       push    edx	  ; store bump map
66
       push    esi	  ; store e. map
67
     ; sub     esp,120
68
 .sort3:		  ; sort triangle coordinates...
69
       cmp     ax,bx
70
       jle     .sort1
71
       xchg    eax,ebx
72
       mov     edx,dword[.b_x1]
73
       xchg    edx,dword[.b_x2]
74
       mov     dword[.b_x1],edx
75
       mov     edx,dword[.e_x1]
76
       xchg    edx,dword[.e_x2]
77
       mov     dword[.e_x1],edx
78
 .sort1:
79
       cmp	bx,cx
80
       jle	.sort2
81
       xchg	ebx,ecx
82
       mov	edx,dword[.b_x2]
83
       xchg	edx,dword[.b_x3]
84
       mov	dword[.b_x2],edx
85
       mov	edx,dword[.e_x2]
86
       xchg	edx,dword[.e_x3]
87
       mov	dword[.e_x2],edx
88
       jmp	.sort3
89
 .sort2:
90
       push	eax	; store triangle coords in variables
91
       push	ebx
92
       push	ecx
93
 
94
       mov     edx,eax	       ; eax,ebx,ecx are ORd together into edx which means that
95
       or      edx,ebx	       ; if any *one* of them is negative a sign flag is raised
96
       or      edx,ecx
97
       test    edx,80000000h   ; Check only X
98
       jne     .loop23_done
99
 
100
       cmp     .x1,SIZE_X    ; {
101
       jg      .loop23_done
102
       cmp     .x2,SIZE_X     ; This can be optimized with effort
103
       jg      .loop23_done
104
       cmp     .x3,SIZE_X
105
       jg      .loop23_done    ; {
106
 
107
 
108
       mov	bx,.y2	     ; calc delta 12
109
       sub	bx,.y1
110
       jnz	.bt_dx12_make
111
       mov	ecx,5
112
       xor	edx,edx
113
     @@:
114
       push	edx   ;dword 0
115
       loop	@b
116
       jmp	.bt_dx12_done
117
 .bt_dx12_make:
118
       mov	ax,.x2
119
       sub	ax,.x1
120
       cwde
121
       movsx	ebx,bx
122
       shl	eax,ROUND
123
       cdq
124
       idiv	ebx
125
 ;      mov      .dx12,eax
126
       push	 eax
127
 
128
       mov	ax,word[.b_x2]
129
       sub	ax,word[.b_x1]
130
       cwde
131
       shl	eax,ROUND
132
       cdq
133
       idiv	ebx
134
 ;      mov      .dbx12,eax
135
       push	 eax
136
 
137
       mov	ax,word[.b_y2]
138
       sub	ax,word[.b_y1]
139
       cwde
140
       shl	eax,ROUND
141
       cdq
142
       idiv	ebx
143
 ;      mov      .dby12,eax
144
       push	 eax
145
 
146
       mov	ax,word[.e_x2]
147
       sub	ax,word[.e_x1]
148
       cwde
149
       shl	eax,ROUND
150
       cdq
151
       idiv	ebx
152
 ;      mov      .dex12,eax
153
       push	 eax
154
 
155
       mov	ax,word[.e_y2]
156
       sub	ax,word[.e_y1]
157
       cwde
158
       shl	eax,ROUND
159
       cdq
160
       idiv	ebx
161
 ;      mov      .dey12,eax
162
       push	 eax
163
   .bt_dx12_done:
164
 
165
       mov	bx,.y3	     ; calc delta13
166
       sub	bx,.y1
167
       jnz	.bt_dx13_make
168
       mov	ecx,5
169
       xor	edx,edx
170
     @@:
171
       push	edx   ;dword 0
172
       loop	@b
173
       jmp	.bt_dx13_done
174
 .bt_dx13_make:
175
       mov	ax,.x3
176
       sub	ax,.x1
177
       cwde
178
       movsx	ebx,bx
179
       shl	eax,ROUND
180
       cdq
181
       idiv	ebx
182
 ;      mov      .dx13,eax
183
       push	 eax
184
 
185
       mov	ax,word[.b_x3]
186
       sub	ax,word[.b_x1]
187
       cwde
188
       shl	eax,ROUND
189
       cdq
190
       idiv	ebx
191
 ;      mov      .dbx13,eax
192
       push	 eax
193
 
194
       mov	ax,word[.b_y3]
195
       sub	ax,word[.b_y1]
196
       cwde
197
       shl	eax,ROUND
198
       cdq
199
       idiv	ebx
200
 ;      mov      .dby13,eax
201
       push	 eax
202
 
203
       mov	ax,word[.e_x3]
204
       sub	ax,word[.e_x1]
205
       cwde
206
       shl	eax,ROUND
207
       cdq
208
       idiv	ebx
209
 ;      mov      .dex13,eax
210
       push	 eax
211
 
212
       mov	ax,word[.e_y3]
213
       sub	ax,word[.e_y1]
214
       cwde
215
       shl	eax,ROUND
216
       cdq
217
       idiv	ebx
218
 ;      mov      .dey13,eax
219
       push	 eax
220
   .bt_dx13_done:
221
 
222
       mov	bx,.y3	     ; calc delta23
223
       sub	bx,.y2
224
       jnz	.bt_dx23_make
225
       mov	ecx,5
226
       xor	edx,edx
227
     @@:
228
       push	edx   ;dword 0
229
       loop	@b
230
       jmp	.bt_dx23_done
231
 .bt_dx23_make:
232
       mov	ax,.x3
233
       sub	ax,.x2
234
       cwde
235
       movsx	ebx,bx
236
       shl	eax,ROUND
237
       cdq
238
       idiv	ebx
239
 ;      mov      .dx23,eax
240
       push	 eax
241
 
242
       mov	ax,word[.b_x3]
243
       sub	ax,word[.b_x2]
244
       cwde
245
       shl	eax,ROUND
246
       cdq
247
       idiv	ebx
248
 ;      mov      .dbx23,eax
249
       push	 eax
250
 
251
       mov	ax,word[.b_y3]
252
       sub	ax,word[.b_y2]
253
       cwde
254
       shl	eax,ROUND
255
       cdq
256
       idiv	ebx
257
 ;      mov      .dby23,eax
258
       push	 eax
259
 
260
       mov	ax,word[.e_x3]
261
       sub	ax,word[.e_x2]
262
       cwde
263
       shl	eax,ROUND
264
       cdq
265
       idiv	ebx
266
 ;      mov      .dex23,eax
267
       push	 eax
268
 
269
       mov	ax,word[.e_y3]
270
       sub	ax,word[.e_y2]
271
       cwde
272
       shl	eax,ROUND
273
       cdq
274
       idiv	ebx
275
 ;      mov      .dey23,eax
276
       push	 eax
277
 
278
      ;  sub     esp,40
279
   .bt_dx23_done:
280
 
281
       movsx	eax,.x1
282
       shl	eax,ROUND
283
     ; mov      .cx1,eax
284
     ; mov      .cx2,eax
285
       push	eax
286
       push	eax
287
 
288
       movsx	eax,word[.b_x1]
289
       shl	eax,ROUND
290
     ; mov      .cbx1,eax
291
     ; mov      .cbx2,eax
292
       push	eax
293
       push	eax
294
 
295
       movsx	eax,word[.b_y1]
296
       shl	eax,ROUND
297
     ; mov      .cby1,eax
298
     ; mov      .cby2,eax
299
       push	eax
300
       push	eax
301
 
302
       movsx	eax,word[.e_x1]
303
       shl	eax,ROUND
304
      ;mov      .cex1,eax
305
      ;mov      .cex2,eax
306
       push	eax
307
       push	eax
308
 
309
       movsx	eax,word[.e_y1]
310
       shl	eax,ROUND
311
      ;mov      .cey1,eax
312
      ;mov      .cey2,eax
313
       push	eax
314
       push	eax
315
 
316
       movzx	ecx,.y1
317
       cmp	cx,.y2
318
       jge	.loop12_done
319
  .loop12:
320
       call	.call_bump_line
321
 
322
       mov	eax,.dx13
323
       add	.cx1,eax
324
       mov	eax,.dx12
325
       add	.cx2,eax
326
 
327
       mov	eax,.dbx13
328
       add	.cbx1,eax
329
       mov	eax,.dbx12
330
       add	.cbx2,eax
331
       mov	eax,.dby13
332
       add	.cby1,eax
333
       mov	eax,.dby12
334
       add	.cby2,eax
335
 
336
       mov	eax,.dex13
337
       add	.cex1,eax
338
       mov	eax,.dex12
339
       add	.cex2,eax
340
       mov	eax,.dey13
341
       add	.cey1,eax
342
       mov	eax,.dey12
343
       add	.cey2,eax
344
 
345
       inc	ecx
346
       cmp	cx,.y2
347
       jl	.loop12
348
   .loop12_done:
349
       movzx	ecx,.y2
350
       cmp	cx,.y3
351
       jge	.loop23_done
352
 
353
       movzx	eax,.x2
354
       shl	eax,ROUND
355
       mov	.cx2,eax
356
 
357
       movzx	eax,word[.b_x2]
358
       shl	eax,ROUND
359
       mov	.cbx2,eax
360
 
361
       movzx	eax,word[.b_y2]
362
       shl	eax,ROUND
363
       mov	.cby2,eax
364
 
365
       movzx	eax,word[.e_x2]
366
       shl	eax,ROUND
367
       mov	.cex2,eax
368
 
369
       movzx	eax,word[.e_y2]
370
       shl	eax,ROUND
371
       mov	.cey2,eax
372
 
373
     .loop23:
374
       call	.call_bump_line
375
 
376
       mov	eax,.dx13
377
       add	.cx1,eax
378
       mov	eax,.dx23
379
       add	.cx2,eax
380
 
381
       mov	eax,.dbx13
382
       add	.cbx1,eax
383
       mov	eax,.dbx23
384
       add	.cbx2,eax
385
       mov	eax,.dby13
386
       add	.cby1,eax
387
       mov	eax,.dby23
388
       add	.cby2,eax
389
 
390
       mov	eax,.dex13
391
       add	.cex1,eax
392
       mov	eax,.dex23
393
       add	.cex2,eax
394
       mov	eax,.dey13
395
       add	.cey1,eax
396
       mov	eax,.dey23
397
       add	.cey2,eax
398
 
399
       inc	ecx
400
       cmp	cx,.y3
401
       jl	.loop23
402
    .loop23_done:
403
       mov	esp,ebp
404
ret   24
405
 
406
.call_bump_line:
407
 
408
      ; push     ebp
409
      ; push     ecx
410
       pushad
411
 
412
       push	.t_emap
413
       push	.t_bmap
414
       push	.cey2
415
       push	.cex2
416
       push	.cey1
417
       push	.cex1
418
       push	.cby2
419
       push	.cbx2
420
       push	.cby1
421
       push	.cbx1
422
       push	ecx
423
 
424
       mov	eax,.cx1
425
       sar	eax,ROUND
426
       mov	ebx,.cx2
427
       sar	ebx,ROUND
428
 
429
       call	bump_line
430
 
431
       popad
432
ret
433
bump_line:
434
;--------------in: eax - x1
435
;--------------    ebx - x2
436
;--------------    edi - pointer to screen buffer
437
;stack - another parameters :
438
.y    equ dword [ebp+4]
439
.bx1  equ dword [ebp+8]   ;   ---
440
.by1  equ dword [ebp+12]  ;       |
441
.bx2  equ dword [ebp+16]  ;       |
442
.by2  equ dword [ebp+20]  ;       |>   bump and env coords
443
.ex1  equ dword [ebp+24]  ;       |>   shifted shl ROUND
444
.ey1  equ dword [ebp+28]  ;       |
445
.ex2  equ dword [ebp+32]  ;       |
446
.ey2  equ dword [ebp+36]  ;   ---
447
.bmap equ dword [ebp+40]
448
.emap equ dword [ebp+44]
449
 
450
.x1   equ dword [ebp-4]
451
.x2   equ dword [ebp-8]
452
.dbx  equ dword [ebp-12]
453
.dby  equ dword [ebp-16]
454
.dex  equ dword [ebp-20]
455
.dey  equ dword [ebp-24]
456
.cbx  equ dword [ebp-28]
457
.cby  equ dword [ebp-32]
458
.cex  equ dword [ebp-36]
459
.cey  equ dword [ebp-40]
460
	mov	ebp,esp
461
 
462
	mov	ecx,.y
463
	or	ecx,ecx
464
	jl	.bl_end
465
	cmp	ecx,SIZE_Y
466
	jge	.bl_end
467
 
468
	cmp	eax,ebx
469
	jl	.bl_ok
470
	je	.bl_end
471
 
472
	xchg	eax,ebx
473
 
474
	mov	edx,.bx1
475
	xchg	edx,.bx2
476
	mov	.bx1,edx
477
	mov	edx,.by1
478
	xchg	edx,.by2
479
	mov	.by1,edx
480
 
481
	mov	edx,.ex1
482
	xchg	edx,.ex2
483
	mov	.ex1,edx
484
	mov	edx,.ey1
485
	xchg	edx,.ey2
486
	mov	.ey1,edx
487
  .bl_ok:
488
	push	eax
489
	push	ebx	      ;store x1, x2
490
 
491
	mov	eax,SIZE_X*3
492
	mov	ebx,.y
493
	mul	ebx
494
	mov	ecx,.x1
495
	lea	ecx,[ecx*3]
496
	add	eax,ecx
497
	add	edi,eax
498
 
499
	mov	ecx,.x2
500
	sub	ecx,.x1
501
 
502
	mov	eax,.bx2       ; calc .dbx
503
	sub	eax,.bx1
504
	cdq
505
	idiv	ecx
506
	push	eax
507
 
508
	mov	eax,.by2       ; calc .dby
509
	sub	eax,.by1
510
	cdq
511
	idiv	ecx
512
	push	eax
513
 
514
	mov	eax,.ex2       ; calc .dex
515
	sub	eax,.ex1
516
	cdq
517
	idiv	ecx
518
	push	eax
519
 
520
	mov	eax,.ey2       ; calc .dey
521
	sub	eax,.ey1
522
	cdq
523
	idiv	ecx
524
	push	eax
525
 
526
	push	.bx1
527
	push	.by1
528
	push	.ex1
529
	push	.ey1
530
     .draw:
531
    ; if TEX = SHIFTING   ;bump drawing only in shifting mode
532
 
533
	mov	eax,.cby
534
	sar	eax,ROUND
535
	shl	eax,TEX_SHIFT
536
	mov	esi,.cbx
537
	sar	esi,ROUND
538
	add	esi,eax
539
 
540
	mov	ebx,esi
541
	dec	ebx
542
	and	ebx,TEXTURE_SIZE
543
	add	ebx,.bmap
544
	movzx	eax,byte [ebx]
545
 
546
	mov	ebx,esi
547
	inc	ebx
548
	and	ebx,TEXTURE_SIZE
549
	add	ebx,.bmap
550
	movzx	ebx,byte [ebx]
551
	sub	eax,ebx
552
 
553
	mov	ebx,esi
554
	sub	ebx,TEX_X
555
	and	ebx,TEXTURE_SIZE
556
	add	ebx,.bmap
557
	movzx	edx,byte [ebx]
558
 
559
	mov	ebx,esi
560
	add	ebx,TEX_X
561
	and	ebx,TEXTURE_SIZE
562
	add	ebx,.bmap
563
	movzx	ebx,byte [ebx]
564
	sub	edx,ebx
565
 
566
	mov	ebx,.cex       ;.cex - current env map X
567
	sar	ebx,ROUND
568
	add	eax,ebx        ; eax - modified x coord
569
 
570
	mov	ebx,.cey       ;.cey - current  env map y
571
	sar	ebx,ROUND
572
	add	edx,ebx        ; edx - modified y coord
573
 
574
	or	eax,eax
575
	jl	.black
576
	cmp	eax,TEX_X
577
	jg	.black
578
	or	edx,edx
579
	jl	.black
580
	cmp	edx,TEX_Y
581
	jg	.black
582
 
583
	shl	edx,TEX_SHIFT
584
	add	edx,eax
585
	lea	edx,[edx*3]
586
	add	edx,.emap
587
	mov	eax,dword[edx]
588
	jmp	.put_pixel
589
     .black:
590
	xor	eax,eax
591
     .put_pixel:
592
	stosd
593
	dec	edi
594
 
595
	mov	eax,.dbx
596
	add	.cbx,eax
597
	mov	eax,.dby
598
	add	.cby,eax
599
	mov	eax,.dex
600
	add	.cex,eax
601
	mov	eax,.dey
602
	add	.cey,eax
603
 
604
	dec	ecx
605
	jnz	.draw
606
   ;   end if
607
  .bl_end:
608
	mov	esp,ebp
609
ret 44