home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Program..: Ticker.prg
- ** Author...: Brenton Farmer
- ** Date.....: 10/10/91
- **
- ** Purpose..: Set of routines to attach a Clipper function to the
- ** system clock interrupt int 8.
- **
- */
- #include "inkey.ch"
- #define TRUE .T.
- #define FALSE .F.
-
- Static bFunction
-
- #define _TEST
- #ifdef _TEST
- Function Main()
- Local cString := "Now Is the Time"
- Local cString2 := "Bla Bla Bla "
-
- cls
- Ticker( 1, "ShowTime")
- setkey( K_ALT_T, {|| HotKeyTest()})
-
- @10,00 say " Type some stuff:" get cString
- @11,00 say " Type some more :" get cString2
- read
-
- setkey( K_ALT_T)
- Ticker( 0)
-
- Return ( NIL)
-
- Function ShowTime()
- Local nRow, nCol, nCursor
-
- nCursor := setcursor( 0)
- nRow := row()
- nCol := col()
- DevPos( 00,70)
- DevOut( time())
- setpos( nRow, nCol)
- setcursor( nCursor)
-
- Return ( NIL)
-
- Function HotKeyTest()
- Local nRow, nCol, nCursor
-
- nCursor := setcursor( 0)
- nRow := row()
- nCol := col()
- DevPos( 00,70)
- DevOut( time())
- setpos( nRow, nCol)
- setcursor( nCursor)
-
- Return ( NIL)
-
- #endif
-
-
- /*
- ** Void Ticker( nTime, cUserFunc)
- **
- ** Attach/UnAttach a Clipper function to the system time interrupt.
- **
- ** If the function was called with nTime and cUserFunc values attempt
- ** to attach ( cUserFunc) to the system timer so that it is executed
- ** every nTime seconds. The system timer is hit 18.2 times ( ticks)
- ** so nTime must be converted into ticks ( int( nTime * 18.2)). If
- ** ticker() is called without parameters and we have previously attached
- ** a function unattach it and restore the original int 8 interrupt
- ** vector.
- **
- ** Arguments:
- ** nTime = Time interval to call ( cUserFunc) expressed in seconds.
- ** cUserFunc = Name of Clipper function to execute every nTime seconds
- **
- */
- Function Ticker( nTime, cUserFunc)
- Static lActive := FALSE
-
- /*
- ** If we have previously redirected the int 8 interrupt vector to our
- ** own routine restore it to its original value.
- */
- if lActive
- C10ckSet( 0)
- lActive := FALSE
- endif
-
- /*
- ** If the ticker() was called with nTime and cUserFunc values attempt
- ** to attach ( cUserFunc) to the system timer. Do the following:
- **
- ** 1. Ensure that ( cUserFunc) has been linked in.
- ** 2. Compile cUserFunc into code block bFunction in order to
- ** cut down runtime overhead from within C10ckEval().
- ** 3. Convert nTime into timer ticks and call the C C10ckSet() function.
- ** 4. Set the lActive flag true.
- */
- if ( nTime != NIL .and. cUserFunc != NIL)
- if !( type( alltrim( cUserFunc)+"()") == "U") // is ( cUserFunc) linked
- bFunction := &("{||" + cUserFunc + "()}") // Yes
- eval( bFunction)
- C10ckSet( int( nTime * 18.2))
- lActive := TRUE
- endif
- endif
-
- Return ( NIL)
-
-
- /*
- ** C10ckEval()
- **
- ** Clock evaluation routine called from our C code int 8 isr routine
- ** C10ckISR() in tickerc.c. Evaluate the code block bFunction which
- ** was defined in Ticker().
- */
- Function _C10ckEval
- eval( bFunction)
- Return ( NIL)
-
-