home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser-CD 2000 January / LCD_01_2000.iso / games / doom / pmdoom / doc / asm next >
Encoding:
Text File  |  1999-12-17  |  6.8 KB  |  284 lines

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