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 > How can this code work???
2012-01-03 22:57
Shadow
Account closed

Registered: Apr 2002
Posts: 355
How can this code work???

I'm using a bit of FPP-code I wrote a while ago. It seems to work like a charm, but now when I look at it, I can't figure out why it is, because if I count correctly, my code per line is 20 cycles, while a badline should be 23, correct?
This means that my code should be badly out of sync after some lines, but somehow it seems to work!

	lda #$32
!wait:
	cmp $d012
	bne !wait-
	ldy #$03
!delay:
	dey
	bne !delay-
.for(var i=0;i<200;i++)
{
	lda #$18+[[i+$32]&7]
	sta $d011
	ldy fpptable+i
	lda fpporig,y
	sta $d018
	nop
}


(both fpptable and fpptable are page-aligned, non-ZP memory locations. I have no sprites enabled)
 
... 2 posts hidden. Click here to view all posts....
 
2012-01-04 15:27
Skate

Registered: Jul 2003
Posts: 494
@Cruzer: Nice and clear explanation but I think this part can be confusing for some ppl.

"If you use more cycles, the bug is moved right, and if you use less it's moved left"

You don't mean spending more/less cycles each line, just the beginning of the interrupt, right? Since Shadow was talking about 20 available cycles, this part might be understood incorrectly.
2012-01-04 19:18
ChristopherJam

Registered: Aug 2004
Posts: 1409
nah, he means more or less per line. VIC will consume as many cycles are left over, but you need to occupy at least 23 to avoid stretching.
2012-01-04 19:41
Cruzer

Registered: Dec 2001
Posts: 1048
What Christopher said. That's the nice thing about FLI - it's auto-jittercorrecting. For each cycle extra you use, the VIC will just use one less for badline DMA fetching, and vice-versa. For FPP without a FLI bug it needs 40 for DMA + 3 for waiting, so that's why you only have 64-40-3 = 20 left for the code each line.
2012-01-04 20:40
Frantic

Registered: Mar 2003
Posts: 1648
...which should obviously be read as 63-40-3 = 20. It would have been so much nicer if a raster line was actually 64 cycles on the C64. Damnit! :)
2012-01-04 21:13
Cruzer

Registered: Dec 2001
Posts: 1048
Oops! :)
2012-01-04 22:32
Digger

Registered: Mar 2005
Posts: 437
Hah, that's why, I was never quite too sure where all these missing cycles were gone... :)
2012-01-05 16:01
Radiant

Registered: Sep 2004
Posts: 639
Am I the only one finding Freshness79's explaination simple to follow and the "common sense answer" impossible to understand?
2012-01-05 17:23
Skate

Registered: Jul 2003
Posts: 494
@radiantx: Freshness79's explaination was correct but wasn't the answer why FPP-code works in 20 cycles and not in 23 cycles. he explained why by using 20 cycles we still have the correct timing alignment. Cruzer explained why FPP occurs in less then 23 cycles. So two answers complete each other i guess.

I admit that I usually add/remove a few cycles to catch the effect i'm looking for instead of counting cycles. :)
2012-01-05 19:29
tlr

Registered: Sep 2003
Posts: 1790
Quote: ...which should obviously be read as 63-40-3 = 20. It would have been so much nicer if a raster line was actually 64 cycles on the C64. Damnit! :)

Old NTSC? ;)
2012-01-06 06:05
Frantic

Registered: Mar 2003
Posts: 1648
@tlr: mpfngghh... I thought you were my PAL. ;) Anyway, in that case the rest of the calculation would be wrong. ;)
Previous - 1 | 2 - 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
Advanced
Users Online
Dr. Doom/RAD
leonofsgr/Singular C..
theK/ATL
Acidchild/Padua
Guests online: 78
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.051 sec.