r_drawa.s 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. //
  2. // r_drawa.s
  3. // x86 assembly-language edge clipping and emission code
  4. //
  5. #include "qasm.h"
  6. #include "d_ifacea.h"
  7. #if id386
  8. // !!! if these are changed, they must be changed in r_draw.c too !!!
  9. #define FULLY_CLIPPED_CACHED 0x80000000
  10. #define FRAMECOUNT_MASK 0x7FFFFFFF
  11. .data
  12. Ld0: .single 0.0
  13. Ld1: .single 0.0
  14. Lstack: .long 0
  15. Lfp_near_clip: .single NEAR_CLIP
  16. Lceilv0: .long 0
  17. Lv: .long 0
  18. Lu0: .long 0
  19. Lv0: .long 0
  20. Lzi0: .long 0
  21. .text
  22. //----------------------------------------------------------------------
  23. // edge clipping code
  24. //----------------------------------------------------------------------
  25. #define pv0 4+12
  26. #define pv1 8+12
  27. #define clip 12+12
  28. .align 4
  29. .globl C(R_ClipEdge)
  30. C(R_ClipEdge):
  31. pushl %esi // preserve register variables
  32. pushl %edi
  33. pushl %ebx
  34. movl %esp,Lstack // for clearing the stack later
  35. // float d0, d1, f;
  36. // mvertex_t clipvert;
  37. movl clip(%esp),%ebx
  38. movl pv0(%esp),%esi
  39. movl pv1(%esp),%edx
  40. // if (clip)
  41. // {
  42. testl %ebx,%ebx
  43. jz Lemit
  44. // do
  45. // {
  46. Lcliploop:
  47. // d0 = DotProduct (pv0->position, clip->normal) - clip->dist;
  48. // d1 = DotProduct (pv1->position, clip->normal) - clip->dist;
  49. flds mv_position+0(%esi)
  50. fmuls cp_normal+0(%ebx)
  51. flds mv_position+4(%esi)
  52. fmuls cp_normal+4(%ebx)
  53. flds mv_position+8(%esi)
  54. fmuls cp_normal+8(%ebx)
  55. fxch %st(1)
  56. faddp %st(0),%st(2) // d0mul2 | d0add0
  57. flds mv_position+0(%edx)
  58. fmuls cp_normal+0(%ebx)
  59. flds mv_position+4(%edx)
  60. fmuls cp_normal+4(%ebx)
  61. flds mv_position+8(%edx)
  62. fmuls cp_normal+8(%ebx)
  63. fxch %st(1)
  64. faddp %st(0),%st(2) // d1mul2 | d1add0 | d0mul2 | d0add0
  65. fxch %st(3) // d0add0 | d1add0 | d0mul2 | d1mul2
  66. faddp %st(0),%st(2) // d1add0 | dot0 | d1mul2
  67. faddp %st(0),%st(2) // dot0 | dot1
  68. fsubs cp_dist(%ebx) // d0 | dot1
  69. fxch %st(1) // dot1 | d0
  70. fsubs cp_dist(%ebx) // d1 | d0
  71. fxch %st(1)
  72. fstps Ld0
  73. fstps Ld1
  74. // if (d0 >= 0)
  75. // {
  76. movl Ld0,%eax
  77. movl Ld1,%ecx
  78. orl %eax,%ecx
  79. js Lp2
  80. // both points are unclipped
  81. Lcontinue:
  82. //
  83. // R_ClipEdge (&clipvert, pv1, clip->next);
  84. // return;
  85. // }
  86. // } while ((clip = clip->next) != NULL);
  87. movl cp_next(%ebx),%ebx
  88. testl %ebx,%ebx
  89. jnz Lcliploop
  90. // }
  91. //// add the edge
  92. // R_EmitEdge (pv0, pv1);
  93. Lemit:
  94. //
  95. // set integer rounding to ceil mode, set to single precision
  96. //
  97. // FIXME: do away with by manually extracting integers from floats?
  98. // FIXME: set less often
  99. fldcw ceil_cw
  100. // edge_t *edge, *pcheck;
  101. // int u_check;
  102. // float u, u_step;
  103. // vec3_t local, transformed;
  104. // float *world;
  105. // int v, v2, ceilv0;
  106. // float scale, lzi0, u0, v0;
  107. // int side;
  108. // if (r_lastvertvalid)
  109. // {
  110. cmpl $0,C(r_lastvertvalid)
  111. jz LCalcFirst
  112. // u0 = r_u1;
  113. // v0 = r_v1;
  114. // lzi0 = r_lzi1;
  115. // ceilv0 = r_ceilv1;
  116. movl C(r_lzi1),%eax
  117. movl C(r_u1),%ecx
  118. movl %eax,Lzi0
  119. movl %ecx,Lu0
  120. movl C(r_v1),%ecx
  121. movl C(r_ceilv1),%eax
  122. movl %ecx,Lv0
  123. movl %eax,Lceilv0
  124. jmp LCalcSecond
  125. // }
  126. LCalcFirst:
  127. // else
  128. // {
  129. // world = &pv0->position[0];
  130. call LTransformAndProject // v0 | lzi0 | u0
  131. fsts Lv0
  132. fxch %st(2) // u0 | lzi0 | v0
  133. fstps Lu0 // lzi0 | v0
  134. fstps Lzi0 // v0
  135. // ceilv0 = (int)(v0 - 2000) + 2000; // ceil(v0);
  136. fistpl Lceilv0
  137. // }
  138. LCalcSecond:
  139. // world = &pv1->position[0];
  140. movl %edx,%esi
  141. call LTransformAndProject // v1 | lzi1 | u1
  142. flds Lu0 // u0 | v1 | lzi1 | u1
  143. fxch %st(3) // u1 | v1 | lzi1 | u0
  144. flds Lzi0 // lzi0 | u1 | v1 | lzi1 | u0
  145. fxch %st(3) // lzi1 | u1 | v1 | lzi0 | u0
  146. flds Lv0 // v0 | lzi1 | u1 | v1 | lzi0 | u0
  147. fxch %st(3) // v1 | lzi1 | u1 | v0 | lzi0 | u0
  148. // r_ceilv1 = (int)(r_v1 - 2000) + 2000; // ceil(r_v1);
  149. fistl C(r_ceilv1)
  150. fldcw single_cw // put back normal floating-point state
  151. fsts C(r_v1)
  152. fxch %st(4) // lzi0 | lzi1 | u1 | v0 | v1 | u0
  153. // if (r_lzi1 > lzi0)
  154. // lzi0 = r_lzi1;
  155. fcom %st(1)
  156. fnstsw %ax
  157. testb $1,%ah
  158. jz LP0
  159. fstp %st(0)
  160. fld %st(0)
  161. LP0:
  162. fxch %st(1) // lzi1 | lzi0 | u1 | v0 | v1 | u0
  163. fstps C(r_lzi1) // lzi0 | u1 | v0 | v1 | u0
  164. fxch %st(1)
  165. fsts C(r_u1)
  166. fxch %st(1)
  167. // if (lzi0 > r_nearzi) // for mipmap finding
  168. // r_nearzi = lzi0;
  169. fcoms C(r_nearzi)
  170. fnstsw %ax
  171. testb $0x45,%ah
  172. jnz LP1
  173. fsts C(r_nearzi)
  174. LP1:
  175. // // for right edges, all we want is the effect on 1/z
  176. // if (r_nearzionly)
  177. // return;
  178. movl C(r_nearzionly),%eax
  179. testl %eax,%eax
  180. jz LP2
  181. LPop5AndDone:
  182. movl C(cacheoffset),%eax
  183. movl C(r_framecount),%edx
  184. cmpl $0x7FFFFFFF,%eax
  185. jz LDoPop
  186. andl $(FRAMECOUNT_MASK),%edx
  187. orl $(FULLY_CLIPPED_CACHED),%edx
  188. movl %edx,C(cacheoffset)
  189. LDoPop:
  190. fstp %st(0) // u1 | v0 | v1 | u0
  191. fstp %st(0) // v0 | v1 | u0
  192. fstp %st(0) // v1 | u0
  193. fstp %st(0) // u0
  194. fstp %st(0)
  195. jmp Ldone
  196. LP2:
  197. // // create the edge
  198. // if (ceilv0 == r_ceilv1)
  199. // return; // horizontal edge
  200. movl Lceilv0,%ebx
  201. movl C(edge_p),%edi
  202. movl C(r_ceilv1),%ecx
  203. movl %edi,%edx
  204. movl C(r_pedge),%esi
  205. addl $(et_size),%edx
  206. cmpl %ecx,%ebx
  207. jz LPop5AndDone
  208. movl C(r_pedge),%eax
  209. movl %eax,et_owner(%edi)
  210. // side = ceilv0 > r_ceilv1;
  211. //
  212. // edge->nearzi = lzi0;
  213. fstps et_nearzi(%edi) // u1 | v0 | v1 | u0
  214. // if (side == 1)
  215. // {
  216. jc LSide0
  217. LSide1:
  218. // // leading edge (go from p2 to p1)
  219. // u_step = ((u0 - r_u1) / (v0 - r_v1));
  220. fsubrp %st(0),%st(3) // v0 | v1 | u0-u1
  221. fsub %st(1),%st(0) // v0-v1 | v1 | u0-u1
  222. fdivrp %st(0),%st(2) // v1 | ustep
  223. // r_emitted = 1;
  224. movl $1,C(r_emitted)
  225. // edge = edge_p++;
  226. movl %edx,C(edge_p)
  227. // pretouch next edge
  228. movl (%edx),%eax
  229. // v2 = ceilv0 - 1;
  230. // v = r_ceilv1;
  231. movl %ecx,%eax
  232. leal -1(%ebx),%ecx
  233. movl %eax,%ebx
  234. // edge->surfs[0] = 0;
  235. // edge->surfs[1] = surface_p - surfaces;
  236. movl C(surface_p),%eax
  237. movl C(surfaces),%esi
  238. subl %edx,%edx
  239. subl %esi,%eax
  240. shrl $(SURF_T_SHIFT),%eax
  241. movl %edx,et_surfs(%edi)
  242. movl %eax,et_surfs+2(%edi)
  243. subl %esi,%esi
  244. // u = r_u1 + ((float)v - r_v1) * u_step;
  245. movl %ebx,Lv
  246. fildl Lv // v | v1 | ustep
  247. fsubp %st(0),%st(1) // v-v1 | ustep
  248. fmul %st(1),%st(0) // (v-v1)*ustep | ustep
  249. fadds C(r_u1) // u | ustep
  250. jmp LSideDone
  251. // }
  252. LSide0:
  253. // else
  254. // {
  255. // // trailing edge (go from p1 to p2)
  256. // u_step = ((r_u1 - u0) / (r_v1 - v0));
  257. fsub %st(3),%st(0) // u1-u0 | v0 | v1 | u0
  258. fxch %st(2) // v1 | v0 | u1-u0 | u0
  259. fsub %st(1),%st(0) // v1-v0 | v0 | u1-u0 | u0
  260. fdivrp %st(0),%st(2) // v0 | ustep | u0
  261. // r_emitted = 1;
  262. movl $1,C(r_emitted)
  263. // edge = edge_p++;
  264. movl %edx,C(edge_p)
  265. // pretouch next edge
  266. movl (%edx),%eax
  267. // v = ceilv0;
  268. // v2 = r_ceilv1 - 1;
  269. decl %ecx
  270. // edge->surfs[0] = surface_p - surfaces;
  271. // edge->surfs[1] = 0;
  272. movl C(surface_p),%eax
  273. movl C(surfaces),%esi
  274. subl %edx,%edx
  275. subl %esi,%eax
  276. shrl $(SURF_T_SHIFT),%eax
  277. movl %edx,et_surfs+2(%edi)
  278. movl %eax,et_surfs(%edi)
  279. movl $1,%esi
  280. // u = u0 + ((float)v - v0) * u_step;
  281. movl %ebx,Lv
  282. fildl Lv // v | v0 | ustep | u0
  283. fsubp %st(0),%st(1) // v-v0 | ustep | u0
  284. fmul %st(1),%st(0) // (v-v0)*ustep | ustep | u0
  285. faddp %st(0),%st(2) // ustep | u
  286. fxch %st(1) // u | ustep
  287. // }
  288. LSideDone:
  289. // edge->u_step = u_step*0x100000;
  290. // edge->u = u*0x100000 + 0xFFFFF;
  291. fmuls fp_1m // u*0x100000 | ustep
  292. fxch %st(1) // ustep | u*0x100000
  293. fmuls fp_1m // ustep*0x100000 | u*0x100000
  294. fxch %st(1) // u*0x100000 | ustep*0x100000
  295. fadds fp_1m_minus_1 // u*0x100000 + 0xFFFFF | ustep*0x100000
  296. fxch %st(1) // ustep*0x100000 | u*0x100000 + 0xFFFFF
  297. fistpl et_u_step(%edi) // u*0x100000 + 0xFFFFF
  298. fistpl et_u(%edi)
  299. // // we need to do this to avoid stepping off the edges if a very nearly
  300. // // horizontal edge is less than epsilon above a scan, and numeric error
  301. // // causes it to incorrectly extend to the scan, and the extension of the
  302. // // line goes off the edge of the screen
  303. // // FIXME: is this actually needed?
  304. // if (edge->u < r_refdef.vrect_x_adj_shift20)
  305. // edge->u = r_refdef.vrect_x_adj_shift20;
  306. // if (edge->u > r_refdef.vrectright_adj_shift20)
  307. // edge->u = r_refdef.vrectright_adj_shift20;
  308. movl et_u(%edi),%eax
  309. movl C(r_refdef)+rd_vrect_x_adj_shift20,%edx
  310. cmpl %edx,%eax
  311. jl LP4
  312. movl C(r_refdef)+rd_vrectright_adj_shift20,%edx
  313. cmpl %edx,%eax
  314. jng LP5
  315. LP4:
  316. movl %edx,et_u(%edi)
  317. movl %edx,%eax
  318. LP5:
  319. // // sort the edge in normally
  320. // u_check = edge->u;
  321. //
  322. // if (edge->surfs[0])
  323. // u_check++; // sort trailers after leaders
  324. addl %esi,%eax
  325. // if (!newedges[v] || newedges[v]->u >= u_check)
  326. // {
  327. movl C(newedges)(,%ebx,4),%esi
  328. testl %esi,%esi
  329. jz LDoFirst
  330. cmpl %eax,et_u(%esi)
  331. jl LNotFirst
  332. LDoFirst:
  333. // edge->next = newedges[v];
  334. // newedges[v] = edge;
  335. movl %esi,et_next(%edi)
  336. movl %edi,C(newedges)(,%ebx,4)
  337. jmp LSetRemove
  338. // }
  339. LNotFirst:
  340. // else
  341. // {
  342. // pcheck = newedges[v];
  343. //
  344. // while (pcheck->next && pcheck->next->u < u_check)
  345. // pcheck = pcheck->next;
  346. LFindInsertLoop:
  347. movl %esi,%edx
  348. movl et_next(%esi),%esi
  349. testl %esi,%esi
  350. jz LInsertFound
  351. cmpl %eax,et_u(%esi)
  352. jl LFindInsertLoop
  353. LInsertFound:
  354. // edge->next = pcheck->next;
  355. // pcheck->next = edge;
  356. movl %esi,et_next(%edi)
  357. movl %edi,et_next(%edx)
  358. // }
  359. LSetRemove:
  360. // edge->nextremove = removeedges[v2];
  361. // removeedges[v2] = edge;
  362. movl C(removeedges)(,%ecx,4),%eax
  363. movl %edi,C(removeedges)(,%ecx,4)
  364. movl %eax,et_nextremove(%edi)
  365. Ldone:
  366. movl Lstack,%esp // clear temporary variables from stack
  367. popl %ebx // restore register variables
  368. popl %edi
  369. popl %esi
  370. ret
  371. // at least one point is clipped
  372. Lp2:
  373. testl %eax,%eax
  374. jns Lp1
  375. // else
  376. // {
  377. // // point 0 is clipped
  378. // if (d1 < 0)
  379. // {
  380. movl Ld1,%eax
  381. testl %eax,%eax
  382. jns Lp3
  383. // // both points are clipped
  384. // // we do cache fully clipped edges
  385. // if (!leftclipped)
  386. movl C(r_leftclipped),%eax
  387. movl C(r_pedge),%ecx
  388. testl %eax,%eax
  389. jnz Ldone
  390. // r_pedge->framecount = r_framecount;
  391. movl C(r_framecount),%eax
  392. andl $(FRAMECOUNT_MASK),%eax
  393. orl $(FULLY_CLIPPED_CACHED),%eax
  394. movl %eax,C(cacheoffset)
  395. // return;
  396. jmp Ldone
  397. // }
  398. Lp1:
  399. // // point 0 is unclipped
  400. // if (d1 >= 0)
  401. // {
  402. // // both points are unclipped
  403. // continue;
  404. // // only point 1 is clipped
  405. // f = d0 / (d0 - d1);
  406. flds Ld0
  407. flds Ld1
  408. fsubr %st(1),%st(0)
  409. // // we don't cache partially clipped edges
  410. movl $0x7FFFFFFF,C(cacheoffset)
  411. fdivrp %st(0),%st(1)
  412. subl $(mv_size),%esp // allocate space for clipvert
  413. // clipvert.position[0] = pv0->position[0] +
  414. // f * (pv1->position[0] - pv0->position[0]);
  415. // clipvert.position[1] = pv0->position[1] +
  416. // f * (pv1->position[1] - pv0->position[1]);
  417. // clipvert.position[2] = pv0->position[2] +
  418. // f * (pv1->position[2] - pv0->position[2]);
  419. flds mv_position+8(%edx)
  420. fsubs mv_position+8(%esi)
  421. flds mv_position+4(%edx)
  422. fsubs mv_position+4(%esi)
  423. flds mv_position+0(%edx)
  424. fsubs mv_position+0(%esi) // 0 | 1 | 2
  425. // replace pv1 with the clip point
  426. movl %esp,%edx
  427. movl cp_leftedge(%ebx),%eax
  428. testb %al,%al
  429. fmul %st(3),%st(0)
  430. fxch %st(1) // 1 | 0 | 2
  431. fmul %st(3),%st(0)
  432. fxch %st(2) // 2 | 0 | 1
  433. fmulp %st(0),%st(3) // 0 | 1 | 2
  434. fadds mv_position+0(%esi)
  435. fxch %st(1) // 1 | 0 | 2
  436. fadds mv_position+4(%esi)
  437. fxch %st(2) // 2 | 0 | 1
  438. fadds mv_position+8(%esi)
  439. fxch %st(1) // 0 | 2 | 1
  440. fstps mv_position+0(%esp) // 2 | 1
  441. fstps mv_position+8(%esp) // 1
  442. fstps mv_position+4(%esp)
  443. // if (clip->leftedge)
  444. // {
  445. jz Ltestright
  446. // r_leftclipped = true;
  447. // r_leftexit = clipvert;
  448. movl $1,C(r_leftclipped)
  449. movl mv_position+0(%esp),%eax
  450. movl %eax,C(r_leftexit)+mv_position+0
  451. movl mv_position+4(%esp),%eax
  452. movl %eax,C(r_leftexit)+mv_position+4
  453. movl mv_position+8(%esp),%eax
  454. movl %eax,C(r_leftexit)+mv_position+8
  455. jmp Lcontinue
  456. // }
  457. Ltestright:
  458. // else if (clip->rightedge)
  459. // {
  460. testb %ah,%ah
  461. jz Lcontinue
  462. // r_rightclipped = true;
  463. // r_rightexit = clipvert;
  464. movl $1,C(r_rightclipped)
  465. movl mv_position+0(%esp),%eax
  466. movl %eax,C(r_rightexit)+mv_position+0
  467. movl mv_position+4(%esp),%eax
  468. movl %eax,C(r_rightexit)+mv_position+4
  469. movl mv_position+8(%esp),%eax
  470. movl %eax,C(r_rightexit)+mv_position+8
  471. // }
  472. //
  473. // R_ClipEdge (pv0, &clipvert, clip->next);
  474. // return;
  475. // }
  476. jmp Lcontinue
  477. // }
  478. Lp3:
  479. // // only point 0 is clipped
  480. // r_lastvertvalid = false;
  481. movl $0,C(r_lastvertvalid)
  482. // f = d0 / (d0 - d1);
  483. flds Ld0
  484. flds Ld1
  485. fsubr %st(1),%st(0)
  486. // // we don't cache partially clipped edges
  487. movl $0x7FFFFFFF,C(cacheoffset)
  488. fdivrp %st(0),%st(1)
  489. subl $(mv_size),%esp // allocate space for clipvert
  490. // clipvert.position[0] = pv0->position[0] +
  491. // f * (pv1->position[0] - pv0->position[0]);
  492. // clipvert.position[1] = pv0->position[1] +
  493. // f * (pv1->position[1] - pv0->position[1]);
  494. // clipvert.position[2] = pv0->position[2] +
  495. // f * (pv1->position[2] - pv0->position[2]);
  496. flds mv_position+8(%edx)
  497. fsubs mv_position+8(%esi)
  498. flds mv_position+4(%edx)
  499. fsubs mv_position+4(%esi)
  500. flds mv_position+0(%edx)
  501. fsubs mv_position+0(%esi) // 0 | 1 | 2
  502. movl cp_leftedge(%ebx),%eax
  503. testb %al,%al
  504. fmul %st(3),%st(0)
  505. fxch %st(1) // 1 | 0 | 2
  506. fmul %st(3),%st(0)
  507. fxch %st(2) // 2 | 0 | 1
  508. fmulp %st(0),%st(3) // 0 | 1 | 2
  509. fadds mv_position+0(%esi)
  510. fxch %st(1) // 1 | 0 | 2
  511. fadds mv_position+4(%esi)
  512. fxch %st(2) // 2 | 0 | 1
  513. fadds mv_position+8(%esi)
  514. fxch %st(1) // 0 | 2 | 1
  515. fstps mv_position+0(%esp) // 2 | 1
  516. fstps mv_position+8(%esp) // 1
  517. fstps mv_position+4(%esp)
  518. // replace pv0 with the clip point
  519. movl %esp,%esi
  520. // if (clip->leftedge)
  521. // {
  522. jz Ltestright2
  523. // r_leftclipped = true;
  524. // r_leftenter = clipvert;
  525. movl $1,C(r_leftclipped)
  526. movl mv_position+0(%esp),%eax
  527. movl %eax,C(r_leftenter)+mv_position+0
  528. movl mv_position+4(%esp),%eax
  529. movl %eax,C(r_leftenter)+mv_position+4
  530. movl mv_position+8(%esp),%eax
  531. movl %eax,C(r_leftenter)+mv_position+8
  532. jmp Lcontinue
  533. // }
  534. Ltestright2:
  535. // else if (clip->rightedge)
  536. // {
  537. testb %ah,%ah
  538. jz Lcontinue
  539. // r_rightclipped = true;
  540. // r_rightenter = clipvert;
  541. movl $1,C(r_rightclipped)
  542. movl mv_position+0(%esp),%eax
  543. movl %eax,C(r_rightenter)+mv_position+0
  544. movl mv_position+4(%esp),%eax
  545. movl %eax,C(r_rightenter)+mv_position+4
  546. movl mv_position+8(%esp),%eax
  547. movl %eax,C(r_rightenter)+mv_position+8
  548. // }
  549. jmp Lcontinue
  550. // %esi = vec3_t point to transform and project
  551. // %edx preserved
  552. LTransformAndProject:
  553. // // transform and project
  554. // VectorSubtract (world, modelorg, local);
  555. flds mv_position+0(%esi)
  556. fsubs C(modelorg)+0
  557. flds mv_position+4(%esi)
  558. fsubs C(modelorg)+4
  559. flds mv_position+8(%esi)
  560. fsubs C(modelorg)+8
  561. fxch %st(2) // local[0] | local[1] | local[2]
  562. // TransformVector (local, transformed);
  563. //
  564. // if (transformed[2] < NEAR_CLIP)
  565. // transformed[2] = NEAR_CLIP;
  566. //
  567. // lzi0 = 1.0 / transformed[2];
  568. fld %st(0) // local[0] | local[0] | local[1] | local[2]
  569. fmuls C(vpn)+0 // zm0 | local[0] | local[1] | local[2]
  570. fld %st(1) // local[0] | zm0 | local[0] | local[1] |
  571. // local[2]
  572. fmuls C(vright)+0 // xm0 | zm0 | local[0] | local[1] | local[2]
  573. fxch %st(2) // local[0] | zm0 | xm0 | local[1] | local[2]
  574. fmuls C(vup)+0 // ym0 | zm0 | xm0 | local[1] | local[2]
  575. fld %st(3) // local[1] | ym0 | zm0 | xm0 | local[1] |
  576. // local[2]
  577. fmuls C(vpn)+4 // zm1 | ym0 | zm0 | xm0 | local[1] |
  578. // local[2]
  579. fld %st(4) // local[1] | zm1 | ym0 | zm0 | xm0 |
  580. // local[1] | local[2]
  581. fmuls C(vright)+4 // xm1 | zm1 | ym0 | zm0 | xm0 |
  582. // local[1] | local[2]
  583. fxch %st(5) // local[1] | zm1 | ym0 | zm0 | xm0 |
  584. // xm1 | local[2]
  585. fmuls C(vup)+4 // ym1 | zm1 | ym0 | zm0 | xm0 |
  586. // xm1 | local[2]
  587. fxch %st(1) // zm1 | ym1 | ym0 | zm0 | xm0 |
  588. // xm1 | local[2]
  589. faddp %st(0),%st(3) // ym1 | ym0 | zm2 | xm0 | xm1 | local[2]
  590. fxch %st(3) // xm0 | ym0 | zm2 | ym1 | xm1 | local[2]
  591. faddp %st(0),%st(4) // ym0 | zm2 | ym1 | xm2 | local[2]
  592. faddp %st(0),%st(2) // zm2 | ym2 | xm2 | local[2]
  593. fld %st(3) // local[2] | zm2 | ym2 | xm2 | local[2]
  594. fmuls C(vpn)+8 // zm3 | zm2 | ym2 | xm2 | local[2]
  595. fld %st(4) // local[2] | zm3 | zm2 | ym2 | xm2 | local[2]
  596. fmuls C(vright)+8 // xm3 | zm3 | zm2 | ym2 | xm2 | local[2]
  597. fxch %st(5) // local[2] | zm3 | zm2 | ym2 | xm2 | xm3
  598. fmuls C(vup)+8 // ym3 | zm3 | zm2 | ym2 | xm2 | xm3
  599. fxch %st(1) // zm3 | ym3 | zm2 | ym2 | xm2 | xm3
  600. faddp %st(0),%st(2) // ym3 | zm4 | ym2 | xm2 | xm3
  601. fxch %st(4) // xm3 | zm4 | ym2 | xm2 | ym3
  602. faddp %st(0),%st(3) // zm4 | ym2 | xm4 | ym3
  603. fxch %st(1) // ym2 | zm4 | xm4 | ym3
  604. faddp %st(0),%st(3) // zm4 | xm4 | ym4
  605. fcoms Lfp_near_clip
  606. fnstsw %ax
  607. testb $1,%ah
  608. jz LNoClip
  609. fstp %st(0)
  610. flds Lfp_near_clip
  611. LNoClip:
  612. fdivrs float_1 // lzi0 | x | y
  613. fxch %st(1) // x | lzi0 | y
  614. // // FIXME: build x/yscale into transform?
  615. // scale = xscale * lzi0;
  616. // u0 = (xcenter + scale*transformed[0]);
  617. flds C(xscale) // xscale | x | lzi0 | y
  618. fmul %st(2),%st(0) // scale | x | lzi0 | y
  619. fmulp %st(0),%st(1) // scale*x | lzi0 | y
  620. fadds C(xcenter) // u0 | lzi0 | y
  621. // if (u0 < r_refdef.fvrectx_adj)
  622. // u0 = r_refdef.fvrectx_adj;
  623. // if (u0 > r_refdef.fvrectright_adj)
  624. // u0 = r_refdef.fvrectright_adj;
  625. // FIXME: use integer compares of floats?
  626. fcoms C(r_refdef)+rd_fvrectx_adj
  627. fnstsw %ax
  628. testb $1,%ah
  629. jz LClampP0
  630. fstp %st(0)
  631. flds C(r_refdef)+rd_fvrectx_adj
  632. LClampP0:
  633. fcoms C(r_refdef)+rd_fvrectright_adj
  634. fnstsw %ax
  635. testb $0x45,%ah
  636. jnz LClampP1
  637. fstp %st(0)
  638. flds C(r_refdef)+rd_fvrectright_adj
  639. LClampP1:
  640. fld %st(1) // lzi0 | u0 | lzi0 | y
  641. // scale = yscale * lzi0;
  642. // v0 = (ycenter - scale*transformed[1]);
  643. fmuls C(yscale) // scale | u0 | lzi0 | y
  644. fmulp %st(0),%st(3) // u0 | lzi0 | scale*y
  645. fxch %st(2) // scale*y | lzi0 | u0
  646. fsubrs C(ycenter) // v0 | lzi0 | u0
  647. // if (v0 < r_refdef.fvrecty_adj)
  648. // v0 = r_refdef.fvrecty_adj;
  649. // if (v0 > r_refdef.fvrectbottom_adj)
  650. // v0 = r_refdef.fvrectbottom_adj;
  651. // FIXME: use integer compares of floats?
  652. fcoms C(r_refdef)+rd_fvrecty_adj
  653. fnstsw %ax
  654. testb $1,%ah
  655. jz LClampP2
  656. fstp %st(0)
  657. flds C(r_refdef)+rd_fvrecty_adj
  658. LClampP2:
  659. fcoms C(r_refdef)+rd_fvrectbottom_adj
  660. fnstsw %ax
  661. testb $0x45,%ah
  662. jnz LClampP3
  663. fstp %st(0)
  664. flds C(r_refdef)+rd_fvrectbottom_adj
  665. LClampP3:
  666. ret
  667. #endif // id386