moonshot

technical

oljud

oljud is moonshot's sound driver. it drives a sound blaster 16 and plays whatever a ring-3 program hands it through sound(buf, len), one system call. samples are 8-bit mono at 22050 a second, where 128 is silence, so a program can build sound with nothing but store8.

why this card

the sound blaster 16 is an isa card from 1992, and its age is the point. everything about it sits at a fixed address, port 0x220, interrupt 5 and the old isa dma controller. newer audio chips sit on the pci bus and have to be found by walking it first, which moonshot does not do yet. qemu emulates the card, and people still own the real thing.

how it plays

the dma controller loops over a buffer of two halves on its own, and the card interrupts at the end of each half. while it reads one half, the interrupt handler refills the other with what programs have queued, or with silence.

every program has a queue of its own, about three seconds long. sound copies as much as fits and returns how much that was. sound(0, 0) returns how much is still waiting and sound(0, -1) stops the program's sound at once. the queues of all programs are mixed, so two programs are heard together.