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.

353 lines
9.5 KiB

  1. ;-----------------------------------------------------------------------------
  2. ; Monolith 15. Gouraud 16 bit Z Buffered (LE or GT) 888
  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 888.
  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, 4)
  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. iZXorMask dq ?
  64. ; Need externs for all of the variables that are needed for various beads
  65. EXTERN MaskRed565to888:MMWORD
  66. EXTERN MaskGreen565to888:MMWORD
  67. EXTERN MaskBlue565to888:MMWORD
  68. EXTERN MaskRed555to888:MMWORD
  69. EXTERN MaskGreen555to888:MMWORD
  70. EXTERN MaskBlue555to888:MMWORD
  71. EXTERN MaskAlpha1555to8888:MMWORD
  72. EXTERN MaskRed1555to8888:MMWORD
  73. EXTERN MaskGreen1555to8888:MMWORD
  74. EXTERN MaskBlue1555to8888:MMWORD
  75. ; TBD. I think that I want to do 0xffff instead of 0xff. This will
  76. ; have to be checked. There is a value very similiar to this in
  77. ; buf write.
  78. EXTERN SetAlphato0xffff:MMWORD
  79. EXTERN SetAlphato0xff:MMWORD
  80. ; TODO This equate are identical to the ones in texread.mas. Maybe they should be in a common .inc file.
  81. RedShift565to888 equ 8
  82. GreenShift565to888 equ 5
  83. BlueShift565to888 equ 3
  84. RedShift555to888 equ 9
  85. GreenShift555to888 equ 6
  86. BlueShift555to888 equ 3
  87. AlphaShift1555to8888 equ 16
  88. RedShift1555to8888 equ 9
  89. GreenShift1555to8888 equ 6
  90. BlueShift1555to8888 equ 3
  91. EXTERN Zero:MMWORD
  92. EXTERN SetAlphato0xff:MMWORD
  93. EXTERN u888to565RedBlueMask:MMWORD
  94. EXTERN u888to565GreenMask:MMWORD
  95. EXTERN u888to565Multiplier:MMWORD
  96. EXTERN uVal0x000007ff03ff07ff:MMWORD
  97. EXTERN uVal0x0000078003c00780:MMWORD
  98. EXTERN u888to555RedBlueMask:MMWORD
  99. EXTERN u888to555GreenMask:MMWORD
  100. EXTERN u888to555Multiplier:MMWORD
  101. EXTERN uVal0x000007ff07ff07ff:MMWORD
  102. EXTERN uVal0x0000078007800780:MMWORD
  103. ;-----------------------------------------------------------------------------
  104. ; Span Variables
  105. StackPos dd ?
  106. uSpans dd ?
  107. ;-----------------------------------------------------------------------------
  108. ;-----------------------------------------------------------------------------
  109. ; Loop Variables
  110. iSurfaceStep dd ?
  111. iZStep dd ?
  112. uPix dd ?
  113. ;-----------------------------------------------------------------------------
  114. .code
  115. PUBLIC _MMXMLRast_15
  116. _MMXMLRast_15:
  117. push ebp
  118. mov StackPos, esp
  119. mov eax, esp
  120. sub esp, 0Ch ; This will need to change if stack frame size changes.
  121. push ebx
  122. push esi
  123. push edi
  124. xor edi, edi
  125. ; Put pCtx into ebx
  126. mov ebx, [eax+8]
  127. ;PD3DI_RASTPRIM pP = pCtx->pPrim;
  128. mov ecx, [ebx+RASTCTX_pPrim]
  129. ; Need to generate qword iZXorMask since it in pCtx
  130. movd mm2, [ebx+RASTCTX_iZXorMask]
  131. punpckldq mm2, mm2
  132. movq MMWORD PTR iZXorMask, mm2
  133. ; ebx is free after this since gouraud does not need information from pCtx.
  134. ;while (pP)
  135. ;{
  136. PrimLoop:
  137. cmp ecx, 0
  138. je ExitPrimLoop
  139. ;UINT16 uSpans = pP->uSpans;
  140. movzx eax, word ptr [ecx+RASTPRIM_uSpans]
  141. mov uSpans, eax
  142. ;PD3DI_RASTSPAN pS = (PD3DI_RASTSPAN)(pP + 1);
  143. mov ebp, ecx
  144. add ebp, SIZEOF_RASTPRIM
  145. ;while (uSpans-- > 0)
  146. ;{
  147. SpanLoop:
  148. mov edx, uSpans
  149. mov eax, edx
  150. dec eax
  151. mov uSpans, eax
  152. test edx, edx
  153. jle ExitSpanLoop
  154. mov edi, dword ptr [ebp+RASTSPAN_pSurface]
  155. mov esi, [ebp+RASTSPAN_pZ]
  156. movzx eax, word ptr [ebp+RASTSPAN_uPix]
  157. ;if (pP->uFlags & D3DI_RASTPRIM_X_DEC)
  158. ;{
  159. mov edx, [ecx+RASTPRIM_uFlags]
  160. and edx, D3DI_RASTPRIM_X_DEC
  161. test edx, edx
  162. jz LeftToRightSpan
  163. ; SCREWED UP RIGHT TO LEFT CASE
  164. movq mm0, MMWORD PTR [ebp+RASTSPAN_uB]
  165. movd mm4, dword ptr [ebp+RASTSPAN_uZ]
  166. movd mm2, dword ptr [ecx+RASTPRIM_iDZDX]
  167. movq mm1, MMWORD PTR [ecx+RASTPRIM_iDBDX]
  168. beginingpixelsRtoL:
  169. ;WritePixel
  170. ; Ztestcode
  171. ; edx is uZ
  172. ; ebx is uZB
  173. ; 16 bit unsigned format
  174. ;UINT16 uZ = (UINT16)(pS->uZ>>15);
  175. ;UINT16 uZB = *((UINT16*)pS->pZ);
  176. movd edx, mm4
  177. shr edx, 15
  178. movzx ebx, word ptr [esi]
  179. ;pS->uZ += pP->iDZDX;
  180. ;if ((pCtx->iZXorMask)^(uZ > uZB))
  181. sub ebx, edx
  182. paddd mm4, mm2
  183. xor ebx, dword ptr iZXorMask
  184. test ebx, ebx
  185. js ZFailLabelRtoL1
  186. mov word ptr [esi], dx
  187. ; Convert color.
  188. movq mm5, mm0
  189. psrlw mm5, 8 ; Convert color1 from 8.8 two 0.8
  190. packuswb mm5, mm7 ; pack one color1
  191. movd edx, mm5
  192. and edx, 000ffffffh
  193. mov [edi], edx
  194. ZFailLabelRtoL1:
  195. dec eax ; Reduce Pixel count
  196. jz NoMorePixelsRtoL
  197. sub edi, 4 ; decrease destination pointer
  198. sub esi, 2 ; decrease Z Buffer Pointer.
  199. ;pS->uB += pP->iDBDX; pS->uG += pP->iDGDX;
  200. ;pS->uR += pP->iDRDX; pS->uA += pP->iDADX;
  201. paddw mm0, mm1
  202. jmp beginingpixelsRtoL
  203. NoMorePixelsRtoL:
  204. jmp DoneSpanDirif
  205. ;else
  206. ;{
  207. LeftToRightSpan:
  208. ; NORMAL LEFT TO RIGHT CASE
  209. movq mm0, MMWORD PTR [ebp+RASTSPAN_uB]
  210. movd mm4, dword ptr [ebp+RASTSPAN_uZ]
  211. movd mm2, dword ptr [ecx+RASTPRIM_iDZDX]
  212. movq mm1, MMWORD PTR [ecx+RASTPRIM_iDBDX]
  213. beginingpixelsLtoR:
  214. ;WritePixel
  215. ; Ztestcode
  216. ; edx is uZ
  217. ; ebx is uZB
  218. ; 16 bit unsigned format
  219. ;UINT16 uZ = (UINT16)(pS->uZ>>15);
  220. ;UINT16 uZB = *((UINT16*)pS->pZ);
  221. movd edx, mm4
  222. shr edx, 15
  223. movzx ebx, word ptr [esi]
  224. ;pS->uZ += pP->iDZDX;
  225. ;if ((pCtx->iZXorMask)^(uZ > uZB))
  226. sub ebx, edx
  227. paddd mm4, mm2
  228. xor ebx, dword ptr iZXorMask
  229. test ebx, ebx
  230. js ZFailLabelLtoR1
  231. ; Write Z
  232. mov word ptr [esi], dx
  233. ; Convert color.
  234. movq mm5, mm0
  235. psrlw mm5, 8 ; Convert color1 from 8.8 two 0.8
  236. packuswb mm5, mm7 ; pack one color1
  237. movd edx, mm5
  238. and edx, 000ffffffh
  239. mov [edi], edx
  240. ZFailLabelLtoR1:
  241. dec eax ; Reduce Pixel count
  242. jz NoMorePixelsLtoR
  243. add edi, 4 ; Increase destination pointer.
  244. add esi, 2 ; Increase Z Buffer Pointer.
  245. ;pS->uB += pP->iDBDX; pS->uG += pP->iDGDX;
  246. ;pS->uR += pP->iDRDX; pS->uA += pP->iDADX;
  247. paddw mm0, mm1
  248. jmp beginingpixelsLtoR
  249. NoMorePixelsLtoR:
  250. ;}
  251. DoneSpanDirif:
  252. ; Setup Code Ends
  253. ; ----------------------------------------------------------------------------------------------------------------
  254. ; Loop Code Begins
  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