sburrow wrote:
If anyone else has more info I'd love to hear it. Right now I'm going to assume that a falling NMI between the 6502 reading WAI and driving RDY low will still cause it to jump to the NMI vector. But what does RDY look like? Does it stay high, or does it toggle within a half-cycle? Or does it stay low for a cycle or two?
Here are the results of some tests using my Arduino rig. This was executing the sequence:
Code:
NOP
WAI
TXS
I triggered NMI in the middle of both phases of the clock, covering a few cycles either side of the WAI instruction. All samples and signal transitions take place halfway through the high or low phase.
Case 1 - NMI occured early enough to be processed before the WAI instruction (one and a half cycles before the WAI instruction's SYNC cycle):
Code:
20 H R -n -S 000a R ea <= NMI pulse
21 l R -- -- 000b R cb
21 H R -- -- 000b R cb
22 l R -- -S 000b R cb <= NMI interrupt sequence on WAI's SYNC cycle
22 H R -- -S 000b R cb
23 l R -- -- 000b R cb
23 H R -- -- 000b R cb
24 l R -- -- 01ff w cb
24 H R -- -- 01ff w 00
25 l R -- -- 01fe w 00
25 H R -- -- 01fe w 0b
26 l R -- -- 01fd w 0b
26 H R -- -- 01fd w 22
27 l R -- v- fffa R 00
27 H R -- v- fffa R 00
28 l R -- v- fffb R 00
28 H R -- v- fffb R 00
29 l R -- -S 0000 R e6 <= ISR starts
29 H R -- -S 0000 R e6
30 l R -- -- 0001 R ff
30 H R -- -- 0001 R ff
31 l R -- -- 00ff R 00
31 H R -- -- 00ff R 00
32 l R -- -- 00ff R 00
32 H R -- -- 00ff R 00
33 l R -- -- 00ff w 00
33 H R -- -- 00ff w 01
34 l R -- -S 0002 R 40 <= RTI
34 H R -- -S 0002 R 40
35 l R -- -- 0003 R a2
35 H R -- -- 0003 R a2
36 l R -- -- 01fc R 00
36 H R -- -- 01fc R 00
37 l R -- -- 01fd R 22
37 H R -- -- 01fd R 22
38 l R -- -- 01fe R 0b
38 H R -- -- 01fe R 0b
39 l R -- -- 01ff R 00
39 H R -- -- 01ff R 00
40 l R -- -S 000b R cb <= WAI cycle 1
40 H R -- -S 000b R cb
41 l R -- -- 000c R 9a <= WAI cycle 2
41 H - -- -- 000c R 9a <= RDY goes low
42 l - -- -- 000c R 9a <= WAI cycle 2, take 2
42 H - -- -- 000c R 9a
Case 2 - one half cycle later; now WAI executes, and NMI is picked up a little later:
Code:
21 l R -n -- 000b R cb <= NMI pulse
21 H R -- -- 000b R cb
22 l R -- -S 000b R cb <= WAI cycle 1
22 H R -- -S 000b R cb
23 l R -- -- 000c R 9a <= WAI cycle 2
23 H R -- -- 000c R 9a <= RDY didn't go low at all
24 l R -- -- 000c R 9a <= WAI cycle 3
24 H R -- -- 000c R 9a
25 l R -- -S 000c R 9a <= NMI sequence
25 H R -- -S 000c R 9a
26 l R -- -- 000c R 9a
26 H R -- -- 000c R 9a
27 l R -- -- 01ff w 9a
27 H R -- -- 01ff w 00
28 l R -- -- 01fe w 00
28 H R -- -- 01fe w 0c
29 l R -- -- 01fd w 0c
29 H R -- -- 01fd w 22
30 l R -- v- fffa R 00
30 H R -- v- fffa R 00
31 l R -- v- fffb R 00
31 H R -- v- fffb R 00
32 l R -- -S 0000 R e6 <= ISR
32 H R -- -S 0000 R e6
33 l R -- -- 0001 R ff
33 H R -- -- 0001 R ff
34 l R -- -- 00ff R 00
34 H R -- -- 00ff R 00
35 l R -- -- 00ff R 00
35 H R -- -- 00ff R 00
36 l R -- -- 00ff w 00
36 H R -- -- 00ff w 01
37 l R -- -S 0002 R 40 <= RTI
37 H R -- -S 0002 R 40
38 l R -- -- 0003 R a2
38 H R -- -- 0003 R a2
39 l R -- -- 01fc R 00
39 H R -- -- 01fc R 00
40 l R -- -- 01fd R 22
40 H R -- -- 01fd R 22
41 l R -- -- 01fe R 0c
41 H R -- -- 01fe R 0c
42 l R -- -- 01ff R 00
42 H R -- -- 01ff R 00
43 l R -- -S 000c R 9a <= instruction after WAI (TXS)
43 H R -- -S 000c R 9a
44 l R -- -- 000d R 8e
44 H R -- -- 000d R 8e
Case 3 - NMI occurs during low phase of WAI cycle 2 - this is the earliest it can occur while still seeing RDY go low at least for half a cycle:
Code:
22 l R -- -S 000b R cb <= WAI cycle 1
22 H R -- -S 000b R cb
23 l R -n -- 000c R 9a <= WAI cycle 2, NMI pulse
23 H - -- -- 000c R 9a <= RDY goes low
24 l R -- -- 000c R 9a <= WAI cycle 2 take 2, RDY goes high
24 H R -- -- 000c R 9a
25 l R -- -- 000c R 9a <= WAI cycle 3
25 H R -- -- 000c R 9a
26 l R -- -S 000c R 9a <= NMI sequence
26 H R -- -S 000c R 9a
Case 4 - NMI occurs several cycles after WAI, during the high phase of the clock:
Code:
22 l R -- -S 000b R cb <= WAI cycle 1
22 H R -- -S 000b R cb
23 l R -- -- 000c R 9a <= WAI cycle 2
23 H - -- -- 000c R 9a <= RDY goes low
24 l - -- -- 000c R 9a <= WAI cycle 2, take 2
24 H - -n -- 000c R 9a <= NMI pulse
25 l R -- -- 000c R 9a <= WAI cycle 2, take 3 - RDY is high now
25 H R -- -- 000c R 9a
26 l R -- -- 000c R 9a <= WAI cycle 3
26 H R -- -- 000c R 9a
27 l R -- -S 000c R 9a <= NMI sequence
27 H R -- -S 000c R 9a
Case 5 - NMI occurs one half-cycle later again, during the low phase of the clock:
Code:
22 l R -- -S 000b R cb <= WAI cycle 1
22 H R -- -S 000b R cb
23 l R -- -- 000c R 9a <= WAI cycle 2
23 H - -- -- 000c R 9a <= RDY goes low
24 l - -- -- 000c R 9a <= WAI cycle 2 take 2
24 H - -- -- 000c R 9a
25 l - -n -- 000c R 9a <= WAI cycle 2 take 3, NMI pulse
25 H - -- -- 000c R 9a
26 l R -- -- 000c R 9a <= WAI cycle 2 take 4, RDY goes high
26 H R -- -- 000c R 9a
27 l R -- -- 000c R 9a <= WAI cycle 3
27 H R -- -- 000c R 9a
28 l R -- -S 000c R 9a <= NMI sequence
28 H R -- -S 000c R 9a
In my notes above, I'm guessing where WAI's cycle 3 is because it's no different than cycle 2 as far as the external signals look. But I'm assuming cycle 2 is the only one that can repeat.
Overall, I think that as for any other instruction, if NMI occurs one-and-a-half clock cycles before the instruction's SYNC cycle, then the NMI sequence happens instead of the instruction, and the instruction waits until after the NMI handler has run. If NMI occurs later than that, then the instruction begins as usual.
In WAI's case, it looks like with an NMI that's early enough, RDY doesn't go low at all - however, I am only sampling it halfway through the high or low periods of the clock, I'm not watching for edges, and it's possible that it dips briefly then goes up again, e.g. on the rising edge of the PHI2 clock. I'm pretty sure I did observe this in my oscilloscope traces in the other post.
In general for WAI, after cycle 2 and RDY has gone low, then after an interrupt, on the next falling edge of the clock RDY will go high again, then cycle 2 will execute one more time, then cycle 3, then the WAI instruction has finished, and the interrupt interrupts the following instruction (if it's not masked). After the RTI control returns to that next instruction.
Note the edge case that it's possible for NMI to happen before RDY goes low, yet still have RDY go low for half a cycle.