extern g_vtxNonTransformed extern gRSPworldProjectTransported extern g_vtxTransformed extern g_vecProjected extern g_normal extern gRSPmodelViewTopTranspose extern gRSP extern gRSPnumLights extern gRSPlights extern zero extern real255 global SSEVec3Transform global SSEVec3TransformNormal global SSELightVert [section .text] SSEVec3Transform: mov ecx,[esp+4] shl ecx,4 ; ecx = i movaps xmm1, [g_vtxNonTransformed + ecx] ; xmm1 as original vector movaps xmm4, [gRSPworldProjectTransported] ; row1 movaps xmm5, [gRSPworldProjectTransported+0x10] ; row2 movaps xmm6, [gRSPworldProjectTransported+0x20] ; row3 movaps xmm7, [gRSPworldProjectTransported+0x30] ; row4 mulps xmm4, xmm1 ; row 1 mulps xmm5, xmm1 ; row 2 mulps xmm6, xmm1 ; row 3 mulps xmm7, xmm1 ; row 4 movhlps xmm0, xmm4 ; xmm4 high to xmm0 low movlhps xmm0, xmm5 ; xmm5 low to xmm0 high addps xmm4, xmm0 ; result of add are in xmm4 low addps xmm5, xmm0 ; result of add are in xmm5 high shufps xmm0, xmm4, 0x44 ; move xmm4 low DWORDs to xmm0 high shufps xmm4, xmm5, 0xe4 ; move xmm5 high DWORS to xmm4 movhlps xmm5, xmm0 ; xmm4, xmm5 are mirrored shufps xmm4, xmm4, 0x08 ; move xmm4's 3rd DWORD to its 2nd DWORD shufps xmm5, xmm5, 0x0d ; move xmm5's 4th DWORD to its 2nd DWORD, ; and move its 2nd DWORD to its 1st DWORD addps xmm4, xmm5 ; results are in 1st and 2nd DWORD movhlps xmm0, xmm6 ; xmm6 high to xmm0 low movlhps xmm0, xmm7 ; xmm7 low to xmm0 high addps xmm6, xmm0 ; result of add are in xmm6 low addps xmm7, xmm0 ; result of add are in xmm7 high shufps xmm0, xmm6, 0x44 ; move xmm6 low DWORDs to xmm0 high shufps xmm6, xmm7, 0xe4 ; move xmm7 high DWORS to xmm6 movhlps xmm7, xmm0 ; xmm6, xmm7 are mirrored shufps xmm6, xmm6, 0x08 ; move xmm6's 3rd DWORD to its 2nd DWORD shufps xmm7, xmm7, 0x0d ; move xmm7's 4th DWORD to its 2nd DWORD, ; and move its 2nd DWORD to its 1st DWORD addps xmm6, xmm7 ; results are in 1st and 2nd DWORD movlhps xmm4, xmm6 ; final result is in xmm4 movaps [g_vtxTransformed+ecx], xmm4 movaps xmm0,xmm4 shufps xmm0,xmm0,0xff divps xmm4,xmm0 rcpps xmm0,xmm0 movhlps xmm0,xmm4 shufps xmm0,xmm0,0xe8 movlhps xmm4,xmm0 movaps [g_vecProjected+ecx], xmm4 emms ret SSEVec3TransformNormal: mov dword [g_normal+12], 0 movaps xmm4, [gRSPmodelViewTopTranspose] ; row1 movaps xmm5, [gRSPmodelViewTopTranspose+0x10] ; row2 movaps xmm1, [g_normal] ; xmm1 as the normal vector movaps xmm6, [gRSPmodelViewTopTranspose+0x20] ; row3 mulps xmm4, xmm1 ; row 1 mulps xmm5, xmm1 ; row 2 mulps xmm6, xmm1 ; row 3 movhlps xmm0, xmm4 ; xmm4 high to xmm0 low movlhps xmm0, xmm5 ; xmm5 low to xmm0 high addps xmm4, xmm0 ; result of add are in xmm4 low addps xmm5, xmm0 ; result of add are in xmm5 high shufps xmm0, xmm4, 0x44 ; move xmm4 low DWORDs to xmm0 high shufps xmm4, xmm5, 0xe4 ; move xmm5 high DWORS to xmm4 movhlps xmm5, xmm0 ; xmm4, xmm5 are mirrored shufps xmm4, xmm4, 0x08 ; move xmm4's 3rd DWORD to its 2nd DWORD shufps xmm5, xmm5, 0x0d ; move xmm5's 4th DWORD to its 2nd DWORD, addps xmm4, xmm5 ; results are in 1st and 2nd DWORD movaps xmm1,xmm4 mulps xmm1,xmm1 ;square movlhps xmm7, xmm1 shufps xmm7, xmm7,0x03 addss xmm7, xmm1 movhlps xmm0, xmm6 ; xmm6 high to xmm0 low addps xmm6, xmm0 ; result of add are in xmm6 low movlhps xmm0, xmm6 shufps xmm0, xmm0, 0x03 addss xmm0, xmm6 ; result of add is at xmm0's 1st DWORD movlhps xmm4, xmm0 mulss xmm0,xmm0 addss xmm7,xmm0 ; xmm7 1st DWORD is the sum of squares rsqrtss xmm7,xmm7 shufps xmm7,xmm7,0 mulps xmm4,xmm7 movaps [g_normal], xmm4 ; Normalized mov dword [g_normal+12], 0 emms ret SSELightVert: movaps xmm3, [gRSP] ; loading Ambient colors, xmm3 is the result color movaps xmm4, [g_normal] ; xmm4 is the normal mov ecx, 0 loopback: cmp ecx, [gRSPnumLights] jae breakout mov eax,ecx imul eax,0x28 movups xmm5, [gRSPlights+eax] ; Light Dir movups xmm1, [gRSPlights+0x18+eax] ; Light color mulps xmm5, xmm4 ; Lightdir * normals movlhps xmm0,xmm5 addps xmm0,xmm5 shufps xmm5,xmm0,0xf0 ; xmm5 3rd float = xmm0 4th float addps xmm0,xmm5 shufps xmm0,xmm0,0x02 ; xmm0 1st float = xmm0 3rd float comiss xmm0,[zero] jc endloop shufps xmm0,xmm0,0 ; fcosT mulps xmm1,xmm0 addps xmm3,xmm1 endloop: inc ecx jmp loopback breakout: movss xmm0,[real255] shufps xmm0,xmm0,0 minps xmm0,xmm3 ; Without using a memory cvtss2si eax,xmm0 ; move the 1st DWORD to eax shl eax,10h or eax,0FF000000h shufps xmm0,xmm0,0E5h ; move the 2nd DWORD to the 1st DWORD cvtss2si ecx,xmm0 ; move the 1st DWORD to ecx shl ecx,8 or eax,ecx shufps xmm0,xmm0,0E6h ; Move the 3rd DWORD to the 1st DWORD cvtss2si ecx,xmm0 or eax,ecx ret