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


Forums > C64 Coding > Stable IRQ Jitter
2013-03-21 15:25
muh
Account closed

Registered: Feb 2013
Posts: 6
Stable IRQ Jitter

I have a more or less technical question considering the cycles used after an IRQ triggers.
From what i gather this happens after an IRQ triggers:
- finish -already started- instruction (variable cycles)
- 7 cycles for IRQ

I think I understand the way double IRQ works:
IRQ1 ends in NOPs; IRQ2 now has 1 cycle jitter; last cycle of cmp $d012 either at cycle 63 of the current rasterline or cycle 0 of the next, so the beq by actually branching or not fixes the 1 cycle jitter. All fine.

However the examples on codebase I've seen seem to be 2 cycles short. Now I read in these forums the finish-instruction-delay is 2-9 cycles after IRQ trigger.
With a NOP taking 2 or 3 cycles to complete after IRQ trigger the examples make sense.
How can a 2 cycle NOP instruction take 3 cycles to finish? Can anyone explain the logic?

I hope this makes sense ;)
2013-03-21 16:30
Flavioweb

Registered: Nov 2011
Posts: 463
If D012 change just after fourth CMP cycle or, in other words, on the first cicle of BNE, your code takes 3 cycles for branch, 4 cycles for CMP again, and if D012 match the CMP, BNE takes 2 cycles to exit.
9 in total.
Is this cycle what you are looking for?
2013-03-21 17:07
muh
Account closed

Registered: Feb 2013
Posts: 6
Below a snippet taken from codebase to hopefully explain my confusion:

irq2:
	// 7 IRQ cycles
	// I would say 0 or 1 cycles for finishing a NOP (the jitter)
	txs	//2

	ldx #9	//2
!:	dex	//2
	bne !-	//3 (or 2 when done)
		// subtotal: 55/56

	//final cycle wobble check
	lda #irqLine+1	//2
	cmp $d012	//4
		//at best the cmp $d012 ends up at 61/62
	
	beq *+2	//3 or 2

	//the raster is now stable! \o/


I added cycle counts. It seems to me the cmp $d012 should end at cycle 61 or 62, but as the routine works apparently it is at 63/0? Where do the extra 2 cycles come from?

Hoping this makes my question clearer..

Thanks Flavioweb, however I think your answer is to the reason the jitter is there when you do a lda #$30; cmp $d012; bne *-3. Not the answer to the 2 cycles I'm looking for in this case.
2013-03-21 18:22
Fresh

Registered: Jan 2005
Posts: 101
For being served after an instruction an IRQ needs to be triggered 2 cycles before the instruction ends.
Some examples may clarify:

...
NOP
-->IRQ Triggered
NOP
-->IRQ Served
NOP
...

...
NOP -->IRQ Triggered at cycle 1
NOP
-->IRQ Served
NOP
...

...
INC abs16 --> IRQ triggered at cycle 5
(ANY instruction)
-->IRQ served
...

...
INC abs16 --> IRQ triggered at cycle 4
-->IRQ served
(ANY instruction)
...

This clearly expains the two missing cycles, so jittering is 2+(0-7) => 2-9.

Font: http://www.antimon.org/dl/c64/code/stable.txt
2013-03-21 19:07
Oswald

Registered: Apr 2002
Posts: 5094
cool, thats something I didnt know so far.
2013-03-21 19:49
muh
Account closed

Registered: Feb 2013
Posts: 6
Ah thank you.
Little follow-up, I know I could test it but you might know the answer.
Is it the VIC triggering the IRQ that causes the delay or is it the CPU taking 2 cycles to recognize the IRQ signal before the default handling kicks in.
In other words do the same 2 cycles apply for timer generated IRQs?
2013-03-21 20:20
Oswald

Registered: Apr 2002
Posts: 5094
VIC has no idea of the CPU state, so it must be wired cpu behaviour.
2013-03-21 23:20
Fresh

Registered: Jan 2005
Posts: 101
As Oswald's already told you, it's cpu default behavior.
2013-03-22 08:41
lft

Registered: Jul 2007
Posts: 369
For completeness:

I learned recently that if the IRQ arrives while the CPU is stalled e.g. due to sprite fetches, the first cycle of the interrupt sequence (probably just latching the signal) appears to be handled anyway. This means that the total latency will be one cycle less.
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
Advanced
Users Online
MWR/Visdom
Guests online: 95
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Coders
1 Axis  (9.8)
2 Graham  (9.8)
3 Lft  (9.8)
4 Crossbow  (9.8)
5 HCL  (9.8)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.056 sec.