Hello pesco,
My profuse apologies for the delay in replying. I've been swamped with non-PiDP-8 stuff through most of December. Let me clarify, and see if we can move this conversation forward.
First let me see if I can give you a more complete understanding of the testing I did, what I had hoped for as the outcome, what my actual results were, and why I think that it's a problem.
I would very much like to incorporate either your patch, or one with equivalent functionality into the PiDP-8 release. I agree with your initial principle that it would be ideal if a simple software change would enable builders of the PiDP-8 to just "solder the deposit switch in upside-down, and set the configuration option to use it.
The only platform I have available for testing is my own PiDP-8, where I cut a trace, put in a bodge-wire, and soldered in the deposit switch upside down with the regular software.
In your reply you say:
So one wouldn't enable this by default. It's for tinkerers who don't mind compiling their own software but would rather not cut a trace on the board.
What would you think of a new default? Change the instructions to tell people to solder in the switch upside-down and use the "invert-deposit" version of the software?
I'd hoped to offer that as a more mainstream option. But when I tried the invert-deposit option on my test host, it initially seemed benign. I.E. if someone with a regular build ran that option nothing bad would happen. Unfortunately, on one of my test runs, the whole system hung, and I had to power cycle to get my system back. I believe that, when one un-gracefully power-cycles a Pi, it's a roll of the dice as to whether the system image gets corrupted. I got my system back but have been afraid to do more testing ever since.
I don't like the option of, "If you want to tinker, and solder in the deposit switch upside, down and compile with this option enabled it will work, but if you run this option on a stock system it will hang requiring a power cycle, which may corrupt your system image requiring a start agin from scratch."
This is why I called for additional collaboration.
As you said in your reply:
I.e. the switch looks permanently engaged, unless you press it which momentarily disengages it.
Apparently that state of "permanently engaged" can result in the whole Raspbery Pi OS being out in lala land, unable to be interrupted or shut down cleanly.
I'd like to understand how that happens, and add code to prevent such a hangup. Then if someone tries out the option, the risk of catastrophe is eliminated.
@Oscar, @Steve Tokey, or anybody who understands the gpio code better than I, what made the system hangup, and can it be prevented?
-Bill
--
You received this message because you are subscribed to the Google Groups "PiDP-8" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pidp-8+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pidp-8/3c6eeee1-ea2b-4366-8661-e2ef3dd38563%40gmail.com.
--
You received this message because you are subscribed to the Google Groups "PiDP-8" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pidp-8+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pidp-8/CAHF_aixCicV7ya_eH0t%3DQj5i1Mx-qjihBshnxH_1Nov4Gf56yQ%40mail.gmail.com.
On Feb 27, 2026, at 10:27 PM, William Cattey <bill....@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "PiDP-8" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pidp-8+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pidp-8/787e967f-e0fa-4399-b826-401b133601f3n%40googlegroups.com.
If you can filter out the over-confident sounding stuff, does the final testing and conclusions make sense?
I'm prepared to hear that they still don't. Again, however, I did try out the new version and didn't get the system hangup.
Detai: (too much of it, I'm afraid.)
Let me examine how the GPIO thread and SIMH interact, particularly around interrupts and shutdown:
Now I need to understand what gpio_core() does and how it checks the terminate flag. This is the actual loop that the GPIO thread runs. Let me search for information about this:
So gpio_core() is implemented elsewhere (probably in gpio.c or gpio-nls.c). The key insight is that the GPIO thread passes &terminate_gpio_thread to gpio_core(), and gpio_core() is supposed to check this flag and exit when it's set to 1.
Now let's think about the hang problem:
Key Observations About the HangLooking at the code:
Here's my hypothesis about what might be happening:
The Problem with State InconsistencyWhen gss[].stable_state and switchstatus[] disagree:
Now consider what happens when you actually press the DEP switch:
The switch state keeps oscillating between what gss[] thinks it should be and what the GPIO actually reads.
Why This Causes a Complete HangIf gpio_core() is stuck in this infinite debounce loop for the DEP switch:
Can you add debug logging to see if debounce_switch() is being called repeatedly for the DEP switch? Something like:
If you see this counter incrementing rapidly, that confirms the infinite debounce loop theory.
Does this match what you're seeing? The hang might not be the SIMH thread at all - it's the GPIO thread stuck in an infinite loop!
Excellent! This is very revealing. The debug output shows:
Wait - both values are the same! ss=1, stable=1
This means debounce_switch() is being called thousands of times even though the switch state hasn't changed. That's NOT supposed to happen based on the code logic.
Let me re-examine the debounce_switch() function:
Ah! Now I see it. The function debounce_switch() is called for EVERY switch on EVERY scan, regardless of whether the state has changed. Look at line 424 - it's called inside the nested loop that reads all switches.
When ss == stable_state (line 372), it just resets the timer and returns. This is normal operation. The debug counter incrementing just shows that the GPIO scanning loop is running normally.
So this is NOT an infinite loop problem!
Re-thinking the HangThe GPIO thread is working fine - it's scanning switches normally. The problem must be elsewhere.
Let me reconsider: You said both terminal windows became unresponsive. Let's think about what could cause that:
New Theory: The Inversion During Normal OperationLet's trace what happens when you do "Load Address 7600 / Start" with the DEP switch in its resting (open) position:
With original patch (inversion in report_ss()):
This is the bug! After initialization, switchstatus shows DEP closed even though it's physically open, and it never gets corrected because the debouncing logic thinks everything is fine.
Why This Causes the HangWhen SIMH sees DEP as constantly closed:
Can you add more debug output to see what switchstatus[2] actually contains?
I predict you'll see switchstatus=0 (closed) even though gpio_ss=1 and gss_stable=1 (both saying it's open).
Perfect! There's the smoking gun!
The DEP switch is:
And this state never corrects itself because the debouncing logic sees gpio_ss == gss_stable and thinks everything is fine (line 372-377), so it never calls report_ss() again to update switchstatus[].
The Complete Bug ExplanationDuring initialization:
After initialization: 5. Every scan sees GPIO=1, stable=1 (they match) 6. Line 372 condition is true, just resets timer 7. report_ss() is never called again 8. switchstatus stays frozen at 0 forever
Why This Causes the HangSIMH sees the DEP switch as permanently pressed. Depending on what OS/8 is doing during the boot sequence, this could:
The "hang" isn't really a hang in the traditional sense - it's SIMH responding to what it thinks is a held-down DEP switch.
Why Moving the Inversion Fixes ItWith the inversion in debounce_switch() (before any state management):
This is consistent and correct for an inverted switch.