6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Apr 26, 2024 7:41 pm

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Sun Apr 24, 2011 12:34 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 990
Location: near Heidelberg, Germany
Today I found an interesting post here http://www.commodore128.org/index.php?P ... icseen#new

It says that the effects of SEI and CLI are delayed by one opcode. I.e. the opcode after a SEI can be interrupted - and the author says that he (and the VICE emulator) does not interrupt the opcode after a CLI.

Well, I didn't know this fact, and these days I can probably try it with the visual6502 emulator. And thinking about the 6502 architecture, this seems plausible.

But the question in the post it seems is that the 8502, the 6502 derivative in the C64 seems to actually be able to interrupt the opcode after the CLI.

Anyone of you know this?

Cheers,
André


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 24, 2011 4:44 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8144
Location: Midwestern USA
fachat wrote:
Today I found an interesting post here http://www.commodore128.org/index.php?P ... icseen#new

It says that the effects of SEI and CLI are delayed by one opcode. I.e. the opcode after a SEI can be interrupted - and the author says that he (and the VICE emulator) does not interrupt the opcode after a CLI.

Well, I didn't know this fact, and these days I can probably try it with the visual6502 emulator. And thinking about the 6502 architecture, this seems plausible.

But the question in the post it seems is that the 8502, the 6502 derivative in the C64 seems to actually be able to interrupt the opcode after the CLI.

Anyone of you know this?

Cheers,
André

Here's my response to that question. In short, I've never heard of it. It could be errata in the 8502, but I wrote a lot of C-128 code in years past that tinkered with the interrupt handler (e.g., Clock-Calendar 128, which is entirely interrupt-driven). Surely I would have tripped over this anomaly if it did in fact exist.

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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Apr 24, 2011 8:06 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 990
Location: near Heidelberg, Germany
Hm, in fact even if IRQ goes low directly during the CLI, the opcode after the CLI is still executed, and only then the IRQ sequence is started!

See http://visual6502.org/JSSim/expert.html ... ogmore=irq

So the claim, that the effect of CLI is delayed by one opcode is verified by visual6502.

André


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Apr 24, 2011 8:26 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 990
Location: near Heidelberg, Germany
This link http://visual6502.org/JSSim/expert.html ... =0014&d=78 shows that although the SEI is fetched as part of the last cycle of the preceding INC zp, the interrupt routines is started when the interrupt happens mid way of T4 in the INC opcode.

This link http://visual6502.org/JSSim/expert.html ... =0014&d=78 shows that the IRQ is _not_ started when the interrupt happens midway T0 of SEI - but this link shows that half a cycle earlier, the IRQ _does_ happen: http://visual6502.org/JSSim/expert.html ... =0014&d=78
I.e. if the interrupt happens at the beginning of the SEI opcode, the interrupt still is executed, but not if the interrupt happens later, which counters the claim made in the original post.

But, there still may be differences in the 1MHz NMOS version compared to the 4MHz version used for visual6502, and between those and the 8502 version.

André


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Apr 25, 2011 9:16 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Nice work!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri May 06, 2011 2:13 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Hydrophilic has posted an update on that thread with an extensive analysis of the existing docs and the behaviour of visual6502:

http://www.commodore128.org/index.php?t ... 0#msg19270

(I think a common cause of difficulty is to ask questions like "in which cycle does the CPU decide to do X" or "in which cycle does the CPU care about X" because there could be several answers, depending on which mechanism within the CPU is under discussion. We've seen that the CPU may embark on interrupt handling because of IRQ but actually fetch the vectors according to NMI - the CPU is not a single entity.)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 16, 2011 9:06 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Hi André
I'm writing up a wiki article on interrupt handling - it's a minefield of details, so I'm not sure if it will ever be definitive, but a set of links to useful visual6502 simulations should be a resource.

Are you OK for me to use material from your posts?

Ed


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 16, 2011 1:38 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 990
Location: near Heidelberg, Germany
BigEd wrote:
Are you OK for me to use material from your posts?

Ed


Yes, absolutely.

André


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 16, 2011 2:50 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Thanks!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Dec 30, 2011 11:02 am 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 990
Location: near Heidelberg, Germany
fachat wrote:
... shows that the IRQ is _not_ started when the interrupt happens midway T0 of SEI - but this link shows that half a cycle earlier, the IRQ _does_ happen: http://visual6502.org/JSSim/expert.html ... =0014&d=78
I.e. if the interrupt happens at the beginning of the SEI opcode, the interrupt still is executed, but not if the interrupt happens later, which counters the claim made in the original post


In a side note to this post. If you examine the log, you can see that the interrupt handling pushes a status register with the interrupt flag I _set_ in this case! Which is also faithfully restored by RTI to avoid any following interrupts.

I don't think any of the emulators does that :-)

André


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 33 guests


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: