6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Mon May 20, 2024 12:28 pm

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: RTI behaving strangely
PostPosted: Wed Dec 15, 2021 7:57 pm 
Offline

Joined: Thu Mar 04, 2021 10:08 am
Posts: 13
Hey everyone,

I'm currently at a loss.... I try to test and play with interrupts, which btw work as intended, but the RTI instruction is behaving strange...

As soon as I try to RTI, the processor is reading the wrong return address and just randomly jumps anywhere... I logged it and at Interrupt he pushed address $801A into stack, at RTI he pulled $1A1A from stack, landing somewhere in not initialized RAM and just spasms out of control...

anyone here can help?

It both happens at NMI and IRQ, RTS is working just fine, exceot when I try to RTS from the interrupt... I have no Idea what to do...


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 15, 2021 8:28 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10802
Location: England
With what system is this? And how are you logging addresses?


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 15, 2021 8:33 pm 
Offline

Joined: Thu Mar 04, 2021 10:08 am
Posts: 13
on my own SBC I posted a while back (didn't have much time since then but now I'm tackling it again), see http://forum.6502.org/viewtopic.php?f=12&t=6513

I also tried to do something different. basically I tried to RTI to a specific address with the following:

Code:
lda #$80
pha
lda #$20
pha
php
rti


with the first instruction located at $8020 thus creating a loop (checked it in the hex file)
interestingly enough this works perfectly fine, so now I am wondering...

I tried the minimal example of
Code:
ISR:
    rti

which again resulted in wildly different random address accesses...


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 15, 2021 8:36 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8440
Location: Southern California
Since $1A is one of the address bytes and the $80 is lost, it kind of sounds like your ISR is not balancing the stack.

_________________
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?


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 15, 2021 8:58 pm 
Offline

Joined: Thu Mar 04, 2021 10:08 am
Posts: 13
GARTHWILSON wrote:
Since $1A is one of the address bytes and the $80 is lost, it kind of sounds like your ISR is not balancing the stack.


then again, why did the manual approach work?


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 15, 2021 9:18 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8440
Location: Southern California
Can you post your ISR code.

_________________
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?


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 15, 2021 9:26 pm 
Offline

Joined: Thu Mar 04, 2021 10:08 am
Posts: 13
ok, found something out... after back-checking with the 6502-primer here I noticed that /WE should be qualified by Phi2, so that on Phi2=low no write operation would be possible...
I hacked together a small logic circuit out of 2 NAND gates which are first inverting R/W from the 6502 and then NANDing it with Phi2. on slower clock-speeds this works perfectly well, at 1MHz the VIA doesn't issue the IRQ from the button... sooo... something is wrong with the VIA I guess?

Manual triggering of the IRQ-line works as expected now, so consider the problem solved ;)


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 15, 2021 9:39 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8440
Location: Southern California
The WR\ to the memory needs to be separate from the signal to the VIA. Make sure you're observing that. The VIA needs the RS and R/W lines to be valid and stable before the rise of phase 2. I have never seen a VIA come defective when new, even though we used them for 13 years in one of our products. The possible exception, if I'm remembering correctly, was one where a bond wire on one of the port pins seems to have let go after it was in the field for awhile in heavy vibration. Apparently the bond was good enough to get it through initial testing, but not good enough to last.

_________________
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?


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 15, 2021 9:41 pm 
Offline

Joined: Thu Mar 04, 2021 10:08 am
Posts: 13
will have a look at that later,

for now I switched the WDC 65C22S for a Rockwell R65C22P and added a pullup-resistor at the /IRQ-Pin, now it works flawlessly, even at higher clockrate

and thanks Wilson for the primer, should've read it more thorough before designing the pcb ^^


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 15, 2021 9:58 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8190
Location: Midwestern USA
From your other topic:

Quote:
0000 - 3FFF = Banked RAM

Why? Banking that range means the stack, among other things. I'll let you figure out the implications.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 16, 2021 6:36 am 
Offline

Joined: Thu Mar 04, 2021 10:08 am
Posts: 13
BigDumbDinosaur wrote:
From your other topic:

Quote:
0000 - 3FFF = Banked RAM

Why? Banking that range means the stack, among other things. I'll let you figure out the implications.

I know that it is unusual and can be complicated, I had my reasons for that and still have to implement these reasons ;)


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 16, 2021 9:28 am 
Offline

Joined: Thu Mar 04, 2021 10:08 am
Posts: 13
GARTHWILSON wrote:
The WR\ to the memory needs to be separate from the signal to the VIA. Make sure you're observing that. The VIA needs the RS and R/W lines to be valid and stable before the rise of phase 2. I have never seen a VIA come defective when new, even though we used them for 13 years in one of our products. The possible exception, if I'm remembering correctly, was one where a bond wire on one of the port pins seems to have let go after it was in the field for awhile in heavy vibration. Apparently the bond was good enough to get it through initial testing, but not good enough to last.



the R/W for the VIA is untouched. I lifted the /WE pin of the RAM off the board and soldered the gates directly to it. R/W for the VIA still is normal R/W


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: