Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in 
CSDb User Forums

Forums > C64 Coding > Best practice IRQ recovery
2021-06-10 20:30

Registered: Jul 2010
Posts: 208
Best practice IRQ recovery


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:

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.

... 78 posts hidden. Click here to view all posts....
2021-06-10 22:48

Registered: Nov 2011
Posts: 417
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.
2021-06-10 22:50

Registered: Jul 2009
Posts: 499
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).
2021-06-11 11:34

Registered: Aug 2004
Posts: 1164
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 :-/
2021-06-11 14:04

Registered: Dec 2001
Posts: 9913
someone gotta write this "SEI considered harmful" rant already :)
2021-06-11 15:37

Registered: Aug 2004
Posts: 1164
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.
2021-06-12 06:01
Martin Piper

Registered: Nov 2007
Posts: 427
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..
2021-06-12 08:50

Registered: Apr 2002
Posts: 4723
"lda #$7f
sta CIA1InterruptControl
sta CIA2InterruptControl"

I will stick to dc0d dd0d :D letsnamealltheregisters_so_itseasyertocode NOT.
2021-06-12 11:47
Martin Piper

Registered: Nov 2007
Posts: 427
It's easier for me to name registers and sometimes their bitfields.
2021-06-12 13:06

Registered: Dec 2001
Posts: 9913
Is this "how to make trivial code unreadable 101"? /o\
2021-06-12 13:26

Registered: Apr 2002
Posts: 1916
Oh come on, the registers have names already in the datasheet.
And not everybody spent years writing and analysing code with a memory monitor before using a proper assembler. =)

I'd stick to concise symbols like "CIA1_ICR", though.

And yes, using symbols instead of raw addresses and bitfields can make code more readable, especially with rarely used registers.
Previous - 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Users Online
Mr. Mouse/XeNTaX
Scorpion/Contex / Ar..
Guests online: 253
Top Demos
1 Edge of Disgrace  (9.6)
2 Coma Light 13  (9.6)
3 Uncensored  (9.6)
4 Comaland 100%  (9.6)
5 Lunatico  (9.6)
6 Unboxed  (9.6)
7 Memento Mori  (9.5)
8 Christmas Megademo  (9.5)
9 Wonderland XII  (9.5)
10 The Shores of Reflec..  (9.5)
Top onefile Demos
1 Copper Booze  (9.8)
2 Daah, Those Acid Pil..  (9.5)
3 Lovecats  (9.5)
4 To Norah  (9.5)
5 Dawnfall V1.1  (9.5)
6 Elite Code Mechanics  (9.4)
7 Square Booze  (9.4)
8 Amber Cow - The Real..  (9.4)
9 Quadrants  (9.4)
10 Coma Job 2/3  (9.4)
Top Groups
1 Booze Design  (9.4)
2 Oxyron  (9.4)
3 Censor Design  (9.4)
4 PriorArt  (9.3)
5 Crest  (9.3)
Top Organizers
1 Burglar  (9.9)
2 Sixx  (9.8)
3 Irata  (9.8)
4 Taper  (9.8)
5 hedning  (9.8)

Home - Disclaimer
Copyright © No Name 2001-2021
Page generated in: 0.05 sec.