JOHN.ASM 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  11. align 4
  12. TopOfLoop4:
  13. add ebx, DU1
  14. add ebp, DV1
  15. add ecx, DZ1
  16. ; Done with ebx, ebp, ecx until next iteration
  17. push ebx
  18. push ecx
  19. push ebp
  20. push edi
  21. ; Find fixed U1
  22. mov eax, ebx
  23. PDIV
  24. mov ebx, eax ; ebx = U1 until pop's
  25. ; Find fixed V1
  26. mov eax, ebp
  27. PDIV
  28. mov ebp, eax ; ebp = V1 until pop's
  29. mov ecx, U0 ; ecx = U0 until pop's
  30. mov edi, V0 ; edi = V0 until pop's
  31. ; Make ESI = V0:U0 in 6:10,6:10 format
  32. mov eax, ecx
  33. shr eax, 6
  34. mov esi, edi
  35. shl esi, 10
  36. mov si, ax
  37. ; Make EDX = DV:DU in 6:10,6:10 format
  38. mov eax, ebx
  39. sub eax, ecx
  40. sar eax, NBITS+6
  41. mov edx, ebp
  42. sub edx, edi
  43. shl edx, 10-NBITS ; EDX = V1-V0/ 4 in 6:10 int:frac
  44. mov dx, ax ; put delta u in low word
  45. ; Save the U1 and V1 so we don't have to divide on the next iteration
  46. mov U0, ebx
  47. mov V0, ebp
  48. pop edi ; Restore EDI before using it
  49. ; LIGHTING CODE
  50. mov ebx, _fx_l
  51. mov ebp, _fx_dl_dx1
  52. REPT (1 SHL (NBITS-2))
  53. REPT 2
  54. mov eax, esi ; get u,v
  55. shr eax, 26 ; shift out all but int(v)
  56. shld ax,si,6 ; shift in u, shifting up v
  57. add esi, edx ; inc u,v
  58. mov al, es:[eax] ; get pixel from source bitmap
  59. mov ah, bh ; form lighting table lookup value
  60. add ebx, ebp ; update lighting value
  61. mov cl, fs:[eax] ; xlat thru lighting table into dest buffer
  62. ; eax = 0
  63. ; ebx = l in fixed 24.8 (really 8.8)
  64. ; ecx = (dv << 16) | du (in fixed 8.8)
  65. ; edx = free
  66. ; esi = ptr to source bitmap
  67. ; edi = destination ptr
  68. ; ebp = dldx (in fixed 24.8) (really 8.8)
  69. ; MEM [0..3] = (u<<16) | v (in fixed 8.8)
  70. ; Code for 8-bit destination, lighting
  71. mov al, [0] ; get u
  72. mov ah, [2] ; get v
  73. add [0], ecx ; inc u,v
  74. mov al, [esi+eax] ; get source pixel
  75. mov ah, bh ; form lighting lookup value
  76. mov al, FadeTable[eax] ; get lit pixel
  77. mov ah, [edi] ; get prev pixel
  78. mov al, Transparent[eax] ; get transluscent pixel value
  79. mov [edi], al ; write pixel to frame buffer
  80. inc edi ; inc dest
  81. add ebx, ebp ; inc lighting value
  82. ; Code for 8-bit destination, no lighting
  83. mov al, [0] ; get u
  84. mov ah, [2] ; get v
  85. add [0], ecx ; inc u,v
  86. mov al, [esi+eax] ; get source pixel
  87. mov [edi], al ; write pixel to frame buffer
  88. inc edi ; inc dest
  89. add ebx, ebp ; inc dl
  90. ; old way
  91. mov eax,ebp ; clear for
  92. add ebp,edx ; update v coordinate
  93. shr eax,26 ; shift in v coordinate
  94. shld eax,ebx,6 ; shift in u coordinate while shifting up v coordinate
  95. add ebx,ecx ; update u coordinate
  96. mov al,[esi+eax] ; get pixel from source bitmap
  97. mov [edi],al
  98. inc edi
  99. ; Code for 15-bit destination, with fade table in hardware
  100. mov al, ch ; get u,v
  101. mov ah, dh ;
  102. mov al, es:[eax]
  103. mov ah, bh
  104. mov [edi], ax ; write pixel to frame buffer
  105. add edi, 2
  106. add ecx, esi
  107. bswap esi
  108. add edx, esi
  109. bswap esi
  110. add ebx, ebp
  111. ; Code for 15-bit destination, with RGB 15 bit in hardware...
  112. mov al, ch ; get u,v
  113. mov ah, dh ;
  114. mov al, es:[eax]
  115. mov ah, bh
  116. mov ax, gs:[eax*2]
  117. mov [edi], ax ; write pixel to frame buffer
  118. add edi, 2
  119. add ecx, esi
  120. bswap esi
  121. add edx, esi
  122. bswap esi
  123. add ebx, ebp
  124. mov eax, esi ; get u,v
  125. shr eax, 26 ; shift out all but int(v)
  126. shld ax,si,6 ; shift in u, shifting up v
  127. add esi, edx ; inc u,v
  128. mov al, es:[eax] ; get pixel from source bitmap
  129. mov ah, bh ; form lighting table lookup value
  130. esi, ebp
  131. esi, ebp,
  132. ; Do odd pixel
  133. mov eax, esi ; get u,v
  134. shr eax, 26 ; shift out all but int(v)
  135. shld ax,si,6 ; shift in u, shifting up v
  136. add esi, edx ; inc u,v
  137. mov al, es:[eax] ; get pixel from source bitmap
  138. mov ah, bh ; form lighting table lookup value
  139. add ebx, ebp ; update lighting value
  140. mov ch, fs:[eax] ; xlat thru lighting table into dest buffer
  141. ror ecx, 16 ; move to next double dest pixel position
  142. ENDM
  143. mov [edi],ecx ; Draw 4 pixels to display
  144. add edi,4
  145. ENDM
  146. ; LIGHTING CODE
  147. mov _fx_l, ebx
  148. pop ebp
  149. pop ecx
  150. pop ebx
  151. dec _loop_count
  152. jnz TopOfLoop4
  153. mov eax, esi ; get u,v
  154. shr eax, 26 ; shift out all but int(v)
  155. shld ax,si,6 ; shift in u, shifting up v
  156. add esi, edx ; inc u,v
  157. mov al, es:[eax] ; get pixel from source bitmap
  158. cmp al,255
  159. je skipa1
  160. mov ah, bh ; form lighting table lookup value
  161. add ebx, ebp ; update lighting value
  162. mov al, fs:[eax] ; xlat thru lighting table into dest buffer
  163. mov [edi],al
  164. mov eax, esi ; get u,v
  165. shr eax, 26 ; shift out all but int(v)
  166. shld ax,si,6 ; shift in u, shifting up v
  167. add esi, edx ; inc u,v
  168. mov al, es:[eax] ; get pixel from source bitmap
  169. mov ah, bh ; form lighting table lookup value
  170. add ebx, ebp ; update lighting value
  171. mov al, fs:[eax] ; xlat thru lighting table into dest buffer
  172. mov ah, [edi] ; get pixel already drawn here
  173. mov al, gs:[eax] ; lookup in translation table
  174. mov [edi],al ; write pixel
  175. ; Code for 8-bit destination, lighting, transluscency
  176. mov dx, [edi]
  177. mov al, [0] ; get u
  178. mov ah, [2] ; get v
  179. add [0], ecx ; inc u,v
  180. mov al, [esi+eax] ; get source pixel
  181. mov ah, bh ; form lighting lookup value
  182. mov al, FadeTable[eax] ; get lit pixel
  183. mov ah, dl ; get prev pixel
  184. add ebx, ebp ; inc lighting value
  185. mov dl, TransTable[eax] ; get transluscent pixel value
  186. mov al, [0] ; get u
  187. mov ah, [2] ; get v
  188. add [0], ecx ; inc u,v
  189. mov al, [esi+eax] ; get source pixel
  190. mov ah, bh ; form lighting lookup value
  191. mov al, FadeTable[eax] ; get lit pixel
  192. mov ah, dh ; get prev pixel
  193. add ebx, ebp ; inc lighting value
  194. mov dh, TransTable[eax] ; get transluscent pixel value
  195. mov [edi], dx ; write 2 pixels to frame buffer
  196. inc edi ; move to next pixel
  197. inc edi ; move to next pixel
  198. ; compute v coordinate
  199. mov eax,ebp ; get v
  200. cdq
  201. idiv ecx ; eax = (v/z)
  202. and eax,3fh ; mask with height-1
  203. mov ebx,eax
  204. ; compute u coordinate
  205. mov eax,esi ; get u
  206. cdq
  207. idiv ecx ; eax = (u/z)
  208. shl eax,26
  209. shld ebx,eax,6 ; ebx = v*64+u
  210. ; read 1 pixel
  211. movzx eax,byte ptr es:[ebx] ; get pixel from source bitmap
  212. ; LIGHTING CODE
  213. mov ebx, _fx_l ; get temp copy of lighting value
  214. mov ah, bh ; get lighting level
  215. add ebx, _fx_dl_dx ; update lighting value
  216. mov al, fs:[eax] ; xlat pixel thru lighting tables
  217. mov _fx_l, ebx ; save temp copy of lighting value
  218. mov [edi],al
  219. inc edi
  220. ; update deltas
  221. add ebp,_fx_dv_dx
  222. add esi,_fx_du_dx
  223. add ecx,_fx_dz_dx
  224. xchg esi, ebx
  225. dec _loop_count
  226. jns tmap_loop
  227. fix fixdiv(fix a,fix b);
  228. #pragma aux fixdiv parm [eax] [ebx] modify exact [eax edx] = \
  229. "cdq " \
  230. "idiv ebx" \
  231. fix u = u0;
  232. fix v = v0;
  233. fix z = z0;
  234. fix l = l0;
  235. for ( x=x1; x<=x2; x++ ) {
  236. if ( z < zbuffer[x] ) {
  237. zbuffer[x] = z;
  238. color = bitmap[(u/z)&63][(v/z)&63];
  239. if ( color != xparent ) {
  240. color = LightingTable[color][f2i(l)&31];
  241. pixel[x] = color;
  242. }
  243. }
  244. u += du;
  245. v += dv;
  246. z += dz;
  247. l += dl;
  248. }
  249. ;================ PERSPECTIVE TEXTURE MAP INNER LOOPS ========================
  250. ;
  251. ; Usage in loop:
  252. ; eax division, pixel value
  253. ; ebx source pixel pointer
  254. ; ecx z
  255. ; edx division
  256. ; ebp v
  257. ; esi u
  258. ; edi destination pixel pointer
  259. rept niters
  260. mov eax, [_fx_z] ; get z-value
  261. cmp zbuffer[edi], eax ; check if closer
  262. jge skip1 ; don't do if z farther away
  263. mov zbuffer[edi], eax ; update z-buffer
  264. mov eax,[_fx_v] ; get v
  265. cdq ; sign extend into edx:eax
  266. idiv [_fx_z] ; eax = (v/z)
  267. and eax,63 ; mask with height-1
  268. mov ebx,eax ; start build bitmap address
  269. mov eax,[_fx_u] ; get u
  270. cdq ; sign extend into edx:eax
  271. idiv [_fx_z] ; eax = (u/z)
  272. shl eax,26 ; continue building bitmap address
  273. shld ebx,eax,6 ; ebx = v*64+u
  274. mov al,byte ptr es:[ebx] ; get pixel from source bitmap
  275. cmp al,255 ; check if it's transparent
  276. je skip1 ; don't write if transparent
  277. mov bx, [_fx_l] ; get lighting value
  278. mov bl, al ; build lighting table lookup index
  279. mov al, lighting[ebx] ; lookup lighting value
  280. mov video[edi],al ; write the pixel
  281. skip1: inc edi ; go to next pixel address
  282. add [_fx_l],[_fx_dl_dx] ; increment lighting
  283. add [_fx_u],[_fx_du_dx] ; increment u
  284. add [_fx_v],[_fx_dv_dx] ; incrememt v
  285. add [_fx_z],[_fx_dz_dx] ; increment z
  286. je _div_0_abort ; would be dividing by 0, so abort
  287. endm
  288. mov eax, F1_0
  289. mov ebx, [z]
  290. mov edx,eax
  291. sar edx,16
  292. shl eax,16
  293. idiv ebx
  294. "imul edx" \
  295. "shrd eax,edx,16";
  296. // assume 8.12 fixed point
  297. rept niters
  298. mov eax, [_fx_z] ; get z-value
  299. cmp zbuffer[edi], eax ; check if closer
  300. jge skip1 ; don't do if z farther away
  301. mov zbuffer[edi], eax ; update z-buffer
  302. mov eax,[_fx_v] ; get v
  303. cdq
  304. idiv eax, [z]
  305. mov ebx,eax ; start build bitmap address
  306. mov eax,[_fx_u] ; get u
  307. imul eax, [z]
  308. shl eax,26 ; continue building bitmap address
  309. shld ebx,eax,6 ; ebx = v*64+u
  310. mov al,byte ptr es:[ebx] ; get pixel from source bitmap
  311. cmp al,255 ; check if it's transparent
  312. je skip1 ; don't write if transparent
  313. mov bx, [_fx_l] ; get lighting value
  314. mov bl, al ; build lighting table lookup index
  315. mov al, lighting[ebx] ; lookup lighting value
  316. mov video[edi],al ; write the pixel
  317. skip1: inc edi ; go to next pixel address
  318. add [_fx_l],[_fx_dl_dx] ; increment lighting
  319. add [_fx_u],[_fx_du_dx] ; increment u
  320. add [_fx_v],[_fx_dv_dx] ; incrememt v
  321. add [_fx_z],[_fx_dz_dx] ; increment z
  322. je _div_0_abort ; would be dividing by 0, so abort
  323. endm
  324. ;================ PERSPECTIVE TEXTURE MAP INNER LOOPS ========================
  325. ;
  326. ; Usage in loop:
  327. ; eax division, pixel value
  328. ; ebx source pixel pointer
  329. ; ecx z
  330. ; edx division
  331. ; ebp v
  332. ; esi u
  333. ; edi destination pixel pointer
  334. rept niters
  335. cmp zbuffer[edi], ecx ; check if closer
  336. jge skip1 ; don't do if z farther away
  337. mov zbuffer[edi], ecx ; update z-buffer
  338. mov eax,[_fx_v] ; get v
  339. mov edx,[_fx_u] ; get u
  340. idiv ecx ; eax = (v/z)
  341. and eax,63 ; mask with height-1
  342. mov ebx,eax ; start build bitmap address
  343. mov eax,[_fx_u] ; get u
  344. cdq ; sign extend into edx:eax
  345. idiv ecx ; eax = (u/z)
  346. shl eax,26 ; continue building bitmap address
  347. shld ebx,eax,6 ; ebx = v*64+u
  348. mov al,byte ptr es:[ebx] ; get pixel from source bitmap
  349. cmp al,255 ; check if it's transparent
  350. je skip1 ; don't write if transparent
  351. mov bx, [_fx_l] ; get lighting value
  352. mov bl, al ; build lighting table lookup index
  353. mov al, lighting[ebx] ; lookup lighting value
  354. mov video[edi],al ; write the pixel
  355. skip1: inc edi ; go to next pixel address
  356. add [_fx_l],[_fx_dl_dx] ; increment lighting
  357. add [_fx_u],[_fx_du_dx] ; increment u
  358. add [_fx_v],[_fx_dv_dx] ; incrememt v
  359. add ecx,[_fx_dz_dx] ; increment z
  360. je _div_0_abort ; would be dividing by 0, so abort
  361. endm
  362.