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.

386 lines
9.6 KiB

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ; Monolith 19. Non-Perspective Correct Nearest Gouraud Modulated
  4. ; Z buffer (LE or GT) X888
  5. ;
  6. ; Exactly the same as monolith 5 except color input is 32 bits and
  7. ; output is 32 bits
  8. ;
  9. ;-----------------------------------------------------------------------------
  10. INCLUDE iammx.inc
  11. INCLUDE offs_acp.inc
  12. ;TBD check to see if this value is correct.
  13. COLOR_SHIFT equ 8
  14. .586
  15. .model flat
  16. ; Big seperating lines seperate code into span code
  17. ; and loop code. If span and loop are not going to
  18. ; end up being combined then it will be easy to
  19. ; seperate the code.
  20. .data
  21. ; Need externs for all of the variables that are needed for various beads
  22. EXTERN IncHighandLow16:MMWORD
  23. EXTERN UFracVFracMask:MMWORD
  24. EXTERN UV32to15Mask:MMWORD
  25. EXTERN Makelow16one:MMWORD
  26. EXTERN MaskKeepUValues:MMWORD
  27. EXTERN MaskKeepVValues:MMWORD
  28. EXTERN UFrac:MMWORD
  29. EXTERN VFrac:MMWORD
  30. EXTERN Zero:MMWORD
  31. EXTERN memD3DTFG_POINT:MMWORD
  32. EXTERN GiveUp:MMWORD
  33. EXTERN LastW:MMWORD
  34. EXTERN Val0x000a000a:MMWORD
  35. EXTERN Val0xffff:MMWORD
  36. EXTERN Val0x0000002000000020:MMWORD
  37. EXTERN Val0x0000ffff0000ffff:MMWORD
  38. opt_MaskRed565to888 MMWORD 000000000000F800H
  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. StackPos dd ?
  89. uSpans dd ?
  90. ;-----------------------------------------------------------------------------
  91. ;-----------------------------------------------------------------------------
  92. ; Loop Variables
  93. iSurfaceStep dd ?
  94. iZStep dd ?
  95. uPix dd ?
  96. ;-----------------------------------------------------------------------------
  97. .code
  98. PUBLIC _MMXMLRast_19
  99. _MMXMLRast_19:
  100. push ebp
  101. mov StackPos, esp
  102. mov eax, esp
  103. sub esp, 0Ch ; This will need to change if stack frame size changes.
  104. push ebx
  105. push esi
  106. push edi
  107. ; Put pCtx into ebx
  108. mov ebx, [eax+8]
  109. ;PD3DI_RASTPRIM pP = pCtx->pPrim;
  110. mov ecx, [ebx+RASTCTX_pPrim]
  111. ;while (pP)
  112. ;{
  113. PrimLoop:
  114. cmp ecx, 0
  115. je ExitPrimLoop
  116. ;UINT16 uSpans = pP->uSpans;
  117. movzx eax, word ptr [ecx+RASTPRIM_uSpans]
  118. mov uSpans, eax
  119. ;PD3DI_RASTSPAN pS = (PD3DI_RASTSPAN)(pP + 1);
  120. mov ebp, ecx
  121. add ebp, SIZEOF_RASTPRIM
  122. ;while (uSpans-- > 0)
  123. ;{
  124. SpanLoop:
  125. mov edx, uSpans
  126. mov eax, edx
  127. dec eax
  128. mov uSpans, eax
  129. test edx, edx
  130. jle ExitSpanLoop
  131. ;pCtx->pfnBegin(pCtx, pP, pS);
  132. ;-----------------------------------------------------------------------------
  133. ; LoopAny code inserted here. This is to get rid of an extra
  134. ; jump.
  135. ;-----------------------------------------------------------------------------
  136. ; Setup Code begins
  137. movzx eax, word ptr [ebp+RASTSPAN_uPix]
  138. mov uPix, eax
  139. movq mm5, [ebp+RASTSPAN_iUoW1]
  140. psrad mm5, TEX_TO_FINAL_SHIFT
  141. movq [ebx+RASTCTX_SI+SPANITER_iU1], mm5
  142. ;pCtx->SI.iU2 = pS->iUoW2>>TEX_TO_FINAL_SHIFT;
  143. ;pCtx->SI.iV2 = pS->iVoW2>>TEX_TO_FINAL_SHIFT;
  144. ;movq mm5, [ebp+RASTSPAN_iUoW2]
  145. ;pCtx->SI.iDW = 0x0;
  146. mov dword ptr [ebx+RASTCTX_SI+SPANITER_iDW], 0
  147. ;pCtx->SI.iSpecialW = 0;
  148. mov word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW], 0
  149. ; -----
  150. ;if (pP->uFlags & D3DI_RASTPRIM_X_DEC)
  151. ;{
  152. mov eax, [ecx+RASTPRIM_uFlags]
  153. and eax, D3DI_RASTPRIM_X_DEC
  154. test eax, eax
  155. jz LeftToRightSpan
  156. ;iZStep = -pCtx->iZStep;
  157. mov eax, [ebx+RASTCTX_iZStep]
  158. neg eax
  159. mov iZStep, eax
  160. ;iSurfaceStep = -pCtx->iSurfaceStep;
  161. mov eax, [ebx+RASTCTX_iSurfaceStep]
  162. neg eax
  163. mov iSurfaceStep, eax
  164. ;}
  165. jmp DoneSpanDirif
  166. ;else
  167. ;{
  168. LeftToRightSpan:
  169. ;iZStep = pCtx->iZStep;
  170. mov eax, [ebx+RASTCTX_iZStep]
  171. mov iZStep, eax
  172. ;iSurfaceStep = pCtx->iSurfaceStep;
  173. mov eax, [ebx+RASTCTX_iSurfaceStep]
  174. mov iSurfaceStep, eax
  175. ;}
  176. DoneSpanDirif:
  177. movq mm6, [ebp+RASTSPAN_uB]
  178. ; Setup Code Ends
  179. ; ----------------------------------------------------------------------------------------------------------------
  180. ; Loop Code Begins
  181. PixelLoop:
  182. ; Ztestcode
  183. ; edx is uZ
  184. ; eax is uZB
  185. ; 16 bit unsigned format
  186. ;UINT16 uZ = (UINT16)(pS->uZ>>15);
  187. ;UINT16 uZB = *((UINT16*)pS->pZ);
  188. mov edx, [ebp+RASTSPAN_uZ]
  189. movd mm4, edx
  190. mov esi, [ebp+RASTSPAN_pZ]
  191. shr edx, 15
  192. movzx eax, word ptr [esi]
  193. ;pS->uZ += pP->iDZDX;
  194. ;if ((pCtx->iZXorMask)^(uZ > uZB))
  195. ; !(uZ > uZB) <==>
  196. ; (uZ <= uZB) <==>
  197. ; (uZ < uZB+1) <==>
  198. ;
  199. sub eax, edx
  200. paddd mm4, [ecx+RASTPRIM_iDZDX]
  201. movd [ebp+RASTSPAN_uZ], mm4
  202. xor eax, [ebx+RASTCTX_iZXorMask]
  203. test eax, eax
  204. js FailLabel
  205. mov word ptr [esi], dx
  206. ; texturecode
  207. mov esi, [ebx+RASTCTX_pTexture]
  208. movq mm5, MMWORD PTR Val0x000a000a ; This is TEX_FINAL_SHIFT - 6 = 10.
  209. movd mm4, [esi+SPANTEX_iShiftU]
  210. psubw mm5, mm4
  211. movq mm4, mm5
  212. pand mm5, MMWORD PTR Val0xffff
  213. psrld mm4, 16
  214. movd mm1, [ebx+RASTCTX_SI+SPANITER_iU1]
  215. psrad mm1, mm5
  216. movd mm2, [ebx+RASTCTX_SI+SPANITER_iV1]
  217. psrad mm2, mm4
  218. punpckldq mm1, mm2
  219. movzx edx, word ptr [esi+SPANTEX_iShiftPitch]
  220. add edx, 16
  221. movd mm2, edx
  222. movq mm5, MMWORD ptr Makelow16one
  223. pslld mm5, mm2
  224. por mm5, MMWORD ptr Makelow16one
  225. psrad mm1, 6
  226. packssdw mm1, mm1 ; Value needs to be packed since all wrap/mirror
  227. movd mm0, [esi+SPANTEX_uMaskU] ; Load U and V mask
  228. movq mm7, mm1
  229. movd mm4, [esi+SPANTEX_iFlipMaskU]
  230. pand mm7, mm4
  231. pcmpeqw mm7, MMWORD PTR Zero
  232. pandn mm7, mm0
  233. pand mm1, mm0
  234. pxor mm1, mm7
  235. movq mm4, mm1
  236. pmaddwd mm4, mm5 ; Throw in first address calculation.
  237. mov edi, [esi+SPANTEX_pBits]
  238. movd eax, mm4
  239. pxor mm1, mm1
  240. movd mm2, dword ptr [edi+4*eax]
  241. punpcklbw mm2, mm1
  242. ;modulate
  243. movq mm1, mm6
  244. psrlw mm1, COLOR_SHIFT ; COLOR_SHIFT is set to 8.
  245. pmullw mm1, mm2
  246. ;write
  247. mov edi, [ebp+RASTSPAN_pSurface]
  248. psrlw mm1, 8 ; Convert color1 from 8.8 two 0.8
  249. packuswb mm1, mm7 ; pack one color
  250. movd edx, mm1
  251. and edx, 000ffffffh
  252. mov [edi], edx
  253. FailLabel:
  254. dec uPix ;// BUG BUG?? uPix should never start as zero should it?
  255. jle ExitPixelLoop
  256. ; Keeping uB in MM6 so that dont need to store back and forth from memory.
  257. paddw mm6, [ecx+RASTPRIM_iDBDX]
  258. movq mm5, [ebp+RASTSPAN_iUoW1]
  259. paddd mm5, [ecx+RASTPRIM_iDUoW1DX]
  260. movq [ebp+RASTSPAN_iUoW1], mm5
  261. psrad mm5, TEX_TO_FINAL_SHIFT
  262. movq [ebx+RASTCTX_SI+SPANITER_iU1], mm5
  263. mov eax, dword ptr [ebp+RASTSPAN_pZ]
  264. mov edx, dword ptr [ebp+RASTSPAN_pSurface]
  265. add eax, iZStep
  266. add edx, iSurfaceStep
  267. mov dword ptr [ebp+RASTSPAN_pZ], eax
  268. mov dword ptr [ebp+RASTSPAN_pSurface], edx
  269. jmp PixelLoop
  270. ExitPixelLoop:
  271. ; Loop code ends
  272. ;-----------------------------------------------------------------------------
  273. ; LoopAny code ends here
  274. ;-----------------------------------------------------------------------------
  275. add ebp, SIZEOF_RASTSPAN
  276. jmp SpanLoop
  277. ExitSpanLoop:
  278. mov ecx, [ecx+RASTPRIM_pNext]
  279. jmp PrimLoop
  280. ExitPrimLoop:
  281. emms
  282. xor eax, eax
  283. pop edi
  284. pop esi
  285. pop ebx
  286. mov esp, StackPos
  287. pop ebp
  288. ret
  289. END