Interrupt driven real-time-clock

Use this forum to submit new files for the download section of the archive. I will check each submission and upload it to the archive on a regular basis.
zephyr
Posts: 1474
Joined: Mon Jul 21, 2008 1:18 am

Interrupt driven real-time-clock

Post 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
Attachments
Interrupt_driven_clock_v10.zip
(1.99 KiB) Downloaded 251 times
User avatar
robcfg
Posts: 1529
Joined: Sat Apr 04, 2009 10:16 pm
Location: Stockholm, Sweden
Contact:

Re: Interrupt driven real-time-clock

Post 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?
zephyr
Posts: 1474
Joined: Mon Jul 21, 2008 1:18 am

Re: Interrupt driven real-time-clock

Post by zephyr »

No, only the 50Hz (PAL) or 60Hz (NTSC) IRQ interrupt.
zephyr
Posts: 1474
Joined: Mon Jul 21, 2008 1:18 am

Re: Interrupt driven real-time-clock

Post 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.
User avatar
rolfmichelsen
Posts: 296
Joined: Wed Apr 08, 2009 8:43 pm
Location: Oslo, Norway
Contact:

Re: Interrupt driven real-time-clock

Post 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
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: Interrupt driven real-time-clock

Post 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?
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
zephyr
Posts: 1474
Joined: Mon Jul 21, 2008 1:18 am

Re: Interrupt driven real-time-clock

Post by zephyr »

jedie wrote:Can you post the assembly code from this?

The original source code for this routine has been deleted.
sixxie
Posts: 1346
Joined: Fri Jul 18, 2008 8:36 am
Location: Hertfordshire
Contact:

Re: Interrupt driven real-time-clock

Post by sixxie »

You ok with me posting a disassembly?
zephyr
Posts: 1474
Joined: Mon Jul 21, 2008 1:18 am

Re: Interrupt driven real-time-clock

Post by zephyr »

sixxie wrote:You ok with me posting a disassembly?
Is this a reply to jedie or myself? My answer would be yes. :)
sixxie
Posts: 1346
Joined: Fri Jul 18, 2008 8:36 am
Location: Hertfordshire
Contact:

Re: Interrupt driven real-time-clock

Post 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
Post Reply