Page 1 of 1
How to make them computer beep?
Posted: Mon Oct 24, 2005 9:13 pm
by Guest
Is there a way to make the computer beep without writing a fully fledged sound driver (like write to some port or something) ? Help is appreciated...
Also... I found the realmode way to do it with int 21h... I need a way that works without BIOS interrupts..
Thanks in advance.
Re:How to make them computer beep?
Posted: Tue Oct 25, 2005 1:29 am
by Candy
Guest wrote:
Is there a way to make the computer beep without writing a fully fledged sound driver (like write to some port or something) ? Help is appreciated...
Also... I found the realmode way to do it with int 21h... I need a way that works without BIOS interrupts..
Thanks in advance.
The system speaker is connected to the PIT. Try searching the internet for ways to reprogram the PIT and to which port it's connected (don't have any books handy right now).
Re:How to make them computer beep?
Posted: Tue Oct 25, 2005 2:14 am
by Brendan
Hi,
For the PC speaker, there's a 2 bits in I/O port 0x61:
- Bit 0: Connect speaker to PIT channel 2 if set
Bit 1: Speaker state
By clearing bit 0, you can control the PC speaker directly by setting and clearing bit 1. This allows for very advanced effects (e.g. pulse width modulated polyphonic sounds), but consumes a huge amount of CPU time and it isn't easy to get good results. I've heard games get surprising sound effects and tunes using this approach, but that was a long time ago...
By programming PIT channel 2 and then setting bit 0, you can produce monotonic sounds (a beep). You can initialize PIT channel 2 once during boot and then set/clear bit 0 set get the same sound every time, or you could reprogram the PIT channel each time to allow for different frequency sounds.
For information on programming the PIT, see:
http://www.osdev.org/osfaq2/index.php/PIT
Unfortunately, some computers don't have a PC speaker at all, some (most desktops) use small cheap speakers and some use smaller cheaper peizo's (which have problems generating low frequency sounds) - there's no way to detect what hardware's present or predict what it will sound like.
Cheers,
Brendan
Re:How to make them computer beep?
Posted: Tue Oct 25, 2005 2:28 am
by bubach
Code: Select all
;----------------------------------;
; PC-speaker; beep ;
;----------------------------------;
beep:
push eax
in al, 0x61 ; turn the speaker on.
or al, 3
out 0x61, al
;; delay for 150ms or something here...
in al, 0x61
and al, 0xFC ; some do 0xFD, some 0xFC... :/
out 0x61, al
pop ecx
ret