TMAP_LD.ASM 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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_ld.asm $
  13. ; $Revision: 1.4 $
  14. ; $Author: mike $
  15. ; $Date: 1994/11/30 00:56:53 $
  16. ;
  17. ; Inner loop of rgb lighted dithered linear texture mapper
  18. ;
  19. ; $Log: tmap_ld.asm $
  20. ; Revision 1.4 1994/11/30 00:56:53 mike
  21. ; optimization.
  22. ;
  23. ; Revision 1.3 1994/11/12 16:39:40 mike
  24. ; jae to ja.
  25. ;
  26. ; Revision 1.2 1993/11/22 10:23:58 mike
  27. ; *** empty log message ***
  28. ;
  29. ; Revision 1.1 1993/09/08 17:29:49 mike
  30. ; Initial revision
  31. ;
  32. ;
  33. ;
  34. ; Inner loop of rgb lighted dithered linear texture mapper
  35. ; Unlike tmap_rgb.asm, this version does lighting by writing alternate
  36. ; pixels in the light color, and the other colors based on the texture map pixel data.
  37. .386
  38. public asm_tmap_scanline_lin_ld_
  39. include tmap_inc.asm
  40. _DATA SEGMENT DWORD PUBLIC USE32 'DATA'
  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. extrn _reds_16:byte
  52. extrn _fx_rgb:dword,_fx_drgb_dx:dword
  53. extrn _fx_r:dword,_fx_g:dword,_fx_b:dword,_fx_dr_dx:dword,_fx_dg_dx:dword,_fx_db_dx:dword
  54. _DATA ENDS
  55. DGROUP GROUP _DATA
  56. _TEXT SEGMENT PARA PUBLIC USE32 'CODE'
  57. ASSUME DS:_DATA
  58. ASSUME CS:_TEXT
  59. ; --------------------------------------------------------------------------------------------------
  60. ; Enter:
  61. ; _xleft fixed point left x coordinate
  62. ; _xright fixed point right x coordinate
  63. ; _y fixed point y coordinate
  64. ; _pixptr address of source pixel map
  65. ; _u fixed point initial u coordinate
  66. ; _v fixed point initial v coordinate
  67. ; _du_dx fixed point du/dx
  68. ; _dv_dx fixed point dv/dx
  69. ; for (x = (int) xleft; x <= (int) xright; x++) {
  70. ; _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
  71. ; _setpixel(x,y);
  72. ;
  73. ; u += du_dx;
  74. ; v += dv_dx;
  75. ; z += dz_dx;
  76. ; }
  77. align 4
  78. asm_tmap_scanline_lin_ld_:
  79. pusha
  80. ; Setup for loop: _loop_count iterations = (int) xright - (int) xleft
  81. ; esi source pixel pointer = pixptr
  82. ; edi initial row pointer = y*320+x
  83. ; set esi = pointer to start of texture map data
  84. mov esi,_pixptr
  85. ; set edi = address of first pixel to modify
  86. mov edi,_fx_y
  87. cmp edi,_window_bottom
  88. ja _none_to_do
  89. imul edi,_bytes_per_row
  90. mov eax,_fx_xleft
  91. sar eax,16
  92. jns eax_ok
  93. sub eax,eax
  94. eax_ok:
  95. add edi,eax
  96. add edi,write_buffer
  97. ; set _loop_count = # of iterations
  98. mov eax,_fx_xright
  99. sar eax,16
  100. cmp eax,_window_right
  101. jb eax_ok1
  102. mov eax,_window_right
  103. eax_ok1: cmp eax,_window_left
  104. ja eax_ok2
  105. mov eax,_window_left
  106. eax_ok2:
  107. mov ebx,_fx_xleft
  108. sar ebx,16
  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 ebx,_fx_u
  118. mov ebp,_fx_v
  119. shl ebx,10
  120. shl ebp,10
  121. shl _fx_du_dx,10
  122. shl _fx_dv_dx,10
  123. ; rgb values are passed in the following peculiar, confidential, trade secreted, copyrighted, patented format:
  124. ; [ 5 bits ] [ 5 bits ] [ 5 bits ] [ 5 bits ] [ 2 bits ] [ 5 bits ] [ 5 bits ]
  125. ; red int red frac blue int blue frac unused green int green frac
  126. ; The reason they are stored in the order red, blue, green is to optimize the process of packing together the three 5 bit
  127. ; values for red, green, blue in the conventional manner, suitable for an inverse table lookup
  128. ; convert fixed point values in _fx_dr_dx, _fx_dg_dx, _fx_db_dx to _fx_drgb_dx
  129. mov eax,_fx_dg_dx ; get green value
  130. sar eax,11 ; after shift, low order 10 bits are what we want
  131. jns dgok1
  132. inc eax
  133. dgok1: shrd ecx,eax,10 ; shift green 5i.5f into destination
  134. shr ecx,2 ; shift in two don't care bits
  135. mov eax,_fx_db_dx
  136. sar eax,11
  137. jns dbok1
  138. inc eax
  139. dbok1: shrd ecx,eax,10
  140. mov eax,_fx_dr_dx
  141. sar eax,11
  142. jns drok1
  143. inc eax
  144. drok1: shrd ecx,eax,10 ; now %ecx is correct!
  145. mov _fx_drgb_dx,ecx
  146. ; convert fixed point values in _fx_r, _fx_g, _fx_b to _fx_rgb (which is the above peculiar format)
  147. mov eax,_fx_g ; get green value
  148. sar eax,11 ; after shift, low order 10 bits are what we want
  149. jns rok1
  150. sub eax,eax
  151. rok1: shrd ecx,eax,10 ; shift green 5i.5f into destination
  152. shr ecx,2 ; shift in two don't care bits
  153. mov eax,_fx_b
  154. sar eax,11
  155. jns bok1
  156. sub eax,eax
  157. bok1: shrd ecx,eax,10
  158. mov eax,_fx_r
  159. sar eax,11
  160. jns gok1
  161. sub eax,eax
  162. gok1: shrd ecx,eax,10 ; now %ecx is correct!
  163. ; double deltas because we are only writing half as many pixels
  164. sal _fx_du_dx,1
  165. sal _fx_dv_dx,1
  166. sal _fx_drgb_dx,1
  167. ; ---------- Check x and y coords to figure whether to write pixel:light or light:pixel ----------
  168. mov eax,_fx_xleft ; get x coordinate
  169. shr eax,16 ; preserve only integer portion
  170. xor eax,_fx_y ; get checkerboard status
  171. shr eax,1 ; if cy set, then we were odd, else even
  172. jc _xy_odd
  173. ; even case, write pixel:light
  174. test edi,1 ; even align to start
  175. je _even1 ; we are already even aligned
  176. ; we are going to write to an odd address, so write pixel first
  177. ; do the regular texture mapper linear interpolation to get the pixel from the source bitmap
  178. sub edx,edx
  179. shld edx,ebp,6 ; shift in v coordinate
  180. add ebp,_fx_dv_dx ; update v coordinate
  181. shld edx,ebx,6 ; shift in u coordinate while shifting up v coordinate
  182. add ebx,_fx_du_dx ; update u coordinate
  183. mov al,[esi+edx] ; get pixel from source bitmap
  184. ; write the pixel
  185. mov [edi],al ; write texture map pixel, then red value
  186. inc edi
  187. dec _loop_count
  188. js _none_to_do ; all done
  189. inc _loop_count
  190. shr _loop_count,1
  191. je _odd_do_last_pixel ; want to write light for last pixel
  192. pushf
  193. jmp write_light_pixel_loop
  194. _even1:
  195. ; now write all the double pixels, light, then pixel
  196. inc _loop_count
  197. shr _loop_count,1
  198. je _even_do_last_pixel
  199. pushf
  200. ; usage:
  201. ; eax work
  202. ; ebx u coordinate
  203. ; ecx rgb (actually rbg, each i5.f5 with 2 bits between blue and green)
  204. ; edx work
  205. ; ebp v coordinate
  206. ; esi pointer to source bitmap
  207. ; edi write address
  208. ; do all but the last pixel in the unwound loop, last pixel done separately because less work is needed
  209. ; interpolate the rgb values
  210. write_pixel_light_loop:
  211. _loop1: sub eax,eax
  212. shld eax,ecx,4 ; shift in high 4 bits of red gun
  213. add ecx,_fx_drgb_dx
  214. mov ah,_reds_16[eax] ; get color index for 4 bit red value
  215. ; do the regular texture mapper linear interpolation to get the pixel from the source bitmap
  216. sub edx,edx
  217. shld edx,ebp,6 ; shift in v coordinate
  218. add ebp,_fx_dv_dx ; update v coordinate
  219. shld edx,ebx,6 ; shift in u coordinate while shifting up v coordinate
  220. add ebx,_fx_du_dx ; update u coordinate
  221. mov al,[esi+edx] ; get pixel from source bitmap
  222. ; write the pixel
  223. mov [edi],ax ; write texture map pixel, then red value
  224. add edi,2
  225. dec _loop_count
  226. jne _loop1
  227. popf
  228. jnc _none_to_do
  229. ; now do the leftover pixel
  230. ; do the regular texture mapper linear interpolation to get the pixel from the source bitmap
  231. _even_do_last_pixel:
  232. sub edx,edx
  233. shld edx,ebp,6 ; shift in v coordinate
  234. shld edx,ebx,6 ; shift in u coordinate while shifting up v coordinate
  235. mov al,[esi+edx] ; get pixel from source bitmap
  236. ; write the pixel
  237. mov [edi],al
  238. _none_to_do: popa
  239. ret
  240. _xy_odd:
  241. ; even case, write pixel:light
  242. test edi,1 ; even align to start
  243. je _even2 ; we are already even aligned
  244. ; we are going to write to an odd address, so write light first
  245. sub eax,eax
  246. shld eax,ecx,4 ; shift in high 4 bits of red gun
  247. add ecx,_fx_drgb_dx
  248. mov al,_reds_16[eax] ; get color index for 4 bit red value
  249. mov [edi],al ; write texture map pixel, then red value
  250. inc edi
  251. dec _loop_count
  252. js _done2 ; all done
  253. ; now write all the double pixels, light, then pixel
  254. inc _loop_count
  255. shr _loop_count,1
  256. je _even_do_last_pixel
  257. pushf
  258. jmp write_pixel_light_loop
  259. _even2:
  260. ; now write all the double pixels, light, then pixel
  261. inc _loop_count
  262. shr _loop_count,1
  263. je _odd_do_last_pixel
  264. pushf
  265. ; usage:
  266. ; eax work
  267. ; ebx u coordinate
  268. ; ecx rgb (actually rbg, each i5.f5 with 2 bits between blue and green)
  269. ; edx work
  270. ; ebp v coordinate
  271. ; esi pointer to source bitmap
  272. ; edi write address
  273. ; do all but the last pixel in the unwound loop, last pixel done separately because less work is needed
  274. ; interpolate the rgb values
  275. write_light_pixel_loop:
  276. _loop2: sub eax,eax
  277. shld eax,ecx,4 ; shift in high 4 bits of red gun
  278. add ecx,_fx_drgb_dx
  279. mov al,_reds_16[eax] ; get color index for 4 bit red value
  280. ; do the regular texture mapper linear interpolation to get the pixel from the source bitmap
  281. sub edx,edx
  282. shld edx,ebp,6 ; shift in v coordinate
  283. add ebp,_fx_dv_dx ; update v coordinate
  284. shld edx,ebx,6 ; shift in u coordinate while shifting up v coordinate
  285. add ebx,_fx_du_dx ; update u coordinate
  286. mov ah,[esi+edx] ; get pixel from source bitmap
  287. ; write the pixel
  288. mov [edi],ax ; write texture map pixel, then red value
  289. add edi,2
  290. dec _loop_count
  291. jne _loop2
  292. popf
  293. jnc _done2
  294. ; now do the leftover light pixel
  295. _odd_do_last_pixel:
  296. sub eax,eax
  297. shld eax,ecx,4 ; shift in high 4 bits of red gun
  298. mov al,_reds_16[eax] ; get color index for 4 bit red value
  299. mov [edi],al ; write texture map pixel, then red value
  300. _done2:
  301. popa
  302. ret
  303. _TEXT ends
  304. end