First post, by tigrou
I wrote the following code, which is supposed to output a 60 Hz square wave to the PC speaker :
org 100hloop:in al, 61hor al, 00000010b ;turn pc speaker onout 61h, alcall _waitin al, 61hand al, 11111101b ;turn pc speaker offout 61h, alcall _waitjmp loop_wait:mov cx, 00hmov dx, 411ah ;wait 16.666msmov ah, 86hint 15hret
It can be compiled under NASM (http://www.nasm.us/) using the following command :
nasm sound.asm -o sound.com
The PC speaker is turned on/off using bit 1, as described here : http://wiki.osdev.org/PC_Speaker#The_Raw_Hardware
However, when run under DOSBOX it does not works as expected (I did not try on real hardware) :
- It only output sound for a short time, then silence. Why ?
- The sound is heavily distorted. It does not sounds at all like a 100% perfect square wave.
How can I fix this ?
Important : as stated in the OSDev page, the PC Speaker can be controlled using the PIT. However this is not what i want. I want to control the PC speaker directly by sending one and zeroes (in order to output something different than a square wave).