TMAP_FL1.ASM 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. ;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  2. ;SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  3. ;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  4. ;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  5. ;IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  6. ;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  7. ;FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  8. ;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  9. ;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  10. ;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  11. ;
  12. ; $Source: f:/miner/source/texmap/rcs/tmap_fl1.asm $
  13. ; $Revision: 1.6 $
  14. ; $Author: john $
  15. ; $Date: 1995/02/20 18:22:08 $
  16. ;
  17. ; Pseudo-flat shader. Renders nothing for transparent, color #1 otherwise.
  18. ;
  19. ; $Log: tmap_fl1.asm $
  20. ; Revision 1.6 1995/02/20 18:22:08 john
  21. ; Put all the externs in the assembly modules into tmap_inc.asm.
  22. ; Also, moved all the C versions of the inner loops into a new module,
  23. ; scanline.c.
  24. ;
  25. ; Revision 1.5 1994/12/04 20:37:11 mike
  26. ; fix bug caused by changed interface.
  27. ;
  28. ; Revision 1.4 1994/11/12 16:39:34 mike
  29. ; jae to ja.
  30. ;
  31. ; Revision 1.3 1994/05/03 11:08:48 mike
  32. ; who knows...
  33. ;
  34. ; Revision 1.2 1994/04/21 15:04:08 mike
  35. ; Write the whole darn thing.
  36. ;
  37. ; Revision 1.1 1994/04/21 13:50:26 mike
  38. ; Initial revision
  39. ;
  40. ;
  41. .386
  42. public asm_tmap_scanline_matt_
  43. include tmap_inc.asm
  44. _DATA segment dword public USE32 'DATA'
  45. align 4
  46. _loop_count dd ?
  47. zonk equ 1
  48. xonk equ 01010101h
  49. ;---------- local variables
  50. align 4
  51. req_base dd ?
  52. req_size dd ?
  53. U0 dd ?
  54. U1 dd ?
  55. V0 dd ?
  56. V1 dd ?
  57. num_left_over dd ?
  58. DU1 dd ?
  59. DV1 dd ?
  60. DZ1 dd ?
  61. ;**_fx_dl_dx1 dd ?
  62. ;**_fx_dl_dx2 dd ?
  63. rcsid db "$Id: tmap_fl1.asm 1.6 1995/02/20 18:22:08 john Exp $"
  64. align 4
  65. _DATA ends
  66. _TEXT segment dword public USE32 'CODE'
  67. ASSUME DS:_DATA
  68. ASSUME CS:_TEXT
  69. ; --------------------------------------------------------------------------------------------------
  70. ; Enter:
  71. ; _xleft fixed point left x coordinate
  72. ; _xright fixed point right x coordinate
  73. ; _y fixed point y coordinate
  74. ; _pixptr address of source pixel map
  75. ; _u fixed point initial u coordinate
  76. ; _v fixed point initial v coordinate
  77. ; _z fixed point initial z coordinate
  78. ; _du_dx fixed point du/dx
  79. ; _dv_dx fixed point dv/dx
  80. ; _dz_dx fixed point dz/dx
  81. ; for (x = (int) xleft; x <= (int) xright; x++) {
  82. ; _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
  83. ; _setpixel(x,y);
  84. ;
  85. ; u += du_dx;
  86. ; v += dv_dx;
  87. ; z += dz_dx;
  88. ; }
  89. asm_tmap_scanline_matt_:
  90. push es
  91. push fs
  92. pusha
  93. ;---------------------------- setup for loop ---------------------------------
  94. ; Setup for loop: _loop_count iterations = (int) xright - (int) xleft
  95. ; esi source pixel pointer = pixptr
  96. ; edi initial row pointer = y*320+x
  97. ; set esi = pointer to start of texture map data
  98. mov es, _pixel_data_selector ; selector[0*2]
  99. mov fs, _gr_fade_table_selector ; selector[1*2] ; fs = bmd_fade_table
  100. ; set edi = address of first pixel to modify
  101. mov edi, _fx_y
  102. mov edi, _y_pointers[edi*4]
  103. mov ebx, _fx_xleft
  104. add edi, write_buffer
  105. add edi, ebx
  106. ; set _loop_count = # of iterations
  107. mov eax,_fx_xright
  108. sub eax,ebx
  109. js _none_to_do
  110. mov _loop_count,eax
  111. ;-------------------------- setup for dithering -----------------------------
  112. ; lighting values are passed in fixed point, but need to be in 8 bit integer, 8 bit fraction so we can easily
  113. ; get the integer by reading %bh
  114. sar _fx_l, 8
  115. sar _fx_dl_dx,8
  116. jns dl_dx_ok
  117. inc _fx_dl_dx ; round towards 0 for negative deltas
  118. dl_dx_ok:
  119. ; set initial values
  120. mov ebx,_fx_u
  121. mov ebp,_fx_v
  122. mov ecx,_fx_z
  123. test _per2_flag,-1
  124. je tmap_loop
  125. cmp _Lighting_on, 0
  126. je tmap_loop_fast_nolight
  127. jmp tmap_loop_fast
  128. ;================ PERSPECTIVE TEXTURE MAP INNER LOOPS ========================
  129. ;
  130. ; Usage in loop: eax division, pixel value
  131. ; ebx u
  132. ; ecx z
  133. ; edx division
  134. ; ebp v
  135. ; esi source pixel pointer
  136. ; edi destination pixel pointer
  137. ;-------------------- NORMAL PERSPECTIVE TEXTURE MAP LOOP -----------------
  138. align 4
  139. tmap_loop:
  140. xchg ebx, esi
  141. ; compute v coordinate
  142. mov eax,ebp ; get v
  143. cdq
  144. idiv ecx ; eax = (v/z)
  145. and eax,3fh ; mask with height-1
  146. mov ebx,eax
  147. ; compute u coordinate
  148. mov eax,esi ; get u
  149. cdq
  150. idiv ecx ; eax = (u/z)
  151. shl eax,26
  152. shld ebx,eax,6 ; esi = v*64+u
  153. ; read 1 pixel
  154. movzx eax,byte ptr es:[ebx] ; get pixel from source bitmap
  155. ;** cmp _Lighting_on, 0
  156. ;** je NoLight1
  157. ;**
  158. ;**; LIGHTING CODE
  159. ;** mov ebx, _fx_l ; get temp copy of lighting value
  160. ;** mov ah, bh ; get lighting level
  161. ;** add ebx, _fx_dl_dx ; update lighting value
  162. ;** mov al, fs:[eax] ; xlat pixel thru lighting tables
  163. ;** mov _fx_l, ebx ; save temp copy of lighting value
  164. ; transparency check
  165. NoLight1: cmp al,255
  166. je skip1
  167. mov byte ptr [edi],zonk
  168. skip1: inc edi
  169. ; update deltas
  170. add ebp,_fx_dv_dx
  171. add esi,_fx_du_dx
  172. add ecx,_fx_dz_dx
  173. je _div_0_abort ; would be dividing by 0, so abort
  174. xchg esi, ebx
  175. dec _loop_count
  176. jns tmap_loop
  177. _none_to_do:
  178. popa
  179. pop fs
  180. pop es
  181. ret
  182. ; We detected a z=0 condition, which seems pretty bogus, don't you think?
  183. ; So, we abort, but maybe we want to know about it.
  184. _div_0_abort:
  185. int 3
  186. jmp _none_to_do
  187. ;-------------------------- PER/4 TMAPPER ----------------
  188. ;
  189. ; x = x1
  190. ; U0 = u/w; V0 = v/w;
  191. ; while ( 1 )
  192. ; u += du_dx*4; v+= dv_dx*4
  193. ; U1 = u/w; V1 = v/w;
  194. ; DUDX = (U1-U0)/4; DVDX = (V1-V0)/4;
  195. ;
  196. ; ; Pixel 0
  197. ; pixels = texmap[V0*64+U0];
  198. ; U0 += DUDX; V0 += DVDX
  199. ; ; Pixel 1
  200. ; pixels = (pixels<<8)+texmap[V0*64+U0];
  201. ; U0 += DUDX; V0 += DVDX
  202. ; ; Pixel 2
  203. ; pixels = (pixels<<8)+texmap[V0*64+U0];
  204. ; U0 += DUDX; V0 += DVDX
  205. ; ; Pixel 3
  206. ; pixels = (pixels<<8)+texmap[V0*64+U0];
  207. ;
  208. ; screen[x] = pixel
  209. ; x += 4;
  210. ; U0 = U1; V0 = V1
  211. NBITS = 3
  212. ZSHIFT = 3
  213. PDIV MACRO
  214. ; Returns EAX/ECX in 16.16 format in EAX. Trashes EDX
  215. ; sig bits 6.3
  216. ;--old-- cdq
  217. ;--old-- shld edx,eax, ZSHIFT
  218. ;--old-- lea eax, [eax*8]
  219. ;--old-- idiv ecx ; eax = (v/z)
  220. ;--old-- shl eax, 16-ZSHIFT
  221. mov edx,eax
  222. shl eax,ZSHIFT
  223. sar edx,32-ZSHIFT
  224. idiv ecx ; eax = (v/z)
  225. shl eax, 16-ZSHIFT
  226. ENDM
  227. wr_onepix macro num
  228. local skip
  229. cmp cl,255
  230. je skip
  231. mov byte ptr num[edi],zonk
  232. ror ecx,8
  233. skip:
  234. endm
  235. ; -------------------------------------- Start of Getting Dword Aligned ----------------------------------------------
  236. ; ebx fx_u
  237. tmap_loop_fast:
  238. mov esi,ebx
  239. align 4
  240. NotDwordAligned1:
  241. test edi, 11b
  242. jz DwordAligned1
  243. ; compute v coordinate
  244. mov eax,ebp ; get v
  245. cdq
  246. idiv ecx ; eax = (v/z)
  247. and eax,3fh ; mask with height-1
  248. mov ebx,eax
  249. ; compute u coordinate
  250. mov eax,esi ; get u
  251. cdq
  252. idiv ecx ; eax = (u/z)
  253. shl eax,26
  254. shld ebx,eax,6 ; esi = v*64+u
  255. ; read 1 pixel
  256. movzx eax,byte ptr es:[ebx] ; get pixel from source bitmap
  257. ;**; lighting code
  258. ;** mov ebx, _fx_l ; get temp copy of lighting value
  259. ;** mov ah, bh ; get lighting level
  260. ;** add ebx, _fx_dl_dx ; update lighting value
  261. ;** mov _fx_l, ebx ; save temp copy of lighting value
  262. ;**
  263. ;**; transparency check
  264. ;** cmp al,255
  265. ;** je skip2 ; this pixel is transparent, so don't write it (or light it)
  266. ;**
  267. ;** mov al, fs:[eax] ; xlat pixel thru lighting tables
  268. ; write 1 pixel
  269. mov byte ptr [edi],zonk
  270. skip2: inc edi
  271. ; update deltas
  272. add ebp,_fx_dv_dx
  273. add esi,_fx_du_dx
  274. add ecx,_fx_dz_dx
  275. je _div_0_abort ; would be dividing by 0, so abort
  276. dec _loop_count
  277. jns NotDwordAligned1
  278. jmp _none_to_do
  279. ; -------------------------------------- End of Getting Dword Aligned ----------------------------------------------
  280. DwordAligned1:
  281. mov ebx,esi ; get fx_u
  282. mov eax, _loop_count
  283. inc eax
  284. mov num_left_over, eax
  285. shr eax, NBITS
  286. cmp eax, 0
  287. je tmap_loop
  288. mov _loop_count, eax ; _loop_count = pixels / NPIXS
  289. shl eax, 3
  290. sub num_left_over, eax ; num_left_over = obvious
  291. ; compute initial v coordinate
  292. mov eax,ebp ; get v
  293. PDIV
  294. mov V0, eax
  295. ; compute initial u coordinate
  296. mov eax,ebx ; get u
  297. PDIV
  298. mov U0, eax
  299. ; Set deltas to NPIXS pixel increments
  300. mov eax, _fx_du_dx
  301. shl eax, 3
  302. mov DU1, eax
  303. mov eax, _fx_dv_dx
  304. shl eax, 3
  305. mov DV1, eax
  306. mov eax, _fx_dz_dx
  307. shl eax, 3
  308. mov DZ1, eax
  309. align 4
  310. TopOfLoop4:
  311. add ebx, DU1
  312. add ebp, DV1
  313. add ecx, DZ1
  314. je _div_0_abort ; would be dividing by 0, so abort
  315. ; Done with ebx, ebp, ecx until next iteration
  316. push ebx
  317. push ecx
  318. push ebp
  319. push edi
  320. ; Find fixed U1
  321. mov eax, ebx
  322. PDIV
  323. mov ebx, eax ; ebx = U1 until pop's
  324. ; Find fixed V1
  325. mov eax, ebp
  326. PDIV
  327. mov ebp, eax ; ebp = V1 until pop's
  328. mov ecx, U0 ; ecx = U0 until pop's
  329. mov edi, V0 ; edi = V0 until pop's
  330. ; Make ESI = V0:U0 in 6:10,6:10 format
  331. mov eax, ecx
  332. shr eax, 6
  333. mov esi, edi
  334. shl esi, 10
  335. mov si, ax
  336. ; Make EDX = DV:DU in 6:10,6:10 format
  337. mov eax, ebx
  338. sub eax, ecx
  339. sar eax, NBITS+6
  340. mov edx, ebp
  341. sub edx, edi
  342. shl edx, 10-NBITS ; EDX = V1-V0/ 4 in 6:10 int:frac
  343. mov dx, ax ; put delta u in low word
  344. ; Save the U1 and V1 so we don't have to divide on the next iteration
  345. mov U0, ebx
  346. mov V0, ebp
  347. pop edi ; Restore EDI before using it
  348. ; LIGHTING CODE
  349. mov ebx, _fx_l
  350. mov ebp, _fx_dl_dx
  351. test _transparency_on,-1
  352. je no_trans1
  353. REPT (1 SHL (NBITS-2))
  354. local skip3,no_trans1
  355. REPT 2
  356. local skipa1,skipa2
  357. mov eax, esi ; get u,v
  358. shr eax, 26 ; shift out all but int(v)
  359. shld ax,si,6 ; shift in u, shifting up v
  360. add esi, edx ; inc u,v
  361. mov al, es:[eax] ; get pixel from source bitmap
  362. cmp al,255
  363. je skipa1
  364. mov ah, bh ; form lighting table lookup value
  365. ;** add ebx, ebp ; update lighting value
  366. ;** mov al, fs:[eax] ; xlat thru lighting table into dest buffer
  367. mov byte ptr [edi],zonk
  368. skipa1:
  369. inc edi
  370. ; Do odd pixel
  371. mov eax, esi ; get u,v
  372. shr eax, 26 ; shift out all but int(v)
  373. shld ax,si,6 ; shift in u, shifting up v
  374. add esi, edx ; inc u,v
  375. mov al, es:[eax] ; get pixel from source bitmap
  376. cmp al,255
  377. je skipa2
  378. mov ah, bh ; form lighting table lookup value
  379. ;** add ebx, ebp ; update lighting value
  380. ;** mov al, fs:[eax] ; xlat thru lighting table into dest buffer
  381. mov byte ptr [edi],zonk
  382. skipa2:
  383. inc edi
  384. ENDM
  385. ENDM
  386. jmp cont1
  387. ; -------------------------------------------------------
  388. no_trans1:
  389. REPT (1 SHL (NBITS-2))
  390. local skip3
  391. REPT 2
  392. mov eax, esi ; get u,v
  393. shr eax, 26 ; shift out all but int(v)
  394. shld ax,si,6 ; shift in u, shifting up v
  395. add esi, edx ; inc u,v
  396. mov al, es:[eax] ; get pixel from source bitmap
  397. mov ah, bh ; form lighting table lookup value
  398. ;** add ebx, ebp ; update lighting value
  399. ;** mov cl, fs:[eax] ; xlat thru lighting table into dest buffer
  400. ; Do odd pixel
  401. mov eax, esi ; get u,v
  402. shr eax, 26 ; shift out all but int(v)
  403. shld ax,si,6 ; shift in u, shifting up v
  404. add esi, edx ; inc u,v
  405. mov al, es:[eax] ; get pixel from source bitmap
  406. mov ah, bh ; form lighting table lookup value
  407. ;** add ebx, ebp ; update lighting value
  408. ;** mov ch, fs:[eax] ; xlat thru lighting table into dest buffer
  409. ror ecx, 16 ; move to next double dest pixel position
  410. ENDM
  411. mov dword ptr [edi],xonk ; Draw 4 pixels to display
  412. skip3: add edi,4
  413. ENDM
  414. cont1:
  415. ; -------------------------------------------------------
  416. ; LIGHTING CODE
  417. mov _fx_l, ebx
  418. pop ebp
  419. pop ecx
  420. pop ebx
  421. dec _loop_count
  422. jnz TopOfLoop4
  423. EndOfLoop4:
  424. cmp num_left_over, 0
  425. je _none_to_do
  426. ; ----------------------------------------- Start of LeftOver Pixels ------------------------------------------
  427. DoEndPixels:
  428. add ebx, DU1
  429. add ebp, DV1
  430. add ecx, DZ1
  431. je _div_0_abort
  432. push edi ; use edi as a temporary variable
  433. cmp ecx,10
  434. jg ecx_ok
  435. mov ecx,10
  436. ecx_ok:
  437. ; Find fixed U1
  438. mov eax, ebx
  439. PDIV
  440. mov ebx, eax ; ebx = U1 until pop's
  441. ; Find fixed V1
  442. mov eax, ebp
  443. PDIV
  444. mov ebp, eax ; ebp = V1 until pop's
  445. mov ecx, U0 ; ecx = U0 until pop's
  446. mov edi, V0 ; edi = V0 until pop's
  447. ; Make ESI = V0:U0 in 6:10,6:10 format
  448. mov eax, ecx
  449. shr eax, 6
  450. mov esi, edi
  451. shl esi, 10
  452. mov si, ax
  453. ; Make EDX = DV:DU in 6:10,6:10 format
  454. mov eax, ebx
  455. sub eax, ecx
  456. sar eax, NBITS+6
  457. mov edx, ebp
  458. sub edx, edi
  459. shl edx, 10-NBITS ; EDX = V1-V0/ 4 in 6:10 int:frac
  460. mov dx, ax ; put delta u in low word
  461. pop edi ; Restore EDI before using it
  462. mov ecx, num_left_over
  463. ; LIGHTING CODE
  464. mov ebx, _fx_l
  465. mov ebp, _fx_dl_dx
  466. ITERATION = 0
  467. REPT (1 SHL (NBITS-1))
  468. local skip4, skip5
  469. ; Do even pixel
  470. mov eax, esi ; get u,v
  471. shr eax, 26 ; shift out all but int(v)
  472. shld ax,si,6 ; shift in u, shifting up v
  473. mov al, es:[eax] ; get pixel from source bitmap
  474. add esi, edx ; inc u,v
  475. mov ah, bh ; form lighting table lookup value
  476. add ebx, ebp ; update lighting value
  477. cmp al,255
  478. je skip4
  479. ;** mov al, fs:[eax] ; xlat thru lighting table into dest buffer
  480. mov byte ptr [edi+ITERATION], zonk ; write pixel
  481. skip4: dec ecx
  482. jz _none_to_do
  483. ITERATION = ITERATION + 1
  484. ; Do odd pixel
  485. mov eax, esi ; get u,v
  486. shr eax, 26 ; shift out all but int(v)
  487. shld ax,si,6 ; shift in u, shifting up v
  488. mov al, es:[eax] ; get pixel from source bitmap
  489. add esi, edx ; inc u,v
  490. mov ah, bh ; form lighting table lookup value
  491. add ebx, _fx_dl_dx ; update lighting value
  492. cmp al,255
  493. je skip5
  494. ;** mov al, fs:[eax] ; xlat thru lighting table into dest buffer
  495. mov byte ptr [edi+ITERATION], zonk ; write pixel
  496. skip5: dec ecx
  497. jz _none_to_do
  498. ITERATION = ITERATION + 1
  499. ENDM
  500. ; ----------------------------------------- End of LeftOver Pixels ------------------------------------------
  501. ; Should never get here!!!!
  502. int 3
  503. jmp _none_to_do
  504. ; ==================================================== No Lighting Code ======================================================
  505. tmap_loop_fast_nolight:
  506. mov esi,ebx
  507. align 4
  508. NotDwordAligned1_nolight:
  509. test edi, 11b
  510. jz DwordAligned1_nolight
  511. ; compute v coordinate
  512. mov eax,ebp ; get v
  513. cdq
  514. idiv ecx ; eax = (v/z)
  515. and eax,3fh ; mask with height-1
  516. mov ebx,eax
  517. ; compute u coordinate
  518. mov eax,esi ; get u
  519. cdq
  520. idiv ecx ; eax = (u/z)
  521. shl eax,26
  522. shld ebx,eax,6 ; esi = v*64+u
  523. ; read 1 pixel
  524. mov al,es:[ebx] ; get pixel from source bitmap
  525. ; write 1 pixel
  526. cmp al,255
  527. je skip6
  528. mov byte ptr [edi],zonk
  529. skip6: inc edi
  530. ; update deltas
  531. add ebp,_fx_dv_dx
  532. add esi,_fx_du_dx
  533. add ecx,_fx_dz_dx
  534. je _div_0_abort ; would be dividing by 0, so abort
  535. dec _loop_count
  536. jns NotDwordAligned1_nolight
  537. jmp _none_to_do
  538. DwordAligned1_nolight:
  539. mov ebx,esi
  540. mov eax, _loop_count
  541. inc eax
  542. mov num_left_over, eax
  543. shr eax, NBITS
  544. cmp eax, 0
  545. je tmap_loop
  546. mov _loop_count, eax ; _loop_count = pixels / NPIXS
  547. shl eax, NBITS
  548. sub num_left_over, eax ; num_left_over = obvious
  549. ; compute initial v coordinate
  550. mov eax,ebp ; get v
  551. PDIV
  552. mov V0, eax
  553. ; compute initial u coordinate
  554. mov eax,ebx ; get u
  555. PDIV
  556. mov U0, eax
  557. ; Set deltas to NPIXS pixel increments
  558. mov eax, _fx_du_dx
  559. shl eax, NBITS
  560. mov DU1, eax
  561. mov eax, _fx_dv_dx
  562. shl eax, NBITS
  563. mov DV1, eax
  564. mov eax, _fx_dz_dx
  565. shl eax, NBITS
  566. mov DZ1, eax
  567. align 4
  568. TopOfLoop4_nolight:
  569. add ebx, DU1
  570. add ebp, DV1
  571. add ecx, DZ1
  572. je _div_0_abort
  573. ; Done with ebx, ebp, ecx until next iteration
  574. push ebx
  575. push ecx
  576. push ebp
  577. push edi
  578. ; Find fixed U1
  579. mov eax, ebx
  580. PDIV
  581. mov ebx, eax ; ebx = U1 until pop's
  582. ; Find fixed V1
  583. mov eax, ebp
  584. PDIV
  585. mov ebp, eax ; ebp = V1 until pop's
  586. mov ecx, U0 ; ecx = U0 until pop's
  587. mov edi, V0 ; edi = V0 until pop's
  588. ; Make ESI = V0:U0 in 6:10,6:10 format
  589. mov eax, ecx
  590. shr eax, 6
  591. mov esi, edi
  592. shl esi, 10
  593. mov si, ax
  594. ; Make EDX = DV:DU in 6:10,6:10 format
  595. mov eax, ebx
  596. sub eax, ecx
  597. sar eax, NBITS+6
  598. mov edx, ebp
  599. sub edx, edi
  600. shl edx, 10-NBITS ; EDX = V1-V0/ 4 in 6:10 int:frac
  601. mov dx, ax ; put delta u in low word
  602. ; Save the U1 and V1 so we don't have to divide on the next iteration
  603. mov U0, ebx
  604. mov V0, ebp
  605. pop edi ; Restore EDI before using it
  606. REPT (1 SHL (NBITS-2))
  607. local skip7, no_trans2
  608. REPT 4
  609. ; Do 1 pixel
  610. mov eax, esi ; get u,v
  611. shr eax, 26 ; shift out all but int(v)
  612. shld ax,si,6 ; shift in u, shifting up v
  613. mov cl, es:[eax] ; load into buffer register
  614. add esi, edx ; inc u,v
  615. ror ecx, 8 ; move to next dest pixel
  616. ENDM
  617. test _transparency_on,-1
  618. je no_trans2
  619. cmp ecx,-1
  620. je skip7
  621. wr_onepix 0
  622. wr_onepix 1
  623. wr_onepix 2
  624. wr_onepix 3
  625. jmp skip7
  626. no_trans2:
  627. mov dword ptr [edi],xonk ; Draw 4 pixels to display
  628. skip7: add edi,4
  629. ENDM
  630. pop ebp
  631. pop ecx
  632. pop ebx
  633. dec _loop_count
  634. jnz TopOfLoop4_nolight
  635. EndOfLoop4_nolight:
  636. cmp num_left_over, 0
  637. je _none_to_do
  638. DoEndPixels_nolight:
  639. add ebx, DU1
  640. add ebp, DV1
  641. add ecx, DZ1
  642. je _div_0_abort
  643. push edi ; use edi as a temporary variable
  644. ; Find fixed U1
  645. mov eax, ebx
  646. PDIV
  647. mov ebx, eax ; ebx = U1 until pop's
  648. ; Find fixed V1
  649. mov eax, ebp
  650. PDIV
  651. mov ebp, eax ; ebp = V1 until pop's
  652. mov ecx, U0 ; ecx = U0 until pop's
  653. mov edi, V0 ; edi = V0 until pop's
  654. ; Make ESI = V0:U0 in 6:10,6:10 format
  655. mov eax, ecx
  656. shr eax, 6
  657. mov esi, edi
  658. shl esi, 10
  659. mov si, ax
  660. ; Make EDX = DV:DU in 6:10,6:10 format
  661. mov eax, ebx
  662. sub eax, ecx
  663. sar eax, NBITS+6
  664. mov edx, ebp
  665. sub edx, edi
  666. shl edx, 10-NBITS ; EDX = V1-V0/ 4 in 6:10 int:frac
  667. mov dx, ax ; put delta u in low word
  668. pop edi ; Restore EDI before using it
  669. mov ecx, num_left_over
  670. ITERATION = 0
  671. REPT (1 SHL NBITS)
  672. local skip8
  673. ; Do 1 pixel
  674. mov eax, esi ; get u,v
  675. shr eax, 26 ; shift out all but int(v)
  676. shld ax,si,6 ; shift in u, shifting up v
  677. mov al, es:[eax] ; load into buffer register
  678. add esi, edx ; inc u,v
  679. cmp al,255
  680. je skip8
  681. mov byte ptr [edi+ITERATION], zonk ; write pixel
  682. skip8: dec ecx
  683. jz _none_to_do
  684. ITERATION = ITERATION + 1
  685. ENDM
  686. ; Should never get here!!!!!
  687. int 3
  688. jmp _none_to_do
  689. _TEXT ends
  690. end
  691.