home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / languages / obrn-a_1.5_lib.lha / oberon-a / source2.lha / source / amiga / RealTime.mod < prev    next >
Encoding:
Text File  |  1995-01-26  |  9.5 KB  |  314 lines

  1. (*************************************************************************
  2.  
  3.      $RCSfile: RealTime.mod $
  4.   Description: Interface to realtime.library
  5.  
  6.    Created by: fjc (Frank Copeland)
  7.     $Revision: 3.6 $
  8.       $Author: fjc $
  9.         $Date: 1995/01/26 02:39:55 $
  10.  
  11.   Includes Release 40.15
  12.  
  13.   (C) Copyright 1993 Commodore-Amiga, Inc.
  14.       All Rights Reserved
  15.  
  16.   Oberon-A Interface Copyright © 1994-1995, Frank Copeland.
  17.   This file is part of the Oberon-A Interface.
  18.   See Oberon-A.doc for conditions of use and distribution.
  19.  
  20.   Log entries are at the end of the file.
  21.  
  22. *************************************************************************)
  23.  
  24. <* STANDARD- *> <* INITIALISE- *> <* MAIN- *>
  25. <*$ CaseChk-  IndexChk- LongVars+ NilChk-  *>
  26. <*$ RangeChk- StackChk- TypeChk-  OvflChk- *>
  27.  
  28. MODULE [2] RealTime;
  29.  
  30. IMPORT SYS := SYSTEM, Kernel, e := Exec, u := Utility, s := Sets;
  31.  
  32. (*
  33. **      $VER: realtime.h 40.3 (5.4.93)
  34. **
  35. **      realtime.library timing and syncing system
  36. *)
  37.  
  38. (*****************************************************************************)
  39.  
  40. CONST
  41.  
  42. (* realtime.library's idea of time is based on a clock which emits a pulse
  43.  * 1200 times a second (1.2kHz). All time values maintained by realtime.library
  44.  * are based on this number. For example, the field RealTimeBase->rtb_Time
  45.  * expresses an amount of time equivalent to (RealTimeBase->rtb_Time/TICK_FREQ)
  46.  * seconds.
  47.  *)
  48.   tickFreq * = 1200;
  49.  
  50.  
  51. (*****************************************************************************)
  52.  
  53. TYPE
  54.  
  55. (* Each Conductor represents a group of applications which wish to remain
  56.  * synchronized together.
  57.  *
  58.  * This structure must only be allocated by realtime.library and is
  59.  * READ-ONLY!
  60.  *)
  61.   ConductorPtr * = POINTER TO Conductor;
  62.   Conductor * = RECORD (e.NodeBase)
  63.     node -            : e.Node;
  64.     reserved0 -       : e.UWORD;
  65.     players -         : e.MinList; (* this conductor's players      *)
  66.     clockTime -       : e.ULONG;   (* current time of this sequence *)
  67.     startTime -       : e.ULONG;   (* start time of this sequence   *)
  68.     externalTime -    : e.ULONG;   (* time from external unit       *)
  69.     maxExternalTime - : e.ULONG;   (* upper limit on sync'd time    *)
  70.     metronome -       : e.ULONG;   (* MetricTime highest pri node   *)
  71.     reserved1 -       : e.UWORD;
  72.     flags -           : s.SET16;   (* conductor flags               *)
  73.     state -           : SHORTINT;  (* playing or stopped            *)
  74.   END;
  75.  
  76. CONST
  77.  
  78. (* Flag bits for Conductor.cdt_Flags *)
  79.   external * = 0;       (* clock is externally driven *)
  80.   gotTick *  = 1;       (* received 1st external tick *)
  81.   metroSet * = 2;       (* cdt_Metronome filled in    *)
  82.   private *  = 3;       (* conductor is private       *)
  83.  
  84. (* constants for Conductor.cdt_State and SetConductorState() *)
  85.   stopped * = 0;          (* clock is stopped              *)
  86.   paused *  = 1;          (* clock is paused               *)
  87.   locate *  = 2;          (* go to 'running' when ready    *)
  88.   running * = 3;          (* run clock NOW                 *)
  89.  
  90. (* These do not actually exist as Conductor states, but are used as additional
  91.  * arguments to SetConductorState()
  92.  *)
  93.   metric *    = -1;       (* ask high node to locate       *)
  94.   shuttle *   = -2;       (* time changing but not running *)
  95.   locateSet * = -3;       (* maestro done locating         *)
  96.  
  97.  
  98. (*****************************************************************************)
  99.  
  100. TYPE
  101.  
  102. (* The Player is the connection between a Conductor and an application.
  103.  *
  104.  * This structure must only be allocated by realtime.library and is
  105.  * READ-ONLY!
  106.  *)
  107.   PlayerPtr * = POINTER TO Player;
  108.   Player * = RECORD (e.NodeBase)
  109.     node -       : e.Node;
  110.     reserved0 -  : SHORTINT;
  111.     reserved1 -  : SHORTINT;
  112.     hook -       : u.HookPtr;     (* player's hook function       *)
  113.     source -     : ConductorPtr;  (* pointer to parent context    *)
  114.     task -       : e.TaskPtr;     (* task to signal for alarm     *)
  115.     metricTime - : LONGINT;       (* current time in app's metric *)
  116.     alarmTime -  : LONGINT;       (* time to wake up              *)
  117.     userData -   : e.APTR;        (* for application use          *)
  118.     playerID -   : e.UWORD;       (* for application use          *)
  119.     flags -      : s.SET16;       (* general Player flags         *)
  120.   END;
  121.  
  122. CONST
  123.  
  124. (* Flag bits for Player.pl_Flags *)
  125.   ready     * = 0;          (* player is ready to go!        *)
  126.   alarmSet  * = 1;          (* alarm is set                  *)
  127.   quiet     * = 2;          (* a dummy player, used for sync *)
  128.   conducted * = 3;          (* give me metered time          *)
  129.   extSync   * = 4;          (* granted external sync         *)
  130.  
  131.  
  132. (*****************************************************************************)
  133.  
  134. CONST
  135.  
  136. (* Tags for CreatePlayer(), SetPlayerAttrs(), and GetPlayerAttrs() *)
  137.   playerBase *         = u.user + 64;
  138.   playerHook *         = playerBase+1;   (* set address of hook function *)
  139.   playerName *         = playerBase+2;   (* name of player               *)
  140.   playerPriority *     = playerBase+3;   (* priority of player           *)
  141.   playerConductor *    = playerBase+4;   (* set conductor for player     *)
  142.   playerReady *        = playerBase+5;   (* the "ready" flag             *)
  143.   playerAlarmTime *    = playerBase+12;  (* alarm time (sets PLAYERF_ALARMSET) *)
  144.   playerAlarm *        = playerBase+13;  (* sets/clears PLAYERF_ALARMSET flag  *)
  145.   playerAlarmSigTask * = playerBase+6;   (* task to signal for alarm/notify    *)
  146.   playerAlarmSigBit *  = playerBase+8;   (* signal bit for alarm (or -1) *)
  147.   playerConducted *    = playerBase+7;   (* sets/clears PLAYERF_CONDUCTED flag   *)
  148.   playerQuiet *        = playerBase+9;   (* don't process time thru this *)
  149.   playerUserData *     = playerBase+10;
  150.   playerID *           = playerBase+11;
  151.   playerExtSync *      = playerBase+14;  (* attempt/release to ext sync  *)
  152.   playerErrorCode *    = playerBase+15;  (* error return value           *)
  153.  
  154.  
  155. (*****************************************************************************)
  156.  
  157. CONST
  158.  
  159. (* Method types for messages sent via a Player's hook *)
  160.   pmTick * = 0;
  161.   pmState * = 1;
  162.   pmPosition * = 2;
  163.   pmShuttle * = 3;
  164.  
  165. TYPE
  166.  
  167.   MsgPtr * = POINTER TO Msg;
  168.   Msg * = RECORD END;
  169.  
  170. (* used for PM_TICK, PM_POSITION and PM_SHUTTLE methods *)
  171.   PMTimePtr * = POINTER TO PMTime;
  172.   PMTime * = RECORD (Msg) (* PM_TICK, PM_POSITION, or PM_SHUTTLE *)
  173.     method * : e.ULONG;
  174.     time *   : e.ULONG;
  175.   END;
  176.  
  177. (* used for the PM_STATE method *)
  178.   PMStatePtr * = POINTER TO PMState;
  179.   PMState * = RECORD (Msg) (* PM_STATE *)
  180.     method *   : e.ULONG;
  181.     oldState * : e.ULONG;
  182.   END;
  183.  
  184.  
  185. (*****************************************************************************)
  186.  
  187. CONST
  188.  
  189. (* Possible lock types for LockRealTime() *)
  190.   conductors * = 0;     (* conductor list *)
  191.  
  192.  
  193. (*****************************************************************************)
  194.  
  195. CONST
  196.  
  197. (* realtime.library error codes *)
  198.   noMemory *    = 801;  (* memory allocation failed      *)
  199.   noConductor * = 802;  (* player needs a conductor      *)
  200.   noTimer *     = 803;  (* timer (CIA) allocation failed *)
  201.   playing *     = 804;  (* can't shuttle while playing   *)
  202.  
  203.  
  204. (*****************************************************************************)
  205.  
  206. TYPE
  207.  
  208. (* OpenLibrary("realtime.library",0) returns a pointer to this structure.
  209.  * All fields are READ-ONLY.
  210.  *)
  211.   RealTimeBasePtr * = POINTER TO RealTimeBase;
  212.   RealTimeBase * = RECORD (e.LibraryBase)
  213.     libNode -   : e.Library;
  214.     reserved0 - : ARRAY 2 OF e.UBYTE;
  215.  
  216.     time -      : e.ULONG;   (* current time                         *)
  217.     timeFrac -  : e.ULONG;   (* fixed-point fraction part of time    *)
  218.     reserved1 - : e.UWORD;
  219.     tickErr -   : INTEGER;   (* nanosecond error from ideal Tick     *)
  220.   END;                       (* length to real tick length           *)
  221.  
  222. CONST
  223.  
  224. (* Actual tick length is: 1/TICK_FREQ + rtb_TickErr/1e9 *)
  225.  
  226.   tickErrMin * = -705;
  227.   tickErrMax * = 705;
  228.  
  229.  
  230. (*****************************************************************************)
  231.  
  232. (*-- Library Base variable --------------------------------------------*)
  233.  
  234. VAR
  235.  
  236.   base* : RealTimeBasePtr;
  237.  
  238.  
  239. (*-- Library Functions ------------------------------------------------*)
  240.  
  241. TYPE
  242.   RealTimeLock * = POINTER TO RECORD END;
  243.  
  244. (*
  245. **      $VER: realtime_protos.h 40.1 (16.3.93)
  246. *)
  247.  
  248. (*--- functions in V37 or higher (Release 2.04) ---*)
  249.  
  250. (* Locks *)
  251.  
  252. PROCEDURE LockRealTime* [base,-30]
  253.   ( lockType [0] : e.ULONG )
  254.   : RealTimeLock;
  255.  
  256. PROCEDURE UnlockRealTime* [base,-36]
  257.   ( lock [8] : RealTimeLock );
  258.  
  259. (* Conductor *)
  260.  
  261. PROCEDURE CreatePlayerA* [base,-42]
  262.   ( tagList [8] : ARRAY OF u.TagItem )
  263.   : PlayerPtr;
  264.  
  265. PROCEDURE CreatePlayer* [base,-42]
  266.   ( tagList [8]..: u.Tag )
  267.   : PlayerPtr;
  268.  
  269. PROCEDURE DeletePlayer* [base,-48]
  270.   ( player [8] : PlayerPtr );
  271.  
  272. PROCEDURE SetPlayerAttrsA* [base,-54]
  273.   ( player  [8] : PlayerPtr;
  274.     tagList [9] : ARRAY OF u.TagItem )
  275.   : BOOLEAN;
  276.  
  277. PROCEDURE SetPlayerAttrs* [base,-54]
  278.   ( player  [8]  : PlayerPtr;
  279.     tagList [9]..: u.Tag )
  280.   : BOOLEAN;
  281.  
  282. PROCEDURE SetConductorState* [base,-60]
  283.   ( player [8] : PlayerPtr;
  284.     state [0]  : e.ULONG;
  285.     time [1]   : LONGINT )
  286.   : LONGINT;
  287.  
  288. PROCEDURE ExternalSync* [base,-66]
  289.   ( player  [8] : PlayerPtr;
  290.     minTime [0] : LONGINT;
  291.     maxTime [1] : LONGINT )
  292.   : BOOLEAN;
  293.  
  294. PROCEDURE NextConductor* [base,-72]
  295.   ( previousConductor [8] : ConductorPtr )
  296.   : ConductorPtr;
  297.  
  298. PROCEDURE FindConductor* [base,-78]
  299.   ( name [8] : ARRAY OF CHAR )
  300.   : ConductorPtr;
  301.  
  302. PROCEDURE GetPlayerAttrsA* [base,-84]
  303.   ( player  [8] : PlayerPtr;
  304.     tagList [9] : ARRAY OF u.TagItem )
  305.   : e.ULONG;
  306.  
  307. PROCEDURE GetPlayerAttrs* [base,-84]
  308.   ( player  [8]  : PlayerPtr;
  309.     tagList [9]..: u.Tag )
  310.   : e.ULONG;
  311.  
  312. BEGIN base := NIL
  313. END RealTime.
  314.