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 $1 is the texcoord index, 1 or 2.
  234. dnl
  235. define(`d_TexSetupStart',
  236. ` mov ecx, DWORD PTR [esi+RS_WRAP0+eval(decr($1) * 4)] ; Wrap flags
  237. mov eax, ecx
  238. and ecx, D3DWRAP_U
  239. and eax, D3DWRAP_V
  240. mov bWrapU, ecx
  241. mov ecx, pV1
  242. mov bWrapV, eax
  243. ')dnl
  244. dnl
  245. dnl d_TexSetupFinish
  246. dnl
  247. dnl Completes texture coordinate setup.
  248. dnl
  249. dnl $1 is the texcoord index, 1 or 2.
  250. dnl
  251. define(`d_TexSetupFinish',
  252. `d_CorrectAttr(ATTRSET_fUoW$1, `fVa0', `fDVa20', `fDVa10', `TEX_SCALE')dnl
  253. d_CorrectAttr(ATTRSET_fVoW$1, `fVb0', `fDVb20', `fDVb10', `TEX_SCALE')dnl
  254. d_NegateDeltas(Tex$1, ATTRSET_fUoW$1, ATTRSET_fVoW$1)dnl
  255. pushdef(`d_CRPD_Post',
  256. ` mov eax, [ebx+SCTX_pPrim]
  257. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fUoW$1]
  258. fistp DWORD PTR [eax+RASTPRIM_iDUoW$1DX]
  259. fld DWORD PTR [ebx+SCTX_DAttrDY+ATTRSET_fUoW$1]
  260. fistp DWORD PTR [eax+RASTPRIM_iDUoW$1DY]
  261. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fVoW$1]
  262. fistp DWORD PTR [eax+RASTPRIM_iDVoW$1DX]
  263. fld DWORD PTR [ebx+SCTX_DAttrDY+ATTRSET_fVoW$1]
  264. fistp DWORD PTR [eax+RASTPRIM_iDVoW$1DY]
  265. ')dnl
  266. d_CheckRpDeltas(Tex$1, `C_TEX_LIMIT',
  267. SCTX_DAttrDX+ATTRSET_fUoW$1,
  268. SCTX_DAttrDY+ATTRSET_fUoW$1,
  269. SCTX_DAttrDX+ATTRSET_fVoW$1,
  270. SCTX_DAttrDY+ATTRSET_fVoW$1)dnl
  271. popdef(`d_CRPD_Post')dnl
  272. d_CheckFxDeltas(Tex$1, `C_TEX_LIMIT', ATTRSET_fUoW$1, ATTRSET_fVoW$1)dnl
  273. ')dnl
  274. dnl
  275. dnl d_PerspTexDeltas
  276. dnl
  277. dnl Computes UoW,VoW texture deltas.
  278. dnl
  279. dnl $1 is the vertex U offset to use.
  280. dnl $2 is the vertex V offset to use.
  281. dnl
  282. define(`d_PerspTexDeltas',
  283. ` ; Get UoW, VoW and scaled deltas.
  284. fld DWORD PTR [edi+$1] ; U
  285. fmul DWORD PTR [edi+TL_dvRHW] ; UoW
  286. fld DWORD PTR [edi+$2] ; V UoW
  287. fmul DWORD PTR [edi+TL_dvRHW] ; VoW UoW
  288. fxch st(1) ; UoW VoW
  289. fstp fVa0 ; VoW
  290. fstp fVb0 ;
  291. ; DU20.
  292. TEXTURE_DIFF DWORD PTR [edx+$1], DWORD PTR [edi+$1], bWrapU, fTmp
  293. fadd DWORD PTR [edi+$1]
  294. mov ecx, pV1
  295. fmul DWORD PTR [edx+TL_dvRHW]
  296. ; DU10.
  297. TEXTURE_DIFF DWORD PTR [ecx+$1], DWORD PTR [edi+$1], bWrapU, fTmp
  298. fxch st(1)
  299. mov ecx, pV1
  300. ; DU20.
  301. fsub fVa0
  302. fmul TEX_SCALE
  303. fstp fDVa20
  304. ; DU10.
  305. fadd DWORD PTR [edi+$1]
  306. fmul DWORD PTR [ecx+TL_dvRHW]
  307. ; DV20.
  308. TEXTURE_DIFF DWORD PTR [edx+$2], DWORD PTR [edi+$2], bWrapV, fTmp
  309. fxch st(1)
  310. mov ecx, pV1
  311. ; DU10.
  312. fsub fVa0
  313. fmul TEX_SCALE
  314. fstp fDVa10
  315. ; DV20.
  316. fadd DWORD PTR [edi+$2]
  317. fmul DWORD PTR [edx+TL_dvRHW]
  318. ; DV10.
  319. TEXTURE_DIFF DWORD PTR [ecx+$2], DWORD PTR [edi+$2], bWrapV, fTmp
  320. fxch st(1)
  321. mov ecx, pV1
  322. ; DV20.
  323. fsub fVb0
  324. fmul TEX_SCALE
  325. fstp fDVb20
  326. ; Finish DV10.
  327. fadd DWORD PTR [edi+$2]
  328. fmul DWORD PTR [ecx+TL_dvRHW]
  329. fsub fVb0
  330. fmul TEX_SCALE
  331. fstp fDVb10
  332. ')dnl
  333. dnl
  334. dnl d_PerspTexSetup
  335. dnl
  336. dnl Produces perspective-correct texcoord setup code.
  337. dnl
  338. dnl $1 is the vertex U offset to use.
  339. dnl $2 is the vertex V offset to use.
  340. dnl $3 is the texcoord index, 1 or 2.
  341. dnl
  342. define(`d_PerspTexSetup',
  343. `d_TexSetupStart($3)dnl
  344. d_PerspTexDeltas($1, $2)dnl
  345. d_TexSetupFinish($3)dnl
  346. ')dnl
  347. dnl
  348. dnl d_AffineTexDeltas
  349. dnl
  350. dnl Computes U,V texture deltas.
  351. dnl
  352. dnl $1 is the vertex U offset to use.
  353. dnl $2 is the vertex V offset to use.
  354. dnl
  355. define(`d_AffineTexDeltas',
  356. ` ; Get scaled deltas.
  357. ; Start DU20.
  358. mov eax, [edi+$1]
  359. ; Save U in fVa0
  360. mov fVa0, eax
  361. TEXTURE_DIFF DWORD PTR [edx+$1], DWORD PTR [edi+$1], bWrapU, fTmp
  362. fmul TEX_SCALE
  363. mov ecx, pV1
  364. fstp fDVa20
  365. ; DU10.
  366. TEXTURE_DIFF DWORD PTR [ecx+$1], DWORD PTR [edi+$1], bWrapU, fTmp
  367. fmul TEX_SCALE
  368. mov ecx, pV1
  369. ; Start DV20.
  370. mov eax, [edi+$2]
  371. ; Save V in fVb0
  372. mov fVb0, eax
  373. ; DU10.
  374. fstp fDVa10
  375. ; DV20.
  376. TEXTURE_DIFF DWORD PTR [edx+$2], DWORD PTR [edi+$2], bWrapV, fTmp
  377. fmul TEX_SCALE
  378. mov ecx, pV1
  379. ; DV20.
  380. fstp fDVb20
  381. ; DV10.
  382. TEXTURE_DIFF DWORD PTR [ecx+$2], DWORD PTR [edi+$2], bWrapV, fTmp
  383. fmul TEX_SCALE
  384. mov ecx, pV1
  385. fstp fDVb10
  386. ')dnl
  387. dnl
  388. dnl d_AffineTexSetup
  389. dnl
  390. dnl Produces affine-mapped texcoord setup code.
  391. dnl
  392. dnl $1 is the vertex U offset to use.
  393. dnl $2 is the vertex V offset to use.
  394. dnl $3 is the texcoord index, 1 or 2.
  395. dnl
  396. define(`d_AffineTexSetup',
  397. `d_TexSetupStart($3)dnl
  398. d_AffineTexDeltas($1, $2)dnl
  399. d_TexSetupFinish($3)dnl
  400. ')dnl
  401. dnl
  402. dnl d_ColorDelta
  403. dnl
  404. dnl Produces color B - A code.
  405. dnl
  406. dnl $1 is the packed color address to use.
  407. dnl $2 is the edge suffix, `2' or `1'.
  408. dnl
  409. define(`d_ColorDelta',
  410. ` ; A0 R0 G0 B0 sit at the end of the stack throughout.
  411. mov eax, [$1]
  412. mov ecx, eax
  413. ; B is in the correct shifted position.
  414. and eax, 0ffh
  415. mov fTmp, eax
  416. fild fTmp ; B
  417. ; Shift G and store.
  418. mov eax, ecx
  419. shr eax, 8
  420. and eax, 0ffh
  421. mov fTmp, eax
  422. fsub st(0), st(4) ; dB
  423. fild fTmp ; G dB
  424. ; Shift R and store.
  425. mov eax, ecx
  426. shr eax, 16
  427. and eax, 0ffh
  428. mov fTmp, eax
  429. fsub st(0), st(4) ; dG dB
  430. fild fTmp ; R dG dB
  431. ; Shift A and store.
  432. mov eax, ecx
  433. shr eax, 24
  434. mov fTmp, eax
  435. fsub st(0), st(4) ; dR dG dB
  436. fild fTmp ; A dR dG dB
  437. ; Scale deltas.
  438. fxch st(3) ; dB dR dG A
  439. fmul COLOR_SCALE ; dB dR dG A
  440. fxch st(3) ; A dR dG dB
  441. fsub st(0), st(4) ; dA dR dG dB
  442. fxch st(2) ; dG dR dA dB
  443. fmul COLOR_SCALE ; dG dR dA dB
  444. fxch st(1) ; dR dG dA dB
  445. fmul COLOR_SCALE ; dR dG dA dB
  446. fxch st(2) ; dA dG dR dB
  447. fmul COLOR_SCALE ; dA dG dR dB
  448. fxch st(3) ; dB dG dR dA
  449. fstp fDVa$2`'0 ; dG dR dA
  450. fstp fDVb$2`'0 ; dR dA
  451. fstp fDVc$2`'0 ; dA
  452. fstp fDVd$2`'0 ;
  453. ')dnl
  454. dnl
  455. dnl d_SColorDelta
  456. dnl
  457. dnl Produces specular color B - A code.
  458. dnl
  459. dnl $1 is the packed color address to use.
  460. dnl $2 is the edge suffix, `2' or `1'.
  461. dnl
  462. define(`d_SColorDelta',
  463. ` ; R0 G0 B0 sit at the end of the stack throughout.
  464. mov eax, [$1]
  465. mov ecx, eax
  466. ; B is in the correct shifted position.
  467. and eax, 0ffh
  468. mov fTmp, eax
  469. fild fTmp ; B
  470. ; Shift G and store.
  471. mov eax, ecx
  472. shr eax, 8
  473. and eax, 0ffh
  474. mov fTmp, eax
  475. fsub st(0), st(3) ; dB
  476. fild fTmp ; G dB
  477. ; Shift R and store.
  478. mov eax, ecx
  479. shr eax, 16
  480. and eax, 0ffh
  481. mov fTmp, eax
  482. fsub st(0), st(3) ; dG dB
  483. fild fTmp ; R dG dB
  484. ; Scale deltas.
  485. fxch st(2) ; dB dG R
  486. fmul COLOR_SCALE ; dB dG R
  487. fxch st(2) ; R dG dB
  488. fsub st(0), st(3) ; dR dG dB
  489. fxch st(1) ; dG dR dB
  490. fmul COLOR_SCALE ; dG dR dB
  491. fxch st(1) ; dR dG dB
  492. fmul COLOR_SCALE ; dR dG dB
  493. fxch st(2) ; dB dG dR
  494. fstp fDVa$2`'0 ; dG dR
  495. fstp fDVb$2`'0 ; dR
  496. fstp fDVc$2`'0 ;
  497. ')dnl
  498. dnl
  499. dnl d_IdxColorDelta
  500. dnl
  501. dnl Produces indexed color B - A code.
  502. dnl
  503. dnl $1 is the packed color address to use.
  504. dnl $2 is the edge suffix, `2' or `1'.
  505. dnl
  506. define(`d_IdxColorDelta',
  507. ` ; A0 Idx0 sit at the end of the stack throughout.
  508. mov eax, [$1]
  509. mov ecx, eax
  510. ; Mask off alpha.
  511. and eax, 0ffffffh
  512. add eax, 128
  513. mov fTmp, eax
  514. fild fTmp ; Idx
  515. ; Shift A and store.
  516. shr ecx, 24
  517. mov fTmp, ecx
  518. fsub st(0), st(2) ; dIdx
  519. fild fTmp ; A dIdx
  520. ; Scale deltas.
  521. fxch st(1) ; dIdx A
  522. fmul INDEX_COLOR_FIXED_SCALE ; dIdx A
  523. fxch st(1) ; A dIdx
  524. fsub st(0), st(2) ; dA dIdx
  525. fxch st(1) ; dIdx dA
  526. fstp fDVa$2`'0 ; dA
  527. fmul INDEX_COLOR_SCALE ; dA
  528. fstp fDVb$2`'0 ;
  529. ')dnl
  530. dnl
  531. dnl d_ColorSetup
  532. dnl
  533. dnl Produces color setup code.
  534. dnl
  535. dnl $1 is the vertex packed color offset to use.
  536. dnl $2 is the color suffix, `' or `S'.
  537. dnl
  538. define(`d_ColorSetup',
  539. ` ; Get colors from pV0.
  540. mov eax, [edi+$1]
  541. mov ecx, eax
  542. ; B is in the correct shifted position.
  543. and eax, 0ffh
  544. mov fVa0, eax
  545. fild fVa0 ; B
  546. ; Shift G and store.
  547. mov eax, ecx
  548. shr eax, 8
  549. and eax, 0ffh
  550. mov fVb0, eax
  551. fild fVb0 ; G B
  552. ; Shift R and store.
  553. mov eax, ecx
  554. shr eax, 16
  555. and eax, 0ffh
  556. mov fVc0, eax
  557. fild fVc0 ; R G B
  558. ifelse($2, `',
  559. ` ; Shift A and store.
  560. mov eax, ecx
  561. shr eax, 24
  562. mov fVd0, eax
  563. fild fVd0 ; A R G B
  564. ')dnl
  565. ; Get colors from pV2 and subtract pV0.
  566. d_$2ColorDelta(edx+$1, `2')dnl
  567. ; Get colors from pV1 and subtract pV0.
  568. mov ecx, pV1
  569. d_$2ColorDelta(ecx+$1, `1')dnl
  570. mov ecx, pV1
  571. ; Store initial values.
  572. ifelse($2, `',
  573. ` fxch st(3) ; B R G A
  574. fstp fVa0 ; R G A
  575. fxch st(1) ; G R A
  576. fstp fVb0 ; R A
  577. fstp fVc0 ; A
  578. fstp fVd0 ;
  579. ',
  580. ` fxch st(2) ; B G R
  581. fstp fVa0 ; G R
  582. fstp fVb0 ; R
  583. fstp fVc0 ;
  584. ')dnl
  585. d_CorrectAttr(ATTRSET_fB$2, `fVa0', `fDVa20', `fDVa10', `COLOR_SCALE')dnl
  586. d_CorrectAttr(ATTRSET_fG$2, `fVb0', `fDVb20', `fDVb10', `COLOR_SCALE')dnl
  587. d_CorrectAttr(ATTRSET_fR$2, `fVc0', `fDVc20', `fDVc10', `COLOR_SCALE')dnl
  588. ifelse($2, `',
  589. `d_CorrectAttr(ATTRSET_fA$2, `fVd0', `fDVd20', `fDVd10', `COLOR_SCALE')dnl
  590. d_NegateDeltas(Col$2, ATTRSET_fB$2, ATTRSET_fG$2,
  591. ATTRSET_fR$2, ATTRSET_fA$2)dnl
  592. pushdef(`d_CRPD_Post',
  593. ` mov eax, [ebx+SCTX_pPrim]
  594. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fB$2]
  595. fistp DWORD PTR [eax+RASTPRIM_iDB$2DX]
  596. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fG$2]
  597. fistp DWORD PTR [eax+RASTPRIM_iDG$2DX]
  598. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fR$2]
  599. fistp DWORD PTR [eax+RASTPRIM_iDR$2DX]
  600. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fA$2]
  601. fistp DWORD PTR [eax+RASTPRIM_iDA$2DX]
  602. ')dnl
  603. d_CheckRpDeltas(Col$2, `C_COLOR_LIMIT',
  604. SCTX_DAttrDX+ATTRSET_fB$2,
  605. SCTX_DAttrDX+ATTRSET_fR$2,
  606. SCTX_DAttrDX+ATTRSET_fG$2,
  607. SCTX_DAttrDX+ATTRSET_fA$2)dnl
  608. popdef(`d_CRPD_Post')dnl
  609. d_CheckFxDeltas(Col$2, `C_COLOR_LIMIT',
  610. ATTRSET_fB$2, ATTRSET_fG$2, ATTRSET_fR$2, ATTRSET_fA$2)',
  611. `d_NegateDeltas(Col$2, ATTRSET_fB$2, ATTRSET_fG$2,
  612. ATTRSET_fR$2)dnl
  613. pushdef(`d_CRPD_Post',
  614. ` mov eax, [ebx+SCTX_pPrim]
  615. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fB$2]
  616. fistp DWORD PTR [eax+RASTPRIM_iDB$2DX]
  617. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fG$2]
  618. fistp DWORD PTR [eax+RASTPRIM_iDG$2DX]
  619. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fR$2]
  620. fistp DWORD PTR [eax+RASTPRIM_iDR$2DX]
  621. ')dnl
  622. d_CheckRpDeltas(Col$2, `C_COLOR_LIMIT',
  623. SCTX_DAttrDX+ATTRSET_fB$2,
  624. SCTX_DAttrDX+ATTRSET_fR$2,
  625. SCTX_DAttrDX+ATTRSET_fG$2)dnl
  626. popdef(`d_CRPD_Post')dnl
  627. d_CheckFxDeltas(Col$2, `C_COLOR_LIMIT',
  628. ATTRSET_fB$2, ATTRSET_fG$2, ATTRSET_fR$2)')dnl
  629. ')dnl
  630. ;
  631. ; Locations of stack variables.
  632. ; Done as equates since setup functions don't have real stack frames.
  633. ;
  634. ; Generic storage slots for initial value and deltas.
  635. fVa0 EQU DWORD PTR [ebp-4]
  636. fDVa20 EQU DWORD PTR [ebp-8]
  637. fDVa10 EQU DWORD PTR [ebp-12]
  638. fVb0 EQU DWORD PTR [ebp-16]
  639. fDVb20 EQU DWORD PTR [ebp-20]
  640. fDVb10 EQU DWORD PTR [ebp-24]
  641. fVc0 EQU DWORD PTR [ebp-28]
  642. fDVc20 EQU DWORD PTR [ebp-32]
  643. fDVc10 EQU DWORD PTR [ebp-36]
  644. fVd0 EQU DWORD PTR [ebp-40]
  645. fDVd20 EQU DWORD PTR [ebp-44]
  646. fDVd10 EQU DWORD PTR [ebp-48]
  647. fTmp EQU DWORD PTR [ebp-52]
  648. bWrapU EQU DWORD PTR [ebp-56]
  649. bWrapV EQU DWORD PTR [ebp-60]
  650. SETUP_LOCALS EQU 60
  651. ; Parameters
  652. pV1 EQU DWORD PTR [ebp+20]
  653. pV2 EQU DWORD PTR [ebp+24]
  654. dnl d_DeclTriSetup
  655. dnl
  656. dnl Declare a PFN_SETUPATTR from its attribute name.
  657. dnl
  658. dnl $1 is the attribute name.
  659. dnl
  660. define(`d_DeclTriSetup',
  661. `@TriSetup_$1@16 PROC SYSCALL PUBLIC
  662. PROF_ENTRY
  663. ')dnl
  664. define(`d_EndDeclTriSetup',
  665. `@TriSetup_$1@16 ENDP
  666. ')dnl
  667. dnl
  668. ;-----------------------------------------------------------------------------
  669. ;
  670. ; Setup_Start
  671. ;
  672. ; Establishes the stack frame for all setup routines, including
  673. ; preservation of registers and allocation of local storage space.
  674. ; Scales deltas by fOoDet.
  675. ; Puts pStpCtx in ebx, pV0 in edi, pV1 in ecx, pV2 in edx and
  676. ; pdwRenderState in esi.
  677. ; Jumps to first attribute setup bead.
  678. ;
  679. ;-----------------------------------------------------------------------------
  680. d_DeclTriSetup(`Start')dnl
  681. ; Save registers.
  682. push ebx
  683. push esi
  684. push edi
  685. ; Set frame after saving registers so saving more or fewer
  686. ; doesnt alter the locals.
  687. push ebp
  688. mov ebp, esp
  689. ; Allocate local storage space.
  690. sub esp, SETUP_LOCALS
  691. ; Put pStpCtx in ebx.
  692. mov ebx, ecx
  693. ; Put pV0 in edi, pV1 in ecx and pV2 in edx.
  694. mov edi, edx
  695. mov ecx, pV1
  696. mov edx, pV2
  697. ; Fold normalization value into deltas.
  698. fld DWORD PTR [ebx+SCTX_fDX10] ; DX10
  699. fmul DWORD PTR [ebx+SCTX_fOoDet] ; NX10
  700. fld DWORD PTR [ebx+SCTX_fDX20] ; DX20 NX10
  701. fmul DWORD PTR [ebx+SCTX_fOoDet] ; NX20 NX10
  702. mov eax, [ebx+SCTX_pCtx]
  703. fld DWORD PTR [ebx+SCTX_fDY10] ; DY10 NX20 NX10
  704. fmul DWORD PTR [ebx+SCTX_fOoDet] ; NY10 NX20 NX10
  705. fld DWORD PTR [ebx+SCTX_fDY20] ; DY20 NY10 NX20 NX10
  706. fmul DWORD PTR [ebx+SCTX_fOoDet] ; NY20 NY10 NX20 NX10
  707. fxch st(3) ; NX10 NY10 NX20 NY20
  708. fstp DWORD PTR [ebx+SCTX_fNX10] ; NY10 NX20 NY20
  709. fxch st(1) ; NX20 NY10 NY20
  710. fstp DWORD PTR [ebx+SCTX_fNX20] ; NY10 NY20
  711. ; Get pdwRenderState in esi.
  712. ; Now that pdwRenderState is an array of DWORD declared in the context,
  713. ; its address is the address of the context plus the offset
  714. mov esi, eax
  715. add esi, RCTX_pdwRenderState
  716. fstp DWORD PTR [ebx+SCTX_fNY10] ; NY20
  717. fstp DWORD PTR [ebx+SCTX_fNY20] ;
  718. ; Jump to first bead.
  719. jmp DWORD PTR [ebx+SCTX_pfnTriSetupFirstAttr]
  720. d_EndDeclTriSetup(`Start')dnl
  721. ;-----------------------------------------------------------------------------
  722. ;
  723. ; Setup_Z16
  724. ;
  725. ; Attribute setup for 16-bit Z.
  726. ;
  727. ;-----------------------------------------------------------------------------
  728. d_DeclTriSetup(`Z16')dnl
  729. d_ZSetup(`16')dnl
  730. d_EndDeclTriSetup(`Z16')dnl
  731. ;-----------------------------------------------------------------------------
  732. ;
  733. ; Setup_Z32
  734. ;
  735. ; Attribute setup for 32-bit Z.
  736. ;
  737. ;-----------------------------------------------------------------------------
  738. d_DeclTriSetup(`Z32')dnl
  739. d_ZSetup(`32')dnl
  740. d_EndDeclTriSetup(`Z32')dnl
  741. ;-----------------------------------------------------------------------------
  742. ;
  743. ; Setup_Persp_Tex1
  744. ;
  745. ; Attribute setup for OoW and first texture coordinates.
  746. ; Coordinates are set up for perspective correction.
  747. ;
  748. ;-----------------------------------------------------------------------------
  749. d_DeclTriSetup(`Persp_Tex1')dnl
  750. ;
  751. ; Setup for OoW. Slot a is used.
  752. ;
  753. ; Compute OoW deltas.
  754. fld DWORD PTR [edx+TL_dvRHW] ; OoW2
  755. fsub DWORD PTR [edi+TL_dvRHW] ; DOoW20
  756. fld DWORD PTR [ecx+TL_dvRHW] ; OoW1 DOoW20
  757. fsub DWORD PTR [edi+TL_dvRHW] ; DOoW10 DOoW20
  758. ; Scale OoW deltas.
  759. fxch st(1) ; DOoW20 DOoW10
  760. fmul OOW_SCALE ; DOoW20 DOoW10
  761. fxch st(1) ; DOoW10 DOoW20
  762. fmul OOW_SCALE ; DOoW10 DOoW20
  763. fxch st(1) ; DOoW20 DOoW10
  764. fstp fDVa20 ; DOoW10
  765. fstp fDVa10 ;
  766. d_CorrectAttr(`ATTRSET_fOoW', `DWORD PTR [edi+TL_dvRHW]',
  767. `fDVa20', `fDVa10', `OOW_SCALE')dnl
  768. d_NegateDeltas(`OoW', `ATTRSET_fOoW')dnl
  769. pushdef(`d_CRPD_Post',
  770. ` mov eax, [ebx+SCTX_pPrim]
  771. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fOoW]
  772. fistp DWORD PTR [eax+RASTPRIM_iDOoWDX]
  773. fld DWORD PTR [ebx+SCTX_DAttrDY+ATTRSET_fOoW]
  774. fistp DWORD PTR [eax+RASTPRIM_iDOoWDY]
  775. ')dnl
  776. d_CheckRpDeltas(`OoW', `C_OOW_LIMIT',
  777. `SCTX_DAttrDX+ATTRSET_fOoW',
  778. `SCTX_DAttrDY+ATTRSET_fOoW')dnl
  779. popdef(`d_CRPD_Post')dnl
  780. d_CheckFxDeltas(`OoW', `C_OOW_LIMIT', `ATTRSET_fOoW')dnl
  781. ;
  782. ; Setup for tex1. Slot a is used for U and b for V.
  783. ;
  784. d_PerspTexSetup(`TL_dvTU', `TL_dvTV', `1')dnl
  785. ; Jump to next bead.
  786. jmp DWORD PTR [ebx+SCTX_pfnTriSetupTex1End]
  787. d_EndDeclTriSetup(`Persp_Tex1')dnl
  788. ;-----------------------------------------------------------------------------
  789. ;
  790. ; Setup_Affine_Tex1
  791. ;
  792. ; Attribute setup for OoW and first texture coordinates.
  793. ; Coordinates are set up for affine mapping.
  794. ;
  795. ;-----------------------------------------------------------------------------
  796. d_DeclTriSetup(`Affine_Tex1')dnl
  797. ;
  798. ; Setup for OoW. Slot a is used.
  799. ;
  800. mov eax, OOW_SCALE
  801. mov [ebx+SCTX_Attr+ATTRSET_fOoW], eax
  802. xor eax, eax
  803. mov [ebx+SCTX_DAttrDX+ATTRSET_fOoW], eax
  804. mov [ebx+SCTX_DAttrDY+ATTRSET_fOoW], eax
  805. mov [ebx+SCTX_DAttrNC+ATTRSET_fOoW], eax
  806. mov [ebx+SCTX_DAttrCY+ATTRSET_fOoW], eax
  807. mov ecx, [ebx+SCTX_pPrim]
  808. mov [ecx+RASTPRIM_iDOoWDX], eax
  809. mov [ecx+RASTPRIM_iDOoWDY], eax
  810. mov ecx, pV1
  811. ;
  812. ; Setup for tex1. Slot a is used for U and b for V.
  813. ;
  814. d_AffineTexSetup(`TL_dvTU', `TL_dvTV', `1')dnl
  815. ; Jump to next bead.
  816. jmp DWORD PTR [ebx+SCTX_pfnTriSetupTex1End]
  817. d_EndDeclTriSetup(`Affine_Tex1')dnl
  818. ;-----------------------------------------------------------------------------
  819. ;
  820. ; Setup_Persp_Tex2
  821. ;
  822. ; Attribute setup for second texture coordinates.
  823. ; Coordinates are set up for perspective correction.
  824. ;
  825. ;-----------------------------------------------------------------------------
  826. d_DeclTriSetup(`Persp_Tex2')dnl
  827. ;
  828. ; Setup for tex2. Slot a is for U and slot B is for V.
  829. ;
  830. d_PerspTexSetup(`TM_dvTU2', `TM_dvTV2', `2')dnl
  831. ; Jump to next bead.
  832. jmp DWORD PTR [ebx+SCTX_pfnTriSetupTex2End]
  833. d_EndDeclTriSetup(`Persp_Tex2')dnl
  834. ;-----------------------------------------------------------------------------
  835. ;
  836. ; Setup_Affine_Tex2
  837. ;
  838. ; Attribute setup for second texture coordinates.
  839. ; Coordinates are set up for affine mapping.
  840. ;
  841. ;-----------------------------------------------------------------------------
  842. d_DeclTriSetup(`Affine_Tex2')dnl
  843. ;
  844. ; Setup for tex2. Slot a is for U and slot B is for V.
  845. ;
  846. d_AffineTexSetup(`TM_dvTU2', `TM_dvTV2', `2')dnl
  847. ; Jump to next bead.
  848. jmp DWORD PTR [ebx+SCTX_pfnTriSetupTex2End]
  849. d_EndDeclTriSetup(`Affine_Tex2')dnl
  850. ;-----------------------------------------------------------------------------
  851. ;
  852. ; Setup_Diff
  853. ;
  854. ; Attribute setup for interpolated diffuse color.
  855. ;
  856. ;-----------------------------------------------------------------------------
  857. d_DeclTriSetup(`Diff')dnl
  858. ;
  859. ; Slots a - d are B, G, R and A, respectively.
  860. ;
  861. d_ColorSetup(`TL_dcColor', `')dnl
  862. ; Jump to next bead.
  863. jmp DWORD PTR [ebx+SCTX_pfnTriSetupDiffEnd]
  864. d_EndDeclTriSetup(`Diff')dnl
  865. ;-----------------------------------------------------------------------------
  866. ;
  867. ; Setup_DiffFlat
  868. ;
  869. ; Attribute setup for constant diffuse color.
  870. ;
  871. ;-----------------------------------------------------------------------------
  872. d_DeclTriSetup(`DiffFlat')dnl
  873. ;
  874. ; Slots a - d are B, G, R and A, respectively.
  875. ;
  876. ; Get colors from first input vertex. Can't just use pV0
  877. ; because it may have changed due to vertex sorting.
  878. mov eax, [ebx+SCTX_pFlatVtx]
  879. mov eax, [eax+TL_dcColor]
  880. mov ecx, eax
  881. ; G is in the correct shifted position.
  882. and eax, 0ff00h
  883. mov fVb0, eax
  884. fild fVb0 ; G
  885. ; Shift B and store.
  886. mov eax, ecx
  887. shl eax, COLOR_SHIFT
  888. and eax, 0ff00h
  889. mov fVa0, eax
  890. fild fVa0 ; B G
  891. ; Shift R and store.
  892. mov eax, ecx
  893. shr eax, (16 - COLOR_SHIFT)
  894. and eax, 0ff00h
  895. mov fVc0, eax
  896. fild fVc0 ; R B G
  897. ; Shift A and store.
  898. mov eax, ecx
  899. shr eax, (24 - COLOR_SHIFT)
  900. and eax, 0ff00h
  901. mov fVd0, eax
  902. fild fVd0 ; A R B G
  903. fxch st(3) ; G R B A
  904. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fG] ; R B A
  905. fxch st(1) ; B R A
  906. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fB] ; R A
  907. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fR] ; A
  908. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fA] ;
  909. ; Zero out all deltas.
  910. xor eax, eax
  911. mov ecx, [ebx+SCTX_pPrim]
  912. mov [ebx+SCTX_DAttrDX+ATTRSET_fB], eax
  913. mov [ebx+SCTX_DAttrDX+ATTRSET_fG], eax
  914. mov [ebx+SCTX_DAttrDX+ATTRSET_fR], eax
  915. mov [ebx+SCTX_DAttrDX+ATTRSET_fA], eax
  916. mov [ebx+SCTX_DAttrDY+ATTRSET_fB], eax
  917. mov [ebx+SCTX_DAttrDY+ATTRSET_fG], eax
  918. mov [ebx+SCTX_DAttrDY+ATTRSET_fR], eax
  919. mov [ebx+SCTX_DAttrDY+ATTRSET_fA], eax
  920. mov [ebx+SCTX_DAttrNC+ATTRSET_fB], eax
  921. mov [ebx+SCTX_DAttrNC+ATTRSET_fG], eax
  922. mov [ebx+SCTX_DAttrNC+ATTRSET_fR], eax
  923. mov [ebx+SCTX_DAttrNC+ATTRSET_fA], eax
  924. mov [ebx+SCTX_DAttrCY+ATTRSET_fB], eax
  925. mov [ebx+SCTX_DAttrCY+ATTRSET_fG], eax
  926. mov [ebx+SCTX_DAttrCY+ATTRSET_fR], eax
  927. mov [ebx+SCTX_DAttrCY+ATTRSET_fA], eax
  928. ; Fills both B and G.
  929. mov [ecx+RASTPRIM_iDBDX], eax
  930. ; Fills both R and A.
  931. mov [ecx+RASTPRIM_iDRDX], eax
  932. mov ecx, pV1
  933. ; Jump to next bead.
  934. jmp DWORD PTR [ebx+SCTX_pfnTriSetupDiffEnd]
  935. d_EndDeclTriSetup(`DiffFlat')dnl
  936. ;-----------------------------------------------------------------------------
  937. ;
  938. ; Setup_DIdx
  939. ;
  940. ; Attribute setup for interpolated diffuse indexed color.
  941. ;
  942. ;-----------------------------------------------------------------------------
  943. d_DeclTriSetup(`DIdx')dnl
  944. ;
  945. ; Slots a, b are Idx and A, respectively.
  946. ;
  947. ; Get values from pV0.
  948. mov eax, [edi+TL_dcColor]
  949. mov ecx, eax
  950. ; Mask off alpha.
  951. and eax, 0ffffffh
  952. add eax, 128
  953. mov fVa0, eax
  954. fild fVa0 ; Idx
  955. ; Shift A and store.
  956. shr ecx, 24
  957. mov fVb0, ecx
  958. fild fVb0 ; A Idx
  959. ; Get colors from pV2 and subtract pV0.
  960. d_IdxColorDelta(edx+TL_dcColor, `2')dnl
  961. ; Get colors from pV1 and subtract pV0.
  962. mov ecx, pV1
  963. d_IdxColorDelta(ecx+TL_dcColor, `1')dnl
  964. mov ecx, pV1
  965. ; Store initial values.
  966. fstp fVb0 ; Idx
  967. fstp fVa0 ;
  968. d_CorrectAttr(ATTRSET_fDIdx, `fVa0', `fDVa20', `fDVa10',
  969. `INDEX_COLOR_FIXED_SCALE')dnl
  970. d_CorrectAttr(ATTRSET_fDIdxA, `fVb0', `fDVb20', `fDVb10',
  971. `INDEX_COLOR_SCALE')dnl
  972. d_NegateDeltas(IdxCol, ATTRSET_fDIdx, ATTRSET_fDIdxA)dnl
  973. pushdef(`d_CRPD_Post',
  974. ` mov eax, [ebx+SCTX_pPrim]
  975. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fDIdx]
  976. fistp DWORD PTR [eax+RASTPRIM_iDIdxDX]
  977. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fDIdxA]
  978. fistp DWORD PTR [eax+RASTPRIM_iDIdxADX]
  979. ')dnl
  980. d_CheckRpDeltas(IdxCol, `C_INDEX_COLOR_LIMIT',
  981. SCTX_DAttrDX+ATTRSET_fDIdx,
  982. SCTX_DAttrDX+ATTRSET_fDIdxA)dnl
  983. popdef(`d_CRPD_Post')dnl
  984. d_CheckFxDeltas(IdxCol, `C_INDEX_COLOR_LIMIT',
  985. ATTRSET_fDIdx, ATTRSET_fDIdxA)dnl
  986. ; Jump to next bead.
  987. jmp DWORD PTR [ebx+SCTX_pfnTriSetupDiffEnd]
  988. d_EndDeclTriSetup(`DIdx')dnl
  989. ;-----------------------------------------------------------------------------
  990. ;
  991. ; Setup_DIdxFlat
  992. ;
  993. ; Attribute setup for constant diffuse indexed color.
  994. ;
  995. ;-----------------------------------------------------------------------------
  996. d_DeclTriSetup(`DIdxFlat')dnl
  997. ;
  998. ; Slots a, b are Idx and A, respectively.
  999. ;
  1000. ; Get colors from first input vertex. Can't just use pV0
  1001. ; because it may have changed due to vertex sorting.
  1002. mov eax, [ebx+SCTX_pFlatVtx]
  1003. mov eax, [eax+TL_dcColor]
  1004. mov ecx, eax
  1005. ; Mask off alpha and shift.
  1006. shl eax, INDEX_COLOR_FIXED_SHIFT
  1007. ; Should not be necessary to add .5 to Idx, since
  1008. ; no floating point ops are done to it
  1009. mov fVa0, eax
  1010. fild fVa0 ; Idx
  1011. ; Shift A and store.
  1012. shr ecx, (24 - INDEX_COLOR_SHIFT)
  1013. and ecx, 0ffffffh
  1014. mov fVb0, ecx
  1015. fild fVb0 ; A Idx
  1016. fxch st(1) ; Idx A
  1017. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fDIdx] ; A
  1018. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fDIdxA] ;
  1019. ; Zero out all deltas.
  1020. xor eax, eax
  1021. mov ecx, [ebx+SCTX_pPrim]
  1022. mov [ebx+SCTX_DAttrDX+ATTRSET_fDIdx], eax
  1023. mov [ebx+SCTX_DAttrDX+ATTRSET_fDIdxA], eax
  1024. mov [ebx+SCTX_DAttrDY+ATTRSET_fDIdx], eax
  1025. mov [ebx+SCTX_DAttrDY+ATTRSET_fDIdxA], eax
  1026. mov [ebx+SCTX_DAttrNC+ATTRSET_fDIdx], eax
  1027. mov [ebx+SCTX_DAttrNC+ATTRSET_fDIdxA], eax
  1028. mov [ebx+SCTX_DAttrCY+ATTRSET_fDIdx], eax
  1029. mov [ebx+SCTX_DAttrCY+ATTRSET_fDIdxA], eax
  1030. mov [ecx+RASTPRIM_iDIdxDX], eax
  1031. mov [ecx+RASTPRIM_iDIdxADX], eax
  1032. mov ecx, pV1
  1033. ; Jump to next bead.
  1034. jmp DWORD PTR [ebx+SCTX_pfnTriSetupDiffEnd]
  1035. d_EndDeclTriSetup(`DIdxFlat')dnl
  1036. ;-----------------------------------------------------------------------------
  1037. ;
  1038. ; Setup_Spec
  1039. ;
  1040. ; Attribute setup for interpolated specular color.
  1041. ;
  1042. ;-----------------------------------------------------------------------------
  1043. d_DeclTriSetup(`Spec')dnl
  1044. ;
  1045. ; Slots a - c are B, G and R, respectively.
  1046. ;
  1047. d_ColorSetup(`TL_dcSpecular', `S')dnl
  1048. ; Jump to next bead.
  1049. jmp DWORD PTR [ebx+SCTX_pfnTriSetupSpecEnd]
  1050. d_EndDeclTriSetup(`Spec')dnl
  1051. ;-----------------------------------------------------------------------------
  1052. ;
  1053. ; Setup_SpecFlat
  1054. ;
  1055. ; Attribute setup for constant specular color.
  1056. ;
  1057. ;-----------------------------------------------------------------------------
  1058. d_DeclTriSetup(`SpecFlat')dnl
  1059. ;
  1060. ; Slots a - c are B, G and R, respectively.
  1061. ;
  1062. ; Get colors from first input vertex. Can't just use pV0
  1063. ; because it may have changed due to vertex sorting.
  1064. mov eax, [ebx+SCTX_pFlatVtx]
  1065. mov eax, [eax+TL_dcSpecular]
  1066. mov ecx, eax
  1067. ; G is in the correct shifted position.
  1068. and eax, 0ff00h
  1069. mov fVb0, eax
  1070. fild fVb0 ; G
  1071. ; Shift B and store.
  1072. mov eax, ecx
  1073. shl eax, 8
  1074. and eax, 0ff00h
  1075. mov fVa0, eax
  1076. fild fVa0 ; B G
  1077. ; Shift R and store.
  1078. mov eax, ecx
  1079. shr eax, 8
  1080. and eax, 0ff00h
  1081. mov fVc0, eax
  1082. fild fVc0 ; R B G
  1083. fxch st(2) ; G B R
  1084. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fGS] ; B R
  1085. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fBS] ; R
  1086. fstp DWORD PTR [ebx+SCTX_Attr+ATTRSET_fRS] ;
  1087. ; Zero out all deltas.
  1088. xor eax, eax
  1089. mov ecx, [ebx+SCTX_pPrim]
  1090. mov [ebx+SCTX_DAttrDX+ATTRSET_fBS], eax
  1091. mov [ebx+SCTX_DAttrDX+ATTRSET_fGS], eax
  1092. mov [ebx+SCTX_DAttrDX+ATTRSET_fRS], eax
  1093. mov [ebx+SCTX_DAttrDY+ATTRSET_fBS], eax
  1094. mov [ebx+SCTX_DAttrDY+ATTRSET_fGS], eax
  1095. mov [ebx+SCTX_DAttrDY+ATTRSET_fRS], eax
  1096. mov [ebx+SCTX_DAttrNC+ATTRSET_fBS], eax
  1097. mov [ebx+SCTX_DAttrNC+ATTRSET_fGS], eax
  1098. mov [ebx+SCTX_DAttrNC+ATTRSET_fRS], eax
  1099. mov [ebx+SCTX_DAttrCY+ATTRSET_fBS], eax
  1100. mov [ebx+SCTX_DAttrCY+ATTRSET_fGS], eax
  1101. mov [ebx+SCTX_DAttrCY+ATTRSET_fRS], eax
  1102. ; Fills both B and G.
  1103. mov [ecx+RASTPRIM_iDBSDX], eax
  1104. ; Fills both R and Fog. Fog will be set up later, if at all,
  1105. ; so it's OK to trash it here.
  1106. mov [ecx+RASTPRIM_iDRSDX], eax
  1107. mov ecx, pV1
  1108. ; Jump to next bead.
  1109. jmp DWORD PTR [ebx+SCTX_pfnTriSetupSpecEnd]
  1110. d_EndDeclTriSetup(`SpecFlat')dnl
  1111. ;-----------------------------------------------------------------------------
  1112. ;
  1113. ; Setup_Fog
  1114. ;
  1115. ; Attribute setup for vertex fog.
  1116. ;
  1117. ;-----------------------------------------------------------------------------
  1118. d_DeclTriSetup(`Fog')dnl
  1119. ;
  1120. ; Slot a is used with some temporaries in b and c.
  1121. ;
  1122. IFNDEF PWL_FOG
  1123. ; Check for global-into-local fog. If global fog is on,
  1124. ; compute the local fog values from table fog rather than
  1125. ; from the vertex.
  1126. mov eax, [ebx+SCTX_uFlags]
  1127. test eax, PRIMSF_GLOBAL_FOG_USED
  1128. jz L_NormalLocalFog
  1129. ;
  1130. ; Compute table fog values for all three vertex Z values.
  1131. ;
  1132. ; pV1
  1133. push DWORD PTR [ecx+TL_dvSZ]
  1134. mov ecx, esi
  1135. call @ComputeTableFog@8
  1136. mov fVb0, eax
  1137. ; pV0
  1138. push DWORD PTR [edi+TL_dvSZ]
  1139. mov ecx, esi
  1140. call @ComputeTableFog@8
  1141. ; Keep V0 fog in fTmp so that we can write the FP value
  1142. ; into fVa0.
  1143. mov fTmp, eax
  1144. ; pV2
  1145. mov edx, pV2
  1146. push DWORD PTR [edx+TL_dvSZ]
  1147. mov ecx, esi
  1148. call @ComputeTableFog@8
  1149. mov fVc0, eax
  1150. ; Restore pV1 and pV2.
  1151. mov ecx, pV1
  1152. mov edx, pV2
  1153. jmp L_ComputeFogDeltas
  1154. L_NormalLocalFog:
  1155. ENDIF
  1156. ; Extract fog values from specular alpha and shift into position.
  1157. mov eax, [edi+TL_dcSpecular]
  1158. and eax, 0ff000000h
  1159. shr eax, 24 - FOG_SHIFT
  1160. ; Keep V0 fog in fTmp so that we can write the FP value
  1161. ; into fVa0.
  1162. mov fTmp, eax
  1163. mov eax, [ecx+TL_dcSpecular]
  1164. and eax, 0ff000000h
  1165. shr eax, 24 - FOG_SHIFT
  1166. mov fVb0, eax
  1167. mov eax, [edx+TL_dcSpecular]
  1168. and eax, 0ff000000h
  1169. shr eax, 24 - FOG_SHIFT
  1170. mov fVc0, eax
  1171. IFNDEF PWL_FOG
  1172. L_ComputeFogDeltas:
  1173. ENDIF
  1174. fild fTmp
  1175. ; Compute fog deltas from shifted values in fVa?.
  1176. mov eax, fVc0
  1177. sub eax, fTmp
  1178. mov fDVa20, eax
  1179. fstp fVa0
  1180. fild fDVa20
  1181. mov eax, fVb0
  1182. sub eax, fTmp
  1183. mov fDVa10, eax
  1184. fstp fDVa20
  1185. fild fDVa10
  1186. fstp fDVa10
  1187. ; fVa0 is already scaled so the scaling factor is given as 1.0.
  1188. ; This is a little wasteful but it makes the above code simpler
  1189. ; and more integer.
  1190. d_CorrectAttr(`ATTRSET_fFog', `fVa0', `fDVa20', `fDVa10', `_g_fOne')dnl
  1191. d_NegateDeltas(`Fog', `ATTRSET_fFog')dnl
  1192. pushdef(`d_CRPD_Post',
  1193. ` ; Fog deltas are given per span rather than per primitive.
  1194. ; Store local fog value in setup context so that it can be
  1195. ; copied into the spans later.
  1196. fld DWORD PTR [ebx+SCTX_DAttrDX+ATTRSET_fFog]
  1197. fistp DWORD PTR [ebx+SCTX_iDLocalFogDX]
  1198. ')dnl
  1199. d_CheckRpDeltas(`Fog', `C_FOG_LIMIT', `SCTX_DAttrDX+ATTRSET_fFog')dnl
  1200. popdef(`d_CRPD_Post')dnl
  1201. d_CheckFxDeltas(`Fog', `C_FOG_LIMIT', `ATTRSET_fFog')dnl
  1202. ; Jump to next bead.
  1203. jmp DWORD PTR [ebx+SCTX_pfnTriSetupFogEnd]
  1204. d_EndDeclTriSetup(`Fog')dnl
  1205. ;-----------------------------------------------------------------------------
  1206. ;
  1207. ; Setup_End
  1208. ;
  1209. ; Final bead. Restores stack and returns.
  1210. ;
  1211. ;-----------------------------------------------------------------------------
  1212. d_DeclTriSetup(`End')dnl
  1213. ; Give up locals.
  1214. add esp, SETUP_LOCALS
  1215. ; Restore registers.
  1216. pop ebp
  1217. pop edi
  1218. pop esi
  1219. pop ebx
  1220. ret 8
  1221. d_EndDeclTriSetup(`End')dnl
  1222. END