Page 1 of 2

Interrupt driven real-time-clock

Posted: Fri Mar 30, 2012 11:45 pm
by zephyr
Here's an interrupt driven (IRQ) real-time-clock that you can use in your own BASIC programs. The machine code routine is position independent and DragonDOS compatible.

Code: Select all

10 ' INTERRUPT DRIVEN
20 ' REAL-TIME-CLOCK V1.0
30 ' BY STEVE EVANS
40 ' 30TH MARCH, 2012
50 '
60 'LOCATION 252 = IRQ COUNT
70 'LOCATION 253 = SECONDS
80 'LOCATION 254 = MINUTES
90 'LOCATION 255 = HOURS
100 '
110 CLEAR200,32691:START=32692
120 FOR I=0 TO 75:READ A$:X=VAL("&H"+A$):CH=CH+X:POKE START+I,X:NEXT
130 IF CH<>7542 THEN PRINT"ERROR IN DATA LINES.":END
140 '
150 'CHANGE "POKE START+28,49"
160 'TO "POKE START+28,59" FOR
170 '60HZ TANO DRAGON 64
180 '
190 POKE START+28,49:EXEC START:END
200 DATA 1A,50,30,8D,0,12,BC,1,D,27,A,FC,1,D,BF,1,D,ED,8D,0,35,1C,AF,39,96,FC
210 DATA 4C,81,31,25,28,F,FC,96,FD,4C,81,3C,25,1B,F,FD,96,FE,4C,81,3C,25,E,F,FE
220 DATA 96,FF,4C,81,18,25,1,4F,97,FF,20,A,97,FE,20,6,97,FD,20,2,97,FC,7E,9D,3D

Re: Interrupt driven real-time-clock

Posted: Sat Mar 31, 2012 1:33 am
by robcfg
Nice work!

I guess the resolution of the timer would be 50 or 60hz, or does the dragon have a more frequently used interrupt?

Re: Interrupt driven real-time-clock

Posted: Sat Mar 31, 2012 3:01 pm
by zephyr
No, only the 50Hz (PAL) or 60Hz (NTSC) IRQ interrupt.

Re: Interrupt driven real-time-clock

Posted: Sat Mar 31, 2012 6:14 pm
by zephyr
The Dragon/CoCo IRQ can be enabled or disabled from within a BASIC program as follows:

Disable IRQ = POKE65283,PEEK(65283)AND254

Enable IRQ = POKE65283,PEEK(65283)OR1

Enable IRQ = SOUND1,1 etc

The IRQ is used by the BASIC interpreter's PLAY, SOUND, and TIMER routines. Any attempt to use the PLAY command when the IRQ is disabled will result in the computer freezing.

Re: Interrupt driven real-time-clock

Posted: Sat Mar 31, 2012 8:14 pm
by rolfmichelsen
robcfg wrote:I guess the resolution of the timer would be 50 or 60hz, or does the dragon have a more frequently used interrupt?
Normally, IRQ is generated from the video field sync signal at a 50 Hz frequency. It is possible to reconfigure the PIA to generate IRQ interrupts from the horizontal sync as well, with a frequency of 15,7 kHz. Only problem is that servicing that many interrupts will eat most of the CPU clock cycles, but if you want to pay the price of a real high resolution timer, the possibility is there.

-- Rolf

Re: Interrupt driven real-time-clock

Posted: Sat Sep 06, 2014 7:35 pm
by jedie
zephyr wrote:Here's an interrupt driven (IRQ) real-time-clock that you can use in your own BASIC programs. The machine code routine is position independent and DragonDOS compatible.

Code: Select all

200 DATA 1A,50,30,8D,0,12,BC,1,D,27,A,FC,1,D,BF,1,D,ED,8D,0,35,1C,AF,39,96,FC
210 DATA 4C,81,31,25,28,F,FC,96,FD,4C,81,3C,25,1B,F,FD,96,FE,4C,81,3C,25,E,F,FE
220 DATA 96,FF,4C,81,18,25,1,4F,97,FF,20,A,97,FE,20,6,97,FD,20,2,97,FC,7E,9D,3D
Can you post the assembly code from this?

Re: Interrupt driven real-time-clock

Posted: Sun Sep 07, 2014 1:05 am
by zephyr
jedie wrote:Can you post the assembly code from this?

The original source code for this routine has been deleted.

Re: Interrupt driven real-time-clock

Posted: Sun Sep 07, 2014 9:04 am
by sixxie
You ok with me posting a disassembly?

Re: Interrupt driven real-time-clock

Posted: Sun Sep 07, 2014 11:32 am
by zephyr
sixxie wrote:You ok with me posting a disassembly?
Is this a reply to jedie or myself? My answer would be yes. :)

Re: Interrupt driven real-time-clock

Posted: Sun Sep 07, 2014 12:27 pm
by sixxie
zephyr: heh, your post originally, so was asking you. Cool. Here:

Code: Select all

		if	!NTSC
ticks_per_sec	equ	$31
		else
ticks_per_sec	equ	$3b
		endif

ticks		equ	$fc
seconds		equ	$fd
minutes		equ	$fe
hours		equ	$ff

		org	$7fb4
		orcc	#$50
		leax	irq_rtc,pcr
		cmpx	>$010d
		beq	no_init
		ldd	>$010d
		stx	>$010d
		std	old_handler,pcr
no_init		andcc	#$af
		rts	

irq_rtc		lda	<ticks
		inca	
		cmpa	#ticks_per_sec
		bcs	st_ticks
		clr	<ticks
		lda	<seconds
		inca	
		cmpa	#$3c
		bcs	st_seconds
		clr	<seconds
		lda	<minutes
		inca	
		cmpa	#$3c
		bcs	st_minutes
		clr	<minutes
		lda	<hours
		inca	
		cmpa	#$18
		bcs	st_hours
		clra	
st_hours	sta	<hours
		bra	done
st_minutes	sta	<minutes
		bra	done
st_seconds	sta	<seconds
		bra	done
st_ticks	sta	<ticks
done		jmp	>$9d3d
old_handler	equ	done + 1
In case formatting breaks: http://www.6809.org.uk/tmp/da/irq_rtc.s