softpower: Fix the power-off delay spinner range overflowing int16_t - #7888
Merged
OBattler merged 1 commit intoSep 7, 2026
Merged
Conversation
device_config_spinner_t stores min, max and step as int16_t (src/include/86box/device.h:140-144), so the "delay" spinner's .max = 60000 in src/device/softpower.c:169 truncates to -5536, below the .min of 0. qt_deviceconfig.cpp:327-331 calls setMaximum() and then setMinimum() with those values, which collapses the QSpinBox range to [0, 0], so opening the card's configuration dialog clamps the delay to 0 and writes it back to the config. With the delay at 0, softpower_write() arms power_off_timer with a zero delay, and the system powers off before the suspend NMI handler runs. That defeats the point of the card: the IBM PC Convertible Technical Reference Vol. 1 (6280655), "Power System Control (Hex 07F)", describes the power supply removing power roughly two seconds after REQ_POFF so the SUSPEND handler can save system state. Cap the maximum at 30000 ms, which fits int16_t, is a multiple of the 100 ms step, and is fifteen times the delay of the reference hardware. This also clears the -Wconstant-conversion warning clang emits for the file by default.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Opening the configuration dialog for the PC Convertible Soft Power Card silently resets its power-off delay to 0 ms.
device_config_spinner_tholdsmin,maxandstepasint16_t(src/include/86box/device.h:140-144). The "delay" spinner in src/device/softpower.c:169 sets.max = 60000, which does not fit and truncates to -5536, below its.minof 0. src/qt/qt_deviceconfig.cpp:327-328 callssetMaximum()and thensetMinimum()with those values, and Qt pulls the other end of the range along on each call, so the QSpinBox ends up ranged [0, 0]. The dialog therefore displays 0, sees that it differs from the stored 2000, and writesdelay = 0back to the config.softpower_write()then armspower_off_timerwith a zero delay and the machine loses power before the suspend NMI handler runs, which is the window the card exists to provide.This caps the maximum at 30000 ms. It fits
int16_t, it is a multiple of the 100 ms step so the spinner arrows land on it, and it is fifteen times the delay of the real power supply.clang warns about the truncation by default today:
I checked the change two ways.
cc -fsyntax-only -Wall -Wextraon src/device/softpower.c emits the warning above before the change and is clean after it. And a standalone program that reuses thedevice_config_spinner_tdefinition and the range adjustment Qt applies prints:It is the only spinner in the tree that does not fit the field; the next largest is 15872 in src/device/isamem.c.
Checklist
References
IBM PC Convertible Technical Reference Volume 1 (6280655), cited by the card's own header comment for the Power System Control register at hex 07F and the roughly two second delay before power is removed: http://bitsavers.org/pdf/ibm/pc/convertable/6280655_PC_Convertable_Technical_Reference_Volume_1_Feb86.pdf
IBM PC Convertible Technical Reference Volume 2 (55X8817), the BIOS listing containing the SYS_POWER_OFF and SUSPEND handlers that run in that window: http://bitsavers.org/pdf/ibm/pc/convertable/55X8817_PC_Convertable_Technical_Reference_Volume_2_Feb86.pdf