home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 August / PCWorld_2000-08_cd.bin / Software / TemaCD / xbasic / xbpro.exe / xb / atimer.x < prev    next >
Text File  |  1999-12-14  |  3KB  |  85 lines

  1. '
  2. ' ####################
  3. ' #####  PROLOG  #####
  4. ' ####################
  5. '
  6. PROGRAM "atimer"
  7. VERSION "0.0003"
  8. '
  9. IMPORT "xst"
  10. '
  11. DECLARE  FUNCTION  Entry ()
  12. INTERNAL FUNCTION  Timer (timer, count, msec, time)
  13. '
  14. '
  15. ' ######################
  16. ' #####  Entry ()  #####
  17. ' ######################
  18. '
  19. ' This function tells XstStartTimer() to:
  20. '   Create and start a timer.
  21. '   Return timer number in timer1.
  22. '   Tell timer1 to cycle 10 times.
  23. '   Set timer1 interval to 1000 milliseconds.
  24. '   Call Timer() whenever timer1 times out.
  25. '
  26. '   Create and start another timer.
  27. '   Return timer number in timer2.
  28. '   Tell timer2 to cycle 3 times.
  29. '   Set timer2 interval to 2500 milliseconds.
  30. '   Call Timer() whenever timer2 times out.
  31. '
  32. ' *************************************
  33. ' *****  Timers Are Asynchronous  *****
  34. ' *************************************
  35. '
  36. ' Note that timeouts can occur at any machine instruction
  37. ' boundary in your program.  In other words, timeouts can
  38. ' interrupt your program at any point, including part way
  39. ' between lines in your program, and call the function you
  40. ' specified in XstStartTimer().  This function can thus
  41. ' encounter variables, or sets of related variables, in
  42. ' invalid or partially updated state if they are modified
  43. ' elsewhere in your program.  Timeout functions in many
  44. ' programs simply increment a timeout variable that is
  45. ' examined periodically by your program, and acted on and
  46. ' decremented when found to be non-zero.
  47. '
  48. ' Note that GraphicsDesigner timers and timeouts do not
  49. ' have these considerations, since your program has to
  50. ' call XgrProcessMessage(), XgrPeekMessage(), or another
  51. ' GraphicsDesigner function to respond to timeout messages.
  52. '
  53. FUNCTION  Entry ()
  54. '
  55.     PRINT "*****  start atimer.x program  *****"
  56.     XstStartTimer (@timer1, 10, 1000, &Timer())
  57.     XstStartTimer (@timer2, 3, 2500, &Timer())
  58.     XstGetSystemTime (@atime)
  59.     XstSleep (10000)
  60.     XstGetSystemTime (@ztime)
  61.     PRINT "actual sleep time = "; ztime-atime; " ms"
  62.     PRINT "*****  done atimer.x program  *****"
  63.     PRINT
  64. END FUNCTION
  65. '
  66. '
  67. ' ######################
  68. ' #####  Timer ()  #####
  69. ' ######################
  70. '
  71. ' This function can change count to add or subtract remaining timeouts.
  72. ' Entry() told XstStartTimer() to call this function upon timeouts.
  73. ' This function is called whenever either timer times out.
  74. ' This function can call XstKillTimer() to kill timers.
  75. ' This function can return -1 to kill the timer.
  76. '
  77. FUNCTION  Timer (timer, count, msec, time)
  78. '
  79.     PRINT RJUST$(STRING$(timer),5); RJUST$(STRING$(count),3); RJUST$(STRING$(msec),6); RJUST$(STRING$(time),10)
  80.     IF (count = 8) THEN count = 5                                ' reduce count to 5
  81.     IF (count = 3) THEN RETURN (-1)                            ' one way to kill timer
  82.     IF (count = 1) THEN XstKillTimer (timer)        ' kill timer early
  83. END FUNCTION
  84. END PROGRAM
  85.