The timer interrupt will cause an immediate branch to a specified line number or label (similar to a GOSUB). Return from an interrupt is via the IRETURN statement. All statements (including GOSUB/RETURN) can be used within an interrupt.
During processing of an interrupt all other interrupts are disabled until the interrupt routine returns with an IRETURN.
A periodic interrupt (or regular “tick”) with a period specified in milliseconds can be setup using the SETTICK statement. This interrupt has the lowest priority.
Interrupts can occur at any time but they are disabled during INPUT statements. If you need to get input from the keyboard while still accepting interrupts you should use the INKEY$ function. When using interrupts the main program is completely unaffected by the interrupt activity unless a variable used by the main program is changed during the interrupt.
For most programs MMBasic will respond to an interrupt in under 100µS. To prevent slowing the main program by too much an interrupt should be short and execute the IRETURN statement as soon as possible.
Also remember to disable an interrupt when you have finished needing it – background interrupts can cause strange and non-intuitive bugs.
All commands that use an interrupt (eg, SETTICK, ON KEY, etc) can specify a user defined subroutine an addition to a label or a line number. The interrupt subroutine will return control to the main program on an END SUB or EXIT SUB (ie, IRETURN should not be used in the subroutine).