TMAP_16L.ASM 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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_16l.asm $
  13. ; $Revision: 1.4 $
  14. ; $Author: mike $
  15. ; $Date: 1994/11/30 00:56:39 $
  16. ;
  17. ; inner loop of 16 bit per pixel lighted texture mapper
  18. ;
  19. ; $Log: tmap_16l.asm $
  20. ; Revision 1.4 1994/11/30 00:56:39 mike
  21. ; optimization.
  22. ;
  23. ; Revision 1.3 1994/11/12 16:39:31 mike
  24. ; jae to ja.
  25. ;
  26. ; Revision 1.2 1993/11/22 10:24:32 mike
  27. ; *** empty log message ***
  28. ;
  29. ; Revision 1.1 1993/09/08 17:29:20 mike
  30. ; Initial revision
  31. ;
  32. ;
  33. ;
  34. .386
  35. public asm_tmap_scanline_lin_16l_
  36. include tmap_inc.asm
  37. _DATA SEGMENT DWORD PUBLIC USE32 'DATA'
  38. extrn _fx_u:dword
  39. extrn _fx_v:dword
  40. extrn _fx_du_dx:dword
  41. extrn _fx_dv_dx:dword
  42. extrn _fx_y:dword
  43. extrn _fx_xleft:dword
  44. extrn _fx_xright:dword
  45. extrn _pixptr:dword
  46. extrn _x:dword
  47. extrn _loop_count:dword
  48. extrn _fx_rgb:dword
  49. extrn _fx_drgb_dx:dword
  50. extrn _fx_r:dword
  51. extrn _fx_g:dword
  52. extrn _fx_b:dword
  53. extrn _fx_dr_dx:dword
  54. extrn _fx_dg_dx:dword
  55. extrn _fx_db_dx:dword
  56. _DATA ENDS
  57. DGROUP GROUP _DATA
  58. _TEXT SEGMENT PARA PUBLIC USE32 'CODE'
  59. ASSUME DS:_DATA
  60. ASSUME CS:_TEXT
  61. ; --------------------------------------------------------------------------------------------------
  62. ; Enter:
  63. ; _xleft fixed point left x coordinate
  64. ; _xright fixed point right x coordinate
  65. ; _y fixed point y coordinate
  66. ; _pixptr address of source pixel map
  67. ; _u fixed point initial u coordinate
  68. ; _v fixed point initial v coordinate
  69. ; _du_dx fixed point du/dx
  70. ; _dv_dx fixed point dv/dx
  71. ; for (x = (int) xleft; x <= (int) xright; x++) {
  72. ; _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
  73. ; _setpixel(x,y);
  74. ;
  75. ; u += du_dx;
  76. ; v += dv_dx;
  77. ; z += dz_dx;
  78. ; }
  79. align 4
  80. asm_tmap_scanline_lin_rgb_:
  81. pusha
  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
  89. cmp edi,_window_bottom
  90. ja _none_to_do
  91. sub edi,_window_top
  92. imul edi,_bytes_per_row
  93. mov eax,_fx_xleft
  94. sar eax,16
  95. jns eax_ok
  96. sub eax,eax
  97. eax_ok:
  98. sub eax,_window_left
  99. add edi,eax
  100. add edi,eax
  101. add edi,write_buffer
  102. ; set _loop_count = # of iterations
  103. mov eax,_fx_xright
  104. sar eax,16
  105. cmp eax,_window_right
  106. jb eax_ok1
  107. mov eax,_window_right
  108. eax_ok1: cmp eax,_window_left
  109. ja eax_ok2
  110. mov eax,_window_left
  111. eax_ok2:
  112. mov ebx,_fx_xleft
  113. sar ebx,16
  114. sub eax,ebx
  115. js _none_to_do
  116. cmp eax,_window_width
  117. jbe _ok_to_do
  118. mov eax,_window_width
  119. _ok_to_do:
  120. mov _loop_count,eax
  121. ; edi destination pixel pointer
  122. mov ebx,_fx_u
  123. mov ebp,_fx_v
  124. shl ebx,10
  125. shl ebp,10
  126. shl _fx_du_dx,10
  127. shl _fx_dv_dx,10
  128. ; rgb values are passed in the following peculiar, confidential, trade secreted, copyrighted, patented format:
  129. ; [ 5 bits ] [ 5 bits ] [ 5 bits ] [ 5 bits ] [ 2 bits ] [ 5 bits ] [ 5 bits ]
  130. ; red int red frac blue int blue frac unused green int green frac
  131. ; The reason they are stored in the order red, blue, green is to optimize the process of packing together the three 5 bit
  132. ; values for red, green, blue in the conventional manner, suitable for an inverse table lookup
  133. ; convert fixed point values in _fx_dr_dx, _fx_dg_dx, _fx_db_dx to _fx_drgb_dx
  134. ;** int 3
  135. mov eax,_fx_dg_dx ; get green value
  136. sar eax,11 ; after shift, low order 10 bits are what we want
  137. jns dgok1
  138. inc eax
  139. dgok1: shrd ecx,eax,10 ; shift green 5i.5f into destination
  140. shr ecx,2 ; shift in two don't care bits
  141. mov eax,_fx_db_dx
  142. sar eax,11
  143. jns dbok1
  144. inc eax
  145. dbok1: shrd ecx,eax,10
  146. mov eax,_fx_dr_dx
  147. sar eax,11
  148. jns drok1
  149. inc eax
  150. drok1: shrd ecx,eax,10 ; now %ecx is correct!
  151. mov _fx_drgb_dx,ecx
  152. ; convert fixed point values in _fx_r, _fx_g, _fx_b to _fx_rgb (which is the above peculiar format)
  153. mov eax,_fx_g ; get green value
  154. sar eax,11 ; after shift, low order 10 bits are what we want
  155. jns rok1
  156. sub eax,eax
  157. rok1: shrd ecx,eax,10 ; shift green 5i.5f into destination
  158. shr ecx,2 ; shift in two don't care bits
  159. mov eax,_fx_b
  160. sar eax,11
  161. jns bok1
  162. sub eax,eax
  163. bok1: shrd ecx,eax,10
  164. mov eax,_fx_r
  165. sar eax,11
  166. jns gok1
  167. sub eax,eax
  168. gok1: shrd ecx,eax,10 ; now %ecx is correct!
  169. ;** mov ecx,_fx_rgb
  170. _size = (_end1 - _start1)/(num_iters-1)
  171. mov eax,num_iters-1
  172. sub eax,_loop_count
  173. jns itsok
  174. int 3
  175. itsok:
  176. imul eax,eax,dword ptr _size
  177. add eax,offset _start1
  178. ;** dec edi ; inc edi moved before write to separate instructions
  179. jmp eax
  180. align 4
  181. _start1:
  182. ; usage:
  183. ; eax work
  184. ; ebx u coordinate
  185. ; ecx rgb (actually rbg, each i5.f5 with 2 bits between blue and green)
  186. ; edx work
  187. ; ebp v coordinate
  188. ; esi pointer to source bitmap
  189. ; edi write address
  190. ; do all but the last pixel in the unwound loop, last pixel done separately because less work is needed
  191. rept num_iters-1
  192. ; interpolate the rgb values
  193. sub eax,eax
  194. mov edx,ecx ; note, these are in order red, blue, green
  195. add ecx,_fx_drgb_dx
  196. and edx,11111000001111100000001111100000b ; preserve ri, bi, gi, strip out fractional portions and 2 extra bits
  197. shld eax,edx,15 ; shift in ri, bi
  198. or ax,dx ; mask in gi
  199. ; do the regular texture mapper linear interpolation to get the pixel from the source bitmap
  200. sub edx,edx
  201. shld edx,ebp,6 ; shift in v coordinate
  202. add ebp,_fx_dv_dx ; update v coordinate
  203. shld edx,ebx,6 ; shift in u coordinate while shifting up v coordinate
  204. add ebx,_fx_du_dx ; update u coordinate
  205. mov ax,[esi+2*edx] ; get pixel from source bitmap
  206. ; get color value based on looked up value from texture map (%al) and light value (%ah)
  207. mov al,_pixel_average[eax] ; get color value based on palette light and color
  208. ; write the pixel
  209. mov [edi],ax
  210. add edi,2
  211. endm
  212. _end1:
  213. ; now do the leftover pixel
  214. ; interpolate the rgb values
  215. sub eax,eax
  216. mov edx,ecx ; note, these are in order red, blue, green
  217. and edx,11111000001111100000001111100000b ; preserve ri, bi, gi, strip out fractional portions and 2 extra bits
  218. shld eax,edx,15 ; shift in ri, bi
  219. or ax,dx ; mask in gi
  220. mov ah,_rgb_to_palette[eax] ; get color value for 15 bit rgb value
  221. ; do the regular texture mapper linear interpolation to get the pixel from the source bitmap
  222. sub edx,edx
  223. shld edx,ebp,6 ; shift in v coordinate
  224. shld edx,ebx,6 ; shift in u coordinate while shifting up v coordinate
  225. mov al,[esi+edx] ; get pixel from source bitmap
  226. ; get color value based on looked up value from texture map (%al) and light value (%ah)
  227. mov al,_pixel_average[eax] ; get color value based on palette light and color
  228. ; write the pixel
  229. mov [edi],al
  230. _none_to_do: popa
  231. ret
  232. ; -- Code to get rgb 5 bits integer, 5 bits fraction value into 5 bits integer (for each gun)
  233. ; suitable for inverse color lookup
  234. ;**__test:
  235. ;** int 3
  236. ;**; rrrrrfffffrrrrrfffffxxbbbbbfffff
  237. ;** mov eax,11111001001010101110101101110111b
  238. ;** and eax,11111000001111100000001111100000b
  239. ;** shld ebx,eax,15
  240. ;** or bx,ax
  241. _TEXT ends
  242. end