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

  1. ;----------------------------------------------------------------------------
  2. ; Fixed-Point Assembler Modul for Turbo Pascal
  3. ; Copyright (c) 1994,95 by J.E. Hoffmann
  4. ; All rights reserved
  5. ;----------------------------------------------------------------------------
  6.   TITLE FixedPas.ASM
  7.  
  8.  
  9.   MODEL SMALL
  10.  
  11.  
  12.   IDEAL
  13.   NOJUMPS
  14.   LOCALS @@
  15.  
  16.  
  17.   DATASEG
  18.     SinTable \
  19.       DW 00000h, 00006h, 0000Dh, 00013h, 00019h, 0001Fh, 00026h, 0002Ch, 00032h, 00038h, 0003Fh, 00045h, 0004Bh, 00051h, 00058h, 0005Eh
  20.       DW 00064h, 0006Ah, 00070h, 00076h, 0007Ch, 00082h, 00089h, 0008Fh, 00095h, 0009Bh, 000A1h, 000A7h, 000ACh, 000B2h, 000B8h, 000BEh
  21.       DW 000C4h, 000CAh, 000CFh, 000D5h, 000DBh, 000E1h, 000E6h, 000ECh, 000F1h, 000F7h, 000FCh, 00102h, 00107h, 0010Dh, 00112h, 00117h
  22.       DW 0011Ch, 00122h, 00127h, 0012Ch, 00131h, 00136h, 0013Bh, 00140h, 00145h, 0014Ah, 0014Eh, 00153h, 00158h, 0015Ch, 00161h, 00166h
  23.       DW 0016Ah, 0016Eh, 00173h, 00177h, 0017Bh, 00180h, 00184h, 00188h, 0018Ch, 00190h, 00194h, 00197h, 0019Bh, 0019Fh, 001A3h, 001A6h
  24.       DW 001AAh, 001ADh, 001B1h, 001B4h, 001B7h, 001BAh, 001BDh, 001C1h, 001C4h, 001C6h, 001C9h, 001CCh, 001CFh, 001D1h, 001D4h, 001D7h
  25.       DW 001D9h, 001DBh, 001DEh, 001E0h, 001E2h, 001E4h, 001E6h, 001E8h, 001EAh, 001ECh, 001EDh, 001EFh, 001F1h, 001F2h, 001F4h, 001F5h
  26.       DW 001F6h, 001F7h, 001F8h, 001F9h, 001FAh, 001FBh, 001FCh, 001FDh, 001FEh, 001FEh, 001FFh, 001FFh, 001FFh, 00200h, 00200h, 00200h
  27.       DW 00200h
  28.  
  29.  
  30.   CODESEG
  31.   P386N
  32.  
  33.  
  34.   PUBLIC FixMul
  35.   PUBLIC FixDiv
  36.   PUBLIC FixSQR
  37.   PUBLIC FixSin
  38.   PUBLIC FixCos
  39.  
  40.  
  41.  
  42. ;----------------------------------------------------------------------------
  43. ; function FixMul(A,B :Fixed) :Fixed; near; external;
  44. ;----------------------------------------------------------------------------
  45.   PROC FixMul NEAR
  46.        pop    cx
  47.        pop    ebx
  48.        pop    eax
  49.        imul   ebx
  50.        shrd   eax,edx,9
  51.        rol    eax,16
  52.        mov    dx,ax
  53.        rol    eax,16
  54.        push   cx
  55.        ret
  56.   ENDP
  57.  
  58.  
  59.  
  60. ;----------------------------------------------------------------------------
  61. ; function FixDiv(A,B :Fixed) :Fixed; near; external;
  62. ;----------------------------------------------------------------------------
  63.   PROC FixDiv NEAR
  64.        pop    cx
  65.        pop    ebx
  66.        pop    eax
  67.        cdq
  68.        shld   edx,eax,9
  69.        shl    eax,9
  70.        idiv   ebx
  71.        rol    eax,16
  72.        mov    dx,ax
  73.        rol    eax,16
  74.        push   cx
  75.        ret
  76.   ENDP
  77.  
  78.  
  79.  
  80. ;----------------------------------------------------------------------------
  81. ; function FixSQR(A :Fixed) :Fixed; near; external;
  82. ;----------------------------------------------------------------------------
  83.   PROC FixSQR NEAR
  84.        pop    cx
  85.        pop    eax
  86.        imul   eax
  87.        shrd   eax,edx,9
  88.        rol    eax,16
  89.        mov    dx,ax
  90.        rol    eax,16
  91.        push   cx
  92.        ret
  93.   ENDP
  94.  
  95.  
  96.  
  97. ;----------------------------------------------------------------------------
  98. ; function FixSin(W :Integer) :Fixed; near; external;
  99. ;----------------------------------------------------------------------------
  100.   PROC FixSin NEAR
  101.        pop    cx
  102.        pop    bx
  103.   $$Sin:
  104.        and    bx,1FFh
  105.        cmp    bx,256
  106.        jge    @@21
  107.        cmp    bx,128
  108.        jng    @@11
  109.        neg    bx
  110.        add    bx,256
  111.   @@11:
  112.        shl    bx,1
  113.        mov    ax,[bx+SinTable]
  114.        cwd
  115.        push   cx
  116.        ret
  117.   @@21:
  118.        sub    bx,256
  119.        cmp    bx,128
  120.        jnge   @@22
  121.        neg    bx
  122.        add    bx,256
  123.   @@22:
  124.        shl    bx,1
  125.        mov    ax,[bx+SinTable]
  126.        neg    ax
  127.        cwd
  128.        push   cx
  129.        ret
  130.   ENDP
  131.  
  132.  
  133.  
  134. ;----------------------------------------------------------------------------
  135. ; function FixCos(W :Integer) :Fixed; near; external;
  136. ;----------------------------------------------------------------------------
  137.   PROC FixCos NEAR
  138.        pop    cx
  139.        pop    bx
  140.        add    bx,128
  141.        jmp    $$Sin
  142.   ENDP
  143.   END