| |
oziphantom
Registered: Oct 2014 Posts: 478 |
65816 WAI NMI Edge Case
The 65816 has a special mode of WAI, when you Set I it will not fire the IRQB handler and drop to the next instruction.
It does mention that ABORTB will behavior differently, in that it will exit the WAI but not start the processor.
However there is no mention of what happens in the instance of a NMI.
so
SEI
WAI
; NMI fires
does it
a.)handle NMI as per normal and return to the WAI
b.)handle NMI as per normal and exit from the WAI
c.)skip the NMI handler and exit from the WAI
Does anybody know? I can't find any test cases or documented evidence of what it does do. Some things don't mention it, some things say it will trap "any" interrupt. |
|
| |
Krill
Registered: Apr 2002 Posts: 2825 |
From W65C816S manual:
"NMIB, IRQB or RESB will terminate the WAI condition and transfer control to the interrupt handler routine."
This reads like option b.) to me. |
| |
oziphantom
Registered: Oct 2014 Posts: 478 |
keep reading. That is the
CLI
WAI
method.
SEI
WAI
acts differently. |
| |
Krill
Registered: Apr 2002 Posts: 2825 |
Well, relevant rest is basically, "When the Status Register I flag is set (IRQB disabled) the IRQB interrupt will cause the next instruction (following the WAI instruction) to be executed without going to the IRQB interrupt handler."
So there is no special mention of other interrupt sources, implying that the I flag is irrelevant for the NMI case. |
| |
oziphantom
Registered: Oct 2014 Posts: 478 |
only it does affect the ABORTB signal which is not affected by I under any conditions normally and has a higher priority than the NMI.
But ignoring the ABORTB, we are still left with does the NMI do a or c.
Having a react to IRQB in 1 clock getting tripped up by an NMI sounds bad, while I might want to do the NMI I would also probably not want the code that was designed to happen straight after an IRQ to happen without the IRQ. However there is no mention or cation against this scenario either.
This site http://6502.org/tutorials/65c816interrupts.html claims "any" for example when talking about the SEI WAI case. |
| |
Krill
Registered: Apr 2002 Posts: 2825 |
http://forum.6502.org/viewtopic.php?f=1&t=5428#p65552
These guys seem to have practical experience with the issue, and it reads like option c.) to me.
In any case, this stuff should be fairly easy to test on real hardware. |
| |
oziphantom
Registered: Oct 2014 Posts: 478 |
BigDumbDinosaur says it's c.
drogon says 'fairly confident' it's not c, and seems mostly likely they infer b |
| |
Krill
Registered: Apr 2002 Posts: 2825 |
And neither bothered to test it on real hardware? :) |
| |
oziphantom
Registered: Oct 2014 Posts: 478 |
they might have, but if they did, they didn't document their findings. |
| |
chatGPZ
Registered: Dec 2001 Posts: 11100 |
And why dont you? I mean... isnt it the obvious thing to do? :) |
| |
oziphantom
Registered: Oct 2014 Posts: 478 |
I don't have a SuperCPU, I don't have an Apple IIgs, nor a Foniex 256 and I don't have a SDPro for a SNES.
Otherwise I would have. |
| |
chatGPZ
Registered: Dec 2001 Posts: 11100 |
In such case i'd usually write the test program, post it here (and/or on lemon or irc) and ask someone to run it - works for me :)
Bonus: you'll find out if VICE does the right thing, and we can fix it eventually :) |
| |
Karmic
Registered: Apr 2015 Posts: 66 |
I have an FXPak Pro for SNES, if you're willing to write up a test ROM I can run it for you. |
| |
oziphantom
Registered: Oct 2014 Posts: 478 |
https://www.dropbox.com/s/z4hw32cps1lzog6/testNMIWAI.sfc?dl=0
not sure if you need to pad it out for FXPak. ROM Is PAL, but it doesn't matter.
It will set the screen colour.
RED - WAI exited no NMI handler
BLUE - NMI handler executed, WAI didn't exit
PURPLE - NMI handler executed and WAI exited |
| |
Smasher
Registered: Feb 2003 Posts: 512 |
I put 5$ on purple :) |
| |
Karmic
Registered: Apr 2015 Posts: 66 |
Ran it multiple times, and got the purple screen every time. I guess that makes the most sense, NMI is supposed to be non-maskable after all. |
| |
oziphantom
Registered: Oct 2014 Posts: 478 |
it does but then having my critical clock perfect interrupt get broken by a stray NMI also sounds bad. I guess either way is not ideal.
Thanks for testing. |
| |
chatGPZ
Registered: Dec 2001 Posts: 11100 |
Quote:my critical clock perfect interrupt get broken by a stray NMI also sounds bad
So you either do "nmi lock", or just live with it :) It's a common "problem" in many C64 programs. |