Jump to content
IGNORED

How can POKEY IRQ Timers mess up NMI timing?


Sheddy

Recommended Posts

  • 2 months later...
  • 1 month later...

Sorry for resurrecting this somewhat old thread...

 

I looked into this some months ago. It is a cpu bug. The same bug should be present in all the 650X NMOS variants, including Sally. It is, if you want, a variant of the IRQ/BRK concurrency bug. The bug can be seen by checking the CPU internal schematics.

 

The bug would be exposed when the NMI pulse is less than 3 clock cycles, and when the NMI is trigerred at certain specific clocks during the IRQ exception processing. Note that it doesn't matter when the IRQ signal became active, only the NMI signal to IRQ *exception processing* is significant.

 

In the case of the A8, the NMI signal as you all know is trigerred by ANTIC. And ANTIC triggers NMI at constant specific cycles on the scanline. So if you program Pokey interrupts to happen on every scanline at the very same specific scan cycle (note that this depends not only on Pokey timers but also on CPU execution), you would effectively mask NMI.

Edited by ijor
Link to comment
Share on other sites

Sorry for resurrecting this somewhat old thread...

 

I looked into this some months ago. It is a cpu bug. The same bug should be present in all the 650X NMOS variants, including Sally. It is, if you want, a variant of the IRQ/BRK concurrency bug. The bug can be seen by checking the CPU internal schematics.

 

The bug would be exposed when the NMI pulse is less than 3 clock cycles, and when the NMI is trigerred at certain specific clocks during the IRQ exception processing. Note that it doesn't matter when the IRQ signal became active, only the NMI signal to IRQ *exception processing* is significant.

 

In the case of the A8, the NMI signal as you all know is trigerred by ANTIC. And ANTIC triggers NMI at constant specific cycles on the scanline. So if you program Pokey interrupts to happen on every scanline at the very same specific scan cycle (note that this depends not only on Pokey timers but also on CPU execution), you would effectively mask NMI.

 

The bug doesn't show up in the 65C02, but I guess that's not NMOS.

Link to comment
Share on other sites

  • 10 months later...

I was doing some search and found this post. I already saw it some time ago, but I concentrated on the picture, and missed your comment, Bryan.

 

Here's /NMI vs phase2 clock (ph2). The 6502 datasheet states that /NMI will be sampled during the ph2 interval (ph2 high). So, NMI properly falls and rises during the ph1 part of the clock.

 

Just for the records because I don't think it is too relevant to the topic. But I think you are mis-interpreting the data sheet. Docs are a bit misleading, but what actually happens is that the CPU samples the pin on the falling edge of PHI2. It is clear once you check other docs (including later WDC/CMOS datasheet), or even the 6800 datasheet (6501 was supposed to be bus compatible).

 

Then, NMI shouldn't be changed close to the PHI2 falling edge. It is ok during PHI2, as long as it is early enough, or during PHI1 as long as it is late enough (as ANTIC does). Whatever the reason that the ANTIC developer (was Jay Miner himself?) decided to use PHI2 falling edge, it is very interesting that Pokey changes IRQ on the opposite PHI2 edge! (NMI and IRQ are sampled together by the CPU).

Edited by ijor
Link to comment
Share on other sites

Hey ijor,

 

I wonder if /NMI were re-clocked to the next rising edge of Phi2 if the problem caused by a 2-cycle pulse would persist. Either way, the NMIST bits hang around for a long time so an IRQ routine could quickly check them and jump to the NMI routine if needed. You just have to clear the NMIST bits as you service them which you normally don't have to do.

Link to comment
Share on other sites

I wonder if /NMI were re-clocked to the next rising edge of Phi2 if the problem caused by a 2-cycle pulse would persist.

 

I considered this, and while I'm not 100% sure (and certainly didn't test it on hardware), I think it shouldn't fix the problem. Internally, the CPU would (should) still see the signal change at the same edge as before.

 

@Rybags: What I meant is that both signals, NMI and IRQ, are latched at the same edge by the CPU. Then, naturally, a system would be designed in such a way as generating both signal in the same edge. But for some reason (which might be just because ANTIC/POKEY were designed by different people), here they change in opposite edges.

Edited by ijor
Link to comment
Share on other sites

  • 1 month later...
I wrote a test app (attached) to check interference between IRQs and DLIs, and indeed there is exactly one cycle at which a IRQ will block an NMI.

Hi! I'm pleased to say that I've recreated this situation on the visual6502 transistor-level simulator. We've recently made a few changes to make it possible to experiment with exact timings and instruction streams. The URL you need is something like this.

 

It's not too hard to modify these URLs for experimentation, although I know they look ugly. We've got some online docs for how they work. I plan to write this NMI/IRQ collision up on our wiki in our collection of curiosities. (The crucial point about visual6502 being that we can see what the causes are because we have all the transistors: this might be helpful to emulator writers and to other people interested in cycle accurate behaviour. On the other hand, we are modelling a specific NMOS 6502, and we only simulate to switch level, so for example unassigned opcode 8B doesn't misbehave in the expected way - it misbehaves in its own way, but we know why.)

 

Thanks to everyone for the various useful hints on this thread, and to Avery particularly for the Altirra documentation!

 

Cheers

Ed

Link to comment
Share on other sites

  • 4 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...