| |
Trap
Registered: Jul 2010 Posts: 222 |
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.... |
| |
Krill
Registered: Apr 2002 Posts: 2839 |
It's common practice to check for space during an interrupt handler that's executed once a video frame. The I flag is usually still set (because you're in an interrupt) and the interrupt itself was triggered by VIC.
When detecting the keypress, just write 0 to $d01a to disable any VIC interrupts, then write $ff to $d019 to acknowledge any pending VIC interrupts. Resetting any interrupt vectors should not be required. Directly exit to whatever code to unpack and run the next part. |
| |
Trap
Registered: Jul 2010 Posts: 222 |
So
set IRQ vector to default handler
$d01a=0
$d019=$ff
wait a frame or two
go to unpacker
Is that what you meant? |
| |
Krill
Registered: Apr 2002 Posts: 2839 |
Resetting IRQ vectors or waiting shouldn't be required, but should be no harm. It's just unnecessary. :) |
| |
Oswald
Registered: Apr 2002 Posts: 5017 |
my guess is that depacker overwrites your irq code, and on the next irq request cpu tries to jump into that. simply set irq vector to a new piece of irq handler which surely is undisturbed. |
| |
Flavioweb
Registered: Nov 2011 Posts: 447 |
I guess something overwrite $0314/5 before setting $01 to $36.
Force it back to $EA31 (or $EA81) (and may be better to restore other vectors too) insted of call $FF81.
Clear VIC IRQs enable flags too. |
| |
TWW
Registered: Jul 2009 Posts: 541 |
In your IRQ setup, disable CIA Interrupts and ack any pending before setting up your VIC IRQ and IRQ pointers.
Assuming no NMI's, the only thing which should be able to trigger the IRQ handler is the VIC.
If your keyboard detection routine is inside an IRQ, the I-Flag should remain set until you ack it. This means that as long as you don't ack it and the unpacker doesn't ack/cli no IRQ should trigger before your next part start (where you presumably SEI and setup next round of IRQ interrupts). |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1378 |
If you disable CIA and VIC interrupts *without* a preceding SEI you don't even need to acknowledge any pending ones - the existing handler will deal with that.
tinycrunch's self extracting mode only wraps the decrunch in SEI/CLI because too many people were having issues with nucrunch's default of just turning off CIA while trying to crunch things that needed the kernal interrupt to still be in place when they started up :-/ |
| |
chatGPZ
Registered: Dec 2001 Posts: 11108 |
someone gotta write this "SEI considered harmful" rant already :) |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1378 |
Quote: someone gotta write this "SEI considered harmful" rant already :)
Well I think it's already been flogged to death over at
TIL: The instruction after SEI can be executed before a pending IRQ is handled and to a lesser extent in C-64 coding cargo cults but it's always been as an offshoot from a broader discussion, so far as I can find. |
| |
Martin Piper
Registered: Nov 2007 Posts: 634 |
Tried single stepping using the debugger in Vice?
It will probably show where various IRQs happen after the CLI.
Create, or reuse, consistent IRQ disable and ACK code: https://github.com/martinpiper/C64Public/blob/master/stdlib/std..
I generally always use this to initialise to a known state: https://github.com/martinpiper/C64Public/blob/master/stdlib/Ini.. |
Previous - 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 - Next |