Friday, October 18, 2013

Petit Computer Journal #21


A Simple Timer

This here is a simplified version of the timer program. I put it here just to clarify that there are other ways to do this. The previous version was used to show LOOP construct, but this version is an optimized version of it. Notice that duplicate codes are collapsed into one, thus simplifying the whole structure.



  1. 'TIMER PROGRAM BY HARRY HARDJONO
  2. SPSET 1,156,0,0,0,0
  3. SPOFS 1,-50,-50
  4. SPANIM 1,4,15
  5. SPSCALE 1,200

  6. @INIT
  7. CLS
  8. SPOFS 1,0,96,0
  9. SPREAD(1),X,Y
  10. ?"HOW MANY SECONDS?"
  11. INPUT T
  12. IF 0>=T GOTO @END
  13. CLS
  14. ?"A STARTS TIMER"
  15. ?"B SETS NEW TIME"
  16. ?"X EXIT"
  17. ?"Y PAUSE"

  18. @LOOP
  19. VSYNC 1:B=BTRIG()
  20. IF (SPCHK(1) AND 1) THEN SPOFS 1,X,Y,0 
  21. IF (B AND 16) THEN SPOFS 1,224,96,FLOOR((224-X)*T/224)*60:GOTO @TICK
  22. IF (B AND 32) GOTO @INIT
  23. IF (B AND 64) GOTO @END
  24. GOTO @LOOP
  25. @TICK
  26. IF (BUTTON(0) AND 128) GOTO @LOOP
  27. LOCATE 0,8:SPREAD(1),X,Y:?"TIME LEFT: ";FLOOR((224-X)*T/224);"   "
  28. IF (SPCHK(1) AND 1) THEN BEEP 28:WAIT 60:GOTO @TICK
  29. ?"TIME'S UP!":SPOFS 1,0,96,0:X=0:BEEP 50:WAIT 120
  30. GOTO @LOOP

  31. @END
  32. ?"GOODBYE!"
  33. SPCLR 1:WAIT 300


No comments:

Post a Comment