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 > C64 Clock/Time routine
2009-02-04 00:40
SIDWAVE
Account closed

Registered: Apr 2002
Posts: 2238
C64 Clock/Time routine

Houston we have a problem!

About all clocks i have seen on C64, run too slow.

More specificly i am annoyed with SDI music tracker, and PSID64 clocks.

They run too slow!

If they play music for 4 minutes, they will claim they only played like 3:41 or so.

So my question is:

Are the coders on the wrong path, or is the C64 ?
 
... 23 posts hidden. Click here to view all posts....
 
2009-02-04 16:51
SIDWAVE
Account closed

Registered: Apr 2002
Posts: 2238
Well, Charles Deenen coded it correct...
so rip his!
2009-02-04 17:52
chatGPZ

Registered: Dec 2001
Posts: 11386
there is no need to rip a clock routine really, just code it right =D
2009-02-04 20:57
6R6

Registered: Feb 2002
Posts: 245
The current SDI 2.0beta use the Time-Of-Day clock
to display the time. And the current settings for $dc0e look like this:

(50hz for pal)
lda #$81
sta $dc0e

(60hz for ntsc)
lda #$01
sta $dc0e

I'm not doing a proper system check, i'm only checking the value of $02a6 to determine wheter the machine is pal or ntsc. This will be fixed for the next release.
2009-02-04 21:09
Stryyker

Registered: Dec 2001
Posts: 468
No need to post a clock routine. PRG explains it well enough. What matters is the read and write orders.
2009-02-04 21:59
Devia

Registered: Oct 2004
Posts: 401
Quote: The current SDI 2.0beta use the Time-Of-Day clock
to display the time. And the current settings for $dc0e look like this:

(50hz for pal)
lda #$81
sta $dc0e

(60hz for ntsc)
lda #$01
sta $dc0e

I'm not doing a proper system check, i'm only checking the value of $02a6 to determine wheter the machine is pal or ntsc. This will be fixed for the next release.


But you're not setting $dc0e in the player-demo code thingie, so if people use that, they'll get wrong time as default value is #$01

2009-02-05 10:01
yago

Registered: May 2002
Posts: 333
GRG: I also used TOD once, and believe me, there _are_ c64s (well, its more the power-structure itself in certain areas) which totally run TOD wrong.
Better rely on timer or frames.
2009-02-05 10:15
Frantic

Registered: Mar 2003
Posts: 1648
Yes... TOD is unreliable.
2009-02-05 18:03
chatGPZ

Registered: Dec 2001
Posts: 11386
TOD is more than good enough to measure 4 minutes accuratly
2009-02-05 19:55
tlr

Registered: Sep 2003
Posts: 1790
I usually do a phase accumulator approach like this:
	seg	code
	org	$1000

start:
	sei

; setup zeroes
	ldx	#4
lp1:
	lda	#"0"
	sta	$0400,x
	lda	646
	sta	$d800,x
	dex
	bpl	lp1

; wait for frame
lp2:
	jsr	clock
lp3:
	lda     $d011
        bpl     lp3
lp4:
        lda     $d011
        bmi     lp4
	bpl	lp2

; ( 2^24 / CPU_FREQ ) * CYCLES_PER_FRAME
; PAL:  ( 2^24 / 985248 ) * 19656 = ~334711
; NTSC: ( 2^24 / 1022727 ) * 17095 = ~280433
FRAME_ADD	equ	334711

frame_add:
	dc.b	FRAME_ADD >> 16
	dc.b	[FRAME_ADD >> 8] & $ff
	dc.b	FRAME_ADD & $ff

doffs:
	dc.b	0,1,3,4
limit:
	dc.b	$30+10,$30+10,$30+6,$30+10

time_acc:
	dc.b	0,0,0
	

clock:
; phase accumulator
	clc
	ldx	#2
clk_lp1:
	lda	time_acc,x
	adc	frame_add,x
	sta	time_acc,x
	dex
	bpl	clk_lp1
	bcc	clk_skp1	; didn't wrap, skip increment

; increment time
	ldy	#4-1
clk_lp2:
	ldx	doffs,y
	inc	$0400,x
	lda	$0400,x
	cmp	limit,y
	bne	clk_skp1
	lda	#$30
	sta	$0400,x
	dey
	bpl	clk_lp2
	
clk_skp1:
; flash ":" according to MSB in time_acc
	lda	#":"
	bit	time_acc
	bpl	clk_skp2
	lda	#" "
clk_skp2:
	sta	$0402
	rts
2009-02-05 20:04
6R6

Registered: Feb 2002
Posts: 245
Quote: But you're not setting $dc0e in the player-demo code thingie, so if people use that, they'll get wrong time as default value is #$01



Aha... Will fix that aswell.
Previous - 1 | 2 | 3 | 4 - 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
E$G/HF ⭐ 7
MaD ][/Starship
Ben Breton/Absence o..
jicas/Patagonia
Guests online: 130
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 X-Mas Demo 2024  (9.5)
7 Dawnfall V1.1  (9.5)
8 Rainbow Connection  (9.5)
9 Onscreen 5k  (9.5)
10 Morph  (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 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.094 sec.