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 > Raster sync question.
2012-01-05 11:35
Flavioweb

Registered: Nov 2011
Posts: 463
Raster sync question.

i'm writing a -reverse timer- raster sync routine.
In my routine the kernal is switched off and i use $fffe/f as irq vector.
Also all cia irq are switched off.
The main loop is an endless self jmp to avoid opcode cycles problem.
All routines work 'in irq' so i can omit the registers saving part. Every routine start just after the irq trigger.
The cia timer setup is in the initial sei/cli routine but the timer is started using a first raster irq call where the first 2 instructions are lda/sta $d019.
Timer is set up to cycle counter with $07 as value.
The stable irq part is stabilized with $dc04 eor #$07 and the result used to branch into a lda #$a9 part as in most stable irq routines.
To test i use an inc $d021 just to see where/if stable code work.
And it work... But not always at same point!
Sometimes the inc start under border and some others start after it!
The position change if routine is restarted. When run, the position never change.
How can i fix this making inc been executed always at same position?
2012-01-05 12:14
Frantic

Registered: Mar 2003
Posts: 1648
Not sure if I got this right, but I hope you are starting the timers AFTER stabilizing the timing? If not, then the whole routine may be shifted back/forth in time the way you describe, so that it is stable each time the routine is started, but that the stabilized point is different each time the routine is started over.
2012-01-05 12:26
Flavioweb

Registered: Nov 2011
Posts: 463
the timer is setted before first 'stabilized' irq, using another 'normal' raster irq trigger. In my theory this mean at the start of raster line 'x'. This irq start when the endless jmp is running.
2012-01-05 12:39
Cruzer

Registered: Dec 2001
Posts: 1048
The raster needs to be stable when you start the counter. Also some code would help.
2012-01-05 13:38
Frantic

Registered: Mar 2003
Posts: 1648
@Flavioweb: Ok, that wont work. As I said, you need to stabilize first (triggering an interrupt when running an endless loop like "label: JMP label" does not mean you get stable timing) before you start the timer. Otherwise you don't know exactly when you started the timer and as a consequence the whole routine may start a little earlier or a little later, depending on the jitter you get because you haven't first stabilized.

Think of it. What you do is:
1. Start timer at unknown point in time
2. Sync interrupt to the timer.
Result: the routine is indeed stable relative to the counter (because of step 2), but since the point where you started the counter varies depending on when the timer was initially started you get the results you describe.

So.. you must fix step 1 so you start the timer at a stabilized point in time, in order to get the same results every time you start the routine.


2012-01-05 13:56
Flavioweb

Registered: Nov 2011
Posts: 463
ok.
But what is a 'precise source of time'?
Also if i use a cia irq, when this will be triggered related to raster?
I need to be + or - on same position when start sync counter...
how can i compensate this initial difference?
2012-01-05 14:19
Frantic

Registered: Mar 2003
Posts: 1648
> But what is a 'precise source of time'?

You could use the double interrupt method or any other available method for achieving stability in code relative to the raster beam. Read up on stable rasters on codebase64 or so:

http://codebase64.org/doku.php?id=base:interrupts#stable_timing


>Also if i use a cia irq, when this will be triggered related to raster?

That depends entirely on when you start the timer. If you start it at the start of a rasterline (step 1 above), and if we pretend for a moment that you have a timer that counts 63 cycles, then the timer will follow the rasterlines exactly since each rasterline is exactly 63 cycles long. However, this doesn't mean the interrupt will trig nicely exactly on the same point each time, due to cycle jitter, but that is where your $dc04 eor #$07 stuff comes in (step 2 above). (...but you could also use a raster irq of course and still stabilize using the timer, as long as the timer is started at a deterministic rather than unknown point in time.)

Hope I was very clear now. :)
2012-01-05 14:40
Mr. SID

Registered: Jan 2003
Posts: 424
This might be useful:
shortest CIA-stable raster
2012-01-08 05:24
ChristopherJam

Registered: Aug 2004
Posts: 1409
Hey, you could always force a character DMA (bad line) from partway across the screen, let VIC eat the remaining cycles. The instruction after your STA $d011 should be at a constant time.

I'm kind of surprised to not see that in the round up of stabilising methods at codebase64 TBH, it always seemed the simplest method to me, especially for routines at the top of the screen where you could do it just before the border runs out, so you don't even have to hide the three $ff characters fetched at DMA start.

(I know, "bring code!" etc etc)
2012-01-08 07:41
Flavioweb

Registered: Nov 2011
Posts: 463
Quote: Hey, you could always force a character DMA (bad line) from partway across the screen, let VIC eat the remaining cycles. The instruction after your STA $d011 should be at a constant time.

I'm kind of surprised to not see that in the round up of stabilising methods at codebase64 TBH, it always seemed the simplest method to me, especially for routines at the top of the screen where you could do it just before the border runs out, so you don't even have to hide the three $ff characters fetched at DMA start.

(I know, "bring code!" etc etc)


What you mean exactly?
Some like lda $d012 and #$07 ora #$1b sta $d011 then code to stabilize?
2012-01-08 11:27
ChristopherJam

Registered: Aug 2004
Posts: 1409
Yes, something like that. You also need to make sure your within the range of lines DMA is enabled for, of course.
 
... 1 post hidden. Click here to view all posts....
 
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
Microshark/Damage(HUN)
Manex/Anubis
cba
zscs
E$G/HF ⭐ 7
Moderators/CSDb Staff
Guests online: 119
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.059 sec.