TMAP_KL.ASM 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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_kl.asm $
  13. ; $Revision: 1.3 $
  14. ; $Author: mike $
  15. ; $Date: 1994/11/30 00:56:50 $
  16. ;
  17. ; Linear, lighted texture mapper inner loop with a constant lighting value.
  18. ;
  19. ; $Log: tmap_kl.asm $
  20. ; Revision 1.3 1994/11/30 00:56:50 mike
  21. ; optimization.
  22. ;
  23. ; Revision 1.2 1994/11/12 16:39:38 mike
  24. ; jae to ja.
  25. ;
  26. ; Revision 1.1 1994/05/10 09:37:52 mike
  27. ; Initial revision
  28. ;
  29. ; Revision 1.1 1993/09/08 17:29:52 mike
  30. ; Initial revision
  31. ;
  32. ;
  33. ;
  34. .386
  35. public asm_tmap_scanline_lin_lighted_k_
  36. include tmap_inc.asm
  37. _DATA SEGMENT DWORD PUBLIC USE32 'DATA'
  38. extrn _fx_l:dword
  39. ;** extrn _fx_dl_dx:dword
  40. extrn _dither_intensity_lighting:dword
  41. extrn _fx_u:dword
  42. extrn _fx_v:dword
  43. extrn _fx_du_dx:dword
  44. extrn _fx_dv_dx:dword
  45. extrn _fx_y:dword
  46. extrn _fx_xleft:dword
  47. extrn _fx_xright:dword
  48. extrn _pixptr:dword
  49. extrn _x:dword
  50. extrn _loop_count:dword
  51. extern _pixel_data_selector:word, _gr_fade_table_selector:word
  52. _DATA ENDS
  53. DGROUP GROUP _DATA
  54. _TEXT SEGMENT PARA PUBLIC USE32 'CODE'
  55. ASSUME DS:_DATA
  56. ASSUME CS:_TEXT
  57. ; --------------------------------------------------------------------------------------------------
  58. ; Enter:
  59. ; _xleft fixed point left x coordinate
  60. ; _xright fixed point right x coordinate
  61. ; _y fixed point y coordinate
  62. ; _pixptr address of source pixel map
  63. ; _u fixed point initial u coordinate
  64. ; _v fixed point initial v coordinate
  65. ; _du_dx fixed point du/dx
  66. ; _dv_dx fixed point dv/dx
  67. ; for (x = (int) xleft; x <= (int) xright; x++) {
  68. ; _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
  69. ; _setpixel(x,y);
  70. ;
  71. ; u += du_dx;
  72. ; v += dv_dx;
  73. ; z += dz_dx;
  74. ; }
  75. align 4
  76. asm_tmap_scanline_lin_lighted_k_:
  77. push es
  78. push fs
  79. pusha
  80. mov es,_pixel_data_selector ; selector[0*2]
  81. mov fs,_gr_fade_table_selector ; selector[1*2] ; fs = bmd_fade_table
  82. ; Setup for loop: _loop_count iterations = (int) xright - (int) xleft
  83. ; esi source pixel pointer = pixptr
  84. ; edi initial row pointer = y*320+x
  85. ; set esi = pointer to start of texture map data
  86. mov esi,_pixptr
  87. ; set edi = address of first pixel to modify
  88. mov edi,_fx_y ; this is actually an int
  89. cmp edi,_window_bottom
  90. ja _none_to_do
  91. imul edi,_bytes_per_row
  92. mov ebx,_fx_xleft
  93. sar ebx,16
  94. jns ebx_ok
  95. sub ebx,ebx
  96. ebx_ok:
  97. add edi,ebx
  98. add edi,write_buffer
  99. ; set _loop_count = # of iterations
  100. mov eax,_fx_xright
  101. sar eax,16
  102. cmp eax,_window_right
  103. jl eax_ok1
  104. mov eax,_window_right
  105. eax_ok1: cmp eax,_window_left
  106. jg eax_ok2
  107. mov eax,_window_left
  108. eax_ok2:
  109. sub eax,ebx
  110. js _none_to_do
  111. cmp eax,_window_width
  112. jbe _ok_to_do
  113. mov eax,_window_width
  114. _ok_to_do:
  115. mov _loop_count,eax
  116. ; edi destination pixel pointer
  117. mov ecx,offset _lighting_tables
  118. mov eax,_fx_u ; get 32 bit u coordinate
  119. shr eax,6 ; get 6:10 int:frac u coordinate into low word
  120. mov ebp,_fx_v ; get 32 bit v coordinate
  121. shl ebp,10 ; put 6:10 int:frac into high word
  122. mov bp,ax ; put u coordinate in low word
  123. mov eax,_fx_du_dx ; get 32 bit delta u
  124. shr eax,6 ; get 6:10 int:frac delta u into low word
  125. mov edx,_fx_dv_dx ; get 32 bit delta v
  126. shl edx,10 ; put 6:10 int:frac into high word
  127. mov dx,ax ; put delta u in low word
  128. ;; esi, ecx should be free
  129. loop_test = 1 ; set to 1 to run as loop for better profiling
  130. if loop_test
  131. mov ebx,_fx_l
  132. shr ebx,8
  133. mov ecx,_loop_count
  134. inc ecx
  135. shr ecx,1
  136. je one_more_pix
  137. pushf
  138. align 4
  139. loop1:
  140. mov eax,ebp ; get u, v
  141. shr eax,26 ; shift out all but int(v)
  142. shld ax,bp,6 ; shift in u, shifting up v
  143. mov bl,es:[eax] ; get pixel from source bitmap
  144. mov al,fs:[ebx] ; xlat pixel through lighting tables
  145. add ebp,edx ; u += du, v += dv
  146. mov [edi],al ; write pixel...
  147. inc edi ; ...and advance
  148. ; --- ---
  149. mov eax,ebp ; get u, v
  150. shr eax,26 ; shift out all but int(v)
  151. shld ax,bp,6 ; shift in u, shifting up v
  152. mov bl,es:[eax] ; get pixel from source bitmap
  153. add ebp,edx ; u += du, v += dv
  154. mov al,fs:[ebx] ; xlat pixel through lighting tables
  155. mov [edi],al ; write pixel...
  156. inc edi ; ...and advance
  157. dec ecx ; _loop_count
  158. jne loop1
  159. popf
  160. jnc all_done
  161. one_more_pix: mov eax,ebp ; get u, v
  162. shr eax,26 ; shift out all but int(v)
  163. shld ax,bp,6 ; shift in u, shifting up v
  164. mov bl,es:[eax] ; get pixel from source bitmap
  165. mov al,fs:[ebx] ; xlat pixel through lighting tables
  166. mov [edi],al ; write pixel...
  167. all_done: popa
  168. pop fs
  169. pop es
  170. ret
  171. endif
  172. ; usage:
  173. ; eax work
  174. ; ebx lighting value
  175. ; ecx _lighting_tables
  176. ; edx du, dv 6:10:6:10
  177. ; ebp u, v coordinates 6:10:6:10
  178. ; esi pointer to source bitmap
  179. ; edi write address
  180. _size = (_end1 - _start1)/num_iters
  181. mov ebx,_fx_l
  182. shr ebx,8
  183. mov eax,num_iters
  184. sub eax,_loop_count
  185. imul eax,eax,dword ptr _size
  186. add eax,offset _start1
  187. jmp eax
  188. align 4
  189. _start1:
  190. ; usage:
  191. ; eax work
  192. ; ebx lighting value
  193. ; ecx _lighting_tables
  194. ; edx du, dv 6:10:6:10
  195. ; ebp u, v coordinates 6:10:6:10
  196. ; esi pointer to source bitmap
  197. ; edi write address
  198. ; do all but the last pixel in the unwound loop, last pixel done separately because less work is needed
  199. rept num_iters
  200. if 1
  201. mov eax,ebp ; get u, v
  202. shr eax,26 ; shift out all but int(v)
  203. shld ax,bp,6 ; shift in u, shifting up v
  204. add ebp,edx ; u += du, v += dv
  205. mov bl,[esi+eax] ; get pixel from source bitmap
  206. mov al,[ecx+ebx] ; xlat pixel through lighting tables
  207. mov [edi],al ; write pixel...
  208. inc edi ; ...and advance
  209. else
  210. ; version which assumes segment overrides are in place (which they are obviously not)
  211. mov eax,ebp ; get u, v
  212. shr eax,26 ; shift out all but int(v)
  213. shld ax,bp,6 ; shift in u, shifting up v
  214. add ebp,edx ; u += du, v += dv
  215. mov bl,[eax] ; get pixel from source bitmap
  216. mov al,[ebx] ; xlat pixel through lighting tables
  217. mov [edi],al ; write pixel...
  218. inc edi ; ...and advance
  219. endif
  220. endm
  221. _end1:
  222. ; now do the leftover pixel
  223. mov eax,ebp
  224. shr eax,26 ; shift in v coordinate
  225. shld ax,bp,6 ; shift in u coordinate while shifting up v coordinate
  226. mov bl,[esi+eax] ; get pixel from source bitmap
  227. mov al,_lighting_tables[ebx] ; xlat pixel through lighting tables
  228. mov [edi],al ; write pixel...
  229. _none_to_do: popa
  230. pop fs
  231. pop es
  232. ret
  233. ; -- Code to get rgb 5 bits integer, 5 bits fraction value into 5 bits integer (for each gun)
  234. ; suitable for inverse color lookup
  235. ;**__test:
  236. ;** int 3
  237. ;**; rrrrrfffffrrrrrfffffxxbbbbbfffff
  238. ;** mov eax,11111001001010101110101101110111b
  239. ;** and eax,11111000001111100000001111100000b
  240. ;** shld ebx,eax,15
  241. ;** or bx,ax
  242. _TEXT ends
  243. end