The datasheet of the 68HC11 states, that the X bit can be only cleared by
software, but not set. However, this is not quite true.
Somehow the 68HC11 must be able to set the flag obviously, since it is set
after a reset, and when entering the interrupt routine after a XIRQ
occurred.
Upon reaching the rti instruction of the interrupt routine, the previous
state of the flag is restored, that is: It's cleared again when it was
clear before, and it is left set when it was set before.
But how does the 68HC11 know which state the X flag had before calling the interrupt routine ?
The answer is as simple as the solution to the problem of masking the XIRQ: It just looks at the saved CCR on the stack !
That means: If you write a interrupt routine that modifies the saved CCR on
the stack and then trigger a XIRQ, the XIRQ will be masked again !
An interrupt routine doing so might look like this:
xirq_handler:
tsx
bset 1,X #%01000000
rti