| |
Flavioweb
Registered: Nov 2011 Posts: 466 |
Breadbin/C128 Restore key and double nmi.
I noticed a strange thing (at least for me) on some breadbins and C128s.
If we take this code and run it with sys 49152, two counters will appear on the top left of the screen.
For each press of the RESTORE button, one of the two counters is incremented and the border color is changed.
On Vice and the C64c I've tried, it works perfectly this way.
On breadbins and C128s, however, often, for each single press of the RESTORE button, both NMI routines are executed.
You can tell because, in addition to not changing the border color, both counters are incremented at the same time.
Is this a known thing?
Is there a way to avoid it (I would like for each press of the restore button to execute one routine at a time)?
*= $C000
LDA #$7F
STA $DC0D
STA $DD0D
LDA $DC0D
LDA #$30
STA $0400
STA $0402
;-------------------
NMI_01
LDA $DD0D
LDA #<NMI_02
STA $0318
STA $FFFA
LDA #>NMI_02
STA $0319
STA $FFFB
LDA #$01
STA $D020
LDY $0400
INY
CPY #$3A
BNE NMI_01_NC
LDY #$30
NMI_01_NC
STY $0400
JMP *
;-------------------
NMI_02
LDA $DD0D
LDA #<NMI_01
STA $0318
STA $FFFA
LDA #>NMI_01
STA $0319
STA $FFFB
LDA #$03
STA $D020
LDY $0402
INY
CPY #$3A
BNE NMI_02_NC
LDY #$30
NMI_02_NC
STY $0402
JMP *
https://www.dropbox.com/scl/fi/82hkc6wvvbz6x8kub6cb3/nmi-test.p.. |
|
| |
soci
Registered: Sep 2003 Posts: 481 |
Business as usual, it needs debouncing. Just set a flag in the NMI routine and don't try to do anything else there. Then in the main code check it, wait a bit, reset and do whatever needs to be done for each press.
However the problem can also happen when releasing the button.
So while waiting it needs to be checked that it's actually held down for a while or it's just a glitch. That can be done with CIA2 NMIs as those only work after the button was released.
Have fun ;) |
| |
Flavioweb
Registered: Nov 2011 Posts: 466 |
I think the debouncing thing is correct and I have to find a way to implement something similar even if for now I can't imagine how to do it with nmis.
up to this point I have tried it on different machines and they all have the same behavior.
I have to go into more detail, first of all removing the acks (which are useless for an nmi generated by the restore button) and then I have to understand after how long the second nmi is triggered.
In spite of everything I don't understand why it happens: if the line was "held up" too long by the signal generated by the button we would have the nmis blocked until the release.
Here there is something that "pulls the line up and down" triggering more nmis.
For what i can understand, at least. |
| |
Oswald
Registered: Apr 2002 Posts: 5095 |
the solution is extremely simple: just use another key. |
| |
Martin Piper
Registered: Nov 2007 Posts: 726 |
Are you seeing this on a momentary (hard) press? A press and hold down? On a release after a long hold down? |
| |
Flavioweb
Registered: Nov 2011 Posts: 466 |
Quote: Are you seeing this on a momentary (hard) press? A press and hold down? On a release after a long hold down?
This happens no matter how long/hard you press Restore.
About 1 in 4 times it works fine, the other 3 times it doesn't. Then maybe it works fine a couple of times in a row and then 4 or 5 more times it triggers double nmi. |
| |
Martin Piper
Registered: Nov 2007 Posts: 726 |
Quote: This happens no matter how long/hard you press Restore.
About 1 in 4 times it works fine, the other 3 times it doesn't. Then maybe it works fine a couple of times in a row and then 4 or 5 more times it triggers double nmi.
Hmm time to get the logic analyser out and capture some comparisons.
Your different hardware, do some use a 555 timer connected to the restore of key and some use the other chip? The buffering logic changed across hardware revisions. |
| |
chatGPZ
Registered: Dec 2001 Posts: 11387 |
Hard or long or short press is irrelevant for this - and different hardware (switches) will behave different, every time you press them. Waste of time to wonder about this, its just how it is.
Reminds me to add some sort of emulation for contact bounce to VICE :) |
| |
trident
Registered: May 2002 Posts: 92 |
I don't know what the best approach for debouncing the restore key on the C64 is, but here is a pretty good and recent rundown of what debouncing inputs in general entails: https://blog.golioth.io/how-to-debounce-button-inputs-in-a-real..
And Jack Ganssle's debounce guide is still relevant too: https://www.ganssle.com/debouncing-pt2.htm |
| |
TheRyk
Registered: Mar 2009 Posts: 2255 |
OT about the long/short press, IIRC there's some capacitor issue on some boards resulting in having to push RESTORE very hard, can be solved by replacing C38 |