6502 interrupts

model-b
Screenshots
Download
Compatibility
BBC Technical
Retro Fonts
Links

The 8 Bit Acorn Webring
< > Random Hub Join

If interrupts are reenabled with CLI, any pending interrupts do not happen until the instruction after the CLI has finished running.

Assume an interrupt is pending, and it is one the interrupt handler doesn't acknowledge. If interrupts are disabled and then reenabled, one might expect the 6502 to get stuck after the CLI instruction, because the interrupts are now enabled and the pending interrupt is not acknowledged by the handler. The CPU runs the handler, then returns with RTI, and should then be interrupted again, thus going into an infinite loop of interrupt handling.

The following code does not result in infinite interrupts, however:

CLI
SEI

Instead, just one interrupt occurs. The interrupt occurs after SEI, so when the handler returns the I flag is still set, and the IRQ is inhibited. (Until the next CLI, that is...)

The following code will give the expected effect:

CLI
NOP
SEI

So far, the only BBC game I've seen that needs this exact behaviour is Empire Strikes Back. It disables the OS' handling of the timer interrupt, but doesn't disable the interrupt itself, and then calls an OS routine that ends up doing a CLI followed by an SEI.

This has been noticed by others:

C64 mailing list posting by Marko Mäkelä


Tom Seddon -- email modelb snail bbcmicro full-stop com