TMAP_P2.ASM 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  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_p2.asm $
  13. ; $Revision: 1.5 $
  14. ; $Author: mike $
  15. ; $Date: 1994/11/30 00:56:58 $
  16. ;
  17. ; Perspective texture mapper with scan doubling inner loop.
  18. ;
  19. ; $Log: tmap_p2.asm $
  20. ; Revision 1.5 1994/11/30 00:56:58 mike
  21. ; optimization.
  22. ;
  23. ; Revision 1.4 1994/11/12 16:41:07 mike
  24. ; jae -> ja.
  25. ;
  26. ; Revision 1.3 1994/03/14 15:44:42 mike
  27. ; streamline code.
  28. ;
  29. ; Revision 1.2 1994/01/14 14:02:02 mike
  30. ; *** empty log message ***
  31. ;
  32. ;
  33. .386
  34. public asm_tmap_scanline_per_doubled_
  35. include tmap_inc.asm
  36. extern _fx_l:dword
  37. extern _fx_dl_dx:dword
  38. extern _dither_intensity_lighting:dword
  39. extern _Lighting_on:dword,_per2_flag:dword
  40. _DATA SEGMENT DWORD PUBLIC USE32 'DATA'
  41. align 4
  42. extrn _pixel_data_selector:word, _gr_fade_table_selector:word
  43. extrn _fx_u:dword
  44. extrn _fx_v:dword
  45. extrn _fx_z:dword
  46. extrn _fx_du_dx:dword
  47. extrn _fx_dv_dx:dword
  48. extrn _fx_dz_dx:dword
  49. extrn _fx_y:dword
  50. extrn _fx_xleft:dword
  51. extrn _fx_xright:dword
  52. extrn _pixptr:dword
  53. extrn _x:dword
  54. extrn _loop_count:dword
  55. ; ----------^^ These are passed in by the C caller ^^----------
  56. ;---------- local variables
  57. align 4
  58. req_base dd ?
  59. req_size dd ?
  60. U0 dd ?
  61. U1 dd ?
  62. V0 dd ?
  63. V1 dd ?
  64. temp dd ?
  65. num_left_over dd ?
  66. DU1 dd ?
  67. DV1 dd ?
  68. DZ1 dd ?
  69. _fx_dl_dx1 dd ?
  70. _fx_dl_dx2 dd ?
  71. _DATA ENDS
  72. DGROUP GROUP _DATA
  73. wnr macro ofs, reg
  74. push edi
  75. add edi, _bytes_per_row
  76. mov ofs[edi], reg
  77. pop edi
  78. endm
  79. _TEXT SEGMENT PARA PUBLIC USE32 'CODE'
  80. ASSUME DS:_DATA
  81. ASSUME CS:_TEXT
  82. ; --------------------------------------------------------------------------------------------------
  83. ; Enter:
  84. ; _xleft fixed point left x coordinate
  85. ; _xright fixed point right x coordinate
  86. ; _y fixed point y coordinate
  87. ; _pixptr address of source pixel map
  88. ; _u fixed point initial u coordinate
  89. ; _v fixed point initial v coordinate
  90. ; _z fixed point initial z coordinate
  91. ; _du_dx fixed point du/dx
  92. ; _dv_dx fixed point dv/dx
  93. ; _dz_dx fixed point dz/dx
  94. ; for (x = (int) xleft; x <= (int) xright; x++) {
  95. ; _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
  96. ; _setpixel(x,y);
  97. ;
  98. ; u += du_dx;
  99. ; v += dv_dx;
  100. ; z += dz_dx;
  101. ; }
  102. TMAP_NORMAL MACRO
  103. LOCAL NoLight1,skip1
  104. xchg ebx, esi
  105. ; compute v coordinate
  106. mov eax,ebp ; get v
  107. cdq
  108. idiv ecx ; eax = (v/z)
  109. and eax,3fh ; mask with height-1
  110. mov ebx,eax
  111. ; compute u coordinate
  112. mov eax,esi ; get u
  113. cdq
  114. idiv ecx ; eax = (u/z)
  115. shl eax,26
  116. shld ebx,eax,6 ; esi = v*64+u
  117. ; read 1 pixel
  118. mov al,es:[ebx] ; get pixel from source bitmap
  119. cmp _Lighting_on, 0
  120. je NoLight1
  121. ;LIGHTING CODE
  122. mov ebx, _fx_l ; get temp copy of lighting value
  123. mov ah, bh ; get lighting level
  124. and eax, 0fffh
  125. add ebx, _fx_dl_dx1 ; update lighting value
  126. mov al, fs:[eax] ; xlat pixel thru lighting tables
  127. mov _fx_l, ebx ; save temp copy of lighting value
  128. ;DITHERING CODE
  129. mov ebx, _fx_dl_dx1
  130. xchg ebx, _fx_dl_dx2
  131. mov _fx_dl_dx1, ebx
  132. NoLight1:
  133. ; write 1 pixel
  134. cmp al,255
  135. je skip1
  136. mov [edi],al
  137. wnr 0, al
  138. skip1: inc edi
  139. ; update deltas
  140. add ebp,_fx_dv_dx
  141. add esi,_fx_du_dx
  142. add ecx,_fx_dz_dx
  143. xchg esi, ebx
  144. ENDM
  145. asm_tmap_scanline_per_doubled_:
  146. push es
  147. push fs
  148. pusha
  149. ;---------------------------- setup for loop ---------------------------------
  150. ; Setup for loop: _loop_count iterations = (int) xright - (int) xleft
  151. ; esi source pixel pointer = pixptr
  152. ; edi initial row pointer = y*320+x
  153. ; set esi = pointer to start of texture map data
  154. ;** mov esi,_pixptr
  155. mov es,_pixel_data_selector ; selector[0*2]
  156. mov fs,_gr_fade_table_selector ; selector[1*2] ; fs = bmd_fade_table
  157. ; set edi = address of first pixel to modify
  158. mov edi,_fx_y
  159. cmp edi,_window_bottom
  160. ja _none_to_do
  161. imul edi,_bytes_per_row
  162. mov eax,_fx_xleft
  163. sar eax,16
  164. jns eax_ok
  165. sub eax,eax
  166. eax_ok:
  167. add edi,eax
  168. add edi,write_buffer
  169. ; set _loop_count = # of iterations
  170. mov eax,_fx_xright
  171. sar eax,16
  172. cmp eax,_window_right
  173. jb eax_ok1
  174. mov eax,_window_right
  175. eax_ok1: cmp eax,_window_left
  176. ja eax_ok2
  177. mov eax,_window_left
  178. eax_ok2:
  179. mov ebx,_fx_xleft
  180. sar ebx,16
  181. sub eax,ebx
  182. js _none_to_do
  183. cmp eax,_window_width
  184. jbe _ok_to_do
  185. mov eax,_window_width
  186. _ok_to_do:
  187. mov _loop_count,eax
  188. ;-------------------------- setup for dithering -----------------------------
  189. ; lighting values are passed in fixed point, but need to be in 8 bit integer, 8 bit fraction so we can easily
  190. ; get the integer by reading %bh
  191. sar _fx_l, 8
  192. sar _fx_dl_dx,8
  193. jns dl_dx_ok
  194. inc _fx_dl_dx ; round towards 0 for negative deltas
  195. dl_dx_ok:
  196. ; do dithering, use lighting values which are .5 less than and .5 more than actual value
  197. mov ebx,80h ; assume dithering on
  198. test _dither_intensity_lighting,-1
  199. jne do_dither
  200. sub ebx,ebx ; no dithering
  201. do_dither:
  202. mov eax,_fx_dl_dx
  203. add eax,ebx ; add 1/2
  204. mov _fx_dl_dx1,eax
  205. sub eax,ebx
  206. sub eax,ebx
  207. mov _fx_dl_dx2,eax
  208. mov ebx,_fx_xleft
  209. shr ebx,16
  210. xor ebx,_fx_y
  211. and ebx,1
  212. jne dith_1
  213. xchg eax,_fx_dl_dx1
  214. dith_1: mov _fx_dl_dx2,eax
  215. ; set initial values
  216. mov ebx,_fx_u
  217. mov ebp,_fx_v
  218. mov ecx,_fx_z
  219. test _per2_flag,-1
  220. je tmap_loop
  221. cmp _Lighting_on, 0
  222. je tmap_loop_fast_nolight
  223. jmp tmap_loop_fast
  224. ;================ PERSPECTIVE TEXTURE MAP INNER LOOPS ========================
  225. ;
  226. ; Usage in loop: eax division, pixel value
  227. ; ebx u
  228. ; ecx z
  229. ; edx division
  230. ; ebp v
  231. ; esi source pixel pointer
  232. ; edi destination pixel pointer
  233. ;-------------------- NORMAL PERSPECTIVE TEXTURE MAP LOOP -----------------
  234. align 4
  235. tmap_loop:
  236. TMAP_NORMAL
  237. dec _loop_count
  238. jns tmap_loop
  239. align 4
  240. _none_to_do:
  241. popa
  242. pop fs
  243. pop es
  244. ret
  245. ;-------------------------- PER/4 TMAPPER ----------------
  246. ;
  247. ; x = x1
  248. ; U0 = u/w; V0 = v/w;
  249. ; while ( 1 )
  250. ; u += du_dx*4; v+= dv_dx*4
  251. ; U1 = u/w; V1 = v/w;
  252. ; DUDX = (U1-U0)/4; DVDX = (V1-V0)/4;
  253. ;
  254. ; ; Pixel 0
  255. ; pixels = texmap[V0*64+U0];
  256. ; U0 += DUDX; V0 += DVDX
  257. ; ; Pixel 1
  258. ; pixels = (pixels<<8)+texmap[V0*64+U0];
  259. ; U0 += DUDX; V0 += DVDX
  260. ; ; Pixel 2
  261. ; pixels = (pixels<<8)+texmap[V0*64+U0];
  262. ; U0 += DUDX; V0 += DVDX
  263. ; ; Pixel 3
  264. ; pixels = (pixels<<8)+texmap[V0*64+U0];
  265. ;
  266. ; screen[x] = pixel
  267. ; x += 4;
  268. ; U0 = U1; V0 = V1
  269. NBITS = 3
  270. ZSHIFT = 3
  271. PDIV MACRO
  272. ; Returns EAX/ECX in 16.16 format in EAX. Trashes EDX
  273. ; sig bits 6.3
  274. cdq
  275. shld edx,eax, ZSHIFT
  276. shl eax, ZSHIFT
  277. idiv ecx ; eax = (v/z)
  278. shl eax, 16-ZSHIFT
  279. ENDM
  280. tmap_loop_fast:
  281. align 4
  282. NotDwordAligned1:
  283. test edi, 11b
  284. jz DwordAligned1
  285. xchg ebx, esi
  286. ; compute v coordinate
  287. mov eax,ebp ; get v
  288. cdq
  289. idiv ecx ; eax = (v/z)
  290. and eax,3fh ; mask with height-1
  291. mov ebx,eax
  292. ; compute u coordinate
  293. mov eax,esi ; get u
  294. cdq
  295. idiv ecx ; eax = (u/z)
  296. shl eax,26
  297. shld ebx,eax,6 ; esi = v*64+u
  298. ; read 1 pixel
  299. mov al,es:[ebx] ; get pixel from source bitmap
  300. ;LIGHTING CODE
  301. mov ebx, _fx_l ; get temp copy of lighting value
  302. mov ah, bh ; get lighting level
  303. add ebx, _fx_dl_dx1 ; update lighting value
  304. and eax, 0fffh ; make sure no garbage in EAX
  305. mov al, fs:[eax] ; xlat pixel thru lighting tables
  306. mov _fx_l, ebx ; save temp copy of lighting value
  307. ;DITHERING CODE
  308. mov ebx, _fx_dl_dx1
  309. xchg ebx, _fx_dl_dx2
  310. mov _fx_dl_dx1, ebx
  311. ; write 1 pixel
  312. cmp al,255
  313. je skip2
  314. mov [edi],al
  315. wnr 0, al
  316. skip2: inc edi
  317. ; update deltas
  318. add ebp,_fx_dv_dx
  319. add esi,_fx_du_dx
  320. add ecx,_fx_dz_dx
  321. xchg esi, ebx
  322. dec _loop_count
  323. jns NotDwordAligned1
  324. jmp _none_to_do
  325. DwordAligned1:
  326. mov eax, _loop_count
  327. inc eax
  328. mov num_left_over, eax
  329. shr eax, NBITS
  330. cmp eax, 0
  331. je tmap_loop
  332. mov _loop_count, eax ; _loop_count = pixels / NPIXS
  333. lea eax, [eax*8]
  334. sub num_left_over, eax ; num_left_over = obvious
  335. ; compute initial v coordinate
  336. mov eax,ebp ; get v
  337. PDIV
  338. mov V0, eax
  339. ; compute initial u coordinate
  340. mov eax,ebx ; get u
  341. PDIV
  342. mov U0, eax
  343. ; Set deltas to NPIXS pixel increments
  344. mov eax, _fx_du_dx
  345. lea eax, [eax*8]
  346. mov DU1, eax
  347. mov eax, _fx_dv_dx
  348. lea eax, [eax*8]
  349. mov DV1, eax
  350. mov eax, _fx_dz_dx
  351. lea eax, [eax*8]
  352. mov DZ1, eax
  353. align 4
  354. TopOfLoop4:
  355. add ebx, DU1
  356. add ebp, DV1
  357. add ecx, DZ1
  358. ; Done with ebx, ebp, ecx until next iteration
  359. push ebx
  360. push ecx
  361. push ebp
  362. push edi
  363. ; Find fixed U1
  364. mov eax, ebx
  365. PDIV
  366. mov ebx, eax ; ebx = U1 until pop's
  367. ; Find fixed V1
  368. mov eax, ebp
  369. PDIV
  370. mov ebp, eax ; ebp = V1 until pop's
  371. mov ecx, U0 ; ecx = U0 until pop's
  372. mov edi, V0 ; edi = V0 until pop's
  373. ; Make ESI = V0:U0 in 6:10,6:10 format
  374. mov eax, ecx
  375. shr eax, 6
  376. mov esi, edi
  377. shl esi, 10
  378. mov si, ax
  379. ; Make EDX = DV:DU in 6:10,6:10 format
  380. mov eax, ebx
  381. sub eax, ecx
  382. sar eax, NBITS+6
  383. mov edx, ebp
  384. sub edx, edi
  385. shl edx, 10-NBITS ; EDX = V1-V0/ 4 in 6:10 int:frac
  386. mov dx, ax ; put delta u in low word
  387. ; Save the U1 and V1 so we don't have to divide on the next iteration
  388. mov U0, ebx
  389. mov V0, ebp
  390. pop edi ; Restore EDI before using it
  391. ; LIGHTING CODE
  392. mov ebx, _fx_l
  393. ;** mov ebp, _fx_dl_dx1
  394. mov ebp, _bytes_per_row
  395. REPT (1 SHL (NBITS-2))
  396. local skip3
  397. REPT 2
  398. ; Do even pixel
  399. ;-ORIGINAL- mov eax, esi ; get u,v
  400. ;-ORIGINAL- shr eax, 26 ; shift out all but int(v)
  401. ;-ORIGINAL- shld ax,si,6 ; shift in u, shifting up v
  402. ;-ORIGINAL- mov al, es:[eax] ; get pixel from source bitmap
  403. ;-ORIGINAL- add esi, edx ; inc u,v
  404. ;-ORIGINAL- mov ah, bh ; form lighting table lookup value
  405. ;-ORIGINAL- add ebx, _fx_dl_dx1 ; update lighting value
  406. ;-ORIGINAL- and eax, 0fffh ; SAFETY CHECK on lighting value
  407. ;-ORIGINAL- mov cl, fs:[eax] ; xlat thru lighting table into dest buffer
  408. ;-ORIGINAL- ror ecx, 8 ; move to next dest pixel position
  409. ;-ORIGINAL-
  410. ;-ORIGINAL-; Do odd pixel
  411. ;-ORIGINAL- mov eax, esi ; get u,v
  412. ;-ORIGINAL- shr eax, 26 ; shift out all but int(v)
  413. ;-ORIGINAL- shld ax,si,6 ; shift in u, shifting up v
  414. ;-ORIGINAL- mov al, es:[eax] ; get pixel from source bitmap
  415. ;-ORIGINAL- add esi, edx ; inc u,v
  416. ;-ORIGINAL- mov ah, bh ; form lighting table lookup value
  417. ;-ORIGINAL- add ebx, _fx_dl_dx2 ; update lighting value
  418. ;-ORIGINAL- and eax, 0fffh ; SAFETY CHECK on lighting value
  419. ;-ORIGINAL- mov cl, fs:[eax] ; xlat thru lighting table into dest buffer
  420. ;-ORIGINAL- ror ecx, 8 ; move to next dest pixel position
  421. mov eax, esi ; get u,v
  422. shr eax, 26 ; shift out all but int(v)
  423. shld ax,si,6 ; shift in u, shifting up v
  424. add esi, edx ; inc u,v
  425. mov al, es:[eax] ; get pixel from source bitmap
  426. mov ah, bh ; form lighting table lookup value
  427. and ah,0fh
  428. add ebx, _fx_dl_dx1 ; update lighting value
  429. mov cl, fs:[eax] ; xlat thru lighting table into dest buffer
  430. ; Do odd pixel
  431. mov eax, esi ; get u,v
  432. shr eax, 26 ; shift out all but int(v)
  433. shld ax,si,6 ; shift in u, shifting up v
  434. add esi, edx ; inc u,v
  435. mov al, es:[eax] ; get pixel from source bitmap
  436. mov ah, bh ; form lighting table lookup value
  437. and ah, 0fh
  438. add ebx, _fx_dl_dx2 ; update lighting value
  439. mov ch, fs:[eax] ; xlat thru lighting table into dest buffer
  440. ror ecx, 16 ; move to next double dest pixel position
  441. ENDM
  442. cmp ecx,-1
  443. je skip3
  444. mov [edi],ecx ; Draw 4 pixels to display
  445. mov [edi+ebp], ecx
  446. skip3: add edi,4
  447. ENDM
  448. ; LIGHTING CODE
  449. mov _fx_l, ebx
  450. pop ebp
  451. pop ecx
  452. pop ebx
  453. dec _loop_count
  454. jnz TopOfLoop4
  455. EndOfLoop4:
  456. cmp num_left_over, 0
  457. je _none_to_do
  458. DoEndPixels:
  459. add ebx, DU1
  460. add ebp, DV1
  461. add ecx, DZ1
  462. push edi ; use edi as a temporary variable
  463. ; Find fixed U1
  464. mov eax, ebx
  465. PDIV
  466. mov ebx, eax ; ebx = U1 until pop's
  467. ; Find fixed V1
  468. mov eax, ebp
  469. PDIV
  470. mov ebp, eax ; ebp = V1 until pop's
  471. mov ecx, U0 ; ecx = U0 until pop's
  472. mov edi, V0 ; edi = V0 until pop's
  473. ; Make ESI = V0:U0 in 6:10,6:10 format
  474. mov eax, ecx
  475. shr eax, 6
  476. mov esi, edi
  477. shl esi, 10
  478. mov si, ax
  479. ; Make EDX = DV:DU in 6:10,6:10 format
  480. mov eax, ebx
  481. sub eax, ecx
  482. sar eax, NBITS+6
  483. mov edx, ebp
  484. sub edx, edi
  485. shl edx, 10-NBITS ; EDX = V1-V0/ 4 in 6:10 int:frac
  486. mov dx, ax ; put delta u in low word
  487. pop edi ; Restore EDI before using it
  488. mov ecx, num_left_over
  489. ; LIGHTING CODE
  490. mov ebx, _fx_l
  491. ;** mov ebp, _fx_dl_dx1
  492. mov ebp, _bytes_per_row
  493. ITERATION = 0
  494. REPT (1 SHL (NBITS-1))
  495. local skip4,skip6
  496. ; Do even pixel
  497. mov eax, esi ; get u,v
  498. shr eax, 26 ; shift out all but int(v)
  499. shld ax,si,6 ; shift in u, shifting up v
  500. mov al, es:[eax] ; get pixel from source bitmap
  501. add esi, edx ; inc u,v
  502. mov ah, bh ; form lighting table lookup value
  503. add ebx, _fx_dl_dx1 ; update lighting value
  504. and ah,0fh
  505. mov al, fs:[eax] ; xlat thru lighting table into dest buffer
  506. cmp al,255
  507. je skip4
  508. mov [edi+ITERATION], al ; write pixel
  509. mov [edi+ebp+ITERATION], al
  510. skip4: dec ecx
  511. jz _none_to_do
  512. ITERATION = ITERATION + 1
  513. ; Do odd pixel
  514. mov eax, esi ; get u,v
  515. shr eax, 26 ; shift out all but int(v)
  516. shld ax,si,6 ; shift in u, shifting up v
  517. mov al, es:[eax] ; get pixel from source bitmap
  518. add esi, edx ; inc u,v
  519. mov ah, bh ; form lighting table lookup value
  520. add ebx, _fx_dl_dx2 ; update lighting value
  521. and ah, 0fh ; SAFETY CHECK on lighting value
  522. mov al, fs:[eax] ; xlat thru lighting table into dest buffer
  523. cmp al,255
  524. je skip6
  525. mov [edi+ITERATION], al ; write pixel
  526. mov [edi+ebp+ITERATION], al
  527. skip6: dec ecx
  528. jz _none_to_do
  529. ITERATION = ITERATION + 1
  530. ENDM
  531. ; Should never get here!!!!
  532. int 3
  533. jmp _none_to_do
  534. tmap_loop_fast_nolight:
  535. align 4
  536. NotDwordAligned1_nolight:
  537. test edi, 11b
  538. jz DwordAligned1_nolight
  539. xchg ebx, esi
  540. ; compute v coordinate
  541. mov eax,ebp ; get v
  542. cdq
  543. idiv ecx ; eax = (v/z)
  544. and eax,3fh ; mask with height-1
  545. mov ebx,eax
  546. ; compute u coordinate
  547. mov eax,esi ; get u
  548. cdq
  549. idiv ecx ; eax = (u/z)
  550. shl eax,26
  551. shld ebx,eax,6 ; esi = v*64+u
  552. ; read 1 pixel
  553. mov al,es:[ebx] ; get pixel from source bitmap
  554. ; write 1 pixel
  555. cmp al,255
  556. je skip7
  557. mov [edi],al
  558. mov edx,_bytes_per_row
  559. mov [edi+edx], al
  560. skip7: inc edi
  561. ; update deltas
  562. add ebp,_fx_dv_dx
  563. add esi,_fx_du_dx
  564. add ecx,_fx_dz_dx
  565. xchg esi, ebx
  566. dec _loop_count
  567. jns NotDwordAligned1_nolight
  568. jmp _none_to_do
  569. DwordAligned1_nolight:
  570. mov eax, _loop_count
  571. inc eax
  572. mov num_left_over, eax
  573. shr eax, NBITS
  574. cmp eax, 0
  575. je tmap_loop
  576. mov _loop_count, eax ; _loop_count = pixels / NPIXS
  577. ;OPshl eax, NBITS
  578. lea eax, [eax*8]
  579. sub num_left_over, eax ; num_left_over = obvious
  580. ; compute initial v coordinate
  581. mov eax,ebp ; get v
  582. PDIV
  583. mov V0, eax
  584. ; compute initial u coordinate
  585. mov eax,ebx ; get u
  586. PDIV
  587. mov U0, eax
  588. ; Set deltas to NPIXS pixel increments
  589. mov eax, _fx_du_dx
  590. ;OPshl eax, NBITS
  591. lea eax, [eax*8]
  592. mov DU1, eax
  593. mov eax, _fx_dv_dx
  594. ;OPshl eax, NBITS
  595. lea eax, [eax*8]
  596. mov DV1, eax
  597. mov eax, _fx_dz_dx
  598. ;OPshl eax, NBITS
  599. lea eax, [eax*8]
  600. mov DZ1, eax
  601. align 4
  602. TopOfLoop4_nolight:
  603. add ebx, DU1
  604. add ebp, DV1
  605. add ecx, DZ1
  606. ; Done with ebx, ebp, ecx until next iteration
  607. push ebx
  608. push ecx
  609. push ebp
  610. push edi
  611. ; Find fixed U1
  612. mov eax, ebx
  613. PDIV
  614. mov ebx, eax ; ebx = U1 until pop's
  615. ; Find fixed V1
  616. mov eax, ebp
  617. PDIV
  618. mov ebp, eax ; ebp = V1 until pop's
  619. mov ecx, U0 ; ecx = U0 until pop's
  620. mov edi, V0 ; edi = V0 until pop's
  621. ; Make ESI = V0:U0 in 6:10,6:10 format
  622. mov eax, ecx
  623. shr eax, 6
  624. mov esi, edi
  625. shl esi, 10
  626. mov si, ax
  627. ; Make EDX = DV:DU in 6:10,6:10 format
  628. mov eax, ebx
  629. sub eax, ecx
  630. sar eax, NBITS+6
  631. mov edx, ebp
  632. sub edx, edi
  633. shl edx, 10-NBITS ; EDX = V1-V0/ 4 in 6:10 int:frac
  634. mov dx, ax ; put delta u in low word
  635. ; Save the U1 and V1 so we don't have to divide on the next iteration
  636. mov U0, ebx
  637. mov V0, ebp
  638. pop edi ; Restore EDI before using it
  639. REPT (1 SHL (NBITS-2))
  640. local skip8
  641. REPT 4
  642. ; Do 1 pixel
  643. mov eax, esi ; get u,v
  644. shr eax, 26 ; shift out all but int(v)
  645. shld ax,si,6 ; shift in u, shifting up v
  646. mov cl, es:[eax] ; load into buffer register
  647. add esi, edx ; inc u,v
  648. ror ecx, 8 ; move to next dest pixel
  649. ENDM
  650. cmp ecx,-1
  651. je skip8
  652. mov [edi],ecx ; Draw 4 pixels to display
  653. mov ebp, _bytes_per_row
  654. mov [edi+ebp], ecx
  655. skip8: add edi,4
  656. ENDM
  657. pop ebp
  658. pop ecx
  659. pop ebx
  660. dec _loop_count
  661. jnz TopOfLoop4_nolight
  662. EndOfLoop4_nolight:
  663. cmp num_left_over, 0
  664. je _none_to_do
  665. DoEndPixels_nolight:
  666. add ebx, DU1
  667. add ebp, DV1
  668. add ecx, DZ1
  669. push edi ; use edi as a temporary variable
  670. ; Find fixed U1
  671. mov eax, ebx
  672. PDIV
  673. mov ebx, eax ; ebx = U1 until pop's
  674. ; Find fixed V1
  675. mov eax, ebp
  676. PDIV
  677. mov ebp, eax ; ebp = V1 until pop's
  678. mov ecx, U0 ; ecx = U0 until pop's
  679. mov edi, V0 ; edi = V0 until pop's
  680. ; Make ESI = V0:U0 in 6:10,6:10 format
  681. mov eax, ecx
  682. shr eax, 6
  683. mov esi, edi
  684. shl esi, 10
  685. mov si, ax
  686. ; Make EDX = DV:DU in 6:10,6:10 format
  687. mov eax, ebx
  688. sub eax, ecx
  689. sar eax, NBITS+6
  690. mov edx, ebp
  691. sub edx, edi
  692. shl edx, 10-NBITS ; EDX = V1-V0/ 4 in 6:10 int:frac
  693. mov dx, ax ; put delta u in low word
  694. pop edi ; Restore EDI before using it
  695. mov ecx, num_left_over
  696. mov ebp,_bytes_per_row
  697. ITERATION = 0
  698. REPT (1 SHL NBITS)
  699. local skip9
  700. ; Do 1 pixel
  701. mov eax, esi ; get u,v
  702. shr eax, 26 ; shift out all but int(v)
  703. shld ax,si,6 ; shift in u, shifting up v
  704. mov al, es:[eax] ; load into buffer register
  705. add esi, edx ; inc u,v
  706. cmp al,255
  707. je skip9
  708. mov [edi+ITERATION], al ; write pixel
  709. mov [edi+ebp+ITERATION], al
  710. skip9: dec ecx
  711. jz _none_to_do
  712. ITERATION = ITERATION + 1
  713. ENDM
  714. ; Should never get here!!!!!
  715. int 3
  716. jmp _none_to_do
  717. _TEXT ends
  718. end