TMAP_PLN.ASM 6.4 KB

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