TMAP_16G.ASM 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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_16g.asm $
  13. ; $Revision: 1.4 $
  14. ; $Author: mike $
  15. ; $Date: 1994/11/30 00:56:37 $
  16. ;
  17. ; inner loop of rgb lighted linear texture mapper for 16 bits/pixel
  18. ;
  19. ; $Log: tmap_16g.asm $
  20. ; Revision 1.4 1994/11/30 00:56:37 mike
  21. ; optimization.
  22. ;
  23. ; Revision 1.3 1994/11/12 16:39:23 mike
  24. ; jae to ja.
  25. ;
  26. ; Revision 1.2 1993/11/22 10:24:28 mike
  27. ; *** empty log message ***
  28. ;
  29. ; Revision 1.1 1993/09/08 17:29:17 mike
  30. ; Initial revision
  31. ;
  32. ;
  33. ;
  34. .386
  35. option oldstructs
  36. .nolist
  37. include psmacros.inc
  38. .list
  39. public asm_tmap_scanline_lin_rgb_16g_
  40. include tmap_inc.asm
  41. _DATA SEGMENT DWORD PUBLIC USE32 'DATA'
  42. extd _fx_u
  43. extd _fx_v
  44. extd _fx_du_dx
  45. extd _fx_dv_dx
  46. extd _fx_y
  47. extd _fx_xleft
  48. extd _fx_xright
  49. extd _pixptr
  50. extd _x
  51. extd _loop_count
  52. extd _fx_rgb,_fx_drgb_dx
  53. extd _fx_r,_fx_g,_fx_b,_fx_dr_dx,_fx_dg_dx,_fx_db_dx
  54. align 4
  55. _DATA ENDS
  56. DGROUP GROUP _DATA
  57. _TEXT SEGMENT PARA PUBLIC USE32 'CODE'
  58. ASSUME DS:_DATA
  59. ASSUME CS:_TEXT
  60. ; --------------------------------------------------------------------------------------------------
  61. ; Enter:
  62. ; _xleft fixed point left x coordinate
  63. ; _xright fixed point right x coordinate
  64. ; _y fixed point y coordinate
  65. ; _pixptr address of source pixel map
  66. ; _u fixed point initial u coordinate
  67. ; _v fixed point initial v coordinate
  68. ; _du_dx fixed point du/dx
  69. ; _dv_dx fixed point dv/dx
  70. ; for (x = (int) xleft; x <= (int) xright; x++) {
  71. ; _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
  72. ; _setpixel(x,y);
  73. ;
  74. ; u += du_dx;
  75. ; v += dv_dx;
  76. ; z += dz_dx;
  77. ; }
  78. align 4
  79. asm_tmap_scanline_lin_rgb_16g_:
  80. pusha
  81. ; Setup for loop: _loop_count iterations = (int) xright - (int) xleft
  82. ; esi source pixel pointer = pixptr
  83. ; edi initial row pointer = y*320+x
  84. ; set esi = pointer to start of texture map data
  85. mov esi,_pixptr
  86. ; set edi = address of first pixel to modify
  87. mov edi,_fx_y
  88. cmp edi,_window_bottom
  89. ja _none_to_do
  90. sub edi,_window_top
  91. imul edi,_bytes_per_row
  92. mov eax,_fx_xleft
  93. sar eax,16
  94. jns eax_ok
  95. sub eax,eax
  96. eax_ok:
  97. sub eax,_window_left
  98. add edi,eax
  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. ; shift up all light values and deltas so that the highest 5 bits are the integer portion
  122. shl _fx_r,11
  123. shl _fx_g,11
  124. shl _fx_b,11
  125. shl _fx_dr_dx,11
  126. shl _fx_dg_dx,11
  127. shl _fx_db_dx,11
  128. ; ---------------------------------------------------------------------------------------------------------------------
  129. mov eax,_fx_g
  130. mov edx,_fx_b
  131. mov ebx,_fx_r
  132. mov ebp,_fx_dr_dx
  133. mov esi,_fx_dg_dx
  134. ; register usage:
  135. ; eax _fx_g
  136. ; ebx _fx_r
  137. ; ecx work
  138. ; edx _fx_b
  139. ; ebp _fx_dr_dx
  140. ; esi _fx_dg_dx
  141. ; edi write address
  142. ; do the regular texture mapper linear interpolation to get the pixel from the source bitmap
  143. _loop1:
  144. mov ecx,ebx ; light value in high 5 bits
  145. shr ecx,27 ; shift out all but light value
  146. shld ecx,eax,5
  147. shld ecx,edx,5
  148. ; now %ecx = r|g|b, each 5 bits, bit #15 clear, write the pixel
  149. mov [edi],cx
  150. add edi,2
  151. ; now add the deltas
  152. add ebx,ebp
  153. add eax,esi
  154. add edx,_fx_db_dx
  155. dec _loop_count
  156. jns _loop1
  157. ; ---------------------------------------------------------------------------------------------------------------------
  158. _none_to_do: popa
  159. ret
  160. ; -- Code to get rgb 5 bits integer, 5 bits fraction value into 5 bits integer (for each gun)
  161. ; suitable for inverse color lookup
  162. ;**__test:
  163. ;** int 3
  164. ;**; rrrrrfffffrrrrrfffffxxbbbbbfffff
  165. ;** mov eax,11111001001010101110101101110111b
  166. ;** and eax,11111000001111100000001111100000b
  167. ;** shld ebx,eax,15
  168. ;** or bx,ax
  169. _TEXT ends
  170. end