WAI instruction

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Revenant
Posts: 462
Joined: Sat Apr 25, 2015 1:47 pm
Location: FL

Re: WAI instruction

Post by Revenant »

Oziphantom wrote: Thu Apr 29, 2021 1:37 am
Revenant wrote: Wed Apr 28, 2021 2:13 pm
  • An ABORT always calls the interrupt handler, but does not end a WAI instruction
But that is the thing, the datasheet states the ABORTB does end a WAI instruction, when I is set. So the I does modify behavior other than IRQB.
The ABORT does technically end the WAI instruction, but after the interrupt handler runs, the CPU returns to the same WAI instruction and executes it again. It doesn't matter if I was set or not.
Oziphantom wrote: Thu Apr 29, 2021 3:45 am emphasis mine. This is where I go my any idea from. Thus for this matter I treat that sites info as suss and hence are looking for actual hardware test confirmation to clear up the matter. I've reached at to CSDB and a known SuperCPU owner to see if they have any insights.
In that example, the part about "LDA VIA001" running one cycle after the WAI instruction ends only applies if it was ended by an IRQ. For any other interrupt, it'll run after returning from the interrupt handler, the same as when I=0.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: WAI instruction

Post by Oziphantom »

yeah but that is not what it says
However, as soon as any hardware interrupt other than a reset occurs the microprocessor will restart and exactly one Ø2 cycle after the interrupt was received
so anything other than RESET will do it one cycle after.


This has now been tested on hardware.

In the
SEI
WAI
case, the NMI handler will fire and the WAI will exit. Confirmed.
Kaisha
Posts: 14
Joined: Mon Apr 26, 2021 2:58 am

Re: WAI instruction

Post by Kaisha »

You guys are incredibly thorough. So in summary:

If interrupts are enabled (flag I == 0):
WAI + IRQ -> fires IRQ, continues executing next instruction after WAI
WAI + NMI -> fires NMI, continues executing next instruction after WAI
WAI + ABORT -> fires ABORT, returns to WAI
WAI + RESET -> reset chip and run RESET handler in emulation mode

If interrupts are disabled(flag I == 1):
WAI + IRQ -> does not fire IRQ, immediately continues executing next instruction after WAI
WAI + NMI -> fires NMI, continues executing after WAI
WAI + ABORT -> fires ABORT, returns to WAI
WAI + RESET -> reset chip and run RESET handler in emulation mode

Does this seem correct?
creaothceann
Posts: 611
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: WAI instruction

Post by creaothceann »

Code: Select all

if IRQ vector is not disabled (P.i == 0):
WAI + IRQ   ->                 uses IRQ   handler vector; handler returns to the instruction after WAI
WAI + NMI   ->                 uses NMI   handler vector; handler returns to the instruction after WAI
WAI + ABORT ->                 uses ABORT handler vector; handler returns to                       WAI
WAI + RESET -> resets chip and uses RESET handler vector

if IRQ vector is disabled (P.i == 1):
WAI + IRQ   -> does not use IRQ handler vector, immediately continues executing the instruction after WAI
WAI + NMI   -> same as P.i == 0
WAI + ABORT -> same as P.i == 0
WAI + RESET -> same as P.i == 0
(Speaking of 65* interrupts, here's some info about them and why S is $01FD after reset. - EDIT: more)
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
Post Reply