TMAPDITH.ASM 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  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_per.asm $
  13. ; $Revision: 1.18 $
  14. ; $Author: mike $
  15. ; $Date: 1994/05/03 11:08:32 $
  16. ;
  17. ; Perspective texture mapper inner loop.
  18. ;
  19. ; $Log: tmap_per.asm $
  20. ; Revision 1.18 1994/05/03 11:08:32 mike
  21. ; Trap divide overflows.
  22. ;
  23. ; Revision 1.17 1994/04/21 15:03:41 mike
  24. ; make faster.
  25. ;
  26. ; Revision 1.16 1994/04/08 16:46:57 john
  27. ; Made 32 fade levels. Hacked.
  28. ;
  29. ; Revision 1.15 1994/03/31 08:35:18 mike
  30. ; Fix quantized-by-4 bug in inner loop.
  31. ;
  32. ; Revision 1.14 1994/03/14 17:41:14 mike
  33. ; Fix bug in unlighted version.
  34. ;
  35. ; Revision 1.13 1994/03/14 15:45:14 mike
  36. ; streamline code.
  37. ;
  38. ; Revision 1.12 1994/01/14 14:01:58 mike
  39. ; *** empty log message ***
  40. ;
  41. ; Revision 1.11 1993/12/18 14:43:44 john
  42. ; Messed around with doing 1/z, the u*(1/z) and v*(1/z)
  43. ; (Went from 23 fps to 21 fps... not good! )
  44. ;
  45. ; Revision 1.10 1993/12/17 16:14:17 john
  46. ; Split lighted/nonlighted, so there is no cmp lighting
  47. ; in the inner loop.
  48. ;
  49. ; Revision 1.9 1993/12/17 12:34:29 john
  50. ; Made leftover bytes use linear approx instead of correct...
  51. ; should save about 8 divides per scanline on average.
  52. ; Also, took out anti-aliasing code and rearranged to
  53. ; order of some instructions to help on 486 pipelining.
  54. ; (The anti-aliasing code did *not* look good, so I
  55. ; figure there was no reason to keep it in. )
  56. ;
  57. ; Revision 1.8 1993/12/16 18:37:52 mike
  58. ; Align some stuff on 4 byte boundaries.
  59. ;
  60. ; Revision 1.7 1993/11/30 08:44:18 john
  61. ; Made selector set check for < 64*64 bitmaps.
  62. ;
  63. ; Revision 1.6 1993/11/23 17:25:26 john
  64. ; Added safety "and eax, 0fffh" in lighting lookup.
  65. ;
  66. ; Revision 1.5 1993/11/23 15:08:52 mike
  67. ; Fixed lighting bug.
  68. ;
  69. ; Revision 1.4 1993/11/23 14:38:50 john
  70. ; optimized NORMAL code by switching EBX and ESI, so BH can be used in
  71. ; the lighting process.
  72. ;
  73. ; Revision 1.3 1993/11/23 14:30:53 john
  74. ; Made the perspective tmapper do 1/8 divides; added lighting.
  75. ;
  76. ; Revision 1.2 1993/11/22 10:24:59 mike
  77. ; *** empty log message ***
  78. ;
  79. ; Revision 1.1 1993/09/08 17:29:53 mike
  80. ; Initial revision
  81. ;
  82. ;
  83. ;
  84. .386
  85. public _fx_u,_fx_v,_fx_z,_fx_du_dx,_fx_dv_dx,_fx_dz_dx,_fx_y,_fx_xleft,_fx_xright
  86. public _pixptr
  87. public asm_tmap_scanline_per_
  88. include tmap_inc.asm
  89. public _max_ecx,_min_ecx
  90. extern _fx_l:dword
  91. extern _fx_dl_dx:dword
  92. extern _dither_intensity_lighting:dword
  93. extern _Lighting_on:dword
  94. extern _pixel_data_selector:word, _gr_fade_table_selector:word, _transparency_on:dword
  95. _DATA SEGMENT DWORD PUBLIC USE32 'DATA'
  96. align 4
  97. ;**_v_window_left dd _window_left
  98. ;**_v_window_right dd _window_right
  99. ;**_v_window_top dd _window_top
  100. ;**_v_window_bottom dd _window_bottom
  101. ; ---------- These are passed in by the C caller ----------
  102. _fx_u dd ?
  103. _fx_v dd ?
  104. _fx_z dd ?
  105. _fx_du_dx dd ?
  106. _fx_dv_dx dd ?
  107. _fx_dz_dx dd ?
  108. _fx_y dd ?
  109. _fx_xleft dd ?
  110. _fx_xright dd ?
  111. _pixptr dd ?
  112. ; ----------^^ These are passed in by the C caller ^^----------
  113. public _x,_loop_count
  114. align 4
  115. _x dd ?
  116. _loop_count dd ?
  117. _max_ecx dd 0
  118. _min_ecx dd 55555555h
  119. public _per2_flag
  120. _per2_flag dd 1
  121. public _scan_doubling_flag, _linear_if_far_flag
  122. _scan_doubling_flag dd 0
  123. _linear_if_far_flag dd 0
  124. ;---------- local variables
  125. align 4
  126. req_base dd ?
  127. req_size dd ?
  128. U0 dd ?
  129. U1 dd ?
  130. V0 dd ?
  131. V1 dd ?
  132. num_left_over dd ?
  133. DU1 dd ?
  134. DV1 dd ?
  135. DZ1 dd ?
  136. ;*NO_DITHER _fx_dl_dx1 dd ?
  137. ;*NO_DITHER _fx_dl_dx2 dd ?
  138. _DATA ENDS
  139. DGROUP GROUP _DATA
  140. _TEXT SEGMENT DWORD PUBLIC USE32 'CODE'
  141. ASSUME DS:_DATA
  142. ASSUME CS:_TEXT
  143. ; --------------------------------------------------------------------------------------------------
  144. ; Enter:
  145. ; _xleft fixed point left x coordinate
  146. ; _xright fixed point right x coordinate
  147. ; _y fixed point y coordinate
  148. ; _pixptr address of source pixel map
  149. ; _u fixed point initial u coordinate
  150. ; _v fixed point initial v coordinate
  151. ; _z fixed point initial z coordinate
  152. ; _du_dx fixed point du/dx
  153. ; _dv_dx fixed point dv/dx
  154. ; _dz_dx fixed point dz/dx
  155. ; for (x = (int) xleft; x <= (int) xright; x++) {
  156. ; _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
  157. ; _setpixel(x,y);
  158. ;
  159. ; u += du_dx;
  160. ; v += dv_dx;
  161. ; z += dz_dx;
  162. ; }
  163. asm_tmap_scanline_per_:
  164. push es
  165. push fs
  166. pusha
  167. ;---------------------------- setup for loop ---------------------------------
  168. ; Setup for loop: _loop_count iterations = (int) xright - (int) xleft
  169. ; esi source pixel pointer = pixptr
  170. ; edi initial row pointer = y*320+x
  171. ; set esi = pointer to start of texture map data
  172. mov es,_pixel_data_selector ; selector[0*2]
  173. mov fs,_gr_fade_table_selector ; selector[1*2] ; fs = bmd_fade_table
  174. ; set edi = address of first pixel to modify
  175. mov edi,_fx_y
  176. cmp edi,_window_bottom
  177. jae _none_to_do
  178. imul edi,_bytes_per_row
  179. mov eax,_fx_xleft
  180. sar eax,16
  181. jns eax_ok
  182. sub eax,eax
  183. eax_ok:
  184. add edi,eax
  185. add edi,write_buffer
  186. ; set _loop_count = # of iterations
  187. mov eax,_fx_xright
  188. sar eax,16
  189. cmp eax,_window_right
  190. jb eax_ok1
  191. mov eax,_window_right
  192. eax_ok1: cmp eax,_window_left
  193. ja eax_ok2
  194. mov eax,_window_left
  195. eax_ok2:
  196. mov ebx,_fx_xleft
  197. sar ebx,16
  198. sub eax,ebx
  199. js _none_to_do
  200. cmp eax,_window_width
  201. jbe _ok_to_do
  202. mov eax,_window_width
  203. _ok_to_do:
  204. mov _loop_count,eax
  205. ; lighting values are passed in fixed point, but need to be in 8 bit integer, 8 bit fraction so we can easily
  206. ; get the integer by reading %bh
  207. sar _fx_l, 8
  208. sar _fx_dl_dx,8
  209. jns dl_dx_ok
  210. inc _fx_dl_dx ; round towards 0 for negative deltas
  211. dl_dx_ok:
  212. ;*NO_DITHER ;-------------------------- setup for dithering -----------------------------
  213. ;*NO_DITHER ; do dithering, use lighting values which are .5 less than and .5 more than actual value
  214. ;*NO_DITHER mov ebx,40h ; assume dithering on
  215. ;*NO_DITHER mov eax,_fx_dl_dx
  216. ;*NO_DITHER add eax,ebx ; add 1/2
  217. ;*NO_DITHER mov _fx_dl_dx1,eax
  218. ;*NO_DITHER mov eax,_fx_dl_dx
  219. ;*NO_DITHER sub eax,ebx
  220. ;*NO_DITHER mov _fx_dl_dx2,eax
  221. ;*NO_DITHER mov ebx,_fx_xleft
  222. ;*NO_DITHER shr ebx,16
  223. ;*NO_DITHER xor ebx,_fx_y
  224. ;*NO_DITHER and ebx,1
  225. ;*NO_DITHER jne dith_1
  226. ;*NO_DITHER xchg eax,_fx_dl_dx1
  227. ;*NO_DITHER dith_1: mov _fx_dl_dx2,eax
  228. ; set initial values
  229. mov ebx,_fx_u
  230. mov ebp,_fx_v
  231. mov ecx,_fx_z
  232. test _per2_flag,-1
  233. je tmap_loop
  234. cmp _Lighting_on, 0
  235. je tmap_loop_fast_nolight
  236. jmp tmap_loop_fast
  237. ;================ PERSPECTIVE TEXTURE MAP INNER LOOPS ========================
  238. ;
  239. ; Usage in loop: eax division, pixel value
  240. ; ebx u
  241. ; ecx z
  242. ; edx division
  243. ; ebp v
  244. ; esi source pixel pointer
  245. ; edi destination pixel pointer
  246. ;-------------------- NORMAL PERSPECTIVE TEXTURE MAP LOOP -----------------
  247. align 4
  248. tmap_loop:
  249. xchg ebx, esi
  250. ; compute v coordinate
  251. mov eax,ebp ; get v
  252. cdq
  253. idiv ecx ; eax = (v/z)
  254. and eax,3fh ; mask with height-1
  255. mov ebx,eax
  256. ; compute u coordinate
  257. mov eax,esi ; get u
  258. cdq
  259. idiv ecx ; eax = (u/z)
  260. shl eax,26
  261. shld ebx,eax,6 ; esi = v*64+u
  262. ; read 1 pixel
  263. movzx eax,byte ptr es:[ebx] ; get pixel from source bitmap
  264. cmp _Lighting_on, 0
  265. je NoLight1
  266. ; LIGHTING CODE
  267. mov ebx, _fx_l ; get temp copy of lighting value
  268. mov ah, bh ; get lighting level
  269. add ebx, _fx_dl_dx ; update lighting value
  270. ;*NO_DITHER add ebx, _fx_dl_dx1 ; update lighting value
  271. ;*NO_DITHER and eax, (32*256)-1
  272. ;*NO_DITHER push eax ; dithering
  273. ;*NO_DITHER mov eax, _fx_dl_dx2
  274. ;*NO_DITHER xchg _fx_dl_dx1, eax
  275. ;*NO_DITHER mov _fx_dl_dx2, eax
  276. ;*NO_DITHER pop eax
  277. mov al, fs:[eax] ; xlat pixel thru lighting tables
  278. mov _fx_l, ebx ; save temp copy of lighting value
  279. ; transparency check
  280. NoLight1: cmp al,255
  281. je skip1
  282. mov [edi],al
  283. skip1: inc edi
  284. ; update deltas
  285. add ebp,_fx_dv_dx
  286. add esi,_fx_du_dx
  287. add ecx,_fx_dz_dx
  288. je _div_0_abort ; would be dividing by 0, so abort
  289. xchg esi, ebx
  290. dec _loop_count
  291. jns tmap_loop
  292. _none_to_do:
  293. popa
  294. pop fs
  295. pop es
  296. ret
  297. ; We detected a z=0 condition, which seems pretty bogus, don't you think?
  298. ; So, we abort, but maybe we want to know about it.
  299. _div_0_abort:
  300. ;** int 3
  301. jmp _none_to_do
  302. ;-------------------------- PER/4 TMAPPER ----------------
  303. ;
  304. ; x = x1
  305. ; U0 = u/w; V0 = v/w;
  306. ; while ( 1 )
  307. ; u += du_dx*4; v+= dv_dx*4
  308. ; U1 = u/w; V1 = v/w;
  309. ; DUDX = (U1-U0)/4; DVDX = (V1-V0)/4;
  310. ;
  311. ; ; Pixel 0
  312. ; pixels = texmap[V0*64+U0];
  313. ; U0 += DUDX; V0 += DVDX
  314. ; ; Pixel 1
  315. ; pixels = (pixels<<8)+texmap[V0*64+U0];
  316. ; U0 += DUDX; V0 += DVDX
  317. ; ; Pixel 2
  318. ; pixels = (pixels<<8)+texmap[V0*64+U0];
  319. ; U0 += DUDX; V0 += DVDX
  320. ; ; Pixel 3
  321. ; pixels = (pixels<<8)+texmap[V0*64+U0];
  322. ;
  323. ; screen[x] = pixel
  324. ; x += 4;
  325. ; U0 = U1; V0 = V1
  326. NBITS = 3
  327. ZSHIFT = 3
  328. PDIV MACRO
  329. ; Returns EAX/ECX in 16.16 format in EAX. Trashes EDX
  330. ; sig bits 6.3
  331. ;--old-- cdq
  332. ;--old-- shld edx,eax, ZSHIFT
  333. ;--old-- lea eax, [eax*8]
  334. ;--old-- idiv ecx ; eax = (v/z)
  335. ;--old-- shl eax, 16-ZSHIFT
  336. mov edx,eax
  337. shl eax,ZSHIFT
  338. sar edx,32-ZSHIFT
  339. idiv ecx ; eax = (v/z)
  340. shl eax, 16-ZSHIFT
  341. ENDM
  342. wr_onepix macro num
  343. local skip
  344. cmp cl,255
  345. je skip
  346. mov num[edi],cl
  347. ror ecx,8
  348. skip:
  349. endm
  350. public tmap_loop_fast
  351. ; -------------------------------------- Start of Getting Dword Aligned ----------------------------------------------
  352. ; ebx fx_u
  353. tmap_loop_fast:
  354. mov esi,ebx
  355. align 4
  356. NotDwordAligned1:
  357. test edi, 11b
  358. jz DwordAligned1
  359. ; compute v coordinate
  360. mov eax,ebp ; get v
  361. cdq
  362. idiv ecx ; eax = (v/z)
  363. and eax,3fh ; mask with height-1
  364. mov ebx,eax
  365. ; compute u coordinate
  366. mov eax,esi ; get u
  367. cdq
  368. idiv ecx ; eax = (u/z)
  369. shl eax,26
  370. shld ebx,eax,6 ; esi = v*64+u
  371. ; read 1 pixel
  372. movzx eax,byte ptr es:[ebx] ; get pixel from source bitmap
  373. ; lighting code
  374. mov ebx, _fx_l ; get temp copy of lighting value
  375. mov ah, bh ; get lighting level
  376. add ebx, _fx_dl_dx ; update lighting value
  377. mov _fx_l, ebx ; save temp copy of lighting value
  378. ; transparency check
  379. cmp al,255
  380. je skip2 ; this pixel is transparent, so don't write it (or light it)
  381. mov al, fs:[eax] ; xlat pixel thru lighting tables
  382. ; write 1 pixel
  383. mov [edi],al
  384. skip2: inc edi
  385. ; update deltas
  386. add ebp,_fx_dv_dx
  387. add esi,_fx_du_dx
  388. add ecx,_fx_dz_dx
  389. je _div_0_abort ; would be dividing by 0, so abort
  390. dec _loop_count
  391. jns NotDwordAligned1
  392. jmp _none_to_do
  393. ; -------------------------------------- End of Getting Dword Aligned ----------------------------------------------
  394. DwordAligned1:
  395. mov ebx,esi ; get fx_u
  396. mov eax, _loop_count
  397. inc eax
  398. mov num_left_over, eax
  399. shr eax, NBITS
  400. cmp eax, 0
  401. je tmap_loop
  402. mov _loop_count, eax ; _loop_count = pixels / NPIXS
  403. shl eax, 3
  404. sub num_left_over, eax ; num_left_over = obvious
  405. ; compute initial v coordinate
  406. mov eax,ebp ; get v
  407. mov edx,ebp
  408. shl eax,ZSHIFT
  409. sar edx,32-ZSHIFT
  410. idiv ecx ; eax = (v/z)
  411. shl eax, 16-ZSHIFT
  412. mov V0, eax
  413. ; compute initial u coordinate
  414. mov eax,ebx ; get u
  415. mov edx,ebx
  416. shl eax,ZSHIFT
  417. sar edx,32-ZSHIFT
  418. idiv ecx ; eax = (v/z)
  419. shl eax, 16-ZSHIFT
  420. mov U0, eax
  421. ; Set deltas to NPIXS pixel increments
  422. mov eax, _fx_du_dx
  423. shl eax, 3
  424. mov DU1, eax
  425. mov eax, _fx_dv_dx
  426. shl eax, 3
  427. mov DV1, eax
  428. mov eax, _fx_dz_dx
  429. shl eax, 3
  430. mov DZ1, eax
  431. align 4
  432. TopOfLoop4:
  433. add ebx, DU1
  434. add ebp, DV1
  435. add ecx, DZ1
  436. je _div_0_abort ; would be dividing by 0, so abort
  437. ; Done with ebx, ebp, ecx until next iteration
  438. push ebx
  439. push ecx
  440. push ebp
  441. push edi
  442. ; Find fixed U1
  443. mov eax, ebx
  444. mov edx,ebx
  445. shl eax,ZSHIFT
  446. sar edx,32-ZSHIFT
  447. idiv ecx ; eax = (v/z)
  448. shl eax, 16-ZSHIFT
  449. mov ebx, eax ; ebx = U1 until pop's
  450. ; Find fixed V1
  451. mov eax, ebp
  452. mov edx, ebp
  453. shl eax,ZSHIFT
  454. sar edx,32-ZSHIFT
  455. idiv ecx ; eax = (v/z)
  456. mov ecx, U0 ; ecx = U0 until pop's
  457. mov edi, V0 ; edi = V0 until pop's
  458. shl eax, 16-ZSHIFT
  459. mov ebp, eax ; ebp = V1 until pop's
  460. ; Make ESI = V0:U0 in 6:10,6:10 format
  461. mov eax, ecx
  462. shr eax, 6
  463. mov esi, edi
  464. shl esi, 10
  465. mov si, ax
  466. ; Make EDX = DV:DU in 6:10,6:10 format
  467. mov eax, ebx
  468. sub eax, ecx
  469. sar eax, NBITS+6
  470. mov edx, ebp
  471. sub edx, edi
  472. shl edx, 10-NBITS ; EDX = V1-V0/ 4 in 6:10 int:frac
  473. mov dx, ax ; put delta u in low word
  474. ; Save the U1 and V1 so we don't have to divide on the next iteration
  475. mov U0, ebx
  476. mov V0, ebp
  477. pop edi ; Restore EDI before using it
  478. ; LIGHTING CODE
  479. mov ebx, _fx_l
  480. mov ebp, _fx_dl_dx
  481. test _transparency_on,-1
  482. je no_trans1
  483. REPT (1 SHL (NBITS-2))
  484. local skip3,no_trans1
  485. REPT 2
  486. local skipa1,skipa2
  487. mov eax, esi ; get u,v
  488. shr eax, 26 ; shift out all but int(v)
  489. shld ax,si,6 ; shift in u, shifting up v
  490. add esi, edx ; inc u,v
  491. mov al, es:[eax] ; get pixel from source bitmap
  492. cmp al,255
  493. je skipa1
  494. mov ah, bh ; form lighting table lookup value
  495. add ebx, ebp ; update lighting value
  496. mov al, fs:[eax] ; xlat thru lighting table into dest buffer
  497. mov [edi],al
  498. skipa1:
  499. inc edi
  500. ; Do odd pixel
  501. mov eax, esi ; get u,v
  502. shr eax, 26 ; shift out all but int(v)
  503. shld ax,si,6 ; shift in u, shifting up v
  504. add esi, edx ; inc u,v
  505. mov al, es:[eax] ; get pixel from source bitmap
  506. cmp al,255
  507. je skipa2
  508. mov ah, bh ; form lighting table lookup value
  509. add ebx, ebp ; update lighting value
  510. mov al, fs:[eax] ; xlat thru lighting table into dest buffer
  511. mov [edi],al
  512. skipa2:
  513. inc edi
  514. ENDM
  515. ENDM
  516. jmp cont1
  517. ; -------------------------------------------------------
  518. no_trans1:
  519. REPT (1 SHL (NBITS-2))
  520. local skip3
  521. REPT 2
  522. mov eax, esi ; get u,v
  523. shr eax, 26 ; shift out all but int(v)
  524. shld ax,si,6 ; shift in u, shifting up v
  525. add esi, edx ; inc u,v
  526. mov al, es:[eax] ; get pixel from source bitmap
  527. mov ah, bh ; form lighting table lookup value
  528. add ebx, ebp ; update lighting value
  529. mov cl, fs:[eax] ; xlat thru lighting table into dest buffer
  530. ; Do odd pixel
  531. mov eax, esi ; get u,v
  532. shr eax, 26 ; shift out all but int(v)
  533. shld ax,si,6 ; shift in u, shifting up v
  534. add esi, edx ; inc u,v
  535. mov al, es:[eax] ; get pixel from source bitmap
  536. mov ah, bh ; form lighting table lookup value
  537. add ebx, ebp ; update lighting value
  538. mov ch, fs:[eax] ; xlat thru lighting table into dest buffer
  539. ror ecx, 16 ; move to next double dest pixel position
  540. ENDM
  541. mov [edi],ecx ; Draw 4 pixels to display
  542. skip3: add edi,4
  543. ENDM
  544. cont1:
  545. ; -------------------------------------------------------
  546. ; LIGHTING CODE
  547. mov _fx_l, ebx
  548. pop ebp
  549. pop ecx
  550. pop ebx
  551. dec _loop_count
  552. jnz TopOfLoop4
  553. EndOfLoop4:
  554. cmp num_left_over, 0
  555. je _none_to_do
  556. ; ----------------------------------------- Start of LeftOver Pixels ------------------------------------------
  557. DoEndPixels:
  558. add ebx, DU1
  559. add ebp, DV1
  560. add ecx, DZ1
  561. je _div_0_abort
  562. push edi ; use edi as a temporary variable
  563. cmp ecx,10
  564. jg ecx_ok
  565. mov ecx,10
  566. ecx_ok:
  567. ; Find fixed U1
  568. mov eax, ebx
  569. PDIV
  570. mov ebx, eax ; ebx = U1 until pop's
  571. ; Find fixed V1
  572. mov eax, ebp
  573. PDIV
  574. mov ebp, eax ; ebp = V1 until pop's
  575. mov ecx, U0 ; ecx = U0 until pop's
  576. mov edi, V0 ; edi = V0 until pop's
  577. ; Make ESI = V0:U0 in 6:10,6:10 format
  578. mov eax, ecx
  579. shr eax, 6
  580. mov esi, edi
  581. shl esi, 10
  582. mov si, ax
  583. ; Make EDX = DV:DU in 6:10,6:10 format
  584. mov eax, ebx
  585. sub eax, ecx
  586. sar eax, NBITS+6
  587. mov edx, ebp
  588. sub edx, edi
  589. shl edx, 10-NBITS ; EDX = V1-V0/ 4 in 6:10 int:frac
  590. mov dx, ax ; put delta u in low word
  591. pop edi ; Restore EDI before using it
  592. mov ecx, num_left_over
  593. ; LIGHTING CODE
  594. mov ebx, _fx_l
  595. mov ebp, _fx_dl_dx
  596. ITERATION = 0
  597. REPT (1 SHL (NBITS-1))
  598. local skip4, skip5
  599. ; Do even pixel
  600. mov eax, esi ; get u,v
  601. shr eax, 26 ; shift out all but int(v)
  602. shld ax,si,6 ; shift in u, shifting up v
  603. mov al, es:[eax] ; get pixel from source bitmap
  604. add esi, edx ; inc u,v
  605. mov ah, bh ; form lighting table lookup value
  606. ;SAFETYand ah,0fh
  607. add ebx, ebp ; update lighting value
  608. cmp al,255
  609. je skip4
  610. mov al, fs:[eax] ; xlat thru lighting table into dest buffer
  611. mov [edi+ITERATION], al ; write pixel
  612. skip4: dec ecx
  613. jz _none_to_do
  614. ITERATION = ITERATION + 1
  615. ; Do odd pixel
  616. mov eax, esi ; get u,v
  617. shr eax, 26 ; shift out all but int(v)
  618. shld ax,si,6 ; shift in u, shifting up v
  619. mov al, es:[eax] ; get pixel from source bitmap
  620. add esi, edx ; inc u,v
  621. mov ah, bh ; form lighting table lookup value
  622. add ebx, _fx_dl_dx ; update lighting value
  623. cmp al,255
  624. je skip5
  625. ;SAFETYand ah,0fh
  626. mov al, fs:[eax] ; xlat thru lighting table into dest buffer
  627. mov [edi+ITERATION], al ; write pixel
  628. skip5: dec ecx
  629. jz _none_to_do
  630. ITERATION = ITERATION + 1
  631. ENDM
  632. ; ----------------------------------------- End of LeftOver Pixels ------------------------------------------
  633. ; Should never get here!!!!
  634. int 3
  635. jmp _none_to_do
  636. ; ==================================================== No Lighting Code ======================================================
  637. public tmap_loop_fast_nolight
  638. tmap_loop_fast_nolight:
  639. mov esi,ebx
  640. align 4
  641. NotDwordAligned1_nolight:
  642. test edi, 11b
  643. jz DwordAligned1_nolight
  644. ; compute v coordinate
  645. mov eax,ebp ; get v
  646. cdq
  647. idiv ecx ; eax = (v/z)
  648. and eax,3fh ; mask with height-1
  649. mov ebx,eax
  650. ; compute u coordinate
  651. mov eax,esi ; get u
  652. cdq
  653. idiv ecx ; eax = (u/z)
  654. shl eax,26
  655. shld ebx,eax,6 ; esi = v*64+u
  656. ; read 1 pixel
  657. mov al,es:[ebx] ; get pixel from source bitmap
  658. ; write 1 pixel
  659. cmp al,255
  660. je skip6
  661. mov [edi],al
  662. skip6: inc edi
  663. ; update deltas
  664. add ebp,_fx_dv_dx
  665. add esi,_fx_du_dx
  666. add ecx,_fx_dz_dx
  667. je _div_0_abort ; would be dividing by 0, so abort
  668. dec _loop_count
  669. jns NotDwordAligned1_nolight
  670. jmp _none_to_do
  671. DwordAligned1_nolight:
  672. mov ebx,esi
  673. mov eax, _loop_count
  674. inc eax
  675. mov num_left_over, eax
  676. shr eax, NBITS
  677. cmp eax, 0
  678. je tmap_loop
  679. mov _loop_count, eax ; _loop_count = pixels / NPIXS
  680. shl eax, NBITS
  681. sub num_left_over, eax ; num_left_over = obvious
  682. ; compute initial v coordinate
  683. mov eax,ebp ; get v
  684. PDIV
  685. mov V0, eax
  686. ; compute initial u coordinate
  687. mov eax,ebx ; get u
  688. PDIV
  689. mov U0, eax
  690. ; Set deltas to NPIXS pixel increments
  691. mov eax, _fx_du_dx
  692. shl eax, NBITS
  693. mov DU1, eax
  694. mov eax, _fx_dv_dx
  695. shl eax, NBITS
  696. mov DV1, eax
  697. mov eax, _fx_dz_dx
  698. shl eax, NBITS
  699. mov DZ1, eax
  700. align 4
  701. TopOfLoop4_nolight:
  702. add ebx, DU1
  703. add ebp, DV1
  704. add ecx, DZ1
  705. je _div_0_abort
  706. ; Done with ebx, ebp, ecx until next iteration
  707. push ebx
  708. push ecx
  709. push ebp
  710. push edi
  711. ; Find fixed U1
  712. mov eax, ebx
  713. PDIV
  714. mov ebx, eax ; ebx = U1 until pop's
  715. ; Find fixed V1
  716. mov eax, ebp
  717. PDIV
  718. mov ebp, eax ; ebp = V1 until pop's
  719. mov ecx, U0 ; ecx = U0 until pop's
  720. mov edi, V0 ; edi = V0 until pop's
  721. ; Make ESI = V0:U0 in 6:10,6:10 format
  722. mov eax, ecx
  723. shr eax, 6
  724. mov esi, edi
  725. shl esi, 10
  726. mov si, ax
  727. ; Make EDX = DV:DU in 6:10,6:10 format
  728. mov eax, ebx
  729. sub eax, ecx
  730. sar eax, NBITS+6
  731. mov edx, ebp
  732. sub edx, edi
  733. shl edx, 10-NBITS ; EDX = V1-V0/ 4 in 6:10 int:frac
  734. mov dx, ax ; put delta u in low word
  735. ; Save the U1 and V1 so we don't have to divide on the next iteration
  736. mov U0, ebx
  737. mov V0, ebp
  738. pop edi ; Restore EDI before using it
  739. REPT (1 SHL (NBITS-2))
  740. local skip7, no_trans2
  741. REPT 4
  742. ; Do 1 pixel
  743. mov eax, esi ; get u,v
  744. shr eax, 26 ; shift out all but int(v)
  745. shld ax,si,6 ; shift in u, shifting up v
  746. mov cl, es:[eax] ; load into buffer register
  747. add esi, edx ; inc u,v
  748. ror ecx, 8 ; move to next dest pixel
  749. ENDM
  750. test _transparency_on,-1
  751. je no_trans2
  752. cmp ecx,-1
  753. je skip7
  754. wr_onepix 0
  755. wr_onepix 1
  756. wr_onepix 2
  757. wr_onepix 3
  758. jmp skip7
  759. no_trans2:
  760. mov [edi],ecx ; Draw 4 pixels to display
  761. skip7: add edi,4
  762. ENDM
  763. pop ebp
  764. pop ecx
  765. pop ebx
  766. dec _loop_count
  767. jnz TopOfLoop4_nolight
  768. EndOfLoop4_nolight:
  769. cmp num_left_over, 0
  770. je _none_to_do
  771. DoEndPixels_nolight:
  772. add ebx, DU1
  773. add ebp, DV1
  774. add ecx, DZ1
  775. je _div_0_abort
  776. push edi ; use edi as a temporary variable
  777. ; Find fixed U1
  778. mov eax, ebx
  779. PDIV
  780. mov ebx, eax ; ebx = U1 until pop's
  781. ; Find fixed V1
  782. mov eax, ebp
  783. PDIV
  784. mov ebp, eax ; ebp = V1 until pop's
  785. mov ecx, U0 ; ecx = U0 until pop's
  786. mov edi, V0 ; edi = V0 until pop's
  787. ; Make ESI = V0:U0 in 6:10,6:10 format
  788. mov eax, ecx
  789. shr eax, 6
  790. mov esi, edi
  791. shl esi, 10
  792. mov si, ax
  793. ; Make EDX = DV:DU in 6:10,6:10 format
  794. mov eax, ebx
  795. sub eax, ecx
  796. sar eax, NBITS+6
  797. mov edx, ebp
  798. sub edx, edi
  799. shl edx, 10-NBITS ; EDX = V1-V0/ 4 in 6:10 int:frac
  800. mov dx, ax ; put delta u in low word
  801. pop edi ; Restore EDI before using it
  802. mov ecx, num_left_over
  803. ITERATION = 0
  804. REPT (1 SHL NBITS)
  805. local skip8
  806. ; Do 1 pixel
  807. mov eax, esi ; get u,v
  808. shr eax, 26 ; shift out all but int(v)
  809. shld ax,si,6 ; shift in u, shifting up v
  810. mov al, es:[eax] ; load into buffer register
  811. add esi, edx ; inc u,v
  812. cmp al,255
  813. je skip8
  814. mov [edi+ITERATION], al ; write pixel
  815. skip8: dec ecx
  816. jz _none_to_do
  817. ITERATION = ITERATION + 1
  818. ENDM
  819. ; Should never get here!!!!!
  820. int 3
  821. jmp _none_to_do
  822. _TEXT ends
  823. end
  824.