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.

361 lines
9.2 KiB

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ; Monolith 12. Non-Perspective Correct Nearest Gouraud Modulated
  4. ; NO Z buffer 565 output color.
  5. ;
  6. ; Exactly the same as monolith 5 except Z buffer code removed.
  7. ;
  8. ;-----------------------------------------------------------------------------
  9. INCLUDE iammx.inc
  10. INCLUDE offs_acp.inc
  11. ;TBD check to see if this value is correct.
  12. COLOR_SHIFT equ 8
  13. .586
  14. .model flat
  15. ; Big seperating lines seperate code into span code
  16. ; and loop code. If span and loop are not going to
  17. ; end up being combined then it will be easy to
  18. ; seperate the code.
  19. .data
  20. ; Need externs for all of the variables that are needed for various beads
  21. EXTERN IncHighandLow16:MMWORD
  22. EXTERN UFracVFracMask:MMWORD
  23. EXTERN UV32to15Mask:MMWORD
  24. EXTERN Makelow16one:MMWORD
  25. EXTERN MaskKeepUValues:MMWORD
  26. EXTERN MaskKeepVValues:MMWORD
  27. EXTERN UFrac:MMWORD
  28. EXTERN VFrac:MMWORD
  29. EXTERN Zero:MMWORD
  30. EXTERN memD3DTFG_POINT:MMWORD
  31. EXTERN GiveUp:MMWORD
  32. EXTERN LastW:MMWORD
  33. EXTERN Val0x000a000a:MMWORD
  34. EXTERN Val0xffff:MMWORD
  35. EXTERN Val0x0000002000000020:MMWORD
  36. EXTERN Val0x0000ffff0000ffff:MMWORD
  37. opt_MaskRed565to888 MMWORD 000000000000F800H
  38. EXTERN MaskRed565to888:MMWORD
  39. EXTERN MaskGreen565to888:MMWORD
  40. EXTERN MaskBlue565to888:MMWORD
  41. EXTERN MaskRed555to888:MMWORD
  42. EXTERN MaskGreen555to888:MMWORD
  43. EXTERN MaskBlue555to888:MMWORD
  44. EXTERN MaskAlpha1555to8888:MMWORD
  45. EXTERN MaskRed1555to8888:MMWORD
  46. EXTERN MaskGreen1555to8888:MMWORD
  47. EXTERN MaskBlue1555to8888:MMWORD
  48. ; TBD. I think that I want to do 0xffff instead of 0xff. This will
  49. ; have to be checked. There is a value very similiar to this in
  50. ; buf write.
  51. EXTERN SetAlphato0xffff:MMWORD
  52. EXTERN SetAlphato0xff:MMWORD
  53. ; TODO This equate are identical to the ones in texread.mas. Maybe they should be in a common .inc file.
  54. RedShift565to888 equ 8
  55. GreenShift565to888 equ 5
  56. BlueShift565to888 equ 3
  57. RedShift555to888 equ 9
  58. GreenShift555to888 equ 6
  59. BlueShift555to888 equ 3
  60. AlphaShift1555to8888 equ 16
  61. RedShift1555to8888 equ 9
  62. GreenShift1555to8888 equ 6
  63. BlueShift1555to8888 equ 3
  64. EXTERN Zero:MMWORD
  65. EXTERN DW_One_One:MMWORD
  66. EXTERN MaskOffAlpha:MMWORD
  67. EXTERN ShiftTA:MMWORD
  68. EXTERN Val0x00ff00ff00ff00ff:MMWORD
  69. EXTERN Val0x000000ff00ff00ff:MMWORD
  70. EXTERN Val0X0000000001000000:MMWORD
  71. EXTERN AlphaVal128:MMWORD
  72. EXTERN RGBVal128:MMWORD
  73. EXTERN g_uDitherValue:MMWORD
  74. EXTERN SetAlphato0xff:MMWORD
  75. EXTERN u888to565RedBlueMask:MMWORD
  76. EXTERN u888to565GreenMask:MMWORD
  77. EXTERN u888to565Multiplier:MMWORD
  78. EXTERN uVal0x000007ff03ff07ff:MMWORD
  79. EXTERN uVal0x0000078003c00780:MMWORD
  80. EXTERN u888to555RedBlueMask:MMWORD
  81. EXTERN u888to555GreenMask:MMWORD
  82. EXTERN u888to555Multiplier:MMWORD
  83. EXTERN uVal0x000007ff07ff07ff:MMWORD
  84. EXTERN uVal0x0000078007800780:MMWORD
  85. ;-----------------------------------------------------------------------------
  86. ; Span Variables
  87. StackPos dd ?
  88. uSpans dd ?
  89. ;-----------------------------------------------------------------------------
  90. ;-----------------------------------------------------------------------------
  91. ; Loop Variables
  92. iSurfaceStep dd ?
  93. uPix dd ?
  94. ;-----------------------------------------------------------------------------
  95. .code
  96. PUBLIC _MMXMLRast_12
  97. _MMXMLRast_12:
  98. push ebp
  99. mov StackPos, esp
  100. mov eax, esp
  101. sub esp, 0Ch ; This will need to change if stack frame size changes.
  102. push ebx
  103. push esi
  104. push edi
  105. ; Put pCtx into ebx
  106. mov ebx, [eax+8]
  107. ;PD3DI_RASTPRIM pP = pCtx->pPrim;
  108. mov ecx, [ebx+RASTCTX_pPrim]
  109. ;while (pP)
  110. ;{
  111. PrimLoop:
  112. cmp ecx, 0
  113. je ExitPrimLoop
  114. ;UINT16 uSpans = pP->uSpans;
  115. movzx eax, word ptr [ecx+RASTPRIM_uSpans]
  116. mov uSpans, eax
  117. ;PD3DI_RASTSPAN pS = (PD3DI_RASTSPAN)(pP + 1);
  118. mov ebp, ecx
  119. add ebp, SIZEOF_RASTPRIM
  120. ;while (uSpans-- > 0)
  121. ;{
  122. SpanLoop:
  123. mov edx, uSpans
  124. mov eax, edx
  125. dec eax
  126. mov uSpans, eax
  127. test edx, edx
  128. jle ExitSpanLoop
  129. ;pCtx->pfnBegin(pCtx, pP, pS);
  130. ;-----------------------------------------------------------------------------
  131. ; LoopAny code inserted here. This is to get rid of an extra
  132. ; jump.
  133. ;-----------------------------------------------------------------------------
  134. ; Setup Code begins
  135. movzx eax, word ptr [ebp+RASTSPAN_uPix]
  136. mov uPix, eax
  137. movq mm5, [ebp+RASTSPAN_iUoW1]
  138. psrad mm5, TEX_TO_FINAL_SHIFT
  139. movq [ebx+RASTCTX_SI+SPANITER_iU1], mm5
  140. ;pCtx->SI.iU2 = pS->iUoW2>>TEX_TO_FINAL_SHIFT;
  141. ;pCtx->SI.iV2 = pS->iVoW2>>TEX_TO_FINAL_SHIFT;
  142. ;movq mm5, [ebp+RASTSPAN_iUoW2]
  143. ;pCtx->SI.iDW = 0x0;
  144. mov dword ptr [ebx+RASTCTX_SI+SPANITER_iDW], 0
  145. ;pCtx->SI.iSpecialW = 0;
  146. mov word ptr [ebx+RASTCTX_SI+SPANITER_iSpecialW], 0
  147. ; -----
  148. ;if (pP->uFlags & D3DI_RASTPRIM_X_DEC)
  149. ;{
  150. mov eax, [ecx+RASTPRIM_uFlags]
  151. and eax, D3DI_RASTPRIM_X_DEC
  152. test eax, eax
  153. jz LeftToRightSpan
  154. ;iSurfaceStep = -pCtx->iSurfaceStep;
  155. mov eax, [ebx+RASTCTX_iSurfaceStep]
  156. neg eax
  157. mov iSurfaceStep, eax
  158. ;}
  159. jmp DoneSpanDirif
  160. ;else
  161. ;{
  162. LeftToRightSpan:
  163. ;iSurfaceStep = pCtx->iSurfaceStep;
  164. mov eax, [ebx+RASTCTX_iSurfaceStep]
  165. mov iSurfaceStep, eax
  166. ;}
  167. DoneSpanDirif:
  168. movq mm6, [ebp+RASTSPAN_uB]
  169. ; Setup Code Ends
  170. ; ----------------------------------------------------------------------------------------------------------------
  171. ; Loop Code Begins
  172. PixelLoop:
  173. ; texturecode
  174. mov esi, [ebx+RASTCTX_pTexture]
  175. movq mm5, MMWORD PTR Val0x000a000a ; This is TEX_FINAL_SHIFT - 6 = 10.
  176. movd mm4, [esi+SPANTEX_iShiftU]
  177. psubw mm5, mm4
  178. movq mm4, mm5
  179. pand mm5, MMWORD PTR Val0xffff
  180. psrld mm4, 16
  181. movd mm1, [ebx+RASTCTX_SI+SPANITER_iU1]
  182. psrad mm1, mm5
  183. movd mm2, [ebx+RASTCTX_SI+SPANITER_iV1]
  184. psrad mm2, mm4
  185. punpckldq mm1, mm2
  186. movzx edx, word ptr [esi+SPANTEX_iShiftPitch]
  187. add edx, 16
  188. movd mm2, edx
  189. movq mm5, MMWORD ptr Makelow16one
  190. pslld mm5, mm2
  191. por mm5, MMWORD ptr Makelow16one
  192. psrad mm1, 6
  193. packssdw mm1, mm1 ; Value needs to be packed since all wrap/mirror
  194. movd mm0, [esi+SPANTEX_uMaskU] ; Load U and V mask
  195. movq mm7, mm1
  196. movd mm4, [esi+SPANTEX_iFlipMaskU]
  197. pand mm7, mm4
  198. pcmpeqw mm7, MMWORD PTR Zero
  199. pandn mm7, mm0
  200. pand mm1, mm0
  201. pxor mm1, mm7
  202. movq mm4, mm1
  203. pmaddwd mm4, mm5 ; Throw in first address calculation.
  204. mov edi, [esi+SPANTEX_pBits]
  205. movd eax, mm4
  206. movzx eax, word ptr [edi+2*eax]
  207. movd mm1, eax ; Make two more copies of input color
  208. movq mm2, mm1
  209. pand mm1, dword ptr MaskGreen565to888 ; MaskGreen565to888 is in memory
  210. pand mm2, dword ptr opt_MaskRed565to888 ; MaskRed565to888 in memory.
  211. psllq mm2, 24 ;RedShift565to888 ; RedShift should be an immediate
  212. psllq mm1, 13 ;GreenShift565to888
  213. shl eax, 3 ;BlueShift565to888
  214. por mm1, mm2
  215. and eax, 0FFH ;dword ptr MaskBlue565to888
  216. movd mm2, eax
  217. por mm2, mm1
  218. ;modulate
  219. movq mm1, mm6
  220. psrlw mm1, COLOR_SHIFT ; COLOR_SHIFT is set to 8.
  221. pmullw mm1, mm2
  222. ;write
  223. mov edi, [ebp+RASTSPAN_pSurface]
  224. psrlw mm1, 8 ; Convert color1 from 8.8 two 0.8
  225. packuswb mm1, mm7 ; pack one color
  226. movq mm3, mm1
  227. pand mm1, MMWORD PTR u888to565RedBlueMask
  228. pmaddwd mm1, MMWORD PTR u888to565Multiplier
  229. pand mm3, MMWORD PTR u888to565GreenMask
  230. por mm1, mm3
  231. psrld mm1, 5
  232. movd edx, mm1
  233. mov [edi], dx
  234. dec uPix
  235. jle ExitPixelLoop
  236. ; Keeping uB in MM6 so that dont need to store back and forth from memory.
  237. paddw mm6, [ecx+RASTPRIM_iDBDX]
  238. movq mm5, [ebp+RASTSPAN_iUoW1]
  239. paddd mm5, [ecx+RASTPRIM_iDUoW1DX]
  240. movq [ebp+RASTSPAN_iUoW1], mm5
  241. psrad mm5, TEX_TO_FINAL_SHIFT
  242. movq [ebx+RASTCTX_SI+SPANITER_iU1], mm5
  243. mov edx, dword ptr [ebp+RASTSPAN_pSurface]
  244. add edx, iSurfaceStep
  245. mov dword ptr [ebp+RASTSPAN_pSurface], edx
  246. jmp PixelLoop
  247. ExitPixelLoop:
  248. ; Loop code ends
  249. ;-----------------------------------------------------------------------------
  250. ; LoopAny code ends here
  251. ;-----------------------------------------------------------------------------
  252. add ebp, SIZEOF_RASTSPAN
  253. jmp SpanLoop
  254. ExitSpanLoop:
  255. mov ecx, [ecx+RASTPRIM_pNext]
  256. jmp PrimLoop
  257. ExitPrimLoop:
  258. emms
  259. xor eax, eax
  260. pop edi
  261. pop esi
  262. pop ebx
  263. mov esp, StackPos
  264. pop ebp
  265. ret
  266. END