home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / oplexamp / TIME.OPL < prev    next >
Text File  |  1992-08-26  |  5KB  |  153 lines

  1. #include <opllib.oph>       /* opl/g Language includes and definitions */
  2. #include <oplerr.oph>
  3. #include <os.oph>
  4.  
  5. PROC time:
  6.  
  7.     LOCAL err%
  8.  
  9.     PRINT "Setting time and date."
  10.     GET
  11.     
  12.     err% = ossettm%:(13,26,30,TIME_24_HOUR)
  13.     IF err% < 0
  14.         PRINT "Error =",err%
  15.         GET
  16.         STOP
  17.     ENDIF
  18.  
  19.     err% = ossetdt%:(14,1,1992)
  20.     IF err% < 0
  21.         PRINT "Error =",err%
  22.         GET
  23.         STOP
  24.     ENDIF
  25.  
  26.     PRINT "Done"
  27.     GET
  28.  
  29. ENDP
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. /* --------------------------------------------------------
  43.  Name          : ossettm%
  44.  Description   : Set the system time with current date. 
  45.  Parameters    : sec%    0 -> 59
  46.                  min%    0 -> 59
  47.                  hour%   0 -> 23 or 1 -> 12
  48.                  mode%   TIME_AM_12_HOUR   1
  49.                         TIME_PM_12_HOUR   2
  50.                         TIME_24_HOUR      4
  51.  Returned      : SUCCESS or -ve for Fail
  52.  Conditions    : the machine is an MC
  53.  Effects       : none
  54.  --------------------------------------------------------*/
  55.  
  56. PROC ossettm%:(hh%,mm%,ss%,mode%)
  57.                                 /* --------------------------- */
  58.                                 /* Local Variable Declarations */ 
  59.                                 /* --------------------------- */
  60.  
  61.   local hour%                   /* holds supplied hour                  */
  62.  
  63.                                 /* --------------------------- */
  64.                                 /*       Procedure Code        */
  65.                                 /* --------------------------- */
  66.  
  67.   if mode%<TIME_AM_12_HOUR or mode%>TIME_24_HOUR or hh%<0 or mm%<0 or ss%<0
  68.      return -2                  /* check mode in correct range          */
  69.   endif                         /* and times are positive               */
  70.   
  71.   hour% = hh%                   /* assign hour parameter so can be 
  72.                                    altered                              */
  73.   if (mode%=TIME_AM_12_HOUR or mode% = TIME_PM_12_HOUR) 
  74.                                 /* AM or PM mode                        */
  75.     if (hour%<1 or hour%>12)    /* check range for hours : return error */
  76.       return -2                 /* if out of range                      */
  77.     elseif mode% = TIME_AM_12_HOUR and hour% = 12
  78.       hour% = 0                 /* hour = 0 if AM and 12                */
  79.     elseif mode% = TIME_PM_12_HOUR and hour%<>12
  80.       hour% = hour%+12          /* if afternoon and not 12, add 12      */
  81.     endif
  82.   elseif mode% = TIME_24_HOUR and hour%>23
  83.     return -2                   /* if 24 mode,and hour !< 23,return err */
  84.   endif
  85.   if mm%<=59 and ss%<=59        /* check max positive range of min & sec*/
  86.     return setdttm%:(DAY,MONTH,YEAR,hour%,mm%,ss%)
  87.   endif
  88.   return -2                     /* if nothing return error              */
  89.  ENDP
  90.  
  91. /* --------------------------------------------------------
  92.  Name          : ossetdt%
  93.  Description   : Set the system date with current time.
  94.  Parameters    : dd%    1 -> 28,29,30,31
  95.                  mm%    1 -> 12
  96.                  yyyy%  1970 -> 2038
  97.                  mode%  0 (for future use)
  98.  Returned      : SUCCESS or -ve for Fail
  99.  Conditions    : the machine is an MC
  100.  Effects       : none
  101.  --------------------------------------------------------*/
  102.  
  103. PROC ossetdt%:(dd%,mm%,yyyy%)
  104.  
  105.                   /* --------------------------- */
  106.                   /*       Procedure Code        */
  107.                   /* --------------------------- */
  108.   
  109.     return setdttm%:(dd%,mm%,yyyy%,HOUR,MINUTE,SECOND)
  110.   
  111.  ENDP
  112.  
  113. /* --------------------------------------------------------
  114.  Name         : setdttm%:
  115.  Description  : sets system time and date
  116.  Parameters   : day% 
  117.                 month%
  118.                 year%
  119.                 hour%
  120.                 min%
  121.                 sec%
  122.  Returned     : SUCCESS (0)
  123.                 -2 fail (Invalid arguments)
  124.  Conditions   : 
  125.  Effects      : sets system time and date from 01/01/1970 00:00:00 (UNIX time)
  126.  --------------------------------------------------------
  127. */
  128.  
  129. PROC setdttm%:(day%,month%,year%,hour%,min%,sec%)
  130.  
  131. local ax%,bx%,cx%,dx%,si%,di%   /* registers  */
  132. local sec&                      
  133.  
  134.   if year%>=1970
  135.     onerr e::
  136.     sec& = (DAYS(day%,month%,year%)-25567)*86400+hour%*&e10+min%*60+sec%
  137.                                   /* seconds since 01/01/1970 00:00:00
  138.                                      25567 = days (01/01/1970)
  139.                                      86400 = seconds in a day (24*60*60
  140.                                      &e10 = 3600 (ie seconds in an hour)  */
  141.     cx% = peekw(addr(sec&)+2)     /* MS word of seconds into cx           */
  142.     dx% = peekw(addr(sec&))       /* LS word of seconds into dx           */
  143.     ax% = $0300                   /* TimSetSystem is function 3 of
  144.                                      TimManager                           */
  145.     os($89,addr(ax%))             /* $89 = TimManager interrupt -
  146.                                      no flags returned                    */
  147.     return 0
  148.   endif
  149.   e::                             /* error handling label                 */
  150.   onerr off
  151.   return -2
  152. ENDP
  153.