home *** CD-ROM | disk | FTP | other *** search
- ;----------------------------------------------------------------------------
- ; Special Dungeon part fixed point arithmetic
- ; Copyright (c) 1994,95 by J.E. Hoffmann
- ; All rights reserved
- ;----------------------------------------------------------------------------
- TITLE FX_DOOM.ASM
-
-
- MODEL SMALL
-
-
- IDEAL
- NOJUMPS
- LOCALS @@
-
-
- DATASEG
- SinSize EQU 4096
- INCLUDE "SIN.TBL"
-
-
- BitSqrtTbl \
- dw 1,2,2,3,5,7,10,14,20,28,39,55,78,111,157,222,314,443,627,887,1254
- dw 1774,2508,3547,5017,7094,10033,14189,20066,28378,40132,56756
-
-
- CODESEG
- P386N
-
-
- PUBLIC FixMul
- PUBLIC FixDiv
- PUBLIC FixSQR
- PUBLIC FixSin
- PUBLIC FixCos
- PUBLIC FixSqrt
-
-
-
- ;----------------------------------------------------------------------------
- ; function FixMul(A,B :Fixed) :Fixed; near; external;
- ;----------------------------------------------------------------------------
- PROC FixMul NEAR
- pop cx
- pop ebx
- pop eax
- imul ebx
- shrd eax,edx,9
- rol eax,16
- mov dx,ax
- rol eax,16
- push cx
- ret
- ENDP
-
-
-
- ;----------------------------------------------------------------------------
- ; function FixDiv(A,B :Fixed) :Fixed; near; external;
- ;----------------------------------------------------------------------------
- PROC FixDiv NEAR
- pop cx
- pop ebx
- pop eax
- cdq
- shld edx,eax,9
- shl eax,9
- idiv ebx
- rol eax,16
- mov dx,ax
- rol eax,16
- push cx
- ret
- ENDP
-
-
-
- ;----------------------------------------------------------------------------
- ; function FixSQR(A :Fixed) :Fixed; near; external;
- ;----------------------------------------------------------------------------
- PROC FixSQR NEAR
- pop cx
- pop eax
- imul eax
- shrd eax,edx,9
- rol eax,16
- mov dx,ax
- rol eax,16
- push cx
- ret
- ENDP
-
-
-
- ;----------------------------------------------------------------------------
- ; function FixSin(W :Integer) :Fixed; near; external;
- ;----------------------------------------------------------------------------
- PROC FixSin NEAR
- pop cx
- pop bx
- $$Sin:
- and bx,SinSize-1
- cmp bx,SinSize/2
- jge @@21
- cmp bx,SinSize/4
- jng @@11
- neg bx
- add bx,SinSize/2
- @@11:
- shl bx,1
- mov ax,[bx+SinTable]
- cwd
- push cx
- ret
- @@21:
- sub bx,SinSize/2
- cmp bx,SinSize/4
- jnge @@22
- neg bx
- add bx,SinSize/2
- @@22:
- shl bx,1
- mov ax,[bx+SinTable]
- neg ax
- cwd
- push cx
- ret
- ENDP
-
-
-
- ;----------------------------------------------------------------------------
- ; function FixCos(W :Integer) :Fixed; near; external;
- ;----------------------------------------------------------------------------
- PROC FixCos NEAR
- pop cx
- pop bx
- add bx,SinSize/4
- jmp $$Sin
- ENDP
-
-
-
- ;----------------------------------------------------------------------------
- ; function FixSqrt(L :Fixed) :Fixed; near; external;
- ;----------------------------------------------------------------------------
- PROC FixSqrt NEAR
- pop si
- pop edi
- xor ecx,ecx
- bsr ebx,edi
- jz @@12
- shl bx,1
- movzx eax,[bx+BitSqrtTbl]
- @@11:
- xor edx,edx
- mov ebx,ecx
- mov ecx,eax
- mov eax,edi
- div ecx
- add eax,ecx
- shr eax,1
- cmp eax,ecx
- je @@12
- cmp eax,ebx
- jne @@11
- @@12:
- mov ax,cx
- rol ecx,16
- mov dx,cx
- push si
- ret
- ENDP
- END