      PROGRAM WAKE_UP
C
C     The purpose of this program
C     is to wake you up by beeping
C     every second.
C
      EXTERNAL WAIT_AST
C     Set up COMMON with time delay value
C     and address of the AST in it.
      COMMON/TIMER/TIME,WAIT_AST_ADDR
      INTEGER*4 TIME(2),WAIT_AST_ADDR
C     Remember that system times are quadwords
C     counted in 100 nanosecond ticks.
C     The low order half comes first.
      TIME(1) = 1 * 10000000
      TIME(2) = 0
C     Convert to delta time
      TIME(1) = - TIME(1)
      TIME(2) = -1
C     Store AST address in COMMON
      WAIT_AST_ADDR = %LOC(WAIT_AST)
C     Issue first timer request
      CALL IFERR(SYS$SETIMR(,TIME,
     &   %VAL(WAIT_AST_ADDR),%VAL(1)))
C     Now, just fiddle the time away.
C     The AST routine will handle everything!
10    GOTO 10
      END
      
      SUBROUTINE WAIT_AST(M)
C
C     This routine types out a message
C     and requests another wake up call
C     later on.
C
      COMMON/TIMER/TIME,WAIT_AST_ADDR
      INTEGER*4 TIME(2),WAIT_AST_ADDR
C     Watch out, our parameter is passed
C     to us by value! Use %LOC to retrieve
C     that value.
      N = %LOC(M)
C     Type out message
      TYPE *,CHAR(7)//'Wake up call number',N
C     Request another timed AST
      CALL IFERR(SYS$SETIMR(,TIME,
     &   %VAL(WAIT_AST_ADDR),%VAL(N+1)))
      RETURN
      END
