home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / oplexamp / TIMERS2.OPL < prev    next >
Text File  |  1994-06-10  |  3KB  |  134 lines

  1. REM This is a nice and simple
  2. REM introduction to the timer device
  3. REM present in all Series 3 models.
  4. REM It just produces two flashing
  5. REM squares on screen, each one is
  6. REM tied to a different timer, and
  7. REM at the same time, the user is
  8. REM still free to type.
  9.  
  10. REM This example uses function 1
  11. REM of the timer device known as
  12. REM P_FRELATIVE - start timing in
  13. REM tenths of a second relative
  14. REM to now. Note that the timer
  15. REM device expects the tenths
  16. REM variable to be a LONG integer.
  17.  
  18. REM It also uses function 4
  19. REM (known as P_FCANCEL)
  20. REM which cancels IOAs on ANY
  21. REM device, and is always safe
  22. REM to use, even if an IOA isn't
  23. REM outstanding.
  24.  
  25. REM The `magic' value -46 in this
  26. REM code means "I/O pending".
  27. REM In other words, the IOA hasn't
  28. REM finished yet.
  29.  
  30. REM Note the importance of error
  31. REM checking. This is vital when
  32. REM dealing with device drivers.
  33.  
  34. REM Do not remove the keymod%
  35. REM variable, although it looks
  36. REM unused, it is actually
  37. REM filled in by the KEYA
  38. REM function.
  39.  
  40. REM Feel free to use this example
  41. REM in any OPL programs.
  42. REM
  43. REM jezar@cix
  44.  
  45.  
  46. PROC Squares:
  47.     LOCAL tenths1&,tenths2&
  48.     LOCAL thand1%,thand2%
  49.     LOCAL tstat1%,tstat2%
  50.     LOCAL kstat%,keyprs%,keymod%
  51.     LOCAL bitmap%
  52.     
  53.     bitmap%=gCREATE(140,10,75,50,1)
  54.     gBORDER 1
  55.     
  56.     CURSOR ON
  57.     PRINT "Type something,"
  58.     PRINT "`Esc' to quit."
  59.     PRINT "";
  60.     
  61.     REM Our timer speeds:
  62.     tenths1&=5 :tenths2&=7
  63.     
  64.     REM Open two timer channels:
  65.     iocheck%:(IOOPEN(thand1%,"TIM:",-1))
  66.     iocheck%:(IOOPEN(thand2%,"TIM:",-1))
  67.     
  68.     REM Start both timers going:
  69.     iocheck%:(IOA(thand1%,1,tstat1%,tenths1&,#0))
  70.     iocheck%:(IOA(thand2%,1,tstat2%,tenths2&,#0))
  71.     
  72.     REM Issue a request for a keypress:
  73.     iocheck%:(KEYA(kstat%,keyprs%))
  74.     
  75.     DO
  76.         REM Wait for anything
  77.         IOWAIT
  78.         
  79.         REM Was key pressed?
  80.         IF kstat%<>-46
  81.             iocheck%:(kstat%)
  82.             IF keyprs%=13
  83.                 PRINT
  84.                 PRINT "";
  85.             ELSE
  86.                 PRINT CHR$(keyprs%);
  87.             ENDIF
  88.             
  89.             REM We now request another keypress:
  90.             iocheck%:(KEYA(kstat%,keyprs%))
  91.             
  92.         REM Has 1st timer finished?
  93.         ELSEIF tstat1%<>-46
  94.             iocheck%:(tstat1%)
  95.             gAT 5,5
  96.             gINVERT 20,20
  97.             
  98.             REM We now restart this timer:
  99.             iocheck%:(IOA(thand1%,1,tstat1%,tenths1&,#0))
  100.             
  101.         REM Has 2nd timer finished?
  102.         ELSEIF tstat2%<>-46
  103.             iocheck%:(tstat2%)
  104.             gAT 30,5
  105.             gINVERT 40,40
  106.             
  107.             REM We now restart this timer:
  108.             iocheck%:(IOA(thand2%,1,tstat2%,tenths2&,#0))
  109.             
  110.         ELSE
  111.             REM This shouldn't happen:
  112.             ALERT("Stray signal")
  113.         ENDIF
  114.     
  115.     UNTIL keyprs%=27 :REM `Esc' code
  116.     
  117.     REM Cancel everything:
  118.     KEYC(kstat%)
  119.     IOW(thand2%,4,#0,#0)
  120.     IOW(thand1%,4,#0,#0)
  121.     
  122.     REM ..and close:
  123.     IOCLOSE(thand2%)
  124.     IOCLOSE(thand1%)
  125.     gCLOSE(bitmap%)
  126. ENDP
  127.  
  128. PROC iocheck%:(code%)
  129.     IF code%
  130.         RAISE code%
  131.     ENDIF
  132. ENDP
  133.  
  134.