DOS: Fix BIOS keyboard buffer overflow beeps during key autorepeat#15948
Merged
Conversation
Collaborator
|
It seems like we'd miss key events by doing this? |
Collaborator
|
We don't use the BIOS at all for keyboard input...we have an interrupt handler that adds presses to a ring buffer as they happen and then PumpEvents picks them up. This just flushes the BIOS's completely separate (and unused by us) ring buffer, so it doesn't overflow and cause chaos. |
Collaborator
|
@palxex, I've added the standard licensing checkbox to the top of this PR's description. We can't merge this unless you can check that box. |
Contributor
Author
|
@icculus Thanks for the reminder, I've just checked it. |
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.
Problem
In the current implementation, KeyboardIRQHandler is chained on IRQ1, which is the safest approach. However, the BIOS keyboard buffer is never drained during normal operation; it is only flushed when the ISR is uninstalled on exit. When a user holds down a key (arrow keys, letters, etc.), autorepeat fills the BIOS buffer within a few seconds. Once full, the BIOS signals overflow, causing the PC speaker to emit a continuous series of annoying beeps.
This issue is reproducible on real hardware with a piezo buzzer and under 86box, but not in DOSBox (which does not strictly emulate this BIOS buffer overflow behavior).
Solution
Factor out the existing BIOS-draining logic from DOSVESA_QuitKeyboard() into a new static helper DOSVESA_DrainBIOSKeyboardBuffer() and call it in DOSVESA_PumpEvents() so the BIOS queue is flushed every frame. No measurable performance overhead was observed.
Impact
Eliminates the beeps without altering IRQ handling.
Minimal, low-risk change.
Testing
Before this patch, holding down any key ( for exam. arrow keys ) triggered a continuous stream of beeps from the PC speaker on all tested platforms above ( beeps would start within a few seconds of autorepeat and continue incessantly until the key was released ):
Various 86box configurations
An older 845GL board with a built-in buzzer
A B450 board with an external buzzer attached (since modern motherboards no longer have a built-in buzzer)
After applying the patch, no keybuf-overflow beeps occur on these environments, while keyboard input remains fully responsive.