| |
Krill
Registered: Apr 2002 Posts: 2980 |
TIL: The instruction after SEI can be executed before a pending IRQ is handled
As described here: http://visual6502.org/wiki/index.php?title=6502_Timing_of_Inter..
I never knew this, after all those years, and thought i'd share this as a heads-up.
Thanks to Bubis for pointing it out to me! |
|
... 89 posts hidden. Click here to view all posts.... |
| |
Dano
Registered: Jul 2004 Posts: 234 |
Quote: I think you're reading the trace wrong. The next instruction following an SEI can be fetched, but not executed if an IRQ occurs during the SEI. The instruction will be re-fetched and executed following the RTI.
And yes, protecting IRQ setup with SEI/CLI is still wrong, but not for this reason :)
Sorry for being offtopic there, but why is putting the IRQ setup into SEI/CLI wrong? Doesn't this ensure that no IRQ is happening while setting up the shizzle? I am happy to be enlighted on how to do this correctly. |
| |
TWW
Registered: Jul 2009 Posts: 545 |
Quote: Sorry for being offtopic there, but why is putting the IRQ setup into SEI/CLI wrong? Doesn't this ensure that no IRQ is happening while setting up the shizzle? I am happy to be enlighted on how to do this correctly.
What he said |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
Quoting MagerValpI think you're reading the trace wrong. The next instruction following an SEI can be fetched, but not executed if an IRQ occurs during the SEI. The instruction will be re-fetched and executed following the RTI.
Ok, that makes a lot more sense. |
| |
MagerValp
Registered: Dec 2001 Posts: 1078 |
SEI doesn't prevent IRQs from happening, it just stops the CPU from handling them. Odds are good that you have a pending IRQ when you CLI, which means you have to have extra setup code to clear that. So for your generic $080d setup code, simply do
lda #$7f
sta $dc0d before setting up a raster IRQ instead of using SEI. |
| |
lft
Registered: Jul 2007 Posts: 369 |
Quoting MagerValpI think you're reading the trace wrong. The next instruction following an SEI can be fetched, but not executed if an IRQ occurs during the SEI. The instruction will be re-fetched and executed following the RTI.
That makes more sense indeed. The status register will still be pushed with I set, but the interrupt handler is called between the SEI and the following instruction. Phew! |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
Quote: SEI doesn't prevent IRQs from happening, it just stops the CPU from handling them. Odds are good that you have a pending IRQ when you CLI, which means you have to have extra setup code to clear that. So for your generic $080d setup code, simply do
lda #$7f
sta $dc0d before setting up a raster IRQ instead of using SEI.
you also need lda $dc0d to clear the pending irq, lda #$7f.. just stops more to happen. afaik.
lda #$7f
sta $dc0d
sta $dd0d
lda $dc0d
lda $dd0d
to be on the safe side. |
| |
lft
Registered: Jul 2007 Posts: 369 |
Yes, but the point is that if you do
lda #$7f
sta $dc0d
before turning off interrupts, then you don't have to clear the flag. If there is an interrupt pending, it will be invoked right now, once. Then it will be off.
On a side note, there is no need to disable CIA2 interrupts (NMI) at the beginning of a program that is launched from BASIC. They aren't active in that environment. |
| |
Krill
Registered: Apr 2002 Posts: 2980 |
Quoting MagerValpI think you're reading the trace wrong. The next instruction following an SEI can be fetched, but not executed if an IRQ occurs during the SEI. The instruction will be re-fetched and executed following the RTI. You're probably right, that makes a lot more sense. The text on visual6502.org is a bit ambiguous.
Oswald: I guess it's safe to assume that previously installed interrupt handlers would acknowledge their IRQs until you disable them. So don't exchange one cargo cult for another. :)
But anyhow, SEI/CLI is required when you install interrupt hooks on top of pre-existing handlers, especially if you have no knowledge of which interrupts are currently active and shall remain so. |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
ah right, my eye didnt catch the instead :)thanks. |
| |
Krill
Registered: Apr 2002 Posts: 2980 |
Quoting lftOn a side note, there is no need to disable CIA2 interrupts (NMI) at the beginning of a program that is launched from BASIC. You do, however, want to trigger one NMI that you never acknowledge, so the pesky restore key won't disrupt your meticulously hand-crafted timing. :) |
Previous - 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 - Next |