lightbeing wrote:
I'm not sure I fully understood a specific mechanism in the interrupt behaviour. Can anyone help me.
Page 131 of the MCS 6500 programming manual dated January 1976 indicates that during cycle 1 of an IRQ, the processor finishes the previous operation.
I also read this here
https://www.pagetable.com/?p=410 "If there is an IRQ pending and the current instruction has just finished, the interrupt logic in the 6502 forces the instruction register (“IR”) to “0”, so instead of executing the next instruction, the PLA will decode the instruction with the opcode 0x00 – which is BRK!".
Let's imagine an interrupt occurs while the processor is executing a series of NOP's, which take 2 cycles each.
Does this mean that in this case, finishing the previous operation can take either 1 or 2 cycles?
I think there's a tension in every description of interrupt handling, between being simple enough to explain and being detailed enough to be precisely correct. It's rare indeed to see a description which is absolutely correct, because the cycle-by-cycle behaviour is, as it turns out, rather subtle.
That programming manual - link
here to the exact page - has a table which counts off the cycles of the interrupt sequence, starting from the SYNC cycle which is the fetch of the instruction following the last one to complete.
Garth is right in saying that even during that SYNC cycle there are (potentially) internal operations which finish off the actions of that last instruction. But there's no way to see that from the outside, either in hardware or in software. We only see that by looking at the insides of the chip, for example with visual6502. It's interesting because without understanding this, the cycle counts of the instructions don't quite make complete sense.
Michael (aka the pagetable author) is of course also right. The SYNC cycle of the first instruction not to be executed proceeds as normal, as far as the chip's external signals tell us, but on the inside the instruction fetched is replaced with 00. There's no way to see this from the outside.
The program manual is right, in that the cycle after the SYNC is another read, but uniquely it is a read from the same address as the SYNC. This only happens in the case of an interrupt. However, I don't think I would have labelled this as Fetch, because it's not a SYNC cycle. I might have labelled it as Internal Operation.
If you count the IRQ from the cycle in which it is asserted - which is not what the manual is doing - then you will see a variable number of cycles before the next SYNC, which will happen on schedule.
And, to answer your question, yes, if executing a steam of NOPs and getting an asynchronous IRQ, the 6502 will take N or N+1 cycles from the SYNC of the final NOP to the fetch of the interrupt vector. Because the deterministic count starts from the next SYNC, which belongs to the first NOP which won't be executed.
One of the most remarkable threads here is
A taken branch delays interrupt handling by one instructionwhich starts from an observation on a real system, and is interrupted(!) by the arrival of visual6502, which allows us to make full explorations of internal behaviour.
Hope this helps.