
	SUBTTL	Arithmentic Mode Conversion Macros

;SPCWAR uses three modes of arithmetic - integers (fixed), floating-point, and
;fractionals.
;
;Integer and floating-point numbers are the standard hardware representations.
;
;A fractional number is represented as an integer with a conceptual binary
;point (ala FIXED BINARY in PL/1).  The binary point is to the left of bit
;2.9 of the value.  That is, the left half of the word is the integer part,
;and the right half is the fraction.


;FLOAT AC
;   Function:
;	Converts an integer to a floating point value.  The integer must be less than
;	27. bits.
;   Inputs:
;	AC:	The accumulator containing the number.  The result will be in placed here.

DEFINE FLOAT AC
	FSC AC,233
IFDEF $PDP6, FADR AC,[0.0]		;PDP-6 FSC does not normalize.
TERMIN


;FIX AC
;   Function:
;	Convert a floating point number (positive or negative) to an integer.
;   Inputs:
;	AC:	The accumulator containing the floating value.
;   Outputs:
;	AC+1:	The result is placed in this accumulator.  The contents of AC are lost.

DEFINE FIX AC
	MULI AC,400
	TSC AC,AC
	ASH AC+1,-200-35.(AC)
TERMIN


;FIXP AC
;   Function:
;	This macro is identical to FIX.  The only difference is that the value too convert
;	must be positive.

DEFINE FIXP AC
	MULI AC,400
	ASH AC+1,-200-35.(AC)
TERMIN


;FRACT AC
;   Function:
;	Convert a floating-point number to a fractional value.  The input may have any sign.
;	The calling sequence and results are identical to FIX above.

DEFINE FRACT AC
	MULI AC,400
	TSC AC,AC
	ASH AC+1,-200-17.(AC)
TERMIN


;FRACTP AC
;   Function:
;	This macro is identical to FRACT above, but the input must be positive.

DEFINE FRACTP AC
	MULI AC,400
	ASH AC+1,-200,-17.(AC)
TERMIN


;FRCSCL AC,SCALE
;   Function:
;	Convert a floating-point number to a fractional value with an arbitrary binary point.
;   Inputs:
;	AC:	See FIX above.
;	SCALE:	The result will have SCALE bits of fraction in its representation.
;   Outputs:
;	See FIX above.

DEFINE FRCSCL AC,SCALE
	MULI AC,400
	TSC AC,AC
	ASH AC+1,-200-35.+SCALE(AC)
TERMIN
