What did I forget?

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
barnacle
Posts: 1831
Joined: 19 Jan 2004
Location: Potsdam, DE
Contact:

What did I forget?

Post 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
leepivonka
Posts: 167
Joined: 15 Apr 2016

Re: What did I forget?

Post by leepivonka »

Do you need to write back to the interrupt status register to tell it you've serviced the T1 interrupt?
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: What did I forget?

Post 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.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
barnacle
Posts: 1831
Joined: 19 Jan 2004
Location: Potsdam, DE
Contact:

Re: What did I forget?

Post 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
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: What did I forget?

Post 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
x86?  We ain't got no x86.  We don't NEED no stinking x86!
barnacle
Posts: 1831
Joined: 19 Jan 2004
Location: Potsdam, DE
Contact:

Re: What did I forget?

Post by barnacle »

It's currently been running for

Code: Select all

03:47:35.00  
Neil
GlennSmith
Posts: 162
Joined: 26 Dec 2002
Location: Occitanie, France

Re: What did I forget?

Post 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).
Glenn-in-France
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: What did I forget?

Post 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
x86?  We ain't got no x86.  We don't NEED no stinking x86!
FD22
Posts: 2
Joined: 30 May 2012

Re: What did I forget?

Post by FD22 »

Heisenbug. Disappears on examination.
Post Reply