tmap.nas 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448
  1. ;; NASM note: this file abuses the section flags in such a way that
  2. ;; NASM 0.98.37 broke when this was compiled with:
  3. ;; nasm -o tmap.o -f elf -DLINUX tmap.nas
  4. ;;-----------------------------------------------------------------------------
  5. ;;
  6. ;; $Id$
  7. ;;
  8. ;; Copyright (C) 1998-2000 by DooM Legacy Team.
  9. ;;
  10. ;; This program is free software; you can redistribute it and/or
  11. ;; modify it under the terms of the GNU General Public License
  12. ;; as published by the Free Software Foundation; either version 2
  13. ;; of the License, or (at your option) any later version.
  14. ;;
  15. ;; This program is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;;
  20. ;;
  21. ;; $Log$
  22. ;; Revision 1.2 2003/09/10 23:33:38 hpa
  23. ;; Use the version of tmap.nas that actually caused problems
  24. ;;
  25. ;; Revision 1.10 2001/02/24 13:35:21 bpereira
  26. ;; no message
  27. ;;
  28. ;; Revision 1.9 2001/02/10 15:24:19 hurdler
  29. ;; Apply Rob's patch for Linux version
  30. ;;
  31. ;; Revision 1.8 2000/11/12 09:48:15 bpereira
  32. ;; no message
  33. ;;
  34. ;; Revision 1.7 2000/11/06 20:52:16 bpereira
  35. ;; no message
  36. ;;
  37. ;; Revision 1.6 2000/11/03 11:48:40 hurdler
  38. ;; Fix compiling problem under win32 with 3D-Floors and FragglScript (to verify!)
  39. ;;
  40. ;; Revision 1.5 2000/11/03 03:27:17 stroggonmeth
  41. ;; Again with the bug fixing...
  42. ;;
  43. ;; Revision 1.4 2000/11/02 17:50:10 stroggonmeth
  44. ;; Big 3Dfloors & FraggleScript commit!!
  45. ;;
  46. ;; Revision 1.3 2000/04/24 20:24:38 bpereira
  47. ;; no message
  48. ;;
  49. ;; Revision 1.2 2000/02/27 00:42:11 hurdler
  50. ;; fix CR+LF problem
  51. ;;
  52. ;; Revision 1.1.1.1 2000/02/22 20:32:32 hurdler
  53. ;; Initial import into CVS (v1.29 pr3)
  54. ;;
  55. ;;
  56. ;; DESCRIPTION:
  57. ;; assembler optimised rendering code for software mode
  58. ;; draw floor spans, and wall columns.
  59. ;;
  60. ;;-----------------------------------------------------------------------------
  61. [BITS 32]
  62. %ifdef LINUX
  63. %macro cextern 1
  64. [extern %1]
  65. %endmacro
  66. %macro cglobal 1
  67. [global %1]
  68. %endmacro
  69. %define CODE_SEG .data
  70. %else
  71. %macro cextern 1
  72. %define %1 _%1
  73. [extern %1]
  74. %endmacro
  75. %macro cglobal 1
  76. %define %1 _%1
  77. [global %1]
  78. %endmacro
  79. %define CODE_SEG .text
  80. %endif
  81. ;; externs
  82. ;; columns
  83. cextern dc_x
  84. cextern dc_yl
  85. cextern dc_yh
  86. cextern ylookup
  87. cextern columnofs
  88. cextern dc_source
  89. cextern dc_texturemid
  90. cextern dc_iscale
  91. cextern centery
  92. cextern dc_colormap
  93. cextern dc_transmap
  94. cextern colormaps
  95. ;; spans
  96. cextern ds_x1
  97. cextern ds_x2
  98. cextern ds_y
  99. cextern ds_xfrac
  100. cextern ds_yfrac
  101. cextern ds_xstep
  102. cextern ds_ystep
  103. cextern ds_source
  104. cextern ds_colormap
  105. ;cextern ds_textureheight
  106. ; polygon edge rasterizer
  107. cextern prastertab
  108. ;;----------------------------------------------------------------------
  109. ;;
  110. ;; R_DrawColumn
  111. ;;
  112. ;; New optimised version 10-01-1998 by D.Fabrice and P.Boris
  113. ;; TO DO: optimise it much farther... should take at most 3 cycles/pix
  114. ;; once it's fixed, add code to patch the offsets so that it
  115. ;; works in every screen width.
  116. ;;
  117. ;;----------------------------------------------------------------------
  118. [SECTION .data]
  119. ;;.align 4
  120. loopcount dd 0
  121. pixelcount dd 0
  122. tystep dd 0
  123. [SECTION CODE_SEG write]
  124. ;----------------------------------------------------------------------------
  125. ;fixed_t FixedMul (fixed_t a, fixed_t b)
  126. ;----------------------------------------------------------------------------
  127. cglobal FixedMul
  128. ; align 16
  129. FixedMul:
  130. mov eax,[esp+4]
  131. imul dword [esp+8]
  132. shrd eax,edx,16
  133. ret
  134. ;----------------------------------------------------------------------------
  135. ;fixed_t FixedDiv2 (fixed_t a, fixed_t b);
  136. ;----------------------------------------------------------------------------
  137. cglobal FixedDiv2
  138. ; align 16
  139. FixedDiv2:
  140. mov eax,[esp+4]
  141. mov edx,eax ;; these two instructions allow the next
  142. sar edx,31 ;; two to pair, on the Pentium processor.
  143. shld edx,eax,16
  144. sal eax,16
  145. idiv dword [esp+8]
  146. ret
  147. ;----------------------------------------------------------------------------
  148. ; void ASM_PatchRowBytes (int rowbytes);
  149. ;----------------------------------------------------------------------------
  150. cglobal ASM_PatchRowBytes
  151. ; align 16
  152. ASM_PatchRowBytes:
  153. mov eax,[esp+4]
  154. mov [p1+2],eax
  155. mov [p2+2],eax
  156. mov [p3+2],eax
  157. mov [p4+2],eax
  158. mov [p5+2],eax
  159. mov [p6+2],eax
  160. mov [p7+2],eax
  161. mov [p8+2],eax
  162. mov [p9+2],eax
  163. mov [pa+2],eax
  164. mov [pb+2],eax
  165. mov [pc+2],eax
  166. mov [pd+2],eax
  167. mov [pe+2],eax
  168. mov [pf+2],eax
  169. mov [pg+2],eax
  170. mov [ph+2],eax
  171. mov [pi+2],eax
  172. mov [pj+2],eax
  173. mov [pk+2],eax
  174. mov [pl+2],eax
  175. mov [pm+2],eax
  176. mov [pn+2],eax
  177. mov [po+2],eax
  178. mov [pp+2],eax
  179. mov [pq+2],eax
  180. add eax,eax
  181. mov [q1+2],eax
  182. mov [q2+2],eax
  183. mov [q3+2],eax
  184. mov [q4+2],eax
  185. mov [q5+2],eax
  186. mov [q6+2],eax
  187. mov [q7+2],eax
  188. mov [q8+2],eax
  189. ret
  190. ;----------------------------------------------------------------------------
  191. ; 8bpp column drawer
  192. ;----------------------------------------------------------------------------
  193. cglobal R_DrawColumn_8
  194. ; align 16
  195. R_DrawColumn_8:
  196. push ebp ;; preserve caller's stack frame pointer
  197. push esi ;; preserve register variables
  198. push edi
  199. push ebx
  200. ;;
  201. ;; dest = ylookup[dc_yl] + columnofs[dc_x];
  202. ;;
  203. mov ebp,[dc_yl]
  204. mov ebx,ebp
  205. mov edi,[ylookup+ebx*4]
  206. mov ebx,[dc_x]
  207. add edi,[columnofs+ebx*4] ;; edi = dest
  208. ;;
  209. ;; pixelcount = yh - yl + 1
  210. ;;
  211. mov eax,[dc_yh]
  212. inc eax
  213. sub eax,ebp ;; pixel count
  214. mov [pixelcount],eax ;; save for final pixel
  215. jle near vdone ;; nothing to scale
  216. ;;
  217. ;; frac = dc_texturemid - (centery-dc_yl)*fracstep;
  218. ;;
  219. mov ecx,[dc_iscale] ;; fracstep
  220. mov eax,[centery]
  221. sub eax,ebp
  222. imul eax,ecx
  223. mov edx,[dc_texturemid]
  224. sub edx,eax
  225. mov ebx,edx
  226. shr ebx,16 ;; frac int.
  227. and ebx,0x7f
  228. shl edx,16 ;; y frac up
  229. mov ebp,ecx
  230. shl ebp,16 ;; fracstep f. up
  231. shr ecx,16 ;; fracstep i. ->cl
  232. and cl,0x7f
  233. mov esi,[dc_source]
  234. ;;
  235. ;; lets rock :) !
  236. ;;
  237. mov eax,[pixelcount]
  238. mov dh,al
  239. shr eax,2
  240. mov ch,al ;; quad count
  241. mov eax,[dc_colormap]
  242. test dh,0x3
  243. je near v4quadloop
  244. ;;
  245. ;; do un-even pixel
  246. ;;
  247. test dh,0x1
  248. je two_uneven
  249. mov al,[esi+ebx] ;; prep un-even loops
  250. add edx,ebp ;; ypos f += ystep f
  251. adc bl,cl ;; ypos i += ystep i
  252. mov dl,[eax] ;; colormap texel
  253. and bl,0x7f ;; mask 0-127 texture index
  254. mov [edi],dl ;; output pixel
  255. p1: add edi,0x12345678
  256. ;;
  257. ;; do two non-quad-aligned pixels
  258. ;;
  259. two_uneven:
  260. test dh,0x2
  261. je f3
  262. mov al,[esi+ebx] ;; fetch source texel
  263. add edx,ebp ;; ypos f += ystep f
  264. adc bl,cl ;; ypos i += ystep i
  265. mov dl,[eax] ;; colormap texel
  266. and bl,0x7f ;; mask 0-127 texture index
  267. mov [edi],dl ;; output pixel
  268. mov al,[esi+ebx]
  269. add edx,ebp ;; fetch source texel
  270. adc bl,cl ;; ypos f += ystep f
  271. mov dl,[eax] ;; ypos i += ystep i
  272. and bl,0x7f ;; colormap texel
  273. p2: add edi,0x12345678 ;; mask 0-127 texture index
  274. mov [edi],dl
  275. p3: add edi,0x12345678 ;; output pixel
  276. ;;
  277. ;; test if there was at least 4 pixels
  278. ;;
  279. f3:
  280. test ch,0xff ;; test quad count
  281. je near vdone
  282. ;;
  283. ;; ebp : ystep frac. upper 16 bits
  284. ;; edx : y frac. upper 16 bits
  285. ;; ebx : y i. lower 7 bits, masked for index
  286. ;; ecx : ch = counter, cl = y step i.
  287. ;; eax : colormap aligned 256
  288. ;; esi : source texture column
  289. ;; edi : dest screen
  290. ;;
  291. v4quadloop:
  292. mov dh,0x7f ;; prep mask
  293. align 4
  294. vquadloop:
  295. mov al,[esi+ebx] ;; prep loop
  296. add edx,ebp ;; ypos f += ystep f
  297. adc bl,cl ;; ypos i += ystep i
  298. mov dl,[eax] ;; colormap texel
  299. mov [edi],dl ;; output pixel
  300. and bl,0x7f ;; mask 0-127 texture index
  301. mov al,[esi+ebx] ;; fetch source texel
  302. add edx,ebp
  303. adc bl,cl
  304. p4: add edi,0x12345678
  305. mov dl,[eax]
  306. and bl,0x7f
  307. mov [edi],dl
  308. mov al,[esi+ebx] ;; fetch source texel
  309. add edx,ebp
  310. adc bl,cl
  311. p5: add edi,0x12345678
  312. mov dl,[eax]
  313. and bl,0x7f
  314. mov [edi],dl
  315. mov al,[esi+ebx] ;; fetch source texel
  316. add edx,ebp
  317. adc bl,cl
  318. p6: add edi,0x12345678
  319. mov dl,[eax]
  320. and bl,0x7f
  321. mov [edi],dl
  322. p7: add edi,0x12345678
  323. dec ch
  324. jne vquadloop
  325. vdone:
  326. pop ebx ;; restore register variables
  327. pop edi
  328. pop esi
  329. pop ebp ;; restore caller's stack frame pointer
  330. ret
  331. ;;----------------------------------------------------------------------
  332. ;;13-02-98:
  333. ;; R_DrawSkyColumn : same as R_DrawColumn but:
  334. ;;
  335. ;; - wrap around 256 instead of 127.
  336. ;; this is needed because we have a higher texture for mouselook,
  337. ;; we need at least 200 lines for the sky.
  338. ;;
  339. ;; NOTE: the sky should never wrap, so it could use a faster method.
  340. ;; for the moment, we'll still use a wrapping method...
  341. ;;
  342. ;; IT S JUST A QUICK CUT N PASTE, WAS NOT OPTIMISED AS IT SHOULD BE !!!
  343. ;;
  344. ;;----------------------------------------------------------------------
  345. cglobal R_DrawSkyColumn_8
  346. ; align 16
  347. R_DrawSkyColumn_8:
  348. push ebp
  349. push esi
  350. push edi
  351. push ebx
  352. ;;
  353. ;; dest = ylookup[dc_yl] + columnofs[dc_x];
  354. ;;
  355. mov ebp,[dc_yl]
  356. mov ebx,ebp
  357. mov edi,[ylookup+ebx*4]
  358. mov ebx,[dc_x]
  359. add edi,[columnofs+ebx*4] ;; edi = dest
  360. ;;
  361. ;; pixelcount = yh - yl + 1
  362. ;;
  363. mov eax,[dc_yh]
  364. inc eax
  365. sub eax,ebp ;; pixel count
  366. mov [pixelcount],eax ;; save for final pixel
  367. jle near vskydone ;; nothing to scale
  368. ;;
  369. ;; frac = dc_texturemid - (centery-dc_yl)*fracstep;
  370. ;;
  371. mov ecx,[dc_iscale] ;; fracstep
  372. mov eax,[centery]
  373. sub eax,ebp
  374. imul eax,ecx
  375. mov edx,[dc_texturemid]
  376. sub edx,eax
  377. mov ebx,edx
  378. shr ebx,16 ;; frac int.
  379. and ebx,0xff
  380. shl edx,16 ;; y frac up
  381. mov ebp,ecx
  382. shl ebp,16 ;; fracstep f. up
  383. shr ecx,16 ;; fracstep i. ->cl
  384. mov esi,[dc_source]
  385. ;;
  386. ;; lets rock :) !
  387. ;;
  388. mov eax,[pixelcount]
  389. mov dh,al
  390. shr eax,0x2
  391. mov ch,al ;; quad count
  392. mov eax,[dc_colormap]
  393. test dh,0x3
  394. je vskyquadloop
  395. ;;
  396. ;; do un-even pixel
  397. ;;
  398. test dh,0x1
  399. je f2
  400. mov al,[esi+ebx] ;; prep un-even loops
  401. add edx,ebp ;; ypos f += ystep f
  402. adc bl,cl ;; ypos i += ystep i
  403. mov dl,[eax] ;; colormap texel
  404. mov [edi],dl ;; output pixel
  405. p8: add edi,0x12345678
  406. ;;
  407. ;; do two non-quad-aligned pixels
  408. ;;
  409. f2: test dh,0x2
  410. je skyf3
  411. mov al,[esi+ebx] ;; fetch source texel
  412. add edx,ebp ;; ypos f += ystep f
  413. adc bl,cl ;; ypos i += ystep i
  414. mov dl,[eax] ;; colormap texel
  415. mov [edi],dl ;; output pixel
  416. mov al,[esi+ebx] ;; fetch source texel
  417. add edx,ebp ;; ypos f += ystep f
  418. adc bl,cl ;; ypos i += ystep i
  419. mov dl,[eax] ;; colormap texel
  420. p9: add edi,0x12345678
  421. mov [edi],dl ;; output pixel
  422. pa: add edi,0x12345678
  423. ;;
  424. ;; test if there was at least 4 pixels
  425. ;;
  426. skyf3: test ch,0xff ;; test quad count
  427. je vskydone
  428. ;;
  429. ;; ebp : ystep frac. upper 24 bits
  430. ;; edx : y frac. upper 24 bits
  431. ;; ebx : y i. lower 7 bits, masked for index
  432. ;; ecx : ch = counter, cl = y step i.
  433. ;; eax : colormap aligned 256
  434. ;; esi : source texture column
  435. ;; edi : dest screen
  436. ;;
  437. align 4
  438. vskyquadloop:
  439. mov al,[esi+ebx] ;; prep loop
  440. add edx,ebp ;; ypos f += ystep f
  441. mov dl,[eax] ;; colormap texel
  442. adc bl,cl ;; ypos i += ystep i
  443. mov [edi],dl ;; output pixel
  444. mov al,[esi+ebx] ;; fetch source texel
  445. add edx,ebp
  446. adc bl,cl
  447. pb: add edi,0x12345678
  448. mov dl,[eax]
  449. mov [edi],dl
  450. mov al,[esi+ebx] ;; fetch source texel
  451. add edx,ebp
  452. adc bl,cl
  453. pc: add edi,0x12345678
  454. mov dl,[eax]
  455. mov [edi],dl
  456. mov al,[esi+ebx] ;; fetch source texel
  457. add edx,ebp
  458. adc bl,cl
  459. pd: add edi,0x12345678
  460. mov dl,[eax]
  461. mov [edi],dl
  462. pe: add edi,0x12345678
  463. dec ch
  464. jne vskyquadloop
  465. vskydone:
  466. pop ebx
  467. pop edi
  468. pop esi
  469. pop ebp
  470. ret
  471. ;;----------------------------------------------------------------------
  472. ;; R_DrawTranslucentColumn_8
  473. ;;
  474. ;; Vertical column texture drawer, with transparency. Replaces Doom2's
  475. ;; 'fuzz' effect, which was not so beautiful.
  476. ;; Transparency is always impressive in some way, don't know why...
  477. ;;----------------------------------------------------------------------
  478. cglobal R_DrawTranslucentColumn_8
  479. R_DrawTranslucentColumn_8:
  480. push ebp ;; preserve caller's stack frame pointer
  481. push esi ;; preserve register variables
  482. push edi
  483. push ebx
  484. ;;
  485. ;; dest = ylookup[dc_yl] + columnofs[dc_x];
  486. ;;
  487. mov ebp,[dc_yl]
  488. mov ebx,ebp
  489. mov edi,[ylookup+ebx*4]
  490. mov ebx,[dc_x]
  491. add edi,[columnofs+ebx*4] ;; edi = dest
  492. ;;
  493. ;; pixelcount = yh - yl + 1
  494. ;;
  495. mov eax,[dc_yh]
  496. inc eax
  497. sub eax,ebp ;; pixel count
  498. mov [pixelcount],eax ;; save for final pixel
  499. jle near vtdone ;; nothing to scale
  500. ;;
  501. ;; frac = dc_texturemid - (centery-dc_yl)*fracstep;
  502. ;;
  503. mov ecx,[dc_iscale] ;; fracstep
  504. mov eax,[centery]
  505. sub eax,ebp
  506. imul eax,ecx
  507. mov edx,[dc_texturemid]
  508. sub edx,eax
  509. mov ebx,edx
  510. shr ebx,16 ;; frac int.
  511. and ebx,0x7f
  512. shl edx,16 ;; y frac up
  513. mov ebp,ecx
  514. shl ebp,16 ;; fracstep f. up
  515. shr ecx,16 ;; fracstep i. ->cl
  516. and cl,0x7f
  517. push cx
  518. mov ecx,edx
  519. pop cx
  520. mov edx,[dc_colormap]
  521. mov esi,[dc_source]
  522. ;;
  523. ;; lets rock :) !
  524. ;;
  525. mov eax,[pixelcount]
  526. shr eax,0x2
  527. test byte [pixelcount],0x3
  528. mov ch,al ;; quad count
  529. mov eax,[dc_transmap]
  530. je vt4quadloop
  531. ;;
  532. ;; do un-even pixel
  533. ;;
  534. test byte [pixelcount],0x1
  535. je trf2
  536. mov ah,[esi+ebx] ;; fetch texel : colormap number
  537. add ecx,ebp
  538. adc bl,cl
  539. mov al,[edi] ;; fetch dest : index into colormap
  540. and bl,0x7f
  541. mov dl,[eax]
  542. mov dl,[edx]
  543. mov [edi],dl
  544. pf: add edi,0x12345678
  545. ;;
  546. ;; do two non-quad-aligned pixels
  547. ;;
  548. trf2: test byte [pixelcount],0x2
  549. je trf3
  550. mov ah,[esi+ebx] ;; fetch texel : colormap number
  551. add ecx,ebp
  552. adc bl,cl
  553. mov al,[edi] ;; fetch dest : index into colormap
  554. and bl,0x7f
  555. mov dl,[eax]
  556. mov dl,[edx]
  557. mov [edi],dl
  558. pg: add edi,0x12345678
  559. mov ah,[esi+ebx] ;; fetch texel : colormap number
  560. add ecx,ebp
  561. adc bl,cl
  562. mov al,[edi] ;; fetch dest : index into colormap
  563. and bl,0x7f
  564. mov dl,[eax]
  565. mov dl,[edx]
  566. mov [edi],dl
  567. ph: add edi,0x12345678
  568. ;;
  569. ;; test if there was at least 4 pixels
  570. ;;
  571. trf3: test ch,0xff ;; test quad count
  572. je near vtdone
  573. ;;
  574. ;; ebp : ystep frac. upper 24 bits
  575. ;; edx : y frac. upper 24 bits
  576. ;; ebx : y i. lower 7 bits, masked for index
  577. ;; ecx : ch = counter, cl = y step i.
  578. ;; eax : colormap aligned 256
  579. ;; esi : source texture column
  580. ;; edi : dest screen
  581. ;;
  582. vt4quadloop:
  583. mov ah,[esi+ebx] ;; fetch texel : colormap number
  584. mov [tystep],ebp
  585. pi: add edi,0x12345678
  586. mov al,[edi] ;; fetch dest : index into colormap
  587. pj: sub edi,0x12345678
  588. mov ebp,edi
  589. pk: sub edi,0x12345678
  590. jmp short inloop
  591. align 4
  592. vtquadloop:
  593. add ecx,[tystep]
  594. adc bl,cl
  595. q1: add ebp,0x23456789
  596. and bl,0x7f
  597. mov dl,[eax]
  598. mov ah,[esi+ebx] ;; fetch texel : colormap number
  599. mov dl,[edx]
  600. mov [edi],dl
  601. mov al,[ebp] ;; fetch dest : index into colormap
  602. inloop:
  603. add ecx,[tystep]
  604. adc bl,cl
  605. q2: add edi,0x23456789
  606. and bl,0x7f
  607. mov dl,[eax]
  608. mov ah,[esi+ebx] ;; fetch texel : colormap number
  609. mov dl,[edx]
  610. mov [ebp+0x0],dl
  611. mov al,[edi] ;; fetch dest : index into colormap
  612. add ecx,[tystep]
  613. adc bl,cl
  614. q3: add ebp,0x23456789
  615. and bl,0x7f
  616. mov dl,[eax]
  617. mov ah,[esi+ebx] ;; fetch texel : colormap number
  618. mov dl,[edx]
  619. mov [edi],dl
  620. mov al,[ebp] ;; fetch dest : index into colormap
  621. add ecx,[tystep]
  622. adc bl,cl
  623. q4: add edi,0x23456789
  624. and bl,0x7f
  625. mov dl,[eax]
  626. mov ah,[esi+ebx] ;; fetch texel : colormap number
  627. mov dl,[edx]
  628. mov [ebp],dl
  629. mov al,[edi] ;; fetch dest : index into colormap
  630. dec ch
  631. jne vtquadloop
  632. vtdone:
  633. pop ebx
  634. pop edi
  635. pop esi
  636. pop ebp
  637. ret
  638. ;;----------------------------------------------------------------------
  639. ;; R_DrawShadeColumn
  640. ;;
  641. ;; for smoke..etc.. test.
  642. ;;----------------------------------------------------------------------
  643. cglobal R_DrawShadeColumn_8
  644. R_DrawShadeColumn_8:
  645. push ebp ;; preserve caller's stack frame pointer
  646. push esi ;; preserve register variables
  647. push edi
  648. push ebx
  649. ;;
  650. ;; dest = ylookup[dc_yl] + columnofs[dc_x];
  651. ;;
  652. mov ebp,[dc_yl]
  653. mov ebx,ebp
  654. mov edi,[ylookup+ebx*4]
  655. mov ebx,[dc_x]
  656. add edi,[columnofs+ebx*4] ;; edi = dest
  657. ;;
  658. ;; pixelcount = yh - yl + 1
  659. ;;
  660. mov eax,[dc_yh]
  661. inc eax
  662. sub eax,ebp ;; pixel count
  663. mov [pixelcount],eax ;; save for final pixel
  664. jle near shdone ;; nothing to scale
  665. ;;
  666. ;; frac = dc_texturemid - (centery-dc_yl)*fracstep;
  667. ;;
  668. mov ecx,[dc_iscale] ;; fracstep
  669. mov eax,[centery]
  670. sub eax,ebp
  671. imul eax,ecx
  672. mov edx,[dc_texturemid]
  673. sub edx,eax
  674. mov ebx,edx
  675. shr ebx,16 ;; frac int.
  676. and ebx,byte +0x7f
  677. shl edx,16 ;; y frac up
  678. mov ebp,ecx
  679. shl ebp,16 ;; fracstep f. up
  680. shr ecx,16 ;; fracstep i. ->cl
  681. and cl,0x7f
  682. mov esi,[dc_source]
  683. ;;
  684. ;; lets rock :) !
  685. ;;
  686. mov eax,[pixelcount]
  687. mov dh,al
  688. shr eax,2
  689. mov ch,al ;; quad count
  690. mov eax,[colormaps]
  691. test dh,3
  692. je sh4quadloop
  693. ;;
  694. ;; do un-even pixel
  695. ;;
  696. test dh,0x1
  697. je shf2
  698. mov ah,[esi+ebx] ;; fetch texel : colormap number
  699. add edx,ebp
  700. adc bl,cl
  701. mov al,[edi] ;; fetch dest : index into colormap
  702. and bl,0x7f
  703. mov dl,[eax]
  704. mov [edi],dl
  705. pl: add edi,0x12345678
  706. ;;
  707. ;; do two non-quad-aligned pixels
  708. ;;
  709. shf2:
  710. test dh,0x2
  711. je shf3
  712. mov ah,[esi+ebx] ;; fetch texel : colormap number
  713. add edx,ebp
  714. adc bl,cl
  715. mov al,[edi] ;; fetch dest : index into colormap
  716. and bl,0x7f
  717. mov dl,[eax]
  718. mov [edi],dl
  719. pm: add edi,0x12345678
  720. mov ah,[esi+ebx] ;; fetch texel : colormap number
  721. add edx,ebp
  722. adc bl,cl
  723. mov al,[edi] ;; fetch dest : index into colormap
  724. and bl,0x7f
  725. mov dl,[eax]
  726. mov [edi],dl
  727. pn: add edi,0x12345678
  728. ;;
  729. ;; test if there was at least 4 pixels
  730. ;;
  731. shf3:
  732. test ch,0xff ;; test quad count
  733. je near shdone
  734. ;;
  735. ;; ebp : ystep frac. upper 24 bits
  736. ;; edx : y frac. upper 24 bits
  737. ;; ebx : y i. lower 7 bits, masked for index
  738. ;; ecx : ch = counter, cl = y step i.
  739. ;; eax : colormap aligned 256
  740. ;; esi : source texture column
  741. ;; edi : dest screen
  742. ;;
  743. sh4quadloop:
  744. mov dh,0x7f ;; prep mask
  745. mov ah,[esi+ebx] ;; fetch texel : colormap number
  746. mov [tystep],ebp
  747. po: add edi,0x12345678
  748. mov al,[edi] ;; fetch dest : index into colormap
  749. pp: sub edi,0x12345678
  750. mov ebp,edi
  751. pq: sub edi,0x12345678
  752. jmp short shinloop
  753. align 4
  754. shquadloop:
  755. add edx,[tystep]
  756. adc bl,cl
  757. and bl,dh
  758. q5: add ebp,0x12345678
  759. mov dl,[eax]
  760. mov ah,[esi+ebx] ;; fetch texel : colormap number
  761. mov [edi],dl
  762. mov al,[ebp] ;; fetch dest : index into colormap
  763. shinloop:
  764. add edx,[tystep]
  765. adc bl,cl
  766. and bl,dh
  767. q6: add edi,0x12345678
  768. mov dl,[eax]
  769. mov ah,[esi+ebx] ;; fetch texel : colormap number
  770. mov [ebp],dl
  771. mov al,[edi] ;; fetch dest : index into colormap
  772. add edx,[tystep]
  773. adc bl,cl
  774. and bl,dh
  775. q7: add ebp,0x12345678
  776. mov dl,[eax]
  777. mov ah,[esi+ebx] ;; fetch texel : colormap number
  778. mov [edi],dl
  779. mov al,[ebp] ;; fetch dest : index into colormap
  780. add edx,[tystep]
  781. adc bl,cl
  782. and bl,dh
  783. q8: add edi,0x12345678
  784. mov dl,[eax]
  785. mov ah,[esi+ebx] ;; fetch texel : colormap number
  786. mov [ebp],dl
  787. mov al,[edi] ;; fetch dest : index into colormap
  788. dec ch
  789. jne shquadloop
  790. shdone:
  791. pop ebx ;; restore register variables
  792. pop edi
  793. pop esi
  794. pop ebp ;; restore caller's stack frame pointer
  795. ret
  796. ;;----------------------------------------------------------------------
  797. ;;
  798. ;; R_DrawSpan
  799. ;;
  800. ;; Horizontal texture mapping
  801. ;;
  802. ;;----------------------------------------------------------------------
  803. [SECTION .data]
  804. oldcolormap dd 0
  805. [SECTION CODE_SEG write]
  806. cglobal R_DrawSpan_8
  807. R_DrawSpan_8:
  808. push ebp ;; preserve caller's stack frame pointer
  809. push esi ;; preserve register variables
  810. push edi
  811. push ebx
  812. ;;
  813. ;; initilise registers
  814. ;;
  815. mov edx, [ds_xfrac]
  816. mov eax, [ds_ystep]
  817. ror edx, 14
  818. ror eax, 15
  819. mov bl, dl
  820. mov ecx, [ds_xstep]
  821. mov dh, al
  822. mov ax, 1
  823. mov [tystep], eax
  824. mov eax, [ds_yfrac]
  825. ror ecx, 13
  826. ror eax, 16
  827. mov dl, cl
  828. mov bh, al
  829. xor cx, cx
  830. and ebx, 0x3fff
  831. mov [pixelcount],ecx
  832. mov ecx, [ds_x2]
  833. mov edi, [ds_y]
  834. mov esi, [ds_x1]
  835. mov edi, [ylookup+edi*4]
  836. mov ebp, ebx
  837. add edi, [columnofs+esi*4]
  838. sub esi, ecx ;; pixel count
  839. shr ebp, 2
  840. mov ecx, [ds_colormap]
  841. mov ax, si
  842. mov esi, [ds_source]
  843. sar ax,1
  844. jnc near .midloop ;; check parity
  845. ; summary
  846. ; edx = high16bit xfrac[0..13], ah=ystep[16..24] al=xtep[14..21]
  847. ; ebx = high16bit =0, bh=yfrac[16..24], bl=xfrac[14..21]
  848. ; ecx = colormap table cl=0 (colormap is aligned 8 bits)
  849. ; eax = high16bit yfrac[0..15], dx = count
  850. ; esi = flat texture source
  851. ; edi = screeen buffer destination
  852. ; ebp = work register
  853. ; pixelcount = high16bit xstep[0..13] rest to 0
  854. ; tystep = high16bit ystep[0..15] low 16 bit = 2 (increment of count)
  855. align 4
  856. .loop
  857. add eax, [tystep]
  858. mov cl, [esi+ebp]
  859. adc bh, dh
  860. mov cl, [ecx]
  861. and bh, 0x3f
  862. mov [edi], cl
  863. mov ebp, ebx
  864. inc edi
  865. shr ebp, 2
  866. .midloop:
  867. add edx, [pixelcount]
  868. mov cl, [esi+ebp]
  869. adc bl, dl
  870. mov cl, [ecx]
  871. mov ebp, ebx
  872. mov [edi], cl
  873. inc edi
  874. shr ebp, 2
  875. test eax, 0xffff
  876. jnz near .loop
  877. .hdone: pop ebx ;; restore register variables
  878. pop edi
  879. pop esi
  880. pop ebp ;; restore caller's stack frame pointer
  881. ret
  882. [SECTION .data]
  883. obelix dd 0
  884. etaussi dd 0
  885. [SECTION CODE_SEG]
  886. cglobal R_DrawSpan_8_old
  887. R_DrawSpan_8_old:
  888. push ebp ;; preserve caller's stack frame pointer
  889. push esi ;; preserve register variables
  890. push edi
  891. push ebx
  892. ;;
  893. ;; find loop count
  894. ;;
  895. mov eax,[ds_x2]
  896. inc eax
  897. sub eax,[ds_x1] ;; pixel count
  898. mov [pixelcount],eax ;; save for final pixel
  899. js near .hdone ;; nothing to scale
  900. shr eax,0x1 ;; double pixel count
  901. mov [loopcount],eax
  902. ;;
  903. ;; build composite position
  904. ;;
  905. mov ebp,[ds_xfrac]
  906. shl ebp,10
  907. and ebp,0xffff0000
  908. mov eax,[ds_yfrac]
  909. shr eax,6
  910. and eax,0xffff
  911. mov edi,[ds_y]
  912. or ebp,eax
  913. mov esi,[ds_source]
  914. ;;
  915. ;; calculate screen dest
  916. ;;
  917. mov edi,[ylookup+edi*4]
  918. mov eax,[ds_x1]
  919. add edi,[columnofs+eax*4]
  920. ;;
  921. ;; build composite step
  922. ;;
  923. mov ebx,[ds_xstep]
  924. shl ebx,10
  925. and ebx,0xffff0000
  926. mov eax,[ds_ystep]
  927. shr eax,6
  928. and eax,0xffff
  929. or ebx,eax
  930. mov [obelix],ebx
  931. mov [etaussi],esi
  932. ;; %eax aligned colormap
  933. ;; %ebx aligned colormap
  934. ;; %ecx,%edx scratch
  935. ;; %esi virtual source
  936. ;; %edi moving destination pointer
  937. ;; %ebp frac
  938. mov eax,[ds_colormap]
  939. mov ecx,ebp
  940. add ebp,ebx ;; advance frac pointer
  941. shr cx,10
  942. rol ecx,6
  943. and ecx,4095 ;; finish calculation for third pixel
  944. mov edx,ebp
  945. shr dx,10
  946. rol edx,6
  947. add ebp,ebx ;; advance frac pointer
  948. and edx,4095 ;; finish calculation for fourth pixel
  949. mov ebx,eax
  950. mov al,[esi+ecx] ;; get first pixel
  951. mov bl,[esi+edx] ;; get second pixel
  952. test dword [pixelcount],0xfffffffe
  953. mov dl,[eax] ;; color translate first pixel
  954. ;; movw $0xf0f0,%dx ;;see visplanes start
  955. je .hchecklast
  956. mov dh,[ebx] ;; color translate second pixel
  957. mov esi,[loopcount]
  958. align 4
  959. .hdoubleloop:
  960. mov ecx,ebp
  961. shr cx,10
  962. rol ecx,6
  963. add ebp,[obelix] ;; advance frac pointer
  964. mov [edi],dx ;; write first pixel
  965. and ecx,4095 ;; finish calculation for third pixel
  966. mov edx,ebp
  967. shr dx,10
  968. rol edx,6
  969. add ecx,[etaussi]
  970. and edx,4095 ;; finish calculation for fourth pixel
  971. mov al,[ecx] ;; get third pixel
  972. add ebp,[obelix] ;; advance frac pointer
  973. add edx,[etaussi]
  974. mov bl,[edx] ;; get fourth pixel
  975. mov dl,[eax] ;; color translate third pixel
  976. add edi,byte +0x2 ;; advance to third pixel destination
  977. dec esi ;; done with loop?
  978. mov dh,[ebx] ;; color translate fourth pixel
  979. jne .hdoubleloop
  980. ;; check for final pixel
  981. .hchecklast:
  982. test dword [pixelcount],0x1
  983. je .hdone
  984. mov [edi],dl ;; write final pixel
  985. .hdone: pop ebx ;; restore register variables
  986. pop edi
  987. pop esi
  988. pop ebp ;; restore caller's stack frame pointer
  989. ret
  990. ;; ========================================================================
  991. ;; Rasterization des segments d'un polyg“ne textur‚ de maniŠre LINEAIRE.
  992. ;; Il s'agit donc d'interpoler les coordonn‚es aux bords de la texture en
  993. ;; mˆme temps que les abscisses minx/maxx pour chaque ligne.
  994. ;; L'argument 'dir' indique quels bords de la texture sont interpolés:
  995. ;; 0 : segments associ‚s aux bord SUPERIEUR et INFERIEUR ( TY constant )
  996. ;; 1 : segments associ‚s aux bord GAUCHE et DROITE ( TX constant )
  997. ;; ========================================================================
  998. ;;
  999. ;; void rasterize_segment_tex( LONG x1, LONG y1, LONG x2, LONG y2, LONG tv1, LONG tv2, LONG tc, LONG dir );
  1000. ;; ARG1 ARG2 ARG3 ARG4 ARG5 ARG6 ARG7 ARG8
  1001. ;;
  1002. ;; Pour dir = 0, (tv1,tv2) = (tX1,tX2), tc = tY, en effet TY est constant.
  1003. ;;
  1004. ;; Pour dir = 1, (tv1,tv2) = (tY1,tY2), tc = tX, en effet TX est constant.
  1005. ;;
  1006. ;;
  1007. ;; Uses: extern struct rastery *_rastertab;
  1008. ;;
  1009. [SECTION CODE_SEG write]
  1010. MINX EQU 0
  1011. MAXX EQU 4
  1012. TX1 EQU 8
  1013. TY1 EQU 12
  1014. TX2 EQU 16
  1015. TY2 EQU 20
  1016. RASTERY_SIZEOF EQU 24
  1017. cglobal rasterize_segment_tex
  1018. rasterize_segment_tex:
  1019. push ebp
  1020. mov ebp,esp
  1021. sub esp,byte +0x8 ;; alloue les variables locales
  1022. push ebx
  1023. push esi
  1024. push edi
  1025. o16 mov ax,es
  1026. push eax
  1027. ;; #define DX [ebp-4]
  1028. ;; #define TD [ebp-8]
  1029. mov eax,[ebp+0xc] ;; y1
  1030. mov ebx,[ebp+0x14] ;; y2
  1031. cmp ebx,eax
  1032. je near .L_finished ;; special (y1==y2) segment horizontal, exit!
  1033. jg near .L_rasterize_right
  1034. ;;rasterize_left: ;; on rasterize un segment … la GAUCHE du polyg“ne
  1035. mov ecx,eax
  1036. sub ecx,ebx
  1037. inc ecx ;; y1-y2+1
  1038. mov eax,RASTERY_SIZEOF
  1039. mul ebx ;; * y2
  1040. mov esi,[prastertab]
  1041. add esi,eax ;; point into rastertab[y2]
  1042. mov eax,[ebp+0x8] ;; ARG1
  1043. sub eax,[ebp+0x10] ;; ARG3
  1044. shl eax,0x10 ;; ((x1-x2)<<PRE) ...
  1045. cdq
  1046. idiv ecx ;; dx = ... / (y1-y2+1)
  1047. mov [ebp-0x4],eax ;; DX
  1048. mov eax,[ebp+0x18] ;; ARG5
  1049. sub eax,[ebp+0x1c] ;; ARG6
  1050. shl eax,0x10
  1051. cdq
  1052. idiv ecx ;; tdx =((tx1-tx2)<<PRE) / (y1-y2+1)
  1053. mov [ebp-0x8],eax ;; idem tdy =((ty1-ty2)<<PRE) / (y1-y2+1)
  1054. mov eax,[ebp+0x10] ;; ARG3
  1055. shl eax,0x10 ;; x = x2<<PRE
  1056. mov ebx,[ebp+0x1c] ;; ARG6
  1057. shl ebx,0x10 ;; tx = tx2<<PRE d0
  1058. ;; ty = ty2<<PRE d1
  1059. mov edx,[ebp+0x20] ;; ARG7
  1060. shl edx,0x10 ;; ty = ty<<PRE d0
  1061. ;; tx = tx<<PRE d1
  1062. push ebp
  1063. mov edi,[ebp-0x4] ;; DX
  1064. cmp dword [ebp+0x24],byte +0x0 ;; ARG8 direction ?
  1065. mov ebp,[ebp-0x8] ;; TD
  1066. je .L_rleft_h_loop
  1067. ;;
  1068. ;; TY varie, TX est constant
  1069. ;;
  1070. .L_rleft_v_loop:
  1071. mov [esi+MINX],eax ;; rastertab[y].minx = x
  1072. add ebx,ebp
  1073. mov [esi+TX1],edx ;; .tx1 = tx
  1074. add eax,edi
  1075. mov [esi+TY1],ebx ;; .ty1 = ty
  1076. ;;addl DX, %eax // x += dx
  1077. ;;addl TD, %ebx // ty += tdy
  1078. add esi,RASTERY_SIZEOF ;; next raster line into rastertab[]
  1079. dec ecx
  1080. jne .L_rleft_v_loop
  1081. pop ebp
  1082. jmp .L_finished
  1083. ;;
  1084. ;; TX varie, TY est constant
  1085. ;;
  1086. .L_rleft_h_loop:
  1087. mov [esi+MINX],eax ;; rastertab[y].minx = x
  1088. add eax,edi
  1089. mov [esi+TX1],ebx ;; .tx1 = tx
  1090. add ebx,ebp
  1091. mov [esi+TY1],edx ;; .ty1 = ty
  1092. ;;addl DX, %eax // x += dx
  1093. ;;addl TD, %ebx // tx += tdx
  1094. add esi,RASTERY_SIZEOF ;; next raster line into rastertab[]
  1095. dec ecx
  1096. jne .L_rleft_h_loop
  1097. pop ebp
  1098. jmp .L_finished
  1099. ;;
  1100. ;; on rasterize un segment … la DROITE du polyg“ne
  1101. ;;
  1102. .L_rasterize_right:
  1103. mov ecx,ebx
  1104. sub ecx,eax
  1105. inc ecx ;; y2-y1+1
  1106. mov ebx,RASTERY_SIZEOF
  1107. mul ebx ;; * y1
  1108. mov esi,[prastertab]
  1109. add esi,eax ;; point into rastertab[y1]
  1110. mov eax,[ebp+0x10] ;; ARG3
  1111. sub eax,[ebp+0x8] ;; ARG1
  1112. shl eax,0x10 ;; ((x2-x1)<<PRE) ...
  1113. cdq
  1114. idiv ecx ;; dx = ... / (y2-y1+1)
  1115. mov [ebp-0x4],eax ;; DX
  1116. mov eax,[ebp+0x1c] ;; ARG6
  1117. sub eax,[ebp+0x18] ;; ARG5
  1118. shl eax,0x10
  1119. cdq
  1120. idiv ecx ;; tdx =((tx2-tx1)<<PRE) / (y2-y1+1)
  1121. mov [ebp-0x8],eax ;; idem tdy =((ty2-ty1)<<PRE) / (y2-y1+1)
  1122. mov eax,[ebp+0x8] ;; ARG1
  1123. shl eax,0x10 ;; x = x1<<PRE
  1124. mov ebx,[ebp+0x18] ;; ARG5
  1125. shl ebx,0x10 ;; tx = tx1<<PRE d0
  1126. ;; ty = ty1<<PRE d1
  1127. mov edx,[ebp+0x20] ;; ARG7
  1128. shl edx,0x10 ;; ty = ty<<PRE d0
  1129. ;; tx = tx<<PRE d1
  1130. push ebp
  1131. mov edi,[ebp-0x4] ;; DX
  1132. cmp dword [ebp+0x24], 0 ;; direction ?
  1133. mov ebp,[ebp-0x8] ;; TD
  1134. je .L_rright_h_loop
  1135. ;;
  1136. ;; TY varie, TX est constant
  1137. ;;
  1138. .L_rright_v_loop:
  1139. mov [esi+MAXX],eax ;; rastertab[y].maxx = x
  1140. add ebx,ebp
  1141. mov [esi+TX2],edx ;; .tx2 = tx
  1142. add eax,edi
  1143. mov [esi+TY2],ebx ;; .ty2 = ty
  1144. ;;addl DX, %eax // x += dx
  1145. ;;addl TD, %ebx // ty += tdy
  1146. add esi,RASTERY_SIZEOF
  1147. dec ecx
  1148. jne .L_rright_v_loop
  1149. pop ebp
  1150. jmp short .L_finished
  1151. ;;
  1152. ;; TX varie, TY est constant
  1153. ;;
  1154. .L_rright_h_loop:
  1155. mov [esi+MAXX],eax ;; rastertab[y].maxx = x
  1156. add eax,edi
  1157. mov [esi+TX2],ebx ;; .tx2 = tx
  1158. add ebx,ebp
  1159. mov [esi+TY2],edx ;; .ty2 = ty
  1160. ;;addl DX, %eax // x += dx
  1161. ;;addl TD, %ebx // tx += tdx
  1162. add esi,RASTERY_SIZEOF
  1163. dec ecx
  1164. jne .L_rright_h_loop
  1165. pop ebp
  1166. .L_finished:
  1167. pop eax
  1168. o16 mov es,ax
  1169. pop edi
  1170. pop esi
  1171. pop ebx
  1172. mov esp,ebp
  1173. pop ebp
  1174. ret
  1175. ;;; this version can draw 64x64 tiles, but they would have to be arranged 4 per row,
  1176. ;; so that the stride from one line to the next is 256
  1177. ;;
  1178. ;; .data
  1179. ;;xstep dd 0
  1180. ;;ystep dd 0
  1181. ;;texwidth dd 64 ;; texture width
  1182. ;; .text
  1183. ;; this code is kept in case we add high-detail floor textures for example (256x256)
  1184. ; align 16
  1185. ;_R_DrawSpan_8:
  1186. ; push ebp ;; preserve caller's stack frame pointer
  1187. ; push esi ;; preserve register variables
  1188. ; push edi
  1189. ; push ebx
  1190. ;;
  1191. ;; find loop count
  1192. ;;
  1193. ; mov eax,[ds_x2]
  1194. ; inc eax
  1195. ; sub eax,[ds_x1] ;; pixel count
  1196. ; mov [pixelcount],eax ;; save for final pixel
  1197. ; js near .hdone ;; nothing to scale
  1198. ;;
  1199. ;; calculate screen dest
  1200. ;;
  1201. ; mov edi,[ds_y]
  1202. ; mov edi,[ylookup+edi*4]
  1203. ; mov eax,[ds_x1]
  1204. ; add edi,[columnofs+eax*4]
  1205. ;;
  1206. ;; prepare registers for inner loop
  1207. ;;
  1208. ; xor eax,eax
  1209. ; mov edx,[ds_xfrac]
  1210. ; ror edx,16
  1211. ; mov al,dl
  1212. ; mov ecx,[ds_yfrac]
  1213. ; ror ecx,16
  1214. ; mov ah,cl
  1215. ;
  1216. ; mov ebx,[ds_xstep]
  1217. ; ror ebx,16
  1218. ; mov ch,bl
  1219. ; and ebx,0xffff0000
  1220. ; mov [xstep],ebx
  1221. ; mov ebx,[ds_ystep]
  1222. ; ror ebx,16
  1223. ; mov dh,bl
  1224. ; and ebx,0xffff0000
  1225. ; mov [ystep],ebx
  1226. ;
  1227. ; mov esi,[ds_source]
  1228. ;
  1229. ;;; %eax Yi,Xi in %ah,%al
  1230. ;;; %ebx aligned colormap
  1231. ;;; %ecx Yfrac upper, dXi in %ch, %cl is counter (upto 1024pels, =4x256)
  1232. ;;; %edx Xfrac upper, dYi in %dh, %dl receives mapped pixels from (ebx)
  1233. ;;; ystep dYfrac, add to %ecx, low word is 0
  1234. ;;; xstep dXfrac, add to %edx, low word is 0
  1235. ;;; %ebp temporary register serves as offset like %eax
  1236. ;;; %esi virtual source
  1237. ;;; %edi moving destination pointer
  1238. ;
  1239. ; mov ebx,[pixelcount]
  1240. ; shr ebx,0x2 ;; 4 pixels per loop
  1241. ; test bl,0xff
  1242. ; je near .hchecklast
  1243. ; mov cl,bl
  1244. ;
  1245. ; mov ebx,[dc_colormap]
  1246. ;;;
  1247. ;;; prepare loop with first pixel
  1248. ;;;
  1249. ; add ecx,[ystep] ;;pr‚a1
  1250. ; adc ah,dh
  1251. ; add edx,[xstep]
  1252. ; adc al,ch
  1253. ; and eax,0x3f3f
  1254. ; mov bl,[esi+eax] ;;pr‚b1
  1255. ; mov dl,[ebx] ;;pr‚c1
  1256. ;
  1257. ; add ecx,[ystep] ;;a2
  1258. ; adc ah,dh
  1259. ;
  1260. ;.hdoubleloop:
  1261. ; mov [edi+1],dl
  1262. ; add edx,[xstep]
  1263. ; adc al,ch
  1264. ; add edi,byte +0x2
  1265. ; mov ebp,eax
  1266. ; add ecx,[ystep]
  1267. ; adc ah,dh
  1268. ; and ebp,0x3f3f
  1269. ; add edx,[xstep]
  1270. ; mov bl,[esi+ebp]
  1271. ; adc al,ch
  1272. ; mov dl,[ebx]
  1273. ; and eax,0x3f3f
  1274. ; mov [edi],dl
  1275. ; mov bl,[esi+eax]
  1276. ; add ecx,[ystep]
  1277. ; adc ah,dh
  1278. ; add edx,[xstep]
  1279. ; adc al,ch
  1280. ; mov dl,[ebx]
  1281. ; mov ebp,eax
  1282. ; mov [edi+1],dl
  1283. ; and ebp,0x3f3f
  1284. ; add ecx,[ystep]
  1285. ; adc ah,dh
  1286. ; mov bl,[esi+ebp]
  1287. ; add edi,byte +0x2
  1288. ; add edx,[xstep]
  1289. ; adc al,ch
  1290. ; mov dl,[ebx]
  1291. ; and eax,0x3f3f
  1292. ; mov [edi],dl
  1293. ; mov bl,[esi+eax]
  1294. ; add ecx,[ystep]
  1295. ; adc ah,dh
  1296. ; mov dl,[ebx]
  1297. ; dec cl
  1298. ; jne near .hdoubleloop
  1299. ;;; check for final pixel
  1300. ;.hchecklast:
  1301. ;;; to do
  1302. ;.hdone:
  1303. ; pop ebx
  1304. ; pop edi
  1305. ; pop esi
  1306. ; pop ebp
  1307. ; ret