TMAP_QLN.ASM 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  11. .386
  12. option oldstructs
  13. .nolist
  14. include pstypes.inc
  15. include psmacros.inc
  16. include tmap_inc.asm
  17. .list
  18. assume cs:_TEXT, ds:_DATA
  19. _DATA segment para public USE32 'DATA'
  20. rcsid db "$Id: tmap_qln.asm 1.1 1996/02/01 14:52:06 matt Exp $"
  21. _DATA ends
  22. _TEXT segment para public USE32 'CODE'
  23. align 16
  24. public asm_tmap_scanline_qln_
  25. asm_tmap_scanline_qln_:
  26. NBITS = 5 ; Divide every 32 pixels
  27. START_TIMER
  28. push eax
  29. push ecx
  30. push edx
  31. push ebx
  32. push ebp
  33. push esi
  34. push edi
  35. ;---------------------------- setup for loop ---------------------------------
  36. ; Setup for loop: _loop_count iterations = (int) xright - (int) xleft
  37. ; esi source pixel pointer = pixptr
  38. ; edi initial row pointer = y*320+x
  39. ; NOTE: fx_xright and fx_xleft changed from fix to int by mk on 12/01/94.
  40. ; set esi = pointer to start of texture map data
  41. ; set edi = address of first pixel to modify
  42. mov edi, _dest_row_data
  43. ; set initial values
  44. mov ebx,_fx_u
  45. mov ebp,_fx_v
  46. mov ecx,_fx_z
  47. INVERT_ECX
  48. ; compute initial v coordinate
  49. mov eax,ebp ; get v
  50. PDIV
  51. mov V0, eax
  52. ; compute initial u coordinate
  53. mov eax,ebx ; get u
  54. PDIV
  55. mov U0, eax
  56. mov ecx,_fx_z
  57. ; find number of subdivisions
  58. mov eax, _loop_count
  59. inc eax
  60. mov esi, eax
  61. and esi, (1 shl NBITS) - 1
  62. sar eax, NBITS
  63. mov num_left_over, esi
  64. jz DoEndPixels ;there are no 2^NBITS chunks, do divide/pixel for whole scanline
  65. mov _loop_count, eax
  66. ; Set deltas to NPIXS pixel increments
  67. mov eax, _fx_du_dx
  68. shl eax, NBITS
  69. mov DU1, eax
  70. mov eax, _fx_dv_dx
  71. shl eax, NBITS
  72. mov DV1, eax
  73. mov eax, _fx_dz_dx
  74. shl eax, NBITS
  75. mov DZ1, eax
  76. align 4
  77. TopOfLoop4:
  78. add ebx, DU1
  79. add ebp, DV1
  80. add ecx, DZ1
  81. ; Done with ebx, ebp, ecx until next iteration
  82. push ebx
  83. push ecx
  84. push ebp
  85. push edi
  86. INVERT_ECX
  87. ; Find fixed U1
  88. mov eax, ebx
  89. PDIV
  90. mov ebx, eax ; ebx = U1 until pop's
  91. ; Find fixed V1
  92. mov eax, ebp
  93. PDIV
  94. mov ebp, eax ; ebx = V1 until pop's
  95. ; Get last correct U,Vs
  96. mov ecx, U0 ; ecx = U0 until pop's
  97. mov edi, V0 ; edi = V0 until pop's
  98. ; Make ESI = V0:U0 in 6:10,6:10 format
  99. mov eax, edi
  100. shr eax, 6
  101. mov esi, ecx
  102. shl esi, 10
  103. mov si, ax
  104. ; Make EDX = DV:DU in 6:10,6:10 format
  105. mov eax, ebp
  106. sub eax, edi
  107. sar eax, NBITS+6
  108. mov edx, ebx
  109. sub edx, ecx
  110. shl edx, 10-NBITS ; EDX = V1-V0/ 4 in 6:10 int:frac
  111. mov dx, ax ; put delta u in low word
  112. ; Save the U1 and V1 so we don't have to divide on the next iteration
  113. mov U0, ebx
  114. mov V0, ebp
  115. pop edi ; Restore EDI before using it
  116. ; LIGHTING CODE
  117. mov ebx, _fx_l
  118. mov ebp, _fx_dl_dx
  119. mov ecx, _pixptr
  120. COUNT = 0
  121. REPT (1 SHL NBITS)
  122. mov eax, esi ; get u,v
  123. shr ax, 10 ; shift out frac(v)
  124. rol eax, 6 ; shift int(u) into low eax
  125. and eax, 0ffffh ; clear upper bits of eax
  126. add esi, edx ; inc u,v
  127. mov al, [eax+ecx] ; get pixel from source bitmap
  128. mov ah, bh ; form lighting table lookup value
  129. add ebx, ebp ; update lighting value
  130. mov al, _gr_fade_table[eax] ; xlat thru lighting table into dest buffer
  131. mov [edi+COUNT],al ; Draw 4 pixels to display
  132. COUNT = COUNT + 1
  133. ENDM
  134. add edi,COUNT
  135. mov _fx_l, ebx ; Save current lighting value
  136. pop ebp
  137. pop ecx
  138. pop ebx
  139. dec _loop_count
  140. jnz TopOfLoop4
  141. EndOfLoop4:
  142. test num_left_over, -1
  143. je _none_to_do
  144. cmp num_left_over, 4
  145. ja DoEndPixels
  146. ; If less than 4, then just keep interpolating without
  147. ; calculating a new DU:DV.
  148. mov ebx, _fx_l
  149. mov ebp, _fx_dl_dx
  150. mov ecx, _pixptr
  151. jmp FinishOff
  152. ; ----------------------------------------- Start of LeftOver Pixels ------------------------------------------
  153. DoEndPixels:
  154. push edi
  155. mov ecx, _fx_z_right
  156. INVERT_ECX
  157. ; Find fixed U1
  158. mov eax, _fx_u_right
  159. PDIV
  160. mov ebx, eax ; ebx = U1 until pop's
  161. ; Find fixed V1
  162. mov eax, _fx_v_right
  163. PDIV
  164. mov ebp, eax ; ebp = V1 until pop's
  165. mov ecx, U0 ; ecx = U0 until pop's
  166. mov edi, V0 ; edi = V0 until pop's
  167. ; Make EDX = DV:DU in 6:10,6:10 format
  168. mov eax, ebx
  169. sub eax, ecx
  170. mov edx, eax ; These two lines are faster than cdq
  171. sar edx, 31
  172. idiv num_left_over ; eax = (v1-v0)/num_left_over
  173. shl eax, 16-6 ; go from 16.16 to 6.10, and move into high 16 bits
  174. mov esi, eax ; esi = dvdx<<16
  175. mov eax, ebp
  176. sub eax, edi
  177. mov edx, eax ; These two lines are faster than cdq
  178. sar edx, 31
  179. idiv num_left_over ; eax = (u1-u0)/num_left_over
  180. sar eax, 6 ; go from 16.16 to 6.10 (ax=dvdx in 6.10)
  181. mov si, ax ; esi = dvdx:dudx
  182. mov edx, esi
  183. ; Make ESI = V0:U0 in 6:10,6:10 format
  184. mov eax, edi
  185. shr eax, 6
  186. mov esi, ecx
  187. shl esi, 10
  188. mov si, ax
  189. pop edi ; Restore EDI before using it
  190. ; LIGHTING CODE
  191. mov ebx, _fx_l
  192. mov ebp, _fx_dl_dx
  193. mov ecx, _pixptr
  194. FinishOff:
  195. COUNT = 0
  196. REPT (1 SHL NBITS)
  197. mov eax, esi ; get u,v
  198. shr ax, 10 ; shift out frac(v)
  199. rol eax, 6 ; shift int(u) into low eax
  200. and eax, 0ffffh ; clear upper bits of eax
  201. add esi, edx ; inc u,v
  202. mov al, [eax+ecx] ; get pixel from source bitmap
  203. mov ah, bh ; form lighting table lookup value
  204. add ebx, ebp ; update lighting value
  205. mov al, _gr_fade_table[eax] ; xlat thru lighting table into dest buffer
  206. dec num_left_over
  207. mov [edi+COUNT],al ; Draw 4 pixels to display
  208. COUNT = COUNT + 1
  209. jz _none_to_do
  210. ENDM
  211. _none_to_do:
  212. pop edi
  213. pop esi
  214. pop ebp
  215. pop ebx
  216. pop edx
  217. pop ecx
  218. pop eax
  219. STOP_TIMER
  220. ret
  221. _TEXT ends
  222. end