-- PilotRealControl.mesa
-- Last Modified, Stewart, August 27, 1982 1:15 pm
-- Microcode to Mesa floating point translater

DIRECTORY
  Frame USING [MyLocalFrame],
  Ieee USING [InitIeee],
  MiscAlpha,
  PrincOps USING [StateVector, UnboundLink],
  Real,
  RealOps,
  SDDefs USING [SD, sFADD, sFSUB, sFMUL, sFDIV, sFCOMP, sFIX, sFLOAT],
  TrapSupport USING [BumpPC, opTrapTable];

RealControl: PROGRAM IMPORTS Frame, Ieee, RealOps, TrapSupport EXPORTS Real, RealOps
  =
  BEGIN
  microSticky: CARDINAL ← 0;

  InitReals: PUBLIC SAFE PROC = TRUSTED {
    OPEN SDDefs, TrapSupport;
    SD[sFADD] ← SD[sFSUB] ← SD[sFMUL] ← SD[sFDIV] ← SD[sFCOMP] ← SD[sFIX] ← SD[sFLOAT] ← PrincOps.UnboundLink;
    opTrapTable.misc[MiscAlpha.aFADD] ← LOOPHOLE[TFAdd];
    opTrapTable.misc[MiscAlpha.aFSUB] ← LOOPHOLE[TFSub];
    opTrapTable.misc[MiscAlpha.aFMUL] ← LOOPHOLE[TFMul];
    opTrapTable.misc[MiscAlpha.aFDIV] ← LOOPHOLE[TFDiv];
    opTrapTable.misc[MiscAlpha.aFCOMP] ← LOOPHOLE[TFComp];
    opTrapTable.misc[MiscAlpha.aFIX] ← LOOPHOLE[TFix];
    opTrapTable.misc[MiscAlpha.aFLOAT] ← LOOPHOLE[TFloat];
    opTrapTable.misc[MiscAlpha.aFIXI] ← LOOPHOLE[TFixI];
    opTrapTable.misc[MiscAlpha.aFIXC] ← LOOPHOLE[TFixC];
    opTrapTable.misc[MiscAlpha.aFSTICKY] ← LOOPHOLE[TFSticky];
    opTrapTable.misc[MiscAlpha.aFREM] ← LOOPHOLE[TFRem];
    opTrapTable.misc[MiscAlpha.aROUND] ← LOOPHOLE[TRound];
    opTrapTable.misc[MiscAlpha.aROUNDI] ← LOOPHOLE[TRoundI];
    opTrapTable.misc[MiscAlpha.aROUNDC] ← LOOPHOLE[TRoundC];
    opTrapTable.misc[MiscAlpha.aFSQRT] ← LOOPHOLE[TSqRt];
    opTrapTable.misc[MiscAlpha.aFSC] ← LOOPHOLE[TFSc];
    Ieee.InitIeee[];
    };

  TFAdd: PROC [a, b: REAL] RETURNS [c: REAL] = {
    state: PrincOps.StateVector;
    state ← STATE;
    c ← RealOps.FAdd[a, b];
    TrapSupport.BumpPC[2];
    state.dest ← [frame[Frame.MyLocalFrame[]]];
    TRANSFER WITH state;
    };

  TFSub: PROC [a, b: REAL] RETURNS [c: REAL] = {
    state: PrincOps.StateVector;
    state ← STATE;
    c ← RealOps.FSub[a, b];
    TrapSupport.BumpPC[2];
    state.dest ← [frame[Frame.MyLocalFrame[]]];
    TRANSFER WITH state;
    };

  TFMul: PROC [a, b: REAL] RETURNS [c: REAL] = {
    state: PrincOps.StateVector;
    state ← STATE;
    c ← RealOps.FMul[a, b];
    TrapSupport.BumpPC[2];
    state.dest ← [frame[Frame.MyLocalFrame[]]];
    TRANSFER WITH state;
    };

  TFDiv: PROC [a, b: REAL] RETURNS [c: REAL] = {
    state: PrincOps.StateVector;
    state ← STATE;
    c ← RealOps.FDiv[a, b];
    TrapSupport.BumpPC[2];
    state.dest ← [frame[Frame.MyLocalFrame[]]];
    TRANSFER WITH state;
    };

  TFComp: PROC [a, b: REAL] RETURNS [i: INTEGER] = {
    state: PrincOps.StateVector;
    state ← STATE;
    i ← RealOps.FComp[a, b];
    TrapSupport.BumpPC[2];
    state.dest ← [frame[Frame.MyLocalFrame[]]];
    TRANSFER WITH state;
    };

  TFix: PROC [a: REAL] RETURNS [li: LONG INTEGER] = {
    state: PrincOps.StateVector;
    state ← STATE;
    li ← RealOps.RoundLI[a, RealOps.FixMode];
    TrapSupport.BumpPC[2];
    state.dest ← [frame[Frame.MyLocalFrame[]]];
    TRANSFER WITH state;
    };

  TFloat: PROC [a: LONG INTEGER] RETURNS [c: REAL] = {
    state: PrincOps.StateVector;
    state ← STATE;
    c ← RealOps.Float[a];
    TrapSupport.BumpPC[2];
    state.dest ← [frame[Frame.MyLocalFrame[]]];
    TRANSFER WITH state;
    };

  TFixI: PROC [a: REAL] RETURNS [i: INTEGER] = {
    state: PrincOps.StateVector;
    state← STATE;
    i ← RealOps.RoundI[a, RealOps.FixMode];
    TrapSupport.BumpPC[2];
    state.dest ← [frame[Frame.MyLocalFrame[]]];
    TRANSFER WITH state;
    };

  TFixC: PROC [a: REAL] RETURNS [c: CARDINAL] = {
    state: PrincOps.StateVector;
    state ← STATE;
    c ← RealOps.RoundC[a, RealOps.FixMode];
    TrapSupport.BumpPC[2];
    state.dest ← [frame[Frame.MyLocalFrame[]]];
    TRANSFER WITH state;
    };

  TFSticky: PROC [c: CARDINAL] RETURNS [cr: CARDINAL] = {
    state: PrincOps.StateVector;
    state ← STATE;
    cr ← microSticky;
    microSticky ← c;
    TrapSupport.BumpPC[2];
    state.dest ← [frame[Frame.MyLocalFrame[]]];
    TRANSFER WITH state;
    };

  TFRem: PROC [a, b: REAL] RETURNS [c: REAL] = {
    state: PrincOps.StateVector;
    state ← STATE;
    c ← RealOps.FRem[a, b];
    TrapSupport.BumpPC[2];
    state.dest ← [frame[Frame.MyLocalFrame[]]];
    TRANSFER WITH state;
    };

  TRound: PROC [a: REAL] RETURNS [li: LONG INTEGER] = {
    state: PrincOps.StateVector;
    state ← STATE;
    li ← RealOps.RoundLI[a];
    TrapSupport.BumpPC[2];
    state.dest ← [frame[Frame.MyLocalFrame[]]];
    TRANSFER WITH state;
    };

  TRoundI: PROC [a: REAL] RETURNS [i: INTEGER] = {
    state: PrincOps.StateVector;
    state ← STATE;
    i ← RealOps.RoundI[a];
    TrapSupport.BumpPC[2];
    state.dest ← [frame[Frame.MyLocalFrame[]]];
    TRANSFER WITH state;
    };

  TRoundC: PROC [a: REAL] RETURNS [c: CARDINAL] = {
    state: PrincOps.StateVector;
    state ← STATE;
    c ← RealOps.RoundC[a];
    TrapSupport.BumpPC[2];
    state.dest ← [frame[Frame.MyLocalFrame[]]];
    TRANSFER WITH state;
    };

  TSqRt: PROC [a: REAL] RETURNS [b: REAL] = {
    state: PrincOps.StateVector;
    state ← STATE;
    b ← RealOps.SqRt[a];
    TrapSupport.BumpPC[2];
    state.dest ← [frame[Frame.MyLocalFrame[]]];
    TRANSFER WITH state;
    };

  TFSc: PROC [a: REAL, scale: INTEGER] RETURNS [b: REAL] = {
    state: PrincOps.StateVector;
    state ← STATE;
    b ← RealOps.FScale[a, scale];
    TrapSupport.BumpPC[2];
    state.dest ← [frame[Frame.MyLocalFrame[]]];
    TRANSFER WITH state;
    };

  -- Mainline code

  InitReals[];

  END.
L. Stewart, December 11, 1980  11:37 AM, modify for Pilot from RealControl.mesa
L. Stewart, 4-Feb-81 18:31:04, change to new trap handling
L. Stewart, 6-Feb-81 10:40:32, update trap procedure style
R. Atkinson, 23-Mar-81 16:10:36,
   replaced Frame.MyLocalFrame[] with [frame[Frame.MyLocalFrame[]]]
L. Stewart, June 3, 1982 11:11 am, added FScale and SqRt, removed SETS
L. Stewart, August 27, 1982 1:15 pm, SAFE