6 ;TEXTURE_SIZE EQU (512*512)-1
9 ;TEXTURE_SIZE EQU (TEX_X * TEX_Y)-1
13 ;------- Big thanks to Majuma (www.majuma.xt.pl) for absolutely great---
14 ;------- DOS 13h mode demos --------------------------------------------
15 ;------- Procedure draws bump triangle using Catmull Z-buffer algorithm-
16 ;------- (Z coordinate interpolation)-----------------------------------
18 ;------------------in - eax - x1 shl 16 + y1 -----------
19 ;---------------------- ebx - x2 shl 16 + y2 -----------
20 ;---------------------- ecx - x3 shl 16 + y3 -----------
21 ;---------------------- edx - pointer to bump map ------
22 ;---------------------- esi - pointer to environment map
23 ;---------------------- edi - pointer to screen buffer--
24 ;---------------------- stack : bump coordinates--------
25 ;---------------------- environment coordinates-
26 ;---------------------- Z position coordinates--
27 ;---------------------- pointer io Z buffer-----
28 ;-- Z-buffer - filled with coordinates as dword --------
29 ;-- (Z coor. as word) shl CATMULL_SHIFT ----------------
30 .b_x1 equ ebp+4 ; procedure don't save registers !!!
31 .b_y1 equ ebp+6 ; each coordinate as word
45 .z_buff equ dword[ebp+34] ; pointer to Z-buffer
48 .t_bmap equ dword[ebp-4] ; pointer to bump map
49 .t_emap equ dword[ebp-8] ; pointer to e. map
57 .dx12 equ dword[ebp-24]
59 .dbx12 equ dword[ebp-32]
61 .dex12 equ dword[ebp-40]
64 .dx13 equ dword[ebp-48]
66 .dbx13 equ dword[ebp-56]
68 .dex13 equ dword[ebp-64]
71 .dx23 equ dword[ebp-72]
73 .dbx23 equ dword[ebp-80]
75 .dex23 equ dword[ebp-88]
78 .cx1 equ dword[ebp-96] ; current variables
80 .cx2 equ dword[ebp-104]
82 .cbx1 equ dword[ebp-112]
84 .cex1 equ dword[ebp-120]
86 .cbx2 equ dword[ebp-128]
88 .cex2 equ dword[ebp-136]
92 push edx ; store bump map
93 push esi ; store e. map
95 .sort3: ; sort triangle coordinates...
100 xchg edx,dword[.b_x2]
103 xchg edx,dword[.e_x2]
113 xchg edx,dword[.b_x3]
116 xchg edx,dword[.e_x3]
123 push eax ; store triangle coords in variables
127 mov edx,80008000h ; eax,ebx,ecx are ANDd together into edx which means that
128 and edx,ebx ; if *all* of them are negative a sign flag is raised
131 test edx,80008000h ; Check both X&Y at once
133 ; mov edx,eax ; eax,ebx,ecx are ORd together into edx which means that
134 ; or edx,ebx ; if any *one* of them is negative a sign flag is raised
136 ; test edx,80000000h ; Check only X
141 ; cmp .x2,SIZE_X ; This can be optimized with effort
144 ; jg .loop23_done ; {
147 mov bx,.y2 ; calc delta 12
170 shl eax,CATMULL_SHIFT
177 cvtsi2ss xmm3,ebx ;rcps
179 cvtsi2ss xmm4,[i255d]
210 shufps xmm1,xmm1,10110001b
211 cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords
260 mov bx,.y3 ; calc delta13
283 shl eax,CATMULL_SHIFT
292 cvtsi2ss xmm3,ebx ;rcps
294 cvtsi2ss xmm4,[i255d]
325 shufps xmm1,xmm1,10110001b
326 cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords
374 mov bx,.y3 ; calc delta23
397 shl eax,CATMULL_SHIFT
406 cvtsi2ss xmm3,ebx ;rcps
408 cvtsi2ss xmm4,[i255d]
439 shufps xmm1,xmm1,10110001b
440 cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords
496 movsx eax,word[.b_x1]
503 movsx eax,word[.b_y1]
510 movsx eax,word[.e_x1]
517 movsx eax,word[.e_y1]
525 shl eax,CATMULL_SHIFT
554 if (Ext = MMX) | (Ext = SSE)
612 shl eax,CATMULL_SHIFT
619 movzx eax,word[.b_x2]
623 movzx eax,word[.b_y2]
627 movzx eax,word[.e_x2]
631 movzx eax,word[.e_y2]
653 if (Ext = MMX) | (Ext = SSE)
740 ;--------------in: eax - x1
741 ;-------------- ebx - x2
742 ;-------------- edi - pointer to screen buffer
743 ;stack - another parameters :
745 .bx1 equ [ebp+8] ; ---
746 .by1 equ dword [ebp+12] ; |
747 .ex1 equ [ebp+16] ; |
748 .ey1 equ dword [ebp+20] ; |> bump and env coords
749 .bx2 equ [ebp+24] ; |> shifted shl ROUND
750 .by2 equ dword [ebp+28] ; |
751 .ex2 equ [ebp+32] ; |
752 .ey2 equ dword [ebp+36] ; ---
753 .bmap equ dword [ebp+40]
754 .emap equ dword [ebp+44]
755 .z_buff equ dword [ebp+48]
756 .z2 equ dword [ebp+52] ; -- |> z coords shifted
757 .z1 equ dword [ebp+56] ; -- shl CATMULL_SHIFT
759 .x1 equ dword [ebp-4]
760 .x2 equ dword [ebp-8]
761 .dbx equ dword [ebp-12]
763 .dex equ dword [ebp-20]
765 .dz equ dword [ebp-28]
766 .cbx equ dword [ebp-32]
768 .cex equ dword [ebp-40]
770 .cz equ dword [ebp-48]
771 .czbuff equ dword [ebp-52]
783 ; mov dx,[size_x_var]
785 cmp cx,[size_y_var] ;SIZE_Y
832 push ebx ;store x1, x2
833 movzx edx,word[size_x_var]
846 cvtsi2ss xmm3,ebx ;rcps
849 cvtpi2ps xmm0,.bx1 ;mm0
851 cvtpi2ps xmm0,.ex1 ;mm2
852 cvtpi2ps xmm1,.bx2 ;mm1
854 cvtpi2ps xmm1,.ex2 ;mm3
859 shufps xmm1,xmm1,10110001b
860 cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords
868 mov eax,.bx2 ; calc .dbx
874 mov eax,.by2 ; calc .dby
880 mov eax,.ex2 ; calc .dex
886 mov eax,.ey2 ; calc .dey
894 mov eax,.z2 ; calc .dz
900 cmp .x1,0 ; set correctly begin variable
901 jge @f ; CLIPPING ON FUNCTION
902 ; cutting triangle exceedes screen
905 imul ebx ; eax = .dz * abs(.x1)
925 movzx edx,word[size_x_var]
931 movzx eax,word[size_x_var] ;SIZE_X ;calc memory begin in buffers
939 mov esi,.z_buff ; z-buffer filled with dd variables
945 ; init current variables
951 push .z1 ; current z shl CATMULL_SHIFT
977 ; if TEX = SHIFTING ;bump drawing only in shifting mode
978 mov esi,.czbuff ; .czbuff current address in buffer
979 mov ebx,.cz ; .cz - cur z position
996 add esi,eax ;- ; esi - current bump map index
1008 ; shufps xmm0,xmm0,11100001b
1014 ; shufps xmm0,xmm0,11111110b
1017 movzx edx, byte [ebx]
1019 ; shufps xmm0,xmm0,11111111b
1022 movzx ebx, byte [ebx]
1029 and ebx,TEXTURE_SIZE
1031 movzx eax,byte [ebx]
1035 and ebx,TEXTURE_SIZE
1037 movzx ebx,byte [ebx]
1043 and ebx,TEXTURE_SIZE
1045 movzx edx,byte [ebx]
1049 and ebx,TEXTURE_SIZE
1051 movzx ebx,byte [ebx]
1055 ; eax - horizontal sub
1056 ; edx - vertical sub
1058 mov ebx,.cex ;.cex - current env map X
1060 add eax,ebx ; eax - modified x coord
1062 mov ebx,.cey ;.cey - current env map y
1064 add edx,ebx ; edx - modified y coord
1066 movq mm6,mm1 ; mm5 - copy of cur env coords