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.

1378 lines
44 KiB

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ; This file contains x86 assembly attribute setup.
  4. ;
  5. ; Copyright (C) Microsoft Corporation, 1997.
  6. ;
  7. ; WARNING WARNING WARNING
  8. ; This assembly file generated from mas file.
  9. ; EDIT THE MAS FILE.
  10. ; I warned you.
  11. ; WARNING WARNING WARNING
  12. ;
  13. ;-----------------------------------------------------------------------------
  14. include(`m4hdr.mh')dnl
  15. .386p
  16. .MODEL FLAT
  17. INCLUDE offs_acp.inc
  18. INCLUDE profile.inc
  19. INCLUDE texdiff.inc
  20. EXTERN @ComputeTableFog@8:NEAR
  21. EXTERN _g_fOne:DWORD
  22. .CODE
  23. dnl
  24. dnl d_CorrectAttr
  25. dnl
  26. dnl Generates code to compute the DX and DY steps, the
  27. dnl corrected scaled initial value and the NC and CY steps.
  28. dnl
  29. dnl ebx is assumed to be the PSETUPCTX.
  30. dnl $1 is the ATTRSET offset of the value being corrected.
  31. dnl $2 is the name of the uncorrected initial value.
  32. dnl $3 is the name of the DAttr20 value.
  33. dnl $4 is the name of the DAttr10 value.
  34. dnl $5 is the name of the scale to apply to the initial value before
  35. dnl correction.
  36. dnl
  37. define(`d_CorrectAttr',
  38. ` fld DWORD PTR [ebx+SCTX_fNY10] ; NY10
  39. fmul DWORD PTR $3 ; DXp
  40. fld DWORD PTR [ebx+SCTX_fNY20] ; NY20 DXp
  41. fmul DWORD PTR $4 ; DXn DXp
  42. fld DWORD PTR [ebx+SCTX_fNX20] ; NX20 DXn DXp
  43. fmul DWORD PTR $4 ; DYp DXn DXp
  44. fxch st(2) ; DXp DXn DYp
  45. fld DWORD PTR [ebx+SCTX_fNX10] ; NX10 DXp DXn DYp
  46. fmul DWORD PTR $3 ; DYn DXp DXn DYp
  47. fxch st(2) ; DXn DXp DYn DYp
  48. fsubp st(1), st(0) ; DX DYn DYp
  49. fld DWORD PTR $2 ; 0 DX DYn DYp
  50. fmul DWORD PTR $5 ; 0 DX DYn DYp
  51. fxch st(3) ; DYp DX DYn 0
  52. fld DWORD PTR [ebx+SCTX_fDX] ; fDX DYp DX DYn 0
  53. fmul st(0), st(2) ; cX DYp DX DYn 0
  54. fxch st(3) ; DYn DYp DX cX 0
  55. fsubp st(1), st(0) ; DY DX cX 0
  56. fxch st(3) ; 0 DX cX DY
  57. fld DWORD PTR [ebx+SCTX_fX20NC] ; iNC 0 DX cX DY
  58. fmul st(0), st(2) ; XNC 0 DX cX DY
  59. fxch st(3) ; cX 0 DX XNC DY
  60. faddp st(1), st(0) ; c0X DX XNC DY
  61. fld DWORD PTR [ebx+SCTX_fDY] ; fDY c0X DX XNC DY
  62. fmul st(0), st(4) ; cY c0X DX XNC DY
  63. fxch st(3) ; XNC c0X DX cY DY
  64. fadd st(0), st(4) ; NC c0X DX cY DY
  65. fxch st(1) ; c0X NC DX cY DY
  66. fld DWORD PTR [ebx+SCTX_fX20CY] ; iCY c0X NC DX cY DY
  67. fmul st(0), st(3) ; XCY c0X NC DX cY DY
  68. fxch st(4) ; cY c0X NC DX XCY DY
  69. faddp st(1), st(0) ; c0 NC DX XCY DY
  70. fxch st(1) ; NC c0 DX XCY DY
  71. fstp DWORD PTR [ebx+SCTX_DAttrNC+$1] ; c0 DX XCY DY
  72. fxch st(1) ; DX c0 XCY DY
  73. fstp DWORD PTR [ebx+SCTX_DAttrDX+$1] ; c0 XCY DY
  74. fxch st(1) ; XCY c0 DY
  75. fadd st(0), st(2) ; CY c0 DY
  76. fxch st(1) ; c0 CY DY
  77. fstp DWORD PTR [ebx+SCTX_Attr+$1] ; CY DY
  78. fxch st(1) ; DY CY
  79. fstp DWORD PTR [ebx+SCTX_DAttrDY+$1] ; CY
  80. fstp DWORD PTR [ebx+SCTX_DAttrCY+$1] ;
  81. ')dnl
  82. dnl
  83. dnl d_NegateDeltas
  84. dnl
  85. dnl If X_DEC, negates the given list of deltas in DAttrDX.
  86. dnl
  87. dnl $1 is the name of the block for labels.
  88. dnl Following arguments are ATTRSET offsets in the DAttrDX to process.
  89. dnl
  90. dnl Leaves uFlags in eax.
  91. dnl
  92. define(`d_NegateDeltaLoop',
  93. ` mov eax, [ebx+SCTX_DAttrDX+$1]
  94. xor eax, 080000000h
  95. mov [ebx+SCTX_DAttrDX+$1], eax
  96. ifelse(eval($# > 1), `1', `d_NegateDeltaLoop(d_shift($@))')')dnl
  97. dnl
  98. define(`d_NegateDeltas',
  99. ` mov eax, [ebx+SCTX_uFlags]
  100. test eax, TRIF_X_DEC
  101. jz L_NDXDZ_$1
  102. ; X_DEC. Negate deltas.
  103. d_NegateDeltaLoop(d_shift($@))dnl
  104. mov eax, [ebx+SCTX_uFlags]
  105. L_NDXDZ_$1:
  106. ')dnl
  107. dnl
  108. dnl d_CheckRpDeltas
  109. dnl
  110. dnl Checks given list of deltas against the given limit for
  111. dnl setting of TRIF_RASTPRIM_OVERFLOW. The delta comparisons
  112. dnl can be done in pure integer because the numbers involved are
  113. dnl always positive.
  114. dnl
  115. dnl RASTPRIM filling is usually done in the non-overflow block so
  116. dnl arbitrary processing can be done there by defining the d_CRPD_Post macro
  117. dnl before invocation of this one.
  118. dnl
  119. dnl $1 is the name of the block for labels.
  120. dnl $2 is the name of the limit.
  121. dnl Following arguments are deltas offsets in the SETUPCTX to check.
  122. dnl
  123. dnl Relies on uFlags being in eax at the start. Leaves uFlags in eax.
  124. dnl
  125. define(`d_CheckRpDeltaLoop',
  126. ` mov eax, [ebx+$3]
  127. and eax, 07fffffffh
  128. cmp eax, $2
  129. jge L_RPOD_$1
  130. ifelse(eval($# > 3), `1',
  131. `d_CheckRpDeltaLoop($1, $2, d_shift(d_shift(d_shift($@))))')')dnl
  132. dnl
  133. define(`d_CheckRpDeltas',
  134. ` test eax, TRIF_RASTPRIM_OVERFLOW
  135. jnz L_RPOD_NoLoad_$1
  136. d_CheckRpDeltaLoop($@)dnl
  137. ; No overflow. Do valid delta processing.
  138. d_CRPD_Post(d_shift($@))
  139. mov eax, [ebx+SCTX_uFlags]
  140. jmp L_RP_Exit_$1
  141. L_RPOD_$1:
  142. ; Overflow detected.
  143. mov eax, [ebx+SCTX_uFlags]
  144. L_RPOD_NoLoad_$1:
  145. or eax, TRIF_RASTPRIM_OVERFLOW
  146. mov [ebx+SCTX_uFlags], eax
  147. L_RP_Exit_$1:
  148. ')dnl
  149. dnl
  150. dnl d_CheckFxDeltas
  151. dnl
  152. dnl Checks given list of deltas against the given limit for
  153. dnl setting of TRIF_FIXED_OVERFLOW. The delta comparisons
  154. dnl can be done in pure integer because the numbers involved are
  155. dnl always positive.
  156. dnl
  157. dnl $1 is the name of the block for labels.
  158. dnl $2 is the name of the limit.
  159. dnl Following arguments are ATTRSET offsets in NC and CY to check.
  160. dnl
  161. define(`d_CheckFxDeltaLoop',
  162. ` mov eax, [ebx+SCTX_DAttrNC+$3]
  163. and eax, 07fffffffh
  164. cmp eax, $2
  165. jge L_FXOD_$1
  166. mov eax, [ebx+SCTX_DAttrCY+$3]
  167. and eax, 07fffffffh
  168. cmp eax, $2
  169. jge L_FXOD_$1
  170. ifelse(eval($# > 3), `1',
  171. `d_CheckFxDeltaLoop($1, $2, d_shift(d_shift(d_shift($@))))')')dnl
  172. dnl
  173. define(`d_CheckFxDeltas',
  174. `IFDEF STEP_FIXED
  175. test eax, TRIF_FIXED_OVERFLOW
  176. jnz L_FXOD_NoLoad_$1
  177. d_CheckFxDeltaLoop($@)dnl
  178. ; No overflow.
  179. jmp L_FX_Exit_$1
  180. L_FXOD_$1:
  181. ; Overflow detected.
  182. mov eax, [ebx+SCTX_uFlags]
  183. L_FXOD_NoLoad_$1:
  184. or eax, TRIF_FIXED_OVERFLOW
  185. mov [ebx+SCTX_uFlags], eax
  186. L_FX_Exit_$1:
  187. ENDIF
  188. ')dnl
  189. dnl
  190. dnl d_ZSetup
  191. dnl
  192. dnl Does Z setup.
  193. dnl
  194. dnl $1 is the Z buffer depth.
  195. dnl
  196. define(`d_ZSetup',
  197. ` ;
  198. ; Slot a is used.
  199. ;
  200. ; Compute Z deltas.
  201. fld DWORD PTR [edx+TL_dvSZ] ; Z2
  202. fsub DWORD PTR [edi+TL_dvSZ] ; DZ20
  203. fld DWORD PTR [ecx+TL_dvSZ] ; Z1 DZ20
  204. fsub DWORD PTR [edi+TL_dvSZ] ; DZ10 DZ20
  205. ; Get initial Z and scale Z deltas.
  206. mov eax, [edi+TL_dvSZ]
  207. fxch st(1) ; DZ20 DZ10
  208. fmul Z$1_SCALE ; DZ20 DZ10
  209. fxch st(1) ; DZ10 DZ20
  210. fmul Z$1_SCALE ; DZ10 DZ20
  211. mov fVa0, eax
  212. fxch st(1) ; DZ20 DZ10
  213. fstp fDVa20 ; DZ10
  214. fstp fDVa10 ;
  215. d_CorrectAttr(`ATTRSET_fZ', `fVa0', `fDVa20', `fDVa10', Z$1_SCALE)dnl
  216. d_NegateDeltas(Z$1, `ATTRSET_fZ')dnl
  217. pushdef(`d_CRPD_Post',
  218. ` mov eax, [ebx+SCTX_pPrim]
  219. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fZ]
  220. fistp DWORD PTR [eax+RASTPRIM_iDZDX]
  221. ')dnl
  222. d_CheckRpDeltas(Z$1, `C_Z_LIMIT', `SCTX_DAttrDX+ATTRSET_fZ')dnl
  223. popdef(`d_CRPD_Post')dnl
  224. d_CheckFxDeltas(Z$1, `C_Z_LIMIT', `ATTRSET_fZ')dnl
  225. ; Jump to next bead.
  226. jmp DWORD PTR [ebx+SCTX_pfnTriSetupZEnd]
  227. ')dnl
  228. dnl
  229. dnl d_TexSetupStart
  230. dnl
  231. dnl Begins texture coordinate setup.
  232. dnl
  233. dnl iTex is the texcoord index, 0 ... 7.
  234. dnl
  235. define(`d_TexSetupStart',
  236. ` mov eax, iTex
  237. mov ecx, DWORD PTR [esi+RS_WRAP0+eax * 4] ; Wrap flags
  238. mov eax, ecx
  239. and ecx, D3DWRAP_U
  240. and eax, D3DWRAP_V
  241. mov bWrapU, ecx
  242. mov ecx, pV1
  243. mov bWrapV, eax
  244. ')dnl
  245. dnl
  246. dnl d_TexSetupFinish
  247. dnl
  248. dnl Completes texture coordinate setup.
  249. dnl
  250. dnl iTex is the texcoord index, 0 ... 7.
  251. dnl
  252. define(`d_TexSetupFinish',
  253. ` mov ecx, iTex
  254. d_CorrectAttr(ATTRSET_fUoW + ecx * 4, `fVa0', `fDVa20', `fDVa10', `TEX_SCALE')dnl
  255. d_CorrectAttr(ATTRSET_fVoW + ecx * 4, `fVb0', `fDVb20', `fDVb10', `TEX_SCALE')dnl
  256. d_NegateDeltas(Tex, ATTRSET_fUoW + ecx * 4, ATTRSET_fVoW + ecx * 4)dnl
  257. pushdef(`d_CRPD_Post',
  258. ` mov eax, [ebx+SCTX_pPrim]
  259. mov ecx, iTex
  260. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fUoW + ecx * 4]
  261. fistp DWORD PTR [eax+RASTPRIM_DUVoWDX + ecx * 8]
  262. fld DWORD PTR [ebx+SCTX_DAttrDY+ATTRSET_fUoW + ecx * 4]
  263. fistp DWORD PTR [eax+RASTPRIM_DUVoWDY + ecx * 8]
  264. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fVoW + ecx * 4]
  265. fistp DWORD PTR [eax+RASTPRIM_DUVoWDX + ecx * 8 + 4]
  266. fld DWORD PTR [ebx+SCTX_DAttrDY+ATTRSET_fVoW + ecx * 4]
  267. fistp DWORD PTR [eax+RASTPRIM_DUVoWDY + ecx * 8 + 4]
  268. ')dnl
  269. d_CheckRpDeltas(Tex, `C_TEX_LIMIT',
  270. SCTX_DAttrDX+ATTRSET_fUoW + ecx * 4,
  271. SCTX_DAttrDY+ATTRSET_fUoW + ecx * 4,
  272. SCTX_DAttrDX+ATTRSET_fVoW + ecx * 4,
  273. SCTX_DAttrDY+ATTRSET_fVoW + ecx * 4)dnl
  274. popdef(`d_CRPD_Post')dnl
  275. d_CheckFxDeltas(Tex, `C_TEX_LIMIT', ATTRSET_fUoW + ecx * 4, ATTRSET_fVoW + ecx * 4)dnl
  276. ')dnl
  277. dnl
  278. dnl d_PerspTexDeltas
  279. dnl
  280. dnl Computes UoW,VoW texture deltas.
  281. dnl
  282. dnl
  283. define(`d_PerspTexDeltas',
  284. ` ; Get UoW, VoW and scaled deltas.
  285. mov eax, iTex
  286. fld DWORD PTR [edi+TM_texCoord+eax*8] ; U
  287. fmul DWORD PTR [edi+TL_dvRHW] ; UoW
  288. fld DWORD PTR [edi+TM_texCoord+eax*8+4] ; V UoW
  289. fmul DWORD PTR [edi+TL_dvRHW] ; VoW UoW
  290. fxch st(1) ; UoW VoW
  291. fstp fVa0 ; VoW
  292. fstp fVb0 ;
  293. ; DU20.
  294. TEXTURE_DIFF DWORD PTR [edx+TM_texCoord+eax*8], DWORD PTR [edi+TM_texCoord+eax*8], bWrapU, fTmp
  295. mov eax, iTex
  296. fadd DWORD PTR [edi+TM_texCoord+eax*8]
  297. mov ecx, pV1
  298. fmul DWORD PTR [edx+TL_dvRHW]
  299. ; DU10.
  300. TEXTURE_DIFF DWORD PTR [ecx+TM_texCoord+eax*8], DWORD PTR [edi+TM_texCoord+eax*8], bWrapU, fTmp
  301. fxch st(1)
  302. mov ecx, pV1
  303. ; DU20.
  304. fsub fVa0
  305. fmul TEX_SCALE
  306. fstp fDVa20
  307. ; DU10.
  308. mov eax, iTex
  309. fadd DWORD PTR [edi+TM_texCoord+eax*8]
  310. fmul DWORD PTR [ecx+TL_dvRHW]
  311. ; DV20.
  312. TEXTURE_DIFF DWORD PTR [edx+TM_texCoord+eax*8+4], DWORD PTR [edi+TM_texCoord+eax*8+4], bWrapV, fTmp
  313. fxch st(1)
  314. mov ecx, pV1
  315. ; DU10.
  316. fsub fVa0
  317. fmul TEX_SCALE
  318. fstp fDVa10
  319. ; DV20.
  320. mov eax, iTex
  321. fadd DWORD PTR [edi+TM_texCoord+eax*8+4]
  322. fmul DWORD PTR [edx+TL_dvRHW]
  323. ; DV10.
  324. TEXTURE_DIFF DWORD PTR [ecx+TM_texCoord+eax*8+4], DWORD PTR [edi+TM_texCoord+eax*8+4], bWrapV, fTmp
  325. fxch st(1)
  326. mov ecx, pV1
  327. ; DV20.
  328. fsub fVb0
  329. fmul TEX_SCALE
  330. fstp fDVb20
  331. ; Finish DV10.
  332. mov eax, iTex
  333. fadd DWORD PTR [edi+TM_texCoord+eax*8+4]
  334. fmul DWORD PTR [ecx+TL_dvRHW]
  335. fsub fVb0
  336. fmul TEX_SCALE
  337. fstp fDVb10
  338. ')dnl
  339. dnl
  340. dnl d_PerspTexSetup
  341. dnl
  342. dnl Produces perspective-correct texcoord setup code.
  343. dnl
  344. dnl $1 is the vertex U offset to use.
  345. dnl $2 is the vertex V offset to use.
  346. dnl $3 is the texcoord index, 1 or 2.
  347. dnl
  348. define(`d_PerspTexSetup',
  349. ` xor eax, eax
  350. mov iTex, eax
  351. LoopPerspTexSetup:
  352. mov ecx, [ebx + SCTX_pCtx]
  353. cmp eax, DWORD PTR [ecx + RCTX_cActTex]
  354. jge DonePerspTexSetup
  355. d_TexSetupStart()dnl
  356. d_PerspTexDeltas()dnl
  357. d_TexSetupFinish()dnl
  358. mov eax, iTex
  359. inc eax
  360. mov iTex, eax
  361. jmp LoopPerspTexSetup
  362. DonePerspTexSetup:
  363. ')dnl
  364. dnl
  365. dnl d_AffineTexDeltas
  366. dnl
  367. dnl Computes U,V texture deltas.
  368. dnl
  369. dnl $1 is the vertex U offset to use.
  370. dnl $2 is the vertex V offset to use.
  371. dnl
  372. define(`d_AffineTexDeltas',
  373. ` ; Get scaled deltas.
  374. ; Start DU20.
  375. mov eax, iTex
  376. mov eax, [edi+TM_texCoord+eax*8]
  377. ; Save U in fVa0
  378. mov fVa0, eax
  379. mov eax, iTex
  380. TEXTURE_DIFF DWORD PTR [edx+TM_texCoord+eax*8], DWORD PTR [edi+TM_texCoord+eax*8], bWrapU, fTmp
  381. fmul TEX_SCALE
  382. mov ecx, pV1
  383. fstp fDVa20
  384. ; DU10.
  385. mov eax, iTex
  386. TEXTURE_DIFF DWORD PTR [ecx+TM_texCoord+eax*8], DWORD PTR [edi+TM_texCoord+eax*8], bWrapU, fTmp
  387. fmul TEX_SCALE
  388. mov ecx, pV1
  389. ; Start DV20.
  390. mov eax, iTex
  391. mov eax, [edi+TM_texCoord+eax*8+4]
  392. ; Save V in fVb0
  393. mov fVb0, eax
  394. ; DU10.
  395. fstp fDVa10
  396. ; DV20.
  397. mov eax, iTex
  398. TEXTURE_DIFF DWORD PTR [edx+TM_texCoord+eax*8+4], DWORD PTR [edi+TM_texCoord+eax*8+4], bWrapV, fTmp
  399. fmul TEX_SCALE
  400. mov ecx, pV1
  401. ; DV20.
  402. fstp fDVb20
  403. ; DV10.
  404. mov eax, iTex
  405. TEXTURE_DIFF DWORD PTR [ecx+TM_texCoord+eax*8+4], DWORD PTR [edi+TM_texCoord+eax*8+4], bWrapV, fTmp
  406. fmul TEX_SCALE
  407. mov ecx, pV1
  408. fstp fDVb10
  409. ')dnl
  410. dnl
  411. dnl d_AffineTexSetup
  412. dnl
  413. dnl Produces affine-mapped texcoord setup code.
  414. dnl
  415. dnl $1 is the vertex U offset to use.
  416. dnl $2 is the vertex V offset to use.
  417. dnl $3 is the texcoord index, 1 or 2.
  418. dnl
  419. define(`d_AffineTexSetup',
  420. ` mov eax, 0
  421. mov iTex, eax
  422. LoopAffineTexSetup:
  423. mov ecx, [ebx + SCTX_pCtx]
  424. cmp eax, DWORD PTR [ecx + RCTX_cActTex]
  425. je DoneAffineTexSetup
  426. d_TexSetupStart()dnl
  427. d_AffineTexDeltas()dnl
  428. d_TexSetupFinish()dnl
  429. mov eax, iTex
  430. inc eax
  431. mov iTex, eax
  432. jmp LoopAffineTexSetup
  433. DoneAffineTexSetup:
  434. ')dnl
  435. dnl
  436. dnl d_ColorDelta
  437. dnl
  438. dnl Produces color B - A code.
  439. dnl
  440. dnl $1 is the packed color address to use.
  441. dnl $2 is the edge suffix, `2' or `1'.
  442. dnl
  443. define(`d_ColorDelta',
  444. ` ; A0 R0 G0 B0 sit at the end of the stack throughout.
  445. mov eax, [$1]
  446. mov ecx, eax
  447. ; B is in the correct shifted position.
  448. and eax, 0ffh
  449. mov fTmp, eax
  450. fild fTmp ; B
  451. ; Shift G and store.
  452. mov eax, ecx
  453. shr eax, 8
  454. and eax, 0ffh
  455. mov fTmp, eax
  456. fsub st(0), st(4) ; dB
  457. fild fTmp ; G dB
  458. ; Shift R and store.
  459. mov eax, ecx
  460. shr eax, 16
  461. and eax, 0ffh
  462. mov fTmp, eax
  463. fsub st(0), st(4) ; dG dB
  464. fild fTmp ; R dG dB
  465. ; Shift A and store.
  466. mov eax, ecx
  467. shr eax, 24
  468. mov fTmp, eax
  469. fsub st(0), st(4) ; dR dG dB
  470. fild fTmp ; A dR dG dB
  471. ; Scale deltas.
  472. fxch st(3) ; dB dR dG A
  473. fmul COLOR_SCALE ; dB dR dG A
  474. fxch st(3) ; A dR dG dB
  475. fsub st(0), st(4) ; dA dR dG dB
  476. fxch st(2) ; dG dR dA dB
  477. fmul COLOR_SCALE ; dG dR dA dB
  478. fxch st(1) ; dR dG dA dB
  479. fmul COLOR_SCALE ; dR dG dA dB
  480. fxch st(2) ; dA dG dR dB
  481. fmul COLOR_SCALE ; dA dG dR dB
  482. fxch st(3) ; dB dG dR dA
  483. fstp fDVa$2`'0 ; dG dR dA
  484. fstp fDVb$2`'0 ; dR dA
  485. fstp fDVc$2`'0 ; dA
  486. fstp fDVd$2`'0 ;
  487. ')dnl
  488. dnl
  489. dnl d_SColorDelta
  490. dnl
  491. dnl Produces specular color B - A code.
  492. dnl
  493. dnl $1 is the packed color address to use.
  494. dnl $2 is the edge suffix, `2' or `1'.
  495. dnl
  496. define(`d_SColorDelta',
  497. ` ; R0 G0 B0 sit at the end of the stack throughout.
  498. mov eax, [$1]
  499. mov ecx, eax
  500. ; B is in the correct shifted position.
  501. and eax, 0ffh
  502. mov fTmp, eax
  503. fild fTmp ; B
  504. ; Shift G and store.
  505. mov eax, ecx
  506. shr eax, 8
  507. and eax, 0ffh
  508. mov fTmp, eax
  509. fsub st(0), st(3) ; dB
  510. fild fTmp ; G dB
  511. ; Shift R and store.
  512. mov eax, ecx
  513. shr eax, 16
  514. and eax, 0ffh
  515. mov fTmp, eax
  516. fsub st(0), st(3) ; dG dB
  517. fild fTmp ; R dG dB
  518. ; Scale deltas.
  519. fxch st(2) ; dB dG R
  520. fmul COLOR_SCALE ; dB dG R
  521. fxch st(2) ; R dG dB
  522. fsub st(0), st(3) ; dR dG dB
  523. fxch st(1) ; dG dR dB
  524. fmul COLOR_SCALE ; dG dR dB
  525. fxch st(1) ; dR dG dB
  526. fmul COLOR_SCALE ; dR dG dB
  527. fxch st(2) ; dB dG dR
  528. fstp fDVa$2`'0 ; dG dR
  529. fstp fDVb$2`'0 ; dR
  530. fstp fDVc$2`'0 ;
  531. ')dnl
  532. dnl
  533. dnl d_IdxColorDelta
  534. dnl
  535. dnl Produces indexed color B - A code.
  536. dnl
  537. dnl $1 is the packed color address to use.
  538. dnl $2 is the edge suffix, `2' or `1'.
  539. dnl
  540. define(`d_IdxColorDelta',
  541. ` ; A0 Idx0 sit at the end of the stack throughout.
  542. mov eax, [$1]
  543. mov ecx, eax
  544. ; Mask off alpha.
  545. and eax, 0ffffffh
  546. add eax, 128
  547. mov fTmp, eax
  548. fild fTmp ; Idx
  549. ; Shift A and store.
  550. shr ecx, 24
  551. mov fTmp, ecx
  552. fsub st(0), st(2) ; dIdx
  553. fild fTmp ; A dIdx
  554. ; Scale deltas.
  555. fxch st(1) ; dIdx A
  556. fmul INDEX_COLOR_FIXED_SCALE ; dIdx A
  557. fxch st(1) ; A dIdx
  558. fsub st(0), st(2) ; dA dIdx
  559. fxch st(1) ; dIdx dA
  560. fstp fDVa$2`'0 ; dA
  561. fmul INDEX_COLOR_SCALE ; dA
  562. fstp fDVb$2`'0 ;
  563. ')dnl
  564. dnl
  565. dnl d_ColorSetup
  566. dnl
  567. dnl Produces color setup code.
  568. dnl
  569. dnl $1 is the vertex packed color offset to use.
  570. dnl $2 is the color suffix, `' or `S'.
  571. dnl
  572. define(`d_ColorSetup',
  573. ` ; Get colors from pV0.
  574. mov eax, [edi+$1]
  575. mov ecx, eax
  576. ; B is in the correct shifted position.
  577. and eax, 0ffh
  578. mov fVa0, eax
  579. fild fVa0 ; B
  580. ; Shift G and store.
  581. mov eax, ecx
  582. shr eax, 8
  583. and eax, 0ffh
  584. mov fVb0, eax
  585. fild fVb0 ; G B
  586. ; Shift R and store.
  587. mov eax, ecx
  588. shr eax, 16
  589. and eax, 0ffh
  590. mov fVc0, eax
  591. fild fVc0 ; R G B
  592. ifelse($2, `',
  593. ` ; Shift A and store.
  594. mov eax, ecx
  595. shr eax, 24
  596. mov fVd0, eax
  597. fild fVd0 ; A R G B
  598. ')dnl
  599. ; Get colors from pV2 and subtract pV0.
  600. d_$2ColorDelta(edx+$1, `2')dnl
  601. ; Get colors from pV1 and subtract pV0.
  602. mov ecx, pV1
  603. d_$2ColorDelta(ecx+$1, `1')dnl
  604. mov ecx, pV1
  605. ; Store initial values.
  606. ifelse($2, `',
  607. ` fxch st(3) ; B R G A
  608. fstp fVa0 ; R G A
  609. fxch st(1) ; G R A
  610. fstp fVb0 ; R A
  611. fstp fVc0 ; A
  612. fstp fVd0 ;
  613. ',
  614. ` fxch st(2) ; B G R
  615. fstp fVa0 ; G R
  616. fstp fVb0 ; R
  617. fstp fVc0 ;
  618. ')dnl
  619. d_CorrectAttr(ATTRSET_fB$2, `fVa0', `fDVa20', `fDVa10', `COLOR_SCALE')dnl
  620. d_CorrectAttr(ATTRSET_fG$2, `fVb0', `fDVb20', `fDVb10', `COLOR_SCALE')dnl
  621. d_CorrectAttr(ATTRSET_fR$2, `fVc0', `fDVc20', `fDVc10', `COLOR_SCALE')dnl
  622. ifelse($2, `',
  623. `d_CorrectAttr(ATTRSET_fA$2, `fVd0', `fDVd20', `fDVd10', `COLOR_SCALE')dnl
  624. d_NegateDeltas(Col$2, ATTRSET_fB$2, ATTRSET_fG$2,
  625. ATTRSET_fR$2, ATTRSET_fA$2)dnl
  626. pushdef(`d_CRPD_Post',
  627. ` mov eax, [ebx+SCTX_pPrim]
  628. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fB$2]
  629. fistp DWORD PTR [eax+RASTPRIM_iDB$2DX]
  630. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fG$2]
  631. fistp DWORD PTR [eax+RASTPRIM_iDG$2DX]
  632. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fR$2]
  633. fistp DWORD PTR [eax+RASTPRIM_iDR$2DX]
  634. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fA$2]
  635. fistp DWORD PTR [eax+RASTPRIM_iDA$2DX]
  636. ')dnl
  637. d_CheckRpDeltas(Col$2, `C_COLOR_LIMIT',
  638. SCTX_DAttrDX+ATTRSET_fB$2,
  639. SCTX_DAttrDX+ATTRSET_fR$2,
  640. SCTX_DAttrDX+ATTRSET_fG$2,
  641. SCTX_DAttrDX+ATTRSET_fA$2)dnl
  642. popdef(`d_CRPD_Post')dnl
  643. d_CheckFxDeltas(Col$2, `C_COLOR_LIMIT',
  644. ATTRSET_fB$2, ATTRSET_fG$2, ATTRSET_fR$2, ATTRSET_fA$2)',
  645. `d_NegateDeltas(Col$2, ATTRSET_fB$2, ATTRSET_fG$2,
  646. ATTRSET_fR$2)dnl
  647. pushdef(`d_CRPD_Post',
  648. ` mov eax, [ebx+SCTX_pPrim]
  649. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fB$2]
  650. fistp DWORD PTR [eax+RASTPRIM_iDB$2DX]
  651. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fG$2]
  652. fistp DWORD PTR [eax+RASTPRIM_iDG$2DX]
  653. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fR$2]
  654. fistp DWORD PTR [eax+RASTPRIM_iDR$2DX]
  655. ')dnl
  656. d_CheckRpDeltas(Col$2, `C_COLOR_LIMIT',
  657. SCTX_DAttrDX+ATTRSET_fB$2,
  658. SCTX_DAttrDX+ATTRSET_fR$2,
  659. SCTX_DAttrDX+ATTRSET_fG$2)dnl
  660. popdef(`d_CRPD_Post')dnl
  661. d_CheckFxDeltas(Col$2, `C_COLOR_LIMIT',
  662. ATTRSET_fB$2, ATTRSET_fG$2, ATTRSET_fR$2)')dnl
  663. ')dnl
  664. ;
  665. ; Locations of stack variables.
  666. ; Done as equates since setup functions don't have real stack frames.
  667. ;
  668. ; Generic storage slots for initial value and deltas.
  669. fVa0 EQU DWORD PTR [ebp-4]
  670. fDVa20 EQU DWORD PTR [ebp-8]
  671. fDVa10 EQU DWORD PTR [ebp-12]
  672. fVb0 EQU DWORD PTR [ebp-16]
  673. fDVb20 EQU DWORD PTR [ebp-20]
  674. fDVb10 EQU DWORD PTR [ebp-24]
  675. fVc0 EQU DWORD PTR [ebp-28]
  676. fDVc20 EQU DWORD PTR [ebp-32]
  677. fDVc10 EQU DWORD PTR [ebp-36]
  678. fVd0 EQU DWORD PTR [ebp-40]
  679. fDVd20 EQU DWORD PTR [ebp-44]
  680. fDVd10 EQU DWORD PTR [ebp-48]
  681. fTmp EQU DWORD PTR [ebp-52]
  682. bWrapU EQU DWORD PTR [ebp-56]
  683. bWrapV EQU DWORD PTR [ebp-60]
  684. iTex EQU DWORD PTR [ebp-64]
  685. SETUP_LOCALS EQU 64
  686. ; Parameters
  687. pV1 EQU DWORD PTR [ebp+20]
  688. pV2 EQU DWORD PTR [ebp+24]
  689. dnl d_DeclTriSetup
  690. dnl
  691. dnl Declare a PFN_SETUPATTR from its attribute name.
  692. dnl
  693. dnl $1 is the attribute name.
  694. dnl
  695. define(`d_DeclTriSetup',
  696. `@TriSetup_$1@16 PROC SYSCALL PUBLIC
  697. PROF_ENTRY
  698. ')dnl
  699. define(`d_EndDeclTriSetup',
  700. `@TriSetup_$1@16 ENDP
  701. ')dnl
  702. dnl
  703. ;-----------------------------------------------------------------------------
  704. ;
  705. ; Setup_Start
  706. ;
  707. ; Establishes the stack frame for all setup routines, including
  708. ; preservation of registers and allocation of local storage space.
  709. ; Scales deltas by fOoDet.
  710. ; Puts pStpCtx in ebx, pV0 in edi, pV1 in ecx, pV2 in edx and
  711. ; pdwRenderState in esi.
  712. ; Jumps to first attribute setup bead.
  713. ;
  714. ;-----------------------------------------------------------------------------
  715. d_DeclTriSetup(`Start')dnl
  716. ; Save registers.
  717. push ebx
  718. push esi
  719. push edi
  720. ; Set frame after saving registers so saving more or fewer
  721. ; doesnt alter the locals.
  722. push ebp
  723. mov ebp, esp
  724. ; Allocate local storage space.
  725. sub esp, SETUP_LOCALS
  726. ; Put pStpCtx in ebx.
  727. mov ebx, ecx
  728. ; Put pV0 in edi, pV1 in ecx and pV2 in edx.
  729. mov edi, edx
  730. mov ecx, pV1
  731. mov edx, pV2
  732. ; Fold normalization value into deltas.
  733. fld DWORD PTR [ebx+SCTX_fDX10] ; DX10
  734. fmul DWORD PTR [ebx+SCTX_fOoDet] ; NX10
  735. fld DWORD PTR [ebx+SCTX_fDX20] ; DX20 NX10
  736. fmul DWORD PTR [ebx+SCTX_fOoDet] ; NX20 NX10
  737. mov eax, [ebx+SCTX_pCtx]
  738. fld DWORD PTR [ebx+SCTX_fDY10] ; DY10 NX20 NX10
  739. fmul DWORD PTR [ebx+SCTX_fOoDet] ; NY10 NX20 NX10
  740. fld DWORD PTR [ebx+SCTX_fDY20] ; DY20 NY10 NX20 NX10
  741. fmul DWORD PTR [ebx+SCTX_fOoDet] ; NY20 NY10 NX20 NX10
  742. fxch st(3) ; NX10 NY10 NX20 NY20
  743. fstp DWORD PTR [ebx+SCTX_fNX10] ; NY10 NX20 NY20
  744. fxch st(1) ; NX20 NY10 NY20
  745. fstp DWORD PTR [ebx+SCTX_fNX20] ; NY10 NY20
  746. ; Get pdwRenderState in esi.
  747. ; Now that pdwRenderState is an array of DWORD declared in the context,
  748. ; its address is the address of the context plus the offset
  749. mov esi, eax
  750. add esi, RCTX_pdwRenderState
  751. fstp DWORD PTR [ebx+SCTX_fNY10] ; NY20
  752. fstp DWORD PTR [ebx+SCTX_fNY20] ;
  753. ; Jump to first bead.
  754. jmp DWORD PTR [ebx+SCTX_pfnTriSetupFirstAttr]
  755. d_EndDeclTriSetup(`Start')dnl
  756. ;-----------------------------------------------------------------------------
  757. ;
  758. ; Setup_Z16
  759. ;
  760. ; Attribute setup for 16-bit Z.
  761. ;
  762. ;-----------------------------------------------------------------------------
  763. d_DeclTriSetup(`Z16')dnl
  764. d_ZSetup(`16')dnl
  765. d_EndDeclTriSetup(`Z16')dnl
  766. ;-----------------------------------------------------------------------------
  767. ;
  768. ; Setup_Z32
  769. ;
  770. ; Attribute setup for 32-bit Z.
  771. ;
  772. ;-----------------------------------------------------------------------------
  773. d_DeclTriSetup(`Z32')dnl
  774. d_ZSetup(`32')dnl
  775. d_EndDeclTriSetup(`Z32')dnl
  776. ;-----------------------------------------------------------------------------
  777. ;
  778. ; Setup_Persp_Tex
  779. ;
  780. ; Attribute setup for OoW and first texture coordinates.
  781. ; Coordinates are set up for perspective correction.
  782. ;
  783. ;-----------------------------------------------------------------------------
  784. d_DeclTriSetup(`Persp_Tex')dnl
  785. ;
  786. ; Setup for OoW. Slot a is used.
  787. ;
  788. ; Compute OoW deltas.
  789. fld DWORD PTR [edx+TL_dvRHW] ; OoW2
  790. fsub DWORD PTR [edi+TL_dvRHW] ; DOoW20
  791. fld DWORD PTR [ecx+TL_dvRHW] ; OoW1 DOoW20
  792. fsub DWORD PTR [edi+TL_dvRHW] ; DOoW10 DOoW20
  793. ; Scale OoW deltas.
  794. fxch st(1) ; DOoW20 DOoW10
  795. fmul OOW_SCALE ; DOoW20 DOoW10
  796. fxch st(1) ; DOoW10 DOoW20
  797. fmul OOW_SCALE ; DOoW10 DOoW20
  798. fxch st(1) ; DOoW20 DOoW10
  799. fstp fDVa20 ; DOoW10
  800. fstp fDVa10 ;
  801. d_CorrectAttr(`ATTRSET_fOoW', `DWORD PTR [edi+TL_dvRHW]',
  802. `fDVa20', `fDVa10', `OOW_SCALE')dnl
  803. d_NegateDeltas(`OoW', `ATTRSET_fOoW')dnl
  804. pushdef(`d_CRPD_Post',
  805. ` mov eax, [ebx+SCTX_pPrim]
  806. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fOoW]
  807. fistp DWORD PTR [eax+RASTPRIM_iDOoWDX]
  808. fld DWORD PTR [ebx+SCTX_DAttrDY+ATTRSET_fOoW]
  809. fistp DWORD PTR [eax+RASTPRIM_iDOoWDY]
  810. ')dnl
  811. d_CheckRpDeltas(`OoW', `C_OOW_LIMIT',
  812. `SCTX_DAttrDX+ATTRSET_fOoW',
  813. `SCTX_DAttrDY+ATTRSET_fOoW')dnl
  814. popdef(`d_CRPD_Post')dnl
  815. d_CheckFxDeltas(`OoW', `C_OOW_LIMIT', `ATTRSET_fOoW')dnl
  816. ;
  817. ; Setup for tex. Slot a is used for U and b for V.
  818. ;
  819. d_PerspTexSetup(`TL_dvTU', `TL_dvTV', `1')dnl
  820. ; Jump to next bead.
  821. jmp DWORD PTR [ebx+SCTX_pfnTriSetupTexEnd]
  822. d_EndDeclTriSetup(`Persp_Tex')dnl
  823. ;-----------------------------------------------------------------------------
  824. ;
  825. ; Setup_Affine_Tex
  826. ;
  827. ; Attribute setup for OoW and first texture coordinates.
  828. ; Coordinates are set up for affine mapping.
  829. ;
  830. ;-----------------------------------------------------------------------------
  831. d_DeclTriSetup(`Affine_Tex')dnl
  832. ;
  833. ; Setup for OoW. Slot a is used.
  834. ;
  835. mov eax, OOW_SCALE
  836. mov [ebx+SCTX_Attr+ATTRSET_fOoW], eax
  837. xor eax, eax
  838. mov [ebx+SCTX_DAttrDX+ATTRSET_fOoW], eax
  839. mov [ebx+SCTX_DAttrDY+ATTRSET_fOoW], eax
  840. mov [ebx+SCTX_DAttrNC+ATTRSET_fOoW], eax
  841. mov [ebx+SCTX_DAttrCY+ATTRSET_fOoW], eax
  842. mov ecx, [ebx+SCTX_pPrim]
  843. mov [ecx+RASTPRIM_iDOoWDX], eax
  844. mov [ecx+RASTPRIM_iDOoWDY], eax
  845. mov ecx, pV1
  846. ;
  847. ; Setup for tex. Slot a is used for U and b for V.
  848. ;
  849. d_AffineTexSetup(`TL_dvTU', `TL_dvTV', `1')dnl
  850. ; Jump to next bead.
  851. jmp DWORD PTR [ebx+SCTX_pfnTriSetupTexEnd]
  852. d_EndDeclTriSetup(`Affine_Tex')dnl
  853. ;-----------------------------------------------------------------------------
  854. ;
  855. ; Setup_Diff
  856. ;
  857. ; Attribute setup for interpolated diffuse color.
  858. ;
  859. ;-----------------------------------------------------------------------------
  860. d_DeclTriSetup(`Diff')dnl
  861. ;
  862. ; Slots a - d are B, G, R and A, respectively.
  863. ;
  864. d_ColorSetup(`TL_dcColor', `')dnl
  865. ; Jump to next bead.
  866. jmp DWORD PTR [ebx+SCTX_pfnTriSetupDiffEnd]
  867. d_EndDeclTriSetup(`Diff')dnl
  868. ;-----------------------------------------------------------------------------
  869. ;
  870. ; Setup_DiffFlat
  871. ;
  872. ; Attribute setup for constant diffuse color.
  873. ;
  874. ;-----------------------------------------------------------------------------
  875. d_DeclTriSetup(`DiffFlat')dnl
  876. ;
  877. ; Slots a - d are B, G, R and A, respectively.
  878. ;
  879. ; Get colors from first input vertex. Can't just use pV0
  880. ; because it may have changed due to vertex sorting.
  881. mov eax, [ebx+SCTX_pFlatVtx]
  882. mov eax, [eax+TL_dcColor]
  883. mov ecx, eax
  884. ; G is in the correct shifted position.
  885. and eax, 0ff00h
  886. mov fVb0, eax
  887. fild fVb0 ; G
  888. ; Shift B and store.
  889. mov eax, ecx
  890. shl eax, COLOR_SHIFT
  891. and eax, 0ff00h
  892. mov fVa0, eax
  893. fild fVa0 ; B G
  894. ; Shift R and store.
  895. mov eax, ecx
  896. shr eax, (16 - COLOR_SHIFT)
  897. and eax, 0ff00h
  898. mov fVc0, eax
  899. fild fVc0 ; R B G
  900. ; Shift A and store.
  901. mov eax, ecx
  902. shr eax, (24 - COLOR_SHIFT)
  903. and eax, 0ff00h
  904. mov fVd0, eax
  905. fild fVd0 ; A R B G
  906. fxch st(3) ; G R B A
  907. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fG] ; R B A
  908. fxch st(1) ; B R A
  909. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fB] ; R A
  910. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fR] ; A
  911. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fA] ;
  912. ; Zero out all deltas.
  913. xor eax, eax
  914. mov ecx, [ebx+SCTX_pPrim]
  915. mov [ebx+SCTX_DAttrDX+ATTRSET_fB], eax
  916. mov [ebx+SCTX_DAttrDX+ATTRSET_fG], eax
  917. mov [ebx+SCTX_DAttrDX+ATTRSET_fR], eax
  918. mov [ebx+SCTX_DAttrDX+ATTRSET_fA], eax
  919. mov [ebx+SCTX_DAttrDY+ATTRSET_fB], eax
  920. mov [ebx+SCTX_DAttrDY+ATTRSET_fG], eax
  921. mov [ebx+SCTX_DAttrDY+ATTRSET_fR], eax
  922. mov [ebx+SCTX_DAttrDY+ATTRSET_fA], eax
  923. mov [ebx+SCTX_DAttrNC+ATTRSET_fB], eax
  924. mov [ebx+SCTX_DAttrNC+ATTRSET_fG], eax
  925. mov [ebx+SCTX_DAttrNC+ATTRSET_fR], eax
  926. mov [ebx+SCTX_DAttrNC+ATTRSET_fA], eax
  927. mov [ebx+SCTX_DAttrCY+ATTRSET_fB], eax
  928. mov [ebx+SCTX_DAttrCY+ATTRSET_fG], eax
  929. mov [ebx+SCTX_DAttrCY+ATTRSET_fR], eax
  930. mov [ebx+SCTX_DAttrCY+ATTRSET_fA], eax
  931. ; Fills both B and G.
  932. mov [ecx+RASTPRIM_iDBDX], eax
  933. ; Fills both R and A.
  934. mov [ecx+RASTPRIM_iDRDX], eax
  935. mov ecx, pV1
  936. ; Jump to next bead.
  937. jmp DWORD PTR [ebx+SCTX_pfnTriSetupDiffEnd]
  938. d_EndDeclTriSetup(`DiffFlat')dnl
  939. ;-----------------------------------------------------------------------------
  940. ;
  941. ; Setup_DIdx
  942. ;
  943. ; Attribute setup for interpolated diffuse indexed color.
  944. ;
  945. ;-----------------------------------------------------------------------------
  946. d_DeclTriSetup(`DIdx')dnl
  947. ;
  948. ; Slots a, b are Idx and A, respectively.
  949. ;
  950. ; Get values from pV0.
  951. mov eax, [edi+TL_dcColor]
  952. mov ecx, eax
  953. ; Mask off alpha.
  954. and eax, 0ffffffh
  955. add eax, 128
  956. mov fVa0, eax
  957. fild fVa0 ; Idx
  958. ; Shift A and store.
  959. shr ecx, 24
  960. mov fVb0, ecx
  961. fild fVb0 ; A Idx
  962. ; Get colors from pV2 and subtract pV0.
  963. d_IdxColorDelta(edx+TL_dcColor, `2')dnl
  964. ; Get colors from pV1 and subtract pV0.
  965. mov ecx, pV1
  966. d_IdxColorDelta(ecx+TL_dcColor, `1')dnl
  967. mov ecx, pV1
  968. ; Store initial values.
  969. fstp fVb0 ; Idx
  970. fstp fVa0 ;
  971. d_CorrectAttr(ATTRSET_fDIdx, `fVa0', `fDVa20', `fDVa10',
  972. `INDEX_COLOR_FIXED_SCALE')dnl
  973. d_CorrectAttr(ATTRSET_fDIdxA, `fVb0', `fDVb20', `fDVb10',
  974. `INDEX_COLOR_SCALE')dnl
  975. d_NegateDeltas(IdxCol, ATTRSET_fDIdx, ATTRSET_fDIdxA)dnl
  976. pushdef(`d_CRPD_Post',
  977. ` mov eax, [ebx+SCTX_pPrim]
  978. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fDIdx]
  979. fistp DWORD PTR [eax+RASTPRIM_iDIdxDX]
  980. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fDIdxA]
  981. fistp DWORD PTR [eax+RASTPRIM_iDIdxADX]
  982. ')dnl
  983. d_CheckRpDeltas(IdxCol, `C_INDEX_COLOR_LIMIT',
  984. SCTX_DAttrDX+ATTRSET_fDIdx,
  985. SCTX_DAttrDX+ATTRSET_fDIdxA)dnl
  986. popdef(`d_CRPD_Post')dnl
  987. d_CheckFxDeltas(IdxCol, `C_INDEX_COLOR_LIMIT',
  988. ATTRSET_fDIdx, ATTRSET_fDIdxA)dnl
  989. ; Jump to next bead.
  990. jmp DWORD PTR [ebx+SCTX_pfnTriSetupDiffEnd]
  991. d_EndDeclTriSetup(`DIdx')dnl
  992. ;-----------------------------------------------------------------------------
  993. ;
  994. ; Setup_DIdxFlat
  995. ;
  996. ; Attribute setup for constant diffuse indexed color.
  997. ;
  998. ;-----------------------------------------------------------------------------
  999. d_DeclTriSetup(`DIdxFlat')dnl
  1000. ;
  1001. ; Slots a, b are Idx and A, respectively.
  1002. ;
  1003. ; Get colors from first input vertex. Can't just use pV0
  1004. ; because it may have changed due to vertex sorting.
  1005. mov eax, [ebx+SCTX_pFlatVtx]
  1006. mov eax, [eax+TL_dcColor]
  1007. mov ecx, eax
  1008. ; Mask off alpha and shift.
  1009. shl eax, INDEX_COLOR_FIXED_SHIFT
  1010. ; Should not be necessary to add .5 to Idx, since
  1011. ; no floating point ops are done to it
  1012. mov fVa0, eax
  1013. fild fVa0 ; Idx
  1014. ; Shift A and store.
  1015. shr ecx, (24 - INDEX_COLOR_SHIFT)
  1016. and ecx, 0ffffffh
  1017. mov fVb0, ecx
  1018. fild fVb0 ; A Idx
  1019. fxch st(1) ; Idx A
  1020. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fDIdx] ; A
  1021. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fDIdxA] ;
  1022. ; Zero out all deltas.
  1023. xor eax, eax
  1024. mov ecx, [ebx+SCTX_pPrim]
  1025. mov [ebx+SCTX_DAttrDX+ATTRSET_fDIdx], eax
  1026. mov [ebx+SCTX_DAttrDX+ATTRSET_fDIdxA], eax
  1027. mov [ebx+SCTX_DAttrDY+ATTRSET_fDIdx], eax
  1028. mov [ebx+SCTX_DAttrDY+ATTRSET_fDIdxA], eax
  1029. mov [ebx+SCTX_DAttrNC+ATTRSET_fDIdx], eax
  1030. mov [ebx+SCTX_DAttrNC+ATTRSET_fDIdxA], eax
  1031. mov [ebx+SCTX_DAttrCY+ATTRSET_fDIdx], eax
  1032. mov [ebx+SCTX_DAttrCY+ATTRSET_fDIdxA], eax
  1033. mov [ecx+RASTPRIM_iDIdxDX], eax
  1034. mov [ecx+RASTPRIM_iDIdxADX], eax
  1035. mov ecx, pV1
  1036. ; Jump to next bead.
  1037. jmp DWORD PTR [ebx+SCTX_pfnTriSetupDiffEnd]
  1038. d_EndDeclTriSetup(`DIdxFlat')dnl
  1039. ;-----------------------------------------------------------------------------
  1040. ;
  1041. ; Setup_Spec
  1042. ;
  1043. ; Attribute setup for interpolated specular color.
  1044. ;
  1045. ;-----------------------------------------------------------------------------
  1046. d_DeclTriSetup(`Spec')dnl
  1047. ;
  1048. ; Slots a - c are B, G and R, respectively.
  1049. ;
  1050. d_ColorSetup(`TL_dcSpecular', `S')dnl
  1051. ; Jump to next bead.
  1052. jmp DWORD PTR [ebx+SCTX_pfnTriSetupSpecEnd]
  1053. d_EndDeclTriSetup(`Spec')dnl
  1054. ;-----------------------------------------------------------------------------
  1055. ;
  1056. ; Setup_SpecFlat
  1057. ;
  1058. ; Attribute setup for constant specular color.
  1059. ;
  1060. ;-----------------------------------------------------------------------------
  1061. d_DeclTriSetup(`SpecFlat')dnl
  1062. ;
  1063. ; Slots a - c are B, G and R, respectively.
  1064. ;
  1065. ; Get colors from first input vertex. Can't just use pV0
  1066. ; because it may have changed due to vertex sorting.
  1067. mov eax, [ebx+SCTX_pFlatVtx]
  1068. mov eax, [eax+TL_dcSpecular]
  1069. mov ecx, eax
  1070. ; G is in the correct shifted position.
  1071. and eax, 0ff00h
  1072. mov fVb0, eax
  1073. fild fVb0 ; G
  1074. ; Shift B and store.
  1075. mov eax, ecx
  1076. shl eax, 8
  1077. and eax, 0ff00h
  1078. mov fVa0, eax
  1079. fild fVa0 ; B G
  1080. ; Shift R and store.
  1081. mov eax, ecx
  1082. shr eax, 8
  1083. and eax, 0ff00h
  1084. mov fVc0, eax
  1085. fild fVc0 ; R B G
  1086. fxch st(2) ; G B R
  1087. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fGS] ; B R
  1088. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fBS] ; R
  1089. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fRS] ;
  1090. ; Zero out all deltas.
  1091. xor eax, eax
  1092. mov ecx, [ebx+SCTX_pPrim]
  1093. mov [ebx+SCTX_DAttrDX+ATTRSET_fBS], eax
  1094. mov [ebx+SCTX_DAttrDX+ATTRSET_fGS], eax
  1095. mov [ebx+SCTX_DAttrDX+ATTRSET_fRS], eax
  1096. mov [ebx+SCTX_DAttrDY+ATTRSET_fBS], eax
  1097. mov [ebx+SCTX_DAttrDY+ATTRSET_fGS], eax
  1098. mov [ebx+SCTX_DAttrDY+ATTRSET_fRS], eax
  1099. mov [ebx+SCTX_DAttrNC+ATTRSET_fBS], eax
  1100. mov [ebx+SCTX_DAttrNC+ATTRSET_fGS], eax
  1101. mov [ebx+SCTX_DAttrNC+ATTRSET_fRS], eax
  1102. mov [ebx+SCTX_DAttrCY+ATTRSET_fBS], eax
  1103. mov [ebx+SCTX_DAttrCY+ATTRSET_fGS], eax
  1104. mov [ebx+SCTX_DAttrCY+ATTRSET_fRS], eax
  1105. ; Fills both B and G.
  1106. mov [ecx+RASTPRIM_iDBSDX], eax
  1107. ; Fills both R and Fog. Fog will be set up later, if at all,
  1108. ; so it's OK to trash it here.
  1109. mov [ecx+RASTPRIM_iDRSDX], eax
  1110. mov ecx, pV1
  1111. ; Jump to next bead.
  1112. jmp DWORD PTR [ebx+SCTX_pfnTriSetupSpecEnd]
  1113. d_EndDeclTriSetup(`SpecFlat')dnl
  1114. ;-----------------------------------------------------------------------------
  1115. ;
  1116. ; Setup_Fog
  1117. ;
  1118. ; Attribute setup for vertex fog.
  1119. ;
  1120. ;-----------------------------------------------------------------------------
  1121. d_DeclTriSetup(`Fog')dnl
  1122. ;
  1123. ; Slot a is used with some temporaries in b and c.
  1124. ;
  1125. IFNDEF PWL_FOG
  1126. ; Check for global-into-local fog. If global fog is on,
  1127. ; compute the local fog values from table fog rather than
  1128. ; from the vertex.
  1129. mov eax, [ebx+SCTX_uFlags]
  1130. test eax, PRIMSF_GLOBAL_FOG_USED
  1131. jz L_NormalLocalFog
  1132. ;
  1133. ; Compute table fog values for all three vertex Z values.
  1134. ;
  1135. ; pV1
  1136. push DWORD PTR [ecx+TL_dvSZ]
  1137. mov ecx, esi
  1138. call @ComputeTableFog@8
  1139. mov fVb0, eax
  1140. ; pV0
  1141. push DWORD PTR [edi+TL_dvSZ]
  1142. mov ecx, esi
  1143. call @ComputeTableFog@8
  1144. ; Keep V0 fog in fTmp so that we can write the FP value
  1145. ; into fVa0.
  1146. mov fTmp, eax
  1147. ; pV2
  1148. mov edx, pV2
  1149. push DWORD PTR [edx+TL_dvSZ]
  1150. mov ecx, esi
  1151. call @ComputeTableFog@8
  1152. mov fVc0, eax
  1153. ; Restore pV1 and pV2.
  1154. mov ecx, pV1
  1155. mov edx, pV2
  1156. jmp L_ComputeFogDeltas
  1157. L_NormalLocalFog:
  1158. ENDIF
  1159. ; Extract fog values from specular alpha and shift into position.
  1160. mov eax, [edi+TL_dcSpecular]
  1161. and eax, 0ff000000h
  1162. shr eax, 24 - FOG_SHIFT
  1163. ; Keep V0 fog in fTmp so that we can write the FP value
  1164. ; into fVa0.
  1165. mov fTmp, eax
  1166. mov eax, [ecx+TL_dcSpecular]
  1167. and eax, 0ff000000h
  1168. shr eax, 24 - FOG_SHIFT
  1169. mov fVb0, eax
  1170. mov eax, [edx+TL_dcSpecular]
  1171. and eax, 0ff000000h
  1172. shr eax, 24 - FOG_SHIFT
  1173. mov fVc0, eax
  1174. IFNDEF PWL_FOG
  1175. L_ComputeFogDeltas:
  1176. ENDIF
  1177. fild fTmp
  1178. ; Compute fog deltas from shifted values in fVa?.
  1179. mov eax, fVc0
  1180. sub eax, fTmp
  1181. mov fDVa20, eax
  1182. fstp fVa0
  1183. fild fDVa20
  1184. mov eax, fVb0
  1185. sub eax, fTmp
  1186. mov fDVa10, eax
  1187. fstp fDVa20
  1188. fild fDVa10
  1189. fstp fDVa10
  1190. ; fVa0 is already scaled so the scaling factor is given as 1.0.
  1191. ; This is a little wasteful but it makes the above code simpler
  1192. ; and more integer.
  1193. d_CorrectAttr(`ATTRSET_fFog', `fVa0', `fDVa20', `fDVa10', `_g_fOne')dnl
  1194. d_NegateDeltas(`Fog', `ATTRSET_fFog')dnl
  1195. pushdef(`d_CRPD_Post',
  1196. ` ; Fog deltas are given per span rather than per primitive.
  1197. ; Store local fog value in setup context so that it can be
  1198. ; copied into the spans later.
  1199. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fFog]
  1200. fistp DWORD PTR [ebx+SCTX_iDLocalFogDX]
  1201. ')dnl
  1202. d_CheckRpDeltas(`Fog', `C_FOG_LIMIT', `SCTX_DAttrDX+ATTRSET_fFog')dnl
  1203. popdef(`d_CRPD_Post')dnl
  1204. d_CheckFxDeltas(`Fog', `C_FOG_LIMIT', `ATTRSET_fFog')dnl
  1205. ; Jump to next bead.
  1206. jmp DWORD PTR [ebx+SCTX_pfnTriSetupFogEnd]
  1207. d_EndDeclTriSetup(`Fog')dnl
  1208. ;-----------------------------------------------------------------------------
  1209. ;
  1210. ; Setup_End
  1211. ;
  1212. ; Final bead. Restores stack and returns.
  1213. ;
  1214. ;-----------------------------------------------------------------------------
  1215. d_DeclTriSetup(`End')dnl
  1216. ; Give up locals.
  1217. add esp, SETUP_LOCALS
  1218. ; Restore registers.
  1219. pop ebp
  1220. pop edi
  1221. pop esi
  1222. pop ebx
  1223. ret 8
  1224. d_EndDeclTriSetup(`End')dnl
  1225. END