|Token code:||254/$FE 12/$0B|
in BASIC ROM:
|List of all BASIC keywords|
Type: Command General Programming-Syntax: SLEEP integer
The BASIC command SLEEP stops BASIC program execution for a specified amount of seconds according to the integer parameter. The argument might range from 0 65535. The running mode SLOW/FAST does not influence the timing behavior.
If the value exceeds the previous mentioned range this leads to the error ?ILLEGAL QUANTITY ERROR. Without an argument or more than one argument rises a ?SYNTAX ERROR.
- Even in FAST mode SLEEP works as expected!
- With SLEEP 0 the system waits for the next interrupt. The delay lies in the range from 0 to 16,7 milliseconds (on a NTSC system). Because the timing on the C128 is based on the system's raster interrupt,
SLEEP 0provides a possibility to synchronize with VIC screen frame cycle.
Examples[edit | edit source]
100 PRINT "WAIT A MINUTE ..."; 110 SLEEP 60 120 PRINT "TIME PASSED!"
On each frame the color is changed twice without distortions (except some key is pressed).
SLEEP for BASIC 2.0
With BASIC V2 a SLEEP function could be realized as follows (in a subroutine at line 10):
1 GOTO 100 10 T0=TI: FOR T=T0+T*60 TO T: T=TI: T=T-5184E3*(T<T0): NEXT: RETURN 100 T=5: GOSUB 10: PRINT "TIME PASSED!"
The assignment T=5 passes the delay time to the subroutine in line 10. It might also contain a fractional value.
This implementation considers also the TI timer wrap-around after 24 h at 5184000 (60 ticks/second × 86400 seconds/day).
The expression (T<T0) gives -1 if true, which leads to the addition of the 24h value to ensure that variable T reaches the end value, even TI wrapped back to 0.