-- System.mesa last edited by:
-- McJones on: May 9, 1980  11:07 AM
-- Sandman on: August 26, 1980  12:20 PM (Alto version)

DIRECTORY
  InlineDefs USING [BcplLongNumber, BcplToMesaLongNumber, LongDiv, LongMult];

System: DEFINITIONS IMPORTS InlineDefs =
  BEGIN

  -- Network addresses

  NetworkAddress: TYPE [6];
  nullNetworkAddress: READONLY NetworkAddress;

  -- Timekeeping facilities

  GreenwichMeanTime: TYPE = LONG CARDINAL;
  -- Greenwich mean times should be compared directly only for equality; to 
  -- find which of two gmt's comes first, apply SecondsSinceEpoch to each and 
  -- compare the result.  If t2 is a gmt known to occur after t1, then t2-t1 
  -- is the seconds between t1 and t2.  If t is a gmt, then 
  -- System.GreenwichMeanTime[t+60] is the gmt one minute after t.
  gmtEpoch: GreenwichMeanTime = 0; -- for Alto times
  GetGreenwichMeanTime: PROCEDURE RETURNS [gmt: GreenwichMeanTime] = INLINE
    BEGIN
    time: POINTER TO InlineDefs.BcplLongNumber = LOOPHOLE[572B];
    RETURN[InlineDefs.BcplToMesaLongNumber[time↑]]
    END;

  SecondsSinceEpoch: PROCEDURE [gmt: GreenwichMeanTime] RETURNS [LONG CARDINAL] =
    INLINE BEGIN RETURN[gmt - gmtEpoch] END;

  AdjustGreenwichMeanTime: PROC [gmt: GreenwichMeanTime, delta: LONG INTEGER]
    RETURNS [GreenwichMeanTime] = INLINE {RETURN[gmt + delta]};

  Microseconds: TYPE = LONG CARDINAL;

  Pulses: TYPE = RECORD [CARDINAL];
  GetClockPulses: PROCEDURE RETURNS [p: Pulses] = INLINE
    BEGIN clock: POINTER TO Pulses = LOOPHOLE[430B]; RETURN[clock↑] END;

  PulsesToMicroseconds: PROCEDURE [p: Pulses] RETURNS [m: Microseconds] = INLINE
    BEGIN RETURN[InlineDefs.LongMult[p, 38994]] END;

  MicrosecondsToPulses: PROCEDURE [m: Microseconds] RETURNS [p: Pulses] = INLINE
    BEGIN RETURN[[InlineDefs.LongDiv[m, 38994]]] END;

  END.