Page 1 of 1

What did I forget?

Posted: Fri Dec 26, 2025 9:57 pm
by barnacle
It's been oh, about fifty years since I used a 6522 in anger, so a recent attempt to use one ended in slight disaster.

Obviously I've forgotten something obvious (though my code looks very similar to Garth's helpful page) and I can't see what it is.

Code: Select all

;-----------------------------------------------------------------------
; real time clock timer operations
; Ph2i clock is 1.8432MHz; we want a 50Hz interrupt. Set up timer one
; in free run mode to give that frequency and start it running.
; The timer interval is 1843200/50 = 36864; subtract two for timer
; overhead
start_tick:
	stz fiftieths
	stz seconds
	stz minutes
	stz hours			; reset the clock to midnight (at the oasis)
	
	lda # lo 36862
	sta VIAT1CL			; register 4
	lda # hi 36862
	sta VIAT1CH			; register 5; load counter with full byte
						; and reset IFR6 (timer 1)
	lda VIAACR			; register $b
	and #%01111111
	ora #%01000000		; repeated interrupts required, no portb output
	sta VIAACR			; started
	lda #%11000000		; set interrupt enable for timer one
	sta VIAIER			; register $0e
	cli					; enable interrupts
	rts
	
;-----------------------------------------------------------------------
; real time clock update on irq
; We do not allow further interrupts in this atomic operation
; There are no interrupt sources other than this (at the moment).
rtc_update:
	bit VIAT1CL			; reenable interrupts
	pha					; acc is the only register used
	inc fiftieths
	lda fiftieths
	cmp #50
	bne rtc_u_x			; not yet fifty?
		stz	fiftieths		
		inc seconds
		lda seconds
		cmp #60
		bne rtc_u_x
			stz seconds
			inc minutes
			lda minutes
			cmp #60
			bne rtc_u_x
				stz minutes
				inc hours
				lda hours
				cmp #24
				bne rtc_u_x
					stz hours
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					; FIXME extend to date
					;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
rtc_u_x:
	pla					; restore acc
	rti					; restores binary mode etc
and of course

Code: Select all

;-----------------------------------------------------------------------
;
; reset and interrupt vectors	

	code
	org 0xfffa
	dw init				; nmi
	dw init				; reset
	dw rtc_update		; irq/brk
In a test loop, it appears to trigger the first interrupt and then never return; attempting to print a continuous output of time values stops at the same point every time I try it, partway through an output word (but by counting the characters output, after close to 20ms).

Help?

Neil

Re: What did I forget?

Posted: Sat Dec 27, 2025 1:08 am
by leepivonka
Do you need to write back to the interrupt status register to tell it you've serviced the T1 interrupt?

Re: What did I forget?

Posted: Sat Dec 27, 2025 4:03 am
by GARTHWILSON
leepivonka wrote:
Do you need to write back to the interrupt status register to tell it you've serviced the T1 interrupt?
The bit VIAT1CL takes care of that.

Neil, wow, I went all these years ignoring my own advice!  I never caught it, because in my system I had written to the ACR before getting to the RTC setup code where the counters are written to.  At least at this point I think that's probably the problem.  I've only looked at it a few minutes though.  See my Tip of the Day, Tip #9, at viewtopic.php?p=2311#p2311 .  If you find that's it, let us know, and I'll edit my pages.

Re: What did I forget?

Posted: Sat Dec 27, 2025 9:09 am
by barnacle
"Curiouser and curioser", said Alice.

With no change made that I can recall, this morning it's working exactly as expected, incrementing time in 20ms chunks. Dunno what's going on there at all! Let's see if it continues to work.

Neil

Re: What did I forget?

Posted: Sat Dec 27, 2025 12:23 pm
by BigDumbDinosaur
barnacle wrote:
With no change made that I can recall, this morning it's working exactly as expected, incrementing time in 20ms chunks.  Dunno what's going on there at all!  Let's see if it continues to work.
Anxiously watching for signs of billowing smoke over eastern Germany.  :D

Re: What did I forget?

Posted: Sat Dec 27, 2025 1:54 pm
by barnacle
It's currently been running for

Code: Select all

03:47:35.00  
Neil

Re: What did I forget?

Posted: Sun Dec 28, 2025 7:58 am
by GlennSmith
The French say "Tombé en panne" (could translate to "fallen down broken"), but in my department at the hp factory (I was responsible for the whole infrastructure of some 600 office PCs, around a 100 servers and a shop-floor data collection system of several hundred entry points) - we often had the situation that we couldn't identify why something started to work as planned. We'd say that it had "tombé en marche" (fallen into a working state).

Re: What did I forget?

Posted: Sun Dec 28, 2025 4:48 pm
by BigDumbDinosaur
GlennSmith wrote:
The French say "Tombé en panne" (could translate to "fallen down broken"), but in my department at the hp factory (I was responsible for the whole infrastructure of some 600 office PCs, around a 100 servers and a shop-floor data collection system of several hundred entry points) - we often had the situation that we couldn't identify why something started to work as planned. We'd say that it had "tombé en marche" (fallen into a working state).
A guy I worked with back in the minicomputer days used to say “PFM” when something inexplicably started working after a period of being recalcitrant.

“Pure F***ing Magic”.  :D

Re: What did I forget?

Posted: Sun Dec 28, 2025 11:04 pm
by FD22
Heisenbug. Disappears on examination.