|##########|
|#MAGIC   #|CLABLJAN
|#PROJECT #|"ImportAll"
|#PATHS   #|"StdProject"
|#FLAGS   #|xx-x-x-xx-----x-----------------
|#USERSW  #|--------------------------------
|#USERMASK#|--------------------------------
|#SWITCHES#|x-xx-x----------
|##########|
DEFINITION MODULE Timer;
(* $A- *)
FROM T_Exec    IMPORT nonstdVAL, IOCommand, IORequest, DevicePtr;
FROM System    IMPORT Regs;
FROM Resources IMPORT ContextPtr;

CONST
  addRequest    = IOCommand( nonstdVAL + 0 );
  getSysTime    = IOCommand( nonstdVAL + 1 );
  setSysTime    = IOCommand( nonstdVAL + 2 );

TYPE
  TimerUnits   = (microHz, vBlank, eClock, waitUntil, waitEClock);

TYPE
  TimeVal      = RECORD
		   secs,
		   micro : LONGCARD;
		 END;
  TimeValPtr   = POINTER TO TimeVal;


  EClockVal    = RECORD
		   evHi  : LONGCARD;
		   evLo  : LONGCARD;
		 END;
  EClockValPtr = POINTER TO EClockVal;


  IOTimer      = RECORD OF IORequest
		   IF KEY : BOOLEAN
		     OF TRUE  THEN time   : TimeVal;
		     OF FALSE THEN eClock : EClockVal;
		   END;
		 END;
  IOTimerPtr   = POINTER TO IOTimer;


VAR
  TimerBase    : DevicePtr;

LIBRARY TimerBase BY -42
  PROCEDURE AddTime(VAR dest   IN A0,
			source IN A1  : TimeVal);

LIBRARY TimerBase BY -48
  PROCEDURE SubTime(VAR dest   IN A0,
			source IN A1  : TimeVal);

LIBRARY TimerBase BY -54
  PROCEDURE CmpTime(VAR time1 IN A0,
			time2 IN A1  : TimeVal):INTEGER;

LIBRARY TimerBase BY -60
  PROCEDURE ReadEClock(VAR dest IN A0 : EClockVal):LONGCARD;

LIBRARY TimerBase BY -66
  PROCEDURE GetSysTime(VAR dest IN A0 : TimeVal);

PROCEDURE OpenTimer(unit    : TimerUnits;
		    context : ContextPtr := NIL ):IOTimerPtr;

PROCEDURE CloseTimer(VAR request : IOTimerPtr);

GROUP
  All   = addRequest,getSysTime,setSysTime,TimerUnits,TimeVal,TimeValPtr,
	  IOTimer,IOTimerPtr,TimerBase,AddTime,SubTime,CmpTime,OpenTimer,
	  CloseTimer,T_Exec.ExecIOGrp;

END Timer.

