home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / languages / pcq_incl3v1.lha / Libraries / RealTime.i < prev    next >
Encoding:
Text File  |  1994-09-18  |  7.1 KB  |  203 lines

  1.  
  2. {$I "Include:Exec/Lists.i"}
  3. {$I "Include:Exec/Libraries.i"}
  4. {$I "Include:Exec/Tasks.i"}
  5. {$I "Include:Utility/TagItem.i"}
  6. {$I "Include:Utility/Hooks.i"}
  7.  
  8. {***************************************************************************}
  9.  
  10. const
  11. { realtime.library's idea of time is based on a clock which emits a pulse
  12.  * 1200 times a second (1.2kHz). All time values maintained by realtime.library
  13.  * are based on this number. For example, the field RealTimeBase->rtb_Time
  14.  * expresses an amount of time equivalent to (RealTimeBase->rtb_Time/TICK_FREQ)
  15.  * seconds.
  16.  }
  17.  TICK_FREQ = 1200;
  18.  
  19.  
  20. {***************************************************************************}
  21.  
  22.  
  23. { Each Conductor represents a group of applications which wish to remain
  24.  * synchronized together.
  25.  *
  26.  * This structure must only be allocated by realtime.library and is
  27.  * READ-ONLY!
  28.  }
  29. Type
  30.  Conductor = Record
  31.     cdt_Link        : Node;
  32.     cdt_Reserved0   : WORD;
  33.     cdt_Players     : MinList;           { this conductor's players      }
  34.     cdt_ClockTime,                       { current time of this sequence }
  35.     cdt_StartTime,                       { start time of this sequence   }
  36.     cdt_ExternalTime,                    { time from external unit       }
  37.     cdt_MaxExternalTime,                 { upper limit on sync'd time    }
  38.     cdt_Metronome   : Integer;           { MetricTime highest pri node   }
  39.     cdt_Reserved1   : WORD;
  40.     cdt_Flags       : WORD;              { conductor flags               }
  41.     cdt_State       : Byte;              { playing or stopped            }
  42.  end;
  43.  ConductorPtr = ^Conductor;
  44.  
  45. const
  46. { Flag bits for Conductor.cdt_Flags }
  47.  CONDUCTF_EXTERNAL = 1;   { clock is externally driven }
  48.  CONDUCTF_GOTTICK  = 2;   { received 1st external tick }
  49.  CONDUCTF_METROSET = 4;   { cdt_Metronome filled in    }
  50.  CONDUCTF_PRIVATE  = 8;   { conductor is private       }
  51.  
  52.  CONDUCTB_EXTERNAL = 0;
  53.  CONDUCTB_GOTTICK  = 1;
  54.  CONDUCTB_METROSET = 2;
  55.  CONDUCTB_PRIVATE  = 3;
  56.  
  57. { constants for Conductor.cdt_State and SetConductorState() }
  58.  CONDSTATE_STOPPED    = 0;   { clock is stopped              }
  59.  CONDSTATE_PAUSED     = 1;   { clock is paused               }
  60.  CONDSTATE_LOCATE     = 2;   { go to 'running' when ready    }
  61.  CONDSTATE_RUNNING    = 3;   { run clock NOW                 }
  62.  
  63. { These do not actually exist as Conductor states, but are used as additional
  64.  * arguments to SetConductorState()
  65.  }
  66.  CONDSTATE_METRIC     = -1;   { ask high node to locate       }
  67.  CONDSTATE_SHUTTLE    = -2;   { time changing but not running }
  68.  CONDSTATE_LOCATE_SET = -3;   { maestro done locating         }
  69.  
  70.  
  71. {***************************************************************************}
  72.  
  73.  
  74. { The Player is the connection between a Conductor and an application.
  75.  *
  76.  * This structure must only be allocated by realtime.library and is
  77.  * READ-ONLY!
  78.  }
  79. Type
  80.  Player = Record
  81.     pl_Link             : Node;
  82.     pl_Reserved0,
  83.     pl_Reserved1        : Byte;
  84.     pl_Hook             : HookPtr;       { player's hook function       }
  85.     pl_Source           : ConductorPtr;  { pointer to parent context    }
  86.     pl_Task             : TaskPtr;       { task to signal for alarm     }
  87.     pl_MetricTime       : Integer;       { current time in app's metric }
  88.     pl_AlarmTime        : Integer;       { time to wake up              }
  89.     pl_UserData         : Address;       { for application use  }
  90.     pl_PlayerID         : WORD;          { for application use  }
  91.     pl_Flags            : WORD;          { general Player flags         }
  92.  end;
  93.  PlayerPtr = ^Player;
  94.  
  95. const
  96. { Flag bits for Player.pl_Flags }
  97.  PLAYERF_READY     = 1;   { player is ready to go!        }
  98.  PLAYERF_ALARMSET  = 2;   { alarm is set                  }
  99.  PLAYERF_QUIET     = 3;   { a dummy player, used for sync }
  100.  PLAYERF_CONDUCTED = 8;   { give me metered time          }
  101.  PLAYERF_EXTSYNC   = 16;   { granted external sync         }
  102.  
  103.  PLAYERB_READY     = 0;
  104.  PLAYERB_ALARMSET  = 1;
  105.  PLAYERB_QUIET     = 2;
  106.  PLAYERB_CONDUCTED = 3;
  107.  PLAYERB_EXTSYNC   = 4;
  108.  
  109.  
  110. {***************************************************************************}
  111.  
  112.  
  113. { Tags for CreatePlayer(), SetPlayerAttrs(), and GetPlayerAttrs() }
  114.  PLAYER_Base         = (TAG_USER+64)   ;
  115.  PLAYER_Hook         = (PLAYER_Base+1) ;  { set address of hook function }
  116.  PLAYER_Name         = (PLAYER_Base+2) ;  { name of player       }
  117.  PLAYER_Priority     = (PLAYER_Base+3) ;  { priority of player           }
  118.  PLAYER_Conductor    = (PLAYER_Base+4) ;  { set conductor for player     }
  119.  PLAYER_Ready        = (PLAYER_Base+5) ;  { the "ready" flag             }
  120.  PLAYER_AlarmTime    = (PLAYER_Base+12);  { alarm time (sets PLAYERF_ALARMSET) }
  121.  PLAYER_Alarm        = (PLAYER_Base+13);  { sets/clears PLAYERF_ALARMSET flag  }
  122.  PLAYER_AlarmSigTask = (PLAYER_Base+6) ;  { task to signal for alarm/notify    }
  123.  PLAYER_AlarmSigBit  = (PLAYER_Base+8) ;  { signal bit for alarm (or -1) }
  124.  PLAYER_Conducted    = (PLAYER_Base+7) ;  { sets/clears PLAYERF_CONDUCTED flag   }
  125.  PLAYER_Quiet        = (PLAYER_Base+9) ;  { don't process time thru this }
  126.  PLAYER_UserData     = (PLAYER_Base+10);
  127.  PLAYER_ID           = (PLAYER_Base+11);
  128.  PLAYER_ExtSync      = (PLAYER_Base+14);  { attempt/release to ext sync  }
  129.  PLAYER_ErrorCode    = (PLAYER_Base+15);  { error return value           }
  130.  
  131.  
  132. {***************************************************************************}
  133.  
  134.  
  135. { Method types for messages sent via a Player's hook }
  136.  PM_TICK     = 0;
  137.  PM_STATE    = 1;
  138.  PM_POSITION = 2;
  139.  PM_SHUTTLE  = 3;
  140.  
  141. Type
  142. { used for PM_TICK, PM_POSITION and PM_SHUTTLE methods }
  143.  pmTime = Record
  144.     pmt_Method  : Integer;        { PM_TICK, PM_POSITION, or PM_SHUTTLE }
  145.     pmt_Time    : Integer;
  146.  end;
  147.  pmTimePtr = ^pmTime;
  148.  
  149. { used for the PM_STATE method }
  150.  pmState = Record
  151.     pms_Method  : Integer;        { PM_STATE }
  152.     pms_OldState: Integer;
  153.  end;
  154.  pmStatePtr = ^pmState;
  155.  
  156.  
  157. {***************************************************************************}
  158.  
  159. const
  160. { Possible lock types for LockRealTime() }
  161.  RT_CONDUCTORS = 0;   { conductor list }
  162.  
  163.  
  164. {***************************************************************************}
  165.  
  166.  
  167. { realtime.library error codes }
  168.  RTE_NOMEMORY    = 801;   { memory allocation failed      }
  169.  RTE_NOCONDUCTOR = 802;   { player needs a conductor      }
  170.  RTE_NOTIMER     = 803;   { timer (CIA) allocation failed }
  171.  RTE_PLAYING     = 804;   { can't shuttle while playing   }
  172.  
  173.  
  174. {***************************************************************************}
  175.  
  176.  
  177. { OpenLibrary("realtime.library",0) returns a pointer to this structure.
  178.  * All fields are READ-ONLY.
  179.  }
  180. Type
  181.  RealTimeRec = Record
  182.     rtb_LibNode     : Library;
  183.     rtb_Reserved0   : Array[0..1] of Byte;
  184.  
  185.     rtb_Time,                      { current time                         }
  186.     rtb_TimeFrac    : Integer;     { fixed-point fraction part of time    }
  187.     rtb_Reserved1   : WORD;
  188.     rtb_TickErr     : WORD;        { nanosecond error from ideal Tick     }
  189.  end;                              { length to real tick length           }
  190.  
  191. VAR RealTimeBase : ^RealTimeRec;
  192.  
  193. { Actual tick length is: 1/TICK_FREQ + rtb_TickErr/1e9 }
  194.  
  195. const
  196.  RealTime_TickErr_Min = -705;
  197.  RealTime_TickErr_Max =  705;
  198.  
  199.  
  200. {***************************************************************************}
  201.  
  202.  
  203.