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.

430 lines
11 KiB

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