cbmeeks wrote:
Actually, I think I misspoke. My intention was to only have one true /NMI and the idea was to tie it to a keyboard. But the more I think about that, the more it doesn't really make sense. I was thinking you could press some keyboard sequence (much like the RESTORE key on C64) to interrupt just about anything and return to BASIC. I think it does make more sense to tie it to a "monitor" button. So pressing it would load a system monitor or something similar.
That is, in fact, exactly how the RESTORE key on the C64 works. That "key" is not part of the regular key matrix (and not scanned) but is a momentary switch with its own separate output that is debounced before being fed directly to the NMI line. (The NMI routine does something along the lines of reinitializing the I/O and then checking to see if the STOP key is also currently pressed, indicating it should restart BASIC at the input routine as well.)
I've attached below the diagrams from the C64 service manual showing the keyboard matrix side and block diagram (the vertical line at "RESTORE" is connected to ground above) and the circuit on the motherboard that debounces the switch (the /NMI line has a 3k3 pullup on it that's not on this fragment of the schematic). You might be able to get away with something simpler from
Garth's reset circuits page, but at least some of the Commodore designers—Bil Herd for certain—were firm believers that a 555 or similar one-shot was absolutely necessary for reliable resets and NMIs. (If you're uncertain about your choice of circuit, you could use their technique of producing ten thousand machines and testing each one.)
Using NMI as a "soft reset" to recover from programming errors or similar seems to be a fairly common technique. As well as being used on Commodore machines and BDD's boards, it's also used in my (6800-based) National/Panasonic JR-200: the "BREAK" key on that keyboard is part of the regular keyboard matrix, but that matrix is scanned by a microcontroller that generates a separate NMI output when that key is pressed, rather than putting the key code into a register as it does with all the other keys. I seem to recall that the KIM also had NMI on a debounced switch.
The Apple II used RESET instead for this, freeing NMI for other purposes. To determine whether a reset was a cold or warm start it had a checksum for a vector in the zero page, using that if the checksum was ok or doing a complete machine initialization if it was not. The downside of this technique is that unlike an NMI you don't get the previous program counter and flags pushed on to the stack, which you might want if you're interrupting running code in order to debug it.