Skip to content

DOS: Fix BIOS keyboard buffer overflow beeps during key autorepeat#15948

Merged
icculus merged 1 commit into
libsdl-org:mainfrom
palxex:pr_fix_beep
Jul 6, 2026
Merged

DOS: Fix BIOS keyboard buffer overflow beeps during key autorepeat#15948
icculus merged 1 commit into
libsdl-org:mainfrom
palxex:pr_fix_beep

Conversation

@palxex

@palxex palxex commented Jul 6, 2026

Copy link
Copy Markdown
Contributor
  • I confirm that I am the author of this code and release it to the SDL project under the Zlib license. This contribution does not contain code from other sources, including code generated by a Large Language Model ("AI").

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.

@slouken

slouken commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

It seems like we'd miss key events by doing this?

@icculus

icculus commented Jul 6, 2026

Copy link
Copy Markdown
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.

@icculus

icculus commented Jul 6, 2026

Copy link
Copy Markdown
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.

@palxex

palxex commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@icculus Thanks for the reminder, I've just checked it.

@icculus icculus merged commit ac6e7c7 into libsdl-org:main Jul 6, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants