Changes

Jump to: navigation, search

Locomotive BASIC

40 bytes added, 09:27, 13 August 2012
/* Commands and operators */
==== <code>AFTER </code>‹time delay›[<code>,</code>‹timer number›]<code> GOSUB </code>‹line number› ====
: Waits for ‹time delay›/50 seconds and then jumps NON-RECURRING to the subroutine at ‹line number›. There are 4 delay timers from 0 to 3 which can be specified with ‹timer number›. If omitted ‹timer number› defaults to 0.: In the case of parallel task has 3 the highest and 0 the lowest priority.: With DI or EI you can disable or enable the timing interrupt. With REMAIN <timer number> you can (see also disable an AFTER or EVERY construct and stores the "remaining" time (> REMAIN): Interrupts run as long as the main loop / program runs, even the main programm is paused > press ESC only '''once''' not twice for a break.: It is important to know or realise that low-priority-interrupts which occurs simultanously to higher-priority-interrupts are not lost. Their task remains or handled again after finishing the higher-prio interrupt. <pre>10 REM > interrupts20 EVERY 50i[,0 t] GOSUB 100: REM > lowest priority30 EVERY 100,1 GOSUB 20040 EVERY 200,2 GOSUB 300:50 AFTER 1000,3 GOSUB 400: REM > highest priority60 WHILE flag=070 a=a+1:print a80 WEND90 END100 REM #0110 PEN 2:PRINT line"timer 0":PEN 1120 RETURN200 REM #1210 PEN 2:PRINT "timer 1":PEN 1220 RETURN300 REM #2310 PEN 2:PRINT "timer 2":PEN 1320 RETURN400 REM #3410 flag=1:PEN 2:PRINT "no more interrupts)..."420 RETURN</pre>
==== <code>AUTO </code>[‹line number›][<code>,</code>‹increment›] ====
==== <code>EVERY i[,t] GOSUB ln</code> ====
: BASIC branches to the subroutine at line ln every EVERY (reccuring) i/50 seconds. (see also "AFTER i[,t] GOSUB line" for further informationThere are 4 delay timers from 0 to 3 which can be specified with ‹timer number›. If omitted ‹timer number› defaults to 0.: In the case of parallel task has 3 the highest and 0 the lowest priority.: With DI or EI you can disable or enable the timing interrupt. With REMAIN <timer number> you can also disable an AFTER or EVERY construct and stores the "remaining" time (> REMAIN): Interrupts run as long as the main loop / program runs, even the main programm is paused > press ESC only '''once''' not twice for a break.: It is important to know or realise that low-priority-interrupts which occurs simultanously to higher-priority-interrupts are not lost. Their task remains or handled again after finishing the higher-prio interrupt. <pre>10 REM > interrupts20 EVERY 50,0 GOSUB 100: REM > lowest priority30 EVERY 100,1 GOSUB 20040 EVERY 200,2 GOSUB 300:50 AFTER 1000,3 GOSUB 400: REM > highest priority60 WHILE flag=070 a=a+1:print a80 WEND90 END100 REM #0110 PEN 2:PRINT "timer 0":PEN 1120 RETURN200 REM #1210 PEN 2:PRINT "timer 1":PEN 1220 RETURN300 REM #2310 PEN 2:PRINT "timer 2":PEN 1320 RETURN400 REM #3410 flag=1:PEN 2:PRINT "no more interrupts..."420 RETURN</pre> 
: Hint: Timing with interrupts is important, especially if more than one interrupts run. If the interval of a subroutine driven by an interrupt is too long than the processor can never get back to deal the main program again. Work out timing by measuring the subroutine or by trial and error.
205
edits