TMAP_RGB.ASM 7.7 KB

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