Saturday, 17 January 2026

QBX: PC Speaker Emulation

I'm excited by this. 🙂

Getting closer to running NIBBLES. The latest advancement: PC speaker sound emulation.

You might think, looking at this, that it's not _really_ PC speaker sound emulation, it's QBASIC PLAY statement emulation, right?

Wrong 🙂

Behind the scenes, there's a simulated 8253 timer chip. Its Timer 2 configuration is linked to a simulated 8042 keyboard controller chip (well, this last one is a bit of a stretch, because it only cares about the two speaker control bits). (For performance reasons, it simulates frequencies and ticks instead of communicating actual raw ticks.)

The function in charge of playing a note as part of a PLAY statement does so in a manner that reconfigures the 8253 to generate the target frequency. The sound you're hearing is the raw square wave resulting from the simulated output from the timer chip. Woohoo!

No comments:

Post a Comment