TMAP_PNT.ASM 5.8 KB

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