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.

374 lines
10 KiB

  1. ;-----------------------------------------------------------------------------
  2. ; Monolith 1. Gouraud 16 bit Z Buffered (LE or GT) 565
  3. ;
  4. ; This monolith selects code to draw either left or right.
  5. ;
  6. ; Globals (ATTENTION. Need to put in stack memory so can multi-process)
  7. ; iZXorMask - Copy of iZXorMask since ebx (pCtx) is used for other
  8. ; purposes.
  9. ;
  10. ; uSpans - Count containing the number of spans.
  11. ; StackPos - Saves stack position.
  12. ;
  13. ; Register Usage:
  14. ;
  15. ; eax - Number of pixels to draw
  16. ; ebx - Zbuffer value / temp to determine Z fail
  17. ; ecx - Prim pointer. Same as in non-monolithic loop code. (i.e. C codes pCtx->pPrim)
  18. ; edx - Tri Z value in 16 bits.
  19. ; esi - Pointer to Z Buffer
  20. ; edi - Pointer to Screen Buffer.
  21. ; ebp - Rast Span Pointer. Same as in non-monolithic loop code. (i.e. pS in C code)
  22. ; mm0 - contains four color components.
  23. ; mm1 - contains delta color components.
  24. ; mm2 - Lower DWORD stores Delta Z value
  25. ; mm3 - Temp for color conversion.
  26. ; mm4 - Lower DWORD stores Z value.
  27. ; mm5 - temp for color conversion.
  28. ;
  29. ; Both Left to Right and Right to Left are very similar.
  30. ;
  31. ; Psuedo Code
  32. ;
  33. ; loop:
  34. ; Do LE/GR Z test (load ebx with Z buffer value, copy mm4 to edx then do aritmetic compare of ebx and edx)
  35. ; if (Z test passed)
  36. ; {
  37. ; Write Z (still in edx)
  38. ; copy mm0 to mm5
  39. ; convert mm5 to 565 using PMADD color conversion app note.
  40. ; write color
  41. ; }
  42. ; if (done drawing) {exit loop} (dec eax / jz NoMorePixelsLtoR)
  43. ; increment colors (mm0+=mm1)
  44. ; increment Z buffer pointer (add esi, 2)
  45. ; increment screen pointer (add edi, 2)
  46. ; jump to top of loop
  47. ;
  48. ;-----------------------------------------------------------------------------
  49. INCLUDE iammx.inc
  50. INCLUDE offs_acp.inc
  51. ; Names are read LSB to MSB, so B5G6R5 means five bits of blue starting
  52. ; at the LSB, then six bits of green, then five bits of red.
  53. ;TBD check to see if this value is correct.
  54. COLOR_SHIFT equ 8
  55. .586
  56. .model flat
  57. ; Big seperating lines seperate code into span code
  58. ; and loop code. If span and loop are not going to
  59. ; end up being combined then it will be easy to
  60. ; seperate the code.
  61. .data
  62. ; It would help if these are close together in cache lines.
  63. Val0xe000e000e000 dq 00000e000e000e000h
  64. Val0xf800f800f800f800 dq 0f800f800f800f800h
  65. Val0x07e007e007e007e0 dq 007e007e007e007e0h
  66. DeltaRed dq ?
  67. DeltaGreen dq ?
  68. DeltaBlue dq ?
  69. DeltaZTimes2 dq ?
  70. DeltaZTimes4 dq ?
  71. iZXorMask dq ?
  72. LocalZero dq 0h
  73. ; Need externs for all of the variables that are needed for various beads
  74. EXTERN MaskRed565to888:MMWORD
  75. EXTERN MaskGreen565to888:MMWORD
  76. EXTERN MaskBlue565to888:MMWORD
  77. EXTERN MaskRed555to888:MMWORD
  78. EXTERN MaskGreen555to888:MMWORD
  79. EXTERN MaskBlue555to888:MMWORD
  80. EXTERN MaskAlpha1555to8888:MMWORD
  81. EXTERN MaskRed1555to8888:MMWORD
  82. EXTERN MaskGreen1555to8888:MMWORD
  83. EXTERN MaskBlue1555to8888:MMWORD
  84. ; TBD. I think that I want to do 0xffff instead of 0xff. This will
  85. ; have to be checked. There is a value very similiar to this in
  86. ; buf write.
  87. EXTERN SetAlphato0xffff:MMWORD
  88. EXTERN SetAlphato0xff:MMWORD
  89. ; TODO This equate are identical to the ones in texread.mas. Maybe they should be in a common .inc file.
  90. RedShift565to888 equ 8
  91. GreenShift565to888 equ 5
  92. BlueShift565to888 equ 3
  93. RedShift555to888 equ 9
  94. GreenShift555to888 equ 6
  95. BlueShift555to888 equ 3
  96. AlphaShift1555to8888 equ 16
  97. RedShift1555to8888 equ 9
  98. GreenShift1555to8888 equ 6
  99. BlueShift1555to8888 equ 3
  100. EXTERN Zero:MMWORD
  101. EXTERN SetAlphato0xff:MMWORD
  102. EXTERN u888to565RedBlueMask:MMWORD
  103. EXTERN u888to565GreenMask:MMWORD
  104. EXTERN u888to565Multiplier:MMWORD
  105. EXTERN uVal0x000007ff03ff07ff:MMWORD
  106. EXTERN uVal0x0000078003c00780:MMWORD
  107. EXTERN u888to555RedBlueMask:MMWORD
  108. EXTERN u888to555GreenMask:MMWORD
  109. EXTERN u888to555Multiplier:MMWORD
  110. EXTERN uVal0x000007ff07ff07ff:MMWORD
  111. EXTERN uVal0x0000078007800780:MMWORD
  112. ;-----------------------------------------------------------------------------
  113. ; Span Variables
  114. StackPos dd ?
  115. uSpans dd ?
  116. ;-----------------------------------------------------------------------------
  117. ;-----------------------------------------------------------------------------
  118. ; Loop Variables
  119. iSurfaceStep dd ?
  120. iZStep dd ?
  121. uPix dd ?
  122. ;-----------------------------------------------------------------------------
  123. .code
  124. PUBLIC _MMXMLRast_1
  125. _MMXMLRast_1:
  126. push ebp
  127. mov StackPos, esp
  128. mov eax, esp
  129. sub esp, 0Ch ; This will need to change if stack frame size changes.
  130. push ebx
  131. push esi
  132. push edi
  133. xor edi, edi
  134. ; Put pCtx into ebx
  135. mov ebx, [eax+8]
  136. ;PD3DI_RASTPRIM pP = pCtx->pPrim;
  137. mov ecx, [ebx+RASTCTX_pPrim]
  138. ; Need to generate qword iZXorMask since it in pCtx
  139. movd mm2, [ebx+RASTCTX_iZXorMask]
  140. punpckldq mm2, mm2
  141. movq MMWORD PTR iZXorMask, mm2
  142. ; ebx is free after this since gouraud does not need information from pCtx.
  143. ;while (pP)
  144. ;{
  145. PrimLoop:
  146. cmp ecx, 0
  147. je ExitPrimLoop
  148. ;UINT16 uSpans = pP->uSpans;
  149. movzx eax, word ptr [ecx+RASTPRIM_uSpans]
  150. mov uSpans, eax
  151. ;PD3DI_RASTSPAN pS = (PD3DI_RASTSPAN)(pP + 1);
  152. mov ebp, ecx
  153. add ebp, SIZEOF_RASTPRIM
  154. ;while (uSpans-- > 0)
  155. ;{
  156. SpanLoop:
  157. mov edx, uSpans
  158. mov eax, edx
  159. dec eax
  160. mov uSpans, eax
  161. test edx, edx
  162. jle ExitSpanLoop
  163. mov edi, dword ptr [ebp+RASTSPAN_pSurface]
  164. mov esi, [ebp+RASTSPAN_pZ]
  165. movzx eax, word ptr [ebp+RASTSPAN_uPix]
  166. ;if (pP->uFlags & D3DI_RASTPRIM_X_DEC)
  167. ;{
  168. mov edx, [ecx+RASTPRIM_uFlags]
  169. and edx, D3DI_RASTPRIM_X_DEC
  170. test edx, edx
  171. jz LeftToRightSpan
  172. ; SCREWED UP RIGHT TO LEFT CASE
  173. movq mm0, MMWORD PTR [ebp+RASTSPAN_uB]
  174. movd mm4, dword ptr [ebp+RASTSPAN_uZ]
  175. movd mm2, dword ptr [ecx+RASTPRIM_iDZDX]
  176. movq mm1, MMWORD PTR [ecx+RASTPRIM_iDBDX]
  177. beginingpixelsRtoL:
  178. ;WritePixel
  179. ; Ztestcode
  180. ; edx is uZ
  181. ; ebx is uZB
  182. ; 16 bit unsigned format
  183. ;UINT16 uZ = (UINT16)(pS->uZ>>15);
  184. ;UINT16 uZB = *((UINT16*)pS->pZ);
  185. movd edx, mm4
  186. shr edx, 15
  187. movzx ebx, word ptr [esi]
  188. ;pS->uZ += pP->iDZDX;
  189. ;if ((pCtx->iZXorMask)^(uZ > uZB))
  190. sub ebx, edx
  191. paddd mm4, mm2
  192. xor ebx, dword ptr iZXorMask
  193. test ebx, ebx
  194. js ZFailLabelRtoL1
  195. mov word ptr [esi], dx
  196. ; Convert color.
  197. movq mm5, mm0
  198. psrlw mm5, 8 ; Convert color1 from 8.8 two 0.8
  199. packuswb mm5, mm5 ; Just makes a copy of itself in high and low dwords.
  200. movq mm3, mm5
  201. pand mm5, MMWORD PTR u888to565RedBlueMask
  202. pmaddwd mm5, MMWORD PTR u888to565Multiplier
  203. pand mm3, MMWORD PTR u888to565GreenMask
  204. por mm5, mm3
  205. psrld mm5, 5
  206. movd edx, mm5
  207. mov [edi], dx
  208. ZFailLabelRtoL1:
  209. dec eax ; Reduce Pixel count
  210. jz NoMorePixelsRtoL
  211. sub edi, 2 ; decrease destination pointer
  212. sub esi, 2 ; decrease Z Buffer Pointer.
  213. ;pS->uB += pP->iDBDX; pS->uG += pP->iDGDX;
  214. ;pS->uR += pP->iDRDX; pS->uA += pP->iDADX;
  215. paddw mm0, mm1
  216. jmp beginingpixelsRtoL
  217. NoMorePixelsRtoL:
  218. jmp DoneSpanDirif
  219. ;else
  220. ;{
  221. LeftToRightSpan:
  222. ; NORMAL LEFT TO RIGHT CASE
  223. movq mm0, MMWORD PTR [ebp+RASTSPAN_uB]
  224. movd mm4, dword ptr [ebp+RASTSPAN_uZ]
  225. movd mm2, dword ptr [ecx+RASTPRIM_iDZDX]
  226. movq mm1, MMWORD PTR [ecx+RASTPRIM_iDBDX]
  227. beginingpixelsLtoR:
  228. ;WritePixel
  229. ; Ztestcode
  230. ; edx is uZ
  231. ; ebx is uZB
  232. ; 16 bit unsigned format
  233. ;UINT16 uZ = (UINT16)(pS->uZ>>15);
  234. ;UINT16 uZB = *((UINT16*)pS->pZ);
  235. movd edx, mm4
  236. shr edx, 15
  237. movzx ebx, word ptr [esi]
  238. ;pS->uZ += pP->iDZDX;
  239. ;if ((pCtx->iZXorMask)^(uZ > uZB))
  240. sub ebx, edx
  241. paddd mm4, mm2
  242. xor ebx, dword ptr iZXorMask
  243. test ebx, ebx
  244. js ZFailLabelLtoR1
  245. ; Write Z
  246. mov word ptr [esi], dx
  247. ; Convert color. This color conversion is capable of converting two colors
  248. ; at once, but conditional Z would make this more difficult if using masks.
  249. movq mm5, mm0
  250. psrlw mm5, 8 ; Convert color1 from 8.8 two 0.8
  251. packuswb mm5, mm5 ; Just makes a copy of itself in high and low dwords.
  252. movq mm3, mm5
  253. pand mm5, MMWORD PTR u888to565RedBlueMask
  254. pmaddwd mm5, MMWORD PTR u888to565Multiplier
  255. pand mm3, MMWORD PTR u888to565GreenMask
  256. por mm5, mm3
  257. psrld mm5, 5
  258. movd edx, mm5
  259. mov [edi], dx
  260. ZFailLabelLtoR1:
  261. dec eax ; Reduce Pixel count
  262. jz NoMorePixelsLtoR
  263. add edi, 2 ; Increase destination pointer.
  264. add esi, 2 ; Increase Z Buffer Pointer.
  265. ;pS->uB += pP->iDBDX; pS->uG += pP->iDGDX;
  266. ;pS->uR += pP->iDRDX; pS->uA += pP->iDADX;
  267. paddw mm0, mm1
  268. jmp beginingpixelsLtoR
  269. NoMorePixelsLtoR:
  270. ;}
  271. DoneSpanDirif:
  272. ; Setup Code Ends
  273. ; ----------------------------------------------------------------------------------------------------------------
  274. ; Loop Code Begins
  275. ExitPixelLoop:
  276. ; Loop code ends
  277. ;-----------------------------------------------------------------------------
  278. ; LoopAny code ends here
  279. ;-----------------------------------------------------------------------------
  280. ;pS++;
  281. add ebp, SIZEOF_RASTSPAN
  282. ;}
  283. jmp SpanLoop
  284. ExitSpanLoop:
  285. ;pP = pP->pNext;
  286. mov ecx, [ecx+RASTPRIM_pNext]
  287. ;}
  288. jmp PrimLoop
  289. ExitPrimLoop:
  290. ;_asm{
  291. emms
  292. ;}
  293. ;return S_OK;
  294. xor eax, eax
  295. ;}
  296. pop edi
  297. pop esi
  298. pop ebx
  299. mov esp, StackPos
  300. pop ebp
  301. ret
  302. END