-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[KERNAL] 65C816 native NMI sets up for native return from emulated call #342
[KERNAL] 65C816 native NMI sets up for native return from emulated call #342
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too happy with the instruction cycle cost this adds to NMI, but it's sadly necessary, and the instruction cost will be alleviated with another low RAM jump like discussed in Discord a month ago anyway.
jmp (nminv) | ||
c816_interrupt_impl | ||
intr_common_impl | ||
jmp nmi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nnnmi
needs to setup an emulation mode context and then jump to the nminv
vector, not the KERNAL implementation; otherwise, NMIs in native mode won't ever execute a NMI handler written in emulation mode for the 65C02.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exactly what is done here. nmi
is the target of the emulation mode NMI vector, and this function is what calls jmp (nminv)
which by default leads to nnmi
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code for the emulation mode nmi target is in __nmi
in the source, as it is copied into low RAM at init. The preservation that nmi
does is minimal, so a double pla
from a custom emulation mode NMI handler to clear the stack that it does should be able to rti
into our fake RTI frames, one to return to native mode, and the other to return to the interrupted code.
Most of the cycle cost is avoided by the user changing what
|
This change causes the default native NMI indirect vector target to switch to emulation mode while setting up an RTI stack frame, giving an emulation NMI handler that is 65C816-unaware the ability to return back into native code.
Removed the explicit jump from one of the irq handling macros to make them more general so that the routine could be reused.