TMAP_QLT.ASM 6.2 KB

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