Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

357 lines
10 KiB

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ; Monolith 23. Non-perspective NO Z buffered X888
  4. ;
  5. ; Exactly the same as monolith 2 except color input is 32 bits and
  6. ; output is 32 bits and no Z buffer code
  7. ;
  8. ;-----------------------------------------------------------------------------
  9. INCLUDE iammx.inc
  10. INCLUDE offs_acp.inc
  11. ; Names are read LSB to MSB, so B5G6R5 means five bits of blue starting
  12. ; at the LSB, then six bits of green, then five bits of red.
  13. ;TBD check to see if this value is correct.
  14. COLOR_SHIFT equ 8
  15. .586
  16. .model flat
  17. ; Big separating lines seperate code into span code
  18. ; and loop code. If span and loop are not going to
  19. ; end up being combined then it will be easy to
  20. ; seperate the code.
  21. .data
  22. ; Need externs for all of the variables that are needed for various beads
  23. EXTERN IncHighandLow16:MMWORD
  24. EXTERN UFracVFracMask:MMWORD
  25. EXTERN UV32to15Mask:MMWORD
  26. EXTERN Makelow16one:MMWORD
  27. EXTERN MaskKeepUValues:MMWORD
  28. EXTERN MaskKeepVValues:MMWORD
  29. EXTERN UFrac:MMWORD
  30. EXTERN VFrac:MMWORD
  31. EXTERN Zero:MMWORD
  32. EXTERN memD3DTFG_POINT:MMWORD
  33. EXTERN GiveUp:MMWORD
  34. EXTERN LastW:MMWORD
  35. EXTERN Val0x000a000a:MMWORD
  36. EXTERN Val0xffff:MMWORD
  37. EXTERN Val0x0000002000000020:MMWORD
  38. EXTERN Val0x0000ffff0000ffff:MMWORD
  39. EXTERN MaskRed565to888:MMWORD
  40. EXTERN MaskGreen565to888:MMWORD
  41. EXTERN MaskBlue565to888:MMWORD
  42. EXTERN MaskRed555to888:MMWORD
  43. EXTERN MaskGreen555to888:MMWORD
  44. EXTERN MaskBlue555to888:MMWORD
  45. EXTERN MaskAlpha1555to8888:MMWORD
  46. EXTERN MaskRed1555to8888:MMWORD
  47. EXTERN MaskGreen1555to8888:MMWORD
  48. EXTERN MaskBlue1555to8888:MMWORD
  49. ; TBD. I think that I want to do 0xffff instead of 0xff. This will
  50. ; have to be checked. There is a value very similiar to this in
  51. ; buf write.
  52. EXTERN SetAlphato0xffff:MMWORD
  53. EXTERN SetAlphato0xff:MMWORD
  54. ; TODO This equate are identical to the ones in texread.mas. Maybe they should be in a common .inc file.
  55. RedShift565to888 equ 8
  56. GreenShift565to888 equ 5
  57. BlueShift565to888 equ 3
  58. RedShift555to888 equ 9
  59. GreenShift555to888 equ 6
  60. BlueShift555to888 equ 3
  61. AlphaShift1555to8888 equ 16
  62. RedShift1555to8888 equ 9
  63. GreenShift1555to8888 equ 6
  64. BlueShift1555to8888 equ 3
  65. EXTERN Zero:MMWORD
  66. EXTERN DW_One_One:MMWORD
  67. EXTERN MaskOffAlpha:MMWORD
  68. EXTERN ShiftTA:MMWORD
  69. EXTERN Val0x00ff00ff00ff00ff:MMWORD
  70. EXTERN Val0x000000ff00ff00ff:MMWORD
  71. EXTERN Val0X0000000001000000:MMWORD
  72. EXTERN AlphaVal128:MMWORD
  73. EXTERN RGBVal128:MMWORD
  74. EXTERN g_uDitherValue:MMWORD
  75. EXTERN SetAlphato0xff:MMWORD
  76. EXTERN u888to565RedBlueMask:MMWORD
  77. EXTERN u888to565GreenMask:MMWORD
  78. EXTERN u888to565Multiplier:MMWORD
  79. EXTERN uVal0x000007ff03ff07ff:MMWORD
  80. EXTERN uVal0x0000078003c00780:MMWORD
  81. EXTERN u888to555RedBlueMask:MMWORD
  82. EXTERN u888to555GreenMask:MMWORD
  83. EXTERN u888to555Multiplier:MMWORD
  84. EXTERN uVal0x000007ff07ff07ff:MMWORD
  85. EXTERN uVal0x0000078007800780:MMWORD
  86. ;-----------------------------------------------------------------------------
  87. ; Span Variables
  88. uMaskU dq ?
  89. StackPos dd ?
  90. uSpans dd ?
  91. iShiftU dd ?
  92. iShiftPitch dd ?
  93. pBits dd ?
  94. ;-----------------------------------------------------------------------------
  95. ;-----------------------------------------------------------------------------
  96. ; Loop Variables
  97. iSurfaceStep dd ?
  98. uPix dd ?
  99. ;-----------------------------------------------------------------------------
  100. .code
  101. PUBLIC _MMXMLRast_23
  102. _MMXMLRast_23:
  103. push ebp
  104. mov StackPos, esp
  105. mov eax, esp
  106. sub esp, 0Ch ; This will need to change if stack frame size changes.
  107. push ebx
  108. push esi
  109. push edi
  110. ; Put pCtx into ebx
  111. mov ebx, [eax+8]
  112. ;PD3DI_RASTPRIM pP = pCtx->pPrim;
  113. mov ecx, [ebx+RASTCTX_pPrim]
  114. ;while (pP)
  115. ;{
  116. PrimLoop:
  117. cmp ecx, 0
  118. je ExitPrimLoop
  119. ;UINT16 uSpans = pP->uSpans;
  120. movzx eax, word ptr [ecx+RASTPRIM_uSpans]
  121. mov uSpans, eax
  122. ;PD3DI_RASTSPAN pS = (PD3DI_RASTSPAN)(pP + 1);
  123. mov ebp, ecx
  124. add ebp, SIZEOF_RASTPRIM
  125. SpanLoop:
  126. mov edx, uSpans
  127. mov eax, edx
  128. dec eax
  129. mov uSpans, eax
  130. test edx, edx
  131. jle ExitSpanLoop
  132. ;pCtx->pfnBegin(pCtx, pP, pS);
  133. ;-----------------------------------------------------------------------------
  134. ; LoopAny code inserted here. This is to get rid of an extra
  135. ; jump.
  136. ;-----------------------------------------------------------------------------
  137. ; Setup Code begins - get values to iterate
  138. movzx eax, word ptr [ebp+RASTSPAN_uPix]
  139. mov uPix, eax
  140. movq mm5, [ebp+RASTSPAN_iUoW1]
  141. ; non perspective correct.
  142. psrad mm5, TEX_TO_FINAL_SHIFT
  143. movq [ebx+RASTCTX_SI+SPANITER_iU1], mm5
  144. mov dword ptr [ebx+RASTCTX_SI+SPANITER_iDW], 0
  145. mov word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW], 0
  146. mov eax, [ecx+RASTPRIM_uFlags]
  147. and eax, D3DI_RASTPRIM_X_DEC
  148. test eax, eax
  149. jz LeftToRightSpan
  150. mov eax, [ebx+RASTCTX_iSurfaceStep]
  151. neg eax
  152. mov iSurfaceStep, eax
  153. jmp DoneSpanDirif
  154. LeftToRightSpan:
  155. mov eax, [ebx+RASTCTX_iSurfaceStep]
  156. mov iSurfaceStep, eax
  157. DoneSpanDirif:
  158. ;******************************************
  159. mov esi, [ebx+RASTCTX_pTexture]
  160. mov edx, [esi + SPANTEX_iShiftU]
  161. mov iShiftU, edx
  162. movzx edx, word ptr [esi + SPANTEX_iShiftPitch]
  163. mov iShiftPitch, edx
  164. movd mm0, dword ptr [esi+SPANTEX_uMaskU] ; Load U and V mask
  165. movq MMWORD PTR uMaskU, mm0
  166. mov edx, [esi+SPANTEX_pBits]
  167. mov pBits, edx
  168. mov edi, [ebp+RASTSPAN_pSurface]
  169. ;******************************************
  170. PixelLoop:
  171. ; Doing UV calculation a little more accurate
  172. ; Exactly like C code.
  173. ; I iU and iV to the right not by (TEX_FINAL_SHIFT - iShiftU0) but by
  174. ; (TEX_FINAL_SHIFT - iShiftU0 - 6). iShiftU0 = pTex->iShiftU - iLOD0
  175. ; (TEX_FINAL_SHIFT - (pTex->iShiftU - iLOD0))
  176. ; (TEX_FINAL_SHIFT + iLOD0 - pTex->iShiftU)
  177. ; COMMENT1**
  178. ; If textures have a max of 1024 then shiftU0 would be at most 10 which would
  179. ; make (TEXT_FINAL_SHIFT - iShiftU - 6) at most zero. This is why I choose 6
  180. ; It will also give bi-linear 6 bits of precision I think it was said that
  181. ; only five was needed.
  182. ;INT16 iShiftU0 = pTex->iShiftU - iLOD0;
  183. ;INT16 iShiftV0 = pTex->iShiftV - iLOD0;
  184. movq mm5, MMWORD PTR Val0x000a000a ; This is TEX_FINAL_SHIFT - 6 = 10.
  185. ;******************************************
  186. ;movd mm4, [esi+SPANTEX_iShiftU]
  187. movd mm4, iShiftU
  188. ;******************************************
  189. psubw mm5, mm4
  190. movq mm4, mm5
  191. pand mm5, MMWORD PTR Val0xffff
  192. psrld mm4, 16
  193. movd mm1, [ebx+RASTCTX_SI+SPANITER_iU1]
  194. psrad mm1, mm5
  195. movd mm2, [ebx+RASTCTX_SI+SPANITER_iV1]
  196. psrad mm2, mm4
  197. punpckldq mm1, mm2
  198. ; Texture Pitch cannot be calculated so it must be looked up in the iShiftPitch table
  199. ; ----------------- Start of hack
  200. ; ATTENTION This is really hacked right now. Just to get it working
  201. ; Pitch would be better for me, instead of pitch.
  202. ; With actual pitch, this would be two moves and a .
  203. ;******************************************
  204. ;movzx edx, word ptr [esi+SPANTEX_iShiftPitch]
  205. mov edx, iShiftPitch
  206. ;******************************************
  207. add edx, 16
  208. movd mm2, edx
  209. movq mm5, MMWORD ptr Makelow16one
  210. pslld mm5, mm2
  211. ; ----------------- End of hack
  212. por mm5, MMWORD ptr Makelow16one
  213. ; Make the low 16 bits of dword one
  214. ; This helps in calculating texture address.
  215. ; Gets U and V value into mm1 so that it can be mirrored, wrapped or
  216. ; clamped. This can be done for two values in the point case
  217. ; or four values in the bilinear case.
  218. ;iU00 >>= 6;
  219. ;iV00 >>= 6;
  220. psrad mm1, 6
  221. packssdw mm1, mm1 ; Value needs to be packed since all wrap/mirror
  222. ; operations assume UV in low 32 bits.
  223. ;UINT16 uMaskU0 = pTex->uMaskU >> iLOD0; UINT16 uMaskV0 = pTex->uMaskV >> iLOD0;
  224. ; put mask in mm3 and replicate to match location for wrap/mirror/clamp
  225. pand mm1, MMWORD PTR uMaskU
  226. movq mm4, mm1
  227. pmaddwd mm4, mm5 ; Throw in first address calculation.
  228. ; Just to get it started. Calculate
  229. ; iU0+iV1*iShiftU0 and iU1+iV0*iShiftU0
  230. ; iV0 iU1 address should be done by now.
  231. movd eax, mm4
  232. shl eax, 2
  233. ;add eax, [esi+SPANTEX_pBits]
  234. add eax, pBits
  235. ;pCtx->SI.TexCol[0] = pCtx->pfnTexRead(iU00, iV00, pTex->iShiftU,
  236. ; pTex->pBits[iLOD0], &pCtx->Texture[0]);
  237. ; -------------------- In Monolithic version calls are inlined.
  238. ; Generate Border Mask to always be true in non border case.
  239. ;pcmpeqd mm5, mm5
  240. mov edx, dword ptr [eax]
  241. and edx, 000ffffffh
  242. mov [edi], edx
  243. dec uPix
  244. jle ExitPixelLoop
  245. ; Doing update code after span length test so that an extra update is not done.
  246. movq mm5, [ebp+RASTSPAN_iUoW1]
  247. paddd mm5, [ecx+RASTPRIM_iDUoW1DX]
  248. movq [ebp+RASTSPAN_iUoW1], mm5
  249. ; mm5 still contains iUoW and iVoW which are the iU and iV values for
  250. ; non perspective correct.
  251. psrad mm5, TEX_TO_FINAL_SHIFT
  252. movq [ebx+RASTCTX_SI+SPANITER_iU1], mm5
  253. add edi, iSurfaceStep
  254. jmp PixelLoop
  255. ExitPixelLoop:
  256. ; Loop code ends
  257. ;-----------------------------------------------------------------------------
  258. ; LoopAny code ends here
  259. ;-----------------------------------------------------------------------------
  260. ;pS++;
  261. add ebp, SIZEOF_RASTSPAN
  262. ;}
  263. jmp SpanLoop
  264. ExitSpanLoop:
  265. ;pP = pP->pNext;
  266. mov ecx, [ecx+RASTPRIM_pNext]
  267. ;}
  268. jmp PrimLoop
  269. ExitPrimLoop:
  270. ;_asm{
  271. emms
  272. ;}
  273. ;return S_OK;
  274. xor eax, eax
  275. ;}
  276. pop edi
  277. pop esi
  278. pop ebx
  279. mov esp, StackPos
  280. pop ebp
  281. ret
  282. END