Multi-channel MultiTrack: Suppressing J
There may be times when you are making a multi-channel program using MultiTrack, but need to suppress the jndexed addressing. To achieve this we have introduced a new class of instruction modifier, called a precode.
If any memory or I/O instruction is preceded by NoJ: the normal jndexed addressing will be prevented for that single instruction.
A trap for young players!!
If you GoSub from inside a MultiTrack task, the caller’s J will be used in the subroutine. This can be trap that leads to hard to find bugs. Be careful when writing single-channel subroutines that may be called from multi-channel tasks. Use NoJ: to prevent this happening.
Example:
Imagine in our push on/push off light switch (yes, that same tired old example again!) we want input 7 to enable the outputs. Hence an output may only be on while input 7 is on.
(Click here for some tips for working around problems with copy and paste out of Internet Explorer and HTML-help (.chm) files)
LaunchTask Toggle,0
LaunchTask Toggle,1
LaunchTask Toggle,2
LaunchTask Toggle,3
RunTasksForever
Toggle:
WaitOnK 0 ;Wait for turn-on command
On 4
Toggle1:
YieldTask
GoIfInK 0,Toggle2 ;Test for turn-off
NoJ:GoIfInOn 7,Toggle1 ;Test shared enable i/p
Toggle2:
Off 4
GoTo Toggle
Copy this program into SPLat/PC and study its behaviour. Use the register display to show you what J is doing. You will see I have changed the WaitOnK that turns off the light into a “Yield loop” which tests both the push button (GoIfInK) and the enable input (NoJ:GoIfInOn).
Exercise 1:
The above program has a flaw. If the enable input (7) is off, pressing one of the buttons (0-3) will result in the light flashing on very briefly. This kind of thing could be a nuisance if you were making a lighting system. It would be more than embarrassing if you were making an explosives detonation controller for a coal mine! Modify the program so no light can come on, even momentarily, while input 7 is off. It must work correctly:
- When input 7 is turned on momentarily then off again while the outputs are off. There must be no “carry over” from 7 having been on.
- When one of inputs 0-3 is activated while 7 is off. The light must not come on if input 7 is subsequently turned on.
This exercise should illustrate to you how important it is to design and test for every imaginable circumstance. See also our product disclaimer.