home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / M2V11-1.LHA / modula / examples / src / IncTime.mod < prev    next >
Encoding:
Text File  |  1994-09-28  |  2.3 KB  |  67 lines

  1. (* This is a program that I hacked up when I discoverd my A1200 did not      *)
  2. (*  come with a real time clock.This makes it difficult to use MAKE like     *)
  3. (* programs (eg M2B) which rely on file timestamps.                 *)
  4. (* I once read in amiga publication that on failing to detect a RTC the      *)
  5. (* amiga should set the current date to the most recent file created on SYS: *)
  6. (* However on booting my amiga always gave the same time.             *)
  7. (* What this program does is write out the time every 10 minutes to file     *)
  8. (* devs:time. On bootup the time is set to 11 minutes past the last time     *)
  9. (* written.This means the most recently created file will always have a      *)
  10. (* larger time/datestamp than any existing ones, as required by M2B,MAKE etc *)
  11.  
  12. (* This program is only worth using if you have a hard-disk.             *)
  13. (* It should be called from within s:user-startup/s:startup-sequence         *)
  14.  
  15. MODULE IncTime ;
  16. (* Safe to call even if no devs:time file exists, in which case time=0 *)
  17.  
  18. FROM SYSTEM IMPORT ADR ;
  19.  
  20. IMPORT Dos, Timer, Exec ;
  21.  
  22. VAR
  23.   time  : LONGINT ;
  24.   timer : Timer.TimeRequestPtr ;
  25.  
  26. PROCEDURE SetTime( i : LONGINT ) ;
  27. BEGIN
  28.   timer^.tr_time.tv_secs := i ;
  29.   timer^.tr_node.io_Command := Timer.TR_SETSYSTIME ;
  30.   Exec.DoIO( timer ) ;
  31. END SetTime ;
  32.  
  33. PROCEDURE GetTime( ) : LONGINT ;
  34. BEGIN
  35.   timer^.tr_node.io_Command := Timer.TR_GETSYSTIME ;
  36.   Exec.DoIO( timer ) ;
  37.   RETURN timer^.tr_time.tv_secs ;
  38. END GetTime ;
  39.  
  40. VAR
  41.   port : Exec.MsgPortPtr ;
  42.   num  : LONGINT ;
  43.   file : Dos.FileHandlePtr ;
  44.  
  45. BEGIN
  46.   port := Exec.CreatePort( NIL, NIL ) ;
  47.   IF port = NIL THEN HALT END ;
  48.   timer := Exec.CreateExtIO( port, SIZE( timer^ ) ) ;
  49.   IF timer = NIL THEN HALT END ;
  50.   Exec.OpenDevice( "timer.device", Timer.UNIT_VBLANK, timer, { } ) ;
  51.   file := Dos.Open("devs:time", Dos.MODE_READWRITE ) ;
  52.   IF file = NIL THEN HALT END ;
  53.   num := Dos.Read( file, ADR( time ), SIZE( time ) ) ;
  54.   num := Dos.Seek( file, 0, Dos.OFFSET_BEGINNING ) ;
  55.   INC( time , 11*60 ) ; (* Set time to 11 minutes past last written value *)
  56.   SetTime( time ) ;
  57.   LOOP
  58.     num := Dos.Write( file, ADR( time ), SIZE( time ) ) ;
  59.     num := Dos.Seek( file, 0, Dos.OFFSET_BEGINNING ) ;
  60.     Dos.Close( file ) ;
  61.     Dos.Delay( 60*10*Dos.TICKS_PER_SECOND ) ; (* Sleep for 10 minutes *)
  62.     time := GetTime( ) ;
  63.     file := Dos.Open("devs:time", Dos.MODE_READWRITE ) ;
  64.     IF file = NIL THEN EXIT END
  65.   END
  66. END IncTime.
  67.