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 > $d013 sync ??
2009-08-21 14:21
andym00

Registered: Jun 2009
Posts: 45
$d013 sync ??

Okay, be nice, I've been away from the C64 for over 20 years and I thought this would be easy having seen it mentioned once on here... I cobbled this together a few weeks ago, and now when I've just tried it out again I'm getting variable results, regards getting to a stable clock cycle..
		lda #16		
		sta $dc01
		lda #0
		sta $dc01
		lda $d013
		lsr		
		lsr		
		adc	#17+13	
		lsr		
		sta bm + 1	
bm:		bne *		
		!for .count, 30 {
			nop
		}
		bcs +	; if carry set 3 cycles, if clear 2 cycles..

Okay, so maybe it might be out by a constant amount of cycles, but it's all over the place..
Does this technique actually work (by creating a button press to trigger the light-pen) or have I misunderstood from what little tidbits have been mentioned here ?
I examined a load of demos and don't see much messing with $d013, so I'm guessing maybe I've got the wrong end of the stick, but this should work in theory right ?
I only want it for stablising some CIA IRQs, and I know there's other ways to do it, but this just seemed like something I should give a go, but it's borked :)
2009-08-21 15:45
chatGPZ

Registered: Dec 2001
Posts: 11386
here is a working routine (used this last time over 10 years ago, forgot how exactly it works =P)

.scope
         lda $d019
         sta $d019
         ldx #$ff
         ldy #$00
         stx $dc00
         sty $dc02
         stx $dc03
         stx $dc01
         sty $dc01
         stx $dc01
         lda $d013
         stx $dc02
         sty $dc03
         stx $dc01
         ldx #$7f
         stx $dc00
         lsr a
         lsr a
         lsr a
         sta timeout+1
         bcc timing
timing:  clv
timeout: bvc timeout
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop
         nop

         rts

.endscope
2009-08-21 18:08
Graham
Account closed

Registered: Dec 2002
Posts: 990
The $D013 sync has a major disadvantage: If you press space, it does not work. Better synchronize via double IRQ.
2009-08-21 19:38
algorithm

Registered: May 2002
Posts: 705
Thats interesting

I assume that this is inside the IRQ and that things would sync properly at the end of the routine? Would sprites affect the syncing of this somewhat. Double IRQ is always a better approach, but the above seems somewhat cleaner.
I would not think it would be that much of an issue to not press spacebar (unless it is a 'press space' to continue' demo)
2009-08-22 00:26
chatGPZ

Registered: Dec 2001
Posts: 11386
ofcourse the syncing is affected by sprites... and also by badlines (or what ever else disturbs the timing)
2009-08-22 09:05
Graham
Account closed

Registered: Dec 2002
Posts: 990
I don't think that inverting the CIAs keyboard matrix direction to cheat the VIC into thinking the lightpen has triggered is somewhat "clean" :)

Btw it would be interesting to know who invented this routine. I've first seen it in 64'er magazine issue 11/88.
2009-08-22 09:21
Radiant

Registered: Sep 2004
Posts: 639
I think I've seen stable rasters referred to as "lightpen rasters" in some early demo; perhaps that was the first known method of stabilizing?
2009-08-22 10:38
chatGPZ

Registered: Dec 2001
Posts: 11386
Quote:
I've first seen it in 64'er magazine issue 11/88.


hannes sommer .... (and the routine above is exactly his, copied from said 64er =))
2009-08-22 14:05
andym00

Registered: Jun 2009
Posts: 45
Thanks Groepaz, that works a treat, and I hunted high and low for that original article from Hannes curious to see how he originally wrote it.. Now I know :)
I just wanted a nice clean way to setup CIAs at startup to the exact cycle I wanted, and if the users presses space then woe betide them ;)
I only wanted to try this way because I never had done before and I liked the idea of it..
2011-07-12 07:47
ready.

Registered: Feb 2003
Posts: 441
I am coding a full screen sprite mux, showing sprites on char screen+upper+lower border (not the side boreders) and I need to have a stable raster even in the lower border area where $d011 MSB is at 1.

I think this $d013 stabilizing code is much more handy than double-irq for working in the raster area over $0ff to $137, since you don't need to care about setting $d011. Usually double-irq method just calls for inc $d012, for triggering stable irq on next line, but this does not work in the lower border.
2011-07-12 10:02
Radiant

Registered: Sep 2004
Posts: 639
Of course it works in the lower border. The only time it doesn't work is if you're putting the initial IRQ on line $ff - then you need to set $d011 as well. Workaround: don't do that. Other than that, inc $d012 will work just as fine in the lower border as anywhere else on the screen.
2011-07-12 10:41
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: I am coding a full screen sprite mux, showing sprites on char screen+upper+lower border (not the side boreders) and I need to have a stable raster even in the lower border area where $d011 MSB is at 1.

I think this $d013 stabilizing code is much more handy than double-irq for working in the raster area over $0ff to $137, since you don't need to care about setting $d011. Usually double-irq method just calls for inc $d012, for triggering stable irq on next line, but this does not work in the lower border.


Off-topic (or on topic why you don't need $d013-sync):

Not quite sure why you need stable rasters when sprite multiplexing though... perhaps you switch colors or mode extremly exact? If you just want back to back sprites you can just aswell waste some more memory and save yourself the mess of tight timing. Double the amount of sprites and create intermediate sprites like this:

Normal sprite A:
AA
aa

Normal sprite B:
BB
bb

Intermediate sprite AB:
BB
aa

So, trigger an irq some 10-11 lines after sprite A starts to display and switch to sprite AB and multiplex it in y, then after another 10-11 lines switch to sprite B. Thus you get tight back to back multiplexing without the need for stable rasters or other tight timing.

Use $d012 to multiplex your sprites and fire up an NMI timer to remove the upper and lower border (preferably let timer A trigger in the upper border and timer B at raster line #$f8). By using NMI it will have priority over the sprite multiplexer (which isn't timing critical anymore) and the border will always open.

Just my 2 cents for keeping things simple (assuming my assumptions about your needs are correct).
2011-07-13 08:58
Perplex

Registered: Feb 2009
Posts: 255
Another much used trick if you need to multiplex several sprites, is to toggle between two or more copies of the screen ($d018 bit 4-7). That gives you some extra flexibility for timing sprite pointer updates.
2011-07-13 18:02
Oswald

Registered: Apr 2002
Posts: 5094
not much of a trick tho, I've 'invented' it myself when I was 15 or so.
2011-07-13 21:52
Perplex

Registered: Feb 2009
Posts: 255
2011-07-14 02:15
ChristopherJam

Registered: Aug 2004
Posts: 1409
Such wastage, JackAsser - you only need to duplicate the last couple of lines of the sprites - you just update every 18-20 lines instead of every 21 :)

I agree it's simpler to explain the data requirements if you double your data usage mind.
2011-07-14 07:20
ready.

Registered: Feb 2003
Posts: 441
thanks for your feedback. Actually what I am working on is a full screen upscroller, similar to Royal Arte last part, but without interlace and without gfx on the background.

I will most probably go for the stable IRQ/$d018 method which eats less memory and will let me put some text/gfx behind the sprites.

Thanks to Oswald for inspiring me to synch every frame individually (suggestion done in another thread).

But I am going off topic now.
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
Holy Moses/Role
𝘁𝗡𝗚/FairLight
rexbeng
tlr
Mike
MCM/ONSLAUGHT
iAN CooG/HVSC
Dr.Science/Atlantis
LKP/CFN
Guests online: 107
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 Censor Design  (9.3)
5 Triad  (9.3)
Top Swappers
1 Derbyshire Ram  (10)
2 Jerry  (9.8)
3 Violator  (9.7)
4 Acidchild  (9.7)
5 Cash  (9.6)

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