home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff236.lzh / DiskHandler / timer.c < prev    next >
C/C++ Source or Header  |  1989-08-09  |  3KB  |  98 lines

  1. /* Timer.c - Timer support routines */
  2.  
  3. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  4. /* |_o_o|\\ Copyright (c) 1987 The Software Distillery.  All Rights Reserved */
  5. /* |. o.| || This program may not be distributed without the permission of   */
  6. /* | .  | || the author.                                           BBS:      */
  7. /* | o  | ||   John Toebes    Dave Baker                     (919)-471-6436  */
  8. /* |  . |//                                                                  */
  9. /* ======                                                                    */
  10. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  11.  
  12. #include "handler.h"
  13.  
  14. int OpenTimer(global)
  15. GLOBAL global;    
  16. {
  17.    int error;
  18.  
  19.    /* assumes that a msg port has been allocated */   
  20.  
  21.    if ((global->timerpkt = (struct TimerPacket *)
  22.                 CreateExtIO(global->port, sizeof(struct TimerPacket)))== NULL)
  23.      return(1);
  24.  
  25.    global->timerpkt->tm_req.tr_node.io_Message.mn_Node.ln_Name = 
  26.                                          (char *)&(global->timerpkt->tm_pkt);
  27.    global->timerpkt->tm_pkt.dp_Link =
  28.                                  &(global->timerpkt->tm_req.tr_node.io_Message);
  29.    global->timerpkt->tm_pkt.dp_Port = global->port;
  30.  
  31.    if ((global->systimepkt = (struct timerequest *)
  32.       CreateExtIO(global->port, sizeof(struct timerequest)))== NULL)
  33.       return(1);
  34.  
  35.    error = OpenDevice(TIMERNAME, UNIT_MICROHZ, 
  36.                          (struct IORequest *)&(global->timerpkt->tm_req), 0);
  37.  
  38.    /* Fill in the packet we will use for getting the system time */
  39.    global->systimepkt->tr_node.io_Device =
  40.                                      global->timerpkt->tm_req.tr_node.io_Device;
  41.    global->systimepkt->tr_node.io_Unit   =
  42.                                      global->timerpkt->tm_req.tr_node.io_Unit;
  43.    return(error);
  44. }
  45.  
  46. void GetDateStamp(global, date)
  47. GLOBAL global;
  48. struct DateStamp *date;
  49. {
  50.    register struct timerequest *tr = global->systimepkt;
  51.  
  52.    tr->tr_node.io_Command = TR_GETSYSTIME;
  53.    tr->tr_node.io_Flags   = IOF_QUICK;
  54.    DoIO((struct IORequest *)tr);
  55.    MakeDateStamp(&tr->tr_time, date);
  56. }
  57.  
  58. void CloseTimer(global)
  59. GLOBAL global;
  60. {
  61.    if (global->timerpkt != NULL)
  62.       {
  63.       CloseDevice((struct IORequest *)&(global->timerpkt->tm_req));
  64.       DeleteExtIO((struct IORequest *)global->timerpkt);
  65.       global->timerpkt = NULL;
  66.       }
  67.  
  68.    if (global->systimepkt != NULL)
  69.       {
  70.       DeleteExtIO((struct IORequest *)global->systimepkt);
  71.       global->systimepkt = NULL;
  72.       }
  73. }
  74.  
  75. void PostTimerReq (global)
  76. GLOBAL global;
  77. {
  78.    /* Fill in the timer packet values */
  79.    /* that is the fields required for the timer device timerequest struct */
  80.    /* and the necessary fields of the DosPacket struct                    */
  81.    /* nothing like using 35 meg of store to accomplish a simple task      */
  82.    /* oh well ! this is a 68K machine right ?                             */ 
  83.    /* some of them get trampled on so fill them all */
  84.  
  85.    if (global->timerpkt != NULL)
  86.       {
  87.       global->timerpkt->tm_req.tr_node.io_Command = TR_ADDREQUEST;
  88.       global->timerpkt->tm_req.tr_time.tv_secs = 2; 
  89.       global->timerpkt->tm_req.tr_time.tv_micro = 0;
  90.  
  91.       global->timerpkt->tm_pkt.dp_Type = ACTION_TIMER;
  92.       
  93.       /* Async IO so we don't sleep here for the msg */
  94.      
  95.       SendIO((struct IORequest *)&global->timerpkt->tm_req);
  96.       }
  97. }
  98.