home *** CD-ROM | disk | FTP | other *** search
/ PC Underground / UNDERGROUND.ISO / doom / source / fx_doom.asm < prev    next >
Encoding:
Assembly Source File  |  1995-02-05  |  3.9 KB  |  174 lines

  1. ;----------------------------------------------------------------------------
  2. ; Special Dungeon part fixed point arithmetic
  3. ; Copyright (c) 1994,95 by J.E. Hoffmann
  4. ; All rights reserved
  5. ;----------------------------------------------------------------------------
  6.   TITLE FX_DOOM.ASM
  7.  
  8.  
  9.   MODEL SMALL
  10.  
  11.  
  12.   IDEAL
  13.   NOJUMPS
  14.   LOCALS @@
  15.  
  16.  
  17.   DATASEG
  18.     SinSize EQU 4096
  19.     INCLUDE "SIN.TBL"
  20.  
  21.  
  22.     BitSqrtTbl \
  23.       dw 1,2,2,3,5,7,10,14,20,28,39,55,78,111,157,222,314,443,627,887,1254
  24.       dw 1774,2508,3547,5017,7094,10033,14189,20066,28378,40132,56756
  25.  
  26.  
  27.   CODESEG
  28.   P386N
  29.  
  30.  
  31.   PUBLIC FixMul
  32.   PUBLIC FixDiv
  33.   PUBLIC FixSQR
  34.   PUBLIC FixSin
  35.   PUBLIC FixCos
  36.   PUBLIC FixSqrt
  37.  
  38.  
  39.  
  40. ;----------------------------------------------------------------------------
  41. ; function FixMul(A,B :Fixed) :Fixed; near; external;
  42. ;----------------------------------------------------------------------------
  43.   PROC FixMul NEAR
  44.        pop    cx
  45.        pop    ebx
  46.        pop    eax
  47.        imul   ebx
  48.        shrd   eax,edx,9
  49.        rol    eax,16
  50.        mov    dx,ax
  51.        rol    eax,16
  52.        push   cx
  53.        ret
  54.   ENDP
  55.  
  56.  
  57.  
  58. ;----------------------------------------------------------------------------
  59. ; function FixDiv(A,B :Fixed) :Fixed; near; external;
  60. ;----------------------------------------------------------------------------
  61.   PROC FixDiv NEAR
  62.        pop    cx
  63.        pop    ebx
  64.        pop    eax
  65.        cdq
  66.        shld   edx,eax,9
  67.        shl    eax,9
  68.        idiv   ebx
  69.        rol    eax,16
  70.        mov    dx,ax
  71.        rol    eax,16
  72.        push   cx
  73.        ret
  74.   ENDP
  75.  
  76.  
  77.  
  78. ;----------------------------------------------------------------------------
  79. ; function FixSQR(A :Fixed) :Fixed; near; external;
  80. ;----------------------------------------------------------------------------
  81.   PROC FixSQR NEAR
  82.        pop    cx
  83.        pop    eax
  84.        imul   eax
  85.        shrd   eax,edx,9
  86.        rol    eax,16
  87.        mov    dx,ax
  88.        rol    eax,16
  89.        push   cx
  90.        ret
  91.   ENDP
  92.  
  93.  
  94.  
  95. ;----------------------------------------------------------------------------
  96. ; function FixSin(W :Integer) :Fixed; near; external;
  97. ;----------------------------------------------------------------------------
  98.   PROC FixSin NEAR
  99.        pop    cx
  100.        pop    bx
  101.   $$Sin:
  102.        and    bx,SinSize-1
  103.        cmp    bx,SinSize/2
  104.        jge    @@21
  105.        cmp    bx,SinSize/4
  106.        jng    @@11
  107.        neg    bx
  108.        add    bx,SinSize/2
  109.   @@11:
  110.        shl    bx,1
  111.        mov    ax,[bx+SinTable]
  112.        cwd
  113.        push   cx
  114.        ret
  115.   @@21:
  116.        sub    bx,SinSize/2
  117.        cmp    bx,SinSize/4
  118.        jnge   @@22
  119.        neg    bx
  120.        add    bx,SinSize/2
  121.   @@22:
  122.        shl    bx,1
  123.        mov    ax,[bx+SinTable]
  124.        neg    ax
  125.        cwd
  126.        push   cx
  127.        ret
  128.   ENDP
  129.  
  130.  
  131.  
  132. ;----------------------------------------------------------------------------
  133. ; function FixCos(W :Integer) :Fixed; near; external;
  134. ;----------------------------------------------------------------------------
  135.   PROC FixCos NEAR
  136.        pop    cx
  137.        pop    bx
  138.        add    bx,SinSize/4
  139.        jmp    $$Sin
  140.   ENDP
  141.  
  142.  
  143.  
  144. ;----------------------------------------------------------------------------
  145. ; function FixSqrt(L :Fixed) :Fixed; near; external;
  146. ;----------------------------------------------------------------------------
  147.   PROC FixSqrt NEAR
  148.        pop    si
  149.        pop    edi
  150.        xor    ecx,ecx
  151.        bsr    ebx,edi
  152.        jz     @@12
  153.        shl    bx,1
  154.        movzx  eax,[bx+BitSqrtTbl]
  155.   @@11:
  156.        xor    edx,edx
  157.        mov    ebx,ecx
  158.        mov    ecx,eax
  159.        mov    eax,edi
  160.        div    ecx
  161.        add    eax,ecx
  162.        shr    eax,1
  163.        cmp    eax,ecx
  164.        je     @@12
  165.        cmp    eax,ebx
  166.        jne    @@11
  167.   @@12:
  168.        mov    ax,cx
  169.        rol    ecx,16
  170.        mov    dx,cx
  171.        push   si
  172.        ret
  173.   ENDP
  174.   END