This trap simply switches the QL into Supervisor mode. This means that from this point onwards, nothing will multi-task and you have total control of the machine. It also means that nothing will get shifted in memory
When in Supervisor mode, it is advised to keep routines small and not use more than about 64 bytes of stack. Remember that you are using a different stack now and the value in A7 before the trap is not what it will be after the trap.
Getting out of supervisor mode requires that you turn off the S bit in the status register as follows :
start trap #0 ; Switch into supervisor mode ; ; Do supervisor stuff here andi #$07ff,sr ; Return to user mode
The state of the machine, whether in user or supervisor mode is controlled by the Status Register, which looks like this :
Bit 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Trace | Supervisor | Interrupt | eXtend | Negative | Zero | oVerflow | Carry |
Bit 13 is the supervisor state bit, and when set to 1 indicates that the system is running in Supervisor mode and will be using the Supervisor Stack Pointer version of A7 as opposed to the User Stack Pointer version. When set to 0, the system is running in user mode.
In the code example above, to return to user mode after the supervisor code has been executed, the instruction
andi #$07ff,sris used. This preserves all bits of the SR, except for the Trace & Supervisor bits which is forced back to zero, thus turning these options off.
Note : I have seen code which uses $0dff to switch back into user mode. This has the effect of setting the interupt level in bits 10 to 8 to level 3 (011 in binary) which may or may not be a good thing !