Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Breadbin/C128 Restore key and double nmi.
2024-12-28 20:55
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..
2024-12-28 21:52
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 ;)
2024-12-29 08:44
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.
2024-12-29 10:50
Oswald

Registered: Apr 2002
Posts: 5095
the solution is extremely simple: just use another key.
2024-12-29 11:01
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?
2024-12-29 11:08
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.
2024-12-29 15:02
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.
2024-12-29 18:18
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 :)
2025-01-01 13:51
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
2025-01-02 14:46
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
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Tomxx/KAplus
et1999cc/HF/MS
Pajda/Faith Design
t0m3000/hf^boom!^ibx
zscs
Bob/Censor Design
MCM/ONSLAUGHT
FRaNKy/Smash Designs
Guests online: 135
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.6)
4 Coma Light 13  (9.6)
5 The Demo Coder  (9.6)
6 Edge of Disgrace  (9.6)
7 What Is The Matrix 2  (9.6)
8 Sprite Bukkake 2  (9.6)
9 Uncensored  (9.6)
10 Comaland 100%  (9.6)
Top onefile Demos
1 Layers  (9.7)
2 Cubic Dream  (9.6)
3 Party Elk 2  (9.6)
4 Copper Booze  (9.6)
5 Rainbow Connection  (9.5)
6 Morph  (9.5)
7 Dawnfall V1.1  (9.5)
8 Libertongo  (9.5)
9 Katzen-Video.mp4  (9.5)
10 Onscreen 5k  (9.5)
Top Groups
1 Booze Design  (9.3)
2 Oxyron  (9.3)
3 Performers  (9.3)
4 Fairlight  (9.3)
5 Triad  (9.3)
Top Fullscreen Graphicians
1 Joe  (9.7)
2 Sulevi  (9.6)
3 Veto  (9.6)
4 The Sarge  (9.6)
5 Facet  (9.5)

Home - Disclaimer
Copyright © No Name 2001-2025
Page generated in: 0.045 sec.