README.asm 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. README - DOOM assembly code
  2. Okay, I add the DOS assembly module for the historically
  3. inclined here (may rec.games.programmer suffer). If anyone
  4. feels the urge to port these to GNU GCC; either inline or
  5. as separate modules including Makefile support, be my guest.
  6. Module tmap.S includes the inner loops for texture mapping,
  7. the interesting one being the floor/ceiling span rendering.
  8. There was another module in the source dump, fpfunc.S, that
  9. had both texture mapping and fixed point functions. It
  10. contained implementations both for i386 and M68k. For
  11. brevity, I include only the i386 fixed point stuff below.
  12. //====================================================
  13. // tmap.S as of January 10th, 1997
  14. //================
  15. //
  16. // R_DrawColumn
  17. //
  18. //================
  19. .data
  20. loopcount .long 0
  21. pixelcount .long 0
  22. .text
  23. .align 16
  24. .globl _R_DrawColumn
  25. _R_DrawColumn:
  26. pushad
  27. movl ebp,[_dc_yl]
  28. movl ebx,ebp
  29. movl edi,[_ylookup+ebx*4]
  30. movl ebx,[_dc_x]
  31. addl edi,[_columnofs + ebx*4]
  32. movl eax,[_dc_yh]
  33. incl eax
  34. subl eax,ebp // pixel count
  35. movl [pixelcount],eax // save for final pixel
  36. js done // nothing to scale
  37. shrl eax,1 // double pixel count
  38. movl [loopcount],eax
  39. movl ecx,[_dc_iscale]
  40. movl eax,[_centery]
  41. subl eax,ebp
  42. imull ecx
  43. movl ebp,[_dc_texturemid]
  44. subl ebp,eax
  45. shll ebp,9 // 7 significant bits, 25 frac
  46. movl esi,[_dc_source]
  47. movl ebx,[_dc_iscale]
  48. shll ebx,9
  49. movl eax,OFFSET patch1+2 // convice tasm to modify code...
  50. movl [eax],ebx
  51. movl eax,OFFSET patch2+2 // convice tasm to modify code...
  52. movl [eax],ebx
  53. // eax aligned colormap
  54. // ebx aligned colormap
  55. // ecx,edx scratch
  56. // esi virtual source
  57. // edi moving destination pointer
  58. // ebp frac
  59. movl ecx,ebp // begin calculating first pixel
  60. addl ebp,ebx // advance frac pointer
  61. shrl ecx,25 // finish calculation for first pixel
  62. movl edx,ebp // begin calculating second pixel
  63. addl ebp,ebx // advance frac pointer
  64. shrl edx,25 // finish calculation for second pixel
  65. movl eax,[_dc_colormap]
  66. movl ebx,eax
  67. movb al,[esi+ecx] // get first pixel
  68. movb bl,[esi+edx] // get second pixel
  69. movb al,[eax] // color translate first pixel
  70. movb bl,[ebx] // color translate second pixel
  71. testl [pixelcount],0fffffffeh
  72. jnz doubleloop // at least two pixels to map
  73. jmp checklast
  74. .align 16
  75. doubleloop:
  76. movl ecx,ebp // begin calculating third pixel
  77. patch1:
  78. addl ebp,12345678h // advance frac pointer
  79. movb [edi],al // write first pixel
  80. shrl ecx,25 // finish calculation for third pixel
  81. movl edx,ebp // begin calculating fourth pixel
  82. patch2:
  83. addl ebp,12345678h // advance frac pointer
  84. movl [edi+SCREENWIDTH],bl // write second pixel
  85. shrl edx,25 // finish calculation for fourth pixel
  86. movb al,[esi+ecx] // get third pixel
  87. addl edi,SCREENWIDTH*2 // advance to third pixel destination
  88. movb bl,[esi+edx] // get fourth pixel
  89. decl [loopcount] // done with loop?
  90. movb al,[eax] // color translate third pixel
  91. movb bl,[ebx] // color translate fourth pixel
  92. jnz doubleloop
  93. // check for final pixel
  94. checklast:
  95. testl [pixelcount],1
  96. jz done
  97. movb [edi],al // write final pixel
  98. done:
  99. popad
  100. ret
  101. //================
  102. //
  103. // R_DrawSpan
  104. //
  105. // Horizontal texture mapping
  106. //
  107. //================
  108. .align 16
  109. .globl _R_DrawSpan
  110. _R_DrawSpan:
  111. pushad
  112. //
  113. // find loop count
  114. //
  115. movl eax,[_ds_x2]
  116. incl eax
  117. subl eax,[_ds_x1] // pixel count
  118. movl [pixelcount],eax // save for final pixel
  119. js hdone // nothing to scale
  120. shrl eax,1 // double pixel count
  121. movl [loopcount],eax
  122. //
  123. // build composite position
  124. //
  125. movl ebp,[_ds_xfrac]
  126. shll ebp,10
  127. andl ebp,0ffff0000h
  128. movl eax,[_ds_yfrac]
  129. shrl eax,6
  130. andl eax,0ffffh
  131. orl ebp,eax
  132. movl esi,[_ds_source]
  133. //
  134. // calculate screen dest
  135. //
  136. movl edi,[_ds_y]
  137. movl edi,[_ylookup+edi*4]
  138. movl eax,[_ds_x1]
  139. addl edi,[_columnofs+eax*4]
  140. //
  141. // build composite step
  142. //
  143. movl ebx,[_ds_xstep]
  144. shll ebx,10
  145. andl ebx,0ffff0000h
  146. movl eax,[_ds_ystep]
  147. shrl eax,6
  148. andl eax,0ffffh
  149. orl ebx,eax
  150. movl eax,OFFSET hpatch1+2 // convice tasm to modify code...
  151. movl [eax],ebx
  152. movl eax,OFFSET hpatch2+2 // convice tasm to modify code...
  153. movl [eax],ebx
  154. // eax aligned colormap
  155. // ebx aligned colormap
  156. // ecx,edx scratch
  157. // esi virtual source
  158. // edi moving destination pointer
  159. // ebp frac
  160. shldl ecx,ebp,22 // begin calculating third pixel (y units)
  161. shldl ecx,ebp,6 // begin calculating third pixel (x units)
  162. addl ebp,ebx // advance frac pointer
  163. andl ecx,4095 // finish calculation for third pixel
  164. shldl edx,ebp,22 // begin calculating fourth pixel (y units)
  165. shldl edx,ebp,6 // begin calculating fourth pixel (x units)
  166. addl ebp,ebx // advance frac pointer
  167. andl edx,4095 // finish calculation for fourth pixel
  168. movl eax,[_ds_colormap]
  169. movl ebx,eax
  170. movb al,[esi+ecx] // get first pixel
  171. movb bl,[esi+edx] // get second pixel
  172. movb al,[eax] // color translate first pixel
  173. movb bl,[ebx] // color translate second pixel
  174. testl [pixelcount],0fffffffeh
  175. jnz hdoubleloop // at least two pixels to map
  176. jmp hchecklast
  177. .align 16
  178. hdoubleloop:
  179. shldl ecx,ebp,22 // begin calculating third pixel (y units)
  180. shldl ecx,ebp,6 // begin calculating third pixel (x units)
  181. hpatch1:
  182. addl ebp,12345678h // advance frac pointer
  183. movb [edi],al // write first pixel
  184. andl ecx,4095 // finish calculation for third pixel
  185. shldl edx,ebp,22 // begin calculating fourth pixel (y units)
  186. shldl edx,ebp,6 // begin calculating fourth pixel (x units)
  187. hpatch2:
  188. addl ebp,12345678h // advance frac pointer
  189. movb [edi+1],bl // write second pixel
  190. andl edx,4095 // finish calculation for fourth pixel
  191. movb al,[esi+ecx] // get third pixel
  192. addl edi,2 // advance to third pixel destination
  193. movb bl,[esi+edx] // get fourth pixel
  194. decl [loopcount] // done with loop?
  195. movb al,[eax] // color translate third pixel
  196. movb bl,[ebx] // color translate fourth pixel
  197. jnz hdoubleloop
  198. // check for final pixel
  199. hchecklast:
  200. testl [pixelcount],1
  201. jz hdone
  202. movb [edi],al // write final pixel
  203. hdone:
  204. popad
  205. ret
  206. //====================================================
  207. // fpfunc.S as of January 10th, 1997 (parts)
  208. #ifdef i386
  209. .text
  210. .align 4
  211. .globl _FixedMul
  212. _FixedMul:
  213. pushl %ebp
  214. movl %esp,%ebp
  215. movl 8(%ebp),%eax
  216. imull 12(%ebp)
  217. shrdl $16,%edx,%eax
  218. popl %ebp
  219. ret
  220. .align 4
  221. .globl _FixedDiv2
  222. _FixedDiv2:
  223. pushl %ebp
  224. movl %esp,%ebp
  225. movl 8(%ebp),%eax
  226. cdq
  227. shldl $16,%eax,%edx
  228. sall $16,%eax
  229. idivl 12(%ebp)
  230. popl %ebp
  231. ret
  232. #endif