Date : Tue, 09 Mar 2004 00:41:32 -0000
From : tom@...
Subject: CLI then SEI
Here's an interesting thing that I found out whilst tearing my hair
out over Empire Strikes Back.
Empire Strikes Back sets the OS' System VIA IRQ mask via OSBYTE &E9
such that the T1 flag is clear. Eventually, T1 times out, and never
gets acknowledged. Empire Strikes Back then calls OSBYTE &7A, which
after a bit of faffing runs this bit of code:
F129 JSR &F12E ;call autoscan
F12C CLI ;allow interrupts
F12D SEI ;disable interrupts
On my emulator, the moment CLI is finished, the T1 interrupt happens.
The OS runs the IRQ routine, but doesn't acknowledge the T1 flag, and
so the moment RTI has run (popping the status register with I clear)
the interrupt happens again. And then again. And then again.
But on a real BBC, it seems there's some kind of pipelining-like
behaviour going on. After a bit of playing around, I found that the
interrupt doesn't happen until after the instruction following the
CLI has run! So a CLI/SEI pair won't cause an infinite chain of
interrupts, though a CLI/NOP/SEI will. (The address on the stack on
entry to the IRQ routine is the instruction after the instruction
after the CLI.)
Very strange.
Should I have known this already?! :)
--Tom