| |
Trap
Registered: Jul 2010 Posts: 221 |
Best practice IRQ recovery
Hi,
Here's a little newbie question. Sorry, I'm still learning this shit and it's really complicated :(
I have kernel off ($01=$35) and I am running IRQ's using the normal $fffe/$ffff vectors.
I want to exit from this and call a prepacked piece of code (in this case something packed with TinyCrunch).
I tried restoring the IRQ vectors and jump to the packer. However, it just hangs. I tried some other things but all gave the same result. The only thing that worked was when I did this:
sei
lda #$36
sta $01
jsr $ff81
jmp unpacker
The problem of course is that it resets the VIC which isn't really great for my situation.
So, my question:
What is the correct/proper way to exit from a part and go to the next? preferably not using kernal routines :|
Thank you.
Trap |
|
... 78 posts hidden. Click here to view all posts.... |
| |
Oswald
Registered: Apr 2002 Posts: 5007 |
|
| |
TWW
Registered: Jul 2009 Posts: 541 |
Quoting Groepazyou forgot the second SEI
If a NMI is executed between the SEI and the DD0D disable code, the Processor Status Register (PSR) gets pushed to the stack. When the inevitable RTI is executed the PSR is pulled from stack, the I-flag is restored without the need to set it a second time. |
| |
Trap
Registered: Jul 2010 Posts: 221 |
Wow. This sure sparked a discussion :) I read the thread a few times, but I honestly still don't feel I am any bit closer to knowing how I should deal with my problem?
Thank you all for dishing in - truly wonderful and much appreciated though :) |
| |
chatGPZ
Registered: Dec 2001 Posts: 11088 |
But what if the NMI handler manipulates the Stack? Are you assuming it doesnt? |
| |
Trap
Registered: Jul 2010 Posts: 221 |
I am not using NMI or reading any keyboard presses. Just a normal IRQ running with kernal off ($01=$35). |
| |
chatGPZ
Registered: Dec 2001 Posts: 11088 |
To answer your question we'd still need to know what exactly you are trying to do - there is no universal answer :) |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1359 |
Quoting TrapI am not using NMI or reading any keyboard presses. Just a normal IRQ running with kernal off ($01=$35).
Then you can ignore almost all of the last 50 comments, and just
lda #$7f
sta $dc0d
ldx #0
stx $d01a
no SEI/CLI required. (that said, you do still need to ack the interrupt you're responding to if you do this in an ISR instead of in your main) |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1359 |
Quoting TWWWhen the inevitable RTI is executed
We already covered this - the RTI is not at all inevitable if the interrupt in question is just setting up for another interrupt. |
| |
TWW
Registered: Jul 2009 Posts: 541 |
Quote: But what if the NMI handler manipulates the Stack? Are you assuming it doesnt?
If the NMI code messes with the stack, the RTI won't work, and chances are any previously running code prior to this would not have worked either.
@ Trap: If you setup and have control of your interrupts as I posted above, it should be straight forward to handle unpacking and transitions since you only need to handle Raster IRQs (assuming no funky memory banking).
// space is pressed inside a raster IRQ or whatever
// I-Flag is set since it's handled inside the IRQ
ldx #0
stx $d01a
inx
stx $d019
cli
// no more (internal) interrupts can happen here
jmp depack
PS. STACK is messed up at this point, so you cannot have any rti/rts. If the depacker sei/cli or not should not matter as long as it doesn't activate any IRQs. Finally ensure that there is no mem-bank trickery going on which may mess things up. |
| |
TWW
Registered: Jul 2009 Posts: 541 |
Quote: Quoting TWWWhen the inevitable RTI is executed
We already covered this - the RTI is not at all inevitable if the interrupt in question is just setting up for another interrupt.
If the interrupt in question is just setting up for another interrupt, you do not need to do anything except handle the ongoing *known* interrupt and it's source, assuming you *know* that no other internal interrupts may occur. |
Previous - 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 - Next |