MODULE FNC9511;
{$M SIN}
{$M COS}
{$M EXP}
{$M LN}
{$M ARCTAN}
{$M TAN}
{$M ASIN}
{$M ACOS}
{$M LOG10}
{$M PI}
{$M *}

EXTERNAL PROCEDURE @ERR(AN_ERROR:BOOLEAN; ERRNUM:INTEGER);

EXTERNAL PROCEDURE @AMD(FUNC:INTEGER;VAR ARG:REAL;VAR STATUS:INTEGER); 

{THE PROCEDURE @AMD,INTERFACES TO THE AMD9511 ARITHMETIC PROCESSING UNIT (APU).
THE FIRST ARGUMENT IS THE FUNCTION CODE (AND IS STRAIGHT FROM THE AM9511
LITERATURE).  THE SECOND IS THE ADDRESS OF ARG, A REAL VARIABLE, THE FUNTION
ARGUMENT IS IN ARG, AND THE RESULT IS RETURNED IN ARG.	THE THIRD ARGUMENT IS
THE ADDRESS WHERE THE APU STATUS IS RETURNED.}

{TAN, ASIN, ACOS, LOG10, AND PI FUNCTIONS ADDED BY FICOMP, INC. 9/13/81}

FUNCTION SIN(ARG:REAL):REAL; {SINE FUNCTION}
VAR	STATUS:INTEGER;
BEGIN
  @AMD($02,ARG,STATUS);
  SIN:=ARG;
END;

FUNCTION COS(ARG:REAL):REAL; {COSINE FUNCTION}
VAR	STATUS:INTEGER;
BEGIN
  @AMD($03,ARG,STATUS);
  COS:=ARG;
END;

FUNCTION EXP(ARG:REAL):REAL; {E TO THE X FUNCTION}
VAR	STATUS:INTEGER;
BEGIN
  @AMD($0A,ARG,STATUS);
  IF (STATUS & $1E) = $18 THEN
    BEGIN
      WRITE('EXP outside range');
      @ERR(TRUE,4); { -32< ARGUMENT >+32 }
      EXP := 0.0;
    END
  ELSE
    EXP := ARG;
END;

FUNCTION LN(ARG:REAL): REAL; {NATURAL LOGARITHM FUNCTION}
VAR	STATUS: INTEGER;
BEGIN
  @AMD($09,ARG,STATUS);
  IF (STATUS & $1E) = $8 THEN
    BEGIN
      WRITE('LN negative argument');
      @ERR(TRUE,4); { NEGATIVE ARGUMENT }
      LN := 0.0;
    END
  ELSE
    LN := ARG;
END;

FUNCTION ARCTAN(ARG:REAL): REAL; {INVERSE TANGENT FUNCTION}
VAR	STATUS: INTEGER;
BEGIN
  @AMD($07,ARG,STATUS);
  ARCTAN := ARG;
END;

FUNCTION TAN(ARG:REAL):REAL; {TANGENT FUNCTION}
VAR	STATUS:INTEGER;
BEGIN
  @AMD($04,ARG,STATUS);
  TAN := ARG;
END;

FUNCTION ASIN(ARG:REAL):REAL; {ARCSINE FUNCTION}
VAR	STATUS:INTEGER;
BEGIN
  @AMD($05,ARG,STATUS);
  IF (STATUS & $1E) = $18 THEN
    BEGIN
      WRITE('ASIN outside range');
      @ERR(TRUE,4); { -1< ARGUMENT >+1 }
      ASIN := 0.0;
    END
  ELSE
    ASIN := ARG;
END;

FUNCTION ACOS(ARG:REAL):REAL; {ARCCOSINE FUNCTION}
VAR	STATUS:INTEGER;
BEGIN
  @AMD($06,ARG,STATUS);
  IF (STATUS & $1E) = $18 THEN
    BEGIN
      WRITE('ACOS outside range');
      @ERR(TRUE,4); { -1< ARGUMENT >+1 }
      ACOS := 0.0;
    END
  ELSE
    ACOS := ARG;
END;

FUNCTION LOG10(ARG:REAL):REAL; {COMMON LOG FUNCTION}
VAR	STATUS:INTEGER;
BEGIN
  @AMD($08,ARG,STATUS);
  IF (STATUS & $1E) = $8 THEN
    BEGIN
      WRITE('LOG10 negative argument');
      @ERR(TRUE,4); { NEGATIVE ARGUMENT }
      LOG10 := 0.0;
    END
  ELSE
    LOG10 := ARG;
END;

FUNCTION PI(ARG:REAL):REAL; {RETURNS PI*ARG; PI(1)=3.14159}
VAR	STATUS:INTEGER;
	MULT:REAL;
BEGIN
  MULT := ARG;
  @AMD($1A,ARG,STATUS);
  PI := ARG*MULT;
END;

MODEND.
.14159}
VAR	STATUS:INTEGER;
	MULT:REAL;
BEGIN
  MULT := ARG;
  @AMD($1A,ARG,STATUS);
  