Rev 1979 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1245 | hidnplayr | 1 | |
2 | ;SIZE_Y equ 350 |
||
3 | ;ROUND equ 8 |
||
4 | ;TEX_X equ 512 |
||
5 | ;TEX_Y equ 512 |
||
6 | ;TEXTURE_SIZE EQU (512*512)-1 |
||
7 | ;TEX_SHIFT EQU 9 |
||
8 | |||
9 | |||
10 | ;TEXTURE_SIZE EQU (TEX_X * TEX_Y)-1 |
||
11 | ;Ext = SSE |
||
12 | ;SSE = 3 |
||
13 | ;MMX = 1 |
||
14 | ;NON = 0 |
||
15 | ;use32 |
||
16 | ;------- Big thanks to Majuma (www.majuma.xt.pl) for absolutely great--- |
||
17 | ;------- DOS 13h mode demos -------------------------------------------- |
||
18 | ;------- Procedure draws triangle with two overlapped textures, I use -- |
||
19 | ;--------Catmull Z-buffer algorithm- (Z coordinate interpolation)------- |
||
20 | ;--------I calc texture pixel by this way: col1*col2/256 --------------- |
||
21 | two_tex_triangle_z: |
||
22 | ;------------------in - eax - x1 shl 16 + y1 ----------- |
||
23 | ;---------------------- ebx - x2 shl 16 + y2 ----------- |
||
24 | ;---------------------- ecx - x3 shl 16 + y3 ----------- |
||
25 | ;---------------------- edx - pointer to b. texture----- |
||
26 | ;---------------------- esi - pointer to e. texture----- |
||
27 | ;---------------------- edi - pointer to screen buffer-- |
||
28 | ;---------------------- stack : b. tex coordinates------ |
||
29 | ;---------------------- e. tex coordinates------ |
||
30 | ;---------------------- Z position coordinates-- |
||
31 | ;---------------------- pointer io Z buffer----- |
||
32 | ;-- Z-buffer - filled with coordinates as dword -------- |
||
33 | ;-- (Z coor. as word) shl CATMULL_SHIFT ---------------- |
||
34 | .b_x1 equ ebp+4 ; procedure don't save registers !!! |
||
2192 | leency | 35 | .b_y1 equ ebp+6 ; each coordinate as word |
36 | .b_x2 equ ebp+8 |
||
37 | .b_y2 equ ebp+10 ; b - first texture |
||
38 | .b_x3 equ ebp+12 |
||
39 | .b_y3 equ ebp+14 ; e - second texture |
||
40 | .e_x1 equ ebp+16 |
||
41 | .e_y1 equ ebp+18 |
||
42 | .e_x2 equ ebp+20 |
||
43 | .e_y2 equ ebp+22 |
||
44 | .e_x3 equ ebp+24 |
||
45 | .e_y3 equ ebp+26 |
||
46 | .z1 equ word[ebp+28] |
||
47 | .z2 equ word[ebp+30] |
||
48 | .z3 equ word[ebp+32] |
||
49 | .z_buff equ dword[ebp+34] ; pointer to Z-buffer |
||
50 | |||
1245 | hidnplayr | 51 | |
52 | |||
2192 | leency | 53 | .t_emap equ dword[ebp-8] ; pointer to e. texture |
54 | .x1 equ word[ebp-10] |
||
55 | .y1 equ word[ebp-12] |
||
56 | .x2 equ word[ebp-14] |
||
57 | .y2 equ word[ebp-16] |
||
58 | .x3 equ word[ebp-18] |
||
59 | .y3 equ word[ebp-20] |
||
60 | |||
1245 | hidnplayr | 61 | |
62 | .dbx12 equ dword[ebp-28] |
||
63 | .dby12 equ dword[ebp-32] |
||
64 | .dby12q equ [ebp-32] |
||
2192 | leency | 65 | .dex12 equ dword[ebp-36] |
1245 | hidnplayr | 66 | .dey12 equ dword[ebp-40] |
67 | .dey12q equ [ebp-40] |
||
2192 | leency | 68 | .dz12 equ dword[ebp-44] |
1245 | hidnplayr | 69 | |
70 | |||
71 | .dbx13 equ dword[ebp-52] |
||
72 | .dby13 equ dword[ebp-56] |
||
73 | .dby13q equ [ebp-56] |
||
2192 | leency | 74 | .dex13 equ dword[ebp-60] |
1245 | hidnplayr | 75 | .dey13 equ dword[ebp-64] |
76 | .dey13q equ [ebp-64] |
||
2192 | leency | 77 | .dz13 equ dword[ebp-68] |
1245 | hidnplayr | 78 | |
79 | |||
80 | .dbx23 equ dword[ebp-76] |
||
81 | .dby23 equ dword[ebp-80] |
||
82 | .dby23q equ [ebp-80] |
||
2192 | leency | 83 | .dex23 equ dword[ebp-84] |
1245 | hidnplayr | 84 | .dey23 equ dword[ebp-88] |
85 | .dey23q equ [ebp-88] |
||
2192 | leency | 86 | .dz23 equ dword[ebp-92] |
1245 | hidnplayr | 87 | |
88 | |||
89 | .cx2 equ dword[ebp-100] |
||
90 | .cbx1 equ dword[ebp-104] |
||
91 | .cby1 equ [ebp-108] |
||
92 | .cex1 equ dword[ebp-112] |
||
2192 | leency | 93 | .cey1 equ [ebp-116] |
94 | .cbx2 equ dword[ebp-120] |
||
95 | .cby2 equ [ebp-124] |
||
96 | .cex2 equ dword[ebp-128] |
||
1245 | hidnplayr | 97 | .cey2 equ [ebp-132] |
98 | |||
99 | |||
100 | .cz2 equ dword[ebp-140] |
||
101 | |||
102 | |||
103 | emms |
||
104 | else |
||
105 | cld |
||
106 | end if |
||
107 | mov ebp,esp |
||
108 | push edx esi ; store bump map |
||
2192 | leency | 109 | ; push esi ; store e. map |
1245 | hidnplayr | 110 | ; sub esp,120 |
111 | .sort3: ; sort triangle coordinates... |
||
2192 | leency | 112 | cmp ax,bx |
1245 | hidnplayr | 113 | jle .sort1 |
114 | xchg eax,ebx |
||
115 | mov edx,dword[.b_x1] |
||
116 | xchg edx,dword[.b_x2] |
||
117 | mov dword[.b_x1],edx |
||
118 | mov edx,dword[.e_x1] |
||
119 | xchg edx,dword[.e_x2] |
||
120 | mov dword[.e_x1],edx |
||
121 | mov dx,.z1 |
||
122 | xchg dx,.z2 |
||
123 | mov .z1,dx |
||
124 | .sort1: |
||
125 | cmp bx,cx |
||
2192 | leency | 126 | jle .sort2 |
127 | xchg ebx,ecx |
||
128 | mov edx,dword[.b_x2] |
||
129 | xchg edx,dword[.b_x3] |
||
130 | mov dword[.b_x2],edx |
||
131 | mov edx,dword[.e_x2] |
||
132 | xchg edx,dword[.e_x3] |
||
133 | mov dword[.e_x2],edx |
||
134 | mov dx,.z2 |
||
1245 | hidnplayr | 135 | xchg dx,.z3 |
136 | mov .z2,dx |
||
137 | jmp .sort3 |
||
2192 | leency | 138 | .sort2: |
1245 | hidnplayr | 139 | push eax ebx ecx ; store triangle coords in variables |
2192 | leency | 140 | ; push ebx |
1245 | hidnplayr | 141 | ; push ecx |
142 | |||
143 | |||
2192 | leency | 144 | and edx,ebx ; if *all* of them are negative a sign flag is raised |
145 | and edx,ecx |
||
146 | and edx,eax |
||
147 | test edx,80008000h ; Check both X&Y at once |
||
148 | jne .loop23_done |
||
149 | ; mov edx,eax ; eax,ebx,ecx are ORd together into edx which means that |
||
1245 | hidnplayr | 150 | ; or edx,ebx ; if any *one* of them is negative a sign flag is raised |
151 | ; or edx,ecx |
||
152 | ; test edx,80000000h ; Check only X |
||
153 | ; jne .loop23_done |
||
154 | |||
155 | |||
156 | ; jg .loop23_done |
||
157 | ; cmp .x2,SIZE_X ; This can be optimized with effort |
||
158 | ; jg .loop23_done |
||
159 | ; cmp .x3,SIZE_X |
||
160 | ; jg .loop23_done ; { |
||
161 | |||
162 | |||
163 | |||
2192 | leency | 164 | sub bx,.y1 |
165 | jnz .bt_dx12_make |
||
166 | mov ecx,6 |
||
167 | xor edx,edx |
||
168 | @@: |
||
1245 | hidnplayr | 169 | push edx ;dword 0 |
2192 | leency | 170 | loop @b |
171 | jmp .bt_dx12_done |
||
172 | .bt_dx12_make: |
||
1245 | hidnplayr | 173 | mov ax,.x2 |
2192 | leency | 174 | sub ax,.x1 |
175 | cwde |
||
1245 | hidnplayr | 176 | movsx ebx,bx |
2192 | leency | 177 | shl eax,ROUND |
178 | cdq |
||
1245 | hidnplayr | 179 | idiv ebx |
2192 | leency | 180 | ; mov .dx12,eax |
1245 | hidnplayr | 181 | push eax |
2192 | leency | 182 | |
1245 | hidnplayr | 183 | |
184 | |||
185 | |||
2192 | leency | 186 | cvtsi2ss xmm3,ebx ;rcps |
187 | ; mov eax,255 |
||
1245 | hidnplayr | 188 | cvtsi2ss xmm4,[i255d] ;eax |
189 | divss xmm3,xmm4 |
||
2192 | leency | 190 | rcpss xmm3,xmm3 |
191 | ; mulss xmm3,xmm4 |
||
1245 | hidnplayr | 192 | shufps xmm3,xmm3,0 |
2192 | leency | 193 | |
1245 | hidnplayr | 194 | |
2192 | leency | 195 | movd mm1,[.b_x2] |
196 | movd mm2,[.e_x1] |
||
197 | movd mm3,[.e_x2] |
||
198 | ; psubsw mm3,mm2 |
||
1245 | hidnplayr | 199 | ; psubsw mm1,mm0 |
200 | pxor mm4,mm4 |
||
2192 | leency | 201 | punpcklwd mm0,mm4 |
1245 | hidnplayr | 202 | punpcklwd mm1,mm4 |
203 | punpcklwd mm2,mm4 |
||
204 | punpcklwd mm3,mm4 |
||
205 | ; pslld mm0,ROUND |
||
206 | ; pslld mm1,ROUND |
||
207 | ; pslld mm2,ROUND |
||
208 | ; pslld mm3,ROUND |
||
209 | cvtpi2ps xmm0,mm0 |
||
210 | movlhps xmm0,xmm0 |
||
2192 | leency | 211 | cvtpi2ps xmm0,mm2 |
1245 | hidnplayr | 212 | cvtpi2ps xmm1,mm1 |
213 | movlhps xmm1,xmm1 |
||
2192 | leency | 214 | cvtpi2ps xmm1,mm3 |
1245 | hidnplayr | 215 | subps xmm1,xmm0 |
2192 | leency | 216 | |
1245 | hidnplayr | 217 | |
218 | ; movq mm5,mm1 |
||
219 | ; movq mm6,mm1 |
||
220 | ; pcmpeqb mm5,mm4 |
||
221 | ; psubd mm1,mm0 |
||
222 | ; psubd mm3,mm2 |
||
223 | |||
224 | |||
225 |