TMAP_PLT.ASM 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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_plt.asm 1.2 1996/02/01 14:52:59 matt Exp $"
  21. align 4
  22. _DATA ends
  23. _TEXT segment para public USE32 'CODE'
  24. align 16
  25. extn asm_tmap_scanline_qlt_
  26. public asm_tmap_scanline_plt_
  27. asm_tmap_scanline_plt_:
  28. cmp _bytes_per_row, 320
  29. jbe @f
  30. jmp asm_tmap_scanline_qlt_
  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 ebx, _fx_l
  124. mov ebp, _fx_dl_dx
  125. mov ecx, _pixptr
  126. COUNT = 0
  127. REPT (1 SHL NBITS)
  128. mov eax, esi ; get u,v
  129. shr ax, 10 ; shift out frac(v)
  130. rol eax, 6 ; shift int(u) into low eax
  131. and eax, 0ffffh ; clear upper bits of eax
  132. add esi, edx ; inc u,v
  133. mov al, [eax+ecx] ; get pixel from source bitmap
  134. mov ah, bh ; form lighting table lookup value
  135. add ebx, ebp ; update lighting value
  136. cmp al, 255
  137. je @f
  138. mov al, _gr_fade_table[eax] ; xlat thru lighting table into dest buffer
  139. mov [edi+COUNT],al ; Draw 4 pixels to display
  140. @@:
  141. COUNT = COUNT + 1
  142. ENDM
  143. add edi,COUNT
  144. mov _fx_l, ebx ; Save current lighting value
  145. pop ebp
  146. pop ecx
  147. pop ebx
  148. dec _loop_count
  149. jnz TopOfLoop4
  150. EndOfLoop4:
  151. test num_left_over, -1
  152. je _none_to_do
  153. cmp num_left_over, 4
  154. ja DoEndPixels
  155. ; If less than 4, then just keep interpolating without
  156. ; calculating a new DU:DV.
  157. mov ebx, _fx_l
  158. mov ebp, _fx_dl_dx
  159. mov ecx, _pixptr
  160. jmp FinishOff
  161. ; ----------------------------------------- Start of LeftOver Pixels ------------------------------------------
  162. DoEndPixels:
  163. push edi
  164. mov ecx, _fx_z_right
  165. INVERT_ECX
  166. ; Find fixed U1
  167. mov eax, _fx_u_right
  168. PDIV
  169. mov ebx, eax ; ebx = U1 until pop's
  170. ; Find fixed V1
  171. mov eax, _fx_v_right
  172. PDIV
  173. mov ebp, eax ; ebp = V1 until pop's
  174. mov ecx, U0 ; ecx = U0 until pop's
  175. mov edi, V0 ; edi = V0 until pop's
  176. ; Make EDX = DV:DU in 6:10,6:10 format
  177. mov eax, ebx
  178. sub eax, ecx
  179. mov edx, eax ; These two lines are faster than cdq
  180. sar edx, 31
  181. idiv num_left_over ; eax = (v1-v0)/num_left_over
  182. shl eax, 16-6 ; go from 16.16 to 6.10, and move into high 16 bits
  183. mov esi, eax ; esi = dvdx<<16
  184. mov eax, ebp
  185. sub eax, edi
  186. mov edx, eax ; These two lines are faster than cdq
  187. sar edx, 31
  188. idiv num_left_over ; eax = (u1-u0)/num_left_over
  189. sar eax, 6 ; go from 16.16 to 6.10 (ax=dvdx in 6.10)
  190. mov si, ax ; esi = dvdx:dudx
  191. mov edx, esi
  192. ; Make ESI = V0:U0 in 6:10,6:10 format
  193. mov eax, edi
  194. shr eax, 6
  195. mov esi, ecx
  196. shl esi, 10
  197. mov si, ax
  198. pop edi ; Restore EDI before using it
  199. ; LIGHTING CODE
  200. mov ebx, _fx_l
  201. mov ebp, _fx_dl_dx
  202. mov ecx, _pixptr
  203. FinishOff:
  204. COUNT = 0
  205. REPT (1 SHL NBITS)
  206. mov eax, esi ; get u,v
  207. shr ax, 10 ; shift out frac(v)
  208. rol eax, 6 ; shift int(u) into low eax
  209. and eax, 0ffffh ; clear upper bits of eax
  210. add esi, edx ; inc u,v
  211. mov al, [eax+ecx] ; get pixel from source bitmap
  212. mov ah, bh ; form lighting table lookup value
  213. add ebx, ebp ; update lighting value
  214. cmp al, 255
  215. je @f
  216. mov al, _gr_fade_table[eax] ; xlat thru lighting table into dest buffer
  217. mov [edi+COUNT],al ; Draw 4 pixels to display
  218. @@: dec num_left_over
  219. COUNT = COUNT + 1
  220. jz _none_to_do
  221. ENDM
  222. _none_to_do:
  223. pop edi
  224. pop esi
  225. pop ebp
  226. pop ebx
  227. pop edx
  228. pop ecx
  229. pop eax
  230. STOP_TIMER
  231. ret
  232. _TEXT ends
  233. end